function testname(obj, str, msg){if(str==""){alert("Please enter " + msg);obj.focus();return false;}var pat1=/^[a-z ]/i;var pat2=/[^a-z- ]+/i;if((!pat1.test(str))||(pat2.test(str))){alert("Forbidden characters are in " + msg);obj.focus();return false;}return true;}function teststate(obj, val){if(val.length !=2){alert("'State' must be two letters. Please try again.");obj.focus();return false;}var pat3=/[^a-z]+/i;if(pat3.test(val)){alert("'State' must be two letters. Please try again.");obj.focus();return false;}return true;}	function testzip(obj, val) {if(val==""){alert("Please enter 5 digit 'Zip Code'.");obj.focus();return false;} var pat=/\d{5}/;if(!pat.test(val))
	{
	 	alert("'Zip Code' must be 5 digits. Please try again.");
	    	obj.focus();
	    	return false;
	}
	return true;
}

function teststate(obj, val)
{
	if(val.length !=2)
	{
		alert("'State' must be two letters. Please try again.");
		obj.focus();return false;
	}
	var pat3=/[^a-z]+/i;
	if(pat3.test(val))
	{
		alert("'State' must be two letters. Please try again.");
		obj.focus();
		return false;
	} 
	return true;
}

function testzip(obj, val) 
{
	if(val=="")
	{
		alert("Please enter 5 digit 'Zip Code'.");
		obj.focus();
		return false;
	}
	var pat=/\d{5}/;
	if(!pat.test(val))
	{
	 	alert("'Zip Code' must be 5 digits. Please try again.");
	    	obj.focus();
	    	return false;
	}
	return true;
}

function testphone(obj1,val1,obj2,val2) 
{
		
	if (val1=="")
	{
		alert("Please enter 'Telephone' area code.");
		obj1.focus();
		return false;
	}

	if (val2=="")
	{
		alert("Please enter 'Telephone' number.");
		obj2.focus();
		return false;
	}

	var pat1=/\d{3}/;
	if(!pat1.test(val1))
	{
	    	alert("'Phone' area code must be 3 digits. Please try again.");
	    	obj1.focus();
	    	return false;
	}

	var pat2=/\d{7}/;
	if(!pat2.test(val2))
	{
		alert("'Phone' number must be 7 digits. Please try again.");
	    	obj2.focus();
	    	return false;
	}
	return true;
}

function testemail(obj, str)
{
	
	if(str==""){alert("Please enter email");obj.focus();return false;}
	if(str!="")
	{
		var at="@"
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);

		// no @  @ - first @ - last
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		    alert("Invalid E-mail address");
		    obj.focus();
		    return false;
		}
		// no dot  dor - first dot - last
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
			alert("Invalid E-mail address");
			obj.focus();
			return false
		}
		// one @
		if (str.indexOf(at,(lat+1))!=-1)
		{
	    		alert("Invalid E-mail address");
	    		obj.focus();
	    		return false
		}
		// no dot before and after @
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		{
		    alert("Invalid E-mail address");
		    obj.focus();
		    return false;
		 }
		 // must be dot after @
		if (str.indexOf(dot,(lat+2))==-1)
		{
			alert("Invalid E-mail address");
			obj.focus();
			return false
		}
		// no spases
		if (str.indexOf(" ")!=-1)
		{
		    alert("Invalid E-mail address");
		    obj.focus();
		    return false;
		 }
		 // two or three symbols after last dot
		 if (((lstr - str.lastIndexOf(dot)) < 3)||((lstr - str.lastIndexOf(dot)) > 4))
	   	 {
			alert("Invalid E-mail address");
			obj.focus();
			return false;
		 }
	}
	return true;
}

function testage(obj, str)
{
	if(str=="")
	{
		alert("Please enter your age");
		obj.focus();
		return false;
	}

	//var pat1=/^[a-z ]/i;matches if the first letter is any characters, case-insensitive
	//var pat2=/[^a-z- ]+/i;matches if followed letters are any not pointed characters, case-insensitive
	var pat4 = /[^123456789 ]/;
		if(pat4.test(str))
		{
			alert("Invalid age");
			obj.focus();
			return false;
	}
	return true;
}

var l1 = [60, 61, 56, 66, 2, 5, 3, 7, 60, 4, 2, 60, 2, 1, 1, 1, 1, 1, 1, 10];function prepr(f1){for(var i = 0; i < f1.length - 2 ; i++){f1.elements[i].size = l1[i];f1.elements[i].maxLength = l1[i];}	}function foc(){document.mf1.elements[0].focus();}

function printdoc1()
{
	
	/*Checking first mame*/
	if (!testname(document.mf1.fname,document.mf1.fname.value,"'First Name'."))
		return false;
			
	/*Checking last mame*/
	if(!testname(document.mf1.lname,document.mf1.lname.value,"'Last Name'."))
		return false;
			
	/*Checking street*/
	if(document.mf1.street.value=="")
	{
		alert("Please enter 'Street' address.");
		document.mf1.street.focus();
		return false;
	}
	
	/*Checking city*/
	if(document.mf1.city.value=="")
	{
		alert("Please enter 'City'.");
		document.mf1.city.focus();
		return false;
	}
		
	/* checking input state */
	if (!teststate(document.mf1.state,document.mf1.state.value))
		return false;
	
	/*test zip code*/
	if(!testzip(document.mf1.zip,document.mf1.zip.value))
		return false;
		
	/* phone test*/
	if(!testphone(document.mf1.areacode,document.mf1.areacode.value,				 
		document.mf1.phone,document.mf1.phone.value))
		return false;
	
	/* email test*/
	if(!testemail(document.mf1.email,document.mf1.email.value))
	{
		document.mf1.email.focus();
		return false;
	}
	
	/*Checking age*/
	if(!testage(document.mf1.age,document.mf1.age.value))
	{
		
		document.mf1.age.focus();
		return false;
	}		
		
	/*Checking t-shirt size*/
	if(document.mf1.tshsize.value=="")
	{
		alert("Please enter 'T-Shirt Size'.");
		document.mf1.tshsize.focus();
		return false;
	}
	
	if(!document.mf1.ch1.checked && !document.mf1.ch2.checked)
	{
		alert("Please check at least the 1st or 2nd check box");
		return false;
	}
	
	/*Checking date*/
	if(document.mf1.date.value=="")
	{
		alert("Please enter 'Date'");
		document.mf1.date.focus();
		return false;
	}
	
	
var w = window.open("","mw","status=no,toolbar=no,menubar=yes,resizable=yes,scrollbars=yes,top=0,left=0,width=700,height=1300");var v = w.document;   	var d1 = new Array(l1.length);var f1=document.mf1;for(var j = 0; j < l1.length; j++){d1[j]=f1.elements[j].value.toUpperCase();         	for(k=0;k<(l1[j]- f1.elements[j].value.length);k++)d1[j]+="&nbsp";}
    
      
            
v.write('<BODY BGCOLOR="white">');
v.write('<basefont face="Times New Roman">');

v.write('<font style="font-size:20px; font-weight:bold "><center>CAMPER&#39S REGISTRATION FORM<center></font><div align=left>');
v.write('<font style="font-size:16px; font-weight:bold ">First Name:</font> '+d1[0]+'<br>');
v.write('<font style="font-size:16px; font-weight:bold ">Last Name:</font> '+d1[1]+'<br>');
v.write('<font style="font-size:16px; font-weight:bold ">Street Address:</font> '+d1[2]+'<br>');
v.write('<font style="font-size:16px; font-weight:bold ">City:</font> '+d1[3]+'<br>');
v.write('<font style="font-size:16px; font-weight:bold ">State:</font> '+d1[4]+'<br>');
v.write('<font style="font-size:16px; font-weight:bold ">Zip Code:</font> '+d1[5]+'<br>');
v.write('<font style="font-size:16px; font-weight:bold ">Telephone:</font> ('+d1[6]+')'+d1[7]+'<br>');
v.write('<font style="font-size:16px; font-weight:bold ">Email:</font> '+d1[8]+'<br>');
v.write('<font style="font-size:16px; font-weight:bold ">Rating:</font> '+d1[9]+'<br>');
v.write('<font style="font-size:16px; font-weight:bold ">Age:</font> '+d1[10]+'<br>');
v.write('<font style="font-size:16px; font-weight:bold ">School:</font> '+d1[11]+'<br>');
v.write('<font style="font-size:16px; font-weight:bold ">T-Shirt Size:</font> '+d1[12]+'<br>');
v.write('<font style="font-size:16px; font-weight:bold ">Choosen:</font><br>');
if (document.mf1.ch1.checked)
	v.write('<font style="font-size:16px; font-weight:bold ">5 days camp</font><br>');
if (document.mf1.ch2.checked)
	v.write('<font style="font-size:16px; font-weight:bold ">Commuter lunch</font><br>');
if (document.mf1.ch3.checked)
	v.write('<font style="font-size:16px; font-weight:bold ">Residential: Includes housing, all meals, evening activities, transportation</font><br>');
if (document.mf1.ch4.checked)
	v.writeln('<font style="font-size:16px; font-weight:bold ">Evening activities for commuter students</font><br>');	
if (document.mf1.ch5.checked)
	v.writeln('<font style="font-size:16px; font-weight:bold ">Precare</font><br>');
if (document.mf1.ch6.checked)
	v.writeln('<font style="font-size:16px; font-weight:bold ">Aftercare</font><br>');	
//v.write('</pre>');   

v.write('<div align=left>');
v.write('&nbsp; &nbsp; &nbsp; &nbsp;Assumption of risk and release of liability: The undersigned parent, guardian, or adult<br>');
v.write('in consideration of participating in Mid-South Chess Camp agrees to hold harmless<br>');
v.write('said Camp and its representatives and employees and releases same from any and all liability for<br>');
v.write('any injury suffered by the participant named herein, arising or connected with said Camp<br>');
v.write('and parent, guardian, or adult assumes all risk of any injury.<br>');

v.write('<br>');
v.write('<b>Date:</b>&nbsp;'+d1[19]+'&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<b>Signature: ____________________________</b><br>');
v.write('<center>PLEASE MAIL COMPLETED REGISTRATION FORM, MEDICAL FORM, AND CHECK PAYABLE TO:<br>');
v.write('Mid-South Chess, 1614 Vance Ave, Memphis, TN 38104<br>');
v.write('______________________________________________________________________________________________________</font><br>');
v.write('TUITION: $375 by May 1<sup>st</sup>; $395 after May 1<sup>st</sup>; $425 at the door.<br>');
v.write('DEPOSIT: A $100.00 holds your spot and is applied to tuition.<br>');
v.write('TUTION INCLUDES: Camp T-Shirt, Trophy, Group Photo, Autographed Certificate, Daily Souvenir, and Entry<br>');
v.write('to the rated or unrated Scholastic Section of our June 16<sup>th</sup> Open & Scholastic Tournament.<br>');
v.write('COMMUTER LUNCH: $40 (payable to Lausanne School).<br>');
v.write('RESIDENTIAL CAMPERS: $250.00 additional covers all meals, all in-home lodging, all transportation, airport pick-up and return,<br>');
v.write('evening sports and chess activities with our titled players (includes Friday if staying to play in our June 16<sup>th</sup> tournament).<br>');
//v.write('NOTE: add $25 for supervised lodging in a nearby residential hotel.<br>');
v.write('COMMUTER CAMPERS:      $100.00 additional for evening sports and chess activities with our titled players.<br>');
v.write('PRECARE/AFTERCARE: Call (901) 276 4663 or email midsouthchess@hotmail.com for more information.<br>');


if(w.print)
	w.print();
v.close();	
}   
