top.jainfo_array = new Array();

top.jainfo = function()
{
  	this.value = '' ; 
  	this.controlvalue = top.generic_con;
  	this.edited = false;
	this.required_array = new Array();
}

top.jainfo_data = function(){ }

top.jainfo.prototype.init = function()
{	
	top.person.uscan = 'Y';
  	this.index = top.jainfo_array.length;
  	top.jainfo_array[this.index] = new top.jainfo_data();
}

top.jainfo.prototype.leave = function(towhere)
{
   	top.status = '';
   	var temp = '';
   	if(towhere == 'next')
   	{
		for(var i = 0; i <= this.required_index-1; i++)
		{
			if(this.required_array[i] == 'firstname')
			{
				if(!top.person.first)
      				{
         				temp += '\nFirst Name';
      				}
      				if(!top.person.last)
      				{
         				temp += '\nLast Name';
      				}
      			}
			
			if(this.required_array[i] == 'firstmaiden')
			{
				if(!top.person.maiden)
				{
					temp += '\n' + top.page_jainfo.field_array[top.firstmaiden].name;
				}
			}

			if(this.required_array[i] == 'spouse')
			{
				if(!top.person.sname)
				{
					temp+='\nSpouse Name';
				}
				
				if(!top.person.slast)
				{
					temp+='\nSpouse Last';
				}
				
				if(!top.person.smaiden)
				{
					temp+='\nSpouse Maiden';
				}
			}
		}
		
		if(temp)
      		{
         		top.allc = false;
         		alert('You must enter the following information to continue:' + temp);
      		}
   	}
}

top.jainfo.prototype.output = function()
{
   	var tf = top.mainwindow.document.form1;
   	var citem = this;
   	this.setform();

	if(top.firstname != null)
	{
   		tf.first.onchange = function(){citem.check_first('',this);}
   		tf.first.onfocus = function(){top.status ='Please Enter Your First Name';}
   		tf.first.onblur = function(){top.status ='';}
   		tf.last.onchange = function(){citem.check_last('',this);}
   		tf.last.onfocus = function(){top.status = 'Please Enter Your Last Name';}
   		tf.last.onblur = function(){top.status = '';}
   		tf.middle.onchange = function(){citem.check_middle('',this);}
   		tf.middle.onfocus = function(){top.status = 'Please Enter Your Middle Initial';}
   		tf.middle.onblur = function(){top.status = '';}
	}
	
   	if(top.firstmaiden)
   	{
   		tf.maiden.onchange = function(){citem.check_maiden('',this);}
   		tf.maiden.onfocus = function(){top.status = 'Please Enter Your Maiden Name (if applicable)';}
   		tf.maiden.onblur = function(){top.status = '';}
   	}	

   	if(top.spouse)
   	{
   		tf.sname.onchange = function(){citem.check_sname('',this);}
   		tf.sname.onfocus = function(){top.status = 'Please Enter Your Spouse\'s First Name';}
   		tf.sname.onblur = function(){top.status = '';}
   		tf.smiddle.onchange = function(){citem.check_smiddle('',this);}
   		tf.smiddle.onfocus = function(){top.status = 'Please Enter Your Spouse\'s Middle Name';}
   		tf.smiddle.onblur = function(){top.status = '';}
   		tf.slast.onchange = function(){citem.check_slast('',this);}
   		tf.slast.onfocus = function(){top.status = 'Please Enter Your Spouse\'s Last Name';}
   		tf.slast.onblur = function(){top.status = '';}
   		tf.smaiden.onchange = function(){citem.check_smaiden('',this);}
   		tf.smaiden.onfocus = function(){top.status = 'Please Enter Your Spouse\'s Maiden Name (if applicable)';}
   		tf.smaiden.onblur = function(){top.status = '';}
   	}
 
	if(top.uscan)
	{
		tf.uscan.onclick = function(){citem.check_uscan();}
	}
}

top.jainfo.prototype.preoutput = function()
{
        var header_style = '<html><head><title></title><link REL=stylesheet HREF="' +top.domain + top.page_jainfo.stylesheet + '" TYPE="text/css">';
        var header_no_style = '<html><head><title></title>';

	if(this.value){return;}

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

	this.value += top.header;

	this.required_index = 0;
	
	for(var i = 0; i < top.page_jainfo.field_index; i++)
	{
		if(top.page_jainfo.field_array[i].value == 'firstname')
		{
			top.firstname = i;
			this.value += top.name_text;

			if(top.page_jainfo.field_array[i].required_field == 'true')
			{
				this.required_array[this.required_index] = 'firstname';
				this.required_index ++;
			}
		}

		if(top.page_jainfo.field_array[i].value == 'firstmaiden')
		{
			top.firstmaiden = i;
			this.value += top.maiden_text_top + top.page_jainfo.field_array[i].name + top.maiden_text_bottom;
			if(top.page_jainfo.field_array[i].required_field == 'true')
			{
				this.required_array[this.required_index] = 'firstmaiden';
				this.required_index ++;
			}
		}

		if(top.page_jainfo.field_array[i].value == 'spouse')
		{
			top.spouse = i;
			this.value += top.spouse_text;
			
			if(top.page_jainfo.field_array[i].required_field == 'true')
			{
				this.required_array[this.required_index] = 'spouse';
				this.required_index ++;
			}
		}

		if(top.page_jainfo.field_array[i].value == 'uscan')
		{
			top.uscan = i;
			this.value +=  top.uscan_text;
		}
	}

	this.value += top.footer;
}	

top.jainfo.prototype.setform = function()
{
   	var tf = top.mainwindow.document.form1;
	
	if(top.firstname != null)
	{
   		tf.first.value = top.person.first;
   		tf.middle.value = top.person.middle;
   		tf.last.value = top.person.last;
	}	

   	if(top.firstmaiden)
   	{
    		tf.maiden.value = top.person.maiden;
   	}
   
   	if(top.spouse)
   	{
		tf.sname.value = top.person.sname;
		tf.smiddle.value = top.person.smiddle;
   		tf.slast.value = top.person.slast;
   		tf.smaiden.value = top.person.smaiden;
   	}

	if(top.uscan)
	{
		tf.uscan.checked = top.person.uscan;
	}
}

top.jainfo.prototype.check_smiddle = function(towhere, item)
{
   if(top.person.smiddle != top.mainwindow.document.form1.smiddle.value){this.edited = true;}
   return this.checkname(item);
}

top.jainfo.prototype.checkname = function(item)
{
   if(top.leaving && top.fubar){top.allc = false;top.fubar = false; return;}
   var chkstr = item.value;
   if (chkstr.search(/[^a-zA-Z' ]+/) != -1)
   {
      item.value = top.person[item.name];
      if (navigator.appName.indexOf("Microsoft") != -1) 
      {
         alert('You Entered A Name That Contains Inappropriate Characters. Please Try Again.');
      }else if(!top.leaving && !top.fubar)
      {
         alert('You Entered A Address Name That Contains Inappropriate Characters. Please Try Again.');
         item.focus();
         top.fubar = true;
         return 0;
      }
      top.fubar = false;
      if(top.leaving)
      {
         top.allc = false;
      }
      return 0;
   }
   top.person[item.name] = item.value;
   return 1;
}

top.jainfo.prototype.check_first = function(towhere,item)
{
   if(top.person.first != top.mainwindow.document.form1.first.value){this.edited = true;}
   return this.checkname(item);
}

top.jainfo.prototype.check_middle = function(towhere,item)
{
   if(top.person.middle != top.mainwindow.document.form1.middle.value){this.edited
= true;}
   return this.checkname(item);
}

top.jainfo.prototype.check_last = function(towhere,item)
{
   if(top.person.last != top.mainwindow.document.form1.last.value){this.edited = true;}
   return this.checkname(item);
}

top.jainfo.prototype.check_maiden = function(towhere,item)
{
   if(top.person.maiden != top.mainwindow.document.form1.maiden.value){this.edited = true;}
   return this.checkname(item);
}

top.jainfo.prototype.check_sname= function(towhere,item)
{
   if(top.person.sname != top.mainwindow.document.form1.sname.value){this.edited = true;}
   return this.checkname(item);
}

top.jainfo.prototype.check_slast = function(towhere,item)
{
   if(top.person.slast != top.mainwindow.document.form1.slast.value){this.edited = true;}
   return this.checkname(item);
}

top.jainfo.prototype.check_smaiden = function(towhere,item)
{
   if(top.person.smaiden != top.mainwindow.document.form1.smaiden.value){this.edited = true;}
   return this.checkname(item);
}

top.jainfo.prototype.check_uscan = function()
{
   if(top.leaving){return;}
   var tf = top.mainwindow.document.form1;
   this.edited = true;
   if(tf.uscan.checked)
   {
      top.person.uscan = 'Y';
 //     top.jaadd_array[this.index].state = '';
 //     top.jaadd_array[this.index].country = '';
   }
   else
   {
      top.person.uscan = '';
 //     top.jaadd_array[this.index].state = '';
 //     top.jaadd_array[this.index].country = '';
   }
}


top.jainfo.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.jainfo.prototype.gethiddens = function()
{
  	var html = '';
	var page_name = 'jainfo_' + this.index;
	
	if(top.firstname != null)
  	{
		html += '<input type="hidden" name="' + page_name + '_first_name" value="">\n';
  		html += '<input type="hidden" name="' + page_name + '_middle_initial" value="">\n';
  		html += '<input type="hidden" name="' + page_name + '_last_name" value="">\n';
	}   
	
  	html += '<input type="hidden" name="' + page_name + '_contact_type" value="">\n';
  	html += '<input type="hidden" name="' + page_name + '_group" value="">\n';

  	if(top.firstmaiden)
  	{
		if(top.person.maiden)
		{
			html += '<input type="hidden" name="' + page_name + '_maiden_name" value="">\n';
  		}
	}

  	if(top.spouse)
  	{
		if(top.person.sname)
		{
 			html += '<input type="hidden" name="' + page_name + '_sfirst_name" value="">\n';
  			html += '<input type="hidden" name="' + page_name + '_smiddle_initial" value="">\n';
  			html += '<input type="hidden" name="' + page_name + '_slast_name" value="">\n';
  			html += '<input type="hidden" name="' + page_name + '_smaiden_name" value="">\n';
  		}
	}

  	return html;
}

top.jainfo.prototype.sethiddens = function()
{
	var page_name = 'jainfo_' + this.index;
  	var tf = top.mainwindow.document.form1;

	if(top.firstname != null)
	{
   		tf[page_name + '_first_name'].value = top.person.first;
   		tf[page_name + '_middle_initial'].value = top.person.middle;
   		tf[page_name + '_last_name'].value = top.person.last;
	}   
	
  	tf[page_name + '_contact_type'].value = 'Alumni Data';
  	tf[page_name + '_group'].value = 'users';

  	if(top.firstmaiden)
  	{
		if(top.person.maiden)
		{
  			tf[page_name + '_maiden_name'].value = top.person.maiden;
  		}
	}
   
  	if(top.spouse)
  	{
		if(top.person.sname)
		{
  			tf[page_name + '_sfirst_name'].value = top.person.sname;
  			tf[page_name + '_smiddle_initial'].value = top.person.smiddle;
  			tf[page_name + '_slast_name'].value = top.person.slast;
  			tf[page_name + '_smaiden_name'].value = top.person.smaiden;
 		} 
	}
}

