if (document.images) {

  image1On = new Image();
  image1On.src = "images/imgBtnTrangchuOver.gif"; 
  image1Off = new Image();
  image1Off.src = "images/imgBtnTrangchu.gif"; 

  image2On = new Image();
  image2On.src = "images/imgBtnGioithieuOver.gif"; 
  image2Off = new Image();
  image2Off.src = "images/imgBtnGioithieu.gif"; 

  image3On = new Image();
  image3On.src = "images/imgBtnHoivienOver.gif"; 
  image3Off = new Image();
  image3Off.src = "images/imgBtnHoivien.gif"; 
  
  image4On = new Image();
  image4On.src = "images/imgBtnHoidapOver.gif"; 
  image4Off = new Image();
  image4Off.src = "images/imgBtnHoidap.gif"; 

  image5On = new Image();
  image5On.src = "images/imgBtnHuongdanOver.gif"; 
  image5Off = new Image();
  image5Off.src = "images/imgBtnHuongdan.gif"; 

  image6On = new Image();
  image6On.src = "images/imgBtnQuangcaoOver.gif"; 
  image6Off = new Image();
  image6Off.src = "images/imgBtnQuangcao.gif"; 

  image7On = new Image();
  image7On.src = "images/imgBtnLienheOver.gif"; 
  image7Off = new Image();
  image7Off.src = "images/imgBtnLienhe.gif"; 
  
  image8On = new Image();
  image8On.src = "images/imgBtnQuydinhOver.gif"; 
  image8Off = new Image();
  image8Off.src = "images/imgBtnQuydinh.gif"; 

  
  
	smallOn = new Image;
	smallOff = new Image;
	
	smallOn.src ='images/folderopen.gif';
	smallOff.src ='images/folder.gif';
  
    
	
}
function changeImages() {
  if (document.images) {
    for (var i=0; i<2; i+=2) {
      document[changeImages.arguments[i]].src = eval(changeImages.arguments[i+1] + ".src");
    }
  }
}



function initArray() {
   for(i=0;i<initArray.arguments.length; i++)
      this[i] = initArray.arguments[i];
}
function getFullYear(d) { // d is a date object
   yr = d.getYear();
   if (yr < 1000)
     yr+=1900;
   return yr;
}
function outDate(){
    var isnMonths=new initArray("January","February","March","April","May","June","July","August","September","October","November","December");
    var isnDays= new initArray("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
    today=new Date();		
    document.write("<b><font face=Arial color=#CE9A03 size=1> " + isnDays[today.getDay()]+", "+isnMonths[today.getMonth()]+" "+today.getDate()+", " + getFullYear(today) + "</font></b>");

}




/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
PURPOSE: Remove leading blanks from our string.
IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}


/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}
function checkEmail(str){
	var textValue = str.value;
	var err=''
	if (textValue == ''){
		err += "Địa chỉ email không hợp lệ ";
		alert(err);
		str.focus();
		return false
	}
	if (textValue.indexOf('@') <= 0 || textValue.indexOf('@') == textValue.length -1){
		err += "Địa chỉ email không hợp lệ ";		
	} else {
		var substr = textValue.substring(textValue.indexOf('@'),textValue.length);
		if (textValue.indexOf('.') <= 0) {
			err += "Địa chỉ email không hợp lệ \n";
		}
	}
	if (err != '') { 
		alert(err); 
		str.focus();
		return false;
	}
	return true;
}

function checkFormLogin(f) {
	if (!checkEmail(f.user_email)) {
		return false;
	}
	password = f.user_password.value;
	if (password == ""){
		alert('Vui lòng nhập vào mật khẩu');
		f.user_password.focus();
		return false;
	}
	return true;
	
}
function checkFormSearch(f){
	txtSearch = f.txt_search.value;
	if (Trim(txtSearch) == "") {
		alert('Vui lòng nhập vào từ khoá tìm kiếm');
		f.txt_search.focus();
		return false;
	}
	return true;
}
function checkFormMemberInfo(f) {
	companyName = f.company_name.value;
	if (Trim(companyName) == "") {
		alert('Vui lòng nhập vào tên doanh nghiệp');
		f.company_name.focus();
		return false;
	}
	address = f.address.value;
	if (Trim(address) == "") {
		alert('Vui lòng nhập vào địa chỉ');
		f.address.focus();
		return false;
	}
	telephone = f.telephone.value;
	if (Trim(telephone) == "") {
		alert('Vui lòng nhập số điện thoại');
		f.telephone.focus();
		return false;
	}	
	if (!checkEmail(f.email)) {
		return false;
	}
	subCatId = f.sub_cat_id.value;
	if (subCatId == 0){
		alert('Chọn chủng loại');
		f.sub_cat_id.focus();
		return false;
	}
	contactPerson =  f.contact_person.value;
	if (Trim(contactPerson) == "") {
		alert('Vui lòng nhập tên người liên hệ');
		f.contact_person.focus();
		return false;
	}
	companyDesc = f.company_desc.value;
	if (Trim(companyDesc) == "") {
		alert('Vui lòng nhập vào phần giới thiệu doanh nghiệp');
		f.company_desc.focus();
		return false;	
	}
}
	
function checkFormAddProduct(f) {
	productName = f.product_name.value;
	if (Trim(productName) == "") {
		alert('Vui lòng nhập tên sản phẩm');
		f.product_name.focus();
		return false;
	}
	price = f.price.value;
	if (price != "") {
		if (!checkNumber(price)) {
			alert('Nhập giá không hợp lệ');
			f.price.focus();
			return false;
		}
	}	
	productFrom = f.product_from.value;
	if (Trim(productFrom) == "") {
		alert('Vui lòng nhập vào hãng sản xuất');
		f.product_from.focus();
		return false;
	}
	catId = Trim(f.cat_id.value);
	if (catId == "0") {
		alert('Vui lòng chọn ngành hàng');
		f.cat_id.focus();
		return false;
	}

	if (parseInt(catId) > 0 && parseInt(catId) < 4) {
		subCatId = f.sub_cat_id.value;
		if (subCatId == "0") {
			alert('Vui lòng chọn ngành hàng cụ thể');
			f.sub_cat_id.focus();
			return false;
		}
		
	}
	productDesc = f.product_desc.value;
	if (Trim(productDesc) =="") {
		alert('Vui lòng nhập vào mô tả sản phẩm');
		f.product_desc.focus();
		return false;
	} else if (productDesc.length < 50) {
		alert('----------- Thông báo lỗi -----------\n1. Phần mô tả sản phẩm quá ngắn\n2. Xin vui lòng mô tả chi tiết sản phẩm');
		f.product_desc.focus();
		return false;	
	}
	return true;
}

function checkFormUpdateProduct(f) {
	productName = f.product_name.value;
	if (Trim(productName) == "") {
		alert('Vui lòng nhập tên sản phẩm');
		f.product_name.focus();
		return false;
	}
	price = f.price.value;
	if (price != "") {	
		if (!checkNumber(price)) {
			alert('Nhập giá không hợp lệ');
			f.price.focus();
			return false;
		}
	}
	productFrom = f.product_from.value;
	if (Trim(productFrom) == "") {
		alert('Vui lòng nhập vào hãng sản xuất');
		f.product_from.focus();
		return false;
	}
	catId = Trim(f.cat_id.value);
	if (catId == "0") {
		alert('Vui lòng chọn ngành hàng');
		f.cat_id.focus();
		return false;
	}

	if (parseInt(catId) > 0 && parseInt(catId) < 4) {
		subCatId = f.sub_cat_id.value;
		if (subCatId == "0") {
			alert('Vui lòng chọn ngành hàng cụ thể');
			f.sub_cat_id.focus();
			return false;
		}
		
	}
	if (f.is_promotion.checked) {
	
		pricePromotion = f.price_promotion.value;


		if (!checkNumber(pricePromotion)) {
			alert('Giá khuyến mãi không hợp lệ');
			f.price_promotion.focus();
			return false;
		}
		
		beginPromotion = f.begin_promotion.value;
		
		if (isDate(beginPromotion)==false) {			
			f.begin_promotion.focus();
			return false;
		}

		endPromotion = f.end_promotion.value;
		if (isDate(endPromotion) == false) {			
			f.end_promotion.focus();
			return false;
		}		
	}
	

	productDesc = f.product_desc.value;

	if (Trim(productDesc) =="") {
		alert('Vui lòng nhập vào mô tả sản phẩm');
		f.product_desc.focus();
		return false;
	}
	return true;

}

function outKhuyenMai() {
	w = screen.width;
	if (w <=800) {
		document.write("Khuyến mãi");
	} else {
		document.write("Sản phẩm khuyến mãi");
	}

}
function checkNumber(x){
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (anum.test(x)) {
		result=true
	} else{
		//alert("Vui lòng nhập vào số hợp lệ")
		result = false
	}
	return result;
}
function checkChangePassword(f){
	oldPass = f.old_password.value;
	if (oldPass == ""){
		alert('Vui lòng nhập mật khẩu cũ');
		f.old_password.focus();
		return false;
	}
	newPassword1 = f.new_password1.value;
	if (newPassword1 == "") {
		alert('Vui lòng nhập mật khẩu mới');
		f.new_password1.focus();
		return false;
	}
	newPassword2 = f.new_password2.value;
	if (newPassword1 != newPassword2) {
		alert('Lặp lại mật khẩu mới không đúng');
		f.new_password2.focus();
		return false;
	}
	return true;
}
function checkRegister (f) {
	companyName = f.company_name.value;
	if (Trim(companyName) == "") {
		alert('Vui lòng nhập tên doanh nghiệp');
		f.company_name.focus();
		return false;
	}
	address = f.address.value;
	if (Trim(address) == "") {
		alert('Vui lòng nhập vào địa chỉ');
		f.address.focus();
		return false;
	}
	cityWhereId = f.city_where_id.value;
	if (cityWhereId == "0") {
		alert('Vui lòng chọn tỉnh thành phố');
		f.city_where_id.focus();
		return false;
	}
	
	telephone = f.telephone.value;
	if (Trim(telephone) == "") {
		alert('Vui lòng nhập số điện thoại');
		f.telephone.focus();
		return false;
	}
	contactPerson = f.contact_person.value;
	if (Trim(contactPerson) == "") {
		alert('Vui lòng nhập vào người liên hệ');
		f.contact_person.focus();
		return false;
	}
	catId = f.cat_id.value;
	if (catId == "0") {
		alert('Vui lòng chọn ngành nghề');
		f.cat_id.focus();
		return false;
	}
	subCatId = f.sub_cat_id.value;
	if (subCatId == "0") {
		alert('Vui lòng chọn ngành nghề cụ thể');
		f.sub_cat_id.focus();
		return false;
	}	
	companyDesc = f.company_desc.value;
	if (Trim(companyDesc) == ""){
		alert('Vui lòng nhập giới thiệu nội dung doanh nghiệp');
		f.company_desc.focus();
		return false;
	} else if(companyDesc.length < 50) {
		alert('----------- Thông báo lỗi -----------\n1. Phần giới thiệu doanh nghiệp quá ngắn\n2. Xin vui lòng giới thiệu doanh nghiệp chi tiết hơn');
		f.company_desc.focus();
		return false;
	}
	
	if (!checkEmail(f.email_login)) {
		return false
	}
	if (f.user_password.value == "") {
		alert('Vui lòng nhập vào mật khẩu');
		f.user_password.focus();
		return false;
	}
	securityCode = f.security_code.value;
	if (!checkNumber(securityCode)) {
		alert('Nhập mã an toàn không hợp lệ');
		f.security_code.focus();
		return false;
	}
	return true;	
}

function checkLostPassword(f) {
	if (!checkEmail(f.email_login)) {
		return false
	}
	securityCode = f.security_code.value;
	if (!checkNumber(securityCode)) {
		alert('Nhập mã an toàn không hợp lệ');
		f.security_code.focus();
		return false;
	}
	return true;	
	
}

function checkContactForm(f) {
	contactPerson = f.contact_person.value;
	if (Trim(contactPerson) == "") {
		alert('Vui lòng nhập vào tên');
		f.contact_person.focus();
		return false;
	}
	address =  f.address.value;
	if (Trim(address) == "") {
		alert('Vui lòng nhập vào địa chỉ');
		f.address.focus();
		return false;
	}
	if (!checkEmail(f.email)) {
		return false
	}
	telephone = f.telephone.value;
	if (Trim(telephone) == "") {
		alert('Vui lòng nhập số điện thoại');
		f.telephone.focus();
		return false;
	}
	contactBody = f.contact_body.value;
	if (Trim(contactBody) == "") {
		alert('Vui lòng nhập vào nội dung liên hệ');
		f.contact_body.focus();
		return false;
	}
	securityCode = f.security_code.value;
	if (!checkNumber(securityCode)) {
		alert('Nhập mã an toàn không hợp lệ');
		f.security_code.focus();
		return false;
	}
	return true;	
}

function checkProductIdEmpty(f) {	
	var len = f.elements.length;
	for (var i = 0; i< len; i++){
		if (f.elements[i].name == 'chk_status[]' && f.elements[i].checked==true) {
			return confirm('Tất cả sản phẩm bạn chọn sẽ bị xóa?');
		}
	}	
	alert('Vui lòng chọn sản phẩm trước khi xóa');	
	return false;
}
function memberStatusAdd () {
	window.location.href='member_add_product.php?m_sel=1';
}

function checkMailIdEmpty(f) {	
	check = f.check_send.value;
	if (check == 1) {
		return true;
	}
	var len = f.elements.length;
	for (var i = 0; i< len; i++){
		if (f.elements[i].name == 'chk_mail[]' && f.elements[i].checked==true) {
			return confirm('Tất cả mail đã chọn sẽ bị xóa?');
		}
	}	
	alert('Vui lòng chọn mail trước khi xóa');	
	return false;
	
}
function checkFormMailDetail(f) {
	bodyStr = f.body_str.value;
	if (Trim(bodyStr) == "") {
		alert('Vui lòng nhập vào nội dung');
		f.body_str.focus();
		return false;
	}
	return true;
}

function checkAdminMess(f) {
	yourMess = f.your_mess.value;
	if (Trim(yourMess) == "") {
		alert('Vui lòng nhập vào trả lời');
		f.your_mess.focus();
		return false;
	}
	return true;

}
function setCheckSend(){
	f.check_send.value = "1";
	f.submit();
}

function zoom(w,h,file) {
	var linkStr = "main_zoom_picture.php?file_name=" + file;
	window.open(linkStr,'ZOOM','width=' + w + ',height=' + h);
}
function zoom1(w,h,file,isAdmin) {
	var linkStr = "../main_zoom_picture.php?file_name=" + file + "&is_admin=1";
	window.open(linkStr,'ZOOM','width=' + w + ',height=' + h);
}

function alphaNumeric(alphane){
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
		else	{
			 return false;
		  }
		}
 	return true;
}

function checkCreateWeb(f) {
	website = f.user_web.value;
	if (Trim(website) == "" ) {
		alert('Vui lòng nhập địa chỉ cần tạo vào ô trống');
		f.user_web.focus();
		return false;
	} else {
		if (!alphaNumeric(website)) {
			alert('Bạn chỉ nhập được ký tự ký tự a-z và 0-9');
			f.user_web.focus();
			return false;
		} else {		
			return true;
		}
	}	
}

function checkTablePrice(f) {
	
	var userFile = f.userfile.value;
	if (userFile != '') {
		arr = userFile .split('.');
		len = arr.length;
		str = arr[len - 1];
		result = false;		
		str = str.toLowerCase();			
		switch (str) {
			case "doc":
				result = true;		
				break;
			case "xls":
				result = true;			
				break;
			case "pdf":
				result = true;			
				break;	
		}
		if (!result) {
			alert('Bạn chỉ upload bảng giá (*.doc,*.xls,*.pdf)');
			return false;
		}
	} else {
		alert('Vui lòng chọn tập tin upload');
		return false;
	}

}



