// JavaScript Document
	function stateChanged() 
	{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		 { 

			document.getElementById("fabrics_holder").innerHTML=xmlHttp.responseText ;
			$("#loading").css("display", "none");
		 } 
	}
	function selectFabric(obj, ID, name, pricePerM, repeat, thumb_src)
	{
		
		//alert("select fabric");


		var objInfoName = MM_findObj("build_panel_material_info_name_" + fabricForWhat);
		var objInfoPrice = MM_findObj("build_panel_material_info_price_" + fabricForWhat );

		eval("document.form1.fabricID_" + fabricForWhat + ".value = ID;");
		eval("document.form1.fabricName_" + fabricForWhat + ".value = name;");
		eval("document.form1.fabricCostPerM_" + fabricForWhat + ".value = pricePerM;");
		eval("document.form1.fabricRepeat_" + fabricForWhat + ".value = repeat;");

		eval("document.form1.fabricImage_" + fabricForWhat + ".src = thumb_src;");


		document.form1.thumbnailFile.value = thumb_src;

			objInfoName.innerHTML = name;
			objInfoPrice.innerHTML = "£" + pricePerM + " per metre";

			//Hide the fabric selection panel
			hideFabricSelection();

			//Calculate
			calculate_roman_blinds();

	
	
	}

function calculate_roman_blinds()
{
//	alert("calac ajax");	

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{ 
		return;
	}

	//Split lining values
	var lining_detail = document.form1.lining.value.split(",");
	var lining_description = lining_detail[2];

	//Split chain values
	var chain_detail = document.form1.chain.value.split(",");
	var chain_description = chain_detail[2];



	//Call AJAX to calculate pricing + provide summary description
	var url="iwa/include/ajax/roman_blind.php?itemID=" + document.form1.thingID.value + "&height=" + document.form1.drop.value + "&width=" + document.form1.width.value + "&lining=" + document.form1.lining.value + "&chain=" + document.form1.chain.value + "&chain_position=" + document.form1.chain_position.value + "&fabricCostPerM_romanblind=" + document.form1.fabricCostPerM_romanblind.value+ "&fabricName_romanblind=" + document.form1.fabricName_romanblind.value+ "&fabricRepeat_romanblind=" + document.form1.fabricRepeat_romanblind.value;

	xmlHttp.onreadystatechange=calculate_roman_blinds_response;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

	//Store other settings in option variables
	MM_findObj("optionTypeID_1").value = document.form1.fabricName_romanblind.value + ",0.00,Material,0";
	MM_findObj("optionTypeID_2").value = "Drop: " + document.form1.drop.value + "cm / Width: " +  document.form1.width.value + "cm,0.00,Dimensions,0";
	MM_findObj("optionTypeID_3").value = lining_description + ",0.00,Lining,0";
	MM_findObj("optionTypeID_4").value = chain_description + " - " +  document.form1.chain_position.value + ",0.00,Chain,0";
	MM_findObj("optionTypeID_5").value = document.form1.blind_position.value + ",0.00,Blind Position,0";

}

function calculate_roman_blinds_response()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
//		alert(xmlHttp.responseText);
		response = xmlHttp.responseText.split("@@IWA@@");

 
		if (response[0] == "FAILED")
		{
			alert("FAILED:" + response[1]);
			return;
		}
		else if (response[0] == "FAILED_SILENT")
		{
			return;	
		}
		
		var total_cost = response[1];
		var description = response[2];
		
		//document.getElementById("fabrics_holder").innerHTML=xmlHttp.responseText ;
		
		document.getElementById("build_summary_description").innerHTML = description;
	
		var obj_totalPrice = MM_findObj("build_total_price");
		obj_totalPrice.innerHTML = "£" + parseFloat(total_cost).toFixed(2);
		document.form1.rrp.value = total_cost;
	
		var obj_buildRight = MM_findObj("build_right");
		obj_buildRight.style.display = "block";
	
		var obj_buildBuy = MM_findObj("build_buy");
		if (total_cost > 0.00)
			obj_buildBuy.style.display = "block";
		else
			obj_buildBuy.style.display = "none";

		
	} 
	
}
