/*
Copyright 2005 Active Media Architects, Inc. - www.activema.com
Usage of these scripts is limited to their original intent as developed and deployed for Acufinder.com by Active Media Architects, Inc. Copying, selling or distributing of these scripts, in whole or in part, is strictly prohibited.
*/

// Country codes for form checking
var UNITED_STATES = 62;
var CANADA = 8;

///////////////////////////////////////
// Frame Buster
///////////////////////////////////////

if (window != window.top)
  top.location.href = location.href;

//A static event registering object - better way to register things like body onloads etc
//This also masks the difference between Mozilla and IE
var EventRegister = { 
	registered_events: [],
	
	add: function(elem, event_name, func, capture)
	{
		var arr_temp = new Array();
		arr_temp['elem'] = elem;
		arr_temp['event_name'] = event_name;
		arr_temp['func'] = func;
		arr_temp['capture'] = capture;
					
		if ( elem.addEventListener ) {
			//Standards
			elem.addEventListener(event_name, func, capture);
			
		} else if ( elem.attachEvent ) {
			//IE
			if ( !elem.attachEvent('on'+event_name, func) ) {
				return false;	
			}
			
		} else {
			return false; 
				
		}	
		
		return true;	
	}
};


EventRegister.add(window, 'load', handleFocus, false);


function handleFocus()
{
	var arr_inputs = document.getElementsByTagName('input');
	for ( var i=0; i<arr_inputs.length; i++ ) {
		if ( arr_inputs[i].type == "text" ) { 
			if ( arr_inputs[i].name == "loginemail" ) {
				arr_inputs[i].focus();
				return;
			}
		}
	}
}

///////////////////////////////////////
// On-Click-Pop-Center
///////////////////////////////////////
// Requires "onClick="NewWindow(this.href,'title','400','300','no');return false;"" in the A HREF tag
// Example: <a href="doc.html" onClick="NewWindow(this.href,'title','400','300','no');return false;">LINK</a>

function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes,,toolbar=no,menubar=no'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function NewFullWindow(mypage, myname, w, h) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable=yes,,toolbar=yes,menubar=yes'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}


/**
* @param FormElement elem
* @param String test_for
* @param String replace
* @desc This function is for use with those nifty text fields that have a default value like 'First Name Here'
*/
function monitor_value(elem, test_for, replace)
{
	if ( elem.value == test_for ) {
		elem.value = replace;
	}
	
}//end monitor_val


///////////////////////////////////////
// Auto-Select Field
///////////////////////////////////////
// Requires "onLoad=ready()" in the BODY tag
// Example: <body onLoad=ready()>
// Requires form name to match where it reads "form" in script
// Example: <form name="form">
// Requires form field name to match where it reads "field" in script
// Example: <input name="field">

function ready(){document.form.field.focus();}

///////////////////////////////////////
// Form Validation
///////////////////////////////////////
function ValidateListingSearch_Basic(form)
{
	var elem_country = form.elements['country'];
	var elem_city = form.elements['city'];
	var elem_zip = form.elements['zip'];
	var elem_distance = form.elements['distance'];
	var has_zip = false;
	
	if ( elem_country.value == '' ) {
		alert('Please indicate a country to search within.');
		elem_country.focus();
		return false;
	} else if ( elem_country.value == UNITED_STATES ) {
		if ( elem_zip.value != '' ) {
			if ( !isZIPCode(elem_zip.value) || elem_zip.value.length != 5 ) {
				alert('This field must be a 5 digit U.S. ZIP Code (like 90405). Please re-enter it before you continue.');
				elem_zip.focus();
				return false;
			} else {
				if ( elem_zip.value != "Enter Zip/Postal Code" ) {
					has_zip = true;	
				}
			}
		}	
	} else if ( elem_country.value == CANADA ) {
		if ( elem_zip.value != '' ) {
			if ( elem_zip.value.length != 7 ) {
				alert('This field must be a 7 character Canadian ZIP Code (like A0A 1A0). Please re-enter it before you continue.');
				elem_zip.focus();
				return false;
			} else {
				if ( elem_zip.value != "Enter Zip/Postal Code" ) {
					has_zip = true;	
				} 	
			}	
		}
	} else {
		elem_city.value = '';
		return true;	
	}
	
	if ( has_zip && elem_distance.value == '' ) {
		alert("Please indicate a distance to search from " + elem_zip.value + ".");
		elem_distance.focus();
		return false;
	}
	
	if ( elem_distance.value != '' && !has_zip && elem_city.value == '' ) {
		alert("Please indicate a zip code to center the search around.");
		elem_zip.focus();
		return false;
	}
}

function validateGiftCertificate ( form ) {
	return (
				 checkSelect(form.elements["amount"],"V","","Please enter an amount.",false) &&
				 checkSelect(form.elements["recipient_name"],"V","Please enter recipient's name",false) &&
				 checkSelect(form.elements["recipient_email"],"V","","Please enter your recipient's E-mail Address.",false) &&
				 checkEmail(form.elements["recipient_email"],false) &&
				 checkSelect(form.elements["recipient_email"],"V","joe@example.com","Please supply valid E-mail Address.",false));	
}

function validateTell(form) {
	return (
				 checkSelect(form.elements["to_email"],"V","","Please enter your Friend's E-mail Address.",false) &&
				 checkEmail(form.elements["to_email"],false) &&
				 checkSelect(form.elements["to_email"],"V","joe@example.com","Please supply valid E-mail Address.",false) &&
				 checkSelect(form.elements["from_email"],"V","","Please enter Your E-mail Address.",false) &&
				 checkEmail(form.elements["from_email"],false) &&
				 checkSelect(form.elements["from_email"],"V","joe@example.com","Please supply valid E-mail Address.",false) &&
				 checkSelect(form.elements["from_name"],"V","","Please enter Your Name.",false));
}

function validateContactSchool(form) {
	return (
				 checkSelect(form.elements["contact[firstname]"],"V","","Please enter your First Name.",false) &&
				 checkSelect(form.elements["contact[lastname]"],"V","","Please enter your Last Name.",false) &&
				 checkSelect(form.elements["contact[email]"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["contact[email]"],false) &&
				 checkSelect(form.elements["contact[email]"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
				 checkSelect(form.elements["contact[message]"],"V","","Please provide us with your Questions or Comments so we can better respond to you.",false));
}

function validateContact(form) {
	return (
				 checkSelect(form.elements["firstname"],"V","","Please enter your First Name.",false) &&
				 checkSelect(form.elements["lastname"],"V","","Please enter your Last Name.",false) &&
				 checkSelect(form.elements["email"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["email"],false) &&
				 checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
				 checkSelect(form.elements["message"],"V","","Please provide us with your Message.",false));
}

function validateContactPract(form) {
	return (
				 checkSelect(form.elements["firstname"],"V","","Please enter your First Name.",false) &&
				 checkSelect(form.elements["lastname"],"V","","Please enter your Last Name.",false) &&
				 checkSelect(form.elements["email"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["email"],false) &&
				 checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
				 checkSelect(form.elements["message"],"V","","Please provide us with your Message.",false));
}

function validateAskQuestion(form) {
	return (
				 checkSelect(document.getElementById( "firstname" ),"V","","Please enter your First Name.",false) &&
				 checkSelect(document.getElementById( "lastname"),"V","","Please enter your Last Name.",false) &&
				 checkSelect(document.getElementById( "questionemail"),"V","","Please enter your E-mail.",false) &&
				 checkEmail(document.getElementById( "questionemail"),false) &&
				 checkSelect(document.getElementById( "questionemail"),"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
				 checkSelect(document.getElementById( "question"),"V","","Please enter a question for us to answer.",false));
}

function validateEmailSignup(form) {
	return (
				 checkSelect(form.elements["firstname"],"V","","Please enter your First Name.",false) &&
				 checkSelect(form.elements["firstname"],"V","First Name","Please enter your real First Name.",false) &&
				 checkSelect(form.elements["lastname"],"V","","Please enter your Last Name.",false) &&
				 checkSelect(form.elements["lastname"],"V","First Name","Please enter your real Last Name.",false) &&
				 checkSelect(form.elements["email"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["email"],false) &&
				 checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false));
}

function validateUnsub(form) {
	return (
				 checkSelect(form.elements["email"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["email"],false) &&
				 checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false));
}

function validateLogin(form) {
	return (
				 checkSelect(form.elements["email"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["email"],false) &&
				 checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
				 checkSelect(form.elements["password"],"V","","Please enter your Password.",false));
}

function validateNewLogin(form) {
	if (
		 checkSelect(form.elements["account[email]"],"V","","Please enter your E-mail.",false) &&
		 checkEmail(form.elements["account[email]"],false) &&
		 checkSelect(form.elements["account[email]"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
		 checkSelect(form.elements["account[password1]"],"V","","Please create a Password.",false) &&
		 checkSelect(form.elements["account[password2]"],"V","","Please confirm your Password.",false)
	) {
		var checked = false;
		for ( i=0; i<form.elements["account[practitioner]"].length; i++ ) {
			if ( form.elements["account[practitioner]"][i].checked == true ) {
				checked = true;
			}
		}
		
		if ( !checked ) {
			alert("Please specify if you are a Certified Acupuncture Professional.");
			return false;
		} else {
			return (
				checkSelect(form.elements["account[firstname]"],"V","","Please enter your first name.",false) &&
				checkSelect(form.elements["account[lastname]"],"V","","Please enter your last name.",false) &&
				checkSelect(form.elements["account[country]"],"V","","Please enter your country.",false) &&
				(
	 			(( form.elements["account[country]"].value == "62" || form.elements["account[country]"].value == "8" ) &&
	 			checkSelect(form.elements["account[state]"],"V","","Please enter your state.",false) ) || 
	 			(( form.elements["account[country]"].value != "62" && form.elements["account[country]"].value != "8" ) &&
	 			checkSelect(form.elements["account[province]"],"V","","Please enter your province.",false) )
		 		));
		}
	} else {
		return false;
	}
}

function validatePay(form) {
	return (
				validateBillingAddress(form) && 
				checkSelect(form.elements["billing[cc_num]"],"V","","You have chosen to pay by Credit Card. Please enter your Credit Card Number before continuing.",false) &&
				checkSelect(form.elements["billing[exp_month]"],"V","00","Please select the Month this credit card expires.",false) &&
				checkSelect(form.elements["billing[exp_year]"],"V","00","Please select the Year this credit card expires.",false) &&
				checkSelect(form.elements["billing[ccv]"],"V","","Please enter your credit card's 3-digit Identification Number.",false));
}

function validatePractEmailSignup(form) {
	if ("First Name" == form.elements["firstname"].value || "" == form.elements["firstname"].value) {
		$submitable = false;
		alert("Please Enter Your First Name");
		return false;
	}
	if ("Last Name" == form.elements["lastname"].value || "" == form.elements["lastname"].value) {
		$submitable = false;
		alert("Please Enter Your Last Name");
		return false;
	}
	if (!isEmail(form.elements["email"].value)) {
		$submitable = false;
		alert("Please Enter Your E-mail Address");
		return false;
	}
	return true;
}

function listingValidatePay(form)
{
	return (
		checkCheckbox(form.elements['agreement'], "Please check the agreement box indicating that the information you are submitting is accurate") &&
		validatePay(form)
	);
}//end listingValidatePay

function listingValidatePayPal(form)
{
	return checkCheckbox(form.elements['agreement'], "Please check the agreement box indicating that the information you are submitting is accurate")

}

function validateSignin(form) {
	return (
				 checkSelect(form.elements["loginemail"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["loginemail"],false) &&
				 checkSelect(form.elements["loginemail"],"V","joe@example.com","Please supply valid E-mail Address.",false) &&				 
				 checkSelect(form.elements["password"],"V","","Please enter your Password.",false));
}

function validatePO(form)
{
	if (
		checkSelect(form.elements["po_number"],"V","","Please enter the PO Number.",false)
	) {
		//the PO was ok - check the shipping
		return validateShippingAddress(form);
	} else {
		//the PO was empty, return false
		return false;	
	}
	
}//end validatePO

function validateBillingAddress(form)
{
	return ( checkSelect(form.elements["billing[fullname]"],"V","","Please enter the billing Full Name.",false) &&
		 checkSelect(form.elements["billing[address]"],"V","","Please enter the billing Address.",false) &&
		 checkSelect(form.elements["billing[city]"],"V","","Please enter the billing City.",false) && 
		 ( 
		 	( form.elements["billing[country]"].value == 220 && checkSelect(form.elements["billing[state]"],"V","","Please enter the billing State/Prov.",false)) ||
		 	( form.elements["billing[country]"].value == 37 && checkSelect(form.elements["billing[province]"],"V","","Please enter the billing State/Prov.",false)) ||
		 	( form.elements["billing[country]"].value != 37 && form.elements["billing[country]"].value != 220)
		 ) && 
		 checkSelect(form.elements["billing[zip]"],"V","","Please enter the billing ZIP.",false) && 
		 checkSelect(form.elements["billing[phone]"],"V","","Please enter the billing Phone.",false));


}//end validateBillingAddress

function validateEmailme(form) {
	return (
		checkSelect(form.elements["recipient"],"V","","Please enter the Recipient's Name.",false) &&
		checkSelect(form.elements["to"],"V","","Please enter the Recipient's E-mail Address.",false) &&
		checkEmail(form.elements["to"],false) &&
	 	checkSelect(form.elements["to"],"V","joe@example.com","Please supply valid E-mail Address.",false) &&
	 	checkSelect(form.elements["comments"],"V","","Please enter the Message.",false) &&
	 	checkSelect(form.elements["sender"],"V","","Please enter Your Name.",false) &&
		checkSelect(form.elements["from"],"V","","Please enter Your E-mail Address.",false) &&
	 	checkEmail(form.elements["from"],false) &&
		checkSelect(form.elements["from"],"V","joe@example.com","Please supply valid E-mail Address.",false));
}

function checkPasswords(form) {
	
	if ( form.elements["password1"].value != form.elements["password1"].value ) {
		alert("Your passwords does not match.  Please enter re-enter your passwords");
		return false;
	} else {
		return true;
	}
	
}

function validateExpressPurchase(form)
{
	if ( 
		
		checkSelect(form.elements["email_address"],"V","","Please enter your E-mail.",false) &&
		checkEmail(form.elements["email_address"],false) &&
		checkSelect(form.elements["email_address"],"V","joe@example.com","Please supply valid E-mail Address.",false) &&		
		checkSelect(form.elements["billing_fullname"],"V","","Please enter the billing Full Name.",false) &&
		checkSelect(form.elements["billing_address"],"V","","Please enter the billing Address.",false) &&
		checkSelect(form.elements["billing_address"],"V","","Please enter the billing Address.",false) &&
		checkSelect(form.elements["billing_city"],"V","","Please enter the billing City.",false) && 
		checkSelect(form.elements["billing_state"],"V","","Please enter the billing State/Prov.",false) && 
		checkSelect(form.elements["billing_zip"],"V","","Please enter the billing ZIP.",false) && 
		checkSelect(form.elements["billing_phone"],"V","","Please enter the billing Phone.",false)) 
	
	{
		//All billing was ok - check shipping and return it
		return validateShippingAddress(form);
		
	} else {
		//something was false
		return false;	
	}

}//end validateBillingAddress

function validateBillingAddress1(form)
{
	if (
		//checkSelect(form.elements["billing_fullname"],"V","","Please enter the billing First Name.",false) &&
		//checkSelect(form.elements["billing_lastname"],"V","","Please enter the billing Last Name.",false) &&
		checkSelect(form.elements["billing_fullname"],"V","","Please enter the billing Full Name.",false) &&
		checkSelect(form.elements["billing_address"],"V","","Please enter the billing Address.",false) &&
		checkSelect(form.elements["billing_city"],"V","","Please enter the billing City.",false) && 
		checkSelect(form.elements["billing_state"],"V","","Please enter the billing State/Prov.",false) && 
		checkSelect(form.elements["billing_zip"],"V","","Please enter the billing ZIP.",false) && 
		checkSelect(form.elements["billing_phone"],"V","","Please enter the billing Phone.",false) 
		//checkSelect(form.elements["billing_country"],"V","","Please enter the billing Country.",false)
	) {
		//All billing was ok - check shipping and return it
		return validateShippingAddress(form);
		
	} else {
		//something was false
		return false;	
	}

}//end validateBillingAddress

function validateBillingAddress2(form)
{
	if (
		//checkSelect(form.elements["billing_fullname"],"V","","Please enter the billing First Name.",false) &&
		//checkSelect(form.elements["billing_lastname"],"V","","Please enter the billing Last Name.",false) &&
		checkSelect(form.elements["billing_fullname"],"V","","Please enter the billing Full Name.",false) &&
		checkSelect(form.elements["billing_address"],"V","","Please enter the billing Address.",false) &&
		checkSelect(form.elements["billing_city"],"V","","Please enter the billing City.",false) && 
		checkSelect(form.elements["billing_state"],"V","","Please enter the billing State/Prov.",false) && 
		checkSelect(form.elements["billing_zip"],"V","","Please enter the billing ZIP.",false) && 
		checkSelect(form.elements["billing_phone"],"V","","Please enter the billing Phone.",false) 
		//checkSelect(form.elements["billing_country"],"V","","Please enter the billing Country.",false)
	) {
		//All billing was ok - check shipping and return it
		return true;
		
	} else {
		//something was false
		return false;	
	}

}//end validateBillingAddress

function validateShippingAddress(form)
{
	return (
		checkSelect(form.elements["ship_fullname"],"V","","Please enter the shipping full name.",false) &&
		checkSelect(form.elements["ship_phone"],"V","","Please enter the shipping Phone.",false) &&
		checkSelect(form.elements["ship_address"],"V","","Please enter the shipping Address.",false) &&
		checkSelect(form.elements["ship_city"],"V","","Please enter the shipping City.",false) && 
		checkSelect(form.elements["ship_state"],"V","","Please enter the shipping State/Prov.",false) && 
		checkSelect(form.elements["ship_zip"],"V","","Please enter the shipping ZIP.",false) 
	);
}//end validateShippingAddress

function validateExpressPurchase(form)
{
	return (
		checkSelect(form.elements["email_address"],"V","","Please enter your email address..",false) &&
		checkSelect(form.elements["ship_fullname"],"V","","Please enter the shipping full name.",false) &&
		checkSelect(form.elements["ship_phone"],"V","","Please enter the shipping Phone.",false) &&
		checkSelect(form.elements["ship_address"],"V","","Please enter the shipping Address.",false) &&
		checkSelect(form.elements["ship_city"],"V","","Please enter the shipping City.",false) && 
		checkSelect(form.elements["ship_state"],"V","","Please enter the shipping State/Prov.",false) && 
		checkSelect(form.elements["ship_zip"],"V","","Please enter the shipping ZIP.",false) 
	);
}//end validateShippingAddress

function verifyNewsletter(form)
{
	return (
		checkSelect(form.elements["firstname"],"V","","A first name is required.",false) &&
		checkSelect(form.elements["lastname"],"V","","A last name is required.",false) &&
		checkSelect(form.elements["email"],"V","","An e-mail address is required.",false) && 
		checkEmail(form.elements["email"],false)
	);
}//end verifyNewsletter

function validatePaypalForm()
{	
	if (document.getElementById('billing_state').value.length == 0) {
		alert ("Please enter the billing state.");
		return false;
	} else {
		return true;
	}
}//end validateShippingAddress

function validateExpress(form)
{
	if (
		checkSelect(form.elements["email_address"],"V","","Please enter your email address.",false)
	) {
		return validateShipping(form);
	}

	return false;
}

function validateNewAccount(form, checkShipping)
{
	if (
		checkSelect(form.elements["account[firstname]"],"V","","Please enter your first name.",false) &&
		checkSelect(form.elements["account[lastname]"],"V","","Please enter your last name.",false) &&
		checkSelect(form.elements["account[email]"],"V","","Please enter your E-mail.",false) &&
		checkEmail(form.elements["account[email]"],false) &&
		checkSelect(form.elements["account[email]"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
		checkSelect(form.elements["account[password1]"],"V","","Please create a Password.",false) &&
		checkSelect(form.elements["account[password2]"],"V","","Please confirm your Password.",false)
	) {
		if ( checkShipping ) {
			return validateShipping(form);
		} else {
			return true;
		}
	}

	return false;
}

function validateShipping(form)
{
	return (
		checkSelect(form.elements["shipping[fullname]"],"V","","Please enter the shipping full name.",false) &&
		checkSelect(form.elements["shipping[address]"],"V","","Please enter the shipping Address.",false) &&
		checkSelect(form.elements["shipping[city]"],"V","","Please enter the shipping City.",false) &&
		//checkSelect(form.elements["ship_state"],"V","","Please enter the shipping State/Prov.",false) &&
		checkSelect(form.elements["shipping[zip]"],"V","","Please enter the shipping ZIP.",false) &&
		checkSelect(form.elements["shipping[phone]"],"V","","Please enter the shipping Phone.",false)
	);
}

function checkProfile(form)
{
	var arrElements = new Array("fullname","address", "city", "state", "zip");
	var len = arrElements.length;
	var i = 0;
	
	for ( i=0; i<len; i++ ) {
		if ( form.elements['billing_'+arrElements[i]].value != form.elements['hidden_billing_'+arrElements[i]].value ) {
			form.elements['profilecontrol'].value = 'change';	
		}
		
	}//for
	
	//alert(form.elements['profilecontrol'].value);
	
	//and one by hand
	if ( form.elements['cc_type'].value != form.elements['hidden_cc_type'].value ) {
		form.elements['profilecontrol'].value = 'change';
	}
	
	return validateBillingAddress(form);
	
}//end checkProfile

////////////////////////////////////////////////
// disabling and enabling shipping info fields
////////////////////////////////////////////////

function toggleFields(form)
{
	var toggle = form.elements['same_as_billing'];
	
	var arrShipFields = new Array('ship_fullname', 'ship_address', 'ship_city', 'ship_state', 'ship_zip', 'ship_phone');
	var fieldShipCount = arrShipFields.length;
	
	var arrBillFields = new Array('billing_fullname', 'billing_address', 'billing_city', 'billing_state', 'billing_zip', 'billing_phone');
	var fieldBillCount = arrBillFields.length;
	
	var i = 0;
	
	if (toggle.checked == false) {
		//Already checked, unset everything
		for ( i=0; i<fieldShipCount; i++) {
			form.elements[arrShipFields[i]].value = "";
		}//for	
	
	} else {
		//Not yet checked, copy the values from billing
		for ( i=0; i<fieldShipCount; i++) {
			form.elements[arrShipFields[i]].value = form.elements[arrBillFields[i]].value;
		}//for	
	}
	
}//end toggleFields

function toggleSaveProfile(elem) {
	var form = elem.form;
	
	//valid values are insert, donotupdate, and update
	if (elem.checked == true) {
		form.elements['profilecontrol'].value = 'insert';
				
	} else {
		form.elements['profilecontrol'].value = 'donotupdate';
		
	}
	
	//alert(form.elements['profilecontrol'].value);
	
}//end toggleSaveProfile

function checkField() {
	var frm = document.search_store;
	
	if ( (frm.p_keyword.value == "" ) || (frm.p_keyword.value == " " ) ) {
		
		alert("A Keyword is required to search");
		return false;			
	}
	
}


function checkEmailSignup() {

	var frm = document.emailSignup;
	
	if ( (frm.firstname.value == "" ) || (frm.firstname.value == " " ) ) {
		
		alert("First name is required");
		return false;			
	}
	
	if ( (frm.lastname.value == "" ) || (frm.lastname.value == " " ) ) {
		alert("Last name is required");
		return false;	
	}	
	
	if ( (frm.email.value == "") || (frm.email.value == " ") ) {
		
		alert("E-mail is required");
		return false;	
	}
	
	return true;
	
}
function LoginOptionCheck(myself) {

	//frm = document.forms['new_login'];
	frm = myself.form;
	// if the new Customer item is checked
	var elem_pass_new = document.getElementById('newcustomerpassword');
	var elem_pass_old = document.getElementById('returningcustomerpassword');
	
	if ( myself.value == "new" ) {
		elem_pass_old.disabled = true;
		elem_pass_old.style.display = "none";
		elem_pass_new.disabled = true;
		elem_pass_new.style.display = "";
		//frm.elements['action'].value = "account_new";
		
	} else {
	
		elem_pass_old.disabled = false;
		elem_pass_old.style.display = "";
		elem_pass_new.disabled = true;
		elem_pass_new.style.display = "none";
        frm.elements['loginemail'].focus();
		//frm.elements['action'].value = "account";
		
	}
	
	frm.elements['loginemail'].focus();
}


function focusLoginField() {
	if ( typeof(document.new_login) != "undefined" ) {
		document.new_login.loginemail.focus();
	}
}

function loadPreview() {

	var caption_value = window.opener.document.getElementById("caption").value;
	var headline_obj = window.opener.document.getElementById("headline");
	var body_obj = window.opener.document.getElementById("body");
	var child_head = document.getElementById("headline");
	var child_body = document.getElementById("body");
	var child_caption = document.getElementById("img_caption");
	
	if ( caption_value != '' && child_caption != null ) {
		
		child_caption.innerHTML = caption_value;
	}
	child_head.innerHTML = headline_obj.value;
	child_body.innerHTML = body_obj.value;
	
}

function doProfileChange() {
	//document.getElementById('update_profile').style.display = "inline";
}

function fadeout() {
	for (var iterator = 0; iterator < arguments.length; iterator++) {
		arguments[iterator].value = '';
		arguments[iterator].disabled = true;
	}
}

function fadein() {
	for (var iterator = 0; iterator < arguments.length; iterator++) {
		arguments[iterator].disabled = false;
	}
	arguments[1].focus();
	arguments[1].select();
}

function handleStateChange(elem)
{
	if ( elem.value != '' ) {
		//The value changed and now it's soemething
		//hide providence
		document.getElementById("province_tr").style.display = "none";
		elem.form.elements['province'].value = '';
		elem.form.elements['province'].disabled = true;
		
		//auto select US
		elem.form.elements['country'].value = 62;	 
		
	}
	
}//end handleStateChange

function handleProvinceChange(elem)
{
	if ( elem.value != '' ) {
		//Something is still in there...hide the state drop down
		document.getElementById("state_tr").style.display = "none";
		elem.form.elements['state'].value = '';
		elem.form.elements['state'].disabled = true;
		
	}
	
}//end handleProvinceChange

function handleCountryChange(elem)
{
	if ( elem.value == 62 ) {
		elem.form.elements['state'].disabled = false;
		document.getElementById("state_tr").style.display = "";
		
		document.getElementById("province_tr").style.display = "none";
		elem.form.elements['province'].value = '';
		elem.form.elements['province'].disabled = true;
		
			
	} else {
		document.getElementById("state_tr").style.display = "none";
		elem.form.elements['state'].value = '';
		elem.form.elements['state'].disabled = true;
		
		elem.form.elements['province'].disabled = false;
		document.getElementById("province_tr").style.display = "";	
		
	}
	
}//end handleCountryChange


///////////////////////////////////////
// Validate List Pract 1
///////////////////////////////////////

function validateListPract1(form) 
{
	var returnvalue = true;	
	
	if ( form.elements['email'] ) {
		returnvalue = ( 
			checkSelect(form.elements["email"],"V","","Please enter your E-mail.",false) &&
			checkEmail(form.elements["email"],false) &&
			checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
			checkSelect(form.elements["password1"],"V","","Please create a Password.",false) &&
			checkSelect(form.elements["password2"],"V","","Please confirm your Password.",false)
		);
		if ( returnvalue == false ) {
			return false;	
		}
	}
	
	if ( form.elements['practitioner_plan'] != null && form.elements['practitioner_plan'].disabled == false ) {	
		//Now, check that a plan is selected
		var obj_rg = new RadioGroup();
		obj_rg.init(form, "practitioner_plan");
		if ( obj_rg.getValue() == null ) {
			alert("Please select a subscription plan from the Available Plans.");
			return false;
		}
	}

	if (
		checkSelect(form.elements["practice[firstname]"],"V","","Please enter your First Name.",false) &&
		checkSelect(form.elements["practice[lastname]"],"V","","Please enter your Last Name.",false) &&
		checkSelect(form.elements["practice[title]"],"V","","Please enter your Credentials.",false)
		)
	{
		for ( var i=1; i<=3; i++ ) {
			if ( document.getElementById('location'+i).style.display == "" ) {
				if ( checkSelect(form.elements["company_country"+i],"V","","Please select your country.",false) &&
					checkSelect(form.elements["address"+i],"V","","Please enter your address.",false) &&
				 	checkSelect(form.elements["city"+i],"V","","Please enter your city.",false) &&
				 	(
			 			(( form.elements["company_country"+i].value == "62" || form.elements["company_country"+i].value == "8" ) &&
			 			checkSelect(form.elements["company_state"+i],"V","","Please enter your state.",false) ) || 
			 			(( form.elements["company_country"+i].value != "62" && form.elements["company_country"+i].value != "8" ) &&
			 			checkSelect(form.elements["company_province"+i],"V","","Please enter your province.",false) )
				 	) &&
				 	checkSelect(form.elements["zip"+i],"V","","Please enter your zip.",false) &&
				 	checkSelect(form.elements["phone"+i],"V","","Please enter your phone number.",false)) {
				} else {
					return false;
				}
			}	
		}
	} else {
		return false;
	}
}

/*function validateSchoolInfo(form) 
{
	
	var returnvalue = true;
	
	
	//Email isn't always going to be there...
	if ( form.elements['email'] ) {
		returnvalue = ( 
							checkSelect(form.elements["email"],"V","","Please enter your E-mail.",false) &&
							checkEmail(form.elements["email"],false) &&
							checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
							checkSelect(form.elements["password1"],"V","","Please create a Password.",false) &&
							checkSelect(form.elements["password2"],"V","","Please confirm your Password.",false)
					  );
		if ( returnvalue == false ) {
			return false;	
		}
		
		
	}
	
	if ( form.elements['school_plan'] != null ) {	
		//Now, check that a plan is selected
		var obj_rg = new RadioGroup();
		obj_rg.init(form, "school_plan");
		if ( obj_rg.getValue() == null ) {
			alert("Please select a subscription plan from the Available Plans.");
			return false;
				
		} 	
	
	}
	
	if (
		checkSelect(form.elements["school_name"],"V","","Please enter a name for this school.",false) &&
		checkSelect(form.elements["title"],"V","","Please enter your title.",false))
	{
		for ( var i=1; i<=3; i++ ) {
			try {
				if ( document.getElementById('location'+i).style.display == "" ) {
					if (
						checkSelect(form.elements["school"+i],"V","","Please enter your business name.",false) &&
					 	checkSelect(form.elements["address"+i],"V","","Please enter your address.",false) &&
					 	checkSelect(form.elements["city"+i],"V","","Please enter your city.",false) &&
					 	(
					 			
					 		(( form.elements["school_country"+i].value == "62" || form.elements["school_country"+i].value == "8" ) &&
			 				checkSelect(form.elements["school_state"+i],"V","","Please enter your state.",false) ) || 
			 				(( form.elements["school_country"+i].value != "62" && form.elements["school_country"+i].value != "8" ) &&
			 				checkSelect(form.elements["school_province"+i],"V","","Please enter your province.",false) )
							 		
					 		
					 	) &&
					 	checkSelect(form.elements["zip"+i],"V","","Please enter your zip.",false) &&
					 	checkSelect(form.elements["company_country"+i],"V","","Please enter your country.",false) &&
					 	checkSelect(form.elements["phone"+i],"V","","Please enter your phone number.",false)) {
					} else {
			
						return (false);
					}
				}
				
			} catch( e ) {
				
			}
				
			
			
		}//for
	} else {
	
		return (false);
	}
}*/
///////////////////////////////////////


///////////////////////////////////////
// Validate List Pract 2
///////////////////////////////////////
function validateListPract2(form) {
	return (
		checkSelect(form.elements["license[0][type]"],"V","","Please enter your License Type. You must have at least one license.",false) &&
		checkSelect(form.elements["license[0][number]"],"V","","Please enter your License Number.",false) &&
		checkSelect(form.elements["license[0][expiration_date]"],"V","","Please enter your License Expiration Date.",false));
}
///////////////////////////////////////


function validateListPractFree(form) 
{
	var returnVal = true;
	if ( form.elements["email"] ) {
		returnVal = checkSelect(form.elements["email"],"V","","Please enter your E-mail.",false) &&
		checkEmail(form.elements["email"],false) &&
		checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
		checkSelect(form.elements["password1"],"V","","Please create a Password.",false) &&
		checkSelect(form.elements["password2"],"V","","Please confirm your Password.",false);	
	}
	
	if ( !returnVal ) {
		return false;	
	}
	
	var returnVal = true;
	
	returnVal = checkSelect(form.elements["practice[firstname]"],"V","","Please enter your First Name.",false) &&
		checkSelect(form.elements["practice[lastname]"],"V","","Please enter your Last Name.",false) &&
		checkSelect(form.elements["practice[title]"],"V","","Please enter your Credentials.",false) &&
		checkSelect(form.elements["license[0][type]"],"V","","Please enter your License Type. You must have at least one license.",false) &&
		checkSelect(form.elements["license[0][number]"],"V","","Please enter your License Number.",false) &&
		checkSelect(form.elements["license[0][expiration_date]"],"V","","Please enter your License Expiration Date.",false) &&
	 	checkSelect(form.elements["office[0][country]"],"V","","Please select your Country.",false) &&
	 	checkSelect(form.elements["office[0][address]"],"V","","Please enter your Address.",false) &&
	 	checkSelect(form.elements["office[0][city]"],"V","","Please enter your City.",false);
	if ( !returnVal ) {
		return false;
	} else {
		if ( form.elements["office[0][country]"].value == 62 || form.elements["office[0][country]"].value == 8 ) {
			return (
				checkSelect(form.elements["office[0][state]"],"V","","Please select your State.",false) &&
			 	checkSelect(form.elements["office[0][zip]"],"V","","Please enter your Zip/Postal Code.",false) &&
			 	checkSelect(form.elements["office[0][phone]"],"V","","Please enter your Phone Number.",false));
		} else {
			return (
				checkSelect(form.elements["office[0][province]"],"V","","Please enter your Province.",false) &&
			 	checkSelect(form.elements["office[0][zip]"],"V","","Please enter your Zip/Postal Code.",false) &&
			 	checkSelect(form.elements["office[0][phone]"],"V","","Please enter your Phone Number.",false));
		}
	}
}

function checkCountry(elem, num)
{
	var UNITED_STATES = 62;
	var CANADA = 8;
	var elem_city = document.getElementById("city"+num);
	var elem_zip = document.getElementById("zip"+num);
	var elem_distance = document.getElementById("distance"+num);
	
	if ( elem.selectedIndex == -1 || elem.value == '' ) {
		elem.value = UNITED_STATES;	
	}
	
	if ( elem.value == UNITED_STATES || elem.value == CANADA ) {
		//Enable
		elem_zip.disabled = false;
		elem_distance.disabled = false;
		
		//Hide		
		elem_city.style.display = "none";
		
		//Show
		elem_zip.style.display = "";
		elem_distance.style.display = "";
		
		//Disable
		elem_city.disabled = true;	
		
		//Change label	
		if ( document.getElementById('ziplabel'+num) ) {
			document.getElementById('ziplabel'+num).innerHTML = "Zip/Postal Code";
		}
		
		//Make sure distance row shows
		if ( document.getElementById('distancerow'+num) ) {
			document.getElementById('distancerow'+num).style.display = "";
				
		}
		
	} else {
		//Enable
		elem_city.disabled = false;
		
		//Hide		
		elem_zip.style.display = "none";
		elem_distance.style.display = "none";
		
		//Show
		elem_city.style.display = "";
		
		//Disable
		elem_zip.disabled = true;
		elem_distance.disabled = true;	
		
		//Change label
		if ( document.getElementById('ziplabel'+num) ) {
			document.getElementById('ziplabel'+num).innerHTML = "City";
		}
		
		//Make sure distance row hides		
		if ( document.getElementById('distancerow' + num) ) {
			document.getElementById('distancerow' + num).style.display = "none";
				
		}
		
	}
	
}//end checkCountry

function checkCountrySide(elem, num)
{
	var elem_city = document.getElementById("city");
	var elem_zip = document.getElementById("zip");
	var elem_distance = document.getElementById("distance");
	
	if ( elem.selectedIndex == -1 || elem.value == '' ) {
		elem.value = UNITED_STATES;	
	}
	
	if ( elem.value == UNITED_STATES || elem.value == CANADA ) {
		//Enable
		elem_zip.disabled = false;
		elem_distance.disabled = false;
		
		//Hide		
		elem_city.style.display = "none";
		
		//Show
		elem_zip.style.display = "";
		elem_distance.style.display = "";
		
		//Disable
		elem_city.disabled = true;	
		
		//Change label	
		if ( document.getElementById('ziplabel') ) {
			document.getElementById('ziplabel').innerHTML = "Zip/Postal Code";
		}
		
		//Make sure distance row shows
		if ( document.getElementById('distancerow' + num) ) {
			document.getElementById('distancerow' + num).style.display = "";
		}
	} else {
		//Enable
		elem_city.disabled = false;
		
		//Hide		
		elem_zip.style.display = "none";
		elem_distance.style.display = "none";
		
		//Show
		elem_city.style.display = "";
		
		//Disable
		elem_zip.disabled = true;
		elem_distance.disabled = true;	
		
		//Change label
		if ( document.getElementById('ziplabel') ) {
			document.getElementById('ziplabel').innerHTML = "City";
		}
		
		//Make sure distance row hides
		if ( document.getElementById('distancerow' + num) ) {
			document.getElementById('distancerow' + num).style.display = "none";
		}
	}	
}

function addLocation(new_loc_num)
{
	//variables
	var curr_loc_num = new_loc_num - 1;
	var arr_fields = new Array("company", "address", "city", "company_state", "company_province", "zip", "company_country", "phone", "fax");
	
	//Get the two sections we are interested in
	var new_loc  = document.getElementById('location'+new_loc_num);
	
	//Get the add buttons
	var curr_loc_addbutton = document.getElementById('locationbutton'+curr_loc_num);
	var new_loc_addbutton  = document.getElementById('locationbutton'+new_loc_num); 
	
	//handle the remove links
	if ( curr_loc_num != 1 ) {
		document.getElementById("removelink"+curr_loc_num).style.display = "none";
			
	}
	document.getElementById("removelink"+new_loc_num).style.display = "";
	
	//Enable the appropriate fields
	for ( var i=0; i<arr_fields.length; i++ ) {
		document.getElementById(arr_fields[i]+new_loc_num).disabled = false;
		
	}//for
	
	//Hide the previous add button
	curr_loc_addbutton.style.display = "none";
	
	if ( new_loc_num == 3 ) {
		//make sure the current button is showing
		new_loc_addbutton.style.display = "none"; 
	
	} else {
		new_loc_addbutton.style.display = ""; 
		
	}
	
	//Show the new section
	new_loc.style.display = "";

	
}//end addLocation

function removeLocation(remove_num) 
{
	if ( remove_num == 1 ) {
		return false;
			
	}
	
	//variables
	var prev_loc = remove_num - 1;
	var arr_fields = new Array("company", "address", "city", "company_state", "company_province", "zip", "company_country", "phone", "fax");		
	
	//Get the object for the table
	var remove_elem = document.getElementById("location"+remove_num);
	
	//Hide the table
	remove_elem.style.display = "none";
	
	//Disable the fields, clear the values
	for ( var i=0; i<arr_fields.length; i++ ) {
		var elem_field = document.getElementById(arr_fields[i]+remove_num);
		elem_field.value = '';
		elem_field.disabled = true;
		
	}//for
	
	//hide the add current add button
	if ( remove_num != 3 ) {
		document.getElementById("locationbutton"+remove_num).display = "none";
			
	}
	
	//Show the previous add button
	document.getElementById("locationbutton"+prev_loc).style.display = ""; 	
	
	//Show the previous remove link unless it's #1
	if ( prev_loc != 1 ) {
		document.getElementById("removelink"+prev_loc).style.display = "";
		
	}   

	
}//end removeLocation

function addSchoolLocation(new_loc_num)
{
	//variables
	var curr_loc_num = new_loc_num - 1;
	var arr_fields = new Array("school", "address", "city", "school_state", "school_province", "zip", "school_country", "phone", "fax", "tollfree");
	
	//Get the two sections we are interested in
	var new_loc  = document.getElementById('location'+new_loc_num);
	
	//Get the add buttons
	var curr_loc_addbutton = document.getElementById('locationbutton'+curr_loc_num);
	var new_loc_addbutton  = document.getElementById('locationbutton'+new_loc_num); 
	
	//handle the remove links
	if ( curr_loc_num != 1 ) {
		document.getElementById("removelink"+curr_loc_num).style.display = "none";
			
	}
	document.getElementById("removelink"+new_loc_num).style.display = "";
	
	//Enable the appropriate fields
	for ( var i=0; i<arr_fields.length; i++ ) {
		document.getElementById(arr_fields[i]+new_loc_num).disabled = false;
		
	}//for
	
	//Hide the previous add button
	curr_loc_addbutton.style.display = "none";
	
	if ( new_loc_num == 3 ) {
		//make sure the current button is showing
		new_loc_addbutton.style.display = "none"; 
	
	} else {
		new_loc_addbutton.style.display = ""; 
		
	}
	
	//Show the new section
	new_loc.style.display = "";
	
}//end addSchoolLocation

function removeSchoolLocation(remove_num) 
{
	if ( remove_num == 1 ) {
		return false;
			
	}
	
	//variables
	var prev_loc = remove_num - 1;
	var arr_fields = new Array("school", "address", "city", "school_state", "school_province", "zip", "school_country", "phone", "fax", "tollfree");
	
	//Get the object for the table
	var remove_elem = document.getElementById("location"+remove_num);
	
	//Hide the table
	remove_elem.style.display = "none";
	
	//Disable the fields, clear the values
	for ( var i=0; i<arr_fields.length; i++ ) {
		try {
		var elem_field = document.getElementById(arr_fields[i]+remove_num);
		elem_field.value = '';
		elem_field.disabled = true;
		} catch (e) {
			//alert('failed on ' + arr_fields[i]);	
		}
		
	}//for
	
	//hide the add current add button
	if ( remove_num != 3 ) {
		document.getElementById("locationbutton"+remove_num).display = "none";
			
	}
	
	//Show the previous add button
	document.getElementById("locationbutton"+prev_loc).style.display = ""; 	
	
	//Show the previous remove link unless it's #1
	if ( prev_loc != 1 ) {
		document.getElementById("removelink"+prev_loc).style.display = "";
		
	}   

	
}//end removeLocation

function addLocation2() {
	var location1 = document.getElementById('location1');
	var location2 = document.getElementById('location2');
	var location3 = document.getElementById('location3');
	
	var locationbutton1 = document.getElementById('locationbutton1');
	var removelocationbutton1 = document.getElementById('removelocationbutton1');
	
	var locationbutton2 = document.getElementById('locationbutton2');
	var removelocationbutton2 = document.getElementById('removelocationbutton2');
	
	var locationbutton3 = document.getElementById('locationbutton3');
	var removelocationbutton3 = document.getElementById('removelocationbutton3');
	
	location2.style.display = "";
	document.getElementById('company2').disabled=false;
	document.getElementById('address2').disabled=false;
	document.getElementById('city2').disabled=false;
	document.getElementById('company_state2').disabled=false;
	document.getElementById('company_province2').disabled=false;
	document.getElementById('zip2').disabled=false;
	document.getElementById('company_country2').disabled=false;
	document.getElementById('phone2').disabled=false;
	document.getElementById('fax2').disabled=false;
	
	locationbutton1.style.display = "none";
	removelocationbutton1.style.display = "";
	if ( location3.style.display == "" ) {
		locationbutton2.style.display = "none";
	} else {
		locationbutton2.style.display = "";
	}
	if ( location1.style.display == "none" && location3.style.display == "none" ) {
		removelocationbutton2.style.display = "none";
	} else {
		removelocationbutton2.style.display = "";
	}
}
function addLocation3() {
	var location1 = document.getElementById('location1');
	var location2 = document.getElementById('location2');
	var location3 = document.getElementById('location3');
	var locationbutton1 = document.getElementById('locationbutton1');
	var removelocationbutton1 = document.getElementById('removelocationbutton1');
	var locationbutton2 = document.getElementById('locationbutton2');
	var removelocationbutton2 = document.getElementById('removelocationbutton2');
	var locationbutton3 = document.getElementById('locationbutton3');
	var removelocationbutton3 = document.getElementById('removelocationbutton3');
	location3.style.display = "";
	document.getElementById('company3').disabled=false;
	document.getElementById('address3').disabled=false;
	document.getElementById('city3').disabled=false;
	document.getElementById('company_state3').disabled=false;
	document.getElementById('company_province3').disabled=false;
	document.getElementById('zip3').disabled=false;
	document.getElementById('company_country3').disabled=false;
	document.getElementById('phone3').disabled=false;
	document.getElementById('fax3').disabled=false;
	locationbutton2.style.display = "none";
	removelocationbutton2.style.display = "";
	if ( location1.style.display == "" ) {
		locationbutton3.style.display = "none";
	} else {
		locationbutton3.style.display = "";
	}
	if ( location1.style.display == "none" && location2.style.display == "none" ) {
		removelocationbutton3.style.display = "none";
	} else {
		removelocationbutton3.style.display = "";
	}
}
function addLocation1() {
	var location1 = document.getElementById('location1');
	var location2 = document.getElementById('location2');
	var location3 = document.getElementById('location3');
	var locationbutton1 = document.getElementById('locationbutton1');
	var removelocationbutton1 = document.getElementById('removelocationbutton1');
	var locationbutton2 = document.getElementById('locationbutton2');
	var removelocationbutton2 = document.getElementById('removelocationbutton2');
	var locationbutton3 = document.getElementById('locationbutton3');
	var removelocationbutton3 = document.getElementById('removelocationbutton3');
	location1.style.display = "";
	document.getElementById('company1').disabled=false;
	document.getElementById('address1').disabled=false;
	document.getElementById('city1').disabled=false;
	document.getElementById('company_state1').disabled=false;
	document.getElementById('company_province1').disabled=false;
	document.getElementById('zip1').disabled=false;
	document.getElementById('company_country1').disabled=false;
	document.getElementById('phone1').disabled=false;
	document.getElementById('fax1').disabled=false;
	locationbutton3.style.display = "none";
	removelocationbutton3.style.display = "";
	if ( location2.style.display == "" ) {
		locationbutton1.style.display = "none";
	} else {
		locationbutton1.style.display = "";
	}
	if ( location2.style.display == "none" && location3.style.display == "none" ) {
		removelocationbutton1.style.display = "none";
	} else {
		removelocationbutton1.style.display = "";
	}
}
function removeLocation1() {
	var location1 = document.getElementById('location1');
	var location2 = document.getElementById('location2');
	var location3 = document.getElementById('location3');
	var locationbutton1 = document.getElementById('locationbutton1');
	var removelocationbutton1 = document.getElementById('removelocationbutton1');
	var locationbutton2 = document.getElementById('locationbutton2');
	var removelocationbutton2 = document.getElementById('removelocationbutton2');
	var locationbutton3 = document.getElementById('locationbutton3');
	var removelocationbutton3 = document.getElementById('removelocationbutton3');
	if ( location2.style.display == "" || location3.style.display == "" ) {
		location1.style.display = "none";
		document.getElementById('company1').disabled=true;
		document.getElementById('address1').disabled=true;
		document.getElementById('city1').disabled=true;
		document.getElementById('company_state1').disabled=true;
		document.getElementById('company_province1').disabled=true;
		document.getElementById('zip1').disabled=true;
		document.getElementById('company_country1').disabled=true;
		document.getElementById('phone1').disabled=true;
		document.getElementById('fax1').disabled=true;
		locationbutton3.style.display = "";
		if ( location2.style.display == "" && location3.style.display == "none" ) {
			removelocationbutton2.style.display = "none";
		} else if ( location2.style.display == "none" && location3.style.display == "" ) {
			removelocationbutton3.style.display = "none";
		}
	}
}
function removeLocation2() {
	var location1 = document.getElementById('location1');
	var location2 = document.getElementById('location2');
	var location3 = document.getElementById('location3');
	var locationbutton1 = document.getElementById('locationbutton1');
	var removelocationbutton1 = document.getElementById('removelocationbutton1');
	var locationbutton2 = document.getElementById('locationbutton2');
	var removelocationbutton2 = document.getElementById('removelocationbutton2');
	var locationbutton3 = document.getElementById('locationbutton3');
	var removelocationbutton3 = document.getElementById('removelocationbutton3');
	if ( location1.style.display == "" || location3.style.display == "" ) {
		location2.style.display = "none";
		document.getElementById('company2').disabled=true;
		document.getElementById('address2').disabled=true;
		document.getElementById('city2').disabled=true;
		document.getElementById('company_state2').disabled=true;
		document.getElementById('company_province2').disabled=true;
		document.getElementById('zip2').disabled=true;
		document.getElementById('company_country2').disabled=true;
		document.getElementById('phone2').disabled=true;
		document.getElementById('fax2').disabled=true;
		locationbutton1.style.display = "";
		if ( location1.style.display == "" && location3.style.display == "none" ) {
			removelocationbutton1.style.display = "none";
		} else if ( location1.style.display == "none" && location3.style.display == "" ) {
			removelocationbutton3.style.display = "none";
		}
	}
}
function removeLocation3() {
	var location1 = document.getElementById('location1');
	var location2 = document.getElementById('location2');
	var location3 = document.getElementById('location3');
	var locationbutton1 = document.getElementById('locationbutton1');
	var removelocationbutton1 = document.getElementById('removelocationbutton1');
	var locationbutton2 = document.getElementById('locationbutton2');
	var removelocationbutton2 = document.getElementById('removelocationbutton2');
	var locationbutton3 = document.getElementById('locationbutton3');
	var removelocationbutton3 = document.getElementById('removelocationbutton3');
	if ( location2.style.display == "" || location1.style.display == "" ) {
		location3.style.display = "none";
		document.getElementById('company3').disabled=true;
		document.getElementById('address3').disabled=true;
		document.getElementById('city3').disabled=true;
		document.getElementById('company_state3').disabled=true;
		document.getElementById('company_province3').disabled=true;
		document.getElementById('zip3').disabled=true;
		document.getElementById('company_country3').disabled=true;
		document.getElementById('phone3').disabled=true;
		document.getElementById('fax3').disabled=true;
		locationbutton2.style.display = "";
		if ( location2.style.display == "" && location1.style.display == "none" ) {
			removelocationbutton2.style.display = "none";
		} else if ( location2.style.display == "none" && location1.style.display == "" ) {
			removelocationbutton1.style.display = "none";
		}
	}
}

function validateSchoolPersonalInfo(form) {
	if (
	
		checkSelect(form.elements["email"],"V","","Please enter your E-mail.",false) &&
		checkEmail(form.elements["email"],false) &&
		checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
		checkSelect(form.elements["password1"],"V","","Please create a Password.",false) &&
		checkSelect(form.elements["password2"],"V","","Please confirm your Password.",false) &&
		checkSelect(form.elements["firstname"],"V","","Please enter your first name.",false) &&
		checkSelect(form.elements["lastname"],"V","","Please enter your last name.",false) &&
		checkSelect(form.elements["title"],"V","","Please enter your title.",false) &&
		checkSelect(form.elements["phone"],"V","","Please enter your phone number.",false))
	{

	} else {
	
		return (false);
	}
}

function validateSchoolInfo(form) {
	if (
		checkSelect(form.elements["school[name]"],"V","","Please enter your school name.",false) &&
		checkSelect(form.elements["school[url]"],"V","","Please enter your school website address.",false) &&
		checkSelect(form.elements["school[contact_email]"],"V","","Please enter your contact email.",false))
	{
		try {
			if ( document.getElementById('location1').style.display == "" ) {
				if (
					checkSelect(form.elements["school1"],"V","","Please enter a name for location 1, like Main Campus.",false) &&
					checkSelect(form.elements["school_country1"],"V","","Please select a country for location 1.",false) &&
				 	checkSelect(form.elements["address1"],"V","","Please enter an address for location 1.",false) &&
				 	checkSelect(form.elements["city1"],"V","","Please enter a city for location 1.",false) &&
				 	checkSelect(form.elements["zip1"],"V","","Please enter a zip/postal code for location 1.",false) &&
				 	checkSelect(form.elements["phone1"],"V","","Please enter a phone number for location 1.",false)) 
				{
					if ("" == document.getElementById('state_box0').style.display) {
						if (!checkSelect(form.elements["school_state1"],"V","","Please enter a state/province for location 1.",false)) {
				 			return (false);
				 		} 
					} else {
				 		if (!checkSelect(form.elements["school_province1"],"V","","Please enter a province for location 1.",false)) {
							return (false);
				 		}
				 	}
				} else {
					return (false);
				}
			}
		} catch ( e ) {
		}
		try {
			if ( document.getElementById('location2').style.display == "" ) {
				if (
					checkSelect(form.elements["school2"],"V","","Please enter a name for location 2, like Main Campus.",false) &&
					checkSelect(form.elements["school_country2"],"V","","Please select a country for location 2.",false) &&
				 	checkSelect(form.elements["address2"],"V","","Please enter an address for location 2.",false) &&
				 	checkSelect(form.elements["city2"],"V","","Please enter a city for location 2.",false) &&
				 	checkSelect(form.elements["zip2"],"V","","Please enter a zip/postal code for location 2.",false) &&
				 	checkSelect(form.elements["phone2"],"V","","Please enter a phone number for location 2.",false)) 
				{
					if ("" == document.getElementById('state_box1').style.display) {
						if (!checkSelect(form.elements["school_state2"],"V","","Please enter a state/province for location 2.",false)) {
				 			return (false);
				 		} 
					} else {
				 		if (!checkSelect(form.elements["school_province2"],"V","","Please enter a province for location 2.",false)) {
							return (false);
				 		}
				 	}					
				} else {
				
					return (false);
				}
			}		
		} catch ( e ) {
		}
		try {
		 if ( document.getElementById('location3').style.display == "" ) {
		 	if (
		 		checkSelect(form.elements["school3"],"V","","Please enter a name for location 3, like Main Campus.",false) &&
				checkSelect(form.elements["school_country3"],"V","","Please select a country for location 3.",false) &&
			 	checkSelect(form.elements["address3"],"V","","Please enter an address for location 3.",false) &&
			 	checkSelect(form.elements["city3"],"V","","Please enter a city for location 3.",false) &&
			 	checkSelect(form.elements["zip3"],"V","","Please enter a zip/postal code for location 3.",false) &&
			 	checkSelect(form.elements["phone3"],"V","","Please enter a phone number for location 3.",false)) 
			{
					if ("" == document.getElementById('state_box2').style.display) {
						if (!checkSelect(form.elements["school_state3"],"V","","Please enter a state/province for location 3.",false)) {
				 			return (false);
				 		} 
					} else {
				 		if (!checkSelect(form.elements["school_province3"],"V","","Please enter a province for location 3.",false)) {
							return (false);
				 		}
				 	}				
			} else {
	
				return (false);
			}
		}
		} catch ( e ) {
		}

	} else {
	
		return (false);
	}
}

function addSchool2() {
	var location1 = document.getElementById('location1');
	var location2 = document.getElementById('location2');
	var location3 = document.getElementById('location3');
	var locationbutton1 = document.getElementById('locationbutton1');
	var removelocationbutton1 = document.getElementById('removelocationbutton1');
	var locationbutton2 = document.getElementById('locationbutton2');
	var removelocationbutton2 = document.getElementById('removelocationbutton2');
	var locationbutton3 = document.getElementById('locationbutton3');
	var removelocationbutton3 = document.getElementById('removelocationbutton3');
	location2.style.display = "";
	document.getElementById('school2').disabled=false;
	document.getElementById('address2').disabled=false;
	document.getElementById('city2').disabled=false;
	document.getElementById('school_state2').disabled=false;
	document.getElementById('school_province2').disabled=false;
	document.getElementById('zip2').disabled=false;
	document.getElementById('school_country2').disabled=false;
	document.getElementById('phone2').disabled=false;
	document.getElementById('fax2').disabled=false;
	document.getElementById('tollfree2').disabled=false;
	locationbutton1.style.display = "none";
	removelocationbutton1.style.display = "";
	if ( location3.style.display == "" ) {
		locationbutton2.style.display = "none";
	} else {
		locationbutton2.style.display = "";
	}
	if ( location1.style.display == "none" && location3.style.display == "none" ) {
		removelocationbutton2.style.display = "none";
	} else {
		removelocationbutton2.style.display = "";
	}
}
function addSchool3() {
	var location1 = document.getElementById('location1');
	var location2 = document.getElementById('location2');
	var location3 = document.getElementById('location3');
	var locationbutton1 = document.getElementById('locationbutton1');
	var removelocationbutton1 = document.getElementById('removelocationbutton1');
	var locationbutton2 = document.getElementById('locationbutton2');
	var removelocationbutton2 = document.getElementById('removelocationbutton2');
	var locationbutton3 = document.getElementById('locationbutton3');
	var removelocationbutton3 = document.getElementById('removelocationbutton3');
	location3.style.display = "";
	document.getElementById('school3').disabled=false;
	document.getElementById('address3').disabled=false;
	document.getElementById('city3').disabled=false;
	document.getElementById('school_state3').disabled=false;
	document.getElementById('school_province3').disabled=false;
	document.getElementById('zip3').disabled=false;
	document.getElementById('school_country3').disabled=false;
	document.getElementById('phone3').disabled=false;
	document.getElementById('fax3').disabled=false;
	document.getElementById('tollfree3').disabled=false;
	locationbutton2.style.display = "none";
	removelocationbutton2.style.display = "";
	if ( location1.style.display == "" ) {
		locationbutton3.style.display = "none";
	} else {
		locationbutton3.style.display = "";
	}
	if ( location1.style.display == "none" && location2.style.display == "none" ) {
		removelocationbutton3.style.display = "none";
	} else {
		removelocationbutton3.style.display = "";
	}
}
function addSchool1() {
	var location1 = document.getElementById('location1');
	var location2 = document.getElementById('location2');
	var location3 = document.getElementById('location3');
	var locationbutton1 = document.getElementById('locationbutton1');
	var removelocationbutton1 = document.getElementById('removelocationbutton1');
	var locationbutton2 = document.getElementById('locationbutton2');
	var removelocationbutton2 = document.getElementById('removelocationbutton2');
	var locationbutton3 = document.getElementById('locationbutton3');
	var removelocationbutton3 = document.getElementById('removelocationbutton3');
	location1.style.display = "";
	document.getElementById('school1').disabled=false;
	document.getElementById('address1').disabled=false;
	document.getElementById('city1').disabled=false;
	document.getElementById('school_state1').disabled=false;
	document.getElementById('school_province1').disabled=false;
	document.getElementById('zip1').disabled=false;
	document.getElementById('school_country1').disabled=false;
	document.getElementById('phone1').disabled=false;
	document.getElementById('fax1').disabled=false;
	document.getElementById('tollfree1').disabled=false;
	locationbutton3.style.display = "none";
	removelocationbutton3.style.display = "";
	if ( location2.style.display == "" ) {
		locationbutton1.style.display = "none";
	} else {
		locationbutton1.style.display = "";
	}
	if ( location2.style.display == "none" && location3.style.display == "none" ) {
		removelocationbutton1.style.display = "none";
	} else {
		removelocationbutton1.style.display = "";
	}
}
function removeSchool1() {
	var location1 = document.getElementById('location1');
	var location2 = document.getElementById('location2');
	var location3 = document.getElementById('location3');
	var locationbutton1 = document.getElementById('locationbutton1');
	var removelocationbutton1 = document.getElementById('removelocationbutton1');
	var locationbutton2 = document.getElementById('locationbutton2');
	var removelocationbutton2 = document.getElementById('removelocationbutton2');
	var locationbutton3 = document.getElementById('locationbutton3');
	var removelocationbutton3 = document.getElementById('removelocationbutton3');
	if ( location2.style.display == "" || location3.style.display == "" ) {
		location1.style.display = "none";
		document.getElementById('school1').disabled=true;
		document.getElementById('address1').disabled=true;
		document.getElementById('city1').disabled=true;
		document.getElementById('school_state1').disabled=true;
		document.getElementById('school_province1').disabled=true;
		document.getElementById('zip1').disabled=true;
		document.getElementById('school_country1').disabled=true;
		document.getElementById('phone1').disabled=true;
		document.getElementById('fax1').disabled=true;
		document.getElementById('tollfree1').disabled=true;
		locationbutton3.style.display = "";
		if ( location2.style.display == "" && location3.style.display == "none" ) {
			removelocationbutton2.style.display = "none";
		} else if ( location2.style.display == "none" && location3.style.display == "" ) {
			removelocationbutton3.style.display = "none";
		}
	}
}
function removeSchool2() {
	var location1 = document.getElementById('location1');
	var location2 = document.getElementById('location2');
	var location3 = document.getElementById('location3');
	var locationbutton1 = document.getElementById('locationbutton1');
	var removelocationbutton1 = document.getElementById('removelocationbutton1');
	var locationbutton2 = document.getElementById('locationbutton2');
	var removelocationbutton2 = document.getElementById('removelocationbutton2');
	var locationbutton3 = document.getElementById('locationbutton3');
	var removelocationbutton3 = document.getElementById('removelocationbutton3');
	if ( location1.style.display == "" || location3.style.display == "" ) {
		location2.style.display = "none";
		document.getElementById('school2').disabled=true;
		document.getElementById('address2').disabled=true;
		document.getElementById('city2').disabled=true;
		document.getElementById('school_state2').disabled=true;
		document.getElementById('school_province2').disabled=true;
		document.getElementById('zip2').disabled=true;
		document.getElementById('school_country2').disabled=true;
		document.getElementById('phone2').disabled=true;
		document.getElementById('fax2').disabled=true;
		document.getElementById('tollfree2').disabled=true;
		locationbutton1.style.display = "";
		if ( location1.style.display == "" && location3.style.display == "none" ) {
			removelocationbutton1.style.display = "none";
		} else if ( location1.style.display == "none" && location3.style.display == "" ) {
			removelocationbutton3.style.display = "none";
		}
	}
}
function removeSchool3() {
	var location1 = document.getElementById('location1');
	var location2 = document.getElementById('location2');
	var location3 = document.getElementById('location3');
	var locationbutton1 = document.getElementById('locationbutton1');
	var removelocationbutton1 = document.getElementById('removelocationbutton1');
	var locationbutton2 = document.getElementById('locationbutton2');
	var removelocationbutton2 = document.getElementById('removelocationbutton2');
	var locationbutton3 = document.getElementById('locationbutton3');
	var removelocationbutton3 = document.getElementById('removelocationbutton3');
	if ( location2.style.display == "" || location1.style.display == "" ) {
		location3.style.display = "none";
		document.getElementById('school3').disabled=true;
		document.getElementById('address3').disabled=true;
		document.getElementById('city3').disabled=true;
		document.getElementById('school_state3').disabled=true;
		document.getElementById('school_province3').disabled=true;
		document.getElementById('zip3').disabled=true;
		document.getElementById('school_country3').disabled=true;
		document.getElementById('phone3').disabled=true;
		document.getElementById('fax3').disabled=true;
		document.getElementById('tollfree3').disabled=true;
		locationbutton2.style.display = "";
		if ( location2.style.display == "" && location1.style.display == "none" ) {
			removelocationbutton2.style.display = "none";
		} else if ( location2.style.display == "none" && location1.style.display == "" ) {
			removelocationbutton1.style.display = "none";
		}
	}
}

function validateEventPersonalInfo(form) {
	if (
		checkSelect(form.elements["email"],"V","","Please enter your E-mail.",false) &&
		checkEmail(form.elements["email"],false) &&
		checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
		checkSelect(form.elements["password1"],"V","","Please create a Password.",false) &&
		checkSelect(form.elements["password2"],"V","","Please confirm your Password.",false) &&
		checkSelect(form.elements["firstname"],"V","","Please enter your first name.",false) &&
		checkSelect(form.elements["lastname"],"V","","Please enter your last name.",false) &&
		checkSelect(form.elements["phone"],"V","","Please enter your phone number.",false))
	{

	} else {
	
		return (false);
	}
}

function validateEventInfo2(form) {
	if (
		checkSelect(form.elements["title"],"V","","Please enter the event title.",false) &&
		checkSelect(form.elements["organization"],"V","","Please enter the organization.",false) &&
		checkSelect(form.elements["event_date"],"V","","Please enter the event date.",false) &&
		checkSelect(form.elements["address"],"V","","Please enter the stree address.",false) &&
		checkSelect(form.elements["city"],"V","","Please enter the city.",false) &&
		checkSelect(form.elements["state"],"V","","Please enter the state.",false) &&
		checkSelect(form.elements["zip"],"V","","Please enter the zip.",false) &&
		checkSelect(form.elements["country"],"V","","Please the country.",false) &&
		checkSelect(form.elements["phone"],"V","","Please enter a phone number.",false))
	{

	} else {
	
		return (false);
	}
}

function validateEventInfo(form) {
	if (
		checkSelect(form.elements["event[title]"],"V","","Please enter the event title.",false) &&
		checkSelect(form.elements["event[topic]"],"V","","Please enter the event topic.",false) &&
		checkSelect(form.elements["event[startdate]"],"V","","Please enter the event date.",false) &&
		checkSelect(form.elements["event[instructor]"],"V","","Please enter the event instructor's name.",false) &&
		checkSelect(form.elements["event[contact_name]"],"V","","Please enter the event's contact name.",false) &&
		checkSelect(form.elements["event[contact_email]"],"V","","Please enter your E-mail.",false) &&
		checkEmail(form.elements["event[contact_email]"],false) &&
		checkSelect(form.elements["event[contact_email]"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
		checkSelect(form.elements["event[location_name]"],"V","","Please enter the event location name.",false) &&
		checkSelect(form.elements["event[country]"],"V","","Please enter the event location country.",false) &&
		checkSelect(form.elements["event[address]"],"V","","Please enter the event location address.",false) &&
		checkSelect(form.elements["event[city]"],"V","","Please enter the event location city.",false) &&
		checkSelect(form.elements["event[state]"],"V","","Please enter the event location state.",false) &&
		checkSelect(form.elements["event[zip]"],"V","","Please enter the event location zip.",false))
	{

	} else {
	
		return (false);
	}
}

function add_to_cart(id)
{
	var frm = document.getElementById('frmAddCart');
	frm.elements['product_id'].value = id;
	frm.submit();
}//end add_to_cart

function quantity_check(frm)
{
	if ( frm.elements['qty'].value < 1 || !validateInteger(frm.elements['qty'].value) ) {
		alert("Quantity must be an integer greater than 0");
		return false;
	}
}

function multiple_quantity_check(frm)
{
	for ( var i=0; i<arr_content_index.length; i++ ) {
		if ( !validateInteger(frm.elements['update[' + arr_content_index[i] + ']'].value) ) {
 			alert("Quantity must be an integer greater than 0");
			return false;
		}
	}
}

function removeSubmit(obj) {
	obj.form.onsubmit="";
	obj.form.removeAttribute('onsubmit');
}

function transferValue(field, pfield, val) {
	if ( document.getElementById(field) ) {
		document.getElementById(field).value = val;
	} else if ( document.getElementById(pfield) ) {
		document.getElementById(pfield).value = val;
	}
}

function transferValues() {
	document.getElementById('os1').value = document.getElementById('listing_plan_id').value + ",";
	document.getElementById('os1').value +=	document.getElementById('billing_gift').value + ",";
	document.getElementById('os1').value +=	document.getElementById('billing_promo').value;
}

function validateInteger( strValue ) {
	
  var objRegExp  = /(^-?\d\d*$)/;

  return objRegExp.test(strValue);
}


// takes the field and checks to see if it matches the default value, if so, it clears it
function clearField(field, defaultValue)
{
	if (field.value == defaultValue) {
		field.value = "";	
	}	
}


// if the given field is empty, it will populate the field with the default value.
function fillField(field, defaultValue)
{
	if (field.value == "") {
		field.value = defaultValue;	
	}	
}

function pract_country_change(elem, num)
{
	if (elem.value=='62' || elem.value=='8') {
		document.getElementById('province_box'+num).style.display='none'; 
		document.getElementById('state_box'+num).style.display=''; 
	} else {
		document.getElementById('province_box'+num).style.display=''; 
		document.getElementById('state_box'+num).style.display='none'; 
	}
	
}//end pract_country_change

/**
* This Object helps in dealing with Radio Groups
*/
function RadioGroup()
{ 
	this.radioNodeElem = null;
	
	/**
	* Initialize
	*
	* @param form_object obj_form
	* @param string group_name
	* @return bool
	*/
	this.init = function(obj_form, group_name)
	{
		try {
			this.radioNodeElem = obj_form.elements[group_name];	
		} catch (e) {
			this.radioNodeElem = null;	
		}
		
		
	}//end init
	
	/**
	* Get the value of the currently checked radio box
	*
	* @return null
	*/
	this.getValue = function()
	{
		if ( this.radioNodeElem == null ) {
			return null;	
		}
		
		for ( var i=0; i<this.radioNodeElem.length; i++ ) {
			if ( this.radioNodeElem[i].checked == true ) {
				return this.radioNodeElem[i].value;	
			}
			
		}//for	
		
		return null;
		
	}//end value

	/**
	* Set the value of the radio group, value must exist in the set
	*
	* @param string new_value
	* @return mixed
	*/
	this.setValue = function(new_value)
	{
		if ( this.radioNodeElem == null ) {
			return null;	
		}
		
		for ( var i=0; i<this.radioNodeElem.length; i++ ) {
			if ( this.radioNodeElem[i].value == new_value ) {
				this.radioNodeElem[i].checked = true;
				return true;
					
			}
		}//for
		
		return false;
		
	}//end setValue
	
}//end radioGroup

function selectAll(id)
{
	document.getElementById(id).focus();
	document.getElementById(id).select();
	return false;
}

function reloadCaptcha()
{
	var date = new Date();
	time = date.getTime();
	
	document.getElementById('captcha').src = "captcha.php?time="+time;
	
	return false;
}

function changeSearchCountry(country)
{
	if ( country == UNITED_STATES || country == CANADA ) {
		document.getElementById('ziprow').style.display = '';
		document.getElementById('proxrow').style.display = '';
		document.getElementById('staterow').style.display = '';
		document.getElementById('provrow').style.display = 'none';
	} else {
		document.getElementById('ziprow').style.display = 'none';
		document.getElementById('proxrow').style.display = 'none';
		document.getElementById('staterow').style.display = 'none';
		document.getElementById('provrow').style.display = '';
	}
}

function cartAction(product_id, action)
{
	var frm = document.getElementById('frmCart');

	if ( frm.elements['product_id'] ) {
		frm.elements['product_id'].value = product_id;
	}

	if ( frm.elements['action'] ) {
		frm.elements['action'].value = action;
	}

	if ( multi_quantity_check(frm, false) ) {
		frm.submit();
	}

	return false;
}

function multi_quantity_check(frm, popup)
{
	if ( document.getElementById('action') ) {
		if ( document.getElementById('action').value != 'remove_item' ) {
			for ( var i=0; i<frm.length; i++ ) {
				var element = frm.elements[i];
				if ( element.name.search(/qty/) >= 0 ) {
					if ( element.value < 1 || !validateInteger(element.value) ) {
						if ( popup ) {
							alert("Quantity must be an integer greater than 0");
						}
						return false;
					}
				}
			}
		}
	} else {
		for ( var i=0; i<frm.length; i++ ) {
			var element = frm.elements[i];
			if ( element.name.search(/qty/) >= 0 ) {
				if ( element.value < 1 || !validateInteger(element.value) ) {
					if ( popup ) {
						alert("Quantity must be an integer greater than 0");
					}
					return false;
				}
			}
		}
	}

	return true;
}

var paymentTypes = new Array('cc', 'pp', 'po');

function switchPaymentType(type)
{
	for ( var x=0; x<paymentTypes.length; x++ ) {
		if ( type == paymentTypes[x] ) {
			if ( did(paymentTypes[x]+'_form') ) {
				did(paymentTypes[x]+'_form').style.display = '';
			}
		} else {
			if ( did((paymentTypes[x]+'_form')) ) {
				did(paymentTypes[x]+'_form').style.display = 'none';
			}
		}
	}
}

/*function switchPaymentType(type)
{
	var uri = "LiveUpdater.php";
	var data = "";

	data += nh.compressData("action", "switchPaymentType");
	data += nh.compressData("type", type);

	LiveUpdater(uri, data);
}*/

function changeShipping(id)
{
	changedShipping = true;
	if ( id == '' ) {
		changedShipping = false;
		document.getElementById('add_profile').style.display = '';
		document.getElementById('update_profile').style.display = 'none';
	} else {
		document.getElementById('add_profile').style.display = 'none';
		if ( changedShipping ) {
			document.getElementById('update_profile').style.display = '';
		}
	}

	var uri = "LiveUpdater.php";
	var data = "";

	data += nh.compressData("action", "changeShipping");
	data += nh.compressData("id", id);

	LiveUpdater(uri, data);
}

function doProfileChange(type) {
	var id = '';

	if ( did(type+'_id') ) {
		id = did(type+'_id').value;
	}

	if ( id != '' ) {
		if ( type == 'billing' ) {
			did('update_profile').style.display = '';
		}
		
		did(type+'_action').value = 'true';
	} else {
		if ( type == 'billing' ) {
			did('update_profile').style.display = 'none';
		}
	}
}

/*function changeBilling(id)
{
	changedBilling = true;
	if ( id == '' ) {
		changedBilling = false;
		document.getElementById('add_profile').style.display = '';
		document.getElementById('update_profile').style.display = 'none';
	} else {
		document.getElementById('add_profile').style.display = 'none';
		if ( changedBilling ) {
			document.getElementById('update_profile').style.display = '';
		}
	}

	var uri = "LiveUpdater.php";
	var data = "";

	data += nh.compressData("action", "changeBilling");
	data += nh.compressData("id", id);

	LiveUpdater(uri, data);
}*/

function changeBilling(id)
{
	did('update_profile').style.display = 'none';
	
	if ( id == '' ) {
		did('add_profile').style.display = '';
		did('billing_action').value = 'true';
	} else {
		did('add_profile').style.display = 'none';
		did('billing_action').value = 'false';
	}
	
	did('add_billing_profile').checked = false;
	did('update_billing_profile').checked = false;
	
	did('name_profile').style.display = 'none';

	var uri = "LiveUpdater.php";
	var data = "";

	data += nh.compressData("action", "changeBilling");
	data += nh.compressData("id", id);

	LiveUpdater(uri, data);
}

function showProfileName(type, checked, action) {
	var label = '';
	
	switch ( type ) {
		case 'shipping':
			label = 'Address';
			break;
		case 'billing':
			label = 'Saved Card';
			break;
	}
	
	switch ( action ) {
		case 'add':
			did('name_profile_label').innerHTML = 'Name this '+label;
			break;
		case 'update':
			did('name_profile_label').innerHTML = 'Name of '+label;
			break;
	}
	
	if ( checked ) {
		did('name_profile').style.display = '';
	} else {
		did('name_profile').style.display = 'none';
	}
}

function submitPollAnswer()
{
	var answers = document.getElementsByName('pollAnswer');
	
	for ( var x=0; x<answers.length; x++ ) {
		if ( answers[x].checked ) {
			var answer = answers[x].value;
		}
	}
	
	var uri = "LiveUpdater.php";
	var data = "";

	data += nh.compressData("action", "submitPollAnswer");
	data += nh.compressData("answer", answer);

	LiveUpdater(uri, data);
}

function loginToVote()
{
	var answers = document.getElementsByName('pollAnswer');
	
	for ( var x=0; x<answers.length; x++ ) {
		if ( answers[x].checked ) {
			var answer = answers[x].value;
		}
	}
	
	var uri = "LiveUpdater.php";
	var data = "";

	data += nh.compressData("action", "loginToVote");
	data += nh.compressData("answer", answer);

	LiveUpdater(uri, data);
}

function viewPollResults()
{
	var uri = "LiveUpdater.php";
	var data = "";

	data += nh.compressData("action", "viewPollResults");

	LiveUpdater(uri, data);
}

function voteNow()
{
	var uri = "LiveUpdater.php";
	var data = "";

	data += nh.compressData("action", "voteNow");

	LiveUpdater(uri, data);
}

function getShipServices(carrier)
{
	var uri = "LiveUpdater.php";

	var data = "";

	data += nh.compressData('action', "getShipServices");
	data += nh.compressData('target', "shiptype");
	data += nh.compressData('carrier', carrier);

	LiveUpdater(uri, data);
}

/*function updateShipping(shiptype)
{
	document.getElementById('shiptotalvalue').innerHTML = 'loading';
	document.getElementById('gnd_total').innerHTML = 'loading';
	if ( document.getElementById('pmo_total') ) {
		document.getElementById('pmo_total').innerHTML = 'loading';
	}

	if ( document.getElementById('gft_total') ) {
		document.getElementById('gft_total').innerHTML = 'loading';
	}

	var uri = "LiveUpdater.php";

	var data = "";

	data = nh.compressData("action", "update_shipping");
	data += nh.compressData("shiptype", shiptype);

	LiveUpdater(uri, data);
}*/

function getShipPrice(service, carrier)
{
	document.getElementById('shiptotalvalue').innerHTML = 'loading';
	document.getElementById('gnd_total').innerHTML = 'loading';

	if ( document.getElementById('pmo_total') ) {
		document.getElementById('pmo_total').innerHTML = 'loading';
	}

	if ( document.getElementById('gft_total') ) {
		document.getElementById('gft_total').innerHTML = 'loading';
	}

	var uri = "LiveUpdater.php";

	var data = "";

	data = nh.compressData("action", "getShipPrice");
	data += nh.compressData("service", service);
	data += nh.compressData("carrier", carrier);

	LiveUpdater(uri, data);
}

function updatePlan(elem, type)
{
	var plans = elem.form.elements[type+'_plan'];
	var gift_cert = elem.form.elements['gift_cert'];
	var promo = elem.form.elements['promo'];
	
	if ( elem.checked == true ) {
		if ( plans.length ) {
			for ( var i=0; i<plans.length; i++ ) {	
				plans[i].disabled = false;
			}
		} else {
			plans.disabled = false;
		}
				
		gift_cert.disabled  = false;
		promo.disabled = false;
		
		if ( document.getElementById('unpaid_renew') ) {
			document.getElementById('unpaid_renew').checked = false;
			document.getElementById('unpaid_renew').disabled = true;
		}
	} else {
		if ( plans.length ) {
			for ( var i=0; i<plans.length; i++ ) {
				plans[i].checked  = false;
				plans[i].disabled = true;
			}
		} else {
			plans.checked  = false;
			plans.disabled = true;
		}
		
		gift_cert.value = "";
		gift_cert.disabled = true;
		
		promo.value = "";
		promo.disabled = true;
		
		if ( document.getElementById('unpaid_renew') ) {
			document.getElementById('unpaid_renew').checked = false;
			document.getElementById('unpaid_renew').disabled = false;
		}
	}
}

function favoritesAction(product_id, option_id, action)
{
	var frm = document.getElementById('frmFavorites');

	if ( frm.elements['product_id'] ) {
		frm.elements['product_id'].value = product_id;
	}

	if ( frm.elements['option_id'] ) {
		frm.elements['option_id'].value = option_id;
	}

	if ( frm.elements['action'] ) {
		frm.elements['action'].value = action;
	}

	frm.submit();

	return false;
}

function did(name) {
	return document.getElementById(name);
}

function validateSubscription() {
	if(did('subscription_fullname').value == '') {
		alert('Please enter a full name.');
		return false;
	} else if(did('subscription_address').value == '') {
		alert('Please enter a address.');
		return false;
	} else if(did('subscription_city').value == '') {
		alert('Please enter a city.');
		return false;
	} else if(did('subscription_state').value == '') {
		alert('Please enter a state.');
		return false;
	} else if(did('subscription_zip').value == '') {
		alert('Please enter a zip.');
		return false;
	} else {
		return true;
	}
}

function hndlCountryChange(elem_select, div_prefix)
{
	var elem_state_div = document.getElementById(div_prefix + "_stateprov_state");
	var elem_prov_div = document.getElementById(div_prefix + "_stateprov_prov");
	
	if ( elem_select.value == 8 || elem_select.value == 62 ) {
		elem_prov_div.style.display = "none";
		var arr_inputs = elem_prov_div.getElementsByTagName('input');
		for ( var i=0; i<arr_inputs.length; i++ ) {
			arr_inputs[i].value = '';
			arr_inputs[i].disabled = true;
			
		}
		elem_state_div.style.display = "";
		var arr_selects = elem_state_div.getElementsByTagName('select');
		for ( var i=0; i<arr_selects.length; i++ ) {
			arr_selects[i].disabled = false;
			arr_selects[i].selectedIndex = 0;
		}
	} else {
		elem_prov_div.style.display = "";
		var arr_inputs = elem_prov_div.getElementsByTagName('input');
		for ( var i=0; i<arr_inputs.length; i++ ) {
			arr_inputs[i].value = '';
			arr_inputs[i].disabled = false;
			
		}
		elem_state_div.style.display = "none";
		var arr_selects = elem_state_div.getElementsByTagName('select');
		for ( var i=0; i<arr_selects.length; i++ ) {
			arr_selects[i].disabled = true;
			arr_selects[i].selectedIndex = -1;
		}
	}
}

function updateCountry() {
	if ( did('id_country').value == '' ) {
		return;
	}
	
	did('state').style.display = 'none';
	did('province').style.display = 'none';
	did('other').style.display = 'none';
	
	if ( did('id_country').value == '220' ) {
		did('state').style.display = '';
	} else if ( did('id_country').value == '37' ) {
		did('province').style.display = '';
	} else {
		did('other').style.display = '';
	}
}

function recordClick(banner_ad_id) {
	try {
		var uri = "LiveUpdater.php";
	
		var data = "";
	
		data = nh.compressData("action", "recordBannerClick");
		data += nh.compressData("id", banner_ad_id);
	
		LiveUpdater(uri, data);
	} catch(e) { }
}

/**
 * dbn - Shorcut for getElementsByName
 * @param	name	The element name you are looking for
 * @param	parent	optional;The parent item to search within
 * @return			Collection of elements
 */
function dbn(name, parent) {
	return (parent || document).getElementsByName(name);
}
/**
 * dbt - Shorcut for getElementsByTagName
 * @param	tag		The element tagName you are looking for
 * @param	parent	optional;The parent item to search within
 * @return 			Collection of elements
 */
function dbt(tag, parent) {
	return (parent || document).getElementsByTagName(tag);
}
/**
 * dbc - Shortcut for getElementsByClass
 * @param	className	The className you are looking for
 * @param	parent		optional;The parent item to search within
 * @return				Array of elements
 */
function dbc(className, parent) {
	//use default provided by browser if it exists otherwise use our implementation
	if(document.getElementsByClassName) {
		return (parent || document).getElementsByClassName(className);
	}
	var nodes = slice(dbt('*', parent)), elms = [];
	nodes.forEach(function(node){
		if(node.className.indexOf(className) != -1) {
			elms.push(node);
		}
	});	
	return elms;
}
/**
 * slice - Shortcut for Array.prototype.slice.call(obj, idx)
 * @param	obj		mixed		Object to call array.slice on
 * @param	start	integer		Index at which to begin slicing
 * @param	end		integer		Index at which to end slicing
 * @return			array		New array containing values from the idx to the end of the obj
 *		Note: Useful for transforming arguments object and collections into regular arrays
 *		ex.	function(){ var args = slice(arguments); alert(args instanceof Array); }
 */
function slice(obj, start, end){
	var ret = obj;
	if(window.ActiveXObject){
		if(typeof obj.length=='undefined'){ obj.length = getLength(obj); }
		ret = Array.prototype.map.call(obj,function(item){return item;});
	}
	var args = [(start || 0)];
	if(end && !isNaN(Number(end))) {
		args.push(Number(end));
	}
	return Array.prototype.slice.apply(ret,args);
}

/**
 * getLength - Finds the total number of all non-function properties owned by the object (see hasOwnProperty)
 * @param obj    object    The object whose properties to count.
 * @return       int       The length of the object or 0 if obj was invalid
 */
function getLength(obj){
    if(!obj){ return 0; }
    var i=0;
    for(var key in obj){
        if(obj.hasOwnProperty(key) && typeof obj[key] !='function'){i++;}
    }
    return i;
}