top.jagen_array = new Array();

top.jagen = function()
{
  	this.value = '';
  	this.controlvalue = top.generic_con;
  	this.edited = false;
  	this.allowpass = false;
  	this.firstyear_allowpass = false;
  	this.lastyear_allowpass = false;
	this.required_array = new Array();
	this.required_index = 0;
	this.verified_email = new Array();
	this.verified_email_index = 0;
}

top.email_buffer = new Array();

top.jagen_data = function(){}

top.jagen.prototype.init = function()
{
	this.index = top.jagen_array.length;
   	top.jagen_array[this.index] = '';;

	this.page_profile = 'page_jagen' + this.index;
}

top.jagen.prototype.check_how_many_email = function()
{
	this.email_array = new Array();
	this.email_private_array = new Array();
	
	this.email_number = 0;

	for(var i = 0; i < top[this.page_profile].field_index; i++)
	{
		if(top[this.page_profile].field_array[i].value == 'email')
		{
			this.email_array[this.email_number] = top[this.page_profile].field_array[i].name;
			if(top[this.page_profile].field_array[i].private_field)
			{
				top[this.page_profile].private_field = true;
				top.person.email_private_array[this.email_number] = 'P'
			}
			this.email_number++;
		}
	}
}	

top.jagen.prototype.check_how_many_phone = function()
{
	this.phone_array = new Array();
	this.phone_private_array = new Array();
	
	this.phone_number = 0;

	for(var i = 0; i < top[this.page_profile].field_index; i++)
	{
		if(top[this.page_profile].field_array[i].value == 'phone')
		{
			this.phone_array[this.phone_number] = top[this.page_profile].field_array[i].name;
			if(top[this.page_profile].field_array[i].private_field)
			{
				top[this.page_profile].private_field = true;
				top.person.phone_private_array[this.phone_number] = 'P'
			}
			this.phone_number++;
		}
	}
}	

top.jagen.prototype.check_friends = function()
{
	this.friend_number = '';

	for(var i = 0; i < top[this.page_profile].field_index; i++)
	{
		if(top[this.page_profile].field_array[i].value == 'friend')
		{
			this.friend_number = 1;
			return 1;
		}
	}
}

top.jagen.prototype.output = function()
{
	var tf = top.mainwindow.document.form1; 
   	var citem = this;
   	this.setform();
   
	if(this.email_number)
	{
		for(var i = 0 ; i <= this.email_number - 1; i++)
		{
 			email_name = 'email_' + i;
  			email_name_private = 'email_' + i + '_private';
			email_call = this.email_array[i];
			email_status = 'Please Enter Your Email Address'; 

			tf[email_name].onchange = function(){citem.check_email('',this);}
  			if(!top.loading)
			{
     				tf[email_name].onfocus = function(){top.status = email_status;};
  			}
			else
			{
     				tf[email_name].onfocus = function(){this.blur();}
  			}
			tf[email_name].onblur = function(){top.status = '';}
		
			tf[email_name_private].onclick = function() {citem.check_private(this);}
		}
	}

	if(this.phone_number)
	{
		for(var i = 0; i <= this.phone_number - 1 ; i++)
		{
			phone_name = 'phone_' + i;
			phone_call = this.phone_array[i];			
   		phone_name_private = 'phone_' + i + '_private';
			phone_status = 'Please Enter Your Phone Number';

			tf[phone_name].onchange = function(){citem.check_phone('',this);}
   		tf[phone_name].onblur = function(){top.status = '';}
  			tf[phone_name].onfocus = function(){top.status = phone_status;}
			
			tf[phone_name_private].onclick = function() {citem.check_private(this);}
		}			
	}

	if(this.homepage_number)
	{
		tf.homepage.onchange = function(){citem.check_homepage('',this);}
   	tf.homepage.onfocus = function(){top.status = 'Please Enter Your Home Page';}
   	tf.homepage.onblur = function(){top.status = '';}
  	}

	if(this.year_number != null)
	{
   		tf.firstyear.onblur = function(){top.status = '';}
   		tf.firstyear.onfocus = function(){top.status = 'Please Enter The First Year At Camp';}
   		tf.firstyear.onchange = function(){citem.check_firstyear('', this);}

   		tf.lastyear.onblur = function(){top.status = '';}
   		tf.lastyear.onfocus = function(){top.status = 'Please Enter The Last Year At Camp';}
   		tf.lastyear.onchange = function(){citem.check_lastyear('', this);}
	}
	
	if(this.season_number)
	{
		tf[top[this.page_profile].field_array[this.season_number].value].onblur = function(){top.status = '';}
		tf[top[this.page_profile].field_array[this.season_number].value].onchange = function(){citem.check_season('',this)}

		var name = top[this.page_profile].field_array[this.season_number].name;

		tf[top[this.page_profile].field_array[this.season_number].value].onfocus = function(){top.status = 'Please Enter The ' + name;}     
	}
		
	if(this.friend_number)
	{
		tf.friend.onblur = function() {top.status ='';}
		tf.friend.onfocus = function() {top.status ='Please Enter the Long Lost Friends';}
		tf.friend.onchange = function() {citem.check_friend('',this);}
			
		tf.memory.onblur = function() {top.status ='';}
		tf.memory.onfocus = function() {top.status ='Please Enter Your Fondiest Memories';}
		tf.memory.onchange = function() {citem.check_memory('',this);}
	}

	if(this.comment_number)
	{
		tf[top[this.page_profile].field_array[this.comment_number].value].onblur = function(){top.status = '';}
   		tf[top[this.page_profile].field_array[this.comment_number].value].onfocus = function(){top.status = 'Please Enter Your Comments/Remarks';}
   		tf[top[this.page_profile].field_array[this.comment_number].value].onchange = function(){citem.check_comment();}
	}

	if(this.customtext1_number)
	{
		tf[top[this.page_profile].field_array[this.customtext1_number].value].onblur = function() {top.status = '';}
		var name1 = top[this.page_profile].field_array[this.customtext1_number].name;
		
		tf[top[this.page_profile].field_array[this.customtext1_number].value].onfocus = function() {top.status = 'Please Enter Your ' + name1;}

		tf[top[this.page_profile].field_array[this.customtext1_number].value].onchange = function() {citem.check_customtext1('',this);}
	}
	
	if(this.customtext2_number)
	{
		tf[top[this.page_profile].field_array[this.customtext2_number].value].onblur = function() {top.status = '';}
		
		var name2 = top[this.page_profile].field_array[this.customtext2_number].name;
		
		tf[top[this.page_profile].field_array[this.customtext2_number].value].onfocus = function() {top.status = 'Please Enter Your ' + name2;}
		
		tf[top[this.page_profile].field_array[this.customtext2_number].value].onchange = function() {citem.check_customtext2('',this);}
	}

	if(this.customarea1_number)
	{
		tf[top[this.page_profile].field_array[this.customarea1_number].value].onblur = function() {top.status = '';}
		var name3 = top[this.page_profile].field_array[this.customarea1_number].name;
		
		tf[top[this.page_profile].field_array[this.customarea1_number].value].onfocus = function() {top.status = 'Please Enter Your ' + name3;}

		tf[top[this.page_profile].field_array[this.customarea1_number].value].onchange = function() {citem.check_customtext1('',this);}
	}
	
	if(this.customarea2_number)
	{
		tf[top[this.page_profile].field_array[this.customarea2_number].value].onblur = function() {top.status = '';}
		
		var name4 = top[this.page_profile].field_array[this.customarea2_number].name;
		
		tf[top[this.page_profile].field_array[this.customarea2_number].value].onfocus = function() {top.status = 'Please Enter Your ' + name4;}
		
		tf[top[this.page_profile].field_array[this.customarea2_number].value].onchange = function() {citem.check_customtext2('',this);}
	}
}

top.jagen.prototype.init_person = function()
{
	if(this.email_number)
	{
		for(var i = 0; i <= this.email_number - 1; i++)
		{
			top.person.email_array[i] = '';
		}
	}

	if(this.phone_number)
	{
		for(var i = 0; i <= this.phone_number - 1; i++)
      {
      	top.person.phone_array[i] = '';
      }
	}

	if(this.friend_number)
	{
		top.person.friend_array_ans[0] = '';
		top.person.friend_array_ans[1] = '';
	}
}

top.jagen.prototype.check_private = function(item)
{
	var tf = top.mainwindow.document.form1; 
	var field_name = item.name;

	var results = field_name.split(/_/g);

	var field_type = results[0];
	var field_index = results[1];
	var private_name = results[2];	

	var private_array_name = field_type + '_' + private_name + '_array';
	
	if(tf[field_name].checked)
	{
		top.person[private_array_name][field_index] = 'C';
	}
	else
	{
		top.person[private_array_name][field_index] = 'P';
	}
}

top.jagen.prototype.setform = function()
{
	var tf = top.mainwindow.document.form1; 
	
	if(this.email_number)
	{
		for(var i = 0; i <= this.email_number-1; i++)
		{
			var field_name = 'email_' + i;
			var field_private_name = 'email_' + i + '_private';
			tf[field_name].value = top.person.email_array[i];
			
			if(top.person.email_private_array[i] == 'P')
			{
				tf[field_private_name].checked = false;
			}
			else
			{
				tf[field_private_name].checked = true; 
			}
		}
	}

	if(this.homepage_number)
	{
		tf.homepage.value = top.person.homepage;
	}

	if(this.phone_number)
	{
		for(var i = 0; i <= this.phone_number-1; i++)
		{
			var field_name = 'phone_' + i;
			var field_private_name = 'phone_' + i + '_private';
			tf[field_name].value = top.person.phone_array[i];
			
			if(top.person.phone_private_array[i] == 'P')
			{
				tf[field_private_name].checked = false;
			}
			else
			{
				tf[field_private_name].checked = true; 
			}
		}
	}
   	
	if(this.year_number != null)
	{
		tf.firstyear.value = top.person.firstyear;
   		tf.lastyear.value = top.person.lastyear;
	}   
	
	if(this.season_number)
	{
		tf[top[this.page_profile].field_array[this.season_number].value].value = top.person.season;
	}
	
	if(this.comment_number)
	{
		tf[top[this.page_profile].field_array[this.comment_number].value].value = top.person.comment;
	}

	if(this.friend_number)
	{
		tf.memory.value = top.person.friend_array_ans[0];
		tf.friend.value = top.person.friend_array_ans[1];
	}
	
	if(this.customtext1_number)
	{
		tf[top[this.page_profile].field_array[this.customtext1_number].value].value = top.person.customtext1;
	}
	
	if(this.customtext2_number)
	{
		tf[top[this.page_profile].field_array[this.customtext2_number].value].value = top.person.customtext2;
	}
}

top.jagen.prototype.leave = function(towhere)
{
	top.status = '';
	tp = top.person
   var temp = '';
	
	for(var i = 0; i <= this.email_number - 1; i++)
	{
		var email_name = 'email_' + i;
		var eitem = top.mainwindow.document.form1[email_name];

		this.check_email(towhere,eitem);
	}
	
	for(var i = 0; i <= this.phone_number - 1; i++)
	{
		var phone_name = 'phone_' + i;
		var pitem = top.mainwindow.document.form1[phone_name];

		this.check_phone(towhere, pitem);
	}

	if(this.checking_email || top.loading)
	{
		top.allc = false;
		
		alert('Verifying email. Please Wait....');	
	
		return;
	}

	if(towhere == 'next')
	{
		for(var i = 0; i <= this.required_index - 1; i++)
		{
			if(this.required_array[i].match(/email/))
			{
				var results = this.required_array[i].split(/_/);
			
				var name = results[0];
				var index = results[1];
			
				if(!tp.email_array[index])	
				{
					temp += '\n' + this.email_array[index] + ' Email';		
				}
			}

			if(this.required_array[i] == 'homepage')
			{	
				if(!tp.homepage)
				{
					temp += '\nHomepage'
				}
			}

			if(this.required_array[i].match(/phone/))
			{
				var results = this.required_array[i].split(/_/);
			
				var name = results[0];
				var index = results[1];
			
				if(!tp.phone_array[index])	
				{
					temp += '\n' + this.phone_array[index] + ' Phone';		
				}
			}
		
			if(this.required_array[i] == 'year')
			{
				if(!this.firstyear_allowpass || !this.lastyear_allowpass)
	     			{
					if(!this.firstyear_allowpass)
					{
						temp += '\nFirst Year';
        				}
	
        				if(!this.lastyear_allowpass)
					{
						temp += '\nLastYear';
  					}
      				}
				else
				{
					if(top.mainwindow.document.form1.firstyear.value > top.mainwindow.document.form1.lastyear.value)
					{
						top.allc = false;
						alert('The First Year Attended Is Later Than The Last Year Attended');
					}
				}
			}

			if(this.required_array[i] == 'season')
			{
				if(!top.season)
				{
					var field_name = top[this.page_profile].field_array[this.season_number].name;
					temp += '\n' + field_name;
				}
			} 			

			if(this.required_array[i] == 'friend')
			{
				if(!top.friend_array_ans[0])
				{
					temp += '\n Favorite Camp Memories';	
				}
			
				if(!top.friend_array_ans[1])
				{
					temp += '\n Long Lost Freinds';
				}
			}
	
			if(this.required_array[i] == 'comment')
			{
				if(!top.comment)
				{
					var field_name1 = top[this.page_profile].field_array[this.comment_number].name;
				
					temp += '\n' + field_name1;	
				}
			}
		
			if(this.required_array[i] == 'customtext1')
			{
				if(!top.customtext1)
				{
					var field_name2 = top[this.page_profile].field_array[this.customtext1_number].name;
					
					temp += '\n' + field_name2;
				}
			}
	
			if(this.required_array[i] == 'customtext2')
			{
				if(!top.customtext2)
				{
					var field_name3 = top[this.page_profile].field_array[this.customtext2_number].name;
				
					temp += '\n' + field_name3;
				}
			}

			if(this.required_array[i] == 'customtarea1')
			{
				if(!top.customarea1)
				{
					var field_name4 = top[this.page_profile].field_array[this.customarea1_number].name;
				
					temp += '\n' + field_name4;
				}
			}

			if(this.required_array[i] == 'customarea2')
			{
				if(!top.customarea2)
				{
					var field_name5 = top[this.page_profile].field_array[this.customarea2_number].name;
					
					temp += '\n' + field_name5;
				}
			}
	
		}
	}	
	if(temp)
	{		
		top.allc = false;
		alert('You Need To Enter The Following Information:'+temp);
	}
}

top.jagen.prototype.preoutput = function()
{
   var header_style = '<html><head><title></title><link REL=stylesheet HREF="' + top.domain + top[this.page_profile].stylesheet + '" TYPE="text/css">';
	var header_no_style = '<html><head><title></title>';
	
   if(this.value){return;}
 	
	this.check_how_many_email();
	this.check_how_many_phone();
	this.check_friends();
	
	this.init_person();
	
	var email_number = 0;
	var phone_number = 0;
	var email_header_on = '';
	var gen_header_on  = '';

   if(!top[this.page_profile].stylesheet)
   {
        this.value += header_no_style;
   }
   else
   {
        this.value += header_style;
   }

	this.value += top.header;

	var page = this.page_profile;

	if(page.match(/0/) && !email_header_on)
	{
		this.value += top.email_header;
		email_header_on = 'true';
	}	
	if(page.match(/1/) && !gen_header_on)
	{
		this.value += top.jagen.header;
		gen_header_on = 'true';
	}	
	
	for(var i = 0; i < top[this.page_profile].field_index; i++)
	{
		if(top[this.page_profile].field_array[i].value == 'email')
		{
			var field_name =  top[this.page_profile].field_array[i].name;  	
			var field_label =   top[this.page_profile].field_array[i].value; 	
		
			var private_text = top.private_text_top + field_label + '_' + email_number + '_private' + top.private_text_bottom;

			this.value += top.email_text_top + field_name + ' Email:' + top.email_text_top_name + field_label + '_' + email_number  + top.email_text_bottom_name;

			if(top[this.page_profile].field_array[i].private_field)
			{
				this.value += private_text;
			}
			
			if(top[this.page_profile].field_array[i].required_field == 'true')
			{
				this.required_array[this.required_index] = 'email_' + email_number;
				
				this.required_index++;
			}

			email_number++;
		}
	
		if(top[this.page_profile].field_array[i].value == 'homepage')
		{
			this.homepage_number = i;
			this.value += top.homepage_text;
			
			if(top[this.page_profile].field_array[i].required_field == 'true')
			{
				this.required_array[this.required_index] = 'homepage';
				
				this.required_index++;
			}
		}

		if(top[this.page_profile].field_array[i].value == 'phone')
		{
			var field_name = top[this.page_profile].field_array[i].name;
			var field_label =  top[this.page_profile].field_array[i].value;
				
			var private_text = top.private_text_top + field_label + '_' + phone_number + '_private' + top.private_text_bottom;
			
			this.value += top.phone_text_top + field_name +' Phone:' + top.phone_text_top_name + field_label + '_' + phone_number + top.phone_text_bottom_name ;  
					
			if(top[this.page_profile].field_array[i].private_field)
			{
				this.value += private_text;
			}
				
			if(top[this.page_profile].field_array[i].required_field == 'true')
			{
				this.required_array[this.required_index] = 'phone_' + phone_number;
				
				this.required_index++;
			}

			phone_number++;
		}			

	//	this.value += top.header + top.jaedx.header;
	
		if(top[this.page_profile].field_array[i].value == 'year')
		{
			this.year_number = i;
			this.value += top.year_text;
			
			if(top[this.page_profile].field_array[i].required_field == 'true')
			{
				this.required_array[this.required_index] = 'year';
				
				this.required_index++;
			}
		}

		if(top[this.page_profile].field_array[i].value == 'season')
		{
			this.season_number = i;
			
			var field_name = top[this.page_profile].field_array[i].name;
			var field_label = top[this.page_profile].field_array[i].value;
			
			this.value += top.season_text_top + field_name + top.season_name_top + field_label + top.season_name_bottom;
			if(top[this.page_profile].field_array[i].required_field == 'true')
			{
				this.required_array[this.required_index] = 'season';
				
				this.required_index++;
			}
		}
	
		if(top[this.page_profile].field_array[i].value == 'friend')
		{
			this.value += top.memory_text;
			
			if(top[this.page_profile].field_array[i].required_field == 'true')
			{
				this.required_array[this.required_index] = 'freind';
				
				this.required_index++;
			}
		}

		if(top[this.page_profile].field_array[i].value == 'comment')
		{
			this.comment_number = i;
		
			var field_name = top[this.page_profile].field_array[i].name;
			var field_label = top[this.page_profile].field_array[i].value;

			this.value += top.comment_text_top + field_name + top.comment_name_top + field_label + top.comment_name_bottom;
			if(top[this.page_profile].field_array[i].required_field == 'true')
			{
				this.required_array[this.required_index] = 'comment';
				
				this.required_index++;
			}
		}

		if(top[this.page_profile].field_array[i].value == 'customtext1')
		{
			this.customtext1_number = i;
		
			var field_name = top[this.page_profile].field_array[i].name;
			var field_label = top[this.page_profile].field_array[i].value;
			
			this.value += top.customtext_top + field_name + top.customtext_name_top + field_label + top.customtext_name_bottom;
			
			if(top[this.page_profile].field_array[i].required_field == 'true')
			{
				this.required_array[this.required_index] = 'customtext1';
				
				this.required_index++;
			}
		}

		if(top[this.page_profile].field_array[i].value == 'customtext2')
		{
			this.customtext2_number = i;
		
			var field_name = top[this.page_profile].field_array[i].name;
			var field_label = top[this.page_profile].field_array[i].value;
			
			this.value += top.customtext_top + field_name + top.customtext_name_top + field_label + top.customtext_name_bottom;
			
			if(top[this.page_profile].field_array[i].required_field == 'true')
			{
				this.required_array[this.required_index] = 'customtext2';
				
				this.required_index++;
			}
		}

		if(top[this.page_profile].field_array[i].value == 'customarea1')
		{
			this.customarea1_number = i;
		
			var field_name = top[this.page_profile].field_array[i].name;
			var field_label = top[this.page_profile].field_array[i].value;
			
			this.value += top.customtext_top + field_name + top.customtext_name_top + field_label + top.customtext_name_bottom;
			
			if(top[this.page_profile].field_array[i].required_field == 'true')
			{
				this.required_array[this.required_index] = 'customarea1';
				
				this.required_index++;
			}
		}

		if(top[this.page_profile].field_array[i].value == 'customarea2')
		{
			this.customarea2_number = i;
		
			var field_name = top[this.page_profile].field_array[i].name;
			var field_label = top[this.page_profile].field_array[i].value;
			
			this.value += top.customtext_top + field_name + top.customtext_name_top + field_label + top.customtext_name_bottom;
			
			if(top[this.page_profile].field_array[i].required_field == 'true')
			{
				this.required_array[this.required_index] = 'customarea2';
				
				this.required_index++;
			}
		}
	}
	
	if(top[this.page_profile].private_field)
	{
		this.value += top.private_text;
	}

	this.value += top.footer;
}

top.jagen.prototype.checkphone = function(item)
{
   	if(top.leaving && top.fubar){top.allc = false;top.fubar = false; return;}
   
   	var chkstr = item.value;
   	var phone_name = item.name;
	
   	var results = phone_name.split(/_/);

   	var index = results[1];
   
   	if(!chkstr)
   	{
      		top.person.phone_array[index] = '';
      		return;
   	}
   
	if (chkstr.search(/[^-\d\(\)A-Za-z ]/) != -1)
   	{
      		item.value = top.person.phone_array[index];
      		if (navigator.appName.indexOf("Microsoft") != -1) 
      		{
         		alert('You have entered a phone number with illegal characters. It may only contain Capital Letters Numbers and ( ) or -');
      		}
		else if(!top.leaving && !top.fubar)
		{
        		alert('You have entered a phone number with illegal characters. It may only contain Capital Letters Numbers and ( ) or -');
        		item.focus();
        		top.fubar = true;
        		return 0;
      		}
      	
		top.fubar = false;
      		if(top.leaving)
      		{
        		top.allc = false;
      		}
      		return 0;
   	}
   	var result = chkstr.match(/^(1-?)?\(?([\d]{3})\)?-?([a-zA-Z\d]{3})-?([a-zA-Z\d]{4})$/);
   	if (!result)
   	{
      		if(!(confirm('You Have Entered a non US (1-111-111-1111) formatted number: ' + chkstr + ' click OK if this is correct.')))
      		{
         		item.value = top.person.phone_array[index];
         		if (navigator.appName.indexOf("Microsoft") != -1) 
         		{
         		}
			else if(!top.leaving && !top.fubar)
         		{
            			item.focus();
            			item.select();
            			top.fubar = true;
            			return 0;
         		}
         		top.fubar = false;
         		if(top.leaving)
         		{
            			top.allc = false;
         		}
         		item.focus();
         		item.select();
         		return 0;
      		}
   	}
   	else
   	{
      		item.value = '(' + result[2] + ')' + result[3] + '-' + result[4];
   	}
   	top.person.phone_array[index] = item.value;
   	return 1;
}

top.jagen.prototype.check_homepage = function(towhere,item)
{
    if(top.person.homepage != top.mainwindow.document.form1.homepage.value){this.edited = true;}
   
    return this.checkhomepage(item);
}

top.jagen.prototype.check_phone = function(towhere,item)
{
	if(this.phone_number)
	{
		var result = item.name.split(/_/);
		
		var index = result[1];

		var phone_name = item.name;
   			
		if(top.person.phone_array[index] != top.mainwindow.document.form1[phone_name].value){this.edited = true;}
		if(top.person.phone_array[index] != top.mainwindow.document.form1[phone_name].value)
		{
  			return this.checkphone(item);
		}
		else
		{
			return;
		}
	}
}

top.jagen.prototype.check_email = function(towhere,item)
{
	if(this.email_number)
	{
		var email_name = item.name;
		
		var result = email_name.split(/_/);
		
		var index = result[1];		

		if(top.person.email_array[index] != top.mainwindow.document.form1[email_name].value){this.edited = true;}
		if(top.person.email_array[index] != top.mainwindow.document.form1[email_name].value)
		{
			return this.checkemail(item);
		}
		else
		{
			return;	
		}
	}
}

top.jagen.prototype.checkemail = function(item)
{
  	if(top.leaving && top.fubar){top.allc = false;top.fubar = false; return;}
   
	var tf = top.mainwindow.document.form1;
	var email_name = item.name;
	
	var results = email_name.split(/_/);

	var index = results[1];
	
  	var chkstr = tf[email_name].value;
   
	if (!chkstr)
  	{
		top.person.email_array[index] = '';
   	tf[email_name].value = '';
     	return;
  	}
   
	if (chkstr.search(/[^\w\.\-@]+/) != -1)
   {
     	tf[email_name].value = top.person.email_array[index];
     	if (navigator.appName.indexOf("Microsoft") != -1) 
     	{
     		alert('You Entered An Email Address That Contains Inappropriate Characters. Please Try Again.');
     	}
     	else if(!top.leaving && !top.fubar)
     	{
     		alert('You Entered An Email Address That Contains Inappropriate Characters. Please Try Again.');
     		tf[email_name].focus();
     		tf[email_name].select();
     		top.fubar = true;
     		return 0;
      }
     	top.fubar = false;
     	if(top.leaving)
     	{
     		top.allc = false;
     	}
     	return 0;
   }
  	var result = chkstr.match(/^[^@]+@[^@]+\.[^@\.]{2,3}$/);
  	if (result != chkstr)
  	{
   	tf[email_name].value = top.person.email_array[index];
    	if (navigator.appName.indexOf("Microsoft") != -1) 
     	{
     		alert('You Entered A Malformed Email Address. All Email Address Look Like This "something@something.xxx". Where The xxx Suffix Is Two Or Three Characters Long, Such As com,org,uk etc..  Please Try Again.');
     	}else if(!top.leaving && !top.fubar)
     	{
     		alert('You Entered A Malformed Email Address. All Email Address Look Like This "something@something.xxx". Where The xxx Suffix Is Two Or Three Characters Long, Such As com,org,uk etc..  Please Try Again.');
     		tf[email_name].focus();
     		tf[email_name].select();
     		top.fubar = true;
     	 	return 0;
     	}
     	top.fubar = false;
     	if(top.leaving)
      {
     		top.allc = false;
     	}
     	tf[email_name].focus();
     	tf[email_name].select();
     	return 0;
  	}
   	
	if (top.person.email_array[index] != chkstr) 
	{
		this.testdomain(item,index);
	}
}

top.jagen.prototype.checkhomepage = function(item)
{
   	if(top.leaving && top.fubar){top.allc = false;top.fubar = false; return;}
   	var chkstr = item.value;
 
   	if(!chkstr)
   	{
      		top.person.homepage = '';
      		return;
   	}
  
   	var url = /(\w+):\/\/([\w.]+)\/(\S*)/;
   	var results = chkstr.match(url);
   	var url1 = /www.(.+)(\S*)/;
   	var results1 = chkstr.match(url1);
	
   	if(!results)
   	{
			if(!results1)
      	{		
				if(!(confirm('You Have Entered A Non-Standard URL (http://www.domain.com): ' + chkstr + '\n click OK if this is correct.')))
      		{
         		item.value = top.person.homepage;
         		if (navigator.appName.indexOf("Microsoft") != -1)
         		{
         		}
	 				else if(!top.leaving && !top.fubar)
         		{
            			item.focus();
            			item.select();
            			top.fubar = true;
            			return 0;
         		}
         
					top.fubar = false;
         		if(top.leaving)
         		{
            			top.allc = false;
         		}
         		item.focus();
         		item.select();
         		return 0;
      		}
   		}
		}
   	top.person.homepage = item.value;
   	return 1;
}

top.jagen.prototype.testdomain = function(item,arr_index)
{
	if(top.loading)
	{
		top.email_buffer[top.email_buffer.length] = {'item':item,'index':arr_index};	
		return;
	}

   var verified = false;
   var domain_name = item.value.match(/@(.+)$/);

   for(var i = 0; i <= this.verified_email_index ; i++)
   {
      var email = item.value;
   
      if(domain_name[1] == this.verified_email[i]) 
		{ 
         verified = true;
      }
   }

	if(verified)
	{
		this.goodemail(item.value, arr_index);
		return;
	}

 	var tf = top.mainwindow.document.form1;
  	var html = '<html><body bgcolor="#FFFFFF"><form name="form3" target="buffer" action="/perl/alumni_database.cgi/islandlake" method="post"><input type="hidden" name="index" value=""><input type="hidden" name="page" value=""><input type="hidden" name="actiontype" value="checkemail"><input type="hidden" name="arr_index" value=""><input type="hidden" name="email" value=""></form></body></html>';
  	top.buffer.document.open();
  	top.buffer.document.write(html);
  	top.buffer.document.close();
  	top.buffer.document.form3.email.value = item.value;
  	top.buffer.document.form3.index.value = this.index;
  	top.buffer.document.form3.arr_index.value = arr_index;
  	top.loading = true;

//very buggy remove for now
//   	this.tohandle = top.setTimeout("top.maindoc.jagen" + this.index + ".type.timeouterror();",60000);
  
  	var email_name = "email_" + arr_index;

  	tf[email_name].onfocus = function(){this.blur();}
  	this.allowpass = true;
  	top.buffer.document.form3.submit();
}

top.jagen.prototype.timeouterror = function()
{
   	if (navigator.appName.indexOf("Microsoft") != -1) 
   	{
      		top.buffer.location = "/cgi-bin/html/empty.html";
   	}
   	else
   	{
      		top.stop();
   	}
   	alert('In attempting to submit your application there was a network error. Please check your network connection and try again.');
   	top.loading = false;
}


top.jagen.prototype.bademail = function(email,arr_index)
{
   	top.loading = false;
   	var tf = top.mainwindow.document.form1;
   	var email_name = "email_" + arr_index;
   
   	if(tf[email_name])
   	{
      		tf[email_name].onfocus = function(){top.status = 'Please Enter Your Email Address';}
      		tf[email_name].value = top.person.email_array[arr_index];
   	}
   
//   	top.clearTimeout(this.tohandle);
    
   	if(top.person.email_array[arr_index])
   	{
      		alert('After testing the email you entered we found that it does not have a valid domain. Therefore it was reverted to the previously good email address. If the previous email is not acceptable please enter a new one.');
   	}
   	else
   	{
 		alert('After testing the email you entered we found that it does not have a valid domain. Please check it and enter it again');
      		this.allowpass = false;
   	}

	this.checking_email = false;

   if(top.email_buffer.length){
      var item = top.email_buffer[top.email_buffer.length-1];
      top.email_buffer.length = top.email_buffer.length - 1;
      this.testdomain(item.item,item.index);
   }
}

top.jagen.prototype.goodemail = function(email,arr_index) {

	var domain_name = email.match(/@(.+)$/);

	this.verified_email[this.verified_email_index] = domain_name[1];
	this.verified_email_index++;

	this.allowpass = true;
   top.loading = false;
   var tf = top.mainwindow.document.form1;
  	var email_name = "email_" + arr_index;
   
	if(tf[email_name])
   {
     		tf[email_name].onfocus = function(){top.status = 'Please Enter Your Email Address';}
   }
   	
	top.person.email_array[arr_index] = email;
   	
//	top.clearTimeout(this.tohandle);

	this.checking_email = false;

	if(top.email_buffer.length){
		var item = top.email_buffer[top.email_buffer.length-1];
		top.email_buffer.length = top.email_buffer.length - 1;
		this.testdomain(item.item,item.index);
	}
}


top.jagen.prototype.check_firstyear= function(towhere, item)
{
	if(top.person.firstyear != top.mainwindow.document.form1.firstyear.value){this.edited = true;}

	return this.checkyear(item);
}


top.jagen.prototype.check_lastyear = function(towhere, item)
{
	if(top.person.lastyear != top.mainwindow.document.form1.lastyear.value){this.edited = true;}
	
        return this.checkyear(item);
}

top.jagen.prototype.checkyear = function(item)
{
   	if(top.leaving && top.fubar){top.allc = false;top.fubar = false; return;}

   	var chkstr = item.value;
   
   	if(!chkstr)
   	{
   		var name = item.name + '_allowpass';

   		this[name] = false;

   		top.person[item.name] = item.value;
		
      		return;
   	}

   	if(chkstr.search(/[^\d\(\)A-Za-z ]/) != -1)
   	{
      		item.value = top.person[item.name];
      		if (navigator.appName.indexOf("Microsoft") != -1) 
      		{
         		alert('You have entered a Year  with illegal characters. It may only contain Numbers');
      		}
		else if(!top.leaving && !top.fubar)
      		{
         		alert('You have entered a Year  with illegal characters. It may only contain Numbers');
         		item.focus();
         		top.fubar = true;
         		return 0;
      		}
      		top.fubar = false;
      		if(top.leaving)
      		{
         		top.allc = false;
      		}
      		return 0;
   	}

  	var result = chkstr.match(/([1][89]|[2][0])(\d{2})/);
   	if(!result)
   	{
       		alert('Please enter a valid year with four digits (ie 1999). ');
       		item.value = top.person[item.name];
       		if (navigator.appName.indexOf("Microsoft") != -1)
       		{
       		}
		else if(!top.leaving && !top.fubar)
       		{
          		item.focus();
          		item.select();
          		top.fubar = true;
          		return 0;
       		}
       		top.fubar = false;
       		if(top.leaving)
      	 	{
          		top.allc = false;
       		}
       		item.focus();
       		item.select();
       		return 0;
   	}
   	else
   	{
       		item.value = result[1]+result[2];
   	}
 
   	var name = item.name + '_allowpass';

   	this[name] = true;
   	top.person[item.name] = item.value;
}


top.jagen.prototype.check_memory = function(towhere,item)
{
   	if(top.person.friend_array_ans[0] != top.mainwindow.document.form1.memory.value){ this.edited=true;}
   
   	if(top.mainwindow.document.form1.memory.value.length > 500)
   	{
      		top.person.friend_array_ans[0] = top.mainwindow.document.form1.memory.value.substring(0,500);
      		alert('The maximum length of the your Camp Memories field is 500 characters,and you supplied a longer list. As Such it was truncated to the 250 character limit. Please change the content to an appropriate format for this limit.');
      		top.mainwindow.document.form1.memory.value = top.person.friend_array_ans[0];
      		top.mainwindow.document.form1.memory.focus();
      		if(top.leaving)
      		{
         		top.allc = false;
      		}
      		return 0;
   	}
	else
	{
   		top.person.friend_array_ans[0] = top.mainwindow.document.form1.memory.value;
   	}
	
	return 1;
}

top.jagen.prototype.check_friend = function(towhere,item)
{
   	if(top.person.friend_array_ans[1] != top.mainwindow.document.form1.friend.value){this.edited = true;}
   
 	if(top.mainwindow.document.form1.friend.value.length > 250)
   	{
      		top.person.friend_array_ans[1] = top.mainwindow.document.form1.friend.value.substring(0,250);
     		alert('The maximum length of the your Long Lost Friends field is 250 characters,and you supplied a longer list. As Such it was truncated to the 250 character limit. Please change the content to an appropriate format for this limit.');
      		top.mainwindow.document.form1.friend.value = top.person.friend_array_ans[1];
      		top.mainwindow.document.form1.friend.focus();
      		if(top.leaving)
      		{
        		top.allc = false;
      		}
      		return;
   	}
	else
	{
		top.person.friend_array_ans[1] = top.mainwindow.document.form1.friend.value;
	}		
	
	return 1;
}

top.jagen.prototype.check_season = function(towhere,item)
{
	var field_name = top[this.page_profile].field_array[this.season_number].value;
	
	if(top.person.season != top.mainwindow.document.form1[field_name].value){this.edited = true;}
	
	top.person.season = top.mainwindow.document.form1[field_name].value;
}

top.jagen.prototype.check_customtext1 = function(towhere,item)
{
	var field_name = top[this.page_profile].field_array[this.customtext1_number].value;

	if(top.person.customtext1 != top.mainwindow.document.form1[field_name].value){this.edited = true;}
	
	top.person.customtext1 = top.mainwindow.document.form1[field_name].value;
}


top.jagen.prototype.check_customtext2 = function(towhere,item)
{
	var field_name = top[this.page_profile].field_array[this.customtext2_number].value;
	
	if(top.person.customtext2 != top.mainwindow.document.form1[field_name].value){this.edited = true;}
	
	top.person.customtext2 = top.mainwindow.document.form1[field_name].value;
}

top.jagen.prototype.check_comment = function(towhere,item)
{
	var field_name = top[this.page_profile].field_array[this.comment_number].value;
   	
	if(top.person.comment != top.mainwindow.document.form1[field_name].value){this.edited = true;}
   	
	if(top.mainwindow.document.form1[field_name].value.length > 250)
   	{
      		top.person.comment = top.mainwindow.document.form1[field_name].value.substring(0,250);
      		
		alert('The maximum length of the your Comment/Remarks field is 250 characters,and you supplied a longer comment. As Such it was truncated to the 250 character limit. Please change the content to an appropriate format for this limit.');
      		
		top.mainwindow.document.form1[field_name].value = top.person.comment;
      		
		top.mainwindow.document.form1[field_name].focus();
      		if(top.leaving)
      		{
         		top.allc = false;
      		}
      		return;
   	}
	else
	{
		top.person.comment = top.mainwindow.document.form1[field_name].value;
	}
	return 1;
}


top.jagen.prototype.gethiddens = function()
{
  	var html = '';
	var email_number = 0;
	var phone_number = 0;
	var page_name = 'jagen_' + this.index;

	for(var i = 0; i <= top[this.page_profile].field_index-1; i++)
	{
		if(top[this.page_profile].field_array[i].value == 'email')
		{
			if(top.person.email_array[email_number])
			{
				var field_label =   top[this.page_profile].field_array[i].value; 	
	
				html += '<input type="hidden" name="' + page_name + '_' + field_label + '_' + email_number + '_description" value="">\n';
				html += '<input type="hidden" name="' + page_name + '_' + field_label + '_' + email_number + '_email" value="">\n';
			
				html += '<input type="hidden" name="' + page_name + '_' + field_label + '_' + email_number + '_privacy" value="">\n';
			}
			email_number++;
		}
	
		if(top[this.page_profile].field_array[i].value == 'homepage')
		{
			if(tp.homepage)
			{
				html += '<input type="hidden" name="' + page_name + '_homepage" value="">\n';
			}
		}

		if(top[this.page_profile].field_array[i].value == 'phone')
		{
			if(top.person.phone_array[phone_number])
			{
				var field_label =   top[this.page_profile].field_array[i].value; 	
	
				html += '<input type="hidden" name="' + page_name + '_' + field_label + '_' + phone_number + '_phone_number" value="">\n';
				html += '<input type="hidden" name="' + page_name + '_' + field_label + '_' + phone_number + '_description" value="">\n';
		
				html += '<input type="hidden" name="' + page_name + '_' + field_label + '_' + phone_number + '_privacy" value="">\n';
			}
			phone_number++;
		}			
	
		if(top[this.page_profile].field_array[i].value == 'year')
		{
			html += '<input type="hidden" name="' + page_name + '_first_year" value="">\n';
   		html += '<input type="hidden" name="' + page_name + '_last_year" value="">\n';
		}

		if(top[this.page_profile].field_array[i].value == 'season')
		{
			html += '<input type="hidden" name="' + page_name + '_season" value="">\n';
		}
	
		if(top[this.page_profile].field_array[i].value == 'friend')
		{
			html += '<input type="hidden" name="' + page_name + '_friend" value="">\n';
			html += '<input type="hidden" name="' + page_name + '_memory" value="">\n';
		}

		if(top[this.page_profile].field_array[i].value == 'comment')
		{
			html += '<input type="hidden" name="' + page_name + '_comments" value="">\n';
		}

		if(top[this.page_profile].field_array[i].value == 'customtext1')
		{
			html += '<input type="hidden" name="' + page_name + '_customtext1" value="">\n';
		}

		if(top[this.page_profile].field_array[i].value == 'customtext2')
		{
			html += '<input type="hidden" name="' + page_name + '_customtext2" value="">\n';
		}

		if(top[this.page_profile].field_array[i].value == 'customarea1')
		{
			html += '<input type="hidden" name="' + page_name + '_customarea1" value="">\n';
		}

		if(top[this.page_profile].field_array[i].value == 'customarea2')
		{
			html += '<input type="hidden" name="' + page_name + '_customarea2" value="">\n';
		}
	}
	return html;
}

top.jagen.prototype.sethiddens = function()
{
	var email_number = 0;
	var phone_number = 0;
  	var tp = top.person;
	var tf = top.mainwindow.document.form1;
	var page_name = 'jagen_' + this.index;
	
	for(var i = 0; i <= top[this.page_profile].field_index-1; i++)
	{
		if(top[this.page_profile].field_array[i].value == 'email')
		{
			if(top.person.email_array[email_number])
			{
				var field_label =   top[this.page_profile].field_array[i].value; 	
			
				tf[page_name + '_' + field_label + '_' + email_number + '_email'].value = tp.email_array[email_number];
				tf[page_name + '_' + field_label + '_' + email_number + '_privacy'].value = tp.email_private_array[email_number];
				tf[page_name + '_' + field_label + '_' + email_number + '_description'].value = this.email_array[email_number];
			}	
			email_number++;
		}
	
		if(top[this.page_profile].field_array[i].value == 'homepage')
		{
			if(tp.homepage)
			{
				tf[page_name + '_homepage'].value = tp.homepage;
			}
		}

		if(top[this.page_profile].field_array[i].value == 'phone')
		{	
			if(top.person.phone_array[phone_number])
			{
				var field_label =   top[this.page_profile].field_array[i].value; 	
			
				tf[page_name + '_' + field_label + '_' + phone_number + '_phone_number'].value = tp.phone_array[phone_number];
				tf[page_name + '_' + field_label + '_' + phone_number + '_privacy'].value = tp.phone_private_array[phone_number];
				tf[page_name + '_' + field_label + '_' + phone_number + '_description'].value = this.phone_array[phone_number];
			}
			phone_number++;
		}			
	
		if(top[this.page_profile].field_array[i].value == 'year')
		{
			tf[page_name + '_first_year'].value = tp.firstyear;
  			tf[page_name + '_last_year'].value = tp.lastyear;
		}

		if(top[this.page_profile].field_array[i].value == 'season')
		{
			tf[page_name + '_season'].value = tp.season;
		}
	
		if(top[this.page_profile].field_array[i].value == 'friend')
		{
			tf[page_name + '_memory'].value = tp.friend_array_ans[0];
   		tf[page_name + '_friend'].value = tp.friend_array_ans[1];
		}

		if(top[this.page_profile].field_array[i].value == 'comment')
		{
			tf[page_name + '_comments'].value = tp.comment;
		}

		if(top[this.page_profile].field_array[i].value == 'customtext1')
		{
			tf[page_name + '_customtext1'].value = tp.customtext1;
		}

		if(top[this.page_profile].field_array[i].value == 'customtext2')
		{
			tf[page_name + '_customtext2'].value = tp.cutomtext2;
		}

		if(top[this.page_profile].field_array[i].value == 'customarea1')
		{
			tf[page_name + '_customarea1'].value = tp.cutomtext2;
		}

		if(top[this.page_profile].field_array[i].value == 'customarea2')
		{
			tf[page_name + '_customarea2'].value = tp.cutomtext2;
		}
	}
}	

