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 IsNumeric(sText)
{

	var ValidChars = "0123456789.";
	
	var IsNumber=true;
	
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
		
	}
	
	return IsNumber;

}
/**/
function checkEmail(str){
	var textValue = str.value;
	var err=''
	if (textValue == ''){
		err += "Địa chỉ E-mail không hợp lệ";
		alert(err);
		str.focus();
		return false
	}
	if (textValue.indexOf('@') <= 0 || textValue.indexOf('@') == textValue.length -1){
		err += "Địa chỉ E-mail không hợp lệ";		
	} else {
		var substr = textValue.substring(textValue.indexOf('@'),textValue.length);
		if (textValue.indexOf('.') <= 0) {
			err += "Địa chỉ E-mail không hợp lệ\n";
		}
	}
	if (err != '') { 
		alert(err); 
		str.focus();
		return false;
	}
	return true;
}

/*kiem tra lien he*/
function checkRegister (f) {
	companyName = f.txthoten.value;
	
	if (Trim(companyName) == "") {
		alert('Vui lòng nhập họ tên');
		f.txthoten.focus();
		return false;
	}
	if (!checkEmail(f.txtemail)) {
		return false
	}
	
	catId = f.txtnoidung.value;
	if (catId == "") {
		alert('Vui lòng nội dung');
		f.txtnoidung.focus();
		return false;
	}
	
	return true;	
}
function SetRowVisible()
{
	var str	= true;
	var objtextDay 		= document.getElementById("cmbheso");
	
	var objOneway		= document.getElementById('chkcanmang');
	if (objOneway != null )
	{
		if (objOneway.checked)
		{
			objtextDay.disabled		= true;
			str	= true;
		}
		else {
			objtextDay.disabled		= false;
			str	= false;
		}
	}
	
	return str;
}
/*kiem tra lien he*/
function checkModule (f) {
	txtlength = f.txtlength.value;
	
	if (Trim(txtlength) == "")
	{
		alert('Chiều dài khổ in là số');
		f.txtlength.focus();
		return false;
	}
	else
	{
		if (!IsNumeric(txtlength)) {
			alert('Chiều dài khổ in là số');
			f.txtlength.focus();
			return false;
		}
	}
	txtwidth = f.txtwidth.value;
	
	if (Trim(txtwidth) == "")
	{
		alert('Chiều rộng khổ in là số');
		f.txtwidth.focus();
		return false;
	}
	else
	{
		if (!IsNumeric(txtwidth)) {
			alert('Chiều rộng khổ in là số');
			f.txtwidth.focus();
			return false;
		}
	}
	txtamount = f.txtamount.value;
	
	if (Trim(txtamount) == "")
	{
		alert('Nhập số lượng sản phẩm cần in');
		f.txtamount.focus();
		return false;
	}
	else
	{
		if (!IsNumeric(txtamount)) {
			alert('Số lượng sản phẩm phải là số');
			f.txtamount.focus();
			return false;
		}
	}
	cmbpaper = f.cmbpaper.value;
	
	if (Trim(cmbpaper) == "0")
	{
		alert('Chọn loại giấy in');
		f.cmbpaper.focus();
		return false;
	}
	
	txtdinhluong = f.txtdinhluong.value;
	
	if (Trim(txtdinhluong) == "")
	{
		alert('Nhập định lượng giấy');
		f.txtdinhluong.focus();
		return false;
	}
	else
	{
		if (!IsNumeric(txtdinhluong)) {
			alert('Giá trị định lượng phải là số');
			f.txtdinhluong.focus();
			return false;
		}
	}
	
	cmbheso = f.cmbheso.value;
	str = SetRowVisible();
	if (str == false)
	{
		if (Trim(cmbheso) == "0")
		{
			alert('Chọn loại cán');
			f.cmbheso.focus();
			return false;
		}
	}
	txtsomau = f.txtsomau.value;
	
	if (Trim(txtsomau) == "")
	{
		alert('Nhập số màu cần in');
		f.txtsomau.focus();
		return false;
	}
	else
	{
		if (!IsNumeric(txtsomau)) {
			alert('Số màu phải là số');
			f.txtsomau.focus();
			return false;
		}
	}
	return true;	
}