
// Define vaiables used in more than one function.

var isize = 0
var regex = true ;
var regey = true ;
var newl="<br />" ;
var iname = "" ;
var ivalue= "" ;
var iyear = 0 ;
var ifyear = 0 ;
var ityear = 0 ;
var icyear = 0 ;
var ixyear = 0 ;
var isyear = 0 ;
var iryear = 0 ;
var required = false ;
var lyear = false ;
var iret = true ;
var icname = ""

//Function to check form when it is submitted for print

	function okForm(form) {

//Open new window for data output

	NewWin=window.open('','','');

// Check data fields for correct input

	var ierror = false ;

	for ( var i = 0; i < form.length; i++ ) {

// These fields are calculated, not input:

	if ( form(i).name == "Friday_Amount" ||
	form(i).name == "Registration_Fee" || form(i).name == "Total" || 
	form(i).name == "Parking_Pass" || form(i).name == "") continue;  

// Set flag for required fields


	required = false ;
	ivalue = form(i).value ;
	isize = ivalue.length ; 

	if ( form(i).name == "Class_Name" || form(i).name == "First_Name" ||
	form(i).name == "City" || form(i).name == "Address" || form(i).name == "City" ||
	form(i).name == "Class_Year" || form(i).name == "State" ) required = true ;
// icname = "START OF FOR LOOP AFTER SETTING VARIABLES " + form(i).name + " " + isize + " " + ivalue + " " + required + newl + newl ;
// NewWin.document.write(icname) ; 

//test for valid number characters here

	if ( form(i).name == "Friday_Number" ||
	form(i).name == "Registration_Number" ) {

	if (isize == 0)	{

	icname = "Enter 0 in " + form(i).name + " if you are not attending this event." + newl + newl ;
	NewWin.document.write(icname) ; 
	ierror = true; 
	continue;

	}

	regex = /^[0-9][0-9]?$/ ;

	if(regex.test(form(i).value) == false) {

	icname = "You must enter a 1 or 2 digit numeric " + form(i).name + "." + newl + newl ;
	NewWin.document.write(icname) ; 
	ierror = true; 
	continue;

	}

// Calaculate the Total

	ifyear = document.regForm.Friday_Number.value ;
	iyear = "$" + (ifyear * 45) + ".00" ;
	document.regForm.Friday_Amount.value = iyear ;

	iryear = document.regForm.Registration_Number.value ;
	iyear = "$" + (iryear *20) +".00" ;
	document.regForm.Registration_Fee.value = iyear ;

	iyear =  (ifyear * 45) + (isyear * 45) + (iryear * 20) + (icyear * 1) ;
	iyear = "$" + iyear +".00" ;		
	document.regForm.Total.value = iyear ;

//End of Calculations

	continue ;

// End of Testing for valid number characters here.

	}

// Test for valid year here.


	if ( form(i).name == "Class_Year" || regForm.Spouse_Guest_Class_Year.name == "State" ) {

	regex=/^\d{4}$/ ;
	regey=/^\d{2}$/ ;
	
		if(lyear == true && (regex.test(ivalue) == false  && regey.test(ivalue) == false ) ) {

		icname = " You must enter a number in " + form(i).name + "." + newl + newl ;
		NewWin.document.write(icname) ; 
		ierror = true; 
		continue;

		}
		
		if (ivalue >= "00" && ivalue <= "08" ) ivalue = ( 2000 + (1 * ivalue) ) ;
		if (ivalue >= "20" && ivalue <= "99" ) ivalue = ( 1900 + (1 * ivalue) ) ;
		if( ivalue < 1920 || ivalue > 2008 ) {

		icname = "The  " + form(i).name + " must be between 1920 and 2008." + newl + newl ;
		NewWin.document.write(icname) ; 
		ierror = true; 
		continue;

		}

		else {

		form(i).value = ivalue ;

		continue;


		}
// End of Testing for valid valid year.
	}

//test for valid email address here

	if ( form(i).name == "Email_Address" ) {

	ivalue = form(i).value ;
	isize = ivalue.length ;
		
// If no Email address was entered, continue

	if(isize == 0)continue ;

	regex = /^(([\-\w]+)\.?)+@(([\-\w]+)\.?)+\.[a-zA-Z]{2,4}$/;

	if(regex.test(form(i).value) == true ) continue ;

	icname = form.name + " must be a valid email address" + newl + newl ;
	NewWin.document.write(icname) ; 
	ierror = true; 
	continue;

// End of Testing for valid email address here

	}

//test for valid telephone number here

	if ( form(i).name == "Telephone_Number" ) {

	ivalue = form(i).value ;
	isize = ivalue.length ;

// If no Phone number was entered, continue		

	if(isize == 0)continue ;

	regex = /^\(?\d{3}\)?-?\s*\d{3}\s*-?\d{4}$/;
	if(regex.test(form(i).value)) continue;

	icname = "Enter a valid phone number" + newl + newl ;
	NewWin.document.write(icname) ; 
	ierror = true; 
	continue;

// End of Testing for valid telephone number here

	}

//Calculating Contribution Amount and Total

	if ( form(i).name == "Contribution" ) {

	ixyear = document.regForm.Contribution.value ;
	ityear = ixyear.replace(/\.0?0?$/, "") ;
	ixyear = ityear.replace(/\$/g, "") ;
	icyear = ixyear ;
	iyear = "$" + ixyear +".00" ;		
	document.regForm.Contribution.value = iyear ;

	iyear =  (ifyear * 45) + (isyear * 45) + (iryear * 20) + (icyear * 1) ;
	iyear = "$" + iyear +".00" ;		
	document.regForm.Total.value = iyear ;

	continue;

// End of Calclating Contribution here

	}

//test for valid zip code here

	if ( form(i).name == "Zip_Code" ) {

	regex=/^\d{5}$/; // Match for 5 numbers
		
	if ( isize == 0) {
	icname = "You must enter a " + form(i).name + newl + newl ;
	NewWin.document.write(icname) ; 
	ierror = true; 
	continue;
	}
		
	if ( regex.test(form(i).value) == false) {
	icname = form(i).name + " must contain exactly five numbers!" + newl + newl ;
	NewWin.document.write(icname) ; 
	ierror = true; 
	continue;
	}

	
// End of Testing for valid zip code here

	}

// Testing for a Alphanumeric Characters


// If field is not required and empty, continue

	if (isize == 0 && required == false) continue ;

	if ( form(i).name == "Comment" ) continue;

	regex=/^\w/ // match for upper or lowercase letters, numbers,
		     // parentheses or spaces 

	if ( regex.test(form(i).value) == false ) {

	icname = form(i).name + " must contain alphabetic characters!" + newl + newl ;
	NewWin.document.write(icname) ; 
	ierror = true; continue;

	}

	if ( form(i).value == "" && required){
	icname = "You must enter your " + form + "." + newl + newl ;
	NewWin.document.write(icname) ; 
	ierror = true; continue;
	}

	if ( form(i).name != "State" ) continue;

	regex=/^[A-Z]+$/; // match for two character capiton letters for the State variable

	if ( regex.test(form(i).value) == false || isize != 2 ) {
	icname = form(i).name + " must be two capitol letters." + newl + newl ;
	NewWin.document.write(icname) ; 
	ierror = true; continue;
	}

// End of Testing for a Alphanumeric Characters


// Enter more test here

	
}

// end of for loop

// If there is an error in the form fields, return to fix them.

	if ( ierror == true ) return false;



//Write data fields to new window

	 icname = "<h2>-------- 14th Annual Stingaree Jamboree April 26-28, 2010 --------</h2>" ;
	NewWin.document.write(icname) ;

	 icname = "-------------- Class Name: " + regForm.Class_Name.value + newl + newl ;
	NewWin.document.write(icname) ; 

	 icname = "-------------- First Name: " + regForm.First_Name.value + newl + newl ;
	NewWin.document.write(icname) ; 

	 icname = "-------------- Class Year: " + regForm.Class_Year.value + newl + newl ;
	NewWin.document.write(icname) ; 

  	 icname = "---------- Married Name: " + regForm.Married_Name.value + newl + newl ;
	NewWin.document.write(icname) ; 

	 icname = "------------------ Address: " + regForm.Address.value + newl + newl ;
	NewWin.document.write(icname) ; 

	 icname = "---------------------- City: " + regForm.City.value + newl + newl ;
	NewWin.document.write(icname) ; 

	 icname = "--------------------- State: " + regForm.State.value + newl + newl ;
	NewWin.document.write(icname) ; 

	 icname = "---------------- Zip Code: " + regForm.Zip_Code.value + newl + newl ;
	NewWin.document.write(icname) ; 

	 icname = "------------ Spouse/Guest: " + regForm.Spouse_Guest.value + newl + newl ;
	NewWin.document.write(icname) ; 

	 icname = "------------ Maiden Name: " + regForm.Maiden_Name.value + newl + newl ;
	NewWin.document.write(icname) ; 

	 icname = "Spouse Guest Class Year: " + regForm.Spouse_Guest_Class_Year.value + newl + newl ;
	NewWin.document.write(icname) ; 

	 icname = "------------ Email Address: " + regForm.Email_Address.value + newl + newl ;
	NewWin.document.write(icname) ; 

	 icname = "------------ Telephone: " + regForm.Telephone_Number.value + newl + newl ;
	NewWin.document.write(icname) ; 

	 icname = "----------- Tuesday Number: " + regForm.Friday_Number.value ;
	NewWin.document.write(icname) ; 

	 icname = " ------ Tuesday Amount: " + regForm.Friday_Amount.value + newl + newl ;
	NewWin.document.write(icname) ; 

	icname = "------ Registration Number: " + regForm.Registration_Number.value ;
	NewWin.document.write(icname) ; 

	 icname = " ----- Registration Fee: " + regForm.Registration_Fee.value + newl + newl ;
	NewWin.document.write(icname) ; 

	 icname = "----------------------------------------- Contribution: " + regForm.Contribution.value + newl + newl ;
	NewWin.document.write(icname) ; 

	 icname = "------------------------------------------------- Total: " + regForm.Total.value + newl + newl ;
	NewWin.document.write(icname) ; 

	 icname = "Comment: " + regForm.Comment.value + newl + newl ;
	NewWin.document.write(icname) ; 

	 icname = "Make checks payable to - Stingaree Jamboree and mail this page to:" + newl + newl ;
	NewWin.document.write(icname) ; 

	 icname = "2010 Stingaree Jamboree" + newl ;
	NewWin.document.write(icname) ; 

	 icname = "c/o Angel Cortina, Jr." + newl ;
	NewWin.document.write(icname) ; 

	 icname = "305 North Drive" + newl ;
	NewWin.document.write(icname) ; 


	 icname = "Islamorada, FL 33036" + newl + newl ;
	NewWin.document.write(icname) ; 


	 icname = "Thank you for attending." + newl ;
	NewWin.document.write(icname) ; 


	NewWin.document.write('<br clear="all" style="page-break-before:always" />') ;


	NewWin.document.write('<div id="header"><h1>MIAMI SENIOR HIGH STINGAREE JAMBOREE<br />April 26 - 28, 2010</h1>') ;

	NewWin.document.write('</div><div id="page1">') ;

	NewWin.document.write('<p>The 14th Annual Stingaree Jamboree will be April 26 - 28, 2010 at Holiday Inn in Lake Buena Vista, Florida.</p>') ;

	NewWin.document.write('<p>You will be able to pick up your Jamboree packets and name tags in the Jamboree Hospitality Room. The desk at the hotel will have that information available for you.</p>') ;

	NewWin.document.write('<h3>PS: Please pass this information on to any of our classmates that you are in contact with.</h3>') ;

	NewWin.document.write('<p>Rooms available first come first served as follows:<br><br>Single - Double $79.00 per night plus applicable taxes (currently 12.5%).</p>') ;

	NewWin.document.write('<p>This rate is also available for three days pre/post the main group dates.</p>') ;

	NewWin.document.write('<p>There is a daily charge for parking of $10.00 for self parking and $16.00 for valet.</p>') ;

	NewWin.document.write('<p>Reservations may be made by calling 1+800-HOLIDAY or via the internet using the provided group code.</p>') ;

	NewWin.document.write('<p>This rate is also available for three days pre/post the main group dates.</p>') ;

	NewWin.document.write('<p>Deadline for rooms is March 26, 2010.</p>') ;

	NewWin.document.write('<p>Hotel Detail:</p>') ;

	NewWin.document.write('<p>Holiday Inn - In the Walt Disney World Resort<br>1805 Hotel Plaza Blvd<br>Lake Buena Vista, FL 32830<br>Phone: 407-828-8888<br>Fax: 407-827-4623</p>') ;

	NewWin.document.write('<p>If there are any problems please contact Laura Stroemer Miller at 1-904-260-2764.</p>') ;

	NewWin.document.write('</div><br clear="all" style="page-break-before:always" /><div id="page3">') ;

	NewWin.document.write('<div id="header"><h1>MIAMI SENIOR HIGH STINGAREE JAMBOREE<br />April 26 - 28, 2010.</h1>') ;

	NewWin.document.write('<P>Monday – Registration, Hospitality Room open from 8:00AM until 11:00PM.</p>') ;

	NewWin.document.write('<p>Tuesday Hospitality Room open from 8:00AM until time for dinner.</p>') ;

	NewWin.document.write('<p>Tuesday Night – Dinner - Dance - Cash Ba.r</p>') ;

	NewWin.document.write('<p>Wednesday Depart (check out time is 11:00 AM).</p>') ;

	NewWin.document.write('<p>The Hospitality Room will available from 8:00AM until 5:00PM.</p>') ;

	NewWin.document.write('<p>The hotel will store your luggage until actual departure from the hotel.</p>') ;

	NewWin.document.write('<p>==============================================================================</p>') ;

	
	return true ; //This is just for test purposes, change to true when done.

}

// Function to Test Numeric Fields.

	function ok_Num(form) { 
		if ( iret == false ) { iret = true; return true;} 
		ivalue = form.value ;
		isize = ivalue.length ;

		required = false ;
		if ( form.name == "Class_Year") required = true ;

		lnumeric = false ;
		if ( form.name == "Friday_Number" ||
			form.name == "Registration_Number" ) lnumeric = true ;

		lyear = false ;
		if ( form.name == "Class_Year" || form.name == "Spouse_Guest_Class_Year" ) lyear = true ;

//	NewWin=window.open('','',"width=300,height=200') ;
//
//	NewWin.document.write( " lnumeric= " + lnumeric + " iname= " + iname + 
//		" form.value= " + ivalue + " regex= " + regex + newl + newl ) ;

// test the variable numeric values here ("Friday and Registration Numbers.
		
	if (lnumeric == true) {
			
	if (isize == 0)	{
		alert ("Enter 0 in " + form.name + " if you are not attending this event.") ;
		form.focus() ;
		form.select() ;
		iret = false; return false ;
	}

	regex = /^[0-9][0-9]?$/ ;

	if(regex.test(form.value) == false) {
		alert ("You must enter a 1 or 2 digit numeric " + form(i).name + ".") ;
		form.focus() ;
		form.select() ;
		iret = false; return false ;
	}

// calculate Fees and the Total 

		ifyear = document.regForm.Friday_Number.value ;
		iyear = "$" + (ifyear * 45) + ".00" ;
		document.regForm.Friday_Amount.value = iyear ;

		iryear = document.regForm.Registration_Number.value ;
		iyear = "$" + (iryear *20) +".00" ;
		document.regForm.Registration_Fee.value = iyear ;

		iyear =  (ifyear * 45) + (isyear * 45) + (iryear * 20) + (icyear * 1) ;
		iyear = "$" + iyear +".00" ;		
		document.regForm.Total.value = iyear ;

//end of calculations

		return true ;
	}
// test the 4 digit year here.

	if (required == false && isize == 0 ) return true ;

	regex=/^\d{4}$/ ;
	regey=/^\d{2}$/ ;
		
	if(lyear == true && (regex.test(ivalue) == false  && regey.test(ivalue) == false ) ) {
		alert ("You must enter a 2 or 4 digit number in " + form.name + ".") ;
		form.focus() ;
		form.select() ;
		iret = false; return false ;
	}
		
	if (lyear == true && (ivalue >= "00" && ivalue <= "08" )) ivalue = ( 2000 + (1 * ivalue) ) ;
	if (lyear == true && (ivalue >= "20" && ivalue <= "99" )) ivalue = ( 1900 + (1 * ivalue) ) ;

	if (lyear == true && (ivalue < 1920 || ivalue > 2008) ) {
		alert ("The " + form.name + " must be between 1920 and 2008.") ;
		form.focus() ;
		form.select() ;
		iret = false; return false ;
	}

	else {

		form.value = ivalue ;

		return true ;
	}
	}


// Calculating Contribution Amount and filling in form 

	function fillAmount(form) {

	ixyear =  document.regForm.Contribution.value ;
	ityear = ixyear.replace(/\.\d?\d?$/, "") ;
//	ityear = ixyear.replace(/\.00$/, "") ;
	ixyear = ityear.replace(/\$/g, "") ;
	icyear = ixyear ;
	iyear = "$" + ixyear +".00" ;		
	document.regForm.Contribution.value = iyear ;

	iyear =  (ifyear * 45) + (isyear * 45) + (iryear * 20) + (icyear * 1) ;
	iyear = "$" + iyear +".00" ;		
	document.regForm.Total.value = iyear ;

    	return true;
	}
	
// Validating Phone Numbers

	function ok_Phone(form){
		if ( iret == false ) { iret = true; return true;}
		ivalue = form.value ;
		isize = ivalue.length ;
// If no Phone number was entered, return		
	if(isize == 0)return true;

		regex = /^\(?\d{3}\)?-?\s*\d{3}\s*-?\d{4}$/;
		if(regex.test(form.value)){
			return true;
		}
		else{
			alert("Enter a valid phone number");
			form.focus();
			form.select();
			iret = false; return false;
		}
	}

// Validating Email Addresses

	function ok_Email(form){
		if ( iret == false ) { iret = true; return true;} 
		ivalue = form.value ;
		isize = ivalue.length ;
		
// If no Email address was entered, return
	if(isize == 0)return true;
		regex = /^(([\-\w]+)\.?)+@(([\-\w]+)\.?)+\.[a-zA-Z]{2,4}$/;
		if(regex.test(form.value)){
			return true;
		}
		else{
			alert(form.name + " must be a valid email address");
			form.focus();
			form.select();
            iret = false; return false;
		}
	}

// Testing for a Valid Zip Code

	function ok_Zip(form){
		if ( iret == false ) { iret = true; return true;} 
		regex=/^\d{5}$/; // Match for 5 numbers
		
		if ( form.value == ""){
			alert("You must enter a zipcode");
			form.focus();
			form.select();
			iret = false; return false;
		}
		
		if ( regex.test(form.value) == false) {
			alert(form.name + " must contain exactly five numbers!");
			form.focus();
			form.select();
			iret = false; return false;
		}
					return true;
	}


// Testing for a Alphanumeric Characters

	function okAlpha(form){
   		if ( iret == false ) { iret = true; return true;} 
		ivalue = form.value ;
		isize = ivalue.length ; 
	required = false ;

        if ( form.name == "Class_Name" || form.name == "First_Name" ||
        form.name == "Address" || form.name == "City" ||
        form.name == "State" ) required = true ;
        
// If field is not required and empty, return
        if (isize == 0 && required == false) return true ;
	regex=/^[a-zA-Z0-9()\s]+$/; // match for upper or lowercase letters, numbers,
		                            // parentheses or spaces 

		if ( regex.test(form.value) == false) {

		
			alert(form.name + " must contain alphabetic characters!");
			form.focus();
			form.select();
			iret = false; return false;
		}
		if ( form.value == "" && required){
			alert("You must enter your " + form + "." );
			form.focus();
			form.select();
			iret = false; return false;
		}
		
		if ( form.name != "State" ) return true;
		regex=/^[A-Z]+$/; // match for two character capiton letters for the State variable
		if ( regex.test(form.value) == false || isize != 2 ) {
			alert( form.name + " must be two capitol letters." );
			form.focus();
			form.select();
			iret = false; return false;
		}
		 
		return true;
	}
