
//  Calculation Variables---------------------------

var area = 0;
var width = 0;
var length = 0;
var areaM = 0;
var price = 0;
var divider=1000000;
var Pprice = 0;
var PareaM = 0;
var fabric = 1;
var depth = 0;
var serror = 0;    

// Set variables for price calcultion

function GetQuote (form){
recess= "N-A";
side="N-A";
hardware="N-A";
finish="N-A"; 
slats="N-A";
hardware="N-A";
serror=0;

depth="N-A";

width=form.width.value;
Mwidth= width/1000;
length=form.length.value;
area=(form.width.value* form.length.value);
areaM=(area/divider);
PareaM=Math.round(areaM*100)/100;

// Select fixed price according to Blind Type, Confirm width and drop are within limits----------------------------

switch (BlindType)
{

case "Pleated": FixedPrice=PleatedFixed; hardware=form.hardware.value; recess=form.recess.value; side=form.side.value; CheckSizes(MinWidthPle,MinDropPle,MaxWidthPle); break;
case "Roman": FixedPrice=RomanFixed; recess=form.recess.value; side=form.side.value; CheckSizes(MinWidthRom,MinDropRom,MaxWidthRom); break;
case "Roller": FixedPrice=RollerFixed; hardware=form.hardware.value; recess=form.recess.value; side=form.side.value; finish=form.finish.value; CheckSizes(MinWidthRol,MinDropRol,MaxWidthRol); break;
case "Venetian": FixedPrice=VenetianFixed; hardware=form.hardware.value; recess=form.recess.value; slats=form.VenetianSlats.value; CheckSizes(MinWidthVen,MinDropVen,MaxWidthVen); break;
case "Vertical": FixedPrice=VerticalFixed; side=form.side.value; recess=form.recess.value; hardware=form.hardware.value; slats=form.VerticalSlats.value; CheckSizes(MinWidthVer,MinDropVer,MaxWidthVer); break;
case "Perfect": FixedPrice=PerfectFixed; hardware=form.hardware.value; depth=form.depth.value; CheckSizes(MinWidthPer,MinDropPer,MaxWidthPer); CheckDepth(form.depth.value); break;
case "Woodweave": FixedPrice=WoodweaveFixed; hardware=form.hardware.value; recess=form.recess.value; CheckSizes(MinWidthWoo,MinDropWoo,MaxWidthWoo); break;
default: slats="N-A"; finish="N-A";

}

// Check that Trim is selected------------------------------

if (serror == 1)
{
form.textareas.value = "";
form.itemname.value = "";
form.displayprice.value = "";

return;
}

if (BlindType == "Roller" && document.dj.trim.value.length == 0) // replace with above
{
alert ('Please select a Trim for your Roller Blind');
}

else{

// Calculate Blind Price and output to Cart--------------------------

if (BlindType == "Venetian")
{
switch (slats)
{
case "25": price = (areaM*Price25); break;
case "35": price = (areaM*Price30); break; 
case "50": price = (areaM*Price50); break;
}

}

if (BlindType == "Vertical")
{
switch (slats)
{
case "89": price = (areaM*Price89); break;
case "127": price = (areaM*Price127); break;
}

}

if (BlindType != "Venetian" && BlindType != "Vertical")
{
price = (areaM*FabricPrice);
}

if (BlindType == "Roller")
{
trimSupplement = (dj.trimprice.value * Mwidth);
price = (price + trimSupplement);
}
trimtype = document.dj.trim.value
form.fabric.value = (FabricName);
form.textareas.value = (PareaM);
form.textareas.value = form.textareas.value + " sq/M"
form.price.value = Math.round((price+FixedPrice)*100)/100;
form.displayprice.value = "£ " + form.price.value
form.itemname.value = "Blind Type:" + (BlindType) + " / Fabric:" + (FabricName) + " / Trim:" + (trimtype) + " / Width:" + (width) + " / Drop:" + (length) + " / Depth:" + (depth) + " / Recess:" + (recess) + " / Side:" + (side) + " / Finish:" + (finish) + " /Slats:" + (slats) + " / Hardware:" + (hardware);
}

}

//  Output advisory messages and Product Desciptions-----------------------

function messages(messages)
{
document.getElementById('mess').innerHTML=messages
}

function messageCheck(messages)
{
if (BlindType == "Perfect")
	{
	document.getElementById('mess').innerHTML=message08	
	}
else
	{
	document.getElementById('mess').innerHTML=messages
	}	

}

function description(descType)
{
document.getElementById('desc').innerHTML=descType
}
// Disable/Enable appropriate Form Entry fields and Messages according to Blind Type--------------------

function disable()
{
document.dj.fabric.value= (FabricName);

var roller="Roller";
var venetian="Venetian";
var vertical="Vertical";

// Set Drop Downs for form---------------------------------------
switch (BlindType)
{
case "Roman": document.dj.hardware.id="mysubmitNo"; document.dj.NoHardware.id="mysubmit"; document.dj.trim.value= "N/A"; document.dj.finish.id="mysubmitNo"; document.dj.Nofinish.id="mysubmit"; document.dj.VenetianSlats.id="mysubmitNo"; document.dj.NoSlats.id="mysubmit"; document.dj.VerticalSlats.id="mysubmitNo"; break;
case "Roller": document.dj.finish.id="mysubmit"; document.dj.Nofinish.id="mysubmitNo"; document.dj.VenetianSlats.id="mysubmitNo"; document.dj.NoSlats.id="mysubmit"; document.dj.VerticalSlats.id="mysubmitNo"; document.getElementById("showtable").style.visibility="visible"; document.getElementById("showdiv").style.visibility="visible"; break;
case "Venetian": document.dj.trim.value= "N/A"; document.dj.side.id="mysubmitNo"; document.dj.noSide.id="mysubmit"; document.dj.hardware.id="mysubmitNo"; document.dj.NoHardware.id="mysubmit"; document.dj.finish.id="mysubmitNo"; document.dj.Nofinish.id="mysubmit"; document.dj.VenetianSlats.id="mysubmit"; document.dj.NoSlats.id="mysubmitNo"; document.dj.VerticalSlats.id="mysubmitNo"; break;
case "Vertical": document.dj.trim.value= "N/A"; document.dj.finish.id="mysubmitNo"; document.dj.Nofinish.id="mysubmit"; document.dj.VenetianSlats.id="mysubmitNo"; document.dj.NoSlats.id="mysubmitNo"; document.dj.VerticalSlats.id="mysubmit"; break;
case "Woodweave": document.dj.trim.value= "N/A"; document.dj.side.id="mysubmitNo"; document.dj.noSide.id="mysubmit"; document.dj.hardware.id="mysubmitNo"; document.dj.NoHardware.id="mysubmit"; document.dj.finish.id="mysubmitNo"; document.dj.Nofinish.id="mysubmit"; document.dj.VenetianSlats.id="mysubmitNo"; document.dj.NoSlats.id="mysubmit"; document.dj.VerticalSlats.id="mysubmitNo"; break;
case "Perfect": document.getElementById('recessText').innerHTML="Bead Depth in mm"; document.getElementById('widthText').innerHTML="Glass Width in mm"; document.getElementById('dropText').innerHTML="Glass Drop in mm"; document.dj.trim.value= "N/A"; document.dj.recess.id="mysubmitNo"; document.dj.depth.id="mysubmit"; document.dj.side.id="mysubmitNo"; document.dj.noSide.id="mysubmit"; document.dj.hardware.id="mysubmit"; document.dj.NoHardware.id="mysubmitNo"; document.dj.finish.id="mysubmitNo"; document.dj.Nofinish.id="mysubmit"; document.dj.VenetianSlats.id="mysubmitNo"; document.dj.NoSlats.id="mysubmit"; document.dj.VerticalSlats.id="mysubmitNo"; break;
default: document.dj.trim.value= "N/A"; document.dj.finish.id="mysubmitNo"; document.dj.Nofinish.id="mysubmit"; document.dj.VenetianSlats.id="mysubmitNo"; document.dj.NoSlats.id="mysubmit"; document.dj.VerticalSlats.id="mysubmitNo"; break;
}

// Ordering instructions according to blind type--------------------

switch (BlindType)
{
case "Roller": document.getElementById('inst').innerHTML=OrderInstRoller; break;
case "Perfect": document.getElementById('inst').innerHTML=OrderInstPerfect; break;
default: document.getElementById('inst').innerHTML=OrderInstDefault;
}

}

//  Insert Trim Name & Price into Form -------------------------------
	
function putTrim(Trim, Price)
{

document.dj.trim.value= Trim;
document.dj.trimprice.value= Price;

}

// Pop Up Form for Roller Finishes

function topWindow()
{
if (BlindType == "Roller")
	{
	popup = window.open("DBFinish.php","","height=430,width=410,scrollbars=no,top=200,left=25");
	setTimeout('popup.close()',10000)
	}
}

function CheckSizes(MinWidth,MinDrop,MaxWidth)
{

if (MinWidth > width)
{
alert('Width ' + width + ' too Narrow. Should be min. ' + MinWidth + 'mm'); 
serror = 1;
}
if (MaxWidth < width)
{
alert('Width ' + width + ' too Great. Should be max. ' + MaxWidth + 'mm');
serror = 1;
}
if (MinDrop > length)
{
alert('Drop ' + length + ' too Short. Should be min. ' + MinDrop + 'mm'); 
serror = 1;
}

}

function CheckDepth(input)
{
if (input == "")
	{
	alert("Please provide a depth measurement");
	serror = 1;
	return;
	}
if (input < 0 || input > 100)
	{
	alert("Please check your depth measurement or call us to confirm");
	serror = 1.
	}
}

// Added from here
function showfinish()
{
if (BlindType == "Roller")
	{
	if (document.images) document.showIt.src= 'images/finsihes.jpg'
	}
}

function notfinish()
{
if (document.images) document.showIt.src=MainImage;
}
// To Here
