// JScript source code
function GetPriceStock(strStep){
  var strURL, strTypeofBed;
  var strStage, strPriceFrom, strPriceTo;
  var myindex;
  var SelValue, SelText;
  var oHiddenValue
  //image
  var oImage=document.getElementById("imgTop");
  var oHiddenField=document.getElementById("bedFinderStage");
  var oHiddenType=document.getElementById("type");
  
	strURL = strRoot + "/common/bed_finder.vb.asp?";
	strStage = document.forms.frmBedFind.bedFinderStage.value;
	strURL += "bedFinderStage=" + strStage;
  strTypeofBed = oHiddenType.value;
  
	with (document.forms.frmBedFind)
	{
	  if(strStage == "step5" || (strStage == "step4" && strTypeofBed != "DIVAN"))
	  {
	    strPriceFrom = txtPriceFrom.text;
	    strPriceTo = txtPriceTo.text;
	  }
	  else{
	    myindex  = drpDwnFinder.selectedIndex
	    SelText = drpDwnFinder.options[myindex].text
	    SelValue = drpDwnFinder.value
	  }
	}
	
	if (validate(strStage)){
		
	  // Write response to layer
  	
	  if (strStage == "step1"){
	    oHiddenValue=document.getElementById("stepSize");
	    oHiddenValue.value= SelValue;
	    strURL += "&strSize=" + SelValue
	    strURL += "&strBrand=";
	    strURL += "&strType=";
	    strResponse = sendXmlHttpRequest(strURL);
	    MM_setTextOfLayer("txtDropDown","",strResponse);
	    MM_setTextOfLayer("txtHint","","Ok so you are looking for <strong>" + SelText + "</strong>");
	    MM_setTextOfLayer("txtQuestion","","<strong>Now, what <span class=\"orange\">type</span> of bed do you need?</strong></span>");
	    oHiddenField.value = "step2";
	    strImg = strRoot + "/images/bedfinder/step2.jpg";
	    oImage.src=strImg;
	  }
	  else if (strStage == "step2"){
	    
	    oHiddenValue=document.getElementById("stepType");
	    oHiddenValue.value= SelValue;
	    oHiddenValue=document.getElementById("stepTypeText");
	    oHiddenValue.value= SelText;
	    strURL += "&strSize=" + SelValue;
	    strURL += "&strBrand=";
	    strResponse = sendXmlHttpRequest(strURL);
	    MM_setTextOfLayer("txtDropDown","",strResponse);
	    MM_setTextOfLayer("txtHint","","So you are looking for <strong>" + SelText + "</strong>");
	    MM_setTextOfLayer("txtQuestion","","<strong>Is there any particular <span class=\"orange\">brand</span> you would prefer?</strong></span>");
	    oHiddenField.value = "step3";
	    strImg = strRoot + "/images/bedfinder/step3.jpg";
	    oImage.src=strImg;
	    GetParentType(SelValue);
	  }
	  else if (strStage == "step3" && strTypeofBed != "DIVAN"){
	       
	    oHiddenValue=document.getElementById("stepBrand");
	    oHiddenValue.value= SelValue;
	    oHiddenValue=document.getElementById("stepTypeText");
	    var strTypeAndSize = oHiddenValue.value;
	    strURL += "&strSize=" + SelValue;
	    strURL += "&strBrand=";
	    strURL += "&strType=";
	    strResponse = sendXmlHttpRequest(strURL);
	    MM_setTextOfLayer("txtDropDown","",strResponse);
	    MM_setTextOfLayer("txtHint","","Now we know you are looking for <strong>" + SelText + " " + strTypeAndSize + ", </strong>We need to know your budget." );
	    MM_setTextOfLayer("txtQuestion","","<strong>How much are you looking to <span class=\"orange\">spend</span>?</strong></span>");
	    if(strTypeofBed != "DIVAN")
	    {
	      strImg = "<input type=\"image\" height=\"24px\" value=\"Next\" class=\"bedFinderButton\" id=\"imgButton\" src=\"" + strRoot + "/images/bedfinder/find_bed.gif\" />";
	      MM_setTextOfLayer("btnNext","",strImg);
	    }
	    oHiddenField.value = "step4";
	    strImg = strRoot + "/images/bedfinder/step4.jpg";
	    oImage.src=strImg;
	  }
	  
	  else if (strStage == "step3" && strTypeofBed == "DIVAN"){	 
	    oHiddenValue=document.getElementById("stepBrand");
	    oHiddenValue.value= SelValue;
	    oHiddenValue=document.getElementById("stepTypeText");
	    var strTypeAndSize = oHiddenValue.value;   
	    oHiddenValue=document.getElementById("stepType");
      var strStep2Type = oHiddenValue.value;
      strURL += "&strSize=" + strStep2Type;
	    strURL += "&strBrand=" + SelValue;
	    strURL += "&strType=" + strTypeofBed;
	    strResponse = sendXmlHttpRequest(strURL);
	    MM_setTextOfLayer("txtDropDown","",strResponse);
	    MM_setTextOfLayer("txtHint","","Now we know you are looking for <strong>" + SelText + " " + strTypeAndSize + ".");
	    MM_setTextOfLayer("txtQuestion","","<strong>How many <span class=\"orange\">drawers</span> do you require?</strong>");
	    oHiddenField.value = "step4";
	    strImg = strRoot + "/images/bedfinder/step4.jpg";
	    oImage.src=strImg;
	  }
	  else if (strStage == "step4" && strTypeofBed == "DIVAN"){	 
	    oHiddenValue=document.getElementById("stepDrawers");
	    oHiddenValue.value= SelValue;
	    oHiddenValue=document.getElementById("stepDrawersText");
	    oHiddenValue.value= SelText;
	    oHiddenValue=document.getElementById("stepTypeText");
	    var strTypeAndSize = oHiddenValue.value;
	    oHiddenValue=document.getElementById("stepBrand");
	    var strBrand = oHiddenValue.value;   
	    oHiddenValue=document.getElementById("stepType");
      var strStep2Type = oHiddenValue.value
	    strURL += "&strSize=" + SelValue;
	    strURL += "&strType=" + strTypeofBed;
	    strURL += "&strBrand=";
	    strResponse = sendXmlHttpRequest(strURL);
	    MM_setTextOfLayer("txtDropDown","",strResponse);
	    MM_setTextOfLayer("txtHint","","...Finally we know you are looking for <strong>" + strBrand + " " + strTypeAndSize + " with " + SelText + ".");
	    MM_setTextOfLayer("txtQuestion","","<strong>How much are you looking to <span class=\"orange\">spend</span>?</strong></span>");
	    strImg = "<input type=\"image\" height=\"24px\" value=\"Next\" class=\"bedFinderButton\" id=\"imgButton\" src=\"" + strRoot + "/images/bedfinder/find_bed.gif\" />";
	      MM_setTextOfLayer("btnNext","",strImg);
	    oHiddenField.value = "step5";
	    strImg = strRoot + "/images/bedfinder/step5.jpg";
	    oImage.src=strImg;
	  }
	  else{
	    
	    GetResults();
	  }
	}

}

function validate(strStage){
var ok;
  if (strStage == "step4" && document.getElementById("type").value != "DIVAN"){
    ok = check_sendStage4(strStage);
  }
  else if (strStage == "step5" && document.getElementById("type").value == "DIVAN"){
    ok = check_sendStage4(strStage);
  }
  else{
    ok = check_send(strStage);
  }
  return ok;
}

function check_send(strStage)
{
	var ok_to_send = true;
	
	with (document.forms.frmBedFind)
	{
	  if (drpDwnFinder.value == "Please Select" && strStage == "step1")
		{
			alert("Please select a size.");
			ok_to_send = false;
		}
		else if (drpDwnFinder.value == "Please Select" && strStage == "step2")
		{
			alert("Please select a type.");
			ok_to_send = false;
		}
		else if (drpDwnFinder.value == "Please Select" && strStage == "step3")
		{
			alert("Please select a brand.");
			ok_to_send = false;
		}
		
		if (ok_to_send)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

function check_sendStage4(strStage)
{
	var ok_to_send = true;
	
	with (document.forms.frmBedFind)
	{
	  if ((txtPriceFrom.value == "" || txtPriceTo.value == "" ))
		{
			alert("Please give us your budget");
			ok_to_send = false;
		}
		else{
		  oHiddenValue=document.getElementById("stepPriceFrom");
	    oHiddenValue.value= txtPriceFrom.value;
	    oHiddenValue=document.getElementById("stepPriceTo");
	    oHiddenValue.value= txtPriceTo.value;
		}
		
		if (ok_to_send)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

function GetResults(){

      oHiddenValue=document.getElementById("stepType");
      var strStep2Type = oHiddenValue.value
	    
	    strURL += strStep2Type;	
	var strStep1, strStep2, strStep3, strStep4From, strStep4To, strStep5
	    strURL = strRoot + "/products/search.asp?keyword=";
	    
	    oHiddenValue=document.getElementById("stepSize");
	    strStep1 = oHiddenValue.value;
	    oHiddenValue=document.getElementById("type");
	    strStep2 = oHiddenValue.value;
	    
	    oHiddenValue=document.getElementById("stepBrand");
	    strStep3 = oHiddenValue.value;
	    oHiddenValue=document.getElementById("stepPriceFrom");
	    strStep4From = oHiddenValue.value;
	    oHiddenValue=document.getElementById("stepPriceTo");
	    strStep4To = oHiddenValue.value;
	    oHiddenValue=document.getElementById("stepDrawers");
	    strStep5 = oHiddenValue.value;
	    oHiddenValue=document.getElementById("stepDrawersText");
	    strStep5Text = oHiddenValue.value;
	    
	    if (document.getElementById("type").value == "DIVAN"){
	      strURL += "&size=" + strStep1 + "&type=" + strStep2 + "&brand=" + strStep3 + "&priceFrom=" + strStep4From + "&priceTo=" + strStep4To + "&drawers=" + strStep5+ "&drawersText=" + strStep5Text;
	     }
	     else{
	    strURL += "&size=" + strStep1 + "&type=" + strStep2 + "&brand=" + strStep3 + "&priceFrom=" + strStep4From + "&priceTo=" + strStep4To;
	    }
	    
	    window.location.href=strURL;
	}
	
	function GetParentType(strType){
	    strURL = strRoot + "/common/bed_finder.vb.asp?";
	    strURL += "bedFinderStage=type";
	    strURL += "&strSize=" + strType;
	    strURL += "&strType=";
	    strURL += "&strBrand=";
	    strResponse = sendXmlHttpRequest(strURL);
	    
	    oHiddenValue=document.getElementById("type");
	    oHiddenValue.value= strResponse;
	
	}
	
	function Restart(){
	    oHiddenValue=document.getElementById("bedFinderStage");
	    oHiddenValue.value= "step1";
	    window.location.reload();
	
	}
	
	//Check which button was pressed and perform action required.
	function OnSubmitForm()
{
  if(document.pressed == 'Next')
  {
   document.getElementById("frmBedFind").action ="javascript:GetPriceStock(this);";
  }
  else
  if(document.pressed == 'Start Again')
  {
    document.getElementById("frmBedFind").action ="javascript:Restart();";
  }
  return true;
}
