/*------------------------------------------------*/
function popUp(type, extra){
	switch (type) {
		case 'ppolicy' :
			var c = "popup.php?content=ppolicy";
			window.open(c, 'ppolicy_window', 'width=480, height=300, scrollbars=no, status=yes');
			break;
		
		case 'features' : 
			var c = "popup.php?content=features";
			window.open(c,'feature_window', 'width=480, height=480, scrollbars=yes, status=yes');
			break;
		
		case 'poolpic' :
			var c = "popup.php?content=poolpic&image=" + extra;
			window.open(c, 'poolpic_window', 'width=600, height=625, scrollbars=0, status=1');
			break;
			
		case 'note' :
			var c = "popup.php?content=note";
			window.open(c, 'note_window', 'width=400, height=200 scrollbars=0, status=1');
			break;
		
		// if we ever reach the default, there is something wrong.	
		default : window.open("http://www.legacypools.net"); break;
			
	} // end of swith statment
} // end of cuntion popUp()
/*------------------------------------------------*/

function isvalidemail(emailAddress){

	var emailFilter = /^[A-z0-9\._-]+@[A-z0-9][A-z0-9-]*(\.[A-z0-9_-]+)*\.([A-z]{2,6})$/;
	var validemail = true;
	
	if(!emailFilter.test(emailAddress)){ validemail = false; }
	
	return validemail;

} // end of function is valid email


function isvalidphonenumber(phonenumber){

	var vpn = true;
	var phoneFilter = /(\(?\d{3}\)?)?(\-|)?\d{3}(\-|)?\d{4}/;
	
	if(!phoneFilter.test(phonenumber)){ vpn = false; }
	
	return vpn;
	
} // end of function is valid phone number


function isfulladdress(){

	var fulladdress = true;
	
	var address = document.getElementById('address').value;
	var city 	= document.getElementById('city').value;
	var state 	= document.getElementById('state').value;
	var zip 	= document.getElementById('zip').value;

	if(address == "" || city == "" || state == "" || zip == ""){
		fulladdress	= false;
	}
	
	return fulladdress;


} // end of funtion full address



function checkForm(){

	// set the process variable (assuming all is well until we know otherwise)
	var process = "yes";
	
	// get the key values from the form
	var respond = document.getElementById('respond').value;
	var phone	= document.getElementById('phone').value;
	var email	= document.getElementById('email').value;
	var name 	= document.getElementById('name').value;
	
	if(name == ""){
		alert('Please enter your name.');
		document.getElementById('name').focus();
		process = "no";
	}
	
	if(process == "yes"){
		switch (respond){
			case "phone" :
				if(!isvalidphonenumber(phone)){
					alert('Please enter a valid phone number');
					document.getElementById('phone').focus();
					process = "no";
				}
				break;
			case "email" :
				if(!isvalidemail(email)){
					alert('Please enter a valid email address.');
					document.getElementById('email').focus();
					process = "no";
				}
				break;
			case "mail" :
				if(!isfulladdress()){
					alert('Please enter your full mailing address');
					document.getElementById('address').focus();
					process = "no";
				}
				break;
			default :
				alert('Please select a method in which we may respond to you.');
				document.getElementById('respond').focus();
				process = "no";
				break;
		} // end of respond switch
	} // end of if process == "yes"
		
	if(process == "yes"){ document.getElementById('contactForm').submit(); }



} // end of checkForm function


function checkresponce(){

	// get the values from the form
	var phone	= document.getElementById('phone').value;
	var email	= document.getElementById('email').value;
	var respond = document.getElementById('respond').value;
	
	// test the values, make sure they are valid
	var vpn 				= isvalidphonenumber(phone);
	var validemail 			= isvalidemail(email);
	var fulladdress 		= isfulladdress();
	
	// respond to an email request
	if(respond == "email" && validemail == false){
		alert('Please enter a valid email address.');
		document.getElementById('email').focus();
	}
		
	// respond to a snail mail request
	if(respond == "mail" && fulladdress == false){
		alert('Please enter a full mailing address');
		document.getElementById('address').focus();
	
	}
		
	// respond to a phone call request
	if(respond == "phone"){
		document.getElementById('phonetime').style.visibility = "visible";
		if(vpn == false){
			alert('Please enter a valid phone number.');
			document.getElementById('phone').focus();
		}
	} else {
		document.getElementById('phonetime').style.visibility = "hidden";
	}


} // end of check responce function


