// JavaScript Document
function switchSubscribeSubmit(validBOOL,submit_element) {
	
	if(validBOOL == true){
		if(submit_element.value == 'Complete Purchase'){ 
			//document.getElementById('submitButton').style.display = 'none';			
			submit_element.value = 'Please Wait.';			
			
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}

function updateError(formElement,errorMsg) {
	//var errDisplay = document.getElementById('error_' + formElement.name);
	
	var container_p = document.createElement('p');
	container_p.className = "error";
	
	container_p_text = document.createTextNode(errorMsg);	
	container_p.appendChild(container_p_text);	
	
	var errDisplay = document.getElementById('error_' + formElement.id);	
	errDisplay.appendChild(container_p);	
	new Effect.Appear('error_' + formElement.id);
}


function clearPreviousError(formElement) {
	var errDisplay = document.getElementById('error_' + formElement.id);
	
	if(errDisplay.hasChildNodes()) {
		errDisplay.display = 'none';
		errDisplay.removeChild(errDisplay.firstChild);
	}
}

function displayErrorHeader(errorDivID) {
	if(!errorDivID)
		errorDivID = 'errorMsgHeader';
	
	errorDiv = document.getElementById(errorDivID);	
	errorMsg = "Please correct the errors highlighted below";
	if(errorDiv) {	
		var container_p = document.createElement('p');
		container_p.className = "error";
		
		container_p_text = document.createTextNode(errorMsg);
		container_p.appendChild(container_p_text);	
		
		errorDiv.appendChild(container_p);
		new Effect.Appear(errorDiv);
	} else {
		alert(errorMsg);
	}
}

function clearPreviousErrors(formOBJ) {
		
	all_divs = document.getElementsByTagName('div');
	for(i = 0; i < all_divs.length; i++) {
		if(all_divs[i].id.search(/errorMsgHeader/) != -1) {
			all_divs[i].display = 'none';
			if(all_divs[i].hasChildNodes())
				all_divs[i].removeChild(all_divs[i].firstChild);	
		}
	}	
		
	for (var i = 0; i < formOBJ.elements.length; i++) {	
		current_input_error = document.getElementById('error_' + formOBJ[i].id);
		
		if(current_input_error && current_input_error.hasChildNodes())
		{			
			//new Effect.Fade(current_input_error.id);
			current_input_error.style.opacity = 0;
			current_input_error.style.display = "none";
			for(j=0;j<current_input_error.childNodes.length;j++) {
				current_input_error.removeChild(current_input_error.childNodes[j]);
			}
		}			
	}
}



function submitLostPassword(x) {
	var validBOOL = true;
	
	clearPreviousErrors(x);
	var firstField = "";
	
	if(!checkEmail(x.email)) {		
		updateError(x.email,'Please enter a valid email address');
		if(!firstField) firstField = x.email;
		validBOOL = false;		
	} 
		
	if(!checkRadio(x.account_type)) {
		updateError(x.account_type_error,'Please select your Account Type.');		
		validBOOL = false;
	}	
	
	if (validBOOL == true) {		
		return true;
	} else {
		if(firstField)
			firstField.focus();
			
		displayErrorHeader();		
		return false;
	}
}

function submitLogin(x) {
	var validBOOL = true;
	
	clearPreviousErrors(x);
	if(document.getElementById('registerF'))
		clearPreviousErrors(document.getElementById('registerF'));
	var firstField = "";
	
	if(!checkEmail(x.email)) {		
		updateError(x.email,'Please enter a valid email address');
		if(!firstField) firstField = x.email;
		validBOOL = false;		
	} 
	
	if(x.password.value=="") {		
		updateError(x.password,'Please enter your password.');
		if(!firstField) firstField = x.password;
		validBOOL = false;	
	}
	
	if (validBOOL == true) {		
		return true;
	} else {
		if(firstField)
			firstField.focus();
			
		displayErrorHeader('errorMsgHeaderLogin');		
		return false;
	}
}

function submitRegister(x) {
	var validBOOL = true;
	
	clearPreviousErrors(x);
	clearPreviousErrors(document.getElementById('loginF'));
	var firstField = "";
	
	if(x.ClientFirstName.value=="") {		
		updateError(x.ClientFirstName,'Please enter your First Name.');
		if(!firstField) firstField = x.ClientFirstName;
		validBOOL = false;		
	} 
	
	if(x.ClientLastName.value=="") {
		updateError(x.ClientLastName,'Please enter your Last Name.');
		if(!firstField) firstField = x.ClientLastName;
		validBOOL = false;
	} 
	
	if(!checkEmail(x.ClientEmail)) {		
		updateError(x.ClientEmail,'Please enter a valid email address');
		if(!firstField) firstField = x.ClientEmail;
		validBOOL = false;		
	} 
	
	if(!checkPhone(x.ClientPhone)) {
		updateError(x.ClientPhone,'Please enter your Phone in the following format 555-555-5555.');
		if(!firstField) firstField = x.ClientPhone;
		validBOOL = false;
	}
	
	if(x.ClientCompany.value=="") {		
		updateError(x.ClientCompany,'Please enter your Company.');
		if(!firstField) firstField = x.ClientCompany;
		validBOOL = false;		
	}
	
	if (validBOOL == true) {		
		return true;
	} else {
		if(firstField)
			firstField.focus();
			
		displayErrorHeader('errorMsgHeaderRegister');		
		return false;
	}
}

function submitExpressBooking(x) {
	var validBOOL = true;
	
	clearPreviousErrors(x);
	var firstField = "";
	
	if(x.BookingFirstName.value=="") {		
		updateError(x.BookingFirstName,'Please enter your First Name.');
		if(!firstField) firstField = x.BookingFirstName;
		validBOOL = false;		
	} 
	
	if(x.BookingLastName.value=="") {
		updateError(x.BookingLastName,'Please enter your Last Name.');
		if(!firstField) firstField = x.BookingLastName;
		validBOOL = false;
	} 
	
	if(!checkEmail(x.BookingEmail)) {		
		updateError(x.BookingEmail,'Please enter a valid email address');
		if(!firstField) firstField = x.BookingEmail;
		validBOOL = false;		
	} 
	
	if(!checkPhone(x.BookingPhone)) {
		updateError(x.BookingPhone,'Please enter your Phone in the following format 555-555-5555.');
		if(!firstField) firstField = x.BookingPhone;
		validBOOL = false;
	}
	
	if(x.BookingCompany.value=="") {		
		updateError(x.BookingCompany,'Please enter your Company.');
		if(!firstField) firstField = x.BookingCompany;
		validBOOL = false;		
	}
	
	if(x.BookingTitle.value=="" || x.BookingTitle.value == "Specify the Title") {		
		updateError(x.BookingTitle,'Please enter the Title of the Booking.');
		if(!firstField) firstField = x.BookingTitle;
		validBOOL = false;		
	}
	
	if(!checkDate(x.BookingWhen)) {		
		updateError(x.BookingWhen,'Please enter the When of the Booking (mm/dd/yyyy).');
		if(!firstField) firstField = x.BookingWhen;
		validBOOL = false;		
	}
	
	if(x.BookingWhere.value=="" || x.BookingWhere.value == "Specify the Location") {		
		updateError(x.BookingWhere,'Please enter the Where of the Booking.');
		if(!firstField) firstField = x.BookingWhere;
		validBOOL = false;		
	}
	
	if(x.BookingWhat.value=="" || x.BookingWhat.value == "Specify the Details of the Booking") {		
		updateError(x.BookingWhat,'Please enter the What of the Booking.');
		if(!firstField) firstField = x.BookingWhat;
		validBOOL = false;		
	}
	
	if (validBOOL == true) {		
		return true;
	} else {
		if(firstField)
			firstField.focus();
			
		displayErrorHeader();		
		return false;
	}
}

function submitModelApplication(x) {
	var validBOOL = true;
	
	clearPreviousErrors(x);
	var firstField = "";
	
	if(x.ModelFirstName.value=="") {		
		updateError(x.ModelFirstName,'Please enter your First Name.');
		if(!firstField) firstField = x.ModelFirstName;
		validBOOL = false;		
	} 
	
	if(x.ModelLastName.value=="") {
		updateError(x.ModelLastName,'Please enter your Last Name.');
		if(!firstField) firstField = x.ModelLastName;
		validBOOL = false;
	} 
	
	if(!checkEmail(x.ModelEmail)) {		
		updateError(x.ModelEmail,'Please enter a valid email address');
		if(!firstField) firstField = x.ModelEmail;
		validBOOL = false;		
	} 
	
	if(!checkPhone(x.ModelPhone)) {
		updateError(x.ModelPhone,'Please enter your Phone in the following format 555-555-5555.');
		if(!firstField) firstField = x.ModelPhone;
		validBOOL = false;
	}
	//alert(getRadioValue(x.CityID));
	if(!getRadioValue(x.CityID) && x.ModelCity.value == "") {		
		updateError(x.city_radio,'Please select a City or enter a City (Other).');		
		validBOOL = false;		
	}
	//alert(x.CityID.value);
	if(getRadioValue(x.CityID) == '3' && x.ModelCity.value == "") {	
		//alert('hi')
		updateError(x.CityID_input,'Please enter in a City (Other).');
		if(!firstField) firstField = x.ModelCity;
		validBOOL = false;		
	}
	
	if(x.ModelZip.value=="") {
		updateError(x.ModelZip,'Please enter your Zip Code.');
		if(!firstField) firstField = x.ModelZip;
		validBOOL = false;
	} 
		
	if(x.HeightID.value=="") {
		updateError(x.HeightID,'Please select your Height.');		
		validBOOL = false;
	} 
	
	if(x.HairColorID.value=="") {
		updateError(x.HairColorID,'Please select your Hair Color.');		
		validBOOL = false;
	} 
	
	if(x.EyeColorID.value=="") {
		updateError(x.EyeColorID,'Please select your Eye Color.');		
		validBOOL = false;
	}
	
	if(x.EducationLevelID.value=="") {
		updateError(x.EducationLevelID,'Please select your Education Level.');		
		validBOOL = false;
	}
	
	if(x.ModelGender.value=="") {
		updateError(x.ModelGender,'Please choose your gender.');
		validBOOL = false;
	} 	
	
	/*
	if(x.ModelSchool.value=="") {
		updateError(x.ModelSchool,'Please enter your School & Degree.');
		if(!firstField) firstField = x.ModelSchool;
		validBOOL = false;
	}
	
	if(x.ModelLanguages.value=="") {
		updateError(x.ModelLanguages,'Please enter your Languages.');
		if(!firstField) firstField = x.ModelLanguages;
		validBOOL = false;
	}
	*/
	
	if(x.Photo01.value=="") {
		updateError(x.Photo01,'You must select a Primary Photo to upload.');
		if(!firstField) firstField = x.Photo01;
		validBOOL = false;
	}	
	
	if (validBOOL == true) {		
		return true;
	} else {
		if(firstField)
			firstField.focus();
			
		displayErrorHeader();		
		return false;
	}
}