// for popups
function createPopUp(url, name, optionString) {
	if (!name){
		name = "newwnd";
	}
	if (!optionString){
		optionString = "toolbar=no,location=no,directories=no,scrollbars=yes,resizable=yes,height=500,width=730,screenX=4,screenY=4,top=4,left=4";
	}		
	win = window.open(url, name, optionString);
	win.focus();
}

function RegisterWindowLoadEvent(fnHandler)
{
	var evt = "onload";
	var source = window;
	if (arguments.length > 1) evt = arguments[1];
	if (arguments.length > 2) source = arguments[2];
	if ( typeof window.addEventListener != "undefined" )
	{
		source.addEventListener( evt.replace("on", ""), fnHandler, false );
	}
	else
	{
		if ( typeof source.attachEvent != "undefined" )
		{
			source.attachEvent( evt, fnHandler );
			//alert(evt);
		}
		else
		{
			if ( source.onload != null )
			{
				var oldOnload = source.onload;
				source.onload = function ( e )
						{
							oldOnload( e );
							fnHandler();
						}
			}
			else
			{
				source.onload = fnHandler;
			}
		}
	}
}

function MakeUrl(href, arglist) {
  var result = '';
  var key = 0;
  var name = 0;
  var value = 0;
  var sep = "?";
  var argString = "";
  
  if (!arglist) {
    arglist = new Object();
  }
  
  if (href.indexOf("?") != -1) {
    sep = "&";
  }
  for (key in arglist) {
    name = escape(key.toLowerCase());
    value = escape(arglist[key]);
    argString += sep + name + '=' + value;
    sep = "&";
  }
 
  result = href + argString;
  return result;
}
				 
function footerSubmit() {
  var args = new Object();
  args.e0 = document.footerform.email.value;
  args.v0 = document.footerform.email.value;
  var href = document.footerform.action;
  href = MakeUrl(href, args);
  createPopUp(href, 'joinemail', 'toolbar=no,location=no,directories=no,scrollbars=yes,resizable=yes,height=500,width=330,screenX=4,screenY=4,top=4,left=4');
  return false;
}

function emailSubmit() {
  var args = new Object();
  args.e0 = document.emailsubmitform.email.value;
  var href = document.emailsubmitform.action;
  href = MakeUrl(href, args);
  createPopUp(href, 'joinemail', 'toolbar=no,location=no,directories=no,scrollbars=yes,resizable=yes,height=500,width=330,screenX=4,screenY=4,top=4,left=4');
  return false;
}


function commPrefr()
{
        href = "../cust/optout.cfm" ;
        createPopUp(href, 'commPrefr',',toolbar=no,scrollbars=yes,resizable=yes,height=520,width=422,screenX=100,screenY=100,top=10,left=400');

}

function LinkFromFlash(href, redirect) {
	var confirm_redirect = true;
	// tgilbert: need to work on integrating this bit
	//cmLIVEviewClick(href, "");
	// Add dbcmlv=1 to the URL to debug
	// (Short for DeBug CoreMetrics LiveView)
	if (document.URL.indexOf('dbcmlv=1') != -1) {
		if (redirect) {
			confirm_redirect = confirm("LinkFromFlash, OK to redirect:\nHref: "
										+ href + "\nName: " + name);
		} else {
			alert("LinkFromFlash:\nHref: " + href + "\nName: " + name);
		}
	}
	if (redirect && confirm_redirect) {
		document.location = href;
	}
}

function checkAll(field, checked) {
  var i = 0;
  for (i = 0; i < field.length; i++) {
    field[i].checked = checked;
  }
  return 1;
}

function selectqty (linenum) {
	//var s = seq;
	var l = linenum;
	var needqty=1;
	
	eval ('s=a'+l);
	
	for (i=1; i < s.length; i++) {
		eval ('v=document.pipform.L' + l + 'A' + s[i] + '.value');
		if (v == ''){
			needqty=0;
		}
	}
	var line = eval ('document.pipform.q'+l+'.value');
	if (line.length <= 0 ) {
		if (needqty) {
			eval('document.pipform.q'+l+'.value=1');
		}
	}
}

// for cart
var supported = navigator.userAgent.indexOf("Mozilla") == 0 && navigator.userAgent.substring(8,9) >= 3;
function shiptoPopUp(filename, windowname, height, width) {
	if(supported) {
		popup = window.open(filename,windowname,"resizable=yes,scrollbars=yes,status=no,height="+height+",width="+width+",screenX=4,screenY=4,top=4,left=4");
		popup.focus();
		return false;
	} else {
		return true;
	}
}

//mmjs
function MM_findObj(n, d) { //v4.0
	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 && document.getElementById) x=document.getElementById(n); return x;
}

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_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_reloadPage(init) {  //reloads the window if Nav4 resized
	if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
		document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->

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];}
}

function MM_showHideLayers() { //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
		obj.visibility=v; }
}

function MM_setTextOfTextfield(objName,x,newText) { //v3.0
	var obj = MM_findObj(objName); if (obj) obj.value = newText;
}

var topcat1on = "../../images/nav/txt_upholstery_on.gif";
var topcat2on = "../../images/nav/txt_furniture_on.gif";
var topcat3on = "../../images/nav/txt_bedding_on.gif";
var topcat4on = "../../images/nav/txt_bath_on.gif";
var topcat5on = "../../images/nav/txt_rugsandwindows_on.gif";
var topcat6on = "../../images/nav/txt_lighting_on.gif";
var topcat7on = "../../images/nav/txt_diningandent_on.gif";
var topcat8on = "../../images/nav/txt_accessories_on.gif";
var topcat9on = "../../images/nav/txt_holiday_on.gif";
var topcat10on = "../../images/nav/txt_sale_on.gif";

function WS_initialize() {
	WS_hideall ();
	MM_swapImgRestore();
}


function WS_hideall() {
	MM_showHideLayers('topcatlayer1','','hide');
	MM_showHideLayers('topcatlayer2','','hide');
	MM_showHideLayers('topcatlayer3','','hide');
	MM_showHideLayers('topcatlayer4','','hide');
	MM_showHideLayers('topcatlayer5','','hide');
	MM_showHideLayers('topcatlayer6','','hide');
	MM_showHideLayers('topcatlayer7','','hide');
	MM_showHideLayers('topcatlayer8','','hide');
	MM_showHideLayers('topcatlayer9','','hide');
	MM_showHideLayers('topcatlayer10','','hide');
}

var WS_menu=null;

function WS_doinTopCat(num,switchOn) {
	MM_swapImgRestore();
	MM_swapImage('topcat' + num,'',switchOn,1);
	MM_showHideLayers('topcatlayer' + num,'','show');
	if (WS_menu != null) {window.clearTimeout(WS_menu);}
}



function emailPassword() 
{
	href = "../acct/index.cfm?action=requestpass&action1=times&submit=1&e0=" + 
	window.document.signinform.e0.value;
	window.document.location = href;
}



function WS_dooutTopCat(num) {
	if (WS_menu != null) {window.clearTimeout(WS_menu);}
	WS_menu=window.setTimeout('WS_initialize()',0);
}

var agt  = navigator.userAgent.toLowerCase();
var nav4 = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
         && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
				 && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)
				 && (parseInt(navigator.appVersion) == 4));

function ParentWindow (URL) {
	window.close();
	window.opener.top.location =URL;
}
