function ChckPrescription() {
var InterAdd = parseFloat(document.getElementById('InterAdd').value);
var LeftSpDist = parseFloat(document.getElementById('LeftSphereDist').value);
var LeftCylDist = parseFloat(document.getElementById('LeftCylinderDist').value);

var LeftAxisDist = parseFloat(document.getElementById('LeftAxisDist').value);
var RightSpDist = parseFloat(document.getElementById('RightSphereDist').value);
var RightCylDist = parseFloat(document.getElementById('RightCylinderDist').value);

var RightAxisDist = parseFloat(document.getElementById('RightAxisDist').value);

var DistTotal = RightSpDist + LeftSpDist;

var LeftSpNear = parseFloat(document.getElementById('LeftSphereNear').value);

var LeftCylNear = parseFloat(document.getElementById('LeftCylNear').value);
var LeftAxisNear = parseFloat(document.getElementById('LeftAxisNear').value);
var RightSpNear = parseFloat(document.getElementById('RightSphereNear').value);

var RightCylNear = parseFloat(document.getElementById('RightCylNear').value);
var RightAxisNear = parseFloat(document.getElementById('RightAxisNear').value);


var NearTotal = RightSpNear + LeftSpNear;

//var IncSpecs =document.getElementById('IncSpecs').value;

var LenseUse = document.getElementById('LenseUsage').value;

var ErrorMssg = '';
//create error messages
if (NearTotal==40 && DistTotal==40)	{

	ErrorMssg += "* You must fill in at least the Distance sphere values or the Near sphere values";
	ErrorMssg += "\n\n";
	}
	
// Check Dist sphere values 
if (RightSpDist != 20 && LeftSpDist == 20){

	ErrorMssg += "* You must enter a Left Dist sphere value if you have entered a Right value";
	ErrorMssg += "\n";
	}
if (LeftSpDist != 20 && RightSpDist == 20){
	ErrorMssg += "* You must enter a Right Dist sphere value if you entered a Left value";

	ErrorMssg += "\n\n";
	}
if (RightSpNear != 20 && LeftSpNear == 20){
	ErrorMssg += "* You must enter a Left Near sphere value if you have entered a Right value";
	ErrorMssg += "\n\n";

	}
if (LeftSpNear != 20 && RightSpNear == 20){
	ErrorMssg += "* You must enter a Right Near sphere value if you entered a Left value";
	ErrorMssg += "\n\n";
	}
	
// Check Dist Cyl and axis

if (isNaN(LeftAxisDist)==true && LeftCylDist!=12){
	ErrorMssg += "* You must enter a numerical Left Dist Axis value if you entered a Left Cyl value";
	ErrorMssg += "\n\n";
	}
if (isNaN(RightAxisDist)==true && RightCylDist!=12){

	ErrorMssg += "* You must enter a numerical Right Dist Axis value if you entered a Right Cyl value";
	ErrorMssg += "\n\n";
	}
if (isNaN(LeftAxisDist)==false && LeftCylDist==12){
	ErrorMssg += "* You must enter a Left Cyl value if you entered a Left Dist Axis value";

	ErrorMssg += "\n\n";
	}
if (isNaN(RightAxisDist)==false && RightCylDist==12){
	ErrorMssg += "* You must enter a Right Cyl value if you entered a Right Dist Axis value";
	ErrorMssg += "\n\n";

	}
	
// Check Near Cyl and axis
if (isNaN(LeftAxisNear)==true && LeftCylNear!=12){
	ErrorMssg += "* You must enter a numerical Left Near Axis value if you entered a Left Cyl value";
	ErrorMssg += "\n\n";

	}
if (isNaN(RightAxisNear)==true && RightCylNear!=12){
	ErrorMssg += "* You must enter a numerical Right Near Axis value if you entered a Right Cyl value";
	ErrorMssg += "\n\n";
	}

if (isNaN(LeftAxisNear)==false && LeftCylNear==12 && document.getElementById('NearAdd').value == 0){
	ErrorMssg += "* You must enter a Left Near Cyl value if you entered a Left Near Axis value";

	ErrorMssg += "\n\n";
	}
if (isNaN(RightAxisNear)==false && RightCylNear==12 && document.getElementById('NearAdd').value == 0){
	ErrorMssg += "* You must enter a Right Near Cyl value if you entered a Right Near Axis value";

	ErrorMssg += "\n\n";
	}
	
//Check if axis is within range
if (RightAxisNear<0 || RightAxisNear>180){
	ErrorMssg += "* The Right Near Axis value must be between 0 and 180";
	ErrorMssg += "\n\n";

	}
if (LeftAxisNear<0 || LeftAxisNear>180){
	ErrorMssg += "* The Left Near Axis value must be between 0 and 180";
	ErrorMssg += "\n\n";
	}
if (RightAxisDist<0 || RightAxisDist>180){

	ErrorMssg += "* The Right Dist Axis value must be between 0 and 180";
	ErrorMssg += "\n\n";
	}
if (LeftAxisDist<0 || LeftAxisDist>180){
	ErrorMssg += "* The Left Dist Axis value must be between 0 and 180";

	ErrorMssg += "\n\n";
	}
	
//Check values against usage

var user_input="None"
for (i=0;i<document.PrescriptForm.IncSpecs.length;i++) {
	if (document.PrescriptForm.IncSpecs[i].checked) {

		user_input = document.PrescriptForm.IncSpecs[i].value;
	}
}

if (user_input == "None"){
	ErrorMssg +="* You need to inform us if you are sending us an old pair of spectacles to measure your PD value or not.";

	ErrorMssg += "\n\n";
	}
if (document.getElementById('LenseUsage').value == "Please Select"){
	ErrorMssg += "* You need to tell us what you intend to use your spectacles for";

	ErrorMssg += "\n\n";
	}
if (document.getElementById('LenseUsage').value == "Intermediate" && document.getElementById('InterAdd').value == 0){
	ErrorMssg += "* You need to supply an InterAdd value if you require Intermediate strength lenses";

	ErrorMssg += "\n\n";
	}
if (document.getElementById('NearAdd').value == 0){
	if (document.getElementById('LenseUsage').value == "Near" && NearTotal == 40){
	ErrorMssg += "* You need to supply a NearAdd value or Left and Right Near Sphere values if you require Near strength lenses";

	ErrorMssg += "\n\n";
	//alert (NearTotal)
	}
	}
if (document.getElementById('LenseUsage').value == "Distance" && DistTotal == 40){
	ErrorMssg += "* You need to supply Left and Right Dist Sphere values if you require distance strength lenses";

	ErrorMssg += "\n\n";
	}
// Create error or post form	
if (ErrorMssg != ""){
	alert (ErrorMssg);}
else {document.PrescriptForm.submit();}
}

function CheckNearAdd() {
var NearAddVal=(document.getElementById('NearAdd').value)

var $NearAddRghtSphr = document.getElementById('RightSphereNear');
var $NearAddRghtCyl = document.getElementById('RightCylNear');
var $NearAddlftSphr = document.getElementById('LeftSphereNear');

var	$NearAddLftAxis2 = document.getElementById('LeftAxisNear_hide');
var	$NearAddRghtAxis2 = document.getElementById('RightAxisNear_hide')

var $NearAddlftCyl = document.getElementById('LeftCylNear');
var $NearAddRghtAxis = document.getElementById('RightAxisNear');
var $NearAddLftAxis = document.getElementById('LeftAxisNear');

if (NearAddVal!=0)
	{	
	$NearAddRghtSphr.className='HideAdd'
	$NearAddRghtCyl.className='HideAdd'
	$NearAddlftSphr.className='HideAdd'
	$NearAddlftCyl.className='HideAdd'
	$NearAddLftAxis2.className='HideAdd'
	$NearAddRghtAxis2.className='HideAdd'

	$NearAddRghtAxis.className='HideAdd'
	$NearAddLftAxis.className='HideAdd'
	document.PrescriptForm.RightSphereNear.selectedIndex = 0
	document.PrescriptForm.RightCylNear.selectedIndex = 0
	document.PrescriptForm.LeftSphereNear.selectedIndex = 0

	document.PrescriptForm.LeftCylNear.selectedIndex = 0
	//alert (NearAddVal);
	}
else {
	$NearAddRghtSphr.className=''
	$NearAddRghtCyl.className=''
	$NearAddlftSphr.className=''

	$NearAddlftCyl.className=''
	$NearAddRghtAxis.className=''
	$NearAddLftAxis.className=''
	//alert ('No Near Add is chosen');
	}
}
function MM_showHideLayers() { //v9.0

  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }

    obj.visibility=v; }
}

