function numbersonly(myfield, e, dec)
{
	var key;
	var keychar;

	if (window.event)
   		key = window.event.keyCode;
		
	else if (e)
   		key = e.which;
	else
   	return true;
	
	keychar = String.fromCharCode(key);
	//test it
	//alert(keychar+", "+key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || 
    		(key==9) || (key==13) || (key==27) )
   	return true;

	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
   	return true;

	// decimal point jump
	else if (dec && (keychar == "."))
   	{
   		myfield.form.elements[dec].focus();
   		return false;
   	}
	else
   	return false;
     	
}
function submitIssue(request){
var email = document.issue_form.email.value;
var description = document.issue_form.description.value;
if (((email == null) ||(email == ""))||((description == null)||(description == ""))){

alert ("E-mail and description are mandatory fields");
}
else
{
		document.issue_form.action="../../" + request;
		document.issue_form.submit();
}
}
function searchPatient(request){
 
 var authority = document.pat_query.authority.value;
 var consent;
 var err_msg;
 var role = document.pat_query.role.value;
 
 var reason = "";
 if ((role == "Pathologist")||(role =="Technologist")){
 	reason = document.pat_query.reason.value;
 	if (reason == "0")
 	err_msg = "Please specify a reason for inquiry";
	}
 else{
 var consent_yes = document.pat_query.consent[0].checked;
 var consent_no = document.pat_query.consent[1].checked;
 if (consent_yes)
 consent = true;
 else if (consent_no){
 consent = false;
 err_msg = "You must obtain a patient consent before the search can be performed";
 }
 else if ((! consent_yes)&&(! consent_no)){
 consent =false;
 err_msg = "Please indicate that a patient consent \n has been obtained.";
 }
 }
 var health_num = document.pat_query.health_num.value;
 var surname = document.pat_query.surname.value;
 var year = document.pat_query.year.value;
 var month = document.pat_query.month.value;
 var day = document.pat_query.day.value;
 var today = new Date();
 var today_y = today.getYear(); 
 var devide_y = year / 4;
		var round_y = Math.floor(devide_y);
		var leap_y;
		if ((devide_y - round_y) > 0)
		leap_y = false;
		else
		leap_y = true;
 if ((month==4)||(month==6)||(month==9)||(month==11))
 		message = "There are only 30 days in this month";
 		else if ((month==2) && (leap_y==false))
 		message = "There are only 28 days in this month";
 		else if ((month==2)&&(leap_y==true))
 		message = "There are only 29 days in this month";
 		else
		message = "There are only 31 days in this month";
 
 if (authority == 1){
 if ((health_num!=null)&&(health_num!="")&&(surname!=null)&&(surname!="")&&(year!=null)&&(year!="")&&(month!=null)&&(month!="")&&(day!=null)&&(day!="")){
    		if ((consent)||(((role =="Pathologist")||(role == "Technologist"))&&(reason !="0"))) {
    			if (health_num.length < 10)
		   	{
		   	alert("A health number should contain 10 digits");
		   	}
		   	else{
		   	
		   		if ((year >=1900)&&(year <=today_y))
							{
								if ((month <= 12)&&(month > 0))
								{
									if ((((month==4)||(month==6)||(month==9)||(month==11))&&(day<=30))||(((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))&&(day <= 31))||((month==2)&&(day <= 29)&& (leap_y==true))||((month==2)&&(day<=28)&&(leap_y==false))) 
									{
										    document.pat_query.action = "../../" + request;
 										    document.pat_query.submit();
									}
										else
										alert(message);
								}
								else
								alert("The month value can not be less than 1 and greater than 12");
							}
							else
			alert("The year value can not be less than 1900 or greater than the current year");
		   	
		   	 			
  			}
  		}
 		else
 		{
 		alert(err_msg);
 		}
  	}
  	else
  	alert("All fields are mandatory ");
  	
 }
 ///////////////////////
 else if (authority == 2){
 var physician = document.pat_query.physician.value;
 if ((physician!=null)&&(physician!="")&&(health_num!=null)&&(health_num!="")&&(surname!=null)&&(surname!="")&&(year!=null)&&(year!="")&&(month!=null)&&(month!="")&&(day!=null)&&(day!="")){
   		if ((consent)||(((role =="Pathologist")||(role == "Technologist"))&&(reason != "0")))
   		{
   		     if (health_num.length < 10)
   		     
   		     	{
   		     	alert("A health number should contain 10 digits");
   			
 			}
 		     else{
 		     
 		   	 if ((year >=1900)&&(year <=today_y))
		    		{
		    			if ((month <= 12)&&(month > 0))
		    			{
		    				if ((((month==4)||(month==6)||(month==9)||(month==11))&&(day<=30))||(((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))&&(day <= 31))||((month==2)&&(day <= 29)&& (leap_y==true))||((month==2)&&(day<=28)&&(leap_y==false))) 
		    				{
							 //if (document.pat_query.expired.value < 1)
							 if (document.exp_form.expiry_num.value < 1)
							 alert("Sorry, you can not search patient.\nYour subscription has expired.");
							 else{ 
		    				 document.pat_query.action = "../../" + request;
						     document.pat_query.submit();
							 }
		    				}
		    				else
		    				alert(message);
		    			}
		    			else
		    			alert("The month value can not be less than 1 and greater than 12");
		    		}
		    		else
		    		alert("The year value can not be less than 1900 or greater than the current year");
		   	
 			}
 		}
		else
		{
		alert(err_msg);
		}
 	}
 	else
 	alert("All fields are mandatory ");
 }
 else alert("The user role is not identified");
 
 }
 
 function submitNav(request){
 
	if ((document.login_form.logon.value == null) || (document.login_form.logon.value == "")|| (document.login_form.password.value == null)|| (document.login_form.password.value == ""))
		{
		alert("Please enter User Account and User PIN");
		//return;
		}
		else
		{
		document.login_form.action= "/" +request;
		document.login_form.submit();
		}
	}
var exp_array = new Array();//array is filled with the 'expiry_days' values from the rset (search_patient.jsp)
	
 function showExpiry(exp_ind){
 
 var exp_ind = document.pat_query.physician.selectedIndex;
 var display_exp = document.exp_form.expiry_num.value
 
 MM_showHideLayers('expiry','','show');
 document.exp_form.expiry_num.value = exp_array[exp_ind-1];
 var display_exp = exp_array[exp_ind-1];
 document.pat_query.expired.value=exp_array[exp_ind-1];
 	if (display_exp <= 0)
 	{
 		alert("Selected provider`s account expired. Please, have your provider contact INSCYTE corporation at 1-866-645-2224");
		window.location="http://www.inscyte.org/inscyte_login.jsp";
	}
	
 }
 
 function openLogin(){
   
  MM_openBrWindow('https://www.inscyte.org:721/inscyte_login.jsp','','menubar=no,scrollbars=yes,resizable=yes,width=800,height=600');
 }
 
 function openColposcopy(){
 MM_openBrWindow('https://www.inscyte.org:721/CLP','','scrollbars=yes,resizable=yes,width=800,height=600');
 }
 
 function redirect(){
	
	var agt=navigator.userAgent.toLowerCase();
	if (navigator.userAgent.toLowerCase().indexOf("mac")!= -1){
		url=("search_patient_mac.jsp");
		window.location=url; 
		}  
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 