minSphere=-10;
maxSphere=10;
minCylinder=-6;
maxCylinder=6;

function opentip(tipid){
	window.open("tips.asp?Action=GetTip&TipID=" + tipid,"newOne","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=500,height=400");
}

function validateform(ValidateNonePrescription){
 if (nullPreData()) {
   if (document.f.DoPrescription.length>1) {
       document.f.DoPrescription[0].checked=1;
   } else {
	   document.f.DoPrescription.checked=1;
   }	 
    document.f.submit();
 } else {   
   if (document.f.DoPrescription.length>1) {
    if (CheckPreData() && document.f.DoPrescription[0].checked) {
	  document.f.DoPrescription[1].checked=1;
	  if (document.f.DoPrescription.length > 2) {
		alert("Please select prescription option.");
		document.f.DoPrescription[1].focus();  
	  } else {
		document.f.submit();
	  }
    } else {
      if (!CheckPreData()) {
        alert("Please enter valid prescription data")
        document.f.RightSphere.focus();
      } else {
        document.f.submit();
      }
    }
   } else {
     document.f.submit();
   } 
 }  
}

function nullPreData() {
 rsphere=document.f.RightSphere.value;
 rcylinder=document.f.RightCylinder.value;
 raxis=document.f.RightAxis.value;
 lsphere=document.f.LeftSphere.value;
 lcylinder=document.f.LeftCylinder.value;
 laxis=document.f.LeftAxis.value;
 pd=document.f.PD.value;
 if (rsphere=="" && rcylinder=="" && raxis=="" && lsphere=="" && lcylinder=="" && laxis=="" && pd=="") {
	return true;
 } else {
	return false;
 }	
}

function CheckPreData() {
 rsphere=document.f.RightSphere.value;
 rcylinder=document.f.RightCylinder.value;
 raxis=document.f.RightAxis.value;
 lsphere=document.f.LeftSphere.value;
 lcylinder=document.f.LeftCylinder.value;
 laxis=document.f.LeftAxis.value;
 pd=document.f.PD.value;
 if (pd=="") {
   return false;
 } else {
   if (rsphere=="" && rcylinder=="" && raxis=="" && lsphere=="" && lcylinder=="" && laxis=="") {
     return false;
   } else {
          
     if ( ( isNaN(parseFloat(rsphere)) && isNaN(parseFloat(rcylinder)) && isNaN(parseFloat(raxis)) && rsphere!="" && rcylinder!="" && raxis!="" )  || ( isNaN(parseFloat(lsphere)) && isNaN(parseFloat(lcylinder)) && isNaN(parseFloat(laxis)) && lsphere!="" && lcylinder!="" && laxis!="" ) ) {
		return false;
     } else {
       if ((rcylinder!="" && raxis=="") || (lcylinder!="" && laxis=="") || (rcylinder=="" && raxis!="")|| (lcylinder=="" && laxis!="")) {
         return false;
       } else {  
         return true;
       }  
     }
   }     
 }
} 

function CheckPrescription(){
	if(!CheckRulesSphere(ReduceValue(document.f.RightSphere.value))){
		alert("Your prescription entry for Right Sphere is invalid.");
		return false;
	}else{
		return true;
	}
}
function ReduceValue(incoming){
	if(incoming > 10 || incoming < -10){
		incoming = incoming / 100;
		return incoming;
	}else{
		return incoming;
	}
}
function CheckRulesSphere(incoming){
	if(incoming < 10 && incoming > -10){
		return true;
	}else{
		return false;
	}
}
function CheckRulesCylinder(incoming){
	if(incoming < 1 && incoming > -7){
		return true;
	}else{
		if(incoming < 7){
			return true;
		}else{
			return false;
		}
	}
}
function CheckRulesAxis(incoming){
	if(incoming < 181 && incoming > -1){
		return true;
	}else{
		return false;
	}
}
function CheckRulesPD(incoming){
	if(incoming < 71 && incoming > 49){
		return true;
	}else{
		return false;
	}
}

function CheckNull(incoming){
	if(incoming != "" && incoming != null){
		return true;
	}else{
		return false;
	}
}

function CheckNumeric(incoming){
	if(incoming != "" && incoming != null){
		if(isNaN(incoming)){
			return false;
		}else{
			return true;
		}
	}else{
		return false;
	}
}

function Reverse(strToReverse) {	var strRev = new String;	var i = strToReverse.length;	while (i--)	strRev += strToReverse.charAt(i);	return strRev;}

function validateSphere(obj) {
if ((obj.value != "") && (obj.value.toUpperCase() !="PL") && (obj.value.toUpperCase() !="PLANO")) {
 sValue=parseFloat(obj.value);
 if (isNaN(sValue)) {
	alert("It should be a number between " +minSphere +" and " +maxSphere);
    obj.focus();
 } else {
   if (sValue < minSphere || sValue > maxSphere) {
	  alert("Please check the value of sphere, it should be between " +minSphere +" and " +maxSphere);
	  obj.focus();
   } 
 }
}
}

function validateCylinder(obj) {
if ((obj.value != "") && (obj.value != "/") && (obj.value != "\\")) {
  sValue=parseFloat(obj.value);
  if (isNaN(sValue)) {
	alert("It should be a number between " +minCylinder +" and " +maxCylinder);
	obj.focus();
  } else {
    if (sValue < minCylinder || sValue > maxCylinder) {
		alert("Please check the value of Cylinder, it should between " +minCylinder +" and " +maxCylinder);
		obj.focus();
    }
  }
}
}

function validateAxis(obj) {
if ((obj.value != "") && (obj.value != "/") && (obj.value != "\\")) {
  sValue=parseInt(obj.value);
  if (isNaN(sValue)) {
		alert("It should be a number between 0 and 180");
       obj.focus();
  } else {

	 if (sValue < 0 || sValue > 180) {
		alert("Please check the value of Axis, it should be between 0 and 180");
		obj.focus();
	 } 
  }
}
}

function validatePD(obj) {
if (obj.value != "") {
 sValue=parseFloat(obj.value);
 if (isNaN(sValue)) {
	alert("It should be a number between 50 and 70");
    obj.focus();
 } else {
   if (sValue < 50 || sValue > 70) {
	  alert("Please check the value of PD, it should be between 50 and 70");
	  obj.focus();
   } 
 }
}
}
