// Version 2.0 - includes date functions

function closewindow(){
    
    window.opener.location=window.opener.location;
    window.close(); }
    

function openServiceWindow(serviceURL) 
	{
	serviceWindow = window.open(serviceURL, "", "scrollbars,resizable,height=360,width=640")
	}

function BBLogin() 
	{
	BBWindow = window.open("", "BBWindow", "scrollbars,resizable,height=360,width=620");
	}

function openBBWindow(serviceURL) 
	{
	BBwindow = window.open(serviceURL, "", "scrollbars,resizable,height=360,width=620")
	}


// - - - - - - - - - - - - - - - - - - - -
//CheckField Function Start -
// - - - - - - - - - - - - - - - - - - - - 
function CheckField( ValidString, FieldName, FailMessage, MinAvail, MinMessage ) {
//function checks for valid field entries....
  
    var allValid;
	
	allValid = true

	if ( FieldName.value.length < MinAvail ) {
			alert( MinMessage );
			return( false );
			}
	

//now check for valid characters in the field
  for ( i = 0;  i < FieldName.value.length;  i++ ) {
    ch = FieldName.value.charAt(i);
		for ( j = 0;  j < ValidString.length;  j++ ) {
      if ( ch == ValidString.charAt(j) ) {
				break;
      }
			if ( j == (ValidString.length - 1 ) ) {
        allValid = false;
        break;
			}
		}
	}	
	if ( !allValid ) {
	                      alert( FailMessage );
		                  return ( false );
		             }
                          else {return( true );	}
}

// - - - - - - - - - - - - - - - - - - -
//CheckField Function End -
// - - - - - - - - - - - - - - - - - - - 


// - - - - - - - - - - - - - - - - - - - -
//CheckEmail Function Start -
// - - - - - - - - - - - - - - - - - - - -
function CheckEmail( EmailFieldValue ) {
  if ( ( EmailFieldValue == '' ) || ( EmailFieldValue == ' ' ) ) {
		alert( "Please enter your e-mail address." );
		return( false );
	}

	var a=0
	var NewLen = EmailFieldValue.length;

//check for spaces in email addresses

for ( a = 0;  a < NewLen;  a++ ) {
   ch = EmailFieldValue.charAt(a);
	if ( ch == " " ) {
		alert("E-mail addresses shouldn't have any spaces in them. \nTry it like this: myname@myplace.com" );
		return ( false );
	}
}	

   a=0;


	while ( ( a < NewLen ) && ( EmailFieldValue.charAt(a) != "@" ) ) {
		a++
	}
	if ( ( a >= NewLen ) || ( EmailFieldValue.charAt(a) != "@" ) ) {
		alert("We're having a problem with that email address. Try again.");
		return( false );	
	}
	else {
		a=a+2
	}
	while ( ( NewLen > a ) && ( EmailFieldValue.charAt(a) != "." ) ) {
		if ( EmailFieldValue.charAt(a) == "@" ) {
			alert("We're having a problem with that email address. Try again.");
			return(false);
		}
	a++
	}

	if( ( a >= NewLen -1 ) || ( EmailFieldValue.charAt(a) != "." ) ) {
		alert("We're having a problem with that email address. Try again.");
		return( false );
	} 
	else {
		return( true ); 
	}
}
// - - - - - - - - - - - - - - - - - - - -
//CheckEmail Function End -
// - - - - - - - - - - - - - - - - - - - -


function CheckPickList(theField,strFieldDescript){

if(theField.options[theField.selectedIndex].text.length>=1) 
  { return(true);}
  else{
   alert(strFieldDescript + ' is a required field.');
   return(false);}
}




//**********************



function checkValidChars(string1,strValid){
	var i
	for (i=0;i<=string1.length-1;i++) {
		if (strValid.search(string1.charAt(i)) == -1){
			return false;
		}
	}
	return true;
}




function checkMinLength(string1,intMinLength){
	if (string1.length <= intMinLength-1) {
		return false;
	} else {
		return true;
	}
}	

function checkMaxLength(string1,intMaxLength){
	if (string1.length >= intMaxLength+1) {
		return false;
	} else {
		return true;
	}
}	

function checkNumericRange(chkNumber,low,high){
	if ((chkNumber >= low) && (chkNumber <= high)){
		return true;
	} else {
		return false;
	}
}

//************************************

//*********** DATE FUNCTIONS **********************

function checkLeapYear(year){
	// A year which is exactly divisble by four is a leap year.
	// The exception to the rule is the first year of a century, or last year, depending on
	// how you look at it. In that case if the year is exactly divisible by 400 
	// it is also a leap year. So 2000 is a leap year, but 1900 wasn't.
	if (year%4 == 0){
		if(year%100 == 0) {		//century
			if(year%400 == 0) {
				return true;
			} else {
				return false;
			}
		}
		return true;
	} else {
		return false;
	}
}

function checkDate(month, day, year, description){

	switch(month) 
	{
		case '04':

			if (!checkNumericRange(day,1,30)){ 
				alert('The day part of ' + description + ' must be between 1 and 30.\n30 days in April') 
				return false; 
			}
			break;
		case '06':

			if (!checkNumericRange(day,1,30)){ 
				alert('The day part of ' + description + ' must be between 1 and 30.\n30 days in June') 
				return false; 
			}
			break;
		case '09':
	
			if (!checkNumericRange(day,1,30)){ 
				alert('The day part of ' + description + ' must be between 1 and 30.\n30 days in September') 
				return false; 
			}
			break;
		case '11':

			if (!checkNumericRange(day,1,30)){ 
				alert('The day part of ' + description + ' must be between 1 and 30.\n30 days in November') 
				return false; 
			}
			break;

		case '02':

			if (!checkNumericRange(day,1,29))
			    { 
				alert('The day part of ' + description + ' must be between 1 and 28.\n28 days in February (29 in a leap year).') 
				return false; 
				}
				
			if (day == '29') 
			    { 
				if (!checkLeapYear(year))
				    { 
					alert(year + ' is not a leap year.\n Febraury 29 is only valid in a leap year.') 
					return false; 
  				    }
			    }
     }
return(true);
}

//********** END DATE FUNCTIONS **************