/*
Validation script for chelsea's vip/index.asp page. 
*/

/*--Validation starts here and ends here. All other functions are called from this function.--*/
function validate_confirm(formobj){
	init();	//initialize variables.
	
	//loop through all fields in the form
	for(var i = 0; i < formobj.length; i++){
		var e = formobj.elements[i];
		if(e.type == "text"){
			v_text_c(e);
		}
		if(e.type == "select-one"){
			v_sel(e);
		}
		if(e.type == "radio"){
			v_radio(e);
		}
	}	
	
	if(err > 0){
		if(is.ie && on.mac){
			errmsg +="\r\r";
			alert(errmsg);
		}else{
			//show div layer with error message
			toggle_visibility("errorDiv","visible");			
		}
		eval("window.scrollTo(0,0)"); //reposition the page???
		return false;
	}else{
		toggle_visibility("errorDiv","hidden");		
		return true;
		//return false;
	}
}

/*-- functions that do the actual validation of the form elements --*/
function v_text_c(obj){
	var _name = obj.name;
	var _val = obj.value;
	switch(_name){
		case "txt_fname":
			if(_val==""){errmsg+="\tFirst Name\r";toggle_visibility(_name+"_div","visible");err++;}
			else{toggle_visibility(_name+"_div","hidden")};break;
		case "txt_lname":
			if(_val==""){errmsg+="\tLast Name\r";toggle_visibility(_name+"_div","visible");err++;}
			else{toggle_visibility(_name+"_div","hidden")};break;
		case "txt_email":
			if(_val==""){errmsg+="\tEmail Address\r";toggle_visibility(_name+"_div","visible");err++;}
			else{confirm_email_only(_name,trim(_val))};break;
	}
}

//checks the email entry and validates the email format
function confirm_email_only(e_name, e_val){
	confirm_entry = e_name + "confirm";
	//do email type check here. if it is not a real email format then alert user. 
	var boolValidEmail = emailFormat(e_val);
	if(boolValidEmail){
		// do nothing
	}else{
		toggle_visibility(e_name + "_div","visible"); //email entered is not in the valid format.
		toggle_visibility("divBadEmailMsg","visible");
		err++;
		errmsg += "\tInvalid Email\r";
	}
}
