//These will be useful for compressing the javascript
var doc = document;
var win = window;
//This is where we put all things that need to fire instead of body onload event
jQuery(doc).ready(function() {
	/*Cookie Check*/
		setCookie('cookietest','none');
		if ( getCookie("cookietest") == null ) jQuery('div#nocookie').show();
		delCookie('cookietest');
	/* End Cookie Check*/
	jQuery.expr[':'].cross = function(obj){
      return !obj.href.match(/^mailto\:/) && (obj.hostname.indexOf('shop.siriusxm.com') != -1);
	};
	//jQuery('ul#navigation').addClass('shop');
	jQuery('a:cross').addClass('siriusxm');
	jQuery('.popupcontinue').removeClass('siriusxm');
	jQuery('.nopopup').removeClass('siriusxm');
	jQuery('.siriusxm').click(function(e) {
		e.preventDefault();
		if (jQuery('.popupcontinue')) jQuery('.popupcontinue').attr('href', jQuery(this).attr('href'));
		var xmpopwindow = '#popup_default';
		if (getCookie('EIMINICART_2640') && getCookie('EIMINICART_2640') > 0)  xmpopwindow = '#popup_itemsincart';
		if (flCustLogon) xmpopwindow = '#popup_loggedin';
		jQuery.openDOMWindow({ height:319, width:592, windowPadding:0, borderSize:0, windowBGColor:'transparent', overlay:1, overlayColor:'#000000', overlayOpacity:'50', windowSourceID:xmpopwindow });
		jQuery('div#DOMWindowOverlay').css('position','absolute');
		jQuery('div#DOMWindowOverlay').css('height',Screen.getDocumentHeight());
	});
	jQuery('ul#TopNav li').hover(
		function() {
			if (jQuery(this).find('img').length > 0) {
				if (jQuery(this).find('img').attr('src').indexOf('_off') > -1) jQuery(this).find('img').imgHoverOn();
			}
		},
		function() {
			if (jQuery(this).find('img').length > 0) {
				if (jQuery(this).find('img').attr('src').indexOf('_hover') > -1) jQuery(this).find('img').imgHoverOff();
			}
		}
	);

	//VC: new inline validation
	if (validationInline) {
		jQuery('input#usrname').blur(function(){ validateUsrName(this.form); });
		jQuery('input#usname').blur(function(){ validateUsName(this.form); });
		jQuery('input#pwd').blur(function(){ validatePwd(this.form); });
		jQuery('input#pwd_conf').blur(function(){ validatePwd_Conf(this.form); });
		jQuery('input#confirmpwd').blur(function(){ validateConfirmPwd(this.form); });
		jQuery('input#fname').blur(function(){ validateFName(this.form); });
		jQuery('input#lname').blur(function(){ validateLName(this.form); });
		jQuery('input#company_name').blur(function(){ validateCompany_Name(this.form); });
		jQuery('input#addr1').blur(function(){ validateAddr1(this.form); });
		jQuery('input#addr2').blur(function(){ validateAddr2(this.form); });
		jQuery('input#city').blur(function(){ validateCity(this.form); });
		// value is hardcoded unecessary jQuery('form#Registration input#cntry').blur(function(){ validateCntry(this.form); });
		jQuery('input#state').blur(function(){ validateState(this.form); });
		jQuery('select#state').change(function(){ validateState(this.form); });
		jQuery('input#zipc').blur(function(){ validateZipC(this.form); });
		jQuery('input#email').blur(function(){ validateEmail(this.form); });
		jQuery('input#phone').blur(function(){ validatePhone(this.form); });
		jQuery('input#ba_fname').blur(function(){ BAvalidateFName(this.form); });
		jQuery('input#ba_lname').blur(function(){ BAvalidateLName(this.form); });
		jQuery('input#ba_company_name').blur(function(){ BAvalidateCompany_Name(this.form); });
		jQuery('input#ba_addr1').blur(function(){ BAvalidateAddr1(this.form); });
		jQuery('input#ba_addr2').blur(function(){ BAvalidateAddr2(this.form); });
		jQuery('input#ba_city').blur(function(){ BAvalidateCity(this.form); });
		// value is hardcoded unecessary jQuery('form#Registration input#ba_cntry').blur(function(){ BAvalidateCntry(this.form); });
		jQuery('input#ba_state').blur(function(){ BAvalidateState(this.form); });
		jQuery('select#ba_state').change(function(){ BAvalidateState(this.form); });
		jQuery('input#ba_zipc').blur(function(){ BAvalidateZipC(this.form); });
		jQuery('input#ba_email').blur(function(){ BAvalidateEmail(this.form); });
		jQuery('input#ba_phone').blur(function(){ BAvalidatePhone(this.form); });
		//jQuery('input#email_conf').blur(function(){ BAvalidateEmail_Conf(this.form); });
		jQuery('input#billing_fname').blur(function(){ BillingvalidateFName(this.form); });
		jQuery('input#billing_lname').blur(function(){ BillingvalidateLName(this.form); });
		jQuery('input#billing_company_name').blur(function(){ BillingvalidateCompany_Name(this.form); });
		jQuery('input#billing_addr1').blur(function(){ BillingvalidateAddr1(this.form); });
		jQuery('input#billing_addr2').blur(function(){ BillingvalidateAddr2(this.form); });
		jQuery('input#billing_city').blur(function(){ BillingvalidateCity(this.form); });
		// value is hardcoded unecessary jQuery('form#Registration input#billing_cntry').blur(function(){ BillingvalidateCntry(this.form); });
		jQuery('input#billing_state').blur(function(){ BillingvalidateState(this.form); });
		jQuery('select#billing_state').change(function(){ BillingvalidateState(this.form); });
		jQuery('input#billing_zipc').blur(function(){ BillingvalidateZipC(this.form); });
		jQuery('input#billing_email').blur(function(){ BillingvalidateEmail(this.form); });
		jQuery('input#billing_phone').blur(function(){ BillingvalidatePhone(this.form); });
		//jQuery('input#email_conf').blur(function(){ BAvalidateEmail_Conf(this.form); });
		jQuery('input#vca_name').blur(function(){ validateVca_Name(this.form); });
	}
	jQuery('input#send').click(function(){ if(validateForms(this.form)){this.form.submit(); }});
	jQuery('input#addButton').click(function(){if(validateForms(this.form)){doAddNew(this.form); }});

	var changeMe = 0;
	jQuery('ul#TopNav li').hover(
		function() {
			if (jQuery(this).find('img').length > 0) {
				changeMe = jQuery(this).find('img').attr('src').indexOf('_off');
				jQuery(this).find('img').imgHoverOn();
			}
		},
		function() {
			if (jQuery(this).find('img').length > 0)
				if (changeMe > 0) jQuery(this).find('img').imgHoverOff();
		}
	);
	//Shopping Cart banner for Starmate 8
	jQuery('img[src="/ctlimg/sirius/cart_banner/Sirius_Home_Kits_st8.jpg"]').click(function(){
		DynamicForm('ctl_nbr=2640~siId=5984945~siQty=1~nurl=control/AddOrder.vm~eurl=control/StoreItem.vm~rurl=control/AddOrder.vm~omni_scAdd=scAdd','/edealinv/servlet/AddStoreOrderItem','post');
		return false;
	});
	jQuery('img[src="https://shop.sirius.com/ctlimg/sirius/cart_banner/Sirius_Home_Kits_st8.jpg"]').click(function(){
		DynamicForm('ctl_nbr=2640~siId=5984945~siQty=1~nurl=control/AddOrder.vm~eurl=control/StoreItem.vm~rurl=control/AddOrder.vm~omni_scAdd=scAdd','/edealinv/servlet/AddStoreOrderItem','post');
		return false;
	});
	//Shopping Cart banner for Starmate 5
	jQuery('img[src="/ctlimg/sirius/cart_banner/Sirius_Home_Kits_st5.jpg"]').click(function(){
		DynamicForm('ctl_nbr=2640~siId=5984945~siQty=1~nurl=control/AddOrder.vm~eurl=control/StoreItem.vm~rurl=control/AddOrder.vm~omni_scAdd=scAdd','/edealinv/servlet/AddStoreOrderItem','post');
		return false;
	});
	jQuery('img[src="https://shop.sirius.com/ctlimg/sirius/cart_banner/Sirius_Home_Kits_st5.jpg"]').click(function(){
		DynamicForm('ctl_nbr=2640~siId=5984945~siQty=1~nurl=control/AddOrder.vm~eurl=control/StoreItem.vm~rurl=control/AddOrder.vm~omni_scAdd=scAdd','/edealinv/servlet/AddStoreOrderItem','post');
		return false;
	});
	//Shopping Cart banner for Stratus 6
	jQuery('img[src="/ctlimg/sirius/cart_banner/Sirius_Home_Kits_sv6.jpg"]').click(function(){
		DynamicForm('ctl_nbr=2640~siId=5984945~siQty=1~nurl=control/AddOrder.vm~eurl=control/StoreItem.vm~rurl=control/AddOrder.vm~omni_scAdd=scAdd','/edealinv/servlet/AddStoreOrderItem','post');
		return false;
	});
	jQuery('img[src="https://shop.sirius.com/ctlimg/sirius/cart_banner/Sirius_Home_Kits_sv6.jpg"]').click(function(){
		DynamicForm('ctl_nbr=2640~siId=5984945~siQty=1~nurl=control/AddOrder.vm~eurl=control/StoreItem.vm~rurl=control/AddOrder.vm~omni_scAdd=scAdd','/edealinv/servlet/AddStoreOrderItem','post');
		return false;
	});
	//BOGO Offer for December 2011
	jQuery('img[src="/ctlimg/sirius/cart_banner/Sirius_SV6_BOGO_v3.jpg"]').click(function(){
		DynamicForm('ctl_nbr=2640~siId=5921838~skuoption_5680=Quarterly Service w/75 cancel fee [Hardware]|SIR_AUD_EVT|Quarterly Sirius Internet Radio~siQty=1~nurl=control/AddOrder.vm~eurl=control/StoreItem.vm~rurl=control/AddOrder.vm~omni_scAdd=scAdd~sku_subscribe=Y','/edealinv/servlet/AddStoreOrderItem','post');
		return false;
	});
	jQuery('img[src="https://shop.sirius.com/ctlimg/sirius/cart_banner/Sirius_SV6_BOGO_v3.jpg"]').click(function(){
		DynamicForm('ctl_nbr=2640~siId=5921838~skuoption_5680=Quarterly Service w/75 cancel fee [Hardware]|SIR_AUD_EVT|Quarterly Sirius Internet Radio~siQty=1~nurl=control/AddOrder.vm~eurl=control/StoreItem.vm~rurl=control/AddOrder.vm~omni_scAdd=scAdd~sku_subscribe=Y','/edealinv/servlet/AddStoreOrderItem','post');
		return false;
	});
	jQuery('img[src="/ctlimg/sirius/cart_banner/SIR_shopcart_CyberMonday1.jpg"]').click(function(){
		DynamicForm('ctl_nbr=2640~siId=4991383~siQty=1~nurl=control/AddOrder.vm~eurl=control/StoreItem.vm~rurl=control/AddOrder.vm~omni_scAdd=scAdd','/edealinv/servlet/AddStoreOrderItem','post');
		return false;
	});
	jQuery('img[src="https://shop.sirius.com/ctlimg/sirius/cart_banner/SIR_shopcart_CyberMonday1.jpg"]').click(function(){
		DynamicForm('ctl_nbr=2640~siId=4991383~siQty=1~nurl=control/AddOrder.vm~eurl=control/StoreItem.vm~rurl=control/AddOrder.vm~omni_scAdd=scAdd','/edealinv/servlet/AddStoreOrderItem','post');
		return false;
	});

});
jQuery.fn.imgHoverOn = function() {
	jQuery(this).attr('src', jQuery(this).attr('src').replace('_off', '_hover'));
}
jQuery.fn.imgHoverOff = function() {
	jQuery(this).attr('src', jQuery(this).attr('src').replace('_hover', '_off'));
}


/* Other useful functions we will be using throught the site */
function DynamicForm(params, path, method) {
	method = method || 'post'; // Set method to post by default, if not specified.
	path = path || '/edealinv/servlet/AddStoreOrderItem'; // Set path to the default addStoreOrderItem by default, if not specified.
	var form = doc.createElement('form'); //Create our Form
	form.setAttribute('method', method); //Set the Method of the form
	form.setAttribute('action', path); //set the attribute of the form
	parameters = params.split('~'); // Lets split our parameters list
	//Now we will loop through our parameters
	for ( var i = 0; i < parameters.length; ++i ) {
		var pair = parameters[i].split('='); //Split the value to get our name and value
		var hiddenField = doc.createElement('input'); //add input element
		hiddenField.setAttribute('type', 'hidden'); //lets make it hidden since we do not need to see it
		hiddenField.setAttribute('name', pair[0].replace(/^\s\s*/, '').replace(/\s\s*$/, '')); //Assign the name and trim the name in case we have some whitespace from velocity code
		hiddenField.setAttribute('value', pair[1].replace(/^\s\s*/, '').replace(/\s\s*$/, '')); //Assign the value and trim the value in case we have some whitespace from velocity code
		form.appendChild(hiddenField); //append the input to our form
	}
	doc.body.appendChild(form); //append the form to the DOM
	form.submit(); //submit the form
	doc.body.removeChild(form);//Just in case we will remove the form from the DOM
}
// Test if the user is logged in if so the flCustLogon flag will be true
var flCustLogon = false;
if (getCookie('EISESSION_ID') && getCookie('EISESSION_ID') != '') flCustLogon = true;
/* This is for accessing the query string if we need it
**USAGE
	to retrieve value urlObj['query_string_variable_name']
	to test for value if ('query_string_variable_name' in urlObj)
*/
var urlObj = new Object();
win.location.search.replace (
	new RegExp( '([^?=&]+)(=([^&]*))?', 'g' ),
	function( $0, $1, $2, $3 ) { urlObj[ $1 ] = $3; }
);
//This is for getting the cookie pretty simple
function getCookie(cookieName) {
  var results = doc.cookie.match('(^|;) ?' + cookieName + '=([^;]*)(;|$)');
  if (results) return ( unescape(results[2]));
  else return null;
}
function get_cookie(cookieName) { return getCookie(cookieName); }
//This is for setting cookies pretty self explanitory cookieName and cookieValue are required otherwise it will use default values that are not sent default expiry is 10 years
function setCookie(cookieName, cookieValue, cookieExpireHours, cookiePath, cookieDomain, cookieSecure) {
	var expires = 3153600000000;
	var today = new Date();
	today.setTime( today.getTime() );
	if (cookieExpireHours) expires = cookieExpireHours * 1000 * 60;
	var expires_date = new Date( today.getTime() + (expires) );
	doc.cookie = cookieName + '=' + escape( cookieValue ) + ((cookieExpireHours) ? ';expires=' + expires_date.toGMTString() : '') + ((cookiePath) ? ';path=' + cookiePath : '') + (( cookieDomain) ? ';domain=' + cookieDomain : '') + ((cookieSecure) ? ';secure' : '');
}
//This will delete a cookie value
function delCookie(cookieName, cookiePath, cookieDomain) {
	if (getCookie(cookieName)) document.cookie = cookieName + '=' + ((cookiePath) ? ';path=' + cookiePath : '') + ((cookieDomain) ? ';domain=' + cookieDomain : '') + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
 /* Copyright (c)2005-2009 Matt Kruse (javascripttoolbox.com)
 *
 * Dual licensed under the MIT and GPL licenses.
 * This basically means you can use this code however you want for
 * free, but don't claim to have written it yourself!
 * Donations always accepted: http://www.JavascriptToolbox.com/donate/
 *
 * Please do not link to the .js files on javascripttoolbox.com from
 * your site. Copy the files locally to your server instead.
 *
 */
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('k 2K={\'$2M\':1.2F};9 1p(o){5(o!=f&&A(o)=="X"&&A(o.w)=="2u"&&(o.w==0||m(o[0])))};9 1O(o){5(o!=f&&A(o)=="X"&&m(o.1Y)&&o.1Y==31&&!m(o.1c))};9 m(o){5(A(o)!="2N")};9 20(R){k i,j,o;k y=[];7(A(R)=="W"){R=1t 2P(\'$22\',R)}I(i=1;i<S.w;i++){o=S[i];7(1p(o)){I(j=0;j<o.w;j++){y[y.w]=R(o[j])}}x 7(1O(o)){I(j 1x o){y[y.w]=R(o[j])}}x{y[y.w]=R(o)}}5 y};9 2O(o,13){7(!m(o)||o==f){o={}}7(!m(13)||13==f){5 o}I(k p 1x 13){7(!m(o[p])){o[p]=13[p]}}5 o};21.2X.1W=9(o){k i,l;7(!(l=1Z.w)){5 G}I(i=0;i<l;i++){7(o==1Z[i]){5 H}}};k 2S=(9(){k L={};L.2T=9(o,O){7(o==f){5 f}7(1p(O)){O=20("5 $22.1M()",O);1g(o=o.17){7(o.1c&&O.1W(o.1c)){5 o}}}x{O=O.1M();1g(o=o.17){7(o.1c&&O==o.1c){5 o}}}5 f};L.2U=9(o){7(o!=f&&o.17&&o.17.1V){I(k i 1x o){7(A(o[i])=="9"){o[i]=f}}o.17.1V(o);5 H}5 G};L.2V=9(o){7(m(o.1L)){5 o.1L}5 f};L.30=9(o){7(m(o.1I)){5 o.1I}5 f};L.V=9(){k y=1t 21();k i,j,o;I(k i=0;i<S.w;i++){k o=S[i];7(o==f){7(S.w==1){5 f}y[y.w]=f}x 7(A(o)==\'W\'){7(h.1A){o=h.1A(o)}x 7(h.2f){o=h.2f[o]}7(S.w==1){5 o}y[y.w]=o}x 7(1p(o)){I(j=0;j<o.w;j++){y[y.w]=o[j]}}x 7(1O(o)){I(j 1x o){y[y.w]=o[j]}}x 7(S.w==1){5 o}x{y[y.w]=o}}5 y};L.$=L.V;5 L})();k 18=(9(){k r={};r.27=9(1d){7(A(1d)!="W"||!m(1d.1n)){5 f}k 1e=1d.1n(/^\\s*12\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*/);7(1e==f){5 1d}k 12=+1e[1]<<16|+1e[2]<<8|+1e[3];k Q="";k 24="2C";1g(12!=0){Q=24.1F(12&2J)+Q;12>>>=4}1g(Q.w<6){Q=\'0\'+Q}5"#"+Q};r.1E=9(z){7(!m(z)||z==f){5 f}7(z.2I("-")<0){5 z}k 11="";k c=f;k l=z.w;I(k i=0;i<l;i++){c=z.1F(i);11+=(c!="-")?c:z.1F(++i).1M()}5 11};r.1K=9(q,u){7(!m(q)||q==f||!1J){5 G}k 14=1t 1J("(^|\\\\s)"+u+"(\\\\s|$)");7(A(q)=="W"){5 14.1l(q)}x 7(A(q)=="X"&&q.u){5 14.1l(q.u)}5 G};r.25=9(q,u){7(A(q)!="X"||q==f||!m(q.u)){5 G}7(q.u==f||q.u==\'\'){q.u=u;5 H}7(r.1K(q,u)){5 H}q.u=q.u+" "+u;5 H};r.2a=9(q,u){7(A(q)!="X"||q==f||!m(q.u)||q.u==f){5 G}7(!r.1K(q,u)){5 G}k 14=1t 1J("(^|\\\\s+)"+u+"(\\\\s+|$)");q.u=q.u.1N(14,\' \');5 H};r.3k=9(q,u,26){7(A(q)!="X"||q==f||!m(q.u)||q.u==f){5 G}r.2a(q,u);r.25(q,26);5 H};r.1k=9(o,z){7(o==f){5 f}k p=f;k 1f=r.1E(z);7(z=="29"){p=r.1k(o,"2e");7(p==f){p=r.1k(o,"2d")}}x 7(o.1P&&m(o.1P[1f])){p=o.1P[1f]}x 7(Z.28){p=Z.28(o,f).38(z)}x 7(o.F&&m(o.F[1f])){p=o.F[1f]}7(/^\\s*12\\s*\\(/.1l(p)){p=r.27(p)}7(/^#/.1l(p)){p=p.2t()}5 p};r.19=r.1k;r.23=9(o,z,M){7(o==f||!m(o.F)||!m(z)||z==f||!m(M)){5 G}7(z=="29"){o.F["2e"]=M;o.F["2d"]=M}x 7(z=="1b"){o.F[\'-33-1b\']=M;o.F[\'-34-1b\']=M;o.F.1b=M;7(m(o.F.2c)){o.F.2c="35(1b="+M*1q+")"}}x{o.F[r.1E(z)]=M}5 H};r.3b=r.23;r.1X=3h;r.3f=9(o){7(m(o)&&o!=f&&m(o.E)&&o.E!=f&&o.E!=""){5 o.E}k E=f;1g(E==f||h.1A(E)!=f){E="3c"+(r.1X++)}7(m(o)&&o!=f&&(!m(o.E)||o.E=="")){o.E=E}5 E};5 r})();k 3m=(9(){k D={};D.V=9(e){7(!m(e)&&m(Z.2b)){e=Z.2b}5 e};D.3d=9(q,1y,1z,2x){7(q.2B){q.2B(1y,1z,2x);5 H}x 7(q.2z){q.2z("3e"+1y,1z);5 H}5 G};D.3g=9(e){e=D.V(e);7(m(e.2y)){5 e.2y}7(m(e.2A)){5 e.2A+1D.2i()}5 f};D.3a=9(e){e=D.V(e);7(m(e.2v)){5 e.2v}7(m(e.2g)){5 e.2g+1D.2w()}5 f};D.1j=9(e){e=D.V(e);7(A(e.1B)=="9"){e.1B()}7(m(e.1j)){e.1j=H}};D.1B=D.1j;D.1C=9(e){e=D.V(e);7(A(e.1C)=="9"){e.1C()}7(m(e.2m)){e.2m=G}};5 D})();k 1D=(9(){k B={};B.1U=9(){7(h.v){5 h.v}7(h.2k){k 1i=h.2k("36");7(1i!=f&&1i.w>0){5 1i[0]}}5 f};B.2w=9(){7(h.C&&m(h.C.1a)&&h.C.1a>0){5 h.C.1a}7(h.v&&m(h.v.1a)){5 h.v.1a}5 f};B.2i=9(){7(h.C&&m(h.C.15)&&h.C.15>0){5 h.C.15}7(h.v&&m(h.v.15)){5 h.v.15}5 f};B.Y=9(n){5(!m(n)||1m(n))?0:n};B.3j=9(){k T=0;k v=B.1U();7(h.C&&(!h.J||h.J=="1s")){k 2o=1h(18.19(v,\'37\'),10)||0;k 2n=1h(18.19(v,\'39\'),10)||0;T=1w.1u(v.1L+2n+2o,h.C.1r)}x{T=1w.1u(v.1r,v.3i)}7(1m(T)||T==0){T=B.Y(N.2q)}5 T};B.3n=9(){k v=B.1U();k U=(m(N.U)&&!1m(N.U))?N.U:0;7(h.C&&(!h.J||h.J=="1s")){k 2s=1h(18.19(v,\'3p\'),10)||0;k 2r=1h(18.19(v,\'3o\'),10)||0;5 1w.1u(v.1I+2s+2r,h.C.1o,h.C.2p,B.Y(N.U))}5 1w.1u(v.2p,v.1o,B.Y(N.U))};B.3l=9(){7(h.C&&(!h.J||h.J=="1s")){5 h.C.1r}x 7(h.J&&h.v){5 h.v.1r}5 B.Y(N.2q)};B.32=9(){7(!Z.2h&&h.C&&(!h.J||h.J=="1s")){5 h.C.1o}x 7(h.J&&!Z.2h&&h.v){5 h.v.1o}5 B.Y(N.U)};5 B})();k 2H=(9(){k t={};t.1G=9(a,b){7(a==b){5 0}7(a<b){5-1}5 1};t.2G=t.1G;t.1v=9(p){7(A(p)!="2u"){7(A(p)=="W"){p=2D(p.1N(/,/g,\'\'));7(1m(p)||p==f){p=0}}x{p=0}}5 p};t.1T=9(a,b){5 t.1v(a)-t.1v(b)};t.1H=9(p){7(p==f){p=""}5(""+p).2t()};t.2E=9(a,b){5 t.1G(t.1H(a),t.1H(b))};t.1S=9(p){7(A(p)=="W"){p=p.1N(/^[^\\d\\.]/,\'\')}5 t.1v(p)};t.2L=9(a,b){5 t.1T(t.1S(a),t.1S(b))};t.1Q=9(p){9 2l(11){9 1R(P){P=+P;7(P<2W){P+=2Y}x 7(P<1q){P+=2Z}5 P};k K;7(K=11.1n(/(\\d{2,4})-(\\d{1,2})-(\\d{1,2})/)){5(1R(K[1])*2j)+(K[2]*1q)+(+K[3])}7(K=11.1n(/(\\d{1,2})[\\/-](\\d{1,2})[\\/-](\\d{2,4})/)){5(1R(K[3])*2j)+(K[1]*1q)+(+K[2])}5 2R};5 2l(p)};t.2Q=9(a,b){5 t.1T(t.1Q(a),t.1Q(b))};5 t})();',62,212,'|||||return||if||function||||||null||document|||var||defined|||val|obj|css||sort|className|body|length|else|results|property|typeof|screen|documentElement|ev|id|style|false|true|for|compatMode|ret|dom|value|self|tagNames|yr|hex|func|arguments|width|innerHeight|resolve|string|object|zero|window||str|rgb|values|re|scrollLeft||parentNode|CSS|get|scrollTop|opacity|nodeName|rgbString|result|camelProperty|while|parseInt|bodies|cancelBubble|getStyle|test|isNaN|match|clientHeight|isArray|100|clientWidth|CSS1Compat|new|max|NumericConversion|Math|in|type|fn|getElementById|stopPropagation|preventDefault|Screen|hyphen2camel|charAt|AlphaNumeric|IgnoreCaseConversion|offsetHeight|RegExp|hasClass|offsetWidth|toUpperCase|replace|isObject|currentStyle|DateConversion|fixYear|CurrencyConversion|Numeric|getBody|removeChild|contains|uniqueIdNumber|constructor|this|map|Array|_|setStyle|digits|addClass|newClassName|rgb2hex|getComputedStyle|float|removeClass|event|filter|styleFloat|cssFloat|all|clientY|opera|getScrollLeft|10000|getElementsByTagName|getdate|returnValue|leftMargin|rightMargin|scrollHeight|innerWidth|bottomMargin|topMargin|toLowerCase|number|pageY|getScrollTop|capture|pageX|attachEvent|clientX|addEventListener|0123456789abcdef|parseFloat|IgnoreCase|06|Default|Sort|indexOf|0xf|Util|Currency|VERSION|undefined|setDefaultValues|Function|Date|99999999|DOM|getParentByTagName|removeNode|getOuterWidth|50|prototype|2000|1900|getOuterHeight|Object|getViewportHeight|moz|khtml|alpha|BODY|marginRight|getPropertyValue|marginLeft|getMouseY|set|ID_|add|on|createId|getMouseX|1000|scrollWidth|getDocumentWidth|replaceClass|getViewportWidth|Event|getDocumentHeight|marginBottom|marginTop'.split('|'),0,{}))

// Determine if a reference is defined
function defined(o) {
  return (typeof(o)!="undefined");
};
/* ******************************************************************* */
/*   SCREEN FUNCTIONS                                                  */
/* ******************************************************************* */
var Screen = (function() {
  var screen = {};

  // Get a reference to the body
  // --------------------------------------------------------------------
  screen.getBody = function() {
    if (document.body) {
      return document.body;
    }
    if (document.getElementsByTagName) {
      var bodies = document.getElementsByTagName("BODY");
      if (bodies!=null && bodies.length>0) {
        return bodies[0];
      }
    }
    return null;
  };

  // Get the amount that the main document has scrolled from top
  // --------------------------------------------------------------------
  screen.getScrollTop = function() {
    if (document.documentElement && defined(document.documentElement.scrollTop) && document.documentElement.scrollTop>0) {
      return document.documentElement.scrollTop;
    }
    if (document.body && defined(document.body.scrollTop)) {
      return document.body.scrollTop;
    }
    return null;
  };

  // Get the amount that the main document has scrolled from left
  // --------------------------------------------------------------------
  screen.getScrollLeft = function() {
    if (document.documentElement && defined(document.documentElement.scrollLeft) && document.documentElement.scrollLeft>0) {
      return document.documentElement.scrollLeft;
    }
    if (document.body && defined(document.body.scrollLeft)) {
      return document.body.scrollLeft;
    }
    return null;
  };

  // Util function to default a bad number to 0
  // --------------------------------------------------------------------
  screen.zero = function(n) {
    return (!defined(n) || isNaN(n))?0:n;
  };

  // Get the width of the entire document
  // --------------------------------------------------------------------
  screen.getDocumentWidth = function() {
    var width = 0;
    var body = screen.getBody();
    if (document.documentElement && (!document.compatMode || document.compatMode=="CSS1Compat")) {
        var rightMargin = parseInt(CSS.get(body,'marginRight'),10) || 0;
        var leftMargin = parseInt(CSS.get(body,'marginLeft'), 10) || 0;
      width = Math.max(body.offsetWidth + leftMargin + rightMargin, document.documentElement.clientWidth);
    }
    else {
      width =  Math.max(body.clientWidth, body.scrollWidth);
    }
    if (isNaN(width) || width==0) {
      width = screen.zero(self.innerWidth);
    }
    return width;
  };

  // Get the height of the entire document
  // --------------------------------------------------------------------
  screen.getDocumentHeight = function() {
    var body = screen.getBody();
    var innerHeight = (defined(self.innerHeight)&&!isNaN(self.innerHeight))?self.innerHeight:0;
    if (document.documentElement && (!document.compatMode || document.compatMode=="CSS1Compat")) {
        var topMargin = parseInt(CSS.get(body,'marginTop'),10) || 0;
        var bottomMargin = parseInt(CSS.get(body,'marginBottom'), 10) || 0;
      return Math.max(body.offsetHeight + topMargin + bottomMargin, document.documentElement.clientHeight, document.documentElement.scrollHeight, screen.zero(self.innerHeight));
    }
    return Math.max(body.scrollHeight, body.clientHeight, screen.zero(self.innerHeight));
  };

  // Get the width of the viewport (viewable area) in the browser window
  // --------------------------------------------------------------------
  screen.getViewportWidth = function() {
    if (document.documentElement && (!document.compatMode || document.compatMode=="CSS1Compat")) {
      return document.documentElement.clientWidth;
    }
    else if (document.compatMode && document.body) {
      return document.body.clientWidth;
    }
    return screen.zero(self.innerWidth);
  };

  // Get the height of the viewport (viewable area) in the browser window
  // --------------------------------------------------------------------
  screen.getViewportHeight = function() {
    if (!window.opera && document.documentElement && (!document.compatMode || document.compatMode=="CSS1Compat")) {
      return document.documentElement.clientHeight;
    }
    else if (document.compatMode && !window.opera && document.body) {
      return document.body.clientHeight;
    }
    return screen.zero(self.innerHeight);
  };

  return screen;
})();

/*Some customized validation*/
var invalidChars = "\'\"<>&?";
function TestInvalidChars(val) {
	for (var i = 0; i < val.length; i++)
		if (invalidChars.indexOf(val.charAt(i)) != -1) return false;
	return true;
}
function stripPhone(val) {
	var pattern = /[^0-9]/g;
	val = val.replace(pattern, "");
	return val;
}
function customTestPhone(val) {
	var expression = /^\d{10}$/;
	return expression.test(val);
}
function validateRequired(form, input, title) {
	var myField = doc.getElementById(input)
	var valid = TestRequired(myField.value);
	displayValidationOutPut(input, title, valid);
	return valid
}
function validateChars(form, input, title) {
	var myField = doc.getElementById(input)
	var valid = TestInvalidChars(myField.value);
	displayValidationOutPut(input, title, valid, 'An invalid character(' + invalidChars + ') in {title}');
	return valid
}
function displayValidationOutPut(input, title, valid, errorTextPattern) {
	errorTextPattern = errorTextPattern ||  validationDefaultMessage; // Set the default error text pattern
	inlineValidationDisplay(input, title, valid, errorTextPattern);
	submitValidationDisplay(input, title, valid, errorTextPattern);
}
/* Address Book Checks*/
function validateVca_Name(form) {
	if( !jQuery('input#vca_name')[0] ) return true;
	var valid = validateRequired(form, 'vca_name', 'Nickname');
	if (valid) valid = validateChars(form, 'vca_name', 'Nickname');
	return valid;
}
/*Registration checks*/
function validateUsName(form) {
	if( !jQuery('input#usname')[0] ) return true;
	var valid = validateRequired(form, 'usname', 'User Name');
	if (valid) valid = validateChars(form, 'usname', 'User Name');
	return valid;
}
function validateUsrName(form) {
	if( !jQuery('input#usrname')[0] ) return true;
	var valid = validateRequired(form, 'usrname', 'User Name');
	if (valid) valid = validateChars(form, 'usrname', 'User Name');
	return valid;
}
function validatePwd(form) {
	if( !jQuery('input#pwd')[0] ) return true;
	var valid = validateRequired(form, 'pwd', 'Password');
	if (valid) valid = TestLength(form.pwd.value, 4);
	displayValidationOutPut('pwd', 'Password', valid);
	return valid;
}
function validatePwd_Conf(form) {
	if( !jQuery('input#pwd_conf')[0] ) return true;
	var valid = validateRequired(form, 'pwd_conf', 'Password Confirmation');
	var valid = TestRequired(form.pwd_conf.value);
	if (valid) {
		valid = TestCompareValues(form.pwd.value, form.pwd_conf.value);
		displayValidationOutPut('pwd_conf', 'Password Confirmation', valid, 'Passwords does not match.');
	}
	return valid;
}
function validateConfirmPwd(form) {
	if( !jQuery('input#confirmpwd')[0] ) return true;
	var valid = TestRequired(form.confirmpwd.value);
	var valid = validateRequired(form, 'pwd_conf', 'Password Confirmation');
	if (valid){
		valid = TestCompareValues(form.pwd.value, form.confirmpwd.value);
		displayValidationOutPut('confirmpwd', 'Password Confirmation', valid, 'Passwords does not match');
	}
	return valid;
}
/*Shipping Address Checks*/
function validateFName(form) {
	if( !jQuery('input#fname')[0] ) return true;
	var valid = validateRequired(form, 'fname', 'First Name');
	if (valid) valid = validateChars(form, 'fname', 'First Name');
	return valid;
}
function validateLName(form) {
	if( !jQuery('input#lname')[0] ) return true;
	var valid = validateRequired(form, 'lname', 'Last Name');
	if (valid) valid = validateChars(form, 'lname', 'Last Name');
	return valid;
}
function validateAddr1(form) {
	if( !jQuery('input#addr1')[0] ) return true;
	var valid = validateRequired(form, 'addr1', 'Street Address 1');
	if (valid) valid = validateChars(form, 'addr1', 'Street Address 1');
	return valid;
}
function validateAddr2(form) {
	if( !jQuery('input#addr2')[0] ) return true;
	valid = validateChars(form, 'addr2', 'Street Address 2');
	return valid;
}
function validateCity(form) {
	if( !jQuery('input#city')[0] ) return true;
	var valid = validateRequired(form, 'city', 'City');
	if (valid) valid = validateChars(form, 'city', 'City');
	return valid;
}
function validateCompany_Name(form) {
	if( !jQuery('input#company_name')[0] ) return true;
	valid = validateChars(form, 'company_name', 'Company Name');
	return valid;
}
function validateCntry(form) {
	if( !jQuery('input#cntry')[0] ) return true;
	var valid = validateRequired(form, 'cntry', 'Country');
	return valid;
}
function validateState(form) {
	if( !jQuery('input#state')[0] && !jQuery('select#state')[0]) return true;
	var valid = validateRequired(form, 'state', 'State');
	return valid;
}
function validateZipC(form) {
	if( !jQuery('input#zipc')[0] ) return true;
	var valid = validateRequired(form, 'zipc', 'Zip Code');
	if (valid) {
		valid = TestCode(form.zipc.value, form.cntry.value);
		displayValidationOutPut('zipc', 'Zip Code', valid, 'Please enter a valid {title}');
	}
	return valid;
}
function validateEmail(form) {
	if( !jQuery('input#email')[0] ) return true;
	var valid = validateRequired(form, 'email', 'Email');
	if (valid) {
		valid = TestEmail(form.email.value);
		displayValidationOutPut('email', 'Email', valid, 'Please enter a valid {title}');
	}
	return valid;
}
function validatePhone(form) {
	if( !jQuery('input#phone')[0] ) return true;
	var valid = validateRequired(form, 'phone', 'Phone Number');
	form.phone.value = stripPhone(form.phone.value);
	if (valid) {
		valid = customTestPhone(form.phone.value);
		displayValidationOutPut('phone', 'Phone Number', valid, 'Please enter a valid {title}');
	}
	return valid;
}
function validateEmail_Conf(form) {
	if( !jQuery('input#email_conf')[0] ) return true;
	var valid = validateRequired(form, 'email_conf', 'Email Confirmation');
	if (valid) {
		valid = TestCompareValues(form.email.value, form.email_conf.value);
		displayValidationOutPut('email_conf', 'Password Confirmation', valid, 'Emails do not match');
	}
	return valid;
}
/*Billing Address checks*/
function BAvalidateFName(form) {
	if( !jQuery('input#ba_fname')[0] ) return true;
	var valid = validateRequired(form, 'ba_fname', 'First Name');
	if (valid) valid = validateChars(form, 'ba_fname', 'First Name');
	return valid;
}
function BAvalidateLName(form) {
	if( !jQuery('input#ba_lname')[0] ) return true;
	var valid = validateRequired(form, 'ba_lname', 'Last Name');
	if (valid) valid = validateChars(form, 'ba_lname', 'Last Name');
	return valid;
}
function BAvalidateAddr1(form) {
	if( !jQuery('input#ba_addr1')[0] ) return true;
	var valid = validateRequired(form, 'ba_addr1', 'Street Address 1');
	if (valid) valid = validateChars(form, 'ba_addr1', 'Street Address 1');
	return valid;
}
function BAvalidateAddr2(form) {
	if( !jQuery('input#ba_addr2')[0] ) return true;
	valid = validateChars(form, 'ba_addr2', 'Street Address 2');
	return valid;
}
function BAvalidateCity(form) {
	if( !jQuery('input#ba_city')[0] ) return true;
	var valid = validateRequired(form, 'ba_city', 'City');
	if (valid) valid = validateChars(form, 'ba_city', 'City');
	return valid;
}
function BAvalidateCompany_Name(form) {
	if( !jQuery('input#ba_company_name')[0] ) return true;
	valid = validateChars(form, 'ba_company_name', 'Company Name');
	return valid;
}
function BAvalidateCntry(form) {
	if( !jQuery('input#ba_cntry')[0] ) return true;
	var valid = validateRequired(form, 'ba_cntry', 'Country');
	return valid;
}
function BAvalidateState(form) {
	if( !jQuery('input#ba_state')[0] && !jQuery('select#ba_state')[0]) return true;
	var valid = validateRequired(form, 'ba_state', 'State');
	return valid;
}
function BAvalidateZipC(form) {
	if( !jQuery('input#ba_zipc')[0] ) return true;
	var valid = validateRequired(form, 'ba_zipc', 'Zip Code');
	if (valid) {
		valid = TestCode(form.ba_zipc.value, form.ba_cntry.value);
		displayValidationOutPut('ba_zipc', 'Zip Code', valid, 'Please enter a valid {title}');
	}
	return valid;
}
function BAvalidateEmail(form) {
	if( !jQuery('input#ba_email')[0] ) return true;
	var valid = validateRequired(form, 'ba_email', 'Email');
	if (valid) {
		valid = TestEmail(form.ba_email.value);
		displayValidationOutPut('ba_email', 'Email', valid, 'Please enter a valid {title}');
	}
	return valid;
}
function BAvalidatePhone(form) {
	if( !jQuery('input#ba_phone')[0] ) return true;
	var valid = validateRequired(form, 'ba_phone', 'Phone Number');
	form.ba_phone.value = stripPhone(form.ba_phone.value);
	if (valid) {
		valid = customTestPhone(form.ba_phone.value);
		displayValidationOutPut('ba_phone', 'Phone Number', valid, 'Please enter a valid {title}');
	}
	return valid;
}
/*Billing Address checks*/
function BillingvalidateFName(form) {
	if( !jQuery('input#billing_fname')[0] ) return true;
	var valid = validateRequired(form, 'billing_fname', 'First Name');
	if (valid) valid = validateChars(form, 'billing_fname', 'First Name');
	return valid;
}
function BillingvalidateLName(form) {
	if( !jQuery('input#billing_lname')[0] ) return true;
	var valid = validateRequired(form, 'billing_lname', 'Last Name');
	if (valid) valid = validateChars(form, 'billing_lname', 'Last Name');
	return valid;
}
function BillingvalidateAddr1(form) {
	if( !jQuery('input#billing_addr1')[0] ) return true;
	var valid = validateRequired(form, 'billing_addr1', 'Street Address 1');
	if (valid) valid = validateChars(form, 'billing_addr1', 'Street Address 1');
	return valid;
}
function BillingvalidateAddr2(form) {
	if( !jQuery('input#billing_addr2')[0] ) return true;
	valid = validateChars(form, 'billing_addr2', 'Street Address 2');
	return valid;
}
function BillingvalidateCity(form) {
	if( !jQuery('input#billing_city')[0] ) return true;
	var valid = validateRequired(form, 'billing_city', 'City');
	if (valid) valid = validateChars(form, 'billing_city', 'City');
	return valid;
}
function BillingvalidateCompany_Name(form) {
	if( !jQuery('input#billing_company_name')[0] ) return true;
	valid = validateChars(form, 'billing_company_name', 'Company Name');
	return valid;
}
function BillingvalidateCntry(form) {
	if( !jQuery('input#billing_cntry')[0] ) return true;
	var valid = validateRequired(form, 'billing_cntry', 'Country');
	return valid;
}
function BillingvalidateState(form) {
	if( !jQuery('input#billing_state')[0] && !jQuery('select#billing_state')[0]) return true;
	var valid = validateRequired(form, 'billing_state', 'State');
	return valid;
}
function BillingvalidateZipC(form) {
	if( !jQuery('input#billing_zipc')[0] ) return true;
	var valid = validateRequired(form, 'billing_zipc', 'Zip Code');
	if (valid) {
		valid = TestCode(form.billing_zipc.value, form.billing_cntry.value);
		displayValidationOutPut('billing_zipc', 'Zip Code', valid, 'Please enter a valid {title}');
	}
	return valid;
}
function BillingvalidateEmail(form) {
	if( !jQuery('input#billing_email')[0] ) return true;
	var valid = validateRequired(form, 'billing_email', 'Email');
	if (valid) {
		valid = TestEmail(form.billing_email.value);
		displayValidationOutPut('billing_email', 'Email', valid, 'Please enter a valid {title}');
	}
	return valid;
}
function BillingvalidatePhone(form) {
	if( !jQuery('input#billing_phone')[0] ) return true;
	var valid = validateRequired(form, 'billing_phone', 'Phone Number');
	form.billing_phone.value = stripPhone(form.billing_phone.value);
	if (valid) {
		valid = customTestPhone(form.billing_phone.value);
		displayValidationOutPut('billing_phone', 'Phone Number', valid, 'Please enter a valid {title}');
	}
	return valid;
}
function validateForms(form) {
	// example of how to turn inline validation off and use summary note summary requires a div with id errorMessage this is the begining
	//var oldvalidationInline = validationInline;
	//validationInline = false;
	validateUsName(form);
	validateUsrName(form);
	validatePwd(form);
	validatePwd_Conf(form);
	validateVca_Name(form);
	validateFName(form);
	validateLName(form);
	validateAddr1(form);
	validateAddr2(form);
	validateCompany_Name(form);
	validateCity(form);
	//validateCntry(form);
	validateState(form);
	validateZipC(form);
	validatePhone(form);
	validateEmail(form);
	validateEmail_Conf(form);
	BAvalidateFName(form);
	BAvalidateLName(form);
	BAvalidateAddr1(form);
	BAvalidateAddr2(form);
	BAvalidateCity(form);
	BAvalidateCompany_Name(form);
	//BAvalidateCntry(form);
	BAvalidateState(form);
	BAvalidateZipC(form);
	BAvalidateEmail(form);
	BAvalidatePhone(form);
	BillingvalidateFName(form);
	BillingvalidateLName(form);
	BillingvalidateAddr1(form);
	BillingvalidateAddr2(form);
	BillingvalidateCity(form);
	BillingvalidateCompany_Name(form);
	//BillingvalidateCntry(form);
	BillingvalidateState(form);
	BillingvalidateZipC(form);
	BillingvalidateEmail(form);
	BillingvalidatePhone(form);
	return writeErrorMessage();
	// example of how to turn inline validation off and use summary note summary requires a div with id errorMessage this is the finisher
	//validationInline = oldvalidationInline;

}
// BAR functions moved from pages
// TKO: 10/11/2005
// This function should be used on all the pages except for the home page.
function buyItemPlusOne(form, siId, qty) {
	//validate quantity
	var num = new Number(parseInt(qty));
	if(num.toString() == 'NaN') {
		alert(qty + ' is not a valid quantity.  Please double-check the quantity to add to your shopping cart.');
		return;
	}//if
	// we need to handle multiple items
	var si_list = siId;
	var qty_list = qty;
	var perfectFitVar = form.fitPlanSiId;
	si_list += "," + perfectFitVar.value;
	qty_list += ",1";
	form.action = "/edealinv/servlet/AddStoreOrderItem";
	form.nurl.value = "control/AddOrder.vm";
	form.eurl.value = "control/StoreItem.vm";
	form.siId.value = si_list;
	form.siQty.value = qty_list;
	form.method = "post";
	form.submit();
}
// helper function used to validate whether or not a size was selected
function sizeSelectorValidation() {
 if (document.getElementById("sizeSelector") && document.getElementById("sizeSelector").selectedIndex == 0 ) {
		alert("Please select a size");
		return false;
	} else  return true;
}
function LatestProductAdded(siID) {
	var current_date = new Date;
	var cookie_year = current_date.getFullYear ( ) + 1;
	var cookie_month = current_date.getMonth ( );
	var cookie_day = current_date.getDate ( );
	var expires = new Date ( cookie_year, cookie_month, cookie_day );
	document.cookie='LatestProductAdded=' + siID + '; expires=' + expires.toGMTString() + '; path=/;';
	return;
}
function removeOrderItem(theForm, oriId, siId) 	{
	theForm.action = "/edealinv/servlet/DeleteStoreOrderItem";
	theForm.nurl.value = "control/AddOrder.vm";
	theForm.ori_id.value = oriId;
	theForm.siId.value = siId;
	theForm.method = "post";
	theForm.submit();
}
function removeStorePurchase(theForm, stpId) {
	// note that for standard checkout, on store purchases can be removed
	theForm.action = "/edealinv/servlet/DeleteStoreOrderItem";
	theForm.nurl.value = "control/AddOrder.vm";
	theForm.stpId.value = stpId;
	theForm.method = "post";
	theForm.submit();
}
function updateShopCart(theForm) {
	if(theForm.APQuery) {
		var apList = theForm.APQuery.value;
		var apArray = apList.split(",");
		if(apArray.length > 0 && apList != "") {
			for(var i=0; i<apArray.length; i++) {
				var qtyName = "theForm.qnty_" + apArray[i];
				var qtyObj = eval(qtyName);
				var qtyVal = qtyObj.value;
				if(qtyVal > 2) {
					alert("Limit is 2 radios per subscriber for this promotion");
					qtyObj.value = 2;
				}
			}
		}
	}
	theForm.action = "/edealinv/servlet/UpdateShoppingCart";
	theForm.nurl.value = "control/AddOrder.vm";
	theForm.method = "post";
	theForm.submit();
}
// wrapper function used to submit the form from button press
function goSubmit(theForm) {
	if(theForm.APQuery) {
		var apList = theForm.APQuery.value;
		var apArray = apList.split(",");
		if(apArray.length > 0 && apList != "") {
			for(var i=0; i<apArray.length; i++) {
				var qtyName = "theForm.qnty_" + apArray[i];
				var qtyObj = eval(qtyName);
				var qtyVal = qtyObj.value;
				if(qtyVal > 2) {
					alert("Limit is 2 radios per subscriber for this promotion");
					qtyObj.value = 2;
				}
			}
		}
	}
	theForm.action = "/edealinv/servlet/CheckoutItems";
	theForm.method = "post";
	theForm.submit();
}

