function checknumber(strValue)
{
	var x=document.getElementById(strValue).value;
	if(x == '') return true;
	
	var anum=/(^\d+$)|(^\d+\.\d+$)/;
	if (anum.test(x))
	{
		return true;
	}
	return false;
}
function checkConfirm(strValue1,strValue2)
{
	var obj1 = document.getElementById(strValue1);
	var obj2 = document.getElementById(strValue2);
	if(obj1 ==null || obj2 == null)
	{
		return false;
	}
	if(obj1.value == obj2.value)
	{
		return true;
	}
	return false;
}
function checkIsRequirement(strValue)
{
	var obj = document.getElementById(strValue);	
	if(obj != null && obj.value.length > 0)	
		return true;
	obj.focus();
	return false;
}
//function checkMail(obj)
function checkMail(strValue)
{
	var obj = document.getElementById(strValue);
	if(!obj)	return false;
	
	var x =obj.value;
	if(x == '') return true;
	
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) 		
		return true;
	else
	{
		obj.focus();
		return false;
	}
}

function SaveProduct()
{	
	if(ValidationBeforSubmit())
	{	
		var objAct = document.products["hiddencode"];	
		if(objAct)	
		{
		objAct.value = "save";				
		this.products.submit();
		}
	}
	else
	{
		return false;
	}
	return false;
}
function CancelProduct()
{
	var objAct = document.products["hiddencode"];	
	if(obcAct)	
	{
	objAct.value = "cancel";		
	this.products.submit();
	}
}

function ValidationBeforSubmit()
{
	if(!checkIsRequirement("name"))
	{
		alert("Product name is requirement field!");
		return false;
	}
	return true;
}
function validationBeforeSave()
{
	if(!checkIsRequirement("username"))
	{
		alert("User name is requirement field!");
		return false;
	}
	if(!checkIsRequirement("password"))
	{
		alert("Password is requirement field!");
		return false;
	}
	if(!checkIsRequirement("confirmpassword"))
	{
		alert("Confirm password is requirement field!");
		return false;
	}
	if(!checkConfirm("confirmpassword","password" ))
	{
		alert("Confirm password is invalid!");
		return false;
	}
	
	if(!checkIsRequirement("companyname"))
	{
		alert("Company name is requirement field!");
		return false;
	}
	if(!checkIsRequirement("contactperson"))
	{
		alert("Contact person is requirement field!");
		return false;
	}

	if(!checkIsRequirement("address"))
	{
		alert("Company address is requirement field!");
		return false;
	}
	if(!checkIsRequirement("phone"))
	{
		alert("Phone is requirement field!");
		return false;
	}

	if(!checknumber("ct_cellphone"))
	{
		alert("Cellphone must be a number!");
		return false;
	}

	if(!checknumber("fax"))
	{
		alert("Fax must be a number!");
		return false;
	}

	if(!checkIsRequirement("email"))
	{
		alert("Company email is requirement field!");
		return false;
	}
	if(!checkMail("email"))
	{
		alert("Company email is invalid!");
		return false;
	}
	if(!checkMail("ct_email"))
	{
		alert("Contact email is invalid!");
		return false;
	}
	if(!checkIsRequirement("location"))
	{
		alert("Location person is requirement field!");
		return false;
	}
	if(!checknumber("establish_year"))
	{
		alert("Year must be a number!");
		return false;
	}
	if(!checkIsRequirement("txtCaptcha"))
	{
		alert("Captcha is requirement field!");
		return false;
	}
	return true;
}

function cancel_user()
{
	var object = document.getElementById("code");
	if(object)
	{
		object.value = "cancel";	
		document.formSignup.submit();
	}
	else
		return false;
	return true;
}

//contact us
function validateContactUs()
{
	if(!checkIsRequirement("CompanyName"))
	{
		alert("Company Name is requirement field!");
		return false;
	}
	if(!checkIsRequirement("Address"))
	{
		alert("Address is requirement field!");
		return false;
	}
	if(!checkIsRequirement("Tel"))
	{
		alert("Tel is requirement field!");
		return false;
	}
			
	if(!checkIsRequirement("ContactPerson"))
	{
		alert("Contact person is requirement field!");
		return false;
	}

	if(!checkIsRequirement("PerEmail"))
	{
		alert("Email is requirement field!");
		return false;
	}
	if(!checkMail("PerEmail"))
	{
		alert("Email is invalid!");
		return false;
	}
	
	if(!checkIsRequirement("PerPhone"))
	{
		alert("Cellphone is requirement field!");
		return false;
	}

	if(!checknumber("PerPhone"))
	{
		alert("Cellphone must be a number!");
		return false;
	}
	
	if(!checkIsRequirement("postion"))
	{
		alert("Postion person is requirement field!");
		return false;
	}
	
	if(!checkIsRequirement("content"))
	{
		alert("Content is requirement field!");
		return false;
	}
	
	if(!checkIsRequirement("txtCaptcha"))
	{
		alert("Captcha is requirement field!");
		return false;
	}
	return true;
}

function LimitChar(type) {
	if(type==1) {
		var frm = document.form1;
		var field = frm.Enquiry;
		var mlength=field.getAttribute? parseInt(field.getAttribute("maxlength")):"";
		if(field.value.length > mlength) {
			document.getElementById("check_objective").innerHTML=0;
			alert("You must input less than"+' '+mlength+' '+" characters");
			ismaxlength(field);
			return;			
		} 
		document.getElementById("check_objective").innerHTML=mlength - field.value.length;
	} 
}

function isNumberKey(evt)
{
	var charCode = (evt.which) ? evt.which : evt.keyCode
	if(charCode==37||charCode==39||charCode==46)return true;
	if (charCode > 31 && (charCode < 48 || charCode > 57))
	return false;
	
	return true;
}

function onchangeNational()
	{
		var objNat = document.getElementById("national_id");
		var objNatVN = document.getElementById("location_id").style;
		//var objNatUS = document.getElementById("LocationUS").style;
		var objNatOt = document.getElementById("LocationOther").style;
		if(objNat.value=='128')
		{
			//objNatUS.display = "none";
			objNatVN.display = "";
			objNatOt.display ="none";
			document.getElementById("LocationOther").value = "";
		}
		else
		{
			/*
			if(objNat.value=='123')
			{
				objNatUS.display = "";
				objNatVN.display = "none";
				objNatOt.display ="none";
				document.getElementById("LocationOther").value = "";
			}
			else
			{
			*/
				//objNatUS.display = "none";
				objNatVN.display = "none";
				objNatOt.display ="";
			//}
		}
		
}