
if (THC == undefined) 
{
		var THC = {}; 
} 

//see http://javascript.crockford.com/private.html for description of javascript
//public, private and privileged functions
THC.RegistrationController = function () 
{ 	

//============================================================================
	//							CONSTRUCTOR 
	//============================================================================
	//			(must be declared after all functions to be used)
	var that = this;
	
	
	//============================================================================
	//							END CONSTRUCTOR
	//============================================================================
	//============================================================================
	//							PRIVATE FUNCTIONS 
    //============================================================================    	
	
	//============================================================================
	//							END PRIVATE FUNCTIONS 
    //============================================================================  	

	//============================================================================
	//							PRIVILEGED (PUBLIC) FUNCTIONS 
    //============================================================================	

    this.shippingCheckClicked = function(chkBox)
    {
    
   		var tempstyle = chkBox.checked?"none":"";
   		var i = 1;
   		for (i=1; i<23; ++i){
   			dojo.byId("shipel"+i).style.display=tempstyle;
   		}
   		if ( !chkBox.checked ) {
   			that.copyBillingToShipping();
   		}
    };
    this.copyBillingToShipping = function()
    {
    	var form = dojo.byId("registrationForm");
    	form.shipFirstName.value = form.firstName.value;
    	form.shipMiddleName.value = form.middleName.value;
    	form.shipLastName.value = form.lastName.value;
    	form.shipCompany.value = form.company.value;
    	form.shipAddress1.value = form.address1.value;
    	form.shipAddress2.value = form.address2.value;
    	form.shipCity.value = form.city.value;
    	form.shipCountry.value = form.country.value;
    	form.shipFirstName.value = form.firstName.value;
    	form.shipFirstName.value = form.firstName.value;
    	form.shipPhone.value = form.phone.value;
    	form.shipZipCode.value = form.zipCode.value;
    };
     this.copyOnSubmit = function()
    {
    	
    	 var form = dojo.byId("registrationForm");
    	var chkBox = form.chkShipping;
    	if(chkBox.checked)
    	{
	   		form.shipFirstName.value = form.firstName.value;
	    	form.shipMiddleName.value = form.middleName.value;
	    	form.shipLastName.value = form.lastName.value;
	    	form.shipCompany.value = form.company.value;
	    	form.shipAddress1.value = form.address1.value;
	    	form.shipAddress2.value = form.address2.value;
	    	form.shipCity.value = form.city.value;
	    	form.shipCountry.value = form.country.value;
	    	form.shipFirstName.value = form.firstName.value;
	    	form.shipFirstName.value = form.firstName.value;
	    	form.shipPhone.value = form.phone.value;
	    	form.shipZipCode.value = form.zipCode.value;
    	}
    };
    this.copyState = function()
    {
  		if(dijit.byId('shipState') && dijit.byId('state') && dijit.byId('state').item)
    	{
    		dijit.byId('shipState').attr('value', (dijit.byId('state').item).abbreviation);
    	}
   		
    };
    this.userAlreadyRegistered = function(email){
    	var result = false;
    	var ajaxUrl = "";
    	ajaxUrl = "userAlreadyRegistered.html?email="+email;
    	var response;
    	var request = dojo.xhrGet(
    	{
    	    url:ajaxUrl,
    	    preventCache:true,
    	    error: function(type, errObj)
    	    { 
    	     alert("Error getting user already registered");     
    	    },
    	    load: function(type, data, evt)
    	    { 
    	    response = eval(data.xhr.responseText);
    	    },
    	    sync: true,
    	      mimetype: "text/plain"
    	});
	  if(response.error)
	  {
	    alert(response.error);
	  }
	  else if(response.isAlreadyRegistered)
	  {
		  result = response.isAlreadyRegistered == true;
	  }
	  return result;

    }
    //============================================================================
	//							END PRIVILEGED (PUBLIC) FUNCTIONS 
    //============================================================================	
    
	
};

//============================================================================
//							PUBLIC FUNCTIONS 
//============================================================================	
//The prototype mechanism is used for inheritance. It also conserves memory
//as all objects use one definition of the function.
THC.RegistrationController.prototype =
{	

};
//============================================================================
//							END PUBLIC FUNCTIONS 
//============================================================================	
