// JavaScript Document
//document.captureEvents(Event.MOUSEMOVE)
//document.onmousemove = getMouse;
mouseX = 0;
mouseY = 0;

var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
//var tempX = 0
//var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    mouseX = event.clientX + document.body.scrollLeft
    mouseY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    mouseX = e.pageX
    mouseY = e.pageY
  }  
  // catch possible negative values in NS4
  if (mouseX < 0){mouseX = 0}
  if (mouseY < 0){mouseY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  //document.Show.MouseX.value = tempX
  //document.Show.MouseY.value = tempY
  return true
}

/*function getMouse(el) {
	if (el.pageX) {
		mouseX = el.pageX
		mouseY = el.pageY
	} else {
		mouseX = event.clientX// + document.body.scrollLeft;
		mouseY = event.clientY// + document.body.scrollTop;
	}
	return true;
}*/

function showLogo(id) {
	var img = document.getElementById("manuLogo");
	if (img.src.indexOf(id) < 0) { //change image if not the right one
		img.src = "/cats/" + id + ".gif";
	}
	img.style.top = mouseY-20 + "px";
	img.style.left = mouseX+10 + "px";
	img.style.display = "block";
}
function hideLogo(id) {
	document.getElementById("manuLogo").style.display = "none";
}
function flashover()
{
    var t = null

    clearTimeout(t);

var x = document.getElementById("flashpagecontent")
//x.style.clip="rect(130px, 420px, 550px, 0px)"
x.style.height = "600px"
x.style.width = "550px"
}

function flashout()
{
var x = document.getElementById("flashpagecontent")
//x.style.clip="rect(130px, 420px, 550px, 0px)"
x.style.height = "130px"
x.style.width = "130px"
}

function TimeOut()
{
    var t = null

    clearTimeout(t);

    t = setTimeout("flashout()",2000)     
}

function DrawFlash()
{
    	var fo = new FlashObject("/flash/crosby.swf", "mymovie", "550", "600", "6", ""); 
		fo.write("flashInnerContent"); 
		fo.addVariable("variable", "varvalue"); 
}

function WriteFlash()
{
    var LineOne = "<div id='flashpagecontent' style='position:absolute;top:0px;right:0px; width: 550px; height: 600px; overflow: hidden; text-align: right; z-index: 200' >"
    var LineTwo = "<div id='flashInnerContent' style='position:absolute;top:0px;right:0px; width: 550px; height: 600px; text-align: right;'>"
    var LineThree = "<script language='javascript'>DrawFlash();" + "</" + "script>"
    var LineFour = "</div></div>"
    
    document.write(LineOne + LineTwo + LineThree + LineFour);
}

function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

function silhouetteMovie()
{
  var newWindow
  newWindow = window.open('/silhouette.htm','newWin','scrollbars=auto,width=260,height=200');
  newWindow.focus()
}

function convertWindow()
{
  var newWindow
  newWindow = window.open('/convert.asp','newWin','scrollbars=auto,width=550,height=300');
  newWindow.focus()
}
function howWindow(pid)
{
  var newWindow
  newWindow = window.open('measure.asp?pid='+pid,'newWin','scrollbars=yes,width=760,height=550');
  newWindow.focus()
}
function optionWindow(id,pid)
{
  var newWindow
  newWindow = window.open('optiondetail.asp?id='+id+'&pid='+pid,'newWin','scrollbars=yes,width=750,height=400');
  newWindow.focus()
}
function popColour(image)
{
  var newWindow
  newWindow = window.open('colour.asp?image='+image,'newWin','scrollbars=no,width=300,height=240');
  newWindow.focus()
}
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.width1.value <= 200)||(document.frmDim.drop1.value <= 200))
	{
		return confirm("Please check the sizes entered are in millimetres and NOT centimetres");
	}
}
function sizeConvert()
{
  var newWindow
  newWindow = window.open('sizes.asp','newWin','scrollbars=auto,width=500,height=280');
  newWindow.focus()
}
function recessWindow()
{
  var newWindow
  newWindow = window.open('recessexact.asp','newWin','scrollbars=auto,width=500,height=280');
  newWindow.focus()
}
function optionWindow(id,pid)
{
  var newWindow
  newWindow = window.open('optiondetail.asp?id='+id+'&pid='+pid,'newWin','scrollbars=yes,width=750,height=400');
  newWindow.focus()
}

function setOption(label,places)
	{
		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(places);
		} 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(0);
}
	
function calculate(places) {
	var selects = parseInt(document.getElementById("options1").value);
	var total = 0;
	var percent = 0;
	var current = document.getElementById("curcost").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(places);
	document.getElementById("spancost2").innerHTML = "£" + cost.toFixed(places);
}

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 validatebeaterform()
		{
			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.tel.value.length < 6)
			{
				alert("Please enter a valid telephone number");
				document.messageform.tel.focus();
				return false
			}
			else if(document.messageform.website.value.length == 0 || document.messageform.website.value == "http://")
			{
				alert("Please the website where you found this quote");
				document.messageform.website.focus();
				return false
			}
			else
			{var no = document.getElementById('no').value;
			no = parseInt(no);
				for (var x=1;x<=no;x=x+1) 
				{	                                                             
					if(document.getElementById('blind_type'+x).value.length == 0)
					{
						alert("Please enter a blind type");
						document.getElementById('blind_type'+x).focus();
						return false
					}
					else if(document.getElementById('manufacturer'+x).value.length == 0)
					{
						alert("Please enter a manufacturer");
						document.getElementById('manufacturer'+x).focus();
						return false
					}
					else if(document.getElementById('width1'+x).value.length == 0)
					{
						alert("Please enter a width");
						document.getElementById('width1'+x).focus();
						return false
					}
					else if(document.getElementById('drop1'+x).value.length == 0)
					{
						alert("Please enter a drop1");
						document.getElementById('drop'+x).focus();
						return false
					}
					else if(document.getElementById('price'+x).value.length == 0)
					{
						alert("Please enter a price");
						document.getElementById('price'+x).focus();
						return false
					}
				}
				return true
			}
		}
		
		function validatefindform()
		{
			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 ((!isNumeric(document.messageform.tel.value.replace(" ",""))) || (document.messageform.tel.value.length < 6))
			{
				alert("Please enter a valid telephone number");
				document.messageform.tel.focus();
				return false
			}
			else
			{var no = document.getElementById('no').value;
			no = parseInt(no);
				for (var x=1;x<=no;x=x+1) 
				{	
					if(document.getElementById('blind_type'+x).value.length == 0)
					{
						alert("Please enter a blind type");
						document.getElementById('blind_type'+x).focus();
						return false
					}
					else if(document.getElementById('width'+x).value.length == 0)
					{
						alert("Please enter a width");
						document.getElementById('width'+x).focus();
						return false
					}
					else if(document.getElementById('drop'+x).value.length == 0)
					{
						alert("Please enter a drop");
						document.getElementById('drop'+x).focus();
						return false
					}
				}
				return true
			}
		}
		
		
		function isNumeric(val){return(parseFloat(val,10)==(val*1));}
		
		function changeNumber()
		{
			document.messageform.action = "price_beater.asp";
			document.messageform.submit();
		}
		
		function changeNumber2()
		{
			document.messageform.action = "find_my_blind.asp";
			document.messageform.submit();
		}
		
				function validateCatReqForm()
		{
			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.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 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 ((!isNumeric(document.messageform.tel.value)) || (document.messageform.tel.value.length < 6))
			{
				alert("Please enter a valid telephone number");
				document.messageform.tel.focus();
				return false
			}
			else if(document.messageform.subject.value.length == 0)
			{
				alert("Please enter a subject for your message");
				document.messageform.subject.focus();
				return false
			}
			else if(document.messageform.message.value.length == 0)
			{
				alert("Please enter your message");
				document.messageform.message.focus();
				return false
			}
			else
			{
				return true;
			}
		}
		
		function validatetrackingform()
		{
			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 subscribe() {
			document.getElementById('subdiv').style.display = "";
		}
		
		
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));
}