/*Form validations for Contact us forms */



function redirect(x,localizedError){

var temp=document.forms[2].ProductCategory;
for (m=temp.options.length-1;m>0;m = m-1)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i],group[x][i])
}
temp.options[0].selected=true
}
function go(){
location=temp.options[temp.selectedIndex].value
}
function submitForm(form,localizedError) 
{ 
 var validatestring = ''; 
 
 if(form.FirstName.value == '') 
	{
	 var i = document.getElementById('FirstLabel');
	 validatestring += i.innerHTML  + ' -\n'; 
	 
	}
 if(form.LastName.value == '') 
	{
		i = document.getElementById('LastLabel');
		
		validatestring += i.innerHTML +  ' - \n'; 
		
	}
 if(form.Company.value == '') 
	{
		 i = document.getElementById('CompanyLabel');
		validatestring += i.innerHTML + ' - \n';
		
	}
 if(form.Country.selectedIndex == 0) 
	{
	  i = document.getElementById('CountryLabel');
		validatestring += i.innerHTML + ' - \n';
	
	}
 if(form.Phone.value == '') 
	 {
	 i = document.getElementById('PhoneLabel');
		validatestring += i.innerHTML + ' - \n';
	
	}
 
 if(form.Email.value == '') 
	  {
	  i = document.getElementById('EmailLabel');
		validatestring += i.innerHTML +  ' - \n';
	
	}
	

 if(form.FirstName.value == '' || form.LastName.value == '' || form.Email.value == "" || form.Company.value == '' || form.Phone.value == '' || form.Country.selectedIndex == 0 ) 
 { 
  alert(localizedError + validatestring); 
  return false; 
 } 
 else if (echeck(form.Email.value) == false)
 {
 form.Email.focus();
 return false;
 }
 else if (validatePhone(form.Phone.value) == false)
 {
  form.Phone.focus();
  return false;
 }
 else 
 { 
  
  return true; 
 } 
}
function echeck(str) {
  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)
  if (str.indexOf(at)==-1){
     alert(localizedEmailError);
     return false
  }
  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
     alert(localizedEmailError);
     return false
  }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      alert(localizedEmailError);
      return false
  }
   if (str.indexOf(at,(lat+1))!=-1){
     alert(localizedEmailError);
      return false
   }
   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      alert(localizedEmailError);
      return false
   }
   if (str.indexOf(dot,(lat+2))==-1){
      alert(localizedEmailError);
      return false
   }
  
   if (str.indexOf(" ")!=-1){
      alert(localizedEmailError);
      return false
   }
    return true     
 }
function validatePhone(fld) {
	var error = "";
    var stripped = fld.replace(/[\(\)\.\-\ ]/g, '');    
	
    if (isNaN(parseInt(stripped))) 
 {
	
	alert("Phone number has invalid characters");
        return false;
 }

  return true;
 }


function redirect(x){
	var temp=document.forms[2].ProductCategory;

	if(temp.options.length != 0)
	{
		for (m=temp.options.length-1;m>0;m = m-1)
		temp.options[m]=null;
	}
	
	for (i=0;i<group[x].length;i++){
		temp.options[i]=new Option(group[x][i],group[x][i])
	}
	
	//valid product area selection? if so, show the product category
	if(document.getElementById('productCategoryRow') != null) {
		document.forms[2].ProductArea.selectedIndex !=0 ? document.getElementById('productCategoryRow').style.display = '' : document.getElementById('productCategoryRow').style.display = 'none';	
	}
	
	temp.options[0].selected=true
}

function go(){
location=temp.options[temp.selectedIndex].value
}
