// JavaScript Document
function validate_password(s)
{
	if (trim(s.oldpw.value)=="")
	{
		alert("Enter Old Password")
		s.oldpw.focus();
		return false;
	}

	if (trim(s.newpw.value)=="")
	{
		alert("Enter New Password")
		s.newpw.focus();
		return false;
	}
	 else
	 {
	 	var s1=s.newpw.value;
		if (s1.length<6)
		{
			alert("Password should have min. '6' characters")
			s.newpw.focus();
			return false
		}
	 }

	if (trim(s.confirmpw.value)=="")
	{
		alert("Enter Confirm Passwrod")
		s.confirmpw.focus();
		return false;

	}
	if (s.newpw.value!=s.confirmpw.value)
	{
		alert("Confirm Passwrod should be same with new password")
		s.confirmpw.focus();
		return false;
	}

}
function validate_finish(s){
	if(trim(s.qc.value)==""){
		alert("Please enter name")
		s.qc.focus()
		return false
	}
	if(trim(s.NIPO.value)==""){
		alert("Please enter NI P.O.")
		s.NIPO.focus()
		return false
	}
}
function product_validate(s1){
	if(trim(s1.part.value)==""){
		alert("please enter the part number")
		s1.part.focus()
		return false
	}
}
function checkEmail(str)
	{
		if((str.indexOf("@")==-1) || (str.indexOf(".")==-1))
		{
			fstr="Please Enter @ or .";
			return false;
		}
		else
		{
		if((str.indexOf("@") == 0) || (str.indexOf(".") == 0))
		{
			fstr="@ or . Cannot Be first";
			return false;
		}
		if((str.indexOf("@") == (str.length-1)) || (str.indexOf(".") == (str.length-1)))
		{
			fstr="@ or . Cannot Be Last";
			return false;
		}

		//if(str.indexOf("@") > str.indexOf("."))
		//{
		//	fstr="@ Should be After .";
		//	return false;
		//}
		if((str.indexOf("@")+1) == str.indexOf("."))
		{
			fstr="@. Is Invalid Email";
			return false;
		}
		}
		var cp=0;					
	
		if(cp==2)
		{
			fstr="@ cannnot be repeated";
			return false;
		}
		return true;
	}

function adm_login_validate(s)
{
	if(s.Admin.value=="")
	{
		alert("Please Enter Your Login ID")
		s.Admin.focus();
		return false
	}
	if(s.pw.value=="")
	{
		alert("Please Enter Your Password ID")
		s.pw.focus();
		return false
	}
}
function LTrim(str)
{
   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;
}

function RTrim(str)
{
   // 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;
}


function trim(str)
{
   return RTrim(LTrim(str));
}
function submit_validate(s)
{
	if(trim(s.Company.value)==""){
			alert("Please enter your company name")
			s.Company.focus()
			return false
	}
	if(trim(s.First_Name.value)==""){
			alert("Please enter your first name")
			s.First_Name.focus()
			return false
	}
	if(trim(s.Last_Name.value)==""){
			alert("Please enter your last name")
			s.Last_Name.focus()
			return false
	}
	if(trim(s.Address.value)==""){
			alert("Please enter address")
			s.Address.focus()
			return false
	}
	if(trim(s.City.value)==""){
			alert("Please enter city")
			s.City.focus()
			return false
	}
	if(trim(s.State.value)==""){
			alert("Please select state")
			s.State.focus()
			return false
	}
	if(trim(s.Zip.value)==""){
			alert("Please enter zip code")
			s.Zip.focus()
			return false
	}
	if(trim(s.Country.value)==""){
			alert("Please enter country")
			s.Country.focus()
			return false
	}
	if(trim(s.Phone.value)==""){
			alert("Please enter phone no.")
			s.Phone.focus()
			return false
	}
	if(trim(s.Email.value)==""){
			alert("Please enter email id")
			s.Email.focus()
			return false
	} else {
		st=s.Email.value;
		if(checkEmail(st)==false)
		{
			alert("Please Enter Correct Support Email")
			s.Email.focus();
			return false
		}
	}
	if(trim(s.Password1.value)==""){
			alert("Please enter password")
			s.Password1.focus()
			return false
	} 
	if((s.Password1.value)!=(s.Password2.value)){
			alert("Password and confirm password are not same")
			s.Password2.value=""
			s.Password2.focus()
			return false
	} 
}
function validate_login(s1){
	if(trim(s1.uid.value)==""){
		alert("Please enter your email id to login")
		s1.uid.focus()
		return false
	}
	if(trim(s1.pwd.value)==""){
		alert("Please enter password")
		s1.pwd.focus()
		return false
	}
}
function validate_pwd(s)
{
	if(trim(s.Email.value)==""){
			alert("Please enter email id")
			s.Email.focus()
			return false
	} else {
		st=s.Email.value;
		if(checkEmail(st)==false)
		{
			alert("Please Enter Correct Support Email")
			s.Email.focus();
			return false
		}
	}
}
function open_window(s)
{
	window.open('vieworder.php?oid='+s,'','width=700,height=500,scrollbars=yes')
}
function open_window1(s)
{
	window.open('sendmail.php?oid='+s,'','width=600,height=300,scrollbars=yes')
}