function openWin(URL){
	aWindow = window.open(URL,"thewindow","toolbar=0,location=0,directories=0,status=1,menubar=0,resizable=1, scrollbars=no width=648 height=434");
}
function openWinLarge(URL){
	aWindow = window.open(URL,"thewindow","toolbar=0,location=0,directories=0,status=1,menubar=0,resizable=0, scrollbars=no width=648 height=520");
}
function openWinScroll(URL){
	aWindow = window.open(URL,"thewindow","toolbar=0,location=0,directories=0,status=1,menubar=0,resizable=0, scrollbars=yes width=648 height=434");
}

function searchAction(objElement, objForm, strDefault) {
	var strValue = objElement.value;
	if(strValue == 'Cultured Marble') {
		strValue = '/index.cfm/products/' + strValue + '-products'
	} else if(strValue == '') {
		strValue = strDefault;
	} else {
		strValue = '/index.cfm/products/' + strValue + '-tubs'
	}
	strValue = strValue.replace(' ', '-');
	strValue = strValue.toLowerCase();
	objForm.action = strValue;
}


/* *********************************************
FORM VALIDATION ::: CONTACT US
********************************************* */
function formValidatorContactUs(){
	// Make quick references to our fields
	var contactname = document.getElementById('contactname');
	var phone = document.getElementById('phone');
	var email = document.getElementById('email');
	var purchase = document.getElementById('purchase');
	var contact = document.getElementById('contact');
	var blnPurchaseChecked = 0;
	var blnContactChecked = 0;
	

	// PURCHASE
	if (document.frmContactUs.purchase[0].checked==true) {
		blnPurchaseChecked = 1;
	}
	if (document.frmContactUs.purchase[1].checked==true) {
		blnPurchaseChecked = 1;
	}
	if (document.frmContactUs.purchase[2].checked==true) {
		blnPurchaseChecked = 1;
	}
	if (document.frmContactUs.purchase[3].checked==true) {
		blnPurchaseChecked = 1;
	}
	if (document.frmContactUs.purchase[4].checked==true) {
		blnPurchaseChecked = 1;
	}
	if (document.frmContactUs.purchase[5].checked==true) {
		blnPurchaseChecked = 1;
	}

	// CONTACT
	if (document.frmContactUs.contact[0].checked==true) {
		blnContactChecked = 1;
	}
	if (document.frmContactUs.contact[1].checked==true) {
		blnContactChecked = 1;
	}
	if (document.frmContactUs.contact[2].checked==true) {
		blnContactChecked = 1;
	}

	// Check each input in the order that it appears in the form!
	if(notEmpty(contactname, "Please enter a valid Name.")){
		if(notEmpty(phone, "Please enter a valid Phone.")){
			if(emailValidator(email, "Please enter a valid E-mail.")){
				if(blnPurchaseChecked == 0) {
					alert('Please answer Which items are you interested in purchasing?');
					return false;
				} else {
					if(blnContactChecked == 0) {
						alert('Please answer How would you like us to contact you?');
						return false;
					} else {
						return true;
					}
				}
			}
		}
	}

	return false;
}

/* *********************************************
FORM VALIDATION ::: WARRANTY REGISTRATION
********************************************* */
function formValidatorWarrantyRegistration(){
	// Make quick references to our fields
	var buildername = document.getElementById('buildername');
	var firstname = document.getElementById('firstname');
	var lastname = document.getElementById('lastname');
	var address = document.getElementById('address1');
	var city = document.getElementById('city');
	var state = document.getElementById('state');
	var zip = document.getElementById('zip');
	var monthPurchased = document.getElementById('monthPurchased');
	var dayPurchased = document.getElementById('dayPurchased');
	var yearPurchased = document.getElementById('yearPurchased');
	var acceptterms = document.getElementById('acceptterms');

	// Check each input in the order that it appears in the form!
	if(notEmpty(buildername, "Please enter a valid Builder Name.")){
		if(notEmpty(firstname, "Please enter a valid First Name.")){
			if(notEmpty(lastname, "Please enter a valid Last Name.")){
				if(notEmpty(address, "Please enter a valid Street Address.")){
					if(notEmpty(city, "Please enter a valid City.")){
						if(notEmpty(state, "Please enter a valid State.")){
							if(notEmpty(zip, "Please enter a valid Postal Code.")){
								if(notEmpty(monthPurchased, "Please enter a valid Month Purchased.")){
									if(notEmpty(dayPurchased, "Please enter a valid Day Purchased.")){
										if(notEmpty(yearPurchased, "Please enter a valid Year Purchased.")){
											if(acceptterms.checked == false) {
												alert("Please read and accept the terms of my warranty.");
												return false;
											} else {
												return true;
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	return false;
}

/* *********************************************
ASSISTING FUNCTIONS 
********************************************* */
function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	// alert(elem.value.match(emailExp));
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function notEmptyNoFocus(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		// elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}


