function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

var locationUpdater = Class.create();

locationUpdater.prototype = {

   initialize: function() {
	   clearList(document.form1["fhscol_Region"]);
   },

   ajaxUpdate: function(ajaxResponse) {
      locationID = document.form1["fhscol_Region"].value;
	  clearList(document.form1["fhscol_Region"]);
	  for ( var i = 0 ; i < ajaxResponse.childNodes.length ; i++ ) {
         var location = ajaxResponse.childNodes[i];
		 addOption(document.form1["fhscol_Region"],location.getAttribute("region"),location.getAttribute("ID"));
		 if (location.getAttribute("ID") == locationID)
		 	document.form1["fhscol_Region"].selectedIndex = i + 1;
      }
	  
   },

   reset: function() {
      clearList(document.form1["fhscol_Region"]);
   }

};



var ageGroupUpdater = Class.create();

ageGroupUpdater.prototype = {

   initialize: function() {
	   clearList(document.form1["fhscol_AgeGroup"]);
   },

   ajaxUpdate: function(ajaxResponse) {
	  agegroupID = document.form1["fhscol_AgeGroup"].value;
      clearList(document.form1["fhscol_AgeGroup"]);
	  for ( var i = 0 ; i < ajaxResponse.childNodes.length ; i++ ) {
         var agegroup = ajaxResponse.childNodes[i];
		 addOption(document.form1["fhscol_AgeGroup"],agegroup.getAttribute("agegroup"),agegroup.getAttribute("ID"));
		 if (agegroup.getAttribute("ID") == agegroupID)
		 	document.form1["fhscol_AgeGroup"].selectedIndex = i + 1;
      }
	  
   },

   reset: function() {
      clearList(document.form1["fhscol_AgeGroup"]);
   }

};




var groupTypeUpdater = Class.create();

groupTypeUpdater.prototype = {

   initialize: function() {
	   var i = 0;
   },

   ajaxUpdate: function(ajaxResponse) {
	   
	  var gtid = 0;
	  if(document.getElementById('gtRadio') != null){
		  gtLength = document.form1["gtRadio"].length;
		  for (var i = gtLength - 1; i>0; i--){
			  if (document.form1.gtRadio[i].checked)
				gtid = document.form1.gtRadio[i].value;
			 removeGroupType(document.form1.gtRadio[i].value);
		  }
		  removeGroupType(document.form1.gtRadio.value);
	  }
	  	
	  for ( var i = 0 ; i < ajaxResponse.childNodes.length ; i++ ) {
         var grouptype = ajaxResponse.childNodes[i];
		 
		 if (grouptype.getAttribute("ID") == gtid){
		 	addGroupType(grouptype.getAttribute("ID"),grouptype.getAttribute("grouptype"),grouptype.getAttribute("description"), 1);
		 } else {
			addGroupType(grouptype.getAttribute("ID"),grouptype.getAttribute("grouptype"),grouptype.getAttribute("description"), 0);
		 }
      }
	  
   },

   reset: function() {
      var i = 0;
   }

};




var assimilatorUpdater = Class.create();

assimilatorUpdater.prototype = {

   initialize: function() {
	   var i = 0
   },

   ajaxUpdate: function(ajaxResponse) {
	  //document.form1["fhs_return_url"].value = document.form1["fhs_return_url"].value + "?";
	  //alert("here");
	  eraseCookie('assmFirstName');
	  eraseCookie('assmLastName');
	  eraseCookie('assmPhone');
	  eraseCookie('assmEmail');
	  eraseCookie('assmSpouse');
	  for ( var i = 0 ; i < ajaxResponse.childNodes.length ; i++ ) {
         var assimilator = ajaxResponse.childNodes[i];
		 if (i == 0){
			 var lastName = assimilator.getAttribute("lastName");
			 //document.form1["fhs_return_url"].value = document.form1["fhs_return_url"].value + "fn=" + assimilator.getAttribute("firstName");
			 createCookie('assmFirstName',assimilator.getAttribute("firstName"),0);
			 //document.form1["fhs_return_url"].value = document.form1["fhs_return_url"].value + "&ln=" + assimilator.getAttribute("lastName");
			 createCookie('assmLastName',assimilator.getAttribute("lastName"),0);
			 //document.form1["fhs_return_url"].value = document.form1["fhs_return_url"].value + "&ph=" + assimilator.getAttribute("phone");
			 createCookie('assmPhone',assimilator.getAttribute("phone"),0);
			 //document.form1["fhs_return_url"].value = document.form1["fhs_return_url"].value + "&em=" + assimilator.getAttribute("email");
			 createCookie('assmEmail',assimilator.getAttribute("email"),0);
		 } else if (i > 0 && lastName == assimilator.getAttribute("lastName")) {
			 //document.form1["fhs_return_url"].value = document.form1["fhs_return_url"].value + "&sp=" + assimilator.getAttribute("firstName")
			 createCookie('assmSpouse',assimilator.getAttribute("firstName"),0);
		 }
      }
	  //alert(document.form1["fhs_return_url"].value);
	  
   },

   reset: function() {
      var i = 0
   }

};
