function NewWindow(mypage, myname, w, h, scroll) 
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)

	if (parseInt(navigator.appVersion) >=4) { win.window.focus(); }
}

function checknum(numfieldArray,numfieldDisplayArray,form)
{
	var i = 0;
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;
	for(i=0; i<numfieldArray.length; i++)
	{
		strString = eval("form." + numfieldArray[i] + ".value")
		//  test strString consists of valid characters listed above
		for (a = 0; a < strString.length  && blnResult == true; a++)
		{
			strChar = strString.charAt(a);
			if (strValidChars.indexOf(strChar) == -1)
			{
				alert("The field " + numfieldDisplayArray[i] + " must be a numeric.");
				blnResult = false;
			}
		}
		return blnResult;
	}
}

function checkForm()
{
	//First Name required check
	if (document.Entry.FirstName.value == null || document.Entry.FirstName.value.length == 0)
	{
		alert("\nYou must provide a value for the First Name field");
		document.Entry.FirstName.focus();
		return false;
	}

	//Last Name required check
	if (document.Entry.LastName.value == null || document.Entry.LastName.value.length == 0)
	{
		alert("\nYou must provide a value for the Last Name field");
		document.Entry.LastName.focus();
		return false;
	}
	//School required check
	if (document.Entry.SchoolName.value == null || document.Entry.SchoolName.value.length == 0)
	{
		alert("\nYou must provide a value for the School field");
		document.Entry.SchoolName.focus();
		return false;
	}
	//Phone required check
	if (document.Entry.Phone.value == null || document.Entry.Phone.value.length == 0)
	{
		alert("\nYou must provide a value for the Phone field");
		document.Entry.Phone.focus();
		return false;
	}
	
	var numfieldDisplayArray = new Array("Phone");
	var numfieldArray = new Array("Phone");
	
	if (!checknum(numfieldArray,numfieldDisplayArray,document.Entry)){return false;}
		
	//check phone length
	var phone_value = document.Entry.Phone.value;
	var phone_length = document.Entry.Phone.value.length;

	var c = "";
	for (var p = 0; p < phone_length; p++)
	{
		if (phone_value[p] != '.' && phone_value[p] != '-')
		{
			c += phone_value[p];
		}
	}
	if (c.length < 7)
	{
		alert("The phone field is too short - please enter the full phone number.");
		return false;
	}
		
	function checknum(numfieldArray,numfieldDisplayArray,form)
	{
		var i = 0; 
		var strValidChars = "0123456789.-";
		var strChar;
		var blnResult = true;
		
		for(i=0; i<numfieldArray.length; i++)
		{
			strString = eval("form." + numfieldArray[i] + ".value")
		
			//  test strString consists of valid characters listed above
			for (a = 0; a < strString.length  && blnResult == true; a++)
			{
				strChar = strString.charAt(a);
				if (strValidChars.indexOf(strChar) == -1)
				{
					alert("The field " + numfieldDisplayArray[i] + " must be a numeric.");
					blnResult = false;
				}
			}
		}	
		return blnResult;
	}
	
	//email required check
	if (document.Entry.Email.value == null || document.Entry.Email.value.length == 0)
	{
		alert("\nYou must provide a value for the Email field");
		document.Entry.Email.focus();
		return false;
	}
	//email email check
	if (!e(document.Entry.Email.value))
	{
		alert("Please include a proper e-mail address, of the form id@domain.zzz or id@domain.xx.zzz.");
		document.Entry.Email.focus();
		return false;
	}
	
	//details maxlength check
	if(eval("document.Entry.details.value.length") > 500){
		message="the field Detials   can be no longer than 500 characters\nCurrent length equals "+ eval("document.Entry.details.value.length");
		alert(message);
		return false;
	}
	
	// Pressnall Dupe Stopper
	if ( typeof ( formSubmission ) == "number" )
	{
		return false;
	}
	formSubmission = 1;
	
}
function checkreq(reqfieldArray,reqfieldDisplayArray,form){ 
var i = 0;
for(i=0; i<reqfieldArray.length; i++){
	if(eval("form." + reqfieldArray[i] + ".value") == ''){
	alert("The field " + reqfieldDisplayArray[i] + " must be completed to continue.");
	eval("form." + reqfieldArray[i] + ".focus()");
	return false;
}}return true;}

function checkdate(datefieldArray,datefieldDisplayArray,form){
var i = 0;
for(i=0; i<datefieldArray.length; i++){
if(eval("form." + datefieldArray[i] + ".value") != ''&& eval("form." + datefieldArray[i] + ".value") != 'mm/dd/yyyy' ){
	var testYear = eval("form." + datefieldArray[i] + ".value.lastIndexOf('/') + 1");
	var testMonth = eval("form." + datefieldArray[i] + ".value.indexOf('/')");
	var testDay1 = eval("form." + datefieldArray[i] + ".value.indexOf('/')+1");
	var testDay2 = eval("form." + datefieldArray[i] + ".value.lastIndexOf('/')");
	var lenboy = 10;
	if(!isDate(eval("form." + datefieldArray[i] + ".value.substring(testYear,lenboy)"),
		eval("form." + datefieldArray[i] + ".value.substring(0, testMonth)"),
		eval("form." + datefieldArray[i] + ".value.substring(testDay1,testDay2)"))){
		alert("The field " + datefieldDisplayArray[i] + " must be a real date formatted like: mm/dd/yyyy");
		//alert("The date must be a real date formatted like: mm/dd/yyyy");
		eval("form." + datefieldArray[i] + ".focus()");
	return false; 
	}}}return true;}
	
	
function checknum(numfieldArray,numfieldDisplayArray,form){
	var i = 0; 
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;

for(i=0; i<numfieldArray.length; i++){
strString = eval("form." + numfieldArray[i] + ".value")

//  test strString consists of valid characters listed above
   for (i = 0; i < strString.length  && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
		 alert("The field " + numfieldDisplayArray[i] + " must be a numeric.");
         blnResult = false;
         }
      }
   return blnResult;
   }

}



function makeArray(n) {
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}

var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

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 isMonth (s)
{   
	if (s > 0 && s < 13) return true;
	return false; 
}

function isDay (s)
{   
	if (s > 0 && s < 32) return true;
	return false; 
}

function isDate (year, month, day)
{   
	// get rid of '0' in the month if there is one
	if (month.substring(0, 1) == "0")
		month = month.substring(1, 2);

	// catch invalid months and days.
    if (! isMonth(month)) return false;
	if (! isDay(day)) return false;

    // catch invalid days, except for February
    if (day > daysInMonth[month]) return false; 

    if ((month == 2) && (day > daysInFebruary(year))) return false;

    return true;
}

function validateDate(date) {

	var testMonth = date.substring(0, date.indexOf("/"));
	var testDay = date.substring(date.indexOf("/")+1, date.lastIndexOf("/"));
	var testYear = date.substring(date.lastIndexOf("/") + 1,date.length);
	
	if (!isNumber(testMonth)) {
		alert("Please enter a valid 2-digit month for all dates.");
		return false;
		}	
	if (!isNumber(testDay)) {
		alert("Please enter a valid 2-digit day for all dates.");
		return false;
		}	
	if (!isNumber(testYear) || (testYear.length < 4)) {
		alert("Please enter a valid 4-digit year for all dates.");
		return false;
		}
		
	// validate the date
	if (!isDate(testYear, testMonth, testDay)) {
		alert("A date entered is not valid.");
		return false;
		}
		
	return true;

}

// this function returns the full year for a given date
function getFullYear(d) 
{
	var y = d.getYear();
	if (y < 1000) y += 1900;
	return y;
}

// Comparing two dates -- return true if day2 >= day1
// assuming here that both date are valid
function dateCompare(day1, month1, year1, day2, month2, year2)
{
	if(month1 < 10){
		month1 = month1.substring(1,2);
	} 
	if(month2 < 10){
		month2 = month2.substring(1,2);
	} 
	
	if (parseInt(year2) > parseInt(year1)){
		return true;
	}
	
	if (parseInt(year2) == parseInt(year1))
	{
		if (parseInt(month2) > parseInt(month1)){
			return true;
		}
		if (parseInt(month2) == parseInt(month1))
		{
			if (parseInt(day2) >= parseInt(day1)){
				return true;
			} else {
				return false;
			}
		}
		if (parseInt(month2) < parseInt(month1)){
			return false;
		}
	}
	
	if (parseInt(year2) < parseInt(year1)){
		return false;
	}
		
	return true;
}

// Returns true if character c is a digit 
// (0 .. 9).
function isDigit (c)
{   
	return ((c >= "0") && (c <= "9"))
}

function isNumber(s)

{   var i;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isPhoneNumber(phoneNumber){
	// returns true for 10-digit phone number value
	// ignores all whitespace characters and standard phone delimiters:  ( ) - . 
	var ignoreChar = /[\s()-.]/g;
	var strippedNumber = phoneNumber.replace(ignoreChar,"");
	
	if (isNaN(strippedNumber)){
		return false;
	}else if (strippedNumber.length == 10){
		return true;
	}else{
		return false;
	}
}

function isZipCode(zipCode){
	// returns true for 5-digit or 9-digit zip code
	// ignores all whitespace and hyphen characters
	var ignoreChar = /[\s-]/g;
	var strippedZip = zipCode.replace(ignoreChar,"");
	
	if (isNaN(strippedZip)){
		return false;
	}else if (strippedZip.length == 5 || strippedZip.length == 9){
		return true;
	}else{
		return false;
	}
}

function HourCompare(hour1,hour2){
	//alert(hour1);
	//alert(hour1.substring(0,2) + " " + hour1.substring(3,5));
	if(hour2.substring(0,2) > hour1.substring(0,2)){
		return true;
	} else {
		return false;
	}
	
	if(hour2.substring(0,2) == hour1.substring(0,2)){
		if(hour2.substring(5,2) > hour1.substring(5,2)){
			return true;
		} else {
			return false;
		}
	}
}

function e(s) {

	rex=true;

	if (window.RegExp) 
	{st="a";ex=new RegExp(st);
		if (st.match(ex)) {
		r1=new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
		r2=new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
		b=(!r1.test(s)&&r2.test(s));
		}
		else 
		{rex=false;
		}
	} 
	else
	{	rex=false;
	}
	if(!rex) b=(s.indexOf("@")>0 && s.indexOf(".")>0 && s!="" && s!="enter e-mail");
	return (b);
}
