// initial load in variables
top.shkey = new Array();
top.shvalue = new Array();
top.srhkey = new Array();
top.srhvalue = new Array();
top.exhkey = new Array();
top.exhvalue = new Array();
top.edhkey = new Array();
top.edhvalue = new Array();
var fubar = false;
top.currentapp = 0;
var stillloading = true;
var loading = false;
var leaving = false;
var allc = true;
var theform = '<HTML><HEAD></HEAD><BODY><FORM NAME="main">';
var mainshim = new Image();
mainshim.src = '/cgibin/images/crestwood/shim.gif';
var currentadd = 0;

function pagegroup(name)
{
   this.name = name;
   this.pagecount = 0;
   this.thetpages = new Array();
   this.pageindex = 0;
}


pagegroup.prototype.addon = function (item) 
{
   this.thetpages[this.pagecount] = item.name;
   if(this.pagecount)
   {
      if(!item.previous)
      {
         item.previous = this[this.thetpages[this.pagecount - 1]].name;
      }
      this[this.thetpages[this.pagecount - 1]].next = item.name;
   }
   item.docindex = this.pagecount;
   this.pagecount++;
   this[item.name] = item;
   item.type.init();
}

pagegroup.prototype.add = function (item) 
{
   this.thetpages[this.pagecount] = item.name;
   if(this.pagecount)
   {
      if(!item.previous)
      {
         item.previous = this[this.thetpages[this.pagecount - 1]].name;
      }
   }
   item.docindex = this.pagecount;
   this.pagecount++;
   this[item.name] = item;
   item.type.init();
}

pagegroup.prototype.remove = function(itemname)
{
   var previtem = this[itemname].previous;
   var nextitem = this[itemname].next;
   if(previtem)
   {
      if(nextitem)
      {
         this[previtem].next = nextitem;
         this[nextitem].previous = previtem;
      }else
      {
         this[previtem].next = '';
      }
   }else if(nextitem)
   {
      this[nextitem].previous = '';
   }else
   {
      alert('You can not program this code to remove the only page');
   }
   this[itemname].type.remove(itemname);
}

pagegroup.prototype.insert = function(iprev,itemname){ }

function tpages(type,next,previous,active)
{
   if(next)
   {
      this.next = next;
   }else
   {
      this.next = '';
   }
   if(previous)
   {
      this.previous = previous;
   }else
   {
      this.previous = '';
   }
   
   this.name = type + top[type + '_array'].length;

   this.typename = type;

   this.type = new top[type]();
   if(!active || active == 'y')
   {
      this.active = true;
   }else
   {
      this.active = false;
   }
}

tpages.prototype.output = function()
{
   if(this.type.preoutput)
   {
      this.type.preoutput(this);
   }
   var dm = top.mainwindow.document;
   dm.open();
   dm.write(this.type.value);
   dm.close();
   controlframe = 'mainwindow';
   if(top.control)
   {
      tm = top.control.document;
      tm.open();
      tm.write(this.type.controlvalue);
      tm.close();
      controlframe = 'control';
   }
   var citem = this;
   if(this.previous)
   {
      top[controlframe].document.images['back'].onmousedown = function(){citem.leave('previous');}
      top[controlframe].document.images['back'].onmouseover = function(){citem.rollover('back','over',controlframe);}
      top[controlframe].document.images['back'].onmouseout = function(){citem.rollover('back','off',controlframe);}
   }else
   {
      top[controlframe].document.images['back'].onmousedown = function(){}
      top[controlframe].document.images['back'].src = mainshim.src;
   }
   if(this.next)
   {
      top[controlframe].document.images['next'].onmousedown = function(){citem.leave('next');}
      top[controlframe].document.images['next'].onmouseover = function(){citem.rollover('next','over',controlframe);}
      top[controlframe].document.images['next'].onmouseout = function(){citem.rollover('next','off',controlframe);}
   }else
   {
      top[controlframe].document.images['next'].onmousedown = function(){}
      top[controlframe].document.images['next'].src = mainshim.src;
   }
   this.type.output(this);

}

tpages.prototype.rollover = function(bttn,todo,theframe) 
{
  top[theframe].document.images[bttn].src = '/cgibin/images/crestwood/' + 'btn_' + bttn + '_' + todo + '.gif'; 
}

tpages.prototype.leave = function(towhere)
{
   var dm = top.mainwindow.document;
   top.leaving = true;
   for(var i = 0; i < dm.form1.length; i++)
   {
      if(this.type['check_' + dm.form1[i].name])
      {
         this.type['check_' + dm.form1[i].name](towhere,dm.form1[i]);
      }
   } 
   top.leaving = false;
   if(this.type.leave){this.type.leave(towhere);}
   if(!allc)
   {
      allc = true;
      return;
   }
   maindoc[this[towhere]].output();

}

function initframes(who)
{
   stillloading = false;
   top.maindoc[who].output();
}

top.generalerror = function(msg,who)
{
   alert(msg);
   top.loading = false;
   top.clearTimeout(top.maindoc[who].type.tohandle);
   if(top.mainwindow.document.form1.sbutton)
   {
      top.mainwindow.document.form1.sbutton.value = "Submit";
   }
}

top.session = function()
{
	this.first = '';
	this.middle = '';
	this.last = '';
	this.maiden = '';
	this.sname = '';
	this.slast = '';
	this.smiddle = '';
	this.smaiden = '';
	this.email_array = new Array();
	this.email_private_array = new Array();
	this.phone_array = new Array();
	this.phone_private_array = new Array();
	this.address_array = new Array();
	this.uscan = '';
	this.homepage = '';
	this.firstyear = '';
	this.lastyear = '';
	this.season = '';
	this.comment = '';
	this.customtext1 = '';
	this.customtext2 = '';
	this.customarea1 = '';
	this.customarra2 = '';
	this.friend_array_ans = new Array();
}

//adds a new person object which holds all the 
//values from the fields. Created by john
//For use in the Alumni database.

top.person = new top.session();

top.page_profile = function(type,header,style)
{
	this.stylesheet = style;
	this.header_src = header;
	this.type = type;
	this.field_array = new Array();
	this.field_index = 0;
	this.private_field = false;
}

page_profile.prototype.add_field = function(value,name,private_field,required_field)
{
	this.field_array[this.field_index] = new top.field(value,name,private_field,required_field);
	
	this.field_index++;
}

page_profile.prototype.find_name_index = function(value)
{
	for(i = 0; i <= this.field_index; i++)
	{
		if(this.field_array[i].value == value)
		{
			return i;
		}
	}
	return 0;
}	

top.field = function(value,name,private_field,required_field)
{
	this.value = value;
	this.name = name;
	this.private_field = private_field;
	this.required_field = required_field 
}

