// JavaScript Document

function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}
function sizeConvert()
{
//  var newWindow
//  newWindow = window.open('sizes.asp','newWin','scrollbars=auto,width=500,height=280');
//  newWindow.focus()
jQuery.facebox({ ajax: "/sizes.asp" })
}

function NanoType()
{
 // var newWindow
  //newWindow = window.open('nano.asp','newWin','scrollbars=auto,width=500,height=500');
  //newWindow.focus()
  
  jQuery.facebox({ ajax: "/nano.asp"})
}
function convertWindow()
{
  //var newWindow
 // newWindow = window.open('/convert.asp','newWin','scrollbars=auto,width=550,height=300');
 // newWindow.focus()
  
  jQuery.facebox({ ajax: "/convert.asp"})
}

function howWindow(pid)
{
 // var newWindow
 // newWindow = window.open('measure.asp?pid='+pid,'newWin','scrollbars=yes,width=760,height=550');
//.focus()
  
  jQuery.facebox({ ajax: "/measure.asp?pid="+pid})
}
function optionWindow(id,pid)
{
 // var newWindow
//  newWindow = window.open('optiondetail.asp?id='+id+'&pid='+pid,'newWin','scrollbars=yes,width=750,height=400');
// newWindow.focus()
  
 jQuery.facebox({ ajax: "optiondetail.asp?id="+id+"&pid="+pid})
}
function popColour(image)
{
//  var newWindow
//  newWindow = window.open('colour.asp?image='+image,'newWin','scrollbars=no,width=300,height=240');
 // newWindow.focus()
  
  jQuery.facebox({ ajax: "/colour.asp?image="+image})
}
function silhouetteMovie()
{
  //var newWindow
 // newWindow = window.open('/silhouette.htm','newWin','scrollbars=auto,width=260,height=200');
//  newWindow.focus()
  
  jQuery.facebox({ ajax: "/silhouette.htm"})
}


function validatemessageform()
{
	if(document.messageform.firstname.value.length == 0)
	{
		alert("Please enter your first name");
		document.messageform.firstname.focus();
		return false
	}
	else if(document.messageform.lastname.value.length == 0)
	{
		alert("Please enter your last name");
		document.messageform.lastname.focus();
		return false
	}
	else if(document.messageform.email.value.length == 0)
	{
		alert("Please enter your email address");
		document.messageform.email.focus();
		return false
	}
	else if(document.messageform.order.value.length == 0)
	{
		alert("Please enter your order address");
		document.messageform.order.focus();
		return false
	}
	else if(document.messageform.date.value.length == 0)
	{
		alert("Please enter your date address");
		document.messageform.date.focus();
		return false
	}
	else
	{
		return true;
	}
}
function confirmSubmit() {
	if (document.frmDim.slat.value == "0") {
		alert("Please select a Slat Size");
		return false;
	} else if((document.frmDim.width.value <= 200)||(document.frmDim.drop.value <= 200))
	{
		return confirm("Please check the sizes entered are in millimetres and NOT centimetres");
	}
}

function setOption(label)
	{
		var choice = document.getElementById(label).value;
		if (choice.indexOf("#")>0) {
			choice=choice.split("#");
			document.getElementById(label+"span").innerHTML= choice[0];
			document.getElementById("s_1_"+label+"select").value= choice[0];
			document.getElementById(label+"select").value= choice[0];
			document.getElementById(label+"extra").value=choice[1];
			document.getElementById(label+"percent").value=choice[2];
			if (choice[3] != "" && choice[3] != 0) 
			{
			if (choice[2] !="" && choice[2] !=0)
			{
			document.getElementById(label+"percent").value=0;
			document.getElementById(label+"extra").value=choice[3]*((parseInt(choice[2])/100)+1);
			} else {
			document.getElementById(label+"extra").value=choice[3]; }
			}
			calculate();
		} else {
			document.getElementById(label+"percent").value=0;
			document.getElementById(label+"extra").value=0;
		};
	}

function setPaintOption(label)
{
	var choice = document.getElementById(label).value;
	document.getElementById(label+"span").innerHTML= choice;
	document.getElementById("s_1_"+label+"select").value= choice;
	document.getElementById(label+"select").value= choice;
	document.getElementById(label+"extra").value=0;
	document.getElementById(label+"percent").value=0;
	calculate();
}
	
function calculate(places) {
	var selects = parseInt(document.getElementById("options1").value);
	var total = 0;
	var percent = 0;
	var current = document.getElementById("curcost").value;
	var rrp = document.getElementById("rrppc").value;
	for(var x=0 ; x<selects ; x++)
	{
	total = parseFloat(total) + parseFloat(document.getElementById(x+"extra").value) ;  
	current = parseFloat(current) * ((parseInt(document.getElementById(x+"percent").value)/100)+1);
	percent = parseInt(percent) + (parseFloat(current) * ((parseInt(document.getElementById(x+"percent").value)/100)));
	} 
	percent = parseInt(percent);
	document.getElementById("extracost").value = total;
	var extratotal = parseInt(total) + parseInt(percent);
	document.getElementById("option_price").innerHTML = '+£' + extratotal;
	var cost = parseFloat(current) + parseFloat(total);  
	var qty = parseInt(document.getElementById("qty").value);
	document.getElementById("cost").value = cost.toFixed(places);
	document.getElementById("s_cost").value = cost.toFixed(places);
	cost = cost * qty;

	document.getElementById("spancost").innerHTML = "£" + cost.toFixed(0) + ".00";
	document.getElementById("spancost2").innerHTML = "£" + cost.toFixed(0) + ".00";
	document.getElementById("rrpcost2").innerHTML = "£" + (cost*rrp).toFixed(0) + ".00";
	document.getElementById("savecost2").innerHTML = "£" + ((cost*rrp)-cost).toFixed(0) + ".00";
	
}


function checkRequest() {
	if(document.frmrequest.swatch.value == "Select colour...")
	{
		alert("Please select colour");
		document.frmrequest.swatch.focus();
		return false
	} else {
		return true
	}
}

function validateCatReqForm2()
{
	if(document.catreqform.firstname.value.length == 0)
	{
		alert("Please enter your first name");
		document.catreqform.firstname.focus();
		return false
	}
	if(document.catreqform.lastname.value.length == 0)
	{
		alert("Please enter your last name");
		document.catreqform.lastname.focus();
		return false
	}
	if(document.catreqform.postcode.value.length == 0)
	{
		alert("Please enter your postcode");
		document.catreqform.postcode.focus();
		return false
	}
if(document.catreqform.telephone.value.length == 0)
	{
		alert("Please enter your telephone");
		document.catreqform.telephone.focus();
		return false
	}
	if(document.catreqform.email.value.length == 0)
	{
		alert("Please enter your e-mail address");
		document.catreqform.email.focus();
		return false
	}
	else
	{
		return true;
	}
}

function termsc() {
  if (document.form2.terms.checked) {
	//window.open('','checkout','resizable=no,status=yes,height=400,width=600,toolbar=no,scrollbars=yes,copyhistory=no').focus();
	//location='thankyou.asp';
  } else {
	alert('Please read and accept our terms & conditions');
  }
  return document.form2.terms.checked;
}

function numberonly(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
function roundit(which){
	return Math.round(which*100)/100
}
function mmconvertwidth(){
	jQuery("#width2").val(roundit(jQuery("#width1").val()/10));
	jQuery("#width3").val(roundit(jQuery("#width1").val()*0.0393700787));
}
function cmconvertwidth(){
	jQuery("#width1").val(roundit(jQuery("#width2").val()*10).toFixed(0));
	jQuery("#width3").val(roundit(jQuery("#width2").val()/2.54));
}
function inchconvertwidth(){
	jQuery("#width2").val(roundit(jQuery("#width3").val()*2.54));
	jQuery("#width1").val(roundit(jQuery("#width3").val()*25.4).toFixed(0));
}
function mmconvertdrop(){
	jQuery("#drop2").val(roundit(jQuery("#drop1").val()/10));
	jQuery("#drop3").val(roundit(jQuery("#drop1").val()*0.0393700787));
}
function cmconvertdrop(){
	jQuery("#drop1").val(roundit(jQuery("#drop2").val()*10).toFixed(0));
	jQuery("#drop3").val(roundit(jQuery("#drop2").val()/2.54));
}
function inchconvertdrop(){
	jQuery("#drop2").val(roundit(jQuery("#drop3").val()*2.54));
	jQuery("#drop1").val(roundit(jQuery("#drop3").val()*25.4).toFixed(0));
}
function checkOptions()
{
	var contin = false;
	var selects = parseInt(document.getElementById("options1").value);
	for(var x=0 ; x<=selects ; x++)
	{
		if ((document.getElementById(x+"name").value).indexOf("Bead Depth") >= 0)
		{
			if ((document.getElementById(x).value).length > 0)
			{
				contin = true;
			}
			document.getElementById(x).focus();
		}
	} 
	if (!contin)
	{
		alert("Enter Bead-Depth");
	}
	return contin;
}