
/*Note: Anytime adding a new hardware this paremeter needs to get updated as we loop through all the check box to add the selected hardware*/
var auxUrl = "sharpen=1&fmt=jpg&qlt=90";
var Url = "http://s7d4.scene7.com/ir/render/CalicoCornersRender/";
var strParam;
var menuIndex = 0;
var menuArray = new Array("style","fabric","options","hardware","order");

function chkMenuStatus()
{
/*needs 2 parameters to remember last visited menu*/
var strMenu = "";
var strUrl = "";
strUrl = "/quickship/qssetsession.do";
function showSuccess(response){ 
strMenu = response.responseText; 
/*clean up the spaces*/
strMenu = strMenu.replace(/^\s+|\s+$/g,"");
/*split the 2 parameter, a number and a string like 0~style, the number is the index of visited menu, the string is the current menu.*/
var splitResult = strMenu.split("~"); 
document.qsForm.menuIndex.value = splitResult[0];
strMenu = splitResult[1];
var menuMode = splitResult[2];
menuIndex = parseInt(splitResult[0]);
disableMenutab(menuIndex+1,4);
if (strMenu.indexOf("style") == -1 && strMenu.indexOf("fabric") == -1 && strMenu.indexOf("options") == -1 && strMenu.indexOf("hardware") == -1 && strMenu.indexOf("order") == -1)
    {     /*0 disable from 0 - 4*/
         disableMenutab(1,4);
        strMenu = "style";    
    }   
    else { enableMenutab(strMenu,menuArray[menuIndex+1]); }
  
if (menuMode == "edit") {  populateTabContent("style","edit"); strMenu = "fabric"; document.getElementById("menuMode").value = "edit" ; }
if (menuMode == "editHardware") { strMenu = "hardware"; document.getElementById("menuMode").value = "editHardware" ; }

populateTabContent(strMenu,menuMode);
}
            /*get the menu sessions if there are any.*/
        	var request = new Ajax.Request(strUrl, {
			method: 'get',
			onSuccess: showSuccess			
		});

}
function populateTabContent(contentType,menuMode)
{
/*populate each section of menu, when user click on the menu tab*/
var strHTML =""; var nextId =""; var previousId = ""; var strHtml = ""; var tmpHtml = ""; var strPrevious = ""; var strNext = ""; var oBtnNext = document.getElementById("divBtnNext"); var oMainContent = document.getElementById("divTab_content");  oMainContent.innerHTML = "";	 var oExistContent = document.getElementById("div" + contentType + "_content");
_uacct = "UA-1726960-1";
urchinTracker("/QSD/" + contentType + ".htm");

switch(contentType)
{
case "style":
nextId = "fabric"; previousId = ""; document.getElementById('divProductPrice').innerHTML = ''; document.getElementById('divProductPrice2').innerHTML = ''; document.getElementById('divDrapeDescription').innerHTML = document.getElementById('drapeDescription').value; if (menuIndex < 1) menuIndex = 0; document.getElementById('menuIndex').value = menuIndex; generateStyles(); break;
case "fabric":
nextId = "options"; previousId = "style"; document.getElementById('divProductHeader').innerHTML =""; document.getElementById('divProductPrice').innerHTML = ''; document.getElementById('divProductPrice2').innerHTML = ''; document.getElementById('divDrapeDescription').innerHTML = '<font size=\"3\" color=\"#0033CC\">Select fabric</font>'; if (menuIndex < 1) menuIndex = 1; document.getElementById('menuIndex').value = menuIndex; generateFabrics();  break;
case "options":
nextId = "hardware"; previousId = "fabric"; document.getElementById('divProductHeader').innerHTML =""; document.getElementById('divProductPrice').innerHTML = ''; document.getElementById('divProductPrice2').innerHTML = ''; document.getElementById('divDrapeDescription').innerHTML = '<table width="100%\" border=\"0\"><tr><td width=\"60%\"><font size=\"3\" color=\"#0033CC\">Select size & options</font></td><td align=\"left\"><font color=\"red\"><b>* Required</b></font></td></tr></table>'; if (menuIndex < 2) menuIndex = 2; document.getElementById('menuIndex').value = menuIndex; generateOptions(); break;
case "hardware":
nextId = "order"; previousId = "options"; 
document.getElementById('divProductHeader').innerHTML =""; 
document.getElementById('divDrapeDescription').innerHTML = '<font size=\"3\" color=\"#0033CC\">Select hardware - Optional</font><br/><br/><font color=\"maroon\"><b>Quantity can be entered on the next page.</b></font>';  if (menuIndex < 3) menuIndex = 3; document.getElementById('menuIndex').value = menuIndex; tmpHtml = oExistContent.innerHTML; 
generateHardware(); 
break;
case "order":
nextId = ""; previousId = "options"; generateOrder();  break;
}
enableMenutab(contentType,nextId);
if (menuMode == "edit") { document.getElementById('divstyle_Line').innerHTML= "<img src=\"http://www.calicocorners.com/images/en_US/local/page_specific/singlefillslots/quick_ship/menu/grayline.jpg\" width=\"150\" height=\"16\" border=\"0\" alt=\"style\" />" ;
    document.getElementById('divstylePath').innerHTML = "<img src=\"http://www.calicocorners.com/images/en_US/local/page_specific/singlefillslots/quick_ship/menu/style_off.jpg\" height=\"33\" border=\"0\" alt=\"order\" />" ; }
if (menuMode == "editHardware") { disableMenutab(0,3); }
oMainContent.innerHTML = tmpHtml;
}
function enableMenutab(currentTab,nextId)
{
var strHTML ="";
var strHtml = "";
var tmpHtml = "";
var strPrevious = "";
var strNext = "";
var oBtnNext = document.getElementById("divBtnNext");
var menuType = "";
for (var mi=0; mi<=parseInt(document.getElementById('menuIndex').value);mi++)
{
    menuType = menuArray[mi];
    document.getElementById('div' + menuType + '_Line').innerHTML= "<img src=\"http://www.calicocorners.com/images/en_US/local/page_specific/singlefillslots/quick_ship/menu/blackline.jpg\" width=\"150\" height=\"16\" border=\"0\" alt=\"" + menuType + "\" />" ;
    document.getElementById('div' + menuType + 'Path').innerHTML = "<a href=\"javascript:void(0)\" onclick=\"nextStep('" + menuType + "');\"><img src=\"http://www.calicocorners.com/images/en_US/local/page_specific/singlefillslots/quick_ship/menu/" + menuType + "_on.jpg\" height=\"33\" border=\"0\" alt=\"" + menuType + "\" /></a>" ;
}
document.getElementById('div' + currentTab + '_Line').innerHTML= "<img src=\"http://www.calicocorners.com/images/en_US/local/page_specific/singlefillslots/quick_ship/menu/pointer.jpg\" width=\"150\" height=\"16\" border=\"0\" alt=\"" + menuType + "\" />" ;
if (nextId != "") strNext = "<a href=\"javascript:void(0)\" onClick=\"nextStep('" + nextId + "')\"><img src=\"http://www.calicocorners.com/images/en_US/local/page_specific/singlefillslots/quick_ship/btnNext.jpg\" border=\"0\" /></a>";
strHtml = "<table><tr><td>" + strPrevious + "</td><td>" + strNext + "</td></tr></table>";
oBtnNext.innerHTML = strHtml;
document.getElementById('divBtnNext2').innerHTML = strHtml;
}
function disableMenutab(fromWhich , toWhich)
{
 for (var mi=fromWhich;mi<toWhich;mi++)
 {
    var menuType = menuArray[mi];
    document.getElementById('div' + menuType + 'Path').innerHTML = "<img src=\"http://www.calicocorners.com/images/en_US/local/page_specific/singlefillslots/quick_ship/menu/" + menuType + "_off.jpg\" height=\"33\" border=\"0\" alt=\"" + menuType + "\" />" ;
    document.getElementById('div' + menuType + '_Line').innerHTML= "<img src=\"http://www.calicocorners.com/images/en_US/local/page_specific/singlefillslots/quick_ship/menu/grayline.jpg\" width=\"150\" height=\"16\" border=\"0\" alt=\"" + menuType + "\" />" ;
 }
 chkCart();
}
function generateStyles()
{
var strHTML = "";
var strUrl = '';
document.getElementById('divBtnNext').style.display = 'none';
document.getElementById('divBtnNext2').style.display = 'none';
var divProduct = document.getElementById('divTab_content');
strUrl = '/quickship/qsdraperies.do?menuTab=style' ;
	function fillInnerHTML(response) {			
		divProduct.innerHTML = response.responseText;						
	}	
	var request = new Ajax.Request(strUrl, {
			method: 'get',
			onComplete: fillInnerHTML					
		});
}
function generateFabrics()
{
var strHTML = "";
var strUrl = '';
var divProduct = document.getElementById('divTab_content');
strUrl = '/quickship/qsdraperies.do?menuTab=fabric';
document.getElementById('divBtnNext').style.display = 'none';	
document.getElementById('divBtnNext2').style.display = 'none';
function containerHTML2(response) {	divProduct.innerHTML = response.responseText; }	
var request = new Ajax.Request(strUrl, { method: 'get',onComplete: containerHTML2 });
}
function generateOptions()
{
var strUrl = '';
var strItem = "";
var divProduct = document.getElementById('divTab_content');
document.getElementById('divBtnNext').style.display = 'none';
document.getElementById('divBtnNext2').style.display = 'none';
selectedOptions();
if (document.getElementById("drapeId") != null && document.getElementById("drapeId") != undefined && 
document.getElementById("bandOpt1") != null && document.getElementById("bandOpt2") != null && document.getElementById("bandOpt3") != null &&
document.getElementById("bandOpt4") != null)
{
strUrl = "/quickship/qsdraperies.do?menuTab=options&drapeId=" + document.getElementById("drapeId").value + "&bandable=" + document.getElementById('bandable').value + "&bandType=" + document.getElementById('bandType').value;
strUrl += "&bandOpt1=" + document.getElementById('bandOpt1').value; strUrl += "&bandOpt2=" + document.getElementById('bandOpt2').value;
strUrl += "&bandOpt3=" + document.getElementById('bandOpt3').value; strUrl += "&bandOpt4=" + document.getElementById('bandOpt4').value;
strUrl += "&interlined=" + document.getElementById('strInterlined').value; strUrl += "&interlined_recom=" + document.getElementById('strInterlined_recom').value;
strUrl += "&lined=" + document.getElementById('strLined').value; 
function setColorBoxHTML(response) { divProduct.innerHTML = response.responseText; }	
	function assignInnerHtml() 
	{
		if ((document.getElementById('bandType').value != "0") && (document.getElementById('bandable').value != "0"))
	    { 
	        document.getElementById('divBandingYesNo').style.display = 'block';						
	    }
	    else
	    {
	   
	    }
	}
	
var request = new Ajax.Request(strUrl, { method: 'get',onSuccess: setColorBoxHTML,onComplete: assignInnerHtml });
}
}
function generateHardware()
{
var strItem = "";
setSessionForItem("menuTab=hardware");
var strUrl = '';
strUrl = '/quickship/qsdraperies.do?menuTab=hardware';
var tmp1;
var strTmp ="";
getHardwarePrice("0");
document.getElementById('divBtnNext').style.display = 'block';
document.getElementById('divBtnNext2').style.display = 'block';
	function containerHTML2(response) {	
		var strResult=response.responseText;   	    
  	    strResult = strResult.replace(/^\s+|\s+$/g,"");  	      	   
  	    if (strResult != "")
  	    {  	       
  	        var splitResult = strResult.split("~");   	       
  	        for (var mi=0;mi<splitResult.length;mi++)
  	        {  	   
  	                tmp1 = eval("document.getElementById('" + splitResult[mi] + "')");
  	                tmp1.checked = true;
  	                strTmp = splitResult[mi].replace("RC_","");  	                	                
  	                chkRod_click(strTmp);  	         
  	        } 	  	        
  	    }       
	    }	
var request = new Ajax.Request(strUrl, { method: 'get',onComplete: containerHTML2 });
}
function getProduct(drapeId,drapeVnt,availBanding,drapeName,drapeTips,drapeDescription,bandOpt1,bandOpt2,bandOpt3,bandOpt4,whereFrom)
{	
	var strItem = "";
	document.getElementById('bandOpt1').value = bandOpt1; document.getElementById('bandOpt2').value = bandOpt2; document.getElementById('bandOpt3').value = bandOpt3;     document.getElementById('bandOpt4').value = bandOpt4;    
    document.getElementById('divBtnNext').style.display = 'block'; document.getElementById('divBtnNext2').style.display = 'block'; document.getElementById('drapeName').value = drapeName; 	document.getElementById('imgContainer').src =  Url + drapeVnt + "?" + auxUrl;
    document.getElementById('divProductHeader').innerHTML = "<font size=\"3\" color=\"#0033CC\">Select style</font>";
    document.getElementById('divProductSelected').innerHTML = "<font color=\"black\" size=\"3\">Style shown: " + drapeName + " drapery</font>";
    document.getElementById('divDrapeDescription').innerHTML = drapeDescription ; document.getElementById('drapeDescription').value  = drapeDescription ;  
    document.getElementById('bandable').value = availBanding; document.getElementById('drapeId').value = drapeId; document.qsForm.currentPrice.value = "0";
    strItem += "menuTab=style&menuIndex=" + document.getElementById('menuIndex').value + "&drapeId=" + drapeId + "&drapeName=" + drapeName;
    strItem += "&bandable=" + availBanding + "&bandOpt1=" + bandOpt1 + "&bandOpt2=" + bandOpt2 + "&bandOpt3=" + bandOpt3 + "&bandOpt4=" + bandOpt4;
    setSessionForItem(strItem);   
    if (whereFrom == '0') window.location.reload( true ); 
    
 }


function displayCat(whichCat)
{
var temp; var objTemp = "";
if (whichCat == 'colors'){ objTemp = 'colors_cat'; document.qsForm.pattern_cat.selectedIndex=0; document.qsForm.price_cat.selectedIndex=0;} 
if (whichCat == 'pattern') { objTemp = 'pattern_cat'; document.qsForm.colors_cat.selectedIndex=0; document.qsForm.price_cat.selectedIndex=0;} 
if (whichCat == 'price') { objTemp = 'price_cat'; document.qsForm.colors_cat.selectedIndex=0; document.qsForm.pattern_cat.selectedIndex=0;}

temp = document.getElementById(objTemp);
var w = temp.selectedIndex; var selected_index = temp.options[w].value; selected_txt = temp.options[w].text; document.getElementById('lblCategory').innerHTML = selected_txt;
if (selected_index != '') { showSelectedColors(selected_index); }
}

/**************************************/
function showSelectedColors(colorName) {
var strItem = ""; var strUrl = ''; var bandableProduct = ""; var colorBoxDiv = document.getElementById('colorbox_1');

for (i=0;i<document.getElementById('colors_cat').length;i++)
{
    if (document.getElementById('colors_cat').options[i].value == colorName)
        {
            document.getElementById('colors_cat').selectedIndex = i; document.getElementById('lblCategory').innerHTML = document.getElementById('colors_cat').options[i].text;
       
        }

}
for (i=0;i<document.getElementById('pattern_cat').length;i++)
{
    if (document.getElementById('pattern_cat').options[i].value == colorName)
        {
            document.getElementById('pattern_cat').selectedIndex = i; document.getElementById('lblCategory').innerHTML = document.getElementById('pattern_cat').options[i].text;
        
        }

}

for (i=0;i<document.getElementById('price_cat').length;i++)
{
    if (document.getElementById('price_cat').options[i].value == colorName)
        {
            document.getElementById('price_cat').selectedIndex = i; document.getElementById('lblCategory').innerHTML = document.getElementById('price_cat').options[i].text;
        
        }

}
document.getElementById('strCategory').value = colorName;


if ((document.getElementById('bandable') != undefined) && (document.getElementById('bandable') != null)) 	bandableProduct = document.getElementById('bandable').value ;
   
 	colorBoxDiv.innerHTML = 'Please wait.....';
    /*type: is it for Banding or color, category*/
	strUrl = '/quickship/ajaxpage.do?drapeId=' + document.getElementById('drapeId').value + '&type=2&strCategory=' + colorName + '&bandable=' + bandableProduct ; 
   
   	function setColorBoxHTML(response) {			
		colorBoxDiv.innerHTML = response.responseText;				
	}
	
	var request = new Ajax.Request(strUrl, {
			method: 'get',
			onComplete: setColorBoxHTML
		});

	var strMessage = '';  
	var divMessage = document.getElementById('divMessage');
	strMessage = "<table cellpadding=\"5\" width=\"100%\"><tr><td height=\"5\"></td></tr><tr><td>";
	strMessage += "<font size=\"1\" face=\"verdana\"><b>Important: </b>Images help you visualize finished product; pattern placement may vary from actual image shown. Since monitor color varies, we recommend ordering free swatches before you buy.</font></td></tr><tr><td width=\"5\"></td></tr></table>";
	divMessage.innerHTML= strMessage;
	
	strItem = "menuTab=fabric&menuIndex=" + document.getElementById('menuIndex').value + "&strCategory=" + colorName;
	setSessionForItem(strItem);
	
}
			
/**************************************/
function renderMainFabric(smalSwatchSku,strBandType,strStyle,strColor,strGroup,drapeId,renderMaterial,strGrommet,strLined,strInterlined,strInterlined_recom,strSuitable15w3w) 
{ 
    var strItem = "";
/*strBandType = it is 0, 1 or 2, 0 = No banding available, 1s gets certain matching fabrics 2s also geting certain matching fabrics ,,renderMaterial = JDA sku of cut fabric, for Scene7 rendering*/
    document.qsForm.strGrommet.value = strGrommet;  document.qsForm.strInterlined.value = strInterlined; document.qsForm.strInterlined_recom.value = strInterlined_recom; document.qsForm.strLined.value = strLined; document.qsForm.strSuitable15w3w.value = strSuitable15w3w; document.qsForm.strColor.value = strColor; document.qsForm.strGroup.value = strGroup; document.qsForm.strStyle.value = strStyle; document.qsForm.smalSwatchSku.value = smalSwatchSku; 
    document.qsForm.drapeId.value = drapeId; 
    if (document.getElementById('divShoppingcartmessage') != null && document.getElementById('divShoppingcartmessage') != undefined)  
    {
    document.getElementById('divShoppingcartmessage').innerHTML = ""; 
    }   
    document.qsForm.mainMaterial.value = renderMaterial; renderMaterial = renderMaterial + "-tile"; document.getElementById('bandDetail').innerHTML = ""; document.getElementById('bandType').value = strBandType; 
    
    if (document.getElementById('divOrderswatch') != null || document.getElementById('divOrderswatch') != undefined) 
    {
        document.getElementById('divOrderswatch').style.display = 'block'; 
    }    
    waitForImage(buildUrl(drapeId, renderMaterial)); document.getElementById('divBtnNext').style.display = 'block'; document.getElementById('divBtnNext2').style.display = 'block'; strItem = "menuTab=fabric&menuIndex=" + document.getElementById('menuIndex').value + "&mainMaterial=" + document.qsForm.mainMaterial.value + "&strStyle=" + strStyle + "&strGroup=" + strGroup; strItem += "&strColor=" + strColor + "&bandType=" + strBandType + "&strGrommet=" + strGrommet + "&strLined=" + strLined + "&strInterlined=" + strInterlined + "&strInterlined_recom=" + strInterlined_recom; strItem += "&strSuitable15w3w=" + strSuitable15w3w; setSessionForItem(strItem);	document.getElementById('strWidth').value = "0";
   
}

/**************************************/
function orderSwatch()
{
strUrl = '/p2p/detail/ajaxdetail.do?method=add&pid=' + document.qsForm.smalSwatchSku.value ; var request = new Ajax.Request(strUrl, {method: 'get',onComplete: setBoxHTML });		
function setBoxHTML(response) { alert("Your swatch has been added to the shopping cart.\n Remember to 'check out' from your shopping cart to receive your swatches.");	document.getElementById('divShoppingcartmessage').innerHTML = "<font color=\"maroon\">Selected swatch has been added to the shopping cart.</font>"; }
}

function rdoBand_click()
{ var renderMaterial; for (i = 0; i<document.qsForm.c.length; i++) {  document.qsForm.c[i].checked = false; }

if (document.qsForm.b)
{
    if (document.qsForm.b[1].checked == true) 
    { 
    renderMaterial = document.qsForm.mainMaterial.value; 
    renderMaterial = renderMaterial + "-tile"; 
    document.getElementById('imgContainer').src = buildUrl(document.qsForm.drapeId.value, renderMaterial); 
    document.getElementById('bandOption').style.display = 'none'; 
    document.getElementById('bandFabrics').style.display = 'none'; 
    document.getElementById('bandDetail').innerHTML = ''; 
    document.getElementById('divOrdersbandwatch').style.display = 'none'; 
    document.qsForm.bandChoice.value = "none";
    document.qsForm.bandColor.value = "none";
    document.qsForm.bandStyle.value = "none";
    document.qsForm.bandSelection.value ="none"; 
    document.qsForm.bandPrice.value = "0"; 
    document.qsForm.bandMaterial.value = "none";
    if (document.getElementById('strLength').value != "000" && document.getElementById('strWidth').value != "0" && document.getElementById('strGroup').value != "none" ) 
    {
        getPrice();
    }
    var strItem = "menuTab=options&menuIndex=" + document.getElementById('menuIndex').value + "&bandMaterial=none&bandChoice=none&bandStyle=none&bandColor=none";
    setSessionForItem(strItem);     
    }
    else if (document.qsForm.b[0].checked == true) 
        
     { document.getElementById('bandOption').style.display = 'block';  showBands(); }
 }

}
/**************************************/
function rdoBandOpt_click ()
{
document.getElementById('bandFabrics').style.display = 'block';
for (i = 0; i<document.qsForm.c.length; i++)
{
  	if (document.qsForm.c[i].checked)  document.qsForm.bandChoice.value = document.qsForm.c[i].value ;
}
if (document.qsForm.bandMaterial.value != 'none' && document.qsForm.bandMaterial.value != null)
{
  	renderBandFabric(document.qsForm.drapeId.value,document.qsForm.bandStyle.value,document.qsForm.bandColor.value,document.qsForm.bandMaterial.value,document.qsForm.bandSwatch.value);
}
}
/**************************************/
function showBandYesNo(bandChoice) {
if (bandChoice != "" && bandChoice != "none")
{
    if (document.qsForm.b)
    {
        document.qsForm.b[0].checked = true; document.getElementById('bandOption').style.display = 'block'; 
        document.getElementById('bandFabrics').style.display = 'block'; 
        if (bandChoice == "GB") document.qsForm.c[2].checked = true; 
        if (bandChoice == "3BLE") document.qsForm.c[1].checked = true; 
        if (bandChoice == "3BBH") document.qsForm.c[0].checked = true; 
        if (bandChoice == "6BTE") document.qsForm.c[1].checked = true;  
        document.qsForm.bandChoice.value = bandChoice; 
        showBands();
    }
}	
}
/**************************************/
function buildUrl(drapeId, renderMaterial) {
var mainUrl;
mainUrl = Url + drapeId + "?" + auxUrl + "&obj=main&src=" + renderMaterial;
return mainUrl;
}
/**************************************/
function waitForImage(strSrc)
{
pic1 = new Image();
pic1.src = strSrc;
document.getElementById('imageloader').innerHTML = "<img src=\"http://www.calicocorners.com/images/en_US/local/page_specific/singlefillslots/quick_ship/loading.gif\" border=\"0\">";
if (pic1.complete) 
     {
     
     document.getElementById('imgContainer').src = pic1.src;
     document.getElementById('imageloader').innerHTML = "";
     
     }
     pic1.onerror = function()
     {
     
        document.getElementById('imgContainer').src = "http://s7d4.scene7.com/is/image/CalicoCorners/N-A?";
        document.getElementById('imageloader').innerHTML = "";
    } 



pic1.onload = function()  {                      
document.getElementById('imgContainer').src = pic1.src;                 
document.getElementById('imageloader').innerHTML = "";                  
 }
/*************************this line needs be a break*************/
document.qsForm.imagePath.value = pic1.src;

}
/**************************************/
function showBands()

{
	
	var bandBoxDiv = document.getElementById('bandFabrics');

	bandBoxDiv.innerHTML = 'Please wait.....';
	strUrl = '/quickship/ajaxpage.do?drapeId=' + document.getElementById("drapeId").value + '&type=1&band=' + document.getElementById('bandType').value  ; 
	
	function setBandBoxHTML(response) {

		bandBoxDiv.innerHTML = response.responseText;
					
			}
	
	var request = new Ajax.Request(strUrl, {
			method: 'get',
			onComplete: setBandBoxHTML
			});

}


/**************************************/
function renderBandFabric(product,fabric_style,fabric_color,tile,bandSwatch)
{
if (tile != "none" && tile != "no")
{
var strSrc; var bandPrice = "0"; document.qsForm.bandSwatch.value = bandSwatch; 

if (document.getElementById('divOrdersbandwatch') != undefined && document.getElementById('divOrdersbandwatch') != null)
{
 document.getElementById('divOrdersbandwatch').style.display = 'block'; 
 document.getElementById('divBandShoppingcartmessage').innerHTML = "";
}
 
 document.qsForm.bandStyle.value = fabric_style; document.qsForm.bandColor.value = fabric_color; bandChoice = document.qsForm.bandChoice.value; document.qsForm.bandMaterial.value = tile;

tile = tile + '-tile';
var oURl = Url + product + "?" + auxUrl + "&obj=main&src=" + document.qsForm.mainMaterial.value + '-tile'; var lowerStyle = fabric_style.toLowerCase();
var lowerColor = fabric_color.toLowerCase();


switch(bandChoice)
{

case "3BBH":
strSrc = oURl + "&obj=main/right_wing/grand_band/small_band&src=" + tile + "&obj=main/left_wing/grand_band/small_band&src=" + tile + "&obj=main/right_wing/edge/edge2&src=" + tile + "&obj=main/left_wing/edge/edge2&src=" + tile ; document.qsForm.bandSelection.value = "3&quot; Band near bottom hem"; waitForImage(strSrc); document.qsForm.bandPrice.value = document.qsForm.hemband.value;
break;

case "3BLE":
strSrc = oURl + "&obj=main/right_wing/edge/edge1&src=" + tile + "&obj=main/left_wing/edge/edge1&src=" + tile + "&obj=main/right_wing/edge/edge2&src=" + tile + "&obj=main/left_wing/edge/edge2&src=" + tile + "&obj=main/right_wing/edge/edge3&src=" + tile + "&obj=main/left_wing/edge/edge3&src=" + tile ; document.qsForm.bandSelection.value = "3&quot; Band at leading edge"; waitForImage(strSrc); document.qsForm.bandPrice.value = document.qsForm.leadedge.value;
break;

case "6BTE":
strSrc = oURl + "&obj=main/right_wing/top/top_band&src=" + tile + "&obj=main/left_wing/top/top_band&src=" + tile ; document.qsForm.bandSelection.value = "6&quot; Band at top edge"; waitForImage(strSrc); document.qsForm.bandPrice.value = document.qsForm.topedge.value;
break;

case "GB":
strSrc = oURl + "&obj=main/right_wing/grand_band&src=" + tile + "&obj=main/left_wing/grand_band&src=" + tile + "&obj=main/right_wing/edge/edge1&src=" + tile + "&obj=main/left_wing/edge/edge1&src=" + tile + "&obj=main/right_wing/edge/edge2&src=" + tile + "&obj=main/left_wing/edge/edge2&src=" + tile ; document.qsForm.bandSelection.value = "Grand band"; waitForImage(strSrc); document.qsForm.bandPrice.value = document.qsForm.grandband.value;
break;

}
var strItem = "menuTab=options&menuIndex=" + document.getElementById('menuIndex').value + "&bandMaterial=" + document.qsForm.bandMaterial.value + "&bandChoice=" + bandChoice + "&bandStyle=" + fabric_style + "&bandColor=" + fabric_color;
setSessionForItem(strItem);

if (document.getElementById('strLength').value != "000" && document.getElementById('strWidth').value != "0" && document.getElementById('strGroup').value != "none" ) 
{
document.getElementById('divBtnNext').style.display = 'block';
document.getElementById('divBtnNext2').style.display = 'block';
getPrice();
}



}

}
/**************************************/
function orderBandswatch()
{
strUrl = '/p2p/detail/ajaxdetail.do?method=add&pid=' + document.qsForm.bandSwatch.value ;      
   
var request = new Ajax.Request(strUrl, {method: 'get',onComplete: setBoxHTML });		
function setBoxHTML(response) {	

        alert("Your swatch has been added to the shopping cart.\n Remember to 'check out' from your shopping cart to receive your swatches.");		
        document.getElementById('divBandShoppingcartmessage').innerHTML = "<font color=\"maroon\">Selected swatch has been added to the shopping cart.</font>";
				
	}
}
/**************************************/
function rdoLining_click(strSelected)
{
if (document.qsForm.rd_lining != undefined && document.qsForm.rd_lining != null)
{
        document.qsForm.strLining.value = strSelected;
    if (document.qsForm.strLining.value == "Room darkening lining")
    {
        document.qsForm.rd_lining[1].checked = true;
        document.getElementById('divLiningcolor').style.display = 'block';
    }
    
     if (document.qsForm.strLining.value == "Classic lining")
     {
        document.qsForm.rd_lining[2].checked = true;
        document.getElementById('divLiningcolor').style.display = 'block';
     }
    

    if (document.qsForm.strLining.value == "Unlined")
    {
        if (document.qsForm.rd_lining[0])
            document.qsForm.rd_lining[0].checked = true;
        else
            document.qsForm.rd_lining.checked = true;
        document.getElementById('divLiningcolor').style.display = 'none';
       
    }
    if (document.qsForm.strLining.value == "Classic lining plus interlining")
    {
        document.getElementById('divLiningcolor').style.display = 'block';
        document.qsForm.rd_lining[3].checked = true;
     
    }
    

    if (document.qsForm.LC != null || document.qsForm.LC != undefined) 
    {
       
         if (document.qsForm.LC[0].checked) liningColor = document.qsForm.LC[0].value;
         if (document.qsForm.LC[1].checked) liningColor = document.qsForm.LC[1].value;
      
     }


var strItem = "menuTab=options&menuIndex=" + document.getElementById('menuIndex').value + "&strLining=" + document.qsForm.strLining.value + "&strGrommetfinish=" + document.qsForm.strGrommetfinish.value + "&strRodpocketsize=" + document.qsForm.strRodpocketsize.value + "&strLiningcolor=" + document.qsForm.strLiningcolor.value;
setSessionForItem(strItem);
if (document.getElementById('strLength').value != "000" && document.getElementById('strWidth').value != "0" && document.getElementById('strGroup').value != "none" ) 
{
document.getElementById('divBtnNext').style.display = 'block';
document.getElementById('divBtnNext2').style.display = 'block';
getPrice();
}
}
}
/**************************************/
function rdoLiningColor_click(strValue)

{
    if (strValue != "none")
    {
    document.qsForm.strLiningcolor.value = strValue;
    var strItem = "menuTab=options&strLiningcolor=" + document.qsForm.strLiningcolor.value;
    setSessionForItem(strItem);
    }
   

}
/**************************************/
function rdoGrommetfinish_click(strValue)
{
    document.qsForm.strGrommetfinish.value = strValue;
    var strItem = "menuTab=options&strGrommetfinish=" + document.qsForm.strGrommetfinish.value;
    setSessionForItem(strItem);
    

}
/**************************************/
function rdoRodpocketsize_click(strValue)
{
    document.qsForm.strRodpocketsize.value = strValue;
    var strItem = "menuTab=options&strRodpocketsize=" + document.qsForm.strRodpocketsize.value;
    setSessionForItem(strItem);
    

}

/**************************************/
function rdoPanel_click (strSelected,strWidth,strSuitable15w3w,strGroup,liningColor,grommetFinish,strRodpocketsize)
{
      
document.getElementById('strWidth').value = "0";
if (strSelected.indexOf("Pair") == 0) document.qsForm.pnl[0].checked = true; if (strSelected.indexOf("Right Panel") == 0) document.qsForm.pnl[2].checked = true; if (strSelected.indexOf("Left Panel") == 0) document.qsForm.pnl[1].checked = true;

document.qsForm.strSuitable15w3w.value = strSuitable15w3w; if (strGroup != "none") document.qsForm.strGroup.value = strGroup; 
if (grommetFinish != "") document.qsForm.strGrommetfinish.value = grommetFinish;
if (strRodpocketsize != "") document.qsForm.strRodpocketsize.value = strRodpocketsize;

if (document.qsForm.GC != null || document.qsForm.GC != undefined) {
for (i = 0; i<4; i++) 
{   
if (grommetFinish == document.qsForm.GC[i].value) document.qsForm.GC[i].checked = true;
}
}

if (document.qsForm.RODSIZE != null || document.qsForm.RODSIZE != undefined) {
for (i = 0; i<4; i++) 
{   
if (strRodpocketsize == document.qsForm.RODSIZE[i].value) document.qsForm.RODSIZE[i].checked = true;
}
}


for (i = 0; i<document.qsForm.pnl.length; i++) {   if (document.qsForm.pnl[i].checked)  { document.qsForm.strPanel.value = document.qsForm.pnl[i].value ; }
}

if (liningColor != '') 
{ 
    if (liningColor == "none") liningColor = "White";
    document.qsForm.strLiningcolor.value = liningColor; 
    if (document.qsForm.LC != null || document.qsForm.LC != undefined) 
    {
       
         if (liningColor == "White") document.qsForm.LC[0].checked = true;
         if (liningColor == "Ivory") document.qsForm.LC[1].checked = true;
      
     }


 } 
addWidth(document.qsForm.strPanel.value,strWidth);
selectedOptions();
if (document.getElementById('strWidth').value == "0")
{
var strPrice = "<font color=\"green\" size=\"3\" face=\"verdana\">Configured product price: $0.00</font>";
document.getElementById('divProductPrice').innerHTML = strPrice;
document.getElementById('divProductPrice2').innerHTML = strPrice;
document.getElementById('divBtnNext').style.display = 'none';
document.getElementById('divBtnNext2').style.display = 'none';

}

}

/**************************************/
function addWidth(type,strWidth)
{

var strItem = "";
var selectbox;
var w = 0;
var optn ;

if (strWidth == "0")
{
var strPrice = "<font color=\"green\" size=\"3\" face=\"verdana\">Configured product price: $0.00</font>";
document.getElementById('divProductPrice').innerHTML = strPrice;
document.getElementById('divProductPrice2').innerHTML = strPrice;
document.getElementById('divBtnNext').style.display = 'none';
document.getElementById('divBtnNext2').style.display = 'none';

}
if ((type == 'Left Panel') ||  (type == 'Right Panel'))
{

    selectbox = document.getElementById('drpWidth');
    if(selectbox != null) selectbox.length = 0;
    optn = document.createElement("OPTION");
    optn.text = 'Select panel width.';
    optn.value = '0';
    selectbox.options.add(optn);
    optn = document.createElement("OPTION");
    optn.text = '1 width - recommended for windows up to 48" wide';
    optn.value = '1 width';
    selectbox.options.add(optn);
    
    if  (document.qsForm.strSuitable15w3w.value != '0')
    {
        
         optn = document.createElement("OPTION");
         optn.text = '1.5 width - recommended for windows up to 60" wide';
         optn.value = '1.5 width';
         selectbox.options.add(optn);
    }
    optn = document.createElement("OPTION");
    optn.text = '2 width - recommended for windows over 60" wide';
    optn.value = '2 width';
    selectbox.options.add(optn);
    
}


if (type == 'Pair') 
{
    selectbox = document.getElementById('drpWidth');
    if(selectbox != null) selectbox.length = 0;
    optn = document.createElement("OPTION");
    optn.text = 'Select panel width.';
    optn.value = '0';
    selectbox.options.add(optn);
    optn = document.createElement("OPTION");
    optn.text = '1 width per side - recommended for windows up to 48" wide';
    optn.value = '1 width per side';
    selectbox.options.add(optn);
    if  (document.qsForm.strSuitable15w3w.value != '0')
    {
        optn = document.createElement("OPTION");
        optn.text = '1.5 widths per side - recommended for windows up to 60" wide';
        optn.value = '1.5 width per side';
        selectbox.options.add(optn);
    }
    optn = document.createElement("OPTION");
    optn.text = '2 widths per side  - recommended for windows over 60" wide';
    optn.value = '2 width per side';
    selectbox.options.add(optn);

}

for (i=0;i<selectbox.length;i++)
{
      if (selectbox.options[i].value == strWidth && strWidth.indexOf("0") == -1)
        {
            selectbox.selectedIndex = i;
            generateWidth();
            break;
        }
}


}
/**************************************/
function addLength(strSelected,strSelected2)
{

var selectbox;
var selectbox2;
var w = 0;
var optn ;
selectbox = document.getElementById('drpLength');
selectbox2 = document.getElementById('drpHalfLength');
if (strSelected2 == "1/2")
        {
            selectbox2.selectedIndex = 1;
            
        }


var F = 36;
var T = 144;
    for (var i=F; i < T;++i)
    {
        w += 1;
        optn = document.createElement("OPTION");
        optn.text = i;
        optn.value = i;
        selectbox.options.add(optn);
        
        if (selectbox.options[w].value == strSelected)
        {
            selectbox.selectedIndex = w;
            
        }
        
    }    
    
 if (strSelected != "0") generateLength();
    
}

/**************************************/
function getPrice()
{
var strUrl = '';
var price = '';

var strPrice = "<font color=\"green\" size=\"3\" face=\"verdana\">Configured product price: $0.00</font>";
document.getElementById('divProductPrice').innerHTML = strPrice;
document.getElementById('divProductPrice2').innerHTML = strPrice;

strUrl = '/quickship/qsdraperies.do?&menuTab=price&pGroup=' + document.getElementById('strGroup').value + '&wid=' + document.getElementById('strWidth').value + '&len=' + document.getElementById('strLength').value + '&len2=' + document.getElementById('strLength2').value + "&strPanel=" + document.getElementById('strPanel').value ; 
  	function fillBoxHTML(response) {
  	    var strResult=response.responseText;   	  
  	    strResult = strResult.replace(/^\s+|\s+$/g,"");
  	        var splitResult = strResult.split("~");   	    	      	  	  		
 	        document.qsForm.baseprice.value = splitResult[0]; 
 	        document.qsForm.grandband.value = splitResult[1]; 	       
  	        document.qsForm.leadedge.value = splitResult[2]; 
  	        document.qsForm.topedge.value = splitResult[3]; 
  	        document.qsForm.hemband.value = splitResult[4]; 
  	        document.qsForm.cottondelux.value = splitResult[5]; 
  	        document.qsForm.cottondeluxinterlining.value = splitResult[6]; 
  	        document.qsForm.blackout.value = splitResult[7];   	
  	        
  	        if (document.qsForm.bandChoice.value != "none")
  	        {
  	            if (document.qsForm.bandChoice.value == "3BBH") document.qsForm.bandPrice.value  = document.qsForm.hemband.value;
  	            if (document.qsForm.bandChoice.value == "3BLE") document.qsForm.bandPrice.value  = document.qsForm.leadedge.value;
  	            if (document.qsForm.bandChoice.value == "6BTE") document.qsForm.bandPrice.value  = document.qsForm.topedge.value;
  	            if (document.qsForm.bandChoice.value == "GB") document.qsForm.bandPrice.value    = document.qsForm.grandband.value;
  	            
            }        
  	        
  	        
  	        if (document.qsForm.strLining.value == "Room darkening lining") document.qsForm.liningPrice.value = document.qsForm.blackout.value; if (document.qsForm.strLining.value == "Classic lining") document.qsForm.liningPrice.value = document.qsForm.cottondelux.value;
            if (document.qsForm.strLining.value == "Unlined") document.qsForm.liningPrice.value = 0; if (document.qsForm.strLining.value == "Classic lining plus interlining") document.qsForm.liningPrice.value = document.qsForm.cottondeluxinterlining.value;
     	    
 	        calculatePrice(); 	  	  			
	}
    var request = new Ajax.Request(strUrl, {method: 'get',onComplete: fillBoxHTML });
}

/**************************************/
function calculatePrice(){
var price = 0; var bandPrice=0; var liningPrice=0; var hardwarePrice=0; var strItems = "strLength=" + document.getElementById('strLength').value + "&strLength2=" + document.getElementById('strLength2').value; strItems += "&baseprice=" + document.qsForm.baseprice.value + "&strWidth=" + document.getElementById('strWidth').value; strItems += "&bandPrice=" + document.qsForm.bandPrice.value + "&liningPrice=" + document.getElementById('liningPrice').value;    
var strUrl = "/quickship/qsdraperies.do?menuTab=calprice&";
if (document.qsForm.baseprice.value != "0")
{      
    generateRequest(strUrl,strItems);       
}

}
/**************************************/
function generateWidth()
{

var temp;
temp = document.getElementById('drpWidth');
var w = temp.selectedIndex;
var selected_index = temp.options[w].value;
document.getElementById('strWidth').value = selected_index;

if (document.getElementById('strLength').value != "000" && document.getElementById('strWidth').value != "0" && document.getElementById('strGroup').value != "none" ) 
{
    document.getElementById('divBtnNext').style.display = 'block';
    document.getElementById('divBtnNext2').style.display = 'block';
    getPrice();
}

else if (document.getElementById('strWidth').value == "0")
{
     document.getElementById('divBtnNext').style.display = 'none';
     document.getElementById('divBtnNext2').style.display = 'none';
     document.qsForm.baseprice.value = "0";
     document.getElementById('divProductPrice').innerHTML = '<font color="green" size="3" face="verdana">Configured product price: $0</font>';
     document.getElementById('divProductPrice2').innerHTML = '<font color="green" size="3" face="verdana">Configured product price: $0</font>';
 
}


strItem = "menuTab=options&menuIndex=" + document.getElementById('menuIndex').value + "&strWidth=" + document.getElementById('strWidth').value + "&strPanel=" + document.getElementById('strPanel').value + "&strLiningcolor=" + document.qsForm.strLiningcolor.value + "&strGrommetfinish=" + document.getElementById('strGrommetfinish').value + "&strRodpocketsize=" + document.getElementById('strRodpocketsize').value;
setSessionForItem(strItem);

}
/**************************************/
function generateLength()
{

var strItem = "";
var temp;
temp = document.getElementById('drpLength');
var w = temp.selectedIndex;
var w2 = document.getElementById('drpHalfLength').selectedIndex;
var selected_index = temp.options[w].value;
document.getElementById('strLength').value = selected_index;
document.getElementById('strLength2').value= document.getElementById('drpHalfLength').options[w2].value;


if (document.getElementById('strWidth').value != "0" && document.getElementById('strLength').value != "000" && document.getElementById('strGroup').value != "none" ) 
{
    document.getElementById('divBtnNext').style.display = 'block';
    document.getElementById('divBtnNext2').style.display = 'block';
    getPrice();
}
else if (document.getElementById('strLength').value == "000")
{
     document.getElementById('divBtnNext').style.display = 'none';
     document.getElementById('divBtnNext2').style.display = 'none';
     document.qsForm.baseprice.value = "0";
     document.getElementById('divProductPrice').innerHTML = '<font color="green" size="3" face="verdana">Configured product price: $0</font>';
     document.getElementById('divProductPrice2').innerHTML = '<font color="green" size="3" face="verdana">Configured product price: $0</font>';
 
}
strItem = "menuTab=options&menuIndex=" + document.getElementById('menuIndex').value + "&strLength=" + document.getElementById('strLength').value + "&strLength2=" + document.getElementById('strLength2').value;
setSessionForItem(strItem);


}
/**************************************/
function chkRod_click(chkId)
{
var strSelected = ""; var hardwarePrice = 0; var strSize; var tmp1; var tmp2;
tmp1 = eval("document.getElementById('RCSIZE_" + chkId + "')");
for (G=0;G<document.qsForm.elements.length;G++)

{
    el=document.qsForm.elements[G];  
    if((el.type == "checkbox") && (el.name.indexOf("RC_") != -1))
    {
        
        if (el.checked) 
        {
            
            hardwarePrice += parseInt(el.value);            
            strSize = tmp1.value;
            document.qsForm.hardwarePrice.value = hardwarePrice; 
            strSelected += el.name + "~"; 
                                 
        }
          

    }
    
}
var strItem = "menuTab=hardware&hardwareSelection=" + strSelected + "&hardwarePrice=" + document.qsForm.hardwarePrice.value; 
setSessionForItem(strItem); getHardwarePrice(hardwarePrice); addremoveHardwareToCart(chkId,strSize);

}
/**************************************/
function addremoveHardwareToCart(chkId,strSize)
  
  {
  var tmp1;
  var objTmp1;
  var objTmp2;
  var hardwarePrice = 0;
  var hardwareDescription = "";
  var hardwareId = "";
  var strImage = "";
  var strItem = "";
        if (chkId < 3 && chkId >= 0) { objTmp1 = document.getElementById('rodInfo_1'); objTmp2 = document.getElementById('rodImage_1'); }     if (chkId < 6 && chkId >= 3) { objTmp1 = document.getElementById('rodInfo_2'); objTmp2 = document.getElementById('rodImage_2'); }     if (chkId < 9 && chkId >=6) { objTmp1 = document.getElementById('rodInfo_3'); objTmp2 = document.getElementById('rodImage_3'); }      if (chkId < 12 && chkId >= 9) { objTmp1 = document.getElementById('rodInfo_4'); objTmp2 = document.getElementById('rodImage_4'); } if (chkId < 15 && chkId >= 12) { objTmp1 = document.getElementById('rodInfo_5'); objTmp2 = document.getElementById('rodImage_5'); }   if (chkId < 18 && chkId >= 15) { objTmp1 = document.getElementById('rodInfo_6'); objTmp2 = document.getElementById('rodImage_6'); }   if (chkId < 21 && chkId >= 18) { objTmp1 = document.getElementById('rodInfo_7'); objTmp2 = document.getElementById('rodImage_7'); }   if (chkId < 24 && chkId >= 21) { objTmp1 = document.getElementById('rodInfo_8'); objTmp2 = document.getElementById('rodImage_8'); }   if (chkId < 27 && chkId >= 24) { objTmp1 = document.getElementById('rodInfo_9'); objTmp2 = document.getElementById('rodImage_9'); }   if (chkId < 30 && chkId >= 27) { objTmp1 = document.getElementById('rodInfo_10'); objTmp2 = document.getElementById('rodImage_10'); } if (chkId < 33 && chkId >= 30) { objTmp1 = document.getElementById('rodInfo_11'); objTmp2 = document.getElementById('rodImage_11'); } if (chkId < 36 && chkId >= 33) { objTmp1 = document.getElementById('rodInfo_12'); objTmp2 = document.getElementById('rodImage_12'); } if (chkId < 39 && chkId >= 36) { objTmp1 = document.getElementById('rodInfo_13'); objTmp2 = document.getElementById('rodImage_13'); }  if (chkId == 100) { objTmp1 = document.getElementById('rodInfo_100'); objTmp2 = document.getElementById('rodImage_100'); }  
  tmp1 = eval("document.getElementById('RC_" + chkId + "')");
  hardwarePrice = tmp1.value;
  hardwareDescription = objTmp1.value + " - " + strSize;
  hardwareId = "RC_" + chkId; 
  
  if (tmp1.checked)
  {                       
        strImage = "http://www.calicocorners.com/images/en_US/local/page_specific/singlefillslots/quick_ship/hardware/" + objTmp2.value;
        strItem = "menuTab=hardware&hardwareId=" + hardwareId + "&hardwareDescription=" + hardwareDescription + "&hardwarePrice=" + hardwarePrice + "&hardwareImage=" + strImage;
        setSessionForItem(strItem);        
        var strUrl = '/quickship/qscartbeanAction.do?actionType=addHardware&' + strItem;        
  	    function setColorBoxHTML(response) { 
  	   
  	     } 
	    var request = new Ajax.Request(strUrl, {method: 'get',onComplete: setColorBoxHTML});
		
	}
	else if (!(tmp1.checked))
	{
	    
	     removeCart(hardwareId,2);
	}
  
  
  }
/**************************************/  
function getHardwarePrice(strTotal)
{
var strResult;
document.getElementById('divProductPrice').innerHTML = '<font color="green" size="3" face="verdana">Total hardware price: $' + strTotal + '</font>';
document.getElementById('divProductPrice2').innerHTML = '<font color="green" size="3" face="verdana">Total hardware price: $' + strTotal + '</font>';
}      	
  	    	
/**************************************/
function generateOrder()
{
var strUrl = '/quickship/qscartbeanAction.do?actionType=addDrape'; document.getElementById('allContent').style.display = 'none'; document.getElementById('headerDescription').innerHTML = document.getElementById('orderText').innerHTML;
function setColorBoxHTML(response) { showCart(); }	 var request = new Ajax.Request(strUrl, { method: 'get',onComplete: setColorBoxHTML });
document.getElementById('menuIndex').value = 4;
var strItem = "";
strItem = "menuTab=order&menuIndex=4";

}

/**************************************/
function editCart(id,drapeId,strCategory,mainMaterial,drapeName,strPanel,strWidth,strLength1,strLength2,bandChoice,bandMaterial,strLining,strLiningcolor,strGrommetfinish,strRodpocketsize,prodType)
{
var strItem = "";
document.getElementById('drapeName').value = drapeName;
document.qsForm.drapeId.value = drapeId;
document.qsForm.strPanel.value = strPanel;
document.qsForm.mainMaterial.value = mainMaterial;
document.qsForm.strLining.value = strLining;
document.getElementById('bandMaterial').value = bandMaterial;
document.getElementById('bandChoice').value = bandChoice;
document.getElementById('strGrommetfinish').value = strGrommetfinish;
document.qsForm.strRodpocketsize.value = strRodpocketsize;
document.qsForm.strLiningcolor.value = strLiningcolor;
document.qsForm.strLength.value = strLength1;
document.qsForm.strLength2.value = strLength2;
document.qsForm.strWidth.value = strWidth;


strItem = "menuMode=edit&drapeId=" + drapeId + "&strCategory=" + strCategory + "&mainMaterial=" + mainMaterial + "&editConfig=yes&uniqueId=" + id;
strItem += "&mainMaterial=" + mainMaterial ;
strItem += "&drapeName=" + drapeName + "&strPanel=" + strPanel + "&strWidth=" + strWidth + "&strLength=" + strLength1 + "&strLength2=" + strLength2 + "&bandChoice=" + bandChoice + "&bandMaterial=" + bandMaterial;
strItem += "&strLining=" + strLining + "&strLiningcolor=" + strLiningcolor + "&strGrommetfinish=" + strGrommetfinish + "&strRodpocketsize=" + strRodpocketsize ;

setSessionForItem(strItem);
window.location.reload( true );
//location.replace("/category/custom+window+treatments/quick+ship+draperies.do");

}


/**************************************/
function editHardware()
{
var strItem = "";
strItem = "menuTab=hardware&menuMode=editHardware";
setSessionForItem(strItem);
window.location.reload( true );
//location.replace("/category/custom+window+treatments/quick+ship+draperies.do");

}

/**************************************/
function removeCart(id,tag)
{

var strResult = "";
var strUrl = '';
var divTmpOrder = document.getElementById('divorder_content');
strUrl = "/quickship/qscartbeanAction.do?actionType=remove&removeId=" + id;
if (tag == 2) strUrl = "/quickship/qscartbeanAction.do?actionType=removehardware&removeId=" + id;
if (tag == 3) strUrl = "/quickship/qscartbeanAction.do?actionType=removehardware2&removeId=" + id;
 function showSuccess(response){
 
 
 
            strResult = response.responseText;
	        strResult = strResult.replace(/^\s+|\s+$/g,"");
	        if (tag == 1 || tag == 3)
	        {
	            if (strResult == "0") { configureNewProduct(); }
	            else { divTmpOrder.innerHTML = response.responseText; };
	        }
	        

 }
 
	var request = new Ajax.Request(strUrl, {method: 'get',onComplete: showSuccess});

}
/**************************************/
function updateCart(itemId,id)
{
var tmp = eval("document.getElementById('itemct_" + id + "')");
var divTmpOrder = document.getElementById('divorder_content');
var strUrl = '';

if (/^ *[0-9]+ *$/.test(tmp.value))
{ 
strUrl = "/quickship/qscartbeanAction.do?actionType=updateCart&updateId=" + itemId + "&itemct=" + tmp.value;

var request = new Ajax.Request(strUrl, {
			method: 'get',
			onComplete: showSuccess
		});
} else {
alert("Enter a valid quantity"); 
}



 function showSuccess(response){       
         divTmpOrder.innerHTML = response.responseText; document.getElementById('divDiscount').innerHTML = document.getElementById('divDiscountMessage').innerHTML;
 }
 
	
}

/**************************************/
function showCart()
{

var strUrl = '';
var divTmpOrder = document.getElementById('divorder_content');

strUrl = '/quickship/qscartbeanAction.do?actionType=showCart'; 

  	function setColorBoxHTML(response) {	
  	   		 	   		     
	    divTmpOrder.innerHTML = response.responseText;	
	    if (response.responseText == "0") window.location.reload( true );
	    document.getElementById('customerInfo').style.display = 'block';	
	    document.getElementById('divDiscount').innerHTML = document.getElementById('divDiscountMessage').innerHTML;
	    	  
	}
	
	var request = new Ajax.Request(strUrl, {method: 'get', onSuccess: setColorBoxHTML });
}
/**************************************/
function chkCart()
{
var strUrl = '';
strUrl = '/quickship/qssetsession.do?cart=chkCart'; 
var strResult = "";
var tmpNum = 0;

  	function setBoxHTML(response) {	  	   		 	   		     
	    strResult = response.responseText;
	    strResult = strResult.replace(/^\s+|\s+$/g,"");
	   	if (strResult.indexOf("empty")<0)	 
	    { enableOrder(); }  
	}
	
	var request = new Ajax.Request(strUrl, {
			method: 'get',
			onSuccess: setBoxHTML
		});


}
/**************************************/
function enableOrder()
{
document.getElementById('divorder_Line').innerHTML= "<img src=\"http://www.calicocorners.com/images/en_US/local/page_specific/singlefillslots/quick_ship/menu/blackline.jpg\" width=\"150\" height=\"16\" border=\"0\" alt=\"order\" />" ;
document.getElementById('divorderPath').innerHTML = "<a href=\"javascript:void(0)\" onclick=\"nextStep('order');\"><img src=\"http://www.calicocorners.com/images/en_US/local/page_specific/singlefillslots/quick_ship/menu/order_on.jpg\" height=\"33\" border=\"0\" alt=\"order\" /></a>" ;

}
/**************************************/
function configureNewProduct()
{
 
var strItem = "";
strItem = "menuTab=style&moreConfig=yes";
setSessionForItem(strItem);
window.location.reload( true );  
}


function generateRequest(tmpUrl,strNodes)

{ 
var divPrice = document.getElementById('divProductPrice');
var strResult = "";
tmpUrl += strNodes;

    function fillContainerHTML(response) {
	
	    strResult = response.responseText;
	    strResult = strResult.replace(/^\s+|\s+$/g,"");
               		
			}
	function assignResult()
	{	
	    var strItem = "";	
        document.qsForm.currentPrice.value = strResult;	
        divPrice.innerHTML = '<font color="green" size="3" face="verdana">Configured product price: $' + strResult + '</font>';
        document.getElementById('divProductPrice2').innerHTML = '<font color="green" size="3" face="verdana">Configured product price: $' + strResult + '</font>';
        strItem += "menuTab=options&menuIndex=" + document.getElementById('menuIndex').value + "&currentPrice=" + document.qsForm.currentPrice.value;
        setSessionForItem(strItem);
	
	}
	
	var request = new Ajax.Request(tmpUrl, {
			method: 'get',			
			onSuccess: fillContainerHTML,
			onComplete: assignResult
						
			});			
return 
			
}	

/**************************************/
function setSessionForItem(strItem)
{
var strUrl = '';
strUrl = '/quickship/qssetsession.do?' + strItem;

function showSuccess(response){

selectedOptions();

 
 }
 
	var request = new Ajax.Request(strUrl, {
			method: 'get',
			onComplete: showSuccess
		});
}
/**************************************/
function confirmDesigner() { if (document.qsForm.chkDesigner.checked) alert("Your designer discount will be applied when your order is confirmed by Customer Service."); }
/**************************************/
function generateEmail()
{

if (validateCustomerInfo())
{
var strUrl = '';
var strMessage1 = "";
var strMessage2 = "";

if (document.qsForm.chkDesigner.checked) { strMessage1  = "Your designer discount will be applied when your order is confirmed."; strMessage2  = "Confirm and apply designer discount.";} 
strUrl = "/quickship/qsemailAction.do?cartId=" + document.qsForm.cartId.value + "&bfirstName=" + document.qsForm.txtbFirstname.value + "&blastName=" + document.qsForm.txtbLastname.value + "&phone=" + document.qsForm.txtPhone.value + "&email=" + document.qsForm.txtEmail.value + "&strMessage1=" + strMessage1 + "&strMessage2=" + strMessage2;
strUrl += "&bCity=" + document.qsForm.txtbCity.value + "&bAddress1=" + document.qsForm.txtbAddress1.value + "&bAddress2=" + document.qsForm.txtbAddress2.value + "&bState=" + document.qsForm.txtbState.value + "&bZip=" + document.qsForm.txtbZip.value + "&diffShip=" + document.qsForm.chkShipping.value ;
strUrl += "&sfirstName=" + document.qsForm.txtsFirstname.value + "&slastName=" + document.qsForm.txtsLastname.value ;
strUrl += "&sCity=" + document.qsForm.txtsCity.value + "&sAddress1=" + document.qsForm.txtsAddress1.value + "&sAddress2=" + document.qsForm.txtsAddress2.value + "&sState=" + document.qsForm.txtbState.value + "&sZip=" + document.qsForm.txtsZip.value + "&cellphone=" + document.qsForm.txtCellphone.value ;
strUrl += "&txtExt1=" + document.qsForm.txtExt1.value + "&txtExt2=" + document.qsForm.txtExt2.value;

 function showSuccess(){ 
    document.getElementById('divorder_content').innerHTML="";
    document.getElementById('customerInfo').style.display = 'none';
    document.getElementById('divThankyou').style.display = 'block';
    chkMaincart();
    _uacct = "UA-1726960-1";
    urchinTracker("/QSD/Complete.htm");
 
 }
 
    document.getElementById('divSubmit').innerHTML = "<img src=\"http://www.calicocorners.com/images/en_US/local/page_specific/singlefillslots/quick_ship/btnSubmitwait.jpg\" border=\"0\">";
	var request = new Ajax.Request(strUrl, {
			method: 'get',
			onComplete: showSuccess
		});

}

}
/**************************************/
function chkMaincart()
{
var strResult = "";
var strUrl = '/p2p/detail/ajaxdetail.do?method=chkCart'; 

 function showSuccess(response){  
    strResult = response.responseText;
    if (strResult.indexOf("empty") < 0 )
    alert("You have added swatch(es) to the shopping cart.\n To receive your swatches, close this box and then click on the \"Shopping Basket\" button in the upper right of website.\nThank you for shopping at CalicoCorners | Calico Home.");
		}
 
	var request = new Ajax.Request(strUrl, {
			method: 'get',
			onComplete: showSuccess
		});
}


/**************************************/
function populateHideFeilds(drapeId,drapeName,mainMaterial,bandMaterial,bandType,strSuitable15w3w,strGroup,strPanel,strWidth,strLength,strLength2,strLined,strLining,strInterlined,strInterlined_recom,bandable,bandOpt1,bandOpt2,bandOpt3,bandOpt4,hardwarePrice)
{
if (drapeName != "none") document.qsForm.drapeName.value = drapeName; if (drapeId != "none") document.qsForm.drapeId.value = drapeId; if (mainMaterial != "none") document.getElementById('mainMaterial').value = mainMaterial; if (bandMaterial != "none") document.getElementById('bandMaterial').value = bandMaterial; if (strWidth != "0") document.getElementById('strWidth').value = strWidth; if (strLength != "000") document.getElementById('strLength').value = strLength; document.getElementById('strLength2').value = strLength2; if (strGroup != "none") document.getElementById('strGroup').value = strGroup; if (strPanel != "0") document.getElementById('strPanel').value = strPanel; if (strSuitable15w3w != "none") document.getElementById('strSuitable15w3w').value = strSuitable15w3w; if (strLined != "none") document.getElementById('strLined').value = strLined; if (strLining != "none") document.getElementById('strLining').value = strLining; if (strInterlined != "none") document.getElementById('strInterlined').value = strInterlined; if (strInterlined_recom != "none") document.getElementById('strInterlined_recom').value = strInterlined_recom; if (bandType != "none") document.getElementById('bandType').value = bandType; if (bandable != "none") document.getElementById('bandable').value = bandable; if (bandOpt1 != "none") document.getElementById('bandOpt1').value = bandOpt1; if (bandOpt2 != "none") document.getElementById('bandOpt2').value = bandOpt2; if (bandOpt3 != "none") document.getElementById('bandOpt3').value = bandOpt3; if (bandOpt4 != "none") document.getElementById('bandOpt4').value = bandOpt4; if (hardwarePrice != "0") document.getElementById('hardwarePrice').value = hardwarePrice; mainMaterial = mainMaterial + "-tile"; waitForImage(buildUrl(drapeId, mainMaterial)); }

function validateCustomerInfo()
{
strUrl = "/quickship/qsemailAction.do?firstName=" + document.qsForm.txtbFirstname.value + "&lastName=" + document.qsForm.txtbLastname.value + "&phone=" + document.qsForm.txtPhone.value + "&email=" + document.qsForm.txtEmail.value + "&emailMessage=hello";
strEmptyError = "Please provide information below:\n";
var str = true;
var objRegExp  = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
var re = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/;
var rez = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
var re5digit=/^\d{5}$/;
var temp;
 var w;
 var selected_index;


if (document.qsForm.txtbFirstname.value == "") 
    {   
        str=false;
        strEmptyError += "Billing First name.\n";
    }
if (document.qsForm.txtbLastname.value == "") 
    {
        strEmptyError += "Billing Last name.\n";
        str=false;
    }
if (document.qsForm.txtbAddress1.value == "") 
    {
        strEmptyError += "Billing Street address.\n";
        str=false;
    }
if (document.qsForm.txtbCity.value == "") 
    {
        strEmptyError += "Billing City.\n";
        str=false;
    }
    
    
    temp = document.getElementById("txtbState");
    w = temp.selectedIndex; selected_index = temp.options[w].value;
    if (temp.options[w].value == "")
     {
        strEmptyError += "Billing State.\n";
        str=false;
    }
    
        
if (document.qsForm.txtbZip.value == "") 
    {
        strEmptyError += "Billing Zip.\n";
        str=false;
    }
else if (!(rez.test(document.qsForm.txtbZip.value)))
    {
        strEmptyError += "A valid billing zip.\n";
        str=false;
    }
  
if (document.qsForm.txtPhone.value == "") 
    {
        strEmptyError += "A valid phone number.\n";
        str=false;
    }
else if (!(re.test(document.qsForm.txtPhone.value)))

    {
        strEmptyError += "A valid phone number.\n";
        str=false;
    }
 
 
if (document.qsForm.txtEmail.value == "") 

    {
        strEmptyError += "A valid email address.\n";
        str=false;
    }

else if (!(objRegExp.test(document.qsForm.txtEmail.value)))

    {
        strEmptyError += "A valid email address.\n";
        str=false;
    }

if (document.qsForm.txtEmail2.value == "") 

    {
        strEmptyError += "Please confirm your email address.\n";
        str=false;
    }
    
 if (document.qsForm.txtEmail2.value.toLowerCase() != document.qsForm.txtEmail.value.toLowerCase())
    {
        strEmptyError += "Emails won't match.\n";
        str=false;
    }


if (document.qsForm.chkShipping.value == "yes")

    {
    
    if (document.qsForm.txtsFirstname.value == "") 
    {   
        str=false;
        strEmptyError += "Shipping First name.\n";
    }
    if (document.qsForm.txtsLastname.value == "") 
    {
        strEmptyError += "Shipping Last name.\n";
        str=false;
    }
    if (document.qsForm.txtsAddress1.value == "") 
    {
        strEmptyError += "Shipping Street address.\n";
        str=false;
    }
    if (document.qsForm.txtsCity.value == "") 
    {
        strEmptyError += "Shipping City.\n";
        str=false;
    }
    
    
    temp = document.getElementById("txtsState");
    w = temp.selectedIndex; selected_index = temp.options[w].value;
    if (temp.options[w].value == "")
     {
        strEmptyError += "Shipping State.\n";
        str=false;
    }
    
    
    if (document.qsForm.txtsZip.value == "") 
    {
        strEmptyError += "Shipping Zip.\n";
        str=false;
    }
    
}


         
if (!(document.qsForm.chkDisclaimer.checked))
    {
        strEmptyError += "Please read the terms and check the box next to Yes.\n";
        str=false;
    }
    if (!str) alert(strEmptyError);

return str;

}

/**************************************/
function ableShipping()
{
if (document.qsForm.shipInfo.checked) { document.getElementById('divShipinfo').style.display = 'block'; document.qsForm.chkShipping.value = "yes"; } else { document.getElementById('divShipinfo').style.display = 'none'; document.qsForm.chkShipping.value = "no"; }
}


function resetAllHiddenvalues() { document.getElementById('qsForm').reset(); }

function moreInfo()
{
var strUrl = '/quickship/qsdraperies.do?menuTab=tips&prodid=' + document.getElementById("drapeId").value;
myWindow = window.open(strUrl,'blank','width=450','length=200'); 
myWindow.moveTo(0,0);
}

function flyOpen()
{
var strUrl = document.getElementById('imgContainer').src;
strUrl = strUrl + "&wid=500";
myWindow = window.open(strUrl,'CalicoCorners','width=500','length=800'); 
}
function selectedOptions()
{
var strResult = "";
var strUrl = '';
var divTmp = document.getElementById('divSelectedoptions');
strUrl = '/quickship/qsdraperies.do?menuTab=leftInfo&drapeName=' + document.qsForm.drapeName.value + '&strStyle=' + document.qsForm.strStyle.value + '&strColor=' + document.qsForm.strColor.value;
strUrl += '&bandStyle=' + document.qsForm.bandStyle.value + '&bandColor=' + document.qsForm.bandColor.value;
	function setBoxHTML(response) {
	
		strResult = response.responseText;
		if (strResult.indexOf("expired") >= 0)
		{
		document.getElementById('mainContent').innerHTML = "<table width=\"100%\" border=\"0\"><tr><td align=\"center\"><a href=\"/category/custom+window+treatments/quick+ship+draperies.do\"><img src=\"http://www.calicocorners.com/images/en_US/local/page_specific/singlefillslots/quick_ship/errorSession.jpg\" width=\"412\" height=\"159\" border=\"0\"  alt=\"Configure another product\" /></a></td></tr></table>";
		
		}
		else
		{
		divTmp.innerHTML = strResult;
		}							
	}	
	var request = new Ajax.Request(strUrl, {
			method: 'get',
			onComplete: setBoxHTML			
			
		});
}
Array.prototype.findIndex=function(value)
{
var ctr="";
for (var i=0;i<this.length;i++)
{
    if (this[i] == value)
    {
        return i;
    }
}
return ctr;
};
