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:14px; font-weight:bold ">First Name:</font> '+d1[0]+'<br>');
v.write('<font style="font-size:14px; font-weight:bold ">Last Name:</font> '+d1[1]+'<br>');
v.write('<font style="font-size:14px; font-weight:bold ">Street Address:</font> '+d1[2]+'<br>');
v.write('<font style="font-size:14px; font-weight:bold ">City:</font> '+d1[3]+'<br>');
v.write('<font style="font-size:14px; font-weight:bold ">State:</font> '+d1[4]+'<br>');
v.write('<font style="font-size:14px; font-weight:bold ">Zip Code:</font> '+d1[5]+'<br>');
v.write('<font style="font-size:14px; font-weight:bold ">Telephone:</font> ('+d1[6]+')'+d1[7]+'<br>');
v.write('<font style="font-size:14px; font-weight:bold ">Email:</font> '+d1[8]+'<br>');
v.write('<font style="font-size:14px; font-weight:bold ">Rating:</font> '+d1[9]+'<br>');
v.write('<font style="font-size:14px; font-weight:bold ">Age:</font> '+d1[10]+'<br>');
v.write('<font style="font-size:14px; font-weight:bold ">School:</font> '+d1[11]+'<br>');
v.write('<font style="font-size:14px; font-weight:bold ">T-Shirt Size:</font> '+d1[12]+'<br>');
v.write('<font style="font-size:14px; font-weight:bold ">Choosen:</font><br>');
if (document.mf1.ch1.checked)
	v.write('<font style="font-size:14px; font-weight:bold ">5 days camp<sup>*</sup></font><br>');
if (document.mf1.ch2.checked)
	v.write('<font style="font-size:14px; font-weight:bold ">Commuter lunch<sup>**</sup></font><br>');
if (document.mf1.ch3.checked)
	v.write('<font style="font-size:14px; font-weight:bold ">Residential housing and meals<sup>***</sup></font><br>');
if (document.mf1.ch4.checked)
	v.writeln('<font style="font-size:14px; font-weight:bold ">Evening activities for commuter students<sup>****</sup></font><br>');	
if (document.mf1.ch5.checked)
	v.writeln('<font style="font-size:14px; font-weight:bold ">Precare<sup>*****</sup></font><br>');
if (document.mf1.ch6.checked)
	v.writeln('<font style="font-size:14px; font-weight:bold ">Aftercare<sup>*****</sup></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 harm<br>');
v.write('less said Camp and its representatives 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('Please attached completed medical form to registration form<br>');
v.write('______________________________________________________________________________________________________</font><br>');

v.write('<sup>*</sup>SPECTACULAR 5 DAY CAMP: Mon - Thur 10 am - 4 pm and Fri 10 am - 5 pm.<br>');
v.write('TUITION: $350 before May 15; $375 after May 15; $425 at the door.<br>');
v.write('A $100 non-refundable deposit (credited to tuition) will hold a spot for you.<br>');
v.write('REGISTRATION INCLUDES: camp T-shirt, daily souvenirs, camp photo (group), trophy, autographed certificate,<br>');
v.write('and entry to a USCF tournament.<br>');
v.write('<sup>**</sup>COMMUTER LUNCH: $35/week.<br>');
v.write('<sup>***</sup>RESIDENTIAL CAMPERS: $225 additional breakfast, lunch and dinner daily, in-home hospitality in other<br>');
v.write('campers family homes in Memphis,transportation to and from camp and airport and evening chess activities.<br>');
v.write('NOTE: add $25 for supervised lodging in a nearby residential hotel.<br>');
v.write('<sup>****</sup>COMMUTER CAMPERS: $100 additional for extended activities after regular camp hours Monday - Thursday<br>');
v.write('evening 4-6:30 pm includes dinner fun chess activities, and sports.<br>');
v.write('PRECARE and AFTERCARE: precare begins at 7:30 am, aftercare (nominal fee) 4-6 pm<br>');
v.write('please call Arlene at 901-276-4663 for more info or email midsouthchess@hotmail.com<br>');


v.write('<center>Mail completed registrated and medical forms with check payale to:<br>');
v.write('Mid-South Chess, 1614 Vance Ave, Memphis, TN 38104<br>');
v.write('Questions: (901)276 4663</font></center>');

if(w.print)
	w.print();
v.close();	
}   