function self(st)
{
	
	window.document.forms[0].target = "_self";

	window.document.forms[0].action = st;

	window.document.forms[0].submit();

}
function selfsub(st)
{
	
	window.document.forms[1].target = "_self";

	window.document.forms[1].action = st;

	window.document.forms[1].submit();

}
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 += "Invalid E-mail ID";
		alert(err);
		str.focus();
		return false
	}
	if (textValue.indexOf('@') <= 0 || textValue.indexOf('@') == textValue.length -1){
		err += "Invalid E-mail ID ";		
	} else {
		var substr = textValue.substring(textValue.indexOf('@'),textValue.length);
		if (textValue.indexOf('.') <= 0) {
			err += "Invalid E-mail ID \n";
		}
	}
	if (err != '') { 
		alert(err); 
		str.focus();
		return false;
	}
	return true;
}

/**/
function checkRegister (f) {
	companyName = f.txthoten.value;
	
	if (Trim(companyName) == "") {
		alert('Please, put in your name');
		f.txthoten.focus();
		return false;
	}
	if (!checkEmail(f.txtemail)) {
		return false
	}
	
	/*telephone = f.txtdt.value;
	if (Trim(telephone) == "") {
		alert('Please, put in your phone');
		f.txtdt.focus();
		return false;
	}*/
	/*contactPerson = f.txtchude.value;
	if (Trim(contactPerson) == "") {
		alert('Please, put in your contact subject');
		f.txtchude.focus();
		return false;
	}*/
	catId = f.txtnoidung.value;
	if (catId == "") {
		alert('Please, put in your content');
		f.txtnoidung.focus();
		return false;
	}
	
	return true;	
}
/**/
function checkRegisterNew (f) {
	companyName = f.txthoten.value;
	
	if (Trim(companyName) == "") {
		alert('Please, put in your name');
		f.txthoten.focus();
		return false;
	}
	if (!checkEmail(f.txtemail)) {
		return false
	}
	address = f.txtdiachi.value;
	if (Trim(address) == "") {
		alert('Please, put in your addresss');
		f.txtdiachi.focus();
		return false;
	}
	/*telephone = f.txtdt.value;
	if (Trim(telephone) == "") {
		alert('Please, put in your phone');
		f.txtdt.focus();
		return false;
	}*/
	/*contactPerson = f.txtchude.value;
	if (Trim(contactPerson) == "") {
		alert('Please, put in your contact subject');
		f.txtchude.focus();
		return false;
	}*/
	catId = f.txtdienthoai.value;
	if (catId == "") {
		alert('Please, put in your phone');
		f.txtdienthoai.focus();
		return false;
	}
	txtpass = f.txtpass.value;
	if (txtpass == "") {
		alert('Please, create passwrod');
		f.txtpass.focus();
		return false;
	}
	txtcofirm = f.txtconfirm.value;
	if (txtcofirm == "") {
		alert('Please, confirm passwrod');
		f.txtconfirm.focus();
		return false;
	}	
	
	if (txtcofirm != txtpass) {
		alert('Please, create passwrod');
		f.txtconfirm.value = "";
		f.txtconfirm.focus();
		return false;
	}	
	return true;	
}
/*kiem tra thong tin ho tro*/
function checkContact(f)
{
	txthoten = f.txthoten.value;
	if (Trim(txthoten) == "") {
		alert('Please, put in your full name');
		f.txthoten.focus();
		return false;
	}
	if (!checkEmail(f.txtemail)) {
		return false
	}
	catId = f.txtnoidung.value;
	if (catId == "") {
		alert('Please, put in your message');
		f.txtnoidung.focus();
		return false;
	}
	
	return true;	
}
// kiem tra thong tin khi tim kiem san pham
function checkSearch(f)
{
	companyName = f.cmbgroup.value;
	if (Trim(companyName) == "0") {
		alert('Please, select product group name');
		f.cmbgroup.focus();
		return false;
	}
	catId = f.txtsearch.value;
	if (catId == "") {
		alert('Please, put in keyword for search');
		f.txtsearch.focus();
		return false;
	}
	
	return true;	
}
// // kiem tra thong tin dang nhap thanh vien
function checkLogin(f)
{
	//companyName = f.txtusername.value;
	if (!checkEmail(f.txtusername)) {
		return false
	}
	catId = f.txtpass.value;
	if (catId == "") {
		alert('Please, put in your password');
		f.txtpass.focus();
		return false;
	}
	
	return true;
}
// kiem tra thong tin khach hang dang ky dat hang(khach hang cu)
function checkRegisterCart(f)
{
	if (!checkEmail(f.txtemail)) {
		return false
	}
	
	catId = f.txtpass.value;
	if (catId == "") {
		alert('Please, put in your password');
		f.txtpass.focus();
		return false;
	}
	
	return true;	
}
/* kiem tra gui email de nhan lai mat khau*/
function checkForgotPass(f)
{
	if (!checkEmail(f.txtemail)) {
	return false
	}
	return true;
}
/*KIEM tra mua hang*/
function checkOldCustomer (f) {
	//date_delivery = f.txtngaygh.value;
	day			= f.day.value;
	month		= f.month.value;
	year		= f.year.value;
	var dt = new Date() ;
	
  	var dt_year = dt.getFullYear() ;

	var dt_month = dt.getMonth() + 1 ;

	var dt_day = dt.getDate() ;

	
	if (day <= dt_day && month < dt_month)
	{
		alert("Delivery date must after current date")
		return false
	}
	if 	( day > dt_day && month < dt_month )	
	{
		alert("Delivery date must after current date")
		return false
	}
	if 	( day <= dt_day && month == dt_month )	
	{
		alert("Delivery date must after current date")
		return false
	}
	/* kiem tra neu dia chi giao hang khac thong tin tren*/
	var alen = f.elements.length;
	var isChecked = true;
		for (var i = 0 ; i < alen ;  i++)
		{
			if(f.elements[i].type == "checkbox")
			{
				if(f.elements[i].name == "rdoaddcus")
				{
					if (f.elements[i].checked == true)
					{
						
						name_receiver = f.txtreceiver.value;
						if (Trim(name_receiver) == "") {
						alert('Please, Put in receiver name');
						f.txtreceiver.focus();
						return false;
						}
						address_receiver = f.txtdeaddress.value;
						if (Trim(address_receiver) == "") {
							alert('Please, Put in delivery address');
							f.txtdeaddress.focus();
							return false;
						}
						phone_deceiver = f.txtdephone.value;
						
						if (Trim(phone_deceiver) == "") {
							alert('Please, Put in phone');
							f.txtdephone.focus();
							return false;
						}

					}
				}
			}
		}
	return true;	
}

/*kiem tra lien he*/
function checkModule (f) {
	txtlength = f.txtlength.value;
	
	if (Trim(txtlength) == "")
	{
		alert('Put in size of length');
		f.txtlength.focus();
		return false;
	}
	else
	{
		if (!IsNumeric(txtlength)) {
			alert('Value of size is number');
			f.txtlength.focus();
			return false;
		}
	}
	txtwidth = f.txtwidth.value;
	
	if (Trim(txtwidth) == "")
	{
		alert('Put in size of width');
		f.txtwidth.focus();
		return false;
	}
	else
	{
		if (!IsNumeric(txtwidth)) {
			alert('Value of size is number');
			f.txtwidth.focus();
			return false;
		}
	}
	txtamount = f.txtamount.value;
	
	if (Trim(txtamount) == "")
	{
		alert('Put in amout of product to print');
		f.txtamount.focus();
		return false;
	}
	else
	{
		if (!IsNumeric(txtamount)) {
			alert('Value of print is number');
			f.txtamount.focus();
			return false;
		}
	}
	cmbpaper = f.cmbpaper.value;
	
	if (Trim(cmbpaper) == "0")
	{
		alert('Select paper type');
		f.cmbpaper.focus();
		return false;
	}
	
	txtdinhluong = f.txtdinhluong.value;
	
	if (Trim(txtdinhluong) == "")
	{
		alert('Put in weight of paper');
		f.txtdinhluong.focus();
		return false;
	}
	else
	{
		if (!IsNumeric(txtdinhluong)) {
			alert('Value of weight is number');
			f.txtdinhluong.focus();
			return false;
		}
	}
	
	cmbheso = f.cmbheso.value;
	str = SetRowVisible();
	if (str == false)
	{
		if (Trim(cmbheso) == "0")
		{
			alert('Select laminate type');
			f.cmbheso.focus();
			return false;
		}
	}
	txtsomau = f.txtsomau.value;
	
	if (Trim(txtsomau) == "")
	{
		alert('Put in color amount to print');
		f.txtsomau.focus();
		return false;
	}
	else
	{
		if (!IsNumeric(txtsomau)) {
			alert('Value of color is number');
			f.txtsomau.focus();
			return false;
		}
	}
	return true;	
}
