// JavaScript Document
var win = null;
function newWindow(mypage,myname,w,h,features) {
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//form validate for distributor
function validateDistributor(form)
{
   if(IsEmpty(form.name)) 
   { 
      alert('Please enter your Full Name.') 
      form.name.focus(); 
      return false; 
   } 
   if(IsEmpty(form.companyName)) 
   { 
      alert('Please enter your Company Name.') 
      form.companyName.focus(); 
      return false; 
   } 
   if(IsEmpty(form.title)) 
   { 
      alert('Please enter your Title.') 
      form.title.focus(); 
      return false; 
   } 
   if(IsEmpty(form.address)) 
   { 
      alert('Please enter your address') 
      form.address.focus(); 
      return false; 
   } 
   if(IsEmpty(form.city)) 
   { 
      alert('Please enter your City') 
      form.city.focus(); 
      return false; 
   } 
   if (!IsNumeric(form.zip.value)) 
   { 
      alert('Please enter a 5 digit Zip Code') 
      form.zip.focus(); 
      return false; 
   }
   if(IsEmpty(form.zip)) 
   { 
      alert('Please enter a 5 digit Zip Code') 
      form.zip.focus(); 
      return false; 
   }
   if(IsEmpty(form.country)) 
   { 
      alert('Please enter your Country') 
      form.country.focus(); 
      return false; 
   }
   if(IsEmpty(form.phone))
   {
		alert('Please enter a 10 digit Phone Number.')
		form.phone.focus();
		return false;
   }
    if(IsEmpty(form.fax))
   {
		alert('Please enter a 10 digit Fax Number.')
		form.fax.focus();
		return false;
   }
   if(!checkEmail(form))
   {
	   alert("Please enter a valid email address.")
	   form.email.focus();
	   return false;
   }
   if(NoneWithCheck(form.employees))
   {
	   alert("Please tell us if you have employees.")
	   return false;
   }
   if(IsEmpty(form.comments))
   {
		alert('Please Tell Us Why you want to be a Distributor.')
		form.comments.focus();
		return false;
   }
return true;   
}


function checkEmail(myForm)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value))
	{
		//good email address
		return true;
	}

//return false if bad email
return false;
}

function IsEmpty(aTextField)
{
   if ((aTextField.value.length==0) ||
   (aTextField.value==null))
   {
      return true;
   }
   else { return false; }
}	

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 NoneWithCheck(ss) {
for(var i = 0; i < ss.length; i++) {
	if(ss[i].checked) { return false; }
	}
return true;
}

function WithoutCheck(ss) {
if(ss.checked) { return false; }
return true;
}
