//
// Set the fonts and table heights to the clients screen resolution.
// The default is set for 720 height
//  
var load_css=3
if (screen.height==600)
 {(load_css=1)}
if (screen.height==768)
 {(load_css=2)}
if (screen.height==864)
 {(load_css=3)}
if (screen.height==720)
 {(load_css=4)}
if (screen.height==960)
 {(load_css=5)}
if (screen.height==1024)
 {(load_css=6)}

if (load_css == 1) document.write('<'+'link rel="stylesheet" href="includes/styles_a.css" type="text/css">'); 
if (load_css == 2) document.write('<'+'link rel="stylesheet" href="includes/styles_b.css" type="text/css">'); 
if (load_css == 3) document.write('<'+'link rel="stylesheet" href="includes/styles_c.css" type="text/css">'); 
if (load_css == 4) document.write('<'+'link rel="stylesheet" href="includes/styles_d.css" type="text/css">'); 
if (load_css == 5) document.write('<'+'link rel="stylesheet" href="includes/styles_e.css" type="text/css">'); 
if (load_css == 6) document.write('<'+'link rel="stylesheet" href="includes/styles_f.css" type="text/css">'); 
//-->

// This is to validate the inputs for the "Search by Name" selection
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true;
}

function ValidateDate(){
	var dt=document.vcSSN.txtDOB
	if (isDate(dt.value)==false){
		dt.focus()
		return false;
	}
        return true	
}

// this is for the Name Search form //
// on enter check for numbers in the name field //
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)
	{
	if (document.vcName.txtLname.value.match(/^\d+$/)!==null)
		{	
		alert('Please enter an Alpha value for Last Name entry!') 
		document.vcName.txtLname.select();
		return false;
		}
	else
		myfield.form.submit();
   		return false;
   	}
else
   return true;
}
	// the validation for the Name search inputs checks for alfa-numeric types
	// and prompts the user for corrections. 

function checkNameSearch(form) 
{
if (document.vcName.txtLname.value.match(/^\d+$/)!==null)
	{	
	alert('Please enter only Alpha values for Last Name entry!') 
	document.vcName.txtLname.select();
	return false;
	}
else
	{
	if (document.vcName.txtLname.value==0)	
		{
		alert('Please enter Last Name for this inquiry!');
		document.vcName.txtLname.select();
  		return false;
  		}
	else
		if (document.vcName.txtFname.value.match(/^\d+$/)!==null)
		{
		alert('Please enter only Alpha values for First Name entry!') 
		document.vcName.txtFname.select();
		return false;
		}
		else
			if (document.vcName.intMaxRep.value!==0)	
			{
			if (document.vcName.intMaxRep.value.match(/^\d+$/)==null)
				{
				alert('Please enter only numeric values number of records to return!') 
				document.vcName.intMaxRep.select();
				return false;
				}
			else
			document.vcName.submit()
  			}	
  	}		
}
	// this ends the validation for the Name inputs //

	// this check is for the diplomate number and forces the input
	// to be numeric. The second check is for the drop list.  
function CheckDipNumber()
{
if (document.vcNum.intCandId.value.match(/^\d+$/)==null)
	{
	alert('Please enter a Numberic value for the Diplomate Number!') 
  	document.vcNum.intCandId.select();
   	return false;
   	}
else
	if (document.vcNum.selSpclty.value=='Select')
		{
		alert('Please select a specialty from the list.')
		document.vcNum.selSpclty.focus();
		return false
		}
		else 
		document.vcNum.submit()
}

	// this checks for the proper type of alha-numeric input types
	// for the social security number inputs.
	 
function checkSSN()
{

(a=0); (b=0); (c=0);
if (document.vcSSN.intSSN.value.match(/^\d+$/)==null)
	{
	alert('Please enter a Numberic value for Social Security inquery!') 
  	document.vcSSN.intSSN.select();
   	return false;
   	}
else
 	(a=1) 
 if (document.vcSSN.txtLname.value==0)
        (b=0);  	
 else
  	(b=1);
 if (document.vcSSN.txtDOB.value!=="")	
  	{ 
  	// if there is something in the date field then see if it is a proper date
  	// if not, throw a message to the user from the ValidateDate() script
  	// if it is good, submit the form and run the query. 
  	var dt = ValidateDate()
   		if (dt==true)
    		(c=1)
  	}
 	else
        (c=0);
 	if ((a + b + c) >= 2 )
        	document.vcSSN.submit()
        else
        	alert('Please enter a Last Name or Date of Birth!');
        	document.vcSSN.txtLname.select();
	   	return false;	

}
	// this is for the search by Specialty selection.

function checkSpclty()
{
	if (document.vcLoc.selSpclty.value=='Select')
	{
	alert('Please select a specialty from the list.')
	return false
	}
	else
	document.vcLoc.submit()
}

function scrHeight(hgt)
{
var hgt=screen.height
}


