function login()
{
	if(document.loginForm.user.value=="")
	{
		alert('Please fill in the username.');
		document.loginForm.user.focus();
	}
	else if (document.loginForm.password.value=="")
	{
		alert('Please fill in the password.');
		document.loginForm.password.focus();
	}
	
	else
	{
		document.loginForm.submit();
	}
}

function checkPass()
{
	if(document.registerFrm.password.value == document.registerFrm.password2.value)
	{
		document.registerFrm.submit();
	}
	else
	{
		alert("Your passwords don't match please check and try again");
		document.registerFrm.password.value ="";
		document.registerFrm.password2.value ="";
		document.registerFrm.password.focus(); 
	}
}

function lenseLogic(fEyeSize, fBridgeSize)
{
	var passTest = true;

	var addR =	document.frameForm0.RAdd.options[document.frameForm0.RAdd.selectedIndex].value;
	var addL =	document.frameForm0.LAdd.options[document.frameForm0.LAdd.selectedIndex].value;

	var cylR =  document.frameForm0.RCyl.options[document.frameForm0.RCyl.selectedIndex].value;
	var cylL =  document.frameForm0.LCyl.options[document.frameForm0.LCyl.selectedIndex].value;
	
	var axisR = document.frameForm0.RAxi.value;
	//alert(' R AXIS: '+axisR);
	//alert(' R Cyl: '+cylR);

	if (document.frameForm0.bifocaltype.value=='yes' && (addR=='0' || addL=='0'))
	{
		alert('You have chosen Bifocal lenses and have not entered an add value for your eyes.\nPlease do so.');
		document.frameForm0.RAdd.focus();
		passTest = false;
	}
	
	if(axisR ==null || axisR == '')
	{
		if(cylR <0 || cylR >0)
		{
			alert('You have not entered an axis value for your right eye.\nPlease do so.');
			document.frameForm0.RAxi.focus();
			passTest = false;
		}
	}
	
	var axisR = document.frameForm0.RAxi.value;
	//alert(' R AXIS: '+axis);
	if(axisR ==null || axisR == '')
	{
		if(cylL <0 || cylL >0)
		{
			alert('You have not entered an axis value for your left eye.\nPlease do so.');
			document.frameForm0.LAxi.focus();
			passTest = false;
		}
	}
	
	//right eye
	//pos sphere
	
	if((document.frameForm0.RCyl.options[document.frameForm0.RCyl.selectedIndex].value > 0 && document.frameForm0.LCyl.options[document.frameForm0.LCyl.selectedIndex].value < 0) || (document.frameForm0.RCyl.options[document.frameForm0.RCyl.selectedIndex].value < 0 && document.frameForm0.LCyl.options[document.frameForm0.LCyl.selectedIndex].value > 0))
	{
		passTest = false;
		alert('You have entered + and - cyl values. These will always be either + or - not both.\nPlease check and try again');
	}
	if(document.frameForm0.RSph.options[document.frameForm0.RSph.selectedIndex].value >= 0)
	{
		if(document.frameForm0.RCyl.options[document.frameForm0.RCyl.selectedIndex].value >= 0)
		{
			var sphere = Number(document.frameForm0.RSph.options[document.frameForm0.RSph.selectedIndex].value) + Number(document.frameForm0.RCyl.options[document.frameForm0.RCyl.selectedIndex].value);
			//alert('spehere: '+sphere);
			var cyl =  document.frameForm0.RCyl.options[document.frameForm0.RCyl.selectedIndex].value;
			var cyl2 =  document.frameForm0.RCyl.options[document.frameForm0.RCyl.selectedIndex].value;
			cyl = -cyl;
			//alert('cyl: '+cyl);
//			cyl = Math.abs(cyl);
			
			//Set the values of Right Sphere and Cyl
			//document.frameForm0.RSph.value = sphere;
			//document.frameForm0.RCyl.value = cyl;
			
			var axis = document.frameForm0.RAxi.value;
			//alert(' R AXIS: '+axis);
			if(axis ==null || axis == '')
			{
				if(cyl2 <0 || cyl2 >0)
				{
					//alert('You have not entered an axis value for your right eye.\nPlease do so.');
					document.frameForm0.RAxi.focus();
					passTest = false;
				}
			}
			else
			{
				//alert('Axis not null');
				axis = Number(document.frameForm0.RAxi.value) ;
				if(axis >360)
				{
					alert('Please put in an axis value of less than 360');
					passTest=false;
				}
				if(axis >90)
				{
					 axis -=90;
				}
				
				else
				{
					axis +=90;			
				}
			}
			//document.frameForm0.RAxi.value = axis;
		}
		
		if(sphere > 2.75)
		{
			lensePower(fEyeSize, fBridgeSize, sphere);
		}
	}
	
	//neg Sphere
	else
	{
		//if(document.frameForm0.RSph.options[document.frameForm0.RSph.selectedIndex].value <= -3.5)
		if(sphere <2.75)
		{
			document.frameForm0.thinnerLenses.value=1;
		}
	}
	
	//left eye
	
	//pos
	if(document.frameForm0.LSph.options[document.frameForm0.LSph.selectedIndex].value >= 0)
	{
		if(document.frameForm0.LCyl.options[document.frameForm0.LCyl.selectedIndex].value >= 0)
		{
			//alert ('start');
			var sphere = Number(document.frameForm0.LSph.options[document.frameForm0.LSph.selectedIndex].value) + Number(document.frameForm0.LCyl.options[document.frameForm0.LCyl.selectedIndex].value);
			var cyl =  document.frameForm0.LCyl.options[document.frameForm0.LCyl.selectedIndex].value;
			var cyl2 =  document.frameForm0.LCyl.options[document.frameForm0.LCyl.selectedIndex].value;
			cyl = -cyl;
			//cyl = Math.abs(cyl);
			
			//Set the values of Right Sphere and Cyl
			//document.frameForm0.RSph.value = sphere;
			//document.frameForm0.RCyl.value = cyl;
			
			var axis = document.frameForm0.LAxi.value;
		//	alert(' R AXIS: '+axis);
			if(axis ==null || axis == '')
			{
				//alert('null axis, cyl: '+ cyl2);
				if(cyl2 <0 || cyl2 >0)
				{
					//alert('You have not entered an axis value for your left eye.\nPlease do so.');
					document.frameForm0.LAxi.focus();
					passTest = false;
				}
			}
			else
			{
				//alert('Axis not null');
				axis = Number(document.frameForm0.LAxi.value) ;
				if(axis >360)
				{
					alert('Please put in an axis value of less than 360');
					passTest=false;
				}
				if(axis >90)
				{
					 axis -=90;
				}
				
				else
				{
					axis +=90;			
				}
			}
			//document.frameForm0.LAxi.value = axis;
		}
		
		//if(document.frameForm0.LSph.options[document.frameForm0.LSph.selectedIndex].value <2.75)
		if(sphere > 2.75)
		{
			lensePower(fEyeSize, fBridgeSize, sphere);
		}
	}
	
	//neg Sphere
	else
	{
		if(document.frameForm0.LSph.options[document.frameForm0.LSph.selectedIndex].value <= -3.5)
		{
			document.frameForm0.thinnerLenses.value=1;
		}
	}
		if(passTest)
		{
			//alert(document.frameForm0.thinnerLenses.value);
			document.frameForm0.submit();
		}

}

function lensePower(eyeSize, bridgeSize, spheres)
{
	//alert(eyeSize+'-'+bridgeSize);
	var framePD, X, lensSizeNeeded, lensOverSized;
	
	//work out Frame Pupil Distance
	framePD = eyeSize + bridgeSize;
	//alert('Frame PD: '+framePD);
	//Work out X (<- why X??)
	X = framePD - document.frameForm0.pupilDistance.options[document.frameForm0.pupilDistance.selectedIndex].value;
	//alert('X: '+X);
	//work out Lens Size
	lensSizeNeeded = eyeSize + X;
	//alert('Lens Size: '+lensSizeNeeded);
	//work out oversize
	lensOverSized = 65 - lensSizeNeeded;
	//alert('Lens Over Size: '+lensOverSized);
	
	var Y = lensOverSized * spheres ;
	if(Y > 36)
	{
		document.frameForm0.thinnerLenses.value=1;
		//alert('From Lense Power: '+document.frameForm0.thinnerLenses.value);
	}
	
}

//function for purchasing just frames
function justFrames()
{	
  if (document.frameForm0.colourBut.length>1)
  {
		valcheck="";
		for (i=0;i<document.frameForm0.colourBut.length;i++) {
			if (document.frameForm0.colourBut[i].checked) {
				valcheck=document.frameForm0.colourBut[i].value;
			}
		}
		
		if (valcheck=="")
		{
			alert('Please select your frame color.');
			document.frameForm0.colourBut[0].focus();
		}
		else {
		document.frameForm0.action="_transit.php";
		document.frameForm0.submit();
		}
   }
   else {
		document.frameForm0.action="_transit.php";
		document.frameForm0.submit();
   }
}

// check if frame color chosen, no color selected by default, except when there is only one. Added 25-04-2005 TA
function addLenses()
{
  if (document.frameForm0.colourBut.length>1)
  {
		valcheck="";
		for (i=0;i<document.frameForm0.colourBut.length;i++) {
			if (document.frameForm0.colourBut[i].checked) {
				valcheck=document.frameForm0.colourBut[i].value;
			}
		}
		
		if (valcheck=="")
		{
			alert('Please select your frame color.');
			document.frameForm0.colourBut[0].focus();
		}
		else {
		document.frameForm0.submit();
		}
  }
  else
  {
		document.frameForm0.submit();
  }
}

function justFrames2(formName)
{
	formName.action = "_transit.php";
	formName.submit();
}

function checkOpt(lensOption, lensType)
{
	if(lensOption == "Polarised")
	{
		if(document.getElementById("Polarised").checked ==true)
		{
			document.getElementById("Sunglasses Tints").checked = false;
			document.getElementById("Sunglasses Tints").disabled = true;
			document.getElementById("tint").disabled = true;
			document.getElementById("tint").selectedIndex = 0;
			document.getElementById("shade").disabled = true;
			document.getElementById("shade").selectedIndex =0;
			document.getElementById("Photochromic Lenses (light sensitive)").checked = false;
			document.getElementById("Photochromic Lenses (light sensitive)").disabled = true;
			document.getElementById("Polycarbonate Lenses").disabled = false;
			document.getElementById("UV 400 Proactive Coating").disabled = false;
		}
		else
		{
			document.getElementById("Sunglasses Tints").disabled = false;
			document.getElementById("tint").disabled = false;
			document.getElementById("shade").disabled = false;
			document.getElementById("Photochromic Lenses (light sensitive)").disabled = false;
		}
	}
	
	if(lensOption == "Photochromic Lenses (light sensitive)")
	{
		if(document.getElementById("Photochromic Lenses (light sensitive)").checked ==true)
		{
			document.getElementById("Polarised").checked ==false
			document.getElementById("Polarised").disabled = true;
		}
		else
		{			
			if(lensType !=3)
			{
				document.getElementById("Polarised").disabled = false;
			}
		}
	}

	if(lensOption == "Polycarbonate Lenses")
	{
		if(document.getElementById("Polycarbonate Lenses").checked ==true)
		{
			document.getElementById("Photochromic Lenses (light sensitive)").checked = false;
			document.getElementById("Photochromic Lenses (light sensitive)").disabled = true;
			document.getElementById("Polarised").disabled = false;
		}
		else 
		{
			document.getElementById("Photochromic Lenses (light sensitive)").disabled = false;
		}
	}
	
	if(lensOption == "Sunglasses Tints")
	{
		if(document.getElementById("Sunglasses Tints").checked ==true)
		{
			//document.getElementById("UV 400 Proactive Coating").checked = true;
			//document.getElementById("UV 400 Proactive Coating").disabled = true;
			document.getElementById("tint").focus();
		}
		else
		{
			document.getElementById("UV 400 Proactive Coating").checked = false;
			document.getElementById("UV 400 Proactive Coating").disabled = false;
		}
	}
}


function enableDisabled()
{
	var proceedOK = true;
		
	if(document.getElementById("Sunglasses Tints").checked== true && (document.getElementById("tint").selectedIndex == 0 || document.getElementById("shade").selectedIndex == 0))
	{
		proceedOK = false;
		alert('Please choose the colour tint and filter you would like for your frames');
		if(document.getElementById("tint").selectedIndex == 0)
		{
			document.getElementById("tint").focus();
		}
		else if(document.getElementById("shade").selectedIndex == 0)
		{
			document.getElementById("shade").focus();
		}
	}
	
	if(document.getElementById("Sunglasses Tints").checked== false && document.getElementById("tint").selectedIndex > 0 && document.getElementById("shade").selectedIndex > 0)
	{
		
		document.getElementById("Sunglasses Tints").checked = true;
		document.getElementById("Sunglasses Tints").disabled = true;
		
		if(document.getElementById("UV 400 Proactive Coating").checked == false)
		{
			document.getElementById("UV 400 Proactive Coating").checked = true;
			document.getElementById("UV 400 Proactive Coating").disabled = true;
		}
		
		if(document.getElementById("shade").selectedIndex > 0 && document.getElementById("tint").selectedIndex == 0)
		{
			proceedOK = false;
			alert('Please choose the colour tint you would like for your frames');
			document.getElementById("tint").focus();
		}
		
		if(document.getElementById("tint").selectedIndex > 0 && document.getElementById("shade").selectedIndex == 0)
		{
			proceedOK = false;
			alert('Please choose the filter you would like for your frames');
			document.getElementById("shade").focus();
		}
	}
	
	if(proceedOK)
	{
		if(document.getElementById("UV 400 Proactive Coating").disabled == true)
		{
			document.getElementById("UV 400 Proactive Coating").disabled = false;
		}
		
		if(document.getElementById("Polycarbonate Lenses").disabled == true)
		{
			document.getElementById("Polycarbonate Lenses").disabled = false;
		}
		
		if(document.getElementById("Sunglasses Tints").disabled == true)
		{
			document.getElementById("Sunglasses Tints").disabled = false;
		}
		
		if(document.getElementById("Polarised").disabled ==true)
		{
			document.getElementById("Polarised").disabled = false;
		}
		
		
		if(document.getElementById("Thinner Lenses").disabled ==true)
		{
			document.getElementById("Thinner Lenses").disabled = false;
		}
		
		document.frameForm0.submit();
		//alert('would go');
	}
}

/*Shopping cart functions*/
//function to show and hide our div tag with options
function showHide(idname, linkName)
{
	if(idname.style.display == "inline")
	{	
		idname.style.display = "none";
		linkName.innerHTML="(more info...)";
	}

	else
	{
		idname.style.display = "inline";
		linkName.innerHTML="(less info...)";
	}
}

function updateShipping(form2)
{
	value = document.uShipping.shipping.options[document.uShipping.shipping.options.selectedIndex].value;
	if(value == 1 || value == -1)
	{
		form2.submit();
	}
	else
	{
		alert('It appears you reside outside the UK\nPlease ring our customer services number:\n+44 1604 708 500');
	}
}

function checkShipping()
{
	value = document.uShipping.shipping.options[document.uShipping.shipping.options.selectedIndex].value;
	//document.co.action="https://secure.freetimers.com/darlaequestrian/order.php"+details;
	

	/*if (value < 0)
	{
		alert ("Please select your shipping location");
	}
	else
	{*/
		document.co.action="checkout.php";
		document.co.submit();
	//}
}

function doSubmit(form2,action)
{
	form2.mode.value = action;
	form2.submit();

}

function removeItem(form2,val)
{
	form2.remove_index.value = val;
	form2.mode.value = 'remove';
	form2.submit();
}

function goShopping(form3)
{
	form3.action="cat.php";
	form3.submit();
}

function infoConfirm()
{
	//added chosing lens type mandatory, no field selected by default 25-04-2005 TA
	
	lvalcheck="";
	for (i=0;i<document.frameForm0.lensBut.length;i++) {
        if (document.frameForm0.lensBut[i].checked) {
            lvalcheck=document.frameForm0.lensBut[i].value;
        }
    }
	
	if (lvalcheck=="")
	{
		alert('Please select your lens type.');
		document.frameForm0.lensBut[0].focus();
	}
	else {

		if(confirm('You are about to enter your prescription details.\nPlease take great care when entering this information as we will manufacture your glasses based upon this prescription.\nWe cannot be held responsible for incorrect information entered at this stage.\nIf you are unsure, please ask your Optician for your latest prescription\n\nDo you wish to continue?'))
		{
			document.frameForm0.submit();
		}

	}
}

//Submit on enter
function submitenter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (keycode == 13)
	{
		myfield.form.action="loginAct.php";
		myfield.form.submit();
		return false;
	}
	else
		return true;
}
function checkTC(thisValue)
{
	if(thisValue.checked ==true)
	{
		thisValue.value=1;
	}
	
	else
	{
		thisValue.value=0;
	}
}

function checkValue(field,thingywotsit)
{
	var temp = eval("document.checkOutForm."+field+".value;");
	if(temp=="" || temp==" " || temp=="Select Country")
	{
		alert("Please fill in " + thingywotsit + ", and try again.");
		eval("document.checkOutForm."+field+".focus();");
		return false;
	} else {
		return true;
	}

}

function checkForm()
{
	if(checkValue("yname","name") && checkValue("comments","comments"))
	{
		if(emailCheck(document.checkOutForm.email.value))
		{
			document.checkOutForm.submit();
		} else {
			alert("Please fill in your email address, and try again.\nIf you have filled in your email address, check that the '.' and '@' sign are correct. \nAn email address will look something like the examples below:\n\n - yourname@somewhere.com \n - yourname@somewhere.co.uk\n");
			document.checkOutForm.email.focus();
		}
	}
}


function bookmark()
{
	if (document.all)
	{
		window.external.AddFavorite("http://www.glassesonspec.co.uk", "Glasses On Spec");
	}
	else if (window.sidebar)
	{
		window.sidebar.addPanel("Glasses On Spec", "http://www.glassesonspec.co.uk", "");
	}
}