/*
collapsible lists
written by Kae Verens - kverens@contactjuggling.org
you are free to use this. please retain these comments, though.
if there are any questions/suggestions for the code, please email me.
*/
//
//
//
if(window.attachEvent)window.attachEvent('onload',cm);
else if(window.addEventListener)window.addEventListener('load',cm,false);

function cm(){
	return;
 cmId=0;
 if(!document.getElementsByTagName)return; // reject non-compliant browsers
 a=document.getElementsByTagName('UL');
 for(i=0;a[i];i++){
  if(a[i].getElementsByTagName('UL')){
   // a[i] is an object which has a collapsible list in it
   b=a[i].childNodes;
   for(j=0;b[j];j++){
    if(b[j].nodeName=='LI'){
     d=b[j].getElementsByTagName('ul');
     if(d.length){
      c=document.createElement('a');
      c.setAttribute('href','javascript:cmSwitch("cm'+(cmId)+'")');
      c.setAttribute('id','cm'+(cmId)+'A');
      c.style.display='inline';
	  c.style.color='#000000';
	  c.style.textDecoration='none';
      c.innerHTML='[+]';
      b[j].insertBefore(c,d[0]);
      d[0].setAttribute('id','cm'+(cmId++));
      d[0].style.display='none';
     }
    }
   }
  }
 }
}

function cmSwitch(id){
 a=document.getElementById(id);
 a.style.display=(a.style.display=='block')?'none':'block';
 a=document.getElementById(id+'A');
 a.innerHTML=(a.innerHTML=='[+]')?'[-]':'[+]';
}

// JavaScript Document
var w1;

function makeWin(imsrc, ww, wh) {
ww=ww+25; wh=wh+50;
w1=window.open('','w1','width='+ww+',height='+wh+',status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes');
w1.document.open();
w1.document.write("<html><head><title>Image Zoom</title><META HTTP-EQUIV='Pragma' CONTENT='no-cache'><META HTTP-EQUIV='Expires' CONTENT='-1'></head><");
w1.document.write("script>var isNav4, isIE4, hi, wi;if (parseInt(navigator.appVersion.charAt(0)) >= 4) {  isNav4 = (navigator.appName == 'Netscape') ? 1 : 0;  isIE4 = (navigator.appName.indexOf('Microsoft') != -1) ? 1 : 0;}function fitWindowSize(im) {if (isNav4) {  wi = document.images['theimg'].width + 60;  hi = document.images['theimg'].height + 110;  if(hi > 600) hi = 600;  if(wi > 800) wi = 800;  window.innerWidth = wi;  window.innerHeight = hi;}if (isIE4) {  getSizes();  if(hi > 600) hi = 600;  if(wi > 800) wi = 800;  window.resizeTo(wi, hi);  }  }  function getSizes() {  wi = document.images['theimg'].width + 60;  hi = document.images['theimg'].height + 100;}</");
w1.document.write("script><body bgcolor='#FFFFFF' text='#000000' leftmargin=2 topmargin=10><p align=center>");
w1.document.write("<img name=theimg src=" + imsrc + " onload='javascript:fitWindowSize()'><br>");
w1.document.write("<a style='padding:10px;' href=\"javascript:window.close();\"><font size=1 face=tahoma color=#000000>close window<\/font><\/a><\/body><\/html>");
w1.document.close();
w1.focus();
}

function openForm(url){
	var newwindow = "http://www.solidcactus.com/tellafriend/buyingbarstools-tell-friend.asp?url=" + escape(window.location);
	var window_properties = "top=0,left=0,resizable=yes,scrollbars=yes,width=650,height=700,status=yes";
	var PicWindow = window.open(newwindow,"tellfriend",window_properties);
}

function openTellFriendWin(url){
	var window_properties = "top=0,left=0,resizable=yes,scrollbars=yes,width=520,height=700,status=yes";
	var PicWindow = window.open(url,"tellfriend",window_properties);
}

function openSwatchWin(url){
	var window_properties = "top=0,left=0,resizable=no,scrollbars=no,width=535,height=740,status=yes";
	var PicWindow = window.open(url,"tellfriend",window_properties);
}

function openSofaWin(url){
	var window_properties = "top=0,left=0,resizable=no,scrollbars=no,width=905,height=620,status=yes";
	var PicWindow = window.open(url,"tellfriend",window_properties);
}

function openDamageWin(url){
	var window_properties = "top=0,left=0,resizable=yes,scrollbars=yes,width=520,height=600,status=yes";
	var PicWindow = window.open(url,"tellfriend",window_properties);
}

function openAskQuestion(pdtname){
	var newwindow = "ask-question.html?name=" + pdtname;
	var window_properties = "top=0,left=0,scrollbars=yes,width=525,height=700";
	var PicWindow = window.open(newwindow,"tellfriend",window_properties);	
}
function openAskQuestionWin(page_link, params){
	var newwindow = page_link + params;
	var window_properties = "top=0,left=0,resizable=yes,scrollbars=yes,width=460,height=504,status=yes";
	var PicWindow = window.open(newwindow,"tellfriend",window_properties);	
}

function openConditionsWin(url){
	var window_properties = "top=0,left=0,resizable=no,scrollbars=yes,width=630,height=550,status=yes";
	var PicWindow = window.open(url,"tellfriend",window_properties);	
}
// this function is need to work around 
// a bug in IE related to element attributes
function hasClass(obj) {
 var result = false;
 if (obj.getAttributeNode("class") != null) {
	 result = obj.getAttributeNode("class").value;
 }
 return result;
}
function stripeAddToCart() {
	stripe('addToCart', '#FFF', '#EAF4F9');
}
function stripe(id) {

// the flag we'll use to keep track of 
// whether the current row is odd or even
var even = false;

// if arguments are provided to specify the colours
// of the even & odd rows, then use the them;
// otherwise use the following defaults:
var evenColor = arguments[1] ? arguments[1] : "#fff";
var oddColor = arguments[2] ? arguments[2] : "#eee";

// obtain a reference to the desired table
// if no such table exists, abort
var table = document.getElementById(id);
if (! table) { return; }

// by definition, tables can have more than one tbody
// element, so we'll have to get the list of child
// &lt;tbody&gt;s 
var tbodies = table.getElementsByTagName("tbody");

// and iterate through them...
for (var h = 0; h < tbodies.length; h++) {

 // find all the &lt;tr&gt; elements... 
  var trs = tbodies[h].getElementsByTagName("tr");
  
  // ... and iterate through them
  for (var i = 0; i < trs.length; i++) {

	// avoid rows that have a class attribute
	// or backgroundColor style
	if (!hasClass(trs[i]) && ! trs[i].style.backgroundColor) {

	 // get all the cells in this row...
	  var tds = trs[i].getElementsByTagName("td");
	
	  // and iterate through them...
	  for (var j = 0; j < tds.length; j++) {
	
		var mytd = tds[j];

		// avoid cells that have a class attribute
		// or backgroundColor style
		if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
	
		  mytd.style.backgroundColor = even ? evenColor : oddColor;
		  
		}
	  }
	}
	// flip from odd to even, or vice-versa
	even =  ! even;
  }
}
}


function openSizeChart(html) {
	sizechart=window.open('','sizechart','width=300,height=400,status=no,toolbar=no,menubar=no,location=no,resize=yes'); 
	//sizechart.document.write('<style>');
	//sizechart.document.write('* { font:bold 1em/130% Verdana,Arial,sans-serif; }');
	//sizechart.document.write('.Q {background: #999; color: #FFF;}');
	//sizechart.document.write('.A {background: #FCF3CE;}');
	//sizechart.document.write('</style>');
	sizechart.document.write('<center><a href="javascript:;" onclick="window.close()"><font face="verdana,arial" size=1 color=000000>close window</font></a></center><BR>');  
	sizechart.document.write('<');
	sizechart.document.write('SCRIPT language="javascript">function makeWindowHeight() {var col=document.all.tags("table");var e;if (col!=null) {e=col[0];} makeWid = e.rows.length*25+30; window.resizeTo(300,e.rows.length*25+142);}<');
	sizechart.document.write('/SCRIPT>');
	sizechart.document.write('<TABLE ALIGN=left BORDER=0 CELLSPACING=1 CELLPADDING=3 WIDTH=100% bgcolor=#b6b7cb> ');
	sizechart.document.write('<TR><TD colspan=2 bgcolor=white><center>Mattress Size Dimensions</center></TD></TR> ');
	sizechart.document.write('<TR><TD bgcolor=#f4f7fd>Twin</TD><TD>38" x 75"</TD></TR> ');
	sizechart.document.write('<TR><TD bgcolor=#f4f7fd>Full</TD><TD>53" x 75"</TD></TR> ');
	sizechart.document.write('<TR><TD bgcolor=#f4f7fd>Queen</TD><TD>60" x 80"</TD></TR> ');
	sizechart.document.write('<TR><TD bgcolor=#f4f7fd>King</TD><TD>76" x 80"</TD></TR> ');
	sizechart.document.write('<TR><TD bgcolor=#f4f7fd>California King</TD><TD>72" x 84"</TD></TR> </TABLE>');
	//sizechart.document.write('<table id="productInfo" width="100%" cellspacing="2">'); 
	//sizechart.document.write(html);
	//sizechart.document.write('</TABLE>'); 
	sizechart.document.write('<');
	sizechart.document.write('SCRIPT language="javascript">makeWindowHeight()<');
	sizechart.document.write('/SCRIPT>'); 
	sizechart.document.close();
	sizechart.focus();
}
var form_is_submitted = false;
// prevents double submits.
function ok_to_summit_form() {
  if (form_is_submitted) {
	  return false;
  }
  form_is_submitted = true;
  return true;
}



function searchShowHideSubcats ( parent_cat_id ) {

    var main_cat_count_id = parent_cat_id + "count";
    var subcat_document_id = parent_cat_id + "subcats";
    var subcat_expander_id = parent_cat_id + "expander";
    
    var main_cat_count_element = document.getElementById(main_cat_count_id);
    var subcat_element = document.getElementById(subcat_document_id);
    var expander_element = document.getElementById(subcat_expander_id);
    if(subcat_element.style.display == "none"){
        main_cat_count_element.style.visibility = "hidden";
        expander_element.innerHTML = "&nbsp;-&nbsp;";
        subcat_element.style.display = "block";
    }else{
        main_cat_count_element.style.visibility = "visible";
        expander_element.innerHTML = "+";
        subcat_element.style.display = "none";
        
    }
 
} 

function beginCheckout(cart_form){
    cart_form.init_checkout.value='1';
    cart_form.submit();
    return false;
}


function processSearch(domain, keyword){
       keyword = keyword.replace(/^\s+/, '');
       keyword = keyword.replace(/\s+$/, '');
       keyword = keyword.replace(/\s+/g, "-");
       keyword = keyword.replace(/\//g, '');
       keyword = encodeURIComponent(keyword);
       keyword = keyword.replace(/\'/g, "%27");
       keyword = keyword.replace(/\"/g, "%22");
       document.location = domain + keyword + "-shop-by.html?init_search=1";
}


var product_detail_shown = false;