function checkSignature(){
	var form = document.emailMaleMember;
	var error ="";
  	if (form.agree.checked == false){ error +=" Please check box that you agree \n"; }
	 if (form.signature.value == ''){ error +=" Please enter Electronic signature\n"; }
	if (form.agree.checked  && form.signature.value != "" && error == ""){
		form.Email.disabled = false;
	} else {alert(error);}
	
}

function showSignature(){
	var form = document.emailForm;	
	var found=false;
	var whichEl = document.getElementById('signature');

	for (i=0; i<womanIDs.length; i++){
		if (womanIDs[i] ==form.women.value){
		    whichEl.style.display = "" ;
		   found=true;
		}
	}
	if (!found){
		  whichEl.style.display = "none";
	}
}

function validateMensProfile(){
	var form = document.mensProfile;
  var error = "";

 if (form.DOBday.value =="Day"){ error +=" Please enter Day of birth \n"; }
 if (form.DOBmonth.value =="Month"){ error +=" Please enter Month of birth \n"; }
 if (form.DOByear.value =="Year"){ error +=" Please enter Year of birth \n"; }
 if (form.DOBday.value !="Day" && form.DOBmonth.value !="Month" && form.DOByear.value !="Year"){
	dobError = isValidDate(form.DOBmonth.value+"/"+form.DOBday.value+"/"+form.DOByear.value);
	if (dobError!=""){	 error += "-- Date of Birth Errors: \n "+dobError;   }
 }
 if (form.feet.value =="Feet"){ error +=" Please enter Feet \n"; }
 if (form.inches.value =="Inches"){ error +=" Please enter Inches \n"; }
 if (form.mWeight.value =="" || form.mWeight.value==0 ){ error +=" Please enter Weight in lbs \n"; }


 if(typeof(form.a1)!="undefined"){ 
 
 if (radio_button_checker(form.a1) ==false){ error +=" Please answer Question 1\n"; }
 if (radio_button_checker(form.a2) ==false){ error +=" Please enter Question 2\n"; }
 if (radio_button_checker(form.a3) ==false){ error +=" Please enter Question 3\n"; }
 if (radio_button_checker(form.a4) ==false){ error +=" Please enter Question 4\n"; }
 if (radio_button_checker(form.a5) ==false){ error +=" Please enter Question 5\n"; }
 if (radio_button_checker(form.a6) ==false){ error +=" Please enter Question 6\n"; }
 if (radio_button_checker(form.a7) ==false){ error +=" Please enter Question 7\n"; }
 if (radio_button_checker(form.a9) ==false){ error +=" Please enter Question 9\n"; }
 

 if (form.a1[1].checked && form.IMBRA_restraining.value==''){ error +=" Please enter Detailed Statement of Explanation to Question 1\n"; }
 if (form.a2[1].checked && form.IMBRA_convictions.value==''){ error +=" Please enter Detailed Statement of Explanation to Question 2\n"; }
 if (form.a3[1].checked && form.IMBRA_prostitution.value==''){ error +=" Please enter Detailed Statement of Explanation to Question 3\n"; }
 if (form.a4[1].checked && form.IMBRA_alcohol.value==''){ error +=" Please enter Detailed Statement of Explanation to Question 4\n"; }
 if (form.a5[1].checked && form.IMBRA_marriage.value==''){ error +=" Please enter Detailed Statement of Explanation to Question 5\n"; }
 if (form.a6[1].checked && form.IMBRA_sponshorship.value==''){ error +=" Please enter Detailed Statement of Explanation to Question 6\n"; }
 if (form.a7[1].checked && form.IMBRA_children.value==''){ error +=" Please enter Detailed Statement of Explanation to Question 7\n"; }
 if (form.a9[1].checked && form.IMBRA_offender.value==''){ error +=" Please enter Detailed Statement of Explanation to Question 9\n"; }
 
 if ( form.IMBRA_countries.value==''){ error +=" Please enter Detailed Statement of Explanation to Question 8\n"; }
  if (form.signature.value ==""  ){ error +=" Please enter Electronic Signature \n"; }
 }
if (error!=""){alert (error); return false;}

	return true;
}


function validateEmailSubscriptionForm(form){
	var error = "";

	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (form.registerName.value ==""){ error +=" Please enter Full Name \n"; }
	if (filter.test(form.registerEmail.value) == false){
		error += "Please enter valid email address";
	}
	if (error!=""){alert (error); return false;}
	return true;
	
}

function validateLoginForm(){
	
	var form = document.loginForm;
	var error = "";
	if (form.Uname.value ==""){ error +=" Please enter User Name \n"; }
	if (form.Pword.value ==""){ error +=" Please enter Password \n"; }	
	if (form.userType.value ==0){ error +=" Please select User Type \n"; }		
	
	if (error!=""){alert (error); return false;}
	if (form.userType.value ==1){ form.action="/gentlemanarea/login.php";   }
	if (form.userType.value ==2){ form.action="/gentlemen/memberArea/mainMenu.cfm";  }
	form.submit();
	
}

/* =========================------------- IMAGES MANIPULATION -----------------===============================*/
function Check_File_Field(form){
 numImages= document.getElementById('numImages');
  var error = ""; 
 for (i=1; i<= eval(numImages.value); i++){	 
          var TheValue = eval("form.file"+i+".value");
		 //  alert(TheValue);
		  var slashPos= TheValue.lastIndexOf("\\");
		  if (slashPos==0){
			  slashPos= TheValue.lastIndexOf("/");
		  }
		  var fileName = TheValue.substr(slashPos+1,TheValue.length-slashPos); 
		  
          var FileType = TheValue.substr(TheValue.length-3, 3); 
		  if (TheValue!=""){
            if ( FileType.toUpperCase() != "GIF" && FileType.toUpperCase() != "JPG" && FileType.toUpperCase() != "PNG") {				
                  error +=fileName+ " is not a valid Image file. Please upload image with extensions (.jpg,  .gif, .png) \n";
			}
			 if ( FileType == "GIF" || FileType == "JPG" || FileType == "PNG") {
                  error +=fileName+ " is not a valid Image file. Image Extensions (jpg,  gif, png) MUST BE in lower case\n";
            } 
		  }
		  		  
		  if (alphanumeric(fileName.substr(0,fileName.length-4)) == false){
			  error +=fileName+ " is not a valid Image file. Please use only LATIN letters and/or numbers for file name \n";			  			 
		  }
		  
     }// end for
	 
	return error;
}


// check if any radio buttons are checked
function radio_button_checker(radiobuttons)
{  for (counter = 0; counter < radiobuttons.length; counter++){
         if (radiobuttons[counter].checked) { return true;}
    }
   return (false);
}


function validateEditForm(formType){
	var form = document.womensApplicationForm;
	var error = "";
	
	if (radio_button_checker(form.education) ==false){ error +=" Please enter Education\n"; }
    
	if (form.wfirstname.value ==""){ error +=" Please enter First Name \n"; }
	if (form.wlastname.value ==""){ error +=" Please enter Last Name \n"; }
	if (form.email.value ==""){ error +=" Please enter Email \n"; }	
	if (formType == "add"){
	  if (form.DOBday.value =="Day"){ error +=" Please enter Day of birth \n"; }
	  if (form.DOBmonth.value =="Month"){ error +=" Please enter Month of birth \n"; }
	  if (form.DOByear.value =="Year"){ error +=" Please enter Year of birth \n"; }
	}else if (formType== "edit") {
		 if (form.wdob.value ==""){ error +=" Please enter Date of birth \n"; }
	}
	if (form.wheight.value ==""){ error +=" Please enter Height \n"; }
	if (form.wweight.value ==""){ error +=" Please enter Weight\n"; }

	error +=Check_File_Field(form);
    if (error!=""){alert (error); return false;}
	return true;
}

function validateWomenApplication(){
	
	 var form = document.womensApplicationForm;
	 var error = "";
	
	// -------------  disclaimer validation ----------------------
	if (form.firstName.value ==""){ error +=" Please enter First Name \n"; }
	if (form.lastName.value ==""){ error +=" Please enter Last Name \n"; }
	if (form.email.value ==""){ error +=" Please enter Email \n"; }
	if (form.location.value ==""){ error +=" Please enter Location \n"; }
	if (form.DOBday.value =="Day"){ error +=" Please enter Day of birth \n"; }
	if (form.DOBmonth.value =="Month"){ error +=" Please enter Month of birth \n"; }
	if (form.DOByear.value =="Year"){ error +=" Please enter Year of birth \n"; }
	if (form.age.value ==""){ error +=" Please enter Age \n"; }
	if (form.address.value ==""){ error +=" Please enter Address \n"; }
	if (form.phone.value ==""){ error +=" Please enter Phone\n"; }
	if (form.height.value ==""){ error +=" Please enter Height \n"; }
	if (form.weight.value ==""){ error +=" Please enter Weight\n"; }

	 error +=Check_File_Field(form);
	 if (form.disclaimer.checked == false){
		   error +=" Please Read our Agreement and check that you agree \n"; 
	 }

    if (error!=""){alert (error); return false;}
	return true;
}

function addImage(theInput)         	     
{        numImages= document.getElementById('numImages');
         id =  parseInt(numImages.value) + parseInt(1);   
		 numImages.value = id;		     		 
         var row   = document.createElement('tr');		
         var cell  = document.createElement('td');  		     
         var input = document.createElement('input');
             input.size = 30;
			 input.maxlength="255"
             input.name = 'file'+id;  
			 input.type = "file";
			 input.onclick = "Check_File_Field()";
             cell.appendChild(input);
             row.appendChild(cell);			                  	          
         theInput.parentNode.parentNode.parentNode.insertBefore(row,theInput.nextSibling);				
		 return false;
}

function addImagePrivate(theInput)         	     
{        numImages= document.getElementById('numImages');
         id =  parseInt(numImages.value) + parseInt(1);   
		 numImages.value = id;		     		 
         var row   = document.createElement('tr');		
         var cell  = document.createElement('td');  		     
         var input = document.createElement('input');
             input.size = 30;
			 input.maxlength="255"
             input.name = 'file'+id;  
			 input.type = "file";
			 input.onclick = "Check_File_Field()";
             cell.appendChild(input); 		
		var text1 = document.createTextNode("thumb ?  ");
		      cell.appendChild(text1);
        var input = document.createElement('input');
             input.name = "thumb";  
			 input.type = "radio";
             input.value = "NEW"+id;			 
             cell.appendChild(input);
		var text2 = document.createTextNode("video ?  ");
		     cell.appendChild(text2);	 
         var input = document.createElement('input');
             input.name = "video";  
			 input.type = "radio";
             input.value = "NEW"+id;			 
             cell.appendChild(input);
			 
             row.appendChild(cell);			                  	          
         theInput.parentNode.parentNode.parentNode.insertBefore(row,theInput.nextSibling);				
		 return false;
}
/* ----------------------------- VALIDATOIN ----------------------*/

function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}

function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}

var daysInMonth = new Array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);



//to check for leap year
function leapYear(year) {
     return (year%4 == 0);
}



function isValidDate(dateStr) {
error="";
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
  error = "Date is not in a valid format.\n";
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
error = error + " Month must be between 1 and 12.\n";
}
if (day < 1 || day > 31) {
error = error + " Day must be between 1 and 31.\n";
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
  error = error + " Month "+month+" doesn't have 31 days!\n";
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
  if (day>29 || (day==29 && !isleap)) {
   error = error + " February " + year + " doesn't have " + day + " days!\n";

   }
}
return error;  // date is valid
}