// JavaScript Document

function changePage(link){
  window.location = link;
}

function validateForm(obj, section){
  var re2 = /^[(\w)|\@|.|-]*$/; 	
  
  if (section == 'contact')
  {

    if (!obj.name.value)
    {  
      alert("Please complete the mandatory field 'Name'.");
      return false;
    }  

    var emailLen = obj.email.value.length;  	  
    if ((!re2.test(obj.email.value)) || (emailLen < 5))
    {  
      alert("Please complete the mandatory field 'Email' and must contain valid email characters.");
      return false;
    }  
  }

  if (section == 'costimator')
  {

    if (!obj.name.value)
    {  
      alert("Please complete the mandatory field 'Name'.");
      return false;
    }  
    if (!obj.street.value)
    {  
      alert("Please complete the mandatory field 'Street'.");
      return false;
    }	
    if (!obj.city.value)
    {  
      alert("Please complete the mandatory field 'City'.");
      return false;
    }	
    if (!obj.province.value)
    {  
      alert("Please complete the mandatory field 'Province'.");
      return false;
    }	
    if (!obj.country.value)
    {  
      alert("Please complete the mandatory field 'Country'.");
      return false;
    }	
    if (!obj.zip.value)
    {  
      alert("Please complete the mandatory field 'Zip'.");
      return false;
    }	
    if (!obj.telephone.value)
    {  
      alert("Please complete the mandatory field 'Telephone'.");
      return false;
    }	
    var emailLen = obj.email.value.length;  	  
    if ((!re2.test(obj.email.value)) || (emailLen < 5))
    {  
      alert("Please complete the mandatory field 'Email' and must contain valid email characters.");
      return false;
    }  
  }


  if ((section == 'join')||(section == 'milf')||(section == 'contest')||(section == 'comment'))
  {
     if (obj.verif_answer.value != obj.verif_box.value)
    {  
      alert("You entered the wrong verification image number.");
      return false;
    }	
  }
  
}

function validateEmail(obj){
  var aboutMeLen = obj.value.length;
  if ((aboutMeLen<100) || (275 < aboutMeLen)){
	  
    alert("User description must be 100-275 characters.  You entered "+ aboutMeLen);
    obj.select();
    obj.focus();
    return false;
  }
}


function validateProfile(obj, section){
//  var delMode = obj.mode.checked;
//  alert("hi"+ delMode);
  var justNumbers = /^[0-9]*$/;
  var rel = /^[(\w)|(\s)|.|\,|-]*$/; 
  var emailLen = obj.email.value.length;
  
  var re2 = /^[(\w)|\@|.|-]*$/;  
  if ((!re2.test(obj.email.value)) || (emailLen < 5))
  {  
    alert("Please complete the mandatory field 'Email' is mandatory and must contain valid email characters.");
    return false;
  }  
  if (!obj.firstName.value)
  {  
    alert("Please complete the mandatory field 'First'.");
    return false;
  }   
  if (!obj.lastName.value)
  {  
    alert("Please complete the mandatory field 'Last'.");
    return false;
  }   
  if (!obj.companyName.value)
  {  
    alert("Please complete the mandatory field 'Company name'.");
    return false;
  }   
  if (!obj.title.value)
  {  
    alert("Please complete the mandatory field 'Title'.");
    return false;
  }   
  if (!obj.address.value)
  {  
    alert("Please complete the mandatory field 'Address'.");
    return false;
  } 
  if (!obj.city.value)
  {  
    alert("Please complete the mandatory field 'City'.");
    return false;
  } 
  if (!obj.province.value)
  {  
    alert("Please complete the mandatory field 'Province/State'.");
    return false;
  } 
  if (!obj.country.value)
  {  
    alert("Please complete the mandatory field 'Country'.");
    return false;
  }   
  if (!obj.offNum1.value && !obj.offNum2.value && !obj.offNum3.value)
  {  
    alert("Please complete the mandatory field 'Office'.");
    return false;
  }   
  
  if (section == 'Operator')
  {
	  
  if (document.getElementById("no1on1").checked)
  {  
    obj.who.value = "";    
    obj.why.value = "";    
  } 
  if (document.getElementById("yes1on1").checked)
  {  
    if (!obj.who.value || !obj.why.value )  
	{
      alert("Who and why must not be empty.");
	  return false;  
	}
  } 
  }

  if (section == 'Supplier')
  {
    if ((!obj.invoice.checked)&&(!obj.booth.checked)&&(!obj.additional.checked))
	{  
      alert("Payment option must be selected.");
      return false;
    }     
  }
  
  if (obj.password1 && obj.password2){
    if (obj.password1.value != obj.password2.value)
    {  
      alert("Both passwords must be the same.");
      return false;
    }   
  }
/*   
  if ((obj.booth)||(obj.additional))
  { 
    if ((obj.booth.checked)||(obj.additional.checked))
      window.open("./Credit Card Approval form.pdf", "PDF", "status=no,toolbar=no,menubar= no");
  }
*/


/*  var vidDescriptionLen = obj.message.value.length;
  if (((vidDescriptionLen<100) || (400 < vidDescriptionLen))&&(delMode!=true)){
    alert("Video description must be 100-400 characters.  You entered "+ vidDescriptionLen);
    return false;
  }
  var tagsLen = obj.tags.value.length;  
  if (((tagsLen < 4) || (100 < tagsLen))&&(delMode!=true)){
    alert("Tags must be 4-100 characters.  You entered "+ tagsLen);
    return false;
  } */
}

function validatePhoto(obj){

  var fileName = document.photoForm.userfile.value.toLowerCase();
//  alert("hi"+fileName);  
  if((fileName.lastIndexOf(".jpg")!="-1")||(fileName.lastIndexOf(".png")!="-1")||(fileName.lastIndexOf(".jpeg")!="-1")) {
  } else
  {
      alert("Please upload only .jpg, .png, .jpeg image file");
      return false;
  } 
}

function validateRegister(obj)
{
  var re = /^[(\w)|(\s)|.|\,|-]*$/;
  var re1 = /^[(\w)]*$/;  
  if (!re1.test(obj.username.value))
  { 
    alert("Only numbers and letters are allowed for user name.");
    return false;
  }
  var re2 = /^[(\w)|\@|.|-]*$/;  
  if ((!re2.test(obj.email.value))||(!re2.test(obj.email2.value)))
  {  
    alert("Invalid characters in email.");
    return false;
  }  

  if (!re.test(obj.fname.value))
  { 
    alert("Only numbers and letters are allowed for first name.");
    return false;
  }
  if (!re.test(obj.lname.value))
  { 
    alert("Only numbers and letters are allowed for last name.");
    return false;
  }
  if (!re.test(obj.address.value))
  { 
    alert("Only numbers and letters are allowed for street address.");
    return false;
  }  
/*  if (!re.test(obj.postalcode.value))
  { 
    alert("Only numbers and letters are allowed for postal code.");
    return false;
  }    */  
  if ((!re.test(obj.password.value))||(!re.test(obj.password2.value)))
  {  
    alert("Only numbers and letters are allowed for password.");
    return false;
  }
  

}

function ShowToolTip(id)
{
	var obj = document.getElementById(id);
	obj.className = 'tooltip_wrapper';
    return false;
}

function HideToolTip(id)
{
	var obj = document.getElementById(id);
    obj.className = 'tooltip_wrapper_hidden';
    return false;
}
