/* clearSearchField() auto clears the search field box on focus */

function clearSearchField(obj) {
	document.getElementsByName(obj)[0].value = "";
}

/* show() and hide() control the check availability and shipping info "popups" on the details page */

var tablist = new Array("availability", "shippingDet");
							
function show(obj) {
	document.getElementById("hideDiv").style.visibility = "visible";
	for(i=0; i<tablist.length; i++) {
		if (tablist[i] == obj) {
			document.getElementById(obj).style.display = "block";
			document.getElementById(obj+"Link").className = "tabNavActive";
		}
		else {
			document.getElementById(tablist[i]).style.display = "none";
			document.getElementById(tablist[i]+"Link").className = "";
		}
	}			
}

function hide(obj) {
	document.getElementById(obj).style.visibility = "hidden";
	for(i=0; i<tablist.length; i++) {
		document.getElementById(tablist[i]).style.display = "none";
		document.getElementById(tablist[i]+"Link").className = "";
	}
}


/* showhide() controls the checkout page steps 1-5 */

function showhide(div)
{
	if (document.getElementById('ckBillingAddressDiv'))
	{
		var option=['ckBillingAddressDiv','ckPaymentMethodDiv','ckShipAddressDiv','ckShipMethodDiv','ckReviewOrderDiv'];
		for(var i=0; i<option.length; i++) 
			{ obj=document.getElementById(option[i]);
				obj.style.display=(option[i]==div)? "block" : "none"; 
			}
	}
}


/* displayPopupdisplayPopup() controls the hidden css popups - help tabs throughout site */

var state = 'none'; 

function displayPopup(layer_ref) { 

	if (state == 'block') { 
		state = 'none'; 
	} 
	else { 
		state = 'block'; 
	} 
	if (document.all) { //IS IE 4 or 5 (or 6 beta) 
		eval( "document.all." + layer_ref + ".style.display = state"); 
	} 
	if (document.layers) { //IS NETSCAPE 4 or below 
		document.layers[layer_ref].display = state; 
	} 
	if (document.getElementById &&!document.all) { 
		hza = document.getElementById(layer_ref); 
		hza.style.display = state; 
	} 
} 


/* MEREGED FROM PROD_DETAIL.JS */

function validateProductDetail() {
	$('checkOutBtnContainer').setStyles({'opacity': 0, 'display': 'none'});
	
	size = $('size1').value;
	color = $('color1').value;
	logo = $('logo1').value;
	qty = $('qty').value;
	bom_comment = $('bom_comment').value;
	base_product_name = $('base_product_name').value;
	min_qty =$('min_qty').value;
	var error = 0;
	//if size value is null, highligh size and set error to 1 to indicate error level
	//if size avlue is not null, remove highlight 
	if (size == "") {
		$('sizeText').addClass('highlightField');
		error = 1;
	}
	else {
		$('sizeText').removeClass('highlightField');
	}

	//if color value is null, highligh color and set error to 1 to indicate error level
	//if color avlue is not null, remove highlight 
	if (color == "") {
		$('colorText').addClass('highlightField');
		error = 1;
	}
	else {
		$('colorText').removeClass('highlightField');
	}
	
	//if logo value is null, highligh logo and set error to 1 to indicate error level
	//if logo avlue is not null, remove highlight 
	if (logo == "") {
		$('logoText').addClass('highlightField');
		error = 1;
	}
	else {
		$('logoText').removeClass('highlightField');
	}
	
	if (!isInteger(qty)) {
		$('qtyText').removeClass('highlightField');
		error = 3;
	}
	else if (qty < min_qty) {
		$('qtyText').removeClass('highlightField');
		error = 2;
	}
	else {
		$('qtyText').removeClass('highlightField');
	}

	//error 1 indicates required fields are empty
	if (error ==  1) {
		$('errorMsg').setHTML('Highlighted field(s) are required.').setStyle('display', 'block');
		
	}
	//error 2 indicates qty value is invalid
	else if (error == 2) {
		$('errorMsg').setHTML('Quantity can\'t be less than ' + min_qty +'.').setStyle('display', 'block');
		
	}
	//error 3 indicates qty is empty or non numeric
	else if (error == 3) {
		$('errorMsg').setHTML('Please enter a number.').setStyle('display', 'block');
		
	}
	//call add to cart ajax otherwise
	else {
		$('errorMsg').setHTML('').setStyle('display', 'none');
		addToCart(base_product_name,size, color, logo, qty, bom_comment);
	}
	return false;
}

var xmlHttp;

function addToCart(base_product_name,size, color, logo, qty, bom_comment) { 
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	//replace "&" with "___" if there is "&" in logo code
	//if (-1 != logo.indexOf("&"))
	//	logo = logo.replace(/&/, "%26");
	
	//replace "?" with "___" if there is "&" in logo code
	//if (-1 != logo.indexOf("?"))
	//	logo = logo.replace(/&/, "%3f");
	
	var url = "act_manager.cfm?action=addtocart";
	url = url + "&base_product_name=" + encodeURIComponent(base_product_name);
	url = url + "&size=" + encodeURIComponent(size);
	url = url + "&color=" + encodeURIComponent(color);
	url = url + "&logo=" + encodeURIComponent(logo);
	url = url + "&qty=" + qty;
	url = url + "&bom_comment=" + encodeURIComponent(bom_comment);
	xmlHttp.onreadystatechange = addToCartStateChanged;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function addToCartStateChanged() { 
	if (xmlHttp.readyState == 4) { 
		if (xmlHttp.status == 200) {
			/*$('addtocartWrapper').setHTML(xmlHttp.responseText);
			var mySlide = new Fx.Slide('addtocartWrapper', {duration: 800});
			mySlide.hide();
			mySlide.toggle();
			(function(){mySlide.toggle()}).delay(6000);
			updateCartNum();*/
			$('checkOutBtnContainer').setHTML(xmlHttp.responseText).setStyles({'opacity': 0, 'display': 'block'});
			$('checkOutBtnContainer').effect('opacity',{duration: 500}).start(1);
			updateCartNum();
		}
		else
			$('errorMsg').setHTML("Can't add to the cart!").setStyle('display', 'block');
	}
}

function updateCartNum() { 
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	var url = "act_manager.cfm?action=updatecartnum";
	xmlHttp.onreadystatechange = updateCartNumStateChanged;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function updateCartNumStateChanged() { 
	if (xmlHttp.readyState == 4) { 
		if (xmlHttp.status == 200) {
			$('cartCounter').setHTML(xmlHttp.responseText);
		}
		else
			alert("There was a problem retrieving the XML data1:\n" + xmlHttp.statusText);
	}
}


/* MERGED FROM SHOPPINGCART.J */

function validateCartUnitChange() {
	id_counter = $('id_counter').value;
	qty = $('qty' + id_counter).value;
	min_qty = $('min_qty' + id_counter).value;

	if (qty < min_qty) {
		alert( "Quantity can't be less than " + min_qty + ".");
		return false;
	}

	return true;
}

function CheckoutSubmit() {
	document.ShoppingCart.action = "default.cfm?fuse=checkout";
}

function UpdateItem( id_counter) {
	document.ShoppingCart.action = "act_manager.cfm?action=updatecartitem";
	document.ShoppingCart.id_counter.value = id_counter;
}

function SetPromoCode()
{ 
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return false;
	}
	var url = "act_manager.cfm?action=getpromotioncode";
	url = url + "&promotion_code=" + encodeURIComponent(document.getElementById("promotion_code").value);
	xmlHttp.onreadystatechange = PromoCodeValidation;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
	return false;
}

function PromoCodeValidation() { 
	if (xmlHttp.readyState == 4) { 
		if (xmlHttp.status == 200) {
			var xmlDoc = xmlHttp.responseXML;
			// GET TARGET AND CONTENT XML OBJECTS
			targets = xmlDoc.getElementsByTagName("target");
			contents = xmlDoc.getElementsByTagName("content");
			//IF NOT EMPTY, DISPLAY VALIDATION CONTENT(S)
			if (targets.length > 0) {
				//CLEAN PREVIOUS MESSAGE IF EXISTS, J EQUALS TO THE # OF VALIDATION FIELDS
				if (document.getElementById('PromoCodeValidationMsg'))
					$('PromoCodeValidationMsg').remove();

				var msg = new Element('div', {'class': 'validationMsg', 'id':'PromoCodeValidationMsg'});
				msg.setHTML(contents[0].firstChild.nodeValue).injectAfter($(targets[0].firstChild.nodeValue));
			}
			else
				document.ShoppingCart.submit();
		}
		else 
			alert("There was a problem retrieving the XML data2:\n" + xmlHttp.statusText);
	}
}

/* MERGED FROM LOGIN.JS */

var xmlHttp;

function validateNewCustForm() {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}

	var url = "act_manager.cfm?action=newcustlogin";
	url = url + "&newCustEmail=" + encodeURIComponent(document.getElementById("newCustEmail").value);
	url = url + "&newCustPw=" + encodeURIComponent(document.getElementById("newCustPw").value);
	url = url + "&newCustPwVerify=" + encodeURIComponent(document.getElementById("newCustPwVerify").value);
	xmlHttp.onreadystatechange = NewCustStateChanged;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
	return false;
}

function validateNewDlrForm() {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}

	var url = "act_manager.cfm?action=newdealerlogin";
	url = url + "&newCustEmail=" + encodeURIComponent(document.getElementById("newCustEmail").value);
	url = url + "&pa_code=" + encodeURIComponent(document.getElementById("pa_code").value);
	url = url + "&newCustPw=" + encodeURIComponent(document.getElementById("newCustPw").value);
	url = url + "&newCustPwVerify=" + encodeURIComponent(document.getElementById("newCustPwVerify").value);
	xmlHttp.onreadystatechange = NewDealerStateChanged;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
	return false;
}

function validateNewEmployeeForm() {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}

	var url = "act_manager.cfm?action=newemployeelogin";
	url = url + "&newCustEmail=" + encodeURIComponent(document.getElementById("newCustEmail").value);
	url = url + "&newCustPw=" + encodeURIComponent(document.getElementById("newCustPw").value);
	url = url + "&newCustPwVerify=" + encodeURIComponent(document.getElementById("newCustPwVerify").value);
	xmlHttp.onreadystatechange = NewEmployeeStateChanged;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
	return false;
}

function NewCustStateChanged() { 
	if (xmlHttp.readyState == 4) { 
		if (xmlHttp.status == 200) {
			var xmlDoc = xmlHttp.responseXML;
			// GET TARGET AND CONTENT XML OBJECTS
			targets = xmlDoc.getElementsByTagName("target");
			contents = xmlDoc.getElementsByTagName("content");
			//IF NOT EMPTY, DISPLAY VALIDATION CONTENT(S)
			if (targets.length > 0) {
				//CLEAN PREVIOUS MESSAGE IF EXISTS, J EQUALS TO THE # OF VALIDATION FIELDS
				for (j = 0; j < 3; j++) {
					if(document.getElementById('newCustValidationMsg'+j))
						$('newCustValidationMsg'+j).remove();
				}
				for (i = 0; i < targets.length; i++) {
					var msg = new Element('div', {'class': 'validationMsg', 'id':'newCustValidationMsg'+i});
					msg.setHTML(contents[i].firstChild.nodeValue).injectAfter($(targets[i].firstChild.nodeValue));
				}
			}
			else
				document.newCustomer.submit();
		}
		else 
			alert("There was a problem retrieving the XML data3:\n" + xmlHttp.statusText);
	}
}

function NewDealerStateChanged() { 
	if (xmlHttp.readyState == 4) { 
		if (xmlHttp.status == 200) {
			var xmlDoc = xmlHttp.responseXML;
			// GET TARGET AND CONTENT XML OBJECTS
			targets = xmlDoc.getElementsByTagName("target");
			contents = xmlDoc.getElementsByTagName("content");
			//IF NOT EMPTY, DISPLAY VALIDATION CONTENT(S)
			if (targets.length > 0) {
				//CLEAN PREVIOUS MESSAGE IF EXISTS, J EQUALS TO THE # OF VALIDATION FIELDS
				for (j = 0; j < 4; j++) {
					if(document.getElementById('newCustValidationMsg'+j))
						$('newCustValidationMsg'+j).remove();
				}
				for (i = 0; i < targets.length; i++) {
					var msg = new Element('div', {'class': 'validationMsg', 'id':'newCustValidationMsg'+i});
					msg.setHTML(contents[i].firstChild.nodeValue).injectAfter($(targets[i].firstChild.nodeValue));
				}
			}
			else
				document.newDealer.submit();
		}
		else 
			alert("There was a problem retrieving the XML data4:\n" + xmlHttp.statusText);
	}
}

function NewEmployeeStateChanged() { 
	if (xmlHttp.readyState == 4) { 
		if (xmlHttp.status == 200) {
			var xmlDoc = xmlHttp.responseXML;
			// GET TARGET AND CONTENT XML OBJECTS
			targets = xmlDoc.getElementsByTagName("target");
			contents = xmlDoc.getElementsByTagName("content");
			//IF NOT EMPTY, DISPLAY VALIDATION CONTENT(S)
			if (targets.length > 0) {
				//CLEAN PREVIOUS MESSAGE IF EXISTS, J EQUALS TO THE # OF VALIDATION FIELDS
				for (j = 0; j < 3; j++) {
					if(document.getElementById('newCustValidationMsg'+j))
						$('newCustValidationMsg'+j).remove();
				}
				for (i = 0; i < targets.length; i++) {
					var msg = new Element('div', {'class': 'validationMsg', 'id':'newCustValidationMsg'+i});
					msg.setHTML(contents[i].firstChild.nodeValue).injectAfter($(targets[i].firstChild.nodeValue));
				}
			}
			else
				document.newCustomer.submit();
		}
		else 
			alert("There was a problem retrieving the XML data5:\n" + xmlHttp.statusText);
	}
}

function validateReturnCustForm() {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}

	var url = "act_manager.cfm?action=returncustlogin";
	url = url + "&returnCustEmail=" + encodeURIComponent(document.getElementById("returnCustEmail").value);
	url = url + "&returnCustPw=" + encodeURIComponent(document.getElementById("returnCustPw").value);
	xmlHttp.onreadystatechange = ReturnCustStateChanged;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
	return false;
}

function ReturnCustStateChanged() { 
	if (xmlHttp.readyState == 4) { 
		if (xmlHttp.status == 200) {
			var xmlDoc = xmlHttp.responseXML;
			// GET TARGET AND CONTENT XML OBJECTS
			targets = xmlDoc.getElementsByTagName("target");
			contents = xmlDoc.getElementsByTagName("content");
			//IF NOT EMPTY, DISPLAY VALIDATION CONTENT(S)
			if (targets.length > 0) {
				//CLEAN PREVIOUS MESSAGE IF EXISTS, J EQUALS TO THE # OF VALIDATION FIELDS
				for (j = 0; j < 2; j++) {
					if(document.getElementById('returnCustValidationMsg'+j))
						$('returnCustValidationMsg'+j).remove();
				}
				for (i = 0; i < targets.length; i++) {
					var msg = new Element('div', {'class': 'validationMsg', 'id':'returnCustValidationMsg'+i});
					msg.setHTML(contents[i].firstChild.nodeValue).injectAfter($(targets[i].firstChild.nodeValue));
				}
			}
			else
				document.returnCustomer.submit();
		}
		else 
			alert("There was a problem retrieving the XML data6:\n" + xmlHttp.statusText);
	}
}


/* MERGED FROM AJAX_GLOBAL.JS */

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
  // Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
  // Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
} 


/* MERGED FROM TOOLTIPS.JS */

window.addEvent('domready', function(){
	var relatedItemTips = new Tips($$('.relatedItemTips'));
})

/* MERGED FROM GETSIZECOLORLOGO.JS */
var xmlHttp;

function setList(base_product_name, num)
{ 
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	size = $('size'+num).value;
	color = $('color'+num).value;
	logo = $('logo'+num).value;
	
	if(logo == "Noni") {
		if ($('msgContainer'+num))
			$('msgContainer'+num).setStyle('display', 'none');
	}
	else  {
		if ($('msgContainer'+num))
			$('msgContainer'+num).setStyle('display', 'block');
	}
		
		
	
	//replace "&" with "___" if there is "&" in logo code
	if (-1 != logo.indexOf("&"))
		logo = logo.replace(/&/, "%26");
	
	//replace "?" with "___" if there is "&" in logo code
	if (-1 != logo.indexOf("?"))
		logo = logo.replace(/&/, "%3f");
		
	var url = "act_manager.cfm?action=getsizecolorlogo";
	url = url + "&base_product_name=" + encodeURIComponent(base_product_name);
	url = url + "&size=" + encodeURIComponent(size);
	url = url + "&color=" + encodeURIComponent(color);
	url = url + "&logo=" + encodeURIComponent(logo);
	url = url + "&postfix=" + num;
	xmlHttp.onreadystatechange = selectStateChanged;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function selectStateChanged() { 
	if (xmlHttp.readyState == 4) { 
		if (xmlHttp.status == 200) {
			var xmlDoc = xmlHttp.responseXML;
			// GET SIZE CODE AND SIZE DESCRIPTION XML OBJECTS
			size_codes = xmlDoc.getElementsByTagName("sizecode");
			size_descriptions = xmlDoc.getElementsByTagName("sizedescription");
			// GET COLOR CODE AND COLOR DESCRIPTION XML OBJECTS
			color_codes = xmlDoc.getElementsByTagName("colorcode");
			color_descriptions = xmlDoc.getElementsByTagName("colordescription");
			
			// GET LOGO CODE AND LOGO DESCRIPTION XML OBJECTS
			logo_codes = xmlDoc.getElementsByTagName("logocode");
			logo_descriptions = xmlDoc.getElementsByTagName("logodescription");
			
			num = xmlDoc.getElementsByTagName("postfix")[0].firstChild.nodeValue;
			
			//RE-POPULATE SIZE SELECT BOX IF RETURNED SIZE XML OBJECT IS NOT EMPTY
			if (size_codes.length >= 0) {
				//IF THERE IS MORE THAN ONE SIZE
				if(document.getElementById("size"+num).options) {
					document.getElementById("size"+num).options.length = 0;
					with(document.getElementById("size"+num)) {
						options[options.length] = new Option("Select...","");
					}
					for (i = 0; i < size_codes.length; i++) {
						var sizeOpt = new Option(size_descriptions[i].firstChild.nodeValue, size_codes[i].firstChild.nodeValue);
						with(document.getElementById("size"+num)) {
							options[options.length] = sizeOpt;
						}
						if(size_codes[i].getAttribute('selected') == "true") {
							with(document.getElementById("size"+num))
								options[i+1].selected = true;
						}	
					}
				}
			}
			
			//RE-POPULATE COLOR SELECT BOX IF RETURNED COLOR XML OBJECT IS NOT EMPTY
			if (color_codes.length >= 0) {
				if(document.getElementById("color"+num).options) {
					document.getElementById("color"+num).options.length = 0;
					with(document.getElementById("color"+num)) {
						options[options.length] = new Option("Select...","");
					}
					for (i = 0; i < color_codes.length; i++) {
						var colorOpt = new Option(color_descriptions[i].firstChild.nodeValue, color_codes[i].firstChild.nodeValue);
						with(document.getElementById("color"+num)) {
							options[options.length] = colorOpt;
						}
						if(color_codes[i].getAttribute('selected') == "true") {
							with(document.getElementById("color"+num))
								options[i+1].selected = true;
						}	
					}
				}
			}
			
			//RE-POPULATE LOGO SELECT BOX IF RETURNED LOGO XML OBJECT IS NOT EMPTY
			if (logo_codes.length >= 0) {
				if(document.getElementById("logo"+num).options) {
					document.getElementById("logo"+num).options.length = 0;
					with(document.getElementById("logo"+num)) {
						options[options.length] = new Option("Select...","");
					}
					for (i = 0; i < logo_codes.length; i++) {
						var logoOpt = new Option(logo_descriptions[i].firstChild.nodeValue, logo_codes[i].firstChild.nodeValue);
						with(document.getElementById("logo"+num)) {
							options[options.length] = logoOpt;
						}
						if(logo_codes[i].getAttribute('selected') == "true") {
							with(document.getElementById("logo"+num))
								options[i+1].selected = true;
						}	
					}
				}
			}
		}
		else
			alert("There was a problem retrieving the XML data7:\n" + xmlHttp.statusText);
	}
}	

/* MERGED FROM CHK_VALIDATION.JS */
var readySubmit;
var emailError;

function setErrorMsg(errorType, errorField) {
	var errorTypeMsg = new Array("This is a required field.", "Not a valid email address.", "It's an existing account. Please try other email.", "It's not an existing account. Please try other email.", "Emails do not match.", "Password do not match.", "Phone/Fax must have at least 10 numbers.")
	var msg = new Element('span', {'class': 'validationMsg'});
	msg.setHTML(errorTypeMsg[errorType]).injectAfter(errorField);
}

function emailValidation(email) {
	emailError = false;
	if(-1 == email.value.indexOf("@")) {
		emailError = true;
		readySubmit = false;
	}
	if(-1 == email.value.indexOf(".")) {
		emailError = true;
		readySubmit = false;
	}
	if(-1 != email.value.indexOf(",")) { 
		emailError = true;
		readySubmit = false;
	}
	if(-1 != email.value.indexOf("#")) { 
		emailError = true;
		readySubmit = false;
	}
	if(-1 != email.value.indexOf("!")) { 
		emailError = true;
		readySubmit = false;
	}
	if(email.value.length == (email.value.indexOf("@")+1) ) {
		emailError = true;
		readySubmit = false;
	}
	if(email.value.length == (email.value.indexOf(".")+1) ) {
		emailError = true;
		readySubmit = false;
	}
	if(emailError) {
		setErrorMsg(1, email);
		readySubmit = false;
	}
}

function emailConfirmValidation(email, emailToMatch) {
	if (email.value != emailToMatch.value) {
		setErrorMsg(4, email);
		readySubmit = false;
	}
}

function passwordConfirmValidation(password, passwordToMatch) {
	if (password.value != passwordToMatch.value) {
		setErrorMsg(5, password);
		readySubmit = false;
	}
}

function ValidatePhoneNumber(Phone) {
	var len = 0;
	var PhoneNumber = trim(Phone.value);
	
	//Ignore empty strings:
	if (PhoneNumber == "")
		return;
	
	for (var i = 0; i < PhoneNumber.length; i++) {
		if (!isNaN(PhoneNumber.charAt(i)))
			len ++;
	}
	
	if (len < 10) {
		setErrorMsg(6, Phone);
		readySubmit = false;
	}
}

function validateForm(containerId) {
	var requiredFields = $(containerId).getElements('span[class=requiredField]');
	var validationMsgs = $(containerId).getElements('span[class=validationMsg]');
	readySubmit = true;
	if(validationMsgs.length > 0) {
		for (i = 0; i<validationMsgs.length;i++) 
			validationMsgs[i].remove();
	}
	for(i = 0; i < requiredFields.length; i++) {
		var requiredField = requiredFields[i].getChildren()[0];
		if (requiredField.value == '')
			//Ignore fax fields:
			if ( requiredField.getProperty('name').indexOf("fax") == -1 ) {
				setErrorMsg(0, requiredField);	
				readySubmit = false;
			}
		if(requiredField.getProperty('name').indexOf("email") != -1) {
			emailValidation(requiredField);
		}
		if(requiredField.getProperty('name').indexOf("confirm_email") != -1) {
			var emailToMatch = requiredFields[i-1].getChildren()[0];
			emailConfirmValidation(requiredField,emailToMatch);
		}
		if(requiredField.getProperty('name').indexOf("confirm_password") != -1) {
			var passwordToMatch = requiredFields[i-1].getChildren()[0];
			passwordConfirmValidation(requiredField,passwordToMatch);
		}
		if ( ( requiredField.getProperty('name').indexOf("phone") != -1 ) ||
			 ( requiredField.getProperty('name').indexOf("fax") != -1 ) )
			ValidatePhoneNumber(requiredField);
	}
	if(readySubmit) 
		return true;
	else 
		return false;
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

//-------------------------------------------------------------------
// isBlank(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isBlank(val) {
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
}
//-------------------------------------------------------------------
// isDigit(value)
//   Returns true if value is a 1-character digit
//-------------------------------------------------------------------
function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
}
//-------------------------------------------------------------------
// isInteger(value)
//   Returns true if value contains all digits
//-------------------------------------------------------------------
function isInteger(val) {
	if (isBlank(val)){return false;}
	for(var i=0;i<val.length;i++){
		if(!isDigit(val.charAt(i))){return false;}
		}
	return true;
}

function ValidateSearch() {
	var checkStr = trim(document.SearchForm.searchTerm.value);

	if (checkStr.length < 2) {
		alert( "Please enter at least two (2) characters." )
		return false;
	}

	return true;
}

function stateStatus(prefix){	
	$(prefix+'_state_content').getPrevious().setStyle("visibility","visible");
	$(prefix+'_state_content').addClass("requiredField");
	
	if ($(prefix+'_country').getProperty('value') == 'USA' || $(prefix+'_country').getProperty('value') == 'CAN')  {
		//if ($(prefix+'_state').getTag() == 'input') {
			var url = "act_manager.cfm?action=getstates&fieldName="+prefix+"_state&country="+$(prefix+'_country').getProperty('value');
			var log = $(prefix+'_state_content').empty().addClass('ajax-loading');
			var ajax = new Ajax(url, { 
				method: 'get',
				update: log,		
				onComplete: function() {
					log.removeClass('ajax-loading'); 
				}
			}).request();
		//}
	}
	else {
		//if ($(prefix+'_state').getTag() == 'select') {
			if (-1 != prefix.indexOf('new')) {
				state_class = "fullWidthShortInputField";
				state_name = prefix.substring(4,prefix.length+1);			
			}
			else {
				state_class = "columnWidthShortInputField";
				state_name = prefix;
			}
			$(prefix+'_state_content').empty();
			//$(prefix+'_state_content').innerHTML = '<input name="'+state_name+'_state" id="'+prefix+'_state" type="text" class="' + state_class + '" />';
			$(prefix+'_state_content').getPrevious().setStyle("visibility","hidden");
			$(prefix+'_state_content').removeClass("requiredField");
			$(prefix+'_state_content').innerHTML = '<input name="'+state_name+'_state" id="'+prefix+'_state" type="hidden" class="' + state_class + '" />';
		//}											
	}
}
