// http://www.htmldog.com/articles/suckerfish/dropdowns/ // IE COMPATIBILITY FOR :hover psuedo-class.
sfHover = function() { 
	try {
		var sfEls = document.getElementById("nav").getElementsByTagName("LI"); 	
		
		for (var i=0; i<sfEls.length; i++) { 
			
			sfEls[i].onmouseover=function() { 
				this.className+=" sfhover"; 
			} 
			sfEls[i].onmouseout=function() { 
				this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); 
			} 
		
		} 
	}
	catch( e ) {
		;
	}
} 
if (window.attachEvent) window.attachEvent("onload", sfHover); 


// December 18, 2008 WSH // EMU // BORROWED FROM http://lists.evolt.org/pipermail/javascript/2004-June/007409.html
function addCommas(someNum){
	while (someNum.match(/^\d\d{3}/)){
		someNum = someNum.replace(/(\d)(\d{3}(\.|,|$))/, '$1,$2');
	}
	return someNum;
}


	function toggleDiv( target, theLeft, mode ) {
		if (!theLeft) {
			theLeft = '0px';
		}
	
		// October 27, 2008 WSH // ADDED TOGGLING BY CHANGING DISPLAY INSTEAD OF SETTING POSITION, THIS DOESN'T WORK WELL FOR DIVS THAT AREN'T SUPPOSED TO BE FLOATING
		if ( !mode ) {
			mode = "position";
		}
	
		if( mode == "display" ) {
			if ( document.getElementById( target ).style.display == "none" ) {			
				document.getElementById( target ).style.display = "block";
			}
			else {			
				document.getElementById( target ).style.display = "none";
			}			
//				alert( 'mode is' + mode + " -- " + document.getElementById( target ).style.display );
		}
		else {
			if ( document.getElementById( target ).style.left == '-999px' ) {
				 // alert('Left position is -999px, setting to ' + theLeft);
				document.getElementById( target ).style.left = theLeft;
			}
			else {
				// alert('Left position is NOT -999px, is it 0? Setting it to -999px');
				document.getElementById( target ).style.left = '-999px';
			}
		}
	}

	// April 14, 2008 WSH // WHAT IS THIS GEM OF A FUNCTION? TOGGLE DIV ONLY BROUGHT DIVS TO THE LEFT OF SCREEN, THIS ONE IS WAY BETTER, SO I FINISHED OFF THE FUNCTIONALITY
	function toggleDivMiddle( target ) {
		//var winWidth = window.innerWidth;
		//var winHeight = window.innerHeight;
		// September 30, 2008 WSH // IE QUIRK, CAN'T DO ABOVE
		// See http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
		var winWidth = document.body.clientWidth;
		var winHeight = document.body.clientHeight;
		
		//alert("Window is " + winWidth + " x " + winHeight);
		
		var eleWidth = document.getElementById( target ).offsetWidth;
		var eleHeight = document.getElementById( target ).offsetHeight;
		//alert("Element is " + eleWidth + " x " + eleHeight);
		
		theLeft = (winWidth - eleWidth) / 2
		theTop = (winHeight - eleHeight) / 2
		
		theLeft += 'px';
		
		if( document.getElementById( target ).style.left == '-999px' ) {
			//document.getElementById( target ).style.top = theTop;			
			document.getElementById( target ).style.left = theLeft;
		}
		else {
			document.getElementById( target ).style.left = '-999px';
		}
	}
		
	
	
	
	
	
	
	// Copyright © 2001 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.

// ugly workaround for missing support for selectorText in Netscape6/Mozilla
// call onLoad() or before you need to do anything you would have otherwise used
// selectorText for.
var ugly_selectorText_workaround_flag = false;
var allStyleRules;
// code developed using the following workaround (CVS v1.15) as an example.
// http://lxr.mozilla.org/seamonkey/source/extensions/xmlterm/ui/content/XMLTermCommands.js
function ugly_selectorText_workaround() {
	if((navigator.userAgent.indexOf("Gecko") == -1) ||
	   (ugly_selectorText_workaround_flag)) {
		return; // we've already been here or shouldn't be here
	}
	var styleElements = document.getElementsByTagName("style");
	
	for(var i = 0; i < styleElements.length; i++) {
		var styleText = styleElements[i].firstChild.data;
		// this should be using match(/\b[\w-.]+(?=\s*\{)/g but ?= causes an
		// error in IE5, so we include the open brace and then strip it
		allStyleRules = styleText.match(/\b[\w-.]+(\s*\{)/g);
	}

	for(var i = 0; i < allStyleRules.length; i++) {
		// probably insufficient for people who like random gobs of 
		// whitespace in their styles
		allStyleRules[i] = allStyleRules[i].substr(0, (allStyleRules[i].length - 2));
	}
	ugly_selectorText_workaround_flag = true;
}


function updateCartTotals() {
	var subTotal = $('#cart_sub_total_display').html();
	var shipping = $('#shipping_rate_display').html();
	//var taxes = $('').html();
	
	subTotal = subTotal.substr( 1 );
	shipping = shipping.substr( 1 );
	
	subTotal = parseFloat( subTotal );
	shipping = parseFloat( shipping );
	
	var grandTotal = subTotal + shipping;
	grandTotal = grandTotal.toFixed(2);
	
	$('#cart_grand_total_display').html( '$' + grandTotal );
}

// setStyleById: given an element id, style property and 
// value, apply the style.
// args:
//  i - element id
//  p - property
//  v - value
//
function setStyleById(i, p, v) {
	try {
		var n = document.getElementById(i);
		// alert("i is " + i + " and n is " + n + " and v is " + v);
	
		n.style[p] = v;
	}
	catch(e) {
		// July 26, 2007 WSH // ADDED IN A TRY CATCH BLOCK JUST IN CASE IT'S UNSUCCESSFUL IN SETTING THE BORDER COLOR FOR SOME REASON
		//alert(e);
	}
}

// getStyleById: given an element ID and style property
// return the current setting for that property, or null.
// args:
//  i - element id
//  p - property
function getStyleById(i, p) {
	var n = document.getElementById(i);
	var s = eval("n.style." + p);

	// try inline
	if((s != "") && (s != null)) {
		return s;
	}

	// try currentStyle
	if(n.currentStyle) {
		var s = eval("n.currentStyle." + p);
		if((s != "") && (s != null)) {
			return s;
		}
	}
	
	// try styleSheets
	var sheets = document.styleSheets;
	if(sheets.length > 0) {
		// loop over each sheet
		for(var x = 0; x < sheets.length; x++) {
			// grab stylesheet rules
			var rules = sheets[x].cssRules;
			if(rules.length > 0) {
				// check each rule
				for(var y = 0; y < rules.length; y++) {
					var z = rules[y].style;
					// selectorText broken in NS 6/Mozilla: see
					// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
					ugly_selectorText_workaround();
					if(allStyleRules) {
						if(allStyleRules[y] == i) {
							return z[p];
						}			
					} else {
						// use the native selectorText and style stuff
						if(((z[p] != "") && (z[p] != null)) ||
						   (rules[y].selectorText == i)) {
							return z[p];
						}
					}
				}
			}
		}
	}
	return null;
}

// setStyleByClass: given an element type and a class selector,
// style property and value, apply the style.
// args:
//  t - type of tag to check for (e.g., SPAN)
//  c - class name
//  p - CSS property
//  v - value
var ie = (document.all) ? true : false;

function setStyleByClass(t,c,p,v){
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					eval('node.style.' + p + " = '" +v + "'");
				}
			}
		}
	}
}

// getStyleByClass: given an element type, a class selector and a property,
// return the value of the property for that element type.
// args:
//  t - element type
//  c - class identifier
//  p - CSS property
function getStyleByClass(t, c, p) {
	// first loop over elements, because if they've been modified they
	// will contain style data more recent than that in the stylesheet
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					var theStyle = eval('node.style.' + p);
					if((theStyle != "") && (theStyle != null)) {
						return theStyle;
					}
				}
			}
		}		
	}
	// if we got here it's because we didn't find anything
	// try styleSheets
	var sheets = document.styleSheets;
	if(sheets.length > 0) {
		// loop over each sheet
		for(var x = 0; x < sheets.length; x++) {
			// grab stylesheet rules
			var rules = sheets[x].cssRules;
			if(rules.length > 0) {
				// check each rule
				for(var y = 0; y < rules.length; y++) {
					var z = rules[y].style;
					// selectorText broken in NS 6/Mozilla: see
					// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
					ugly_selectorText_workaround();
					if(allStyleRules) {
						if((allStyleRules[y] == c) ||
						   (allStyleRules[y] == (t + "." + c))) {
							return z[p];
						}			
					} else {
						// use the native selectorText and style stuff
						if(((z[p] != "") && (z[p] != null)) &&
						   ((rules[y].selectorText == c) ||
						    (rules[y].selectorText == (t + "." + c)))) {
							return z[p];
						}
					}
				}
			}
		}
	}

	return null;
}

// setStyleByTag: given an element type, style property and 
// value, and whether the property should override inline styles or
// just global stylesheet preferences, apply the style.
// args:
//  e - element type or id
//  p - property
//  v - value
//  g - boolean 0: modify global only; 1: modify all elements in document
function setStyleByTag(e, p, v, g) {
	if(g) {
		var elements = document.getElementsByTagName(e);
		for(var i = 0; i < elements.length; i++) {
			elements.item(i).style[p] = v;
		}
	} else {
		var sheets = document.styleSheets;
		if(sheets.length > 0) {
			for(var i = 0; i < sheets.length; i++) {
				var rules = sheets[i].cssRules;
				if(rules.length > 0) {
					for(var j = 0; j < rules.length; j++) {
						var s = rules[j].style;
						// selectorText broken in NS 6/Mozilla: see
						// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
						ugly_selectorText_workaround();
						if(allStyleRules) {
							if(allStyleRules[j] == e) {
								s[p] = v;
							}			
						} else {
							// use the native selectorText and style stuff
							if(((s[p] != "") && (s[p] != null)) &&
							   (rules[j].selectorText == e)) {
								s[p] = v;
							}
						}

					}
				}
			}
		}
	}
}

// getStyleByTag: given an element type and style property, return
// the property's value
// args:
//  e - element type
//  p - property
function getStyleByTag(e, p) {
	var sheets = document.styleSheets;
	if(sheets.length > 0) {
		for(var i = 0; i < sheets.length; i++) {
			var rules = sheets[i].cssRules;
			if(rules.length > 0) {
				for(var j = 0; j < rules.length; j++) {
					var s = rules[j].style;
					// selectorText broken in NS 6/Mozilla: see
					// http://bugzilla.mozilla.org/show_bug.cgi?id=51944
					ugly_selectorText_workaround();
					if(allStyleRules) {
						if(allStyleRules[j] == e) {
							return s[p];
						}			
					} else {
						// use the native selectorText and style stuff
						if(((s[p] != "") && (s[p] != null)) &&
						   (rules[j].selectorText == e)) {
							return s[p];
						}
					}

				}
			}
		}
	}

	// if we don't find any style sheets, return the value for the first
	// element of this type we encounter without a CLASS or STYLE attribute
	var elements = document.getElementsByTagName(e);
	var sawClassOrStyleAttribute = false;
	for(var i = 0; i < elements.length; i++) {
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if((node.attributes.item(j).nodeName == 'class') ||
			   (node.attributes.item(j).nodeName == 'style')){
			   sawClassOrStyleAttribute = true;
			}
		}
		if(! sawClassOrStyleAttribute) {
			return elements.item(i).style[p];
		}
	}
}


	
	

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";

	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// January 16, 2009 WSH // FOO // ADDED PAYPAL
// February 12, 2007 WSH // ADDED IN DARREN'S NEW PAYMENT BOX SELECTING FUNCTION
function setBox( target ) {
	var boxes = new Array('cc', 'amex', 'po', 'paypal')
	// alert("setting box " + target);
	
	try {
		// December 12, 2007 WSH // CHANGED THE FUNCTION TO SET DISPLAY INSTEAD OF LEFT, BECAUSE THAT JUST MAKES REALLY MESSED UP LOOKING DIVS IN THE MIDDLE OF NOWHERE
		for(i = 0; i < boxes.length; i++) {
			// December 12, 2007 WSH // THE ELEMENT BELOW IS NO LONGER DISPLAYED, SO THAT LINE HAS TO GO
			//document.getElementById( boxes[i] ).style.className = 'py'
			document.getElementById( 'd_' + boxes[i] ).style.display = 'none'
			//document.getElementById( 'sp_' + boxes[i] ).innerHTML = ''
		}
		//alert( 'setting this to on' + target );
		//document.getElementById( target ).style.className = 'py_sel'
		document.getElementById( 'd_' + target ).style.display = 'block'
		//document.getElementById( 'sp_' + target ).innerHTML = 'Selected'
	}
	catch( e ) {
		//alert(e);
	}
	
	try {
		var paymentType = '';
		if( target == 'amex' ) {
			paymentType = 'amex';
		}
		else if( target == 'paypal' ) {
			paymentType = 'paypal';
		}
		else if( target == 'po' ) {
			paymentType = 'po';
		}
		else {
			paymentType = 'psigate_xml';
		}
		
		document.getElementById( 'paymentRadio' ).value = paymentType;		
	}
	catch( e ) {
		alert(e); // do nothing
	}
	// alert("CC now has class "  + document.getElementById( 'cc' ).style.className + "\n AMEX now has class "  + document.getElementById( 'amex' ).style.className + "\n PO now has class "  + document.getElementById( 'po' ).style.className + "\n")
	// alert("Target " + target + ' now has left position ' + document.getElementById( 'd_' + target ).style.left)
	
}

function checkSearch() {
	if( !document.getElementById("search_term").value && !document.getElementById("categories_id").value ) {
		alert("Please enter a search term or select a category.");
		document.getElementById("is_search").value = ""; 			
		return false;
	}
	else {
		return true;
	}
}


function updateLoginPane() {
	var loginType = getRadioValue( 'checkout_payment', 'login_type' );		
	if( loginType == 'existing' ) {
		document.getElementById( 'login_name' ).style.left = '-9999px';
		document.getElementById( 'loginSubmit' ).style.display = 'block';
		// document.getElementById( 'loginSubmitText' ).style.display = 'block';
		// document.getElementById( 'loginSubmitImage' ).style.display = 'block';
		document.getElementById( 'belowLoginDiv' ).style.display = 'none';
	
		document.getElementById( 'email_address' ).className = 'req';
		document.getElementById( 'password' ).className = 'req';
		document.getElementById( 'password_confirmation' ).className = '';
		document.getElementById( 'login_firstname' ).className = '';
		document.getElementById( 'login_lastname' ).className = '';
		// document.getElementById( 'billing_address_name' ).className = '';
		document.getElementById( 'billing_firstname' ).className = '';
		document.getElementById( 'billing_lastname' ).className = '';
		document.getElementById( 'billing_phone' ).className = '';
		document.getElementById( 'billing_street_address' ).className = '';
		// February 9, 2007 WSH // ADDED ANOTHER LINE TO STREET ADDRESS
		document.getElementById( 'billing_street_address2' ).className = '';
		document.getElementById( 'billing_city' ).className = '';
		document.getElementById( 'billing_country_id' ).className = '';
		document.getElementById( 'billing_postcode' ).className = '';
		//document.getElementById( 'shipping_address_name' ).className = '';
		document.getElementById( 'shipping_firstname' ).className = '';
		document.getElementById( 'shipping_lastname' ).className = '';
		document.getElementById( 'shipping_phone' ).className = '';
		document.getElementById( 'shipping_street_address' ).className = '';
		// February 9, 2007 WSH // ADDED ANOTHER LINE TO STREET ADDRESS
		document.getElementById( 'shipping_street_address2' ).className = '';
		document.getElementById( 'shipping_city' ).className = '';
		document.getElementById( 'shipping_country_id' ).className = '';
		document.getElementById( 'shipping_postcode' ).className = '';
	}
	else {
		document.getElementById( 'login_name' ).style.left = '0px';
		document.getElementById( 'loginSubmit' ).style.display = 'none';
		// document.getElementById( 'loginSubmitText' ).style.display = 'none';
		// document.getElementById( 'loginSubmitImage' ).style.display = 'none';
		document.getElementById( 'belowLoginDiv' ).style.display = 'block';
	
		document.getElementById( 'email_address' ).className = 'req';
		document.getElementById( 'password' ).className = 'req';
		document.getElementById( 'password_confirmation' ).className = 'req';
		document.getElementById( 'login_firstname' ).className = 'req';
		document.getElementById( 'login_lastname' ).className = 'req';
		// document.getElementById( 'billing_address_name' ).className = 'req';
		document.getElementById( 'billing_firstname' ).className = 'req';
		document.getElementById( 'billing_lastname' ).className = 'req';
		document.getElementById( 'billing_phone' ).className = 'req';
		document.getElementById( 'billing_street_address' ).className = 'req';
		// February 9, 2007 WSH // ADDED ANOTHER LINE TO STREET ADDRESS
		// document.getElementById( 'billing_street_address2' ).className = 'req';
		document.getElementById( 'billing_city' ).className = 'req';
		document.getElementById( 'billing_country_id' ).className = 'req';
		document.getElementById( 'billing_postcode' ).className = 'req';
		//document.getElementById( 'shipping_address_name' ).className = 'req';
		document.getElementById( 'shipping_firstname' ).className = 'req';
		document.getElementById( 'shipping_lastname' ).className = 'req';
		document.getElementById( 'shipping_phone' ).className = 'req';
		document.getElementById( 'shipping_street_address' ).className = 'req';
		// February 9, 2007 WSH // ADDED ANOTHER LINE TO STREET ADDRESS
		document.getElementById( 'shipping_street_address2' ).className = 'req';
		document.getElementById( 'shipping_city' ).className = 'req';
		document.getElementById( 'shipping_country_id' ).className = 'req';
		document.getElementById( 'shipping_postcode' ).className = 'req';
	
	}
}


function login() {
	var loginType = getRadioValue( 'login_pane', 'login_type' );		
	if( loginType == 'existing' ) {
		document.getElementById( 'login_name' ).setAttribute( 'style', 'display:none' );
		// WSH // TRY TO LOGIN THROUGH JAVASCRIPT?? 	


		ajaxRead('login_ajax.php?email_address=' + document.getElementById('email_address').value + '&password=' + document.getElementById('password').value, 'login');
	}
	else {
		// WSH // CHECK FOR ALREADY EXISTING EMAIL ADDRESS

		// WSH // FILL IN THE NAMES FOR THE BILLING ADDRESS FOR THE NEW ACCOUNT
		document.getElementById( 'billing_firstname' ).value = document.getElementById( 'login_firstname' ).value;
		document.getElementById( 'billing_lastname' ).value = document.getElementById( 'login_lastname' ).value;
	}
}

function processLogin(obj) {
	var dataArray = obj.getElementsByTagName('pets')[0].childNodes; 
 	var dataArrayLen = dataArray.length; 
 	var insertData = ''

 	var counter = 0;
 	for (var i=0; i<dataArrayLen; i++){ 			  	
   		if(dataArray[i].tagName){
   			document.getElementById('adBarID_' + counter).innerHTML = unescape(dataArray[i].getAttribute('content')).replace(/%20/g, ' ').replace(/\+/g, " ");
   			document.getElementById('adBarID_' + counter).setAttribute( 'onClick', dataArray[i].getAttribute('url') );	     
      		//insertData = dataArray[i].getAttribute('promotional_code');				  	 				
 		 		//document.getElementById(websitesArray[j] + 2).src='http://www.' + websitesArray[j] + '/site.php?apply_savings=yes&promotional_code=' + dataArray[i].getAttribute('promotional_code') + '&additional_savings_code=' + newVisitorsID;
 		 		counter++;  				  		 						  				
		}
	}
} 



function getRadioValue( formName, inputName ) {
	var radioLength = eval( 'document' + '.' + formName + '.' + inputName + '.length' );
	for( var i = 0; i < radioLength; i++ ) {
		if( eval( 'document' + '.' + formName + '.' + inputName + '[' + i + '].checked' ) ) {
			var radioValue = eval( 'document' + '.' + formName + '.' + inputName + '[' + i + '].value' );
		}
	}	

	if( !radioLength ) {
		var radioValue = eval( 'document' + '.' + formName + '.' + inputName + '[' + 0 + '].value');
	}

	return( radioValue );
}

// July 28, 2008 WSH // MERGED A FEW STEPS FOR NEW CHECKOUT DESIGN
/* November 26, 2007 WSH // ADDED FUNCTION TO HIGHLIGHT A DIV IN THE CHECKOUT */
function highlightDiv( divID, fromContinue ) {
	var divArray = Array(5);
	divArray[0] = 'account';
	divArray[1] = 'address';
	//divArray[2] = 'shipping';
	divArray[2] = 'payment';
	//divArray[4] = 'comments';
	
	try {		
		// IF NOT GOING THROUGH CONTINUE.GIF, THEN DO NOT ALLOW CLICKING ON DIVS THAT ARE NOT DONE		
		if( ( fromContinue !== true && document.getElementById( divID + "_done" ).src.indexOf( "done.gif" ) < 0 ) ) {
			return;
		}
		for( var i = 0; i < divArray.length; i++ ) {
			//alert( divArray[i] + divID );
			if( divID == divArray[i] + '_div' ) {			
				document.getElementById( divArray[i] + '_div' ).style.display='block';
				//document.getElementById( divArray[i] + '_img' ).src='./images_new/' + divArray[i] + '_on.gif';		
				
				if( divID == "payment_div" ) {
				// December 4, 2007 WSH // PRE SELECT VISA. FOR SOME REASON PSIGATE_XML FIELDS ARE CURRENTLY DEFAULTING TO DISPLAY NONE 
					highlightRow( 'paymentOptions', 'po_visa' ); setBox('cc'); toggle('psigate_xml', 'block');
				}				
			}
			else {
				document.getElementById( divArray[i] + '_div' ).style.display='none';
				//document.getElementById( divArray[i] + '_img' ).src='./images_new/' + divArray[i] + '_off.gif';							
			}			
		}
	}
	catch( e ) {
		 // do nothing
		 //alert( e );
	}
}
	
function highlightRow( tableID, rowId ) {
	var myTable = document.getElementById( tableID );
	for( var i = 0; i < myTable.rows.length; i++ ) {
		if( myTable.rows[i].id == rowId ) {
			//alert( myTable.rows[i].id + ' - ' + rowId );
			myTable.rows[i].className = 'sm_on';			
		}
		else {
			myTable.rows[i].className = 'sm_off';
		}
	}
}	

function toggleElement( element ) {
	var myElement = document.getElementById( element );	
	try {
		if ( myElement.style.display == 'block' ) {
			myElement.style.display = "none";
		}
		else {
			myElement.style.display = "block";
		}
	}
	catch( e ) {
	
	}
}

function selectShipping( value, id ) {
	//shippingOptionsRadio;
	//alert( 'inside selectShipping' + value );
	var radioObj = document.checkout_payment.shippingOptionsRadio;
	
	for(var i = 0; i < radioObj.length; i++) {	
		if(radioObj[i].value == value) {		
			radioObj[i].checked = true;
		   	if( navigator.appName == 'Microsoft Internet Explorer' ) {
   				if( id == 'os' ) {
   					document.getElementById('ownShippingMsg').style.display='block'; document.getElementById('own_account_shipping_company').setAttribute( 'className', 'req'); document.getElementById('own_account_shipping_method').setAttribute( 'className', 'req'); document.getElementById('own_account_account_number').setAttribute( 'className', 'req');
   				}
   				else {
					document.getElementById('ownShippingMsg').style.display='none'; document.getElementById('own_account_shipping_company').setAttribute( 'className', ''); document.getElementById('own_account_shipping_method').setAttribute( 'className', ''); document.getElementById('own_account_account_number').setAttribute( 'className', '');
   				}
		   	}
		   	else {		   
   				if( id == 'os' ) {
   					document.getElementById('ownShippingMsg').style.display='block'; document.getElementById('own_account_shipping_company').setAttribute( 'class', 'req'); document.getElementById('own_account_shipping_method').setAttribute( 'class', 'req'); document.getElementById('own_account_account_number').setAttribute( 'class', 'req');
   				}
   				else {
   					document.getElementById('ownShippingMsg').style.display='none'; document.getElementById('own_account_shipping_company').setAttribute( 'class', ''); document.getElementById('own_account_shipping_method').setAttribute( 'class', ''); document.getElementById('own_account_account_number').setAttribute( 'class', '');
   				}
		   	}   	   
		}
		else {
			radioObj[i].checked = false;
		}
	}	
}

/* November 30, 2007 WSH // ADDED FUNCTION TO CHECK IF ACCOUNT EXISTS */
function existingAccount(obj) {
	var dataArray = obj.getElementsByTagName('data')[0].childNodes; 
 	var dataArrayLen = dataArray.length; 
 	var insertData = ''

 	var found = false;
 	
 	for (var i=0; i<dataArrayLen; i++){ 			  	
   		if(dataArray[i].tagName){
   			if( dataArray[i].getAttribute( "found" ) == "true" ) {
   				found = true;
   				//document.getElementById( 'checkAccount' ).innerHTML = "account already exists";
   				document.getElementById( 'accountExists' ).value = "true";
   				break;
   			}
   			else {
   				document.getElementById( 'accountExists' ).value = "false";
   				break;
   			}

	 		counter++;  				  		 						  				
		}
	}
	
	document.getElementById( "checkingAccount" ).value = "done";
	return( found );
}

function toggleLoginType( id ) {
	try {
		if( id.search( "_login" ) >= 0 ) {
			document.getElementById( "login_type" ).value = "existing";
		}
		else {
			document.getElementById( "login_type" ).value = "new";	
		}
	}
	catch( e ) {
		;
	}
}

function updateAccount() {
alert( "in updateACcount" );
	if( document.getElementById( 'checkAccount' ).innerHTML.search( "already exists" ) ) {
	alert( "email address" );
		document.getElementById( 'email_address_login' ) = "bleh";
	}
}

function isNumeric( myNumber ) {
	var allowedChars = "0123456789";
	var isNumeric = true;
	
	for( var i = 0; i < myNumber.length; i++ ) {
		if( allowedChars.indexOf( myNumber[i] ) < 0 ) {
			isNumeric = false;
			break;
		}		
	}
	
	return( isNumeric );
}

function changeListSorting(source) {
	var sorting = document.getElementById( source ).value;
	
	// August 13, 2008 WSH // THE PRECEEDING SLASH WAS PUT IN PLACE TO COMBAT IE GAYNESS
	window.location = sorting;
}

function checkCompare() {
	
	var maxCompare = 5;
	var numSelected = 0;

	for( var i = 0; i < document.forms['compare'].elements.length; i++ ) {
		if( document.forms['compare'].elements[i].name == "products_ids[]" ) {
			if( document.forms['compare'].elements[i].checked ) {
				numSelected += 1;			
			}
		}	
	}
	
	if( maxCompare >= numSelected ) {
		document.compare.submit();
	}
	else {
		alert( "You may only compare up to " + maxCompare + " products at once." );
	}	
}

