function reloadPage(init) { 
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.pgW=innerWidth; document.pgH=innerHeight; onresize=reloadPage; }}
  else if (innerWidth!=document.pgW || innerHeight!=document.pgH) location.reload();
}

reloadPage(true);

function setForm(){
	var doc = document.form1
	var list = doc.selGender
	var selectedList = list.options[list.selectedIndex].value;
	var confirmPass = doc.PASSWORD.value;
		var confirmPass1 = doc.PASSWORD1.value;
		
	
		
	if(doc.FNAME.value == '' || doc.FNAME.value == 'First'){
		alert('Please enter in your First Name');
			doc.FNAME.focus();
		return false;
	}
	if(doc.LNAME.value == '' || doc.LNAME.value == 'Last'){
		alert('Please enter in your Last Name');
			doc.LNAME.focus();
		return false;
	}

	if(doc.SelectMonth.value == ''){
				alert('Please select your Month in your Birth Date.');
			doc.SelectMonth.focus();
		return false;
	}

	if(doc.SelectDay.value == ''){
				alert('Please select your Day in your Birth Date.');
			doc.SelectDay.focus();
		return false;
	}

	if(doc.SelectYear.value == ''){
				alert('Please select your Year in your Birth Date.');
			doc.SelectYear.focus();
		return false;
	}
			
	if ((doc.SelectMonth.value==4 || doc.SelectMonth.value==6 || doc.SelectMonth.value==9 || doc.SelectMonth.value==11) && doc.SelectDay.value==31) 
		{
				alert(  "This Month doesn't have 31 days.")
				doc.SelectDay.focus();
					
			return false;
		}
				
	if (doc.SelectMonth.value == 2) 
	{ 
		var isleap = (doc.SelectYear.value % 4 == 0 && (doc.SelectYear.value % 100 != 0 || doc.SelectYear.value % 400 == 0));

		if (doc.SelectDay.value>29 || (doc.SelectDay.value==29 && !isleap)) 
		{
				alert("February " + doc.SelectYear.value + " doesn't have " + doc.SelectDay.value + " days.");
				 doc.SelectDay.focus();
		return false;
		}								
	}
	 
	if(confirmPass == '' || confirmPass1 == ''){
		alert('Please enter in your passwords.');
			doc.PASSWORD.focus();
			doc.PASSWORD.value = "";
		return false;
	}else if(confirmPass != confirmPass1){
							
			var msg = 'Your password does not match your confirmed password.\n'
					msg += 'Please Try Again.'
				alert(msg);
			doc.PASSWORD.focus();
			doc.PASSWORD.value = "";
			doc.PASSWORD1.value = "";
			return false;
		}else{
					
	}

	if(!isEmail(doc.EMAIL)) return false;
	if(!CheckPhoneNumber(doc.HPHONE.value)) return false;
	
	if(selectedList == 0){
		alert('Please make a selection for Gender.')
		doc.selGender.focus();
		return false;
	}else{
		doc.selGender.value = selectedList;
	}
	
}

function isEmail(field, msg) {
var doc = document.form1;
	var email = field.value;
	var HowManyAt = 0;
	var HowManyPer = 0;
	var LastPer;
	var LastStr;

	if (!msg)
		msg = "Please enter a valid email address. ex: username@yourprovider.com.";

	// Checks to see if "none" was entered and returns true
//	if(email.toUpperCase() == "NONE") return true

	for (var i = 0; i < email.length;  i++) {
		var thisChar = email.substring(i, i + 1);
		if (thisChar == "@") HowManyAt++
	}
	// Checks to make sure there is at least one "@" and no more.
	if (HowManyAt != 1) {
		alert(msg);
		field.focus();
		return false;
	}

	// Checks to make sure that the first character is not the "@"
	var AtIndex =  email.indexOf("@")
	if (AtIndex == 0) {
		alert(msg);
		field.focus();
		return false;
	}

	// Checks to make sure there is at least one "."
	for (var j = AtIndex; j < email.length; j++) { 
		var thisChar2 = email.substring(j, j + 1);
		if (thisChar2 == ".") {
			HowManyPer++
			LastPer = j;
		}
	}
	if (HowManyPer == 0) {
		alert(msg);
		field.focus();
		return false;
	}
	// Checks to make sure that there are only 2 or 3 digits after the last period.
	LastStr = email.substring(LastPer + 1, email.length + 1)
	if (LastStr.length != 2 && LastStr.length != 3) {
		alert(msg);
		field.focus();
		return false;
	}

	// Email is valid   
	return true;
}

function CheckPhoneNumber(TheNumber) {

	var valid = 1;
	var GoodChars = "0123456789()-+ ";
	var i = 0;
	if (TheNumber == "") {

		// Return false if number is empty
		msg = "Please enter in your Day Time Phone Number";
		alert(msg);
		valid = 0;
			document.form1.HPHONE.focus();
		return false;
	}
	for (i =0; i <= TheNumber.length -1; i++) {
		if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
			alert('Please enter numbers only for the day time phone number')
			valid = 0
			document.form1.HPHONE.focus();
			return false;
		} // End if statement
	} // End for loop
	return true;
}

function firstLoad(){
	
	document.form1.FNAME.value='First';
	document.form1.LNAME.value='Last';
	document.form1.middleinit.value='M';
//	document.login.fname.focus();

}

function ClearFields(frm,field){
	
	if (field == 'FNAME'){
		if (document[frm][field].value == 'First'){
			document[frm][field].value = '';
			document[frm].middleinit.value = '';
		}
	}else if (field == 'LNAME'){
		if (document[frm][field].value == 'Last'){
			document[frm][field].value = '';
		}
	}/*else if (field == 'PatientMI'){
		if (document.frmPrescription.PatientMI.value == 'M'){
			document.frmPrescription.PatientMI.value = '';
		}
	}*/

}

	function openBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) {
	  if(window.screen)if(isCenter)if(isCenter=="true"){
	    var myLeft = (screen.width-myWidth)/2;
	    var myTop = (screen.height-myHeight)/2;
	    features+=(features!='')?',':'';
	    features+=',left='+myLeft+',top='+myTop;
	  }
	 newWin = window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
		newWin.focus();
	}
	

function checkFile(){
	if(CheckEmpty(document.form1.photo_upload)){
		return;
	}
		document.form1.photo_upload.value = Trim(document.form1.photo_upload.value);
}

function CheckEmpty(CONTROL){

	if(Trim(CONTROL.value)==""){
		alert("Please supply some text for trimming");
		CONTROL.value="";
		CONTROL.focus();
		return true;
	}else{
		return false;
	}
}

function checkFile() {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   
   inputString = document.form1.photo_upload.value
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


function setTime(){    
    var dt = new Date(); 
    var h = dt.getHours(), m = dt.getMinutes(); 
    var s = dt.getSeconds(), ms = dt.getMilliseconds(); 
    //alert(h + ":" + m + ":" + s + "." + ms);
    document.form1.TIME.value = h + ':' + m + ':' + s + '.' + ms;
    //document.form1.TIME.value = 'Here';
	//alert(document.form1.TIME.value)    
}