/*
Copyright 2004 Active Media Architects, Inc. - www.activema.com
Usage of these scripts is limited to their original intent as developed and deployed for Site Reign Merchant by Active Media Architects, Inc. Copying, selling or distributing of these scripts, in whole or in part, is strictly prohibited.
*/

var SIJS = {};
SIJS.id = function(id) {
	if ( typeof id == 'string' ) {
		return document.getElementById(id);
	} else {
		return id;
	}
};

SIJS.toggleMenu = function(el, show) {
	// need two for the white space textnode
	var sub = el.getElementsByTagName('ul')[0];
	sub.style.display = show ? 'block' : 'none';
//	sub.style.position = show ? 'relative' : 'absolute';
};

function registerDefaultInput(id, value)
{
	var el = SIJS.id(id);
	if ( !el ) {
		return;
	}

	if ( typeof value == 'undefined' ) {
		value = el.value;
	}

	el.onfocus = function() {
		if ( el.value === value ) {
			el.value = '';
			el.className = '';
		}
	};

	el.onblur = function() {
		if ( el.value === '' ) {
			el.value = value;
			el.className = 'has_placeholder';
		}
	}
}

$jq(document).ready(function() {
	$jq('tr.LiteHover').mouseenter(function() {
		$jq(this).data('oldbgcolor', $jq(this).css('backgroundColor'));
		$jq(this).css('backgroundColor', '#E8EFF7');
	});
	$jq('tr.LiteHover').mouseleave(function() {
		$jq(this).css('backgroundColor', $jq(this).data('oldbgcolor'));
	});
});

	///////////////////////////////////////
	// Mouseovers
	///////////////////////////////////////


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

  

	///////////////////////////////////////
	// Row-Over Effect
	///////////////////////////////////////

	function mouseOverWhite(i) {
		i.style.backgroundColor='#F2F2F2';
	}
	function mouseOutWhite(i) {
		i.style.backgroundColor='#FFFFFF';
	}
	
	function mouseOverGray(i) {
		i.style.backgroundColor='#F2F2F2';
	}
	function mouseOutGray(i) {
		i.style.backgroundColor='#F2F2F2';
	}
	


	///////////////////////////////////////
	// 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(); }
}




	///////////////////////////////////////
	// 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 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 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 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 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 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 validateNewLogin(form) {
	try { // produces error without this in account_new in IE6
	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 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["address"],"V","","Please enter your street address.",false) &&
				 checkSelect(form.elements["city"],"V","","Please enter your city.",false) &&
				 checkSelect(form.elements["state"],"V","","Please select your state or province.",false) &&
				 checkSelect(form.elements["zip"],"V","","Please enter your zip or postal code.",false));
	} catch (e) { }
	return true;
}

function validateGiftCertificateForm(form) {
	return (
				 checkSelect(form.elements["amount"],"V","","Please the amount of gift value.",false) &&
				 checkSelect(form.elements["recipient_name"],"V","","Please enter the recipient name.",false) &&
				 checkSelect(form.elements["recipient_email"],"V","","Please enter the recipient E-mail.",false) &&
				 checkEmail(form.elements["recipient_email"],false) &&
				 checkSelect(form.elements["recipient_email"],"V","joe@example.com","Please supply a valid E-mail Address.",false));
}

function validatePay(form) {
	return (
				 checkSelect(form.elements["cc_num"],"V","","You have chosen to pay by Credit Card. Please enter your Credit Card Number before continuing.",false) &&
				 checkSelect(form.elements["cc_expires_month"],"V","00","Please select the Month this credit card expires.",false) &&
				 checkSelect(form.elements["cc_expires_year"],"V","00","Please select the Year this credit card expires.",false) &&
				 checkSelect(form.elements["cc_id"],"V","","Please enter your credit card's 3-digit Identification Number.",false));
}
function validateCCInfo(form) {
	return (
				 checkSelect(form.elements["cc_number"],"V","","Please enter your Credit Card Number before continuing.",false) &&
				 checkSelect(form.elements["cc_month"],"V","00","Please select the Month this credit card expires.",false) &&
				 checkSelect(form.elements["cc_year"],"V","00","Please select the Year this credit card expires.",false) &&
				 checkSelect(form.elements["cc_first_name"],"V","","Please enter first name on the card.",false) &&
				 checkSelect(form.elements["cc_last_name"],"V","","Please enter last name on the card.",false) &&
				 checkSelect(form.elements["b_address"],"V","","Please enter your address.",false) &&
				 checkSelect(form.elements["b_city"],"V","","Please enter your city.",false) &&
				 checkSelect(form.elements["b_state"],"V","","Please enter your State.",false) &&
				 checkSelect(form.elements["b_zip"],"V","","Please enter your postal zip code.",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)
{
	if (
		checkSelect(form.elements["fullname"],"V","","Please enter your Full 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["password1"],"V","","Please create a Password.",false) &&
		checkSelect(form.elements["password2"],"V","","Please confirm your Password.",false) &&
		checkSelect(form.elements["billing_firstname"],"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_phone"],"V","","Please enter the billing Phone.",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)
	) {
		//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 Full Name.",false) &&
		 checkSelect(form.elements["billing_phone"],"V","","Please enter the billing Phone.",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))
	{
		//All billing was ok - check shipping and return it
		return validateShippingAddress(form);
		
	} 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 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 email.",false) &&
		checkSelect(form.elements["sender"],"V","","Please enter the shipping Address.",false) &&
		checkSelect(form.elements["from"],"V","","Please enter the shipping City.",false));
}

function checkProfile(form)
{
	var arrElements = new Array("fullname","phone", "address", "city", "state", "zip", "state");
	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_phone', 'ship_address', 'ship_city', 'ship_state', 'ship_zip');
	var fieldShipCount = arrShipFields.length;
	
	var arrBillFields = new Array('billing_fullname', 'billing_phone', 'billing_address', 'billing_city', 'billing_state', 'billing_zip');
	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 focusLoginField() {
	if ( typeof(document.new_login) != "undefined" ) {
		document.new_login.loginemail.focus();
	}
}

function LoginOptionCheck(myself) {

	frm = document.forms['new_login'];
	// 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['password'].type = "text";
//		frm.elements['password'].value = "You will be asked later";
//		frm.elements['password'].disabled = true;
		frm.elements['action'].value = "account_new";
		
	} else {
	// else if the old customer item is checked
	
		elem_pass_old.disabled = false;
		elem_pass_old.style.display = "";
		elem_pass_new.disabled = true;
		elem_pass_new.style.display = "none";
		
//		frm.elements['password'].value = "";
//		frm.elements['password'].disabled = false;
//		alert(frm.elements['password'].type);
//		frm.elements['password'].type = "password";
		
		
        frm.elements['loginemail'].focus();
		frm.elements['action'].value = "account";
		
	}
	
	frm.elements['loginemail'].focus();
}

function getCalendarDate()
{
   var months = new Array(13);
   months[0]  = "January";
   months[1]  = "February";
   months[2]  = "March";
   months[3]  = "April";
   months[4]  = "May";
   months[5]  = "June";
   months[6]  = "July";
   months[7]  = "August";
   months[8]  = "September";
   months[9]  = "October";
   months[10] = "November";
   months[11] = "December";
   var now         = new Date();
   var monthnumber = now.getMonth();
   var monthname   = months[monthnumber];
   var monthday    = now.getDate();
   var year        = now.getYear();
   if(year < 2000) { year = year + 1900; }
   var dateString = monthname + 
                    ' ' + 
                    monthday + 
                    ', ' + 
                    year;
   return dateString;
} // function getCalendarDate()

function getClockTime()
{
   var now    = new Date();
   var hour   = now.getHours();
   var minute = now.getMinutes();
   var second = now.getSeconds();
   var ap = "AM";
   if (hour   > 11) { ap = "PM";             }
   if (hour   > 12) { hour = hour - 12;      }
   if (hour   == 0) { hour = 12;             }
   if (hour   < 10) { hour   = "0" + hour;   }
   if (minute < 10) { minute = "0" + minute; }
   if (second < 10) { second = "0" + second; }
   var timeString = hour + 
                    ':' + 
                    minute + 
                    ':' + 
                    second + 
                    " " + 
                    ap;
   return timeString;
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}


function get_cookie_array()
{
	var arrCookies = new Array();
	var arrParts = document.cookie.split(";");
	
	for ( var i=0; i<arrParts.length; i++ ) {
		arrParts2 = arrParts[i].split("=");
		arrCookies[trim(arrParts2[0])] = trim(arrParts2[1]);
		
	}//for
	
	return arrCookies;
}

function changeFontSize(strDirection)
{
	var arrCookies = get_cookie_array();

	if ( !arrCookies['fontsize'] || arrCookies['fontsize'] == 'undefined' || arrCookies['fontsize'] == "NaN" ) {
		document.cookie = "fontsize=3; expires=Sun, 01-Dec-2020 08:00:00 GMT; path=/";
		var fontsize = 3;
		
	} else {
		var fontsize = parseInt(arrCookies['fontsize']);	
		if ( strDirection == "up" && fontsize < 5 ) {
			fontsize++;
				
		} else if ( strDirection == "down" && fontsize > 1 ) {
			fontsize--;
			
		}
		
		document.cookie = "fontsize=" + fontsize + "; expires=Sun, 01-Dec-2020 08:00:00 GMT; path=/";
		
	}
	
	var arrTds = document.getElementsByTagName('div');
	
	for ( var i=0; i<arrTds.length; i++ ) {
		if ( arrTds[i].className.indexOf("copy_story") != -1 ) {
			arrTds[i].className = "copy_story_" + fontsize; 
				
		}
		
	}//for
}

function updatePage()
{
	document.location = document.location;
					
}

function toggleSelectedLabel(node) {
	my_label = document.getElementById('label_for_'+node.id); 
	if (node.checked && my_label.className.indexOf('selected') < 0) { 
		my_label.className += ' selected';
	} else {
		my_label.className = my_label.className.replace(/selected/, '');
	}
}

function changeMainPod( main_div_id, clicked_a ) {
	pods = ['top_news','special_reports','most_read', 'highlighted_stories'];
	for ( i in pods ) {
		try {
			document.getElementById(pods[i]).style.display = 'none';
			document.getElementById(pods[i] + '_tab').className = document.getElementById(pods[i] + '_tab').className.replace(/\bon/,'');
		} catch (e) { }
	}
	
	document.getElementById(main_div_id).style.display = '';
	clicked_a.className += ' on';
}

function changeStockPod(el)
{
	var pods = ['all', 'si', 'pr', 'sec', 'major'];

	var $el = $jq(el);
	var $div = $jq('#' + $el.attr('id').replace('tab_', 'content_'));
	for ( var i = 0; i < pods.length; i++ ) {
		$jq('#content_' + pods[i]).hide();
		$jq('#tab_' + pods[i]).removeClass('on');
	}
	$div.show();
	$el.addClass('on');
}


