String.prototype.trim = function () { return this.replace(/^\s+/,'').replace(/\s+$/,''); };
var emailFilter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

function uncheckOthers(formId, id, prefix) {
	var formControl = document.getElementById(formId);
	var elements = formControl.elements;
	for ( var i = 0; i < elements.length; i++) {
		if (elements[i].type == 'radio') {
			if (elements[i].id.indexOf(prefix) != -1 && elements[i].id != id) {
				elements[i].checked = false;
			}
		}
	}
}
function checkInput(theBox, defaultValue, defaultMessage, email) { 
	if (theBox.value == null || theBox.value.trim().length == 0){ 
		alert(defaultMessage); 
		return false; 
	}  
	if (defaultValue != null && defaultValue.trim().length > 0 && theBox.value.trim() == defaultValue){ 
		alert(defaultMessage);
		return false;
	} 
	if (email != null && email){
		if (emailFilter.test(theBox.value.trim()) == false) {
			alert('Your email address ['+theBox.value+'] is invalid, please re-enter');
			return false;
		}
	}
	return true; 
}
function updateSameAsBilling(theBox, target){ 
	if (theBox != null){ 
		if (theBox == '2'){  			
			if (target != null){ 
				target.checked = false;
			}	 
		}  
	}  
}
function Priority_info(x) {
	if (x == "show") {
		document.getElementById("Priority_info_box").style.display = "block";
	}
	else if (x == "hide"){
		document.getElementById("Priority_info_box").style.display = "none";
	}
} 
function open_win3(zoom) {
	var new_Window3 = window.open(zoom, "new_Window3", "HEIGHT=670,WIDTH=550,scrollbars=no,menubar=no");
}

function open_win360(zoom360) {
	var new_Win360 = window.open(zoom360, "new_Win360", "HEIGHT=670,WIDTH=550,scrollbars=no,menubar=no");
}

//QuickView	 
function showQVButton(buttonNumber) {
	document.getElementById("quickDetailButton" + buttonNumber).style.display = "";
}
function hideQVButton(buttonNumber) {
	document.getElementById("quickDetailButton" + buttonNumber).style.display = "none";
}
function swapImageIn(i,imgPath) {		
	document.getElementById("qImg_"+i).src=imgPath+"/images/quick_detail_button_over.gif";	
}
function swapImageOut(i,imgPath) {		
	document.getElementById("qImg_"+i).src=imgPath+"/images/quick_detail_button.gif";	
}
function swapBrandImageIn(i,imgPath,brandName) {		
	document.getElementById("qImg_"+i).src=imgPath+"/images_"+brandName+"/quick_detail_button_over.gif";	
}
function swapBrandImageOut(i,imgPath,brandName) {		
	document.getElementById("qImg_"+i).src=imgPath+"/images_"+brandName+"/quick_detail_button.gif";	
}
//end of quickView	 


// BEGIN EMAIL VALIDATION SCRIPTS
var form; 

function emptyBox(theBox) {
	if ((theBox.value == null) || (theBox.value.length == 0))
		return true;
	else
		return false;
}

function emailSelect(theForm) {

	if (theForm.submissiontype[0].checked == false && theForm.submissiontype[1].checked == false) {
		alert('Please select subscribe or unsubscribe');
		return false;
	}

	if (theForm.submissiontype[0].checked == true) {
		return emailSignup(theForm);
		}
	else if (theForm.submissiontype[1].checked == true) { 
		return emailSignupRemove(theForm);
	}

	return false;
}

function emailSignup(theForm) {
	
	if (emptyBox(theForm.emailAddress)) {
		alert('Please enter your email address');
		return false;
	}
	
	if (emailFilter.test(theForm.emailAddress.value) == false) {
		alert('Your email address is invalid, please re-enter');
		return false;
	}
	
	if (emptyBox(theForm.Store)) {
		alert('Process setup incorrectly');
		return false;
	}
		
	var parms = new Array();
	parms[parms.length] = theForm.emailAddress.value;
	parms[parms.length] = theForm.Store.value;
	parms[parms.length] = window.location.hostname;
			
	// jsrsExecute("/common/comm/emailSignup/server.asp", emailSignupCallBack,
	// "emailSignup", parms, false);
	
	form = theForm;
	
	return false;
}

function emailSignupCallBack(str) {
	
	if (str.substr(0, 5) != 'ERROR')
		form.reset();
		
	alert(str);		
}

function emailSignupRemove(theForm) {
		
	if (emptyBox(theForm.emailAddress)) {
		alert('Please enter your email address');
		return false;
	}
	
	if (emailFilter.test(theForm.emailAddress.value) == false) {
		alert('Your email address is invalid, please re-enter');
		return false;
	}
	
	if (emptyBox(theForm.Store)) {
		alert('Process setup incorrectly');
		return false;
	}
		
	var parms = new Array();
	parms[parms.length] = theForm.emailAddress.value;
	parms[parms.length] = theForm.Store.value;
	parms[parms.length] = window.location.hostname;
			
	// jsrsExecute("/common/comm/emailSignup/server.asp", emailSignupCallBack,
	// "emailRemove", parms, false);
	
	form = theForm;
	
	return false;
}
//END EMAIL VALIDATION SCRIPTS

function showHide (id) {
	var style = document.getElementById(id).style;
	if (style.visibility == "hidden"){
		style.visibility = "visible";
	}else{
		style.visibility = "hidden";
	}
	
}
function clearAge(idPrefix){
	var elem = idPrefix;
	if (elem){  
		var age = document.getElementById(elem+"day"); 
		if(age){
			if (age.value == "DD"){
				age.value = null;
			}
		} 
		age = document.getElementById(elem+"month"); 
		if(age){
		    if (age.value == "MM"){
		    	age.value = null;
			}
		} 		 		
		age = document.getElementById(elem+"year"); 
		if(age){
		    if (age.value == "YYYY"){
		    	age.value = null;
			}
		} 		 		

	}
}
function initAge(idPrefix){
	var elem = idPrefix;
	if (elem){  
		var age = document.getElementById(elem+"day"); 		
		if(age){			 
			if (age.value == null || age.value.trim().length == 0 || age.value == 'null'){
				age.value = "DD";
			} 
		} 
		age = document.getElementById(elem+"month");  
		if(age){  
			if (age.value == null || age.value.trim().length == 0 || age.value == 'null'){
				age.value = "MM";
			} 
		} 
		age = document.getElementById(elem+"year"); 
		if(age){
			if (age.value == null || age.value.trim().length == 0 || age.value == 'null'){
				age.value = "YYYY";
			} 
		} 
	} 
}

function closeSoftPop() {

killSoftPop = 1;
softPopWindow = window.open("","softPopWindow","status=1,width=350,height=150");

softPopWindow.close();

}

// Limit the # of characters by truncating to the specified length
function messageLimit(messageArea, length) {
	if (messageArea.value.length > length) {
		messageArea.value = messageArea.value.substring(0, length);
	} 
}

