// JavaScript Document
function loadCats(selectBox, targetDiv, level,pt,zoneCode, channelCode) 
{	
	if(level==2)
	{
	 var requestParameters = null;
	 if(path=="")
	 	path = pt;
	 
     var url = path+"/CategoriesLoadServlet";
	 var selectedValue = selectBox[selectBox.selectedIndex].value;
	 var level1=selectedValue;
	 var level2="";
	 var level3="";
	
	requestParameters = "level="+level+"&level1="+level1.replace('&','*')+"&level2="+level2.replace('&','*')+"&level3="+level3.replace('&','*')+"&zoneCode="+zoneCode+"&channelCode="+channelCode;

	  var ajax = new Ajax.Request(
			  url, {
		  method: "post",
		  parameters: requestParameters,
		  onFailure: reportAjaxError,
		  onSuccess: function(request) {
			  var obj = eval('(' + ajax.transport.responseText + ')');
			
			if(obj.error!=null && obj.error!="")
					alert(obj.error);
					
			 
			  Element.remove($(targetDiv).getElementsByTagName("SELECT")[0]);
			  Element.update(targetDiv, obj.categories);
						
		  }
		  
	  });
	}  
}

function loadCatsShare(selectBox, targetDiv, level,pt,zoneCode, channelCode) 
{	
	if(level==3)
	{
	 var requestParameters = null;
	 if(path=="")
	 	path = pt;
	 
     var url = path+"/CategoriesLoadServlet";
	 var selectedValue = selectBox[selectBox.selectedIndex].value;
	 var level1="Share";
	 var level2=selectedValue;
	 var level3="";
	
	requestParameters = "level="+level+"&level1="+level1.replace('&','*')+"&level2="+level2.replace('&','*')+"&level3="+level3.replace('&','*')+"&zoneCode="+zoneCode+"&channelCode="+channelCode;

	  var ajax = new Ajax.Request(
			  url, {
		  method: "post",
		  parameters: requestParameters,
		  onFailure: reportAjaxError,
		  onSuccess: function(request) {
			  var obj = eval('(' + ajax.transport.responseText + ')');
			
			if(obj.error!=null && obj.error!="")
					alert(obj.error);
					
			 
			  Element.remove($(targetDiv).getElementsByTagName("SELECT")[0]);
			  Element.update(targetDiv, obj.categories);
						
		  }
		  
	  });
	}  
}

function loadAutoCategories(selectBox, targetDiv, level,pt,zoneCode, channelCode)
{
	var selectedValue = selectBox[selectBox.selectedIndex].value;
	
	if(selectedValue=='Autos For Sale')
	{
		document.classifiedSearchForm.typeCode.value='F';
	}
	else if(selectedValue=='Autos For Trade')
	{
		document.classifiedSearchForm.typeCode.value='T';
	}
	else if(selectedValue=='Looking To Buy')
	{
		document.classifiedSearchForm.typeCode.value='W';
	}
	
	loadCats(selectBox, targetDiv, level,pt,zoneCode, channelCode);	
}

function loadRealEstateCategories(selectBox, targetDiv, level,pt,zoneCode, channelCode)
{
	var selectedValue = selectBox[selectBox.selectedIndex].value;
	
	if(selectedValue=='Available For Sale')
	{
		document.classifiedSearchForm.typeCode.value='F';
	}
	else if(selectedValue=='Swap')
	{
		document.classifiedSearchForm.typeCode.value='T';
	}
	else if(selectedValue=='Looking To Buy')
	{
		document.classifiedSearchForm.typeCode.value='W';
	}
	else if(selectedValue=='Available For Rent')
	{
		document.classifiedSearchForm.typeCode.value='R';
	}
	else if(selectedValue=='Looking To Rent')
	{
		document.classifiedSearchForm.typeCode.value='L';
	}
		
	loadCats(selectBox, targetDiv, level,pt,zoneCode, channelCode);	
}

function loadCatsMatchMaker(selectBox, targetDiv, level,pt,zoneCode, channelCode) 
{
	var selectedValue = selectBox[selectBox.selectedIndex].value;
	
	var requestParameters = null;
	if(path=="")
		path = pt;
	
	var url = path+"/CategoriesLoadServlet";

	var level1=selectedValue;
	var level2="";
	var level3="";
	if(level==2)
	{
		requestParameters = "level="+level+"&level1="+level1.replace('&','*')+"&level2="+level2.replace('&','*')+"&level3="+level3.replace('&','*')+"&zoneCode="+zoneCode+"&channelCode="+channelCode;

		var ajax = new Ajax.Request(
			url, {
			method: "post",
			parameters: requestParameters,
			onFailure: reportAjaxError,
			onSuccess: function(request) {
				var obj = eval('(' + ajax.transport.responseText + ')');
			
				if(obj.error!=null && obj.error!="")
					alert(obj.error);
					
				Element.remove($(targetDiv).getElementsByTagName("SELECT")[0]);
				Element.update(targetDiv, obj.categories);
				}
			});
		}  
	
		if(selectedValue=='Personals')
		{
			loadCatsMatchMaker2(selectBox,targetDiv,level,pt,zoneCode,channelCode)
		}
		else
		{
			document.getElementById("dependentLevel3").style.visibility="hidden";
			document.getElementById("lookingId").style.visibility="hidden";
		}
	}

function loadCatsMatchMaker2(selectBox, targetDiv, level,pt,zoneCode, channelCode) 
{	
var selectedValue = selectBox[selectBox.selectedIndex].value;
	//alert(targetDiv);
	//alert(level);
	level=3;
	var requestParameters = null;
	 if(path=="")
	 	path = pt;
	 
     var url = path+"/CategoriesLoadServlet";

	 var level1=selectedValue;
	 var level2="Man";	 
	 var level3="";

	requestParameters = "level="+level+"&level1="+level1.replace('&','*')+"&level2="+level2.replace('&','*')+"&level3="+level3.replace('&','*')+"&zoneCode="+zoneCode+"&channelCode="+channelCode;
	//targetDiv=;
	  var ajax = new Ajax.Request(
			  url, {
		  method: "post",
		  parameters: requestParameters,
		  onFailure: reportAjaxError,
		  onSuccess: function(request) {
			  var obj = eval('(' + ajax.transport.responseText + ')');
			
			if(obj.error!=null && obj.error!="")
					alert(obj.error);
					
			document.getElementById("dependentLevel3").style.visibility="visible";
			document.getElementById("lookingId").style.visibility="visible";		 
			  Element.remove($("dependentLevel3").getElementsByTagName("SELECT")[0]);
			  Element.update("dependentLevel3", obj.categories);
						
		  }
		  
	  });
}
