
if (THC == undefined) 
{
		var THC = {}; 
} 

//see http://javascript.crockford.com/private.html for description of javascript
//public, private and privileged functions
THC.AdvancedSearchController = 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.validateSearchForm = function()
    {
     	
     	if(that.checkForm())
     	{
	     	var errorDiv = dojo.byId("errorDiv");	     	
	     	 form.submit();	     	
       }
    };
    this.checkForm = function()
    {
    	
    	var found = false;
    	var form = document.searchForm;
    	   for (var i = 0; i < form.elements.length; i++) 
		   {
		   	 var elem = form.elements[i];
		   	 if(elem.value != "")
		   	 {
		   	 	found= true;
		   	 	break;
		   	 }
		   }
		if(!found)
		{
			var errorDiv = dojo.byId("errorDiv");
			if(errorDiv)
			  {
			  	errorDiv.style.display="block";
			  	errorMsg = "Please enter atleast one value in any field .</br>";
			  	errorDiv.innerHTML = errorMsg; 
			  }
			  return;
		}
		else
		{
			return true;
		}   
    };
    this.getSubCategories = function(srcCategory, tgtCategory)
    {
    	var categories;
    	var catId = dojo.byId(srcCategory).value;
    	var request = dojo.xhrGet(
 		{
   	 		url:"getSubCategories.html?catId="+catId,
		 	error: function(type, errObj)
		 	{ 
		 		//do nothing					
		 	},
		 	load: function(type, data, evt)
		 	{	
				categories = eval(data.xhr.responseText);
		 	},
		 	sync: true,
		    mimetype: "text/plain"
		});
		var newCategory = dojo.byId(tgtCategory);
		if(newCategory)
		{
			if(categories && categories.length > 0)
			{
				newCategory.options.length = categories.length;
				for(i=0; i< categories.length; i++)
				{
					newCategory.options[i+1] = new Option(categories[i].title,categories[i].id);
			
				}
			}
		}
    }
    //============================================================================
	//							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.AdvancedSearchController.prototype =
{	

};
//============================================================================
//							END PUBLIC FUNCTIONS 
//============================================================================	