// JavaScript Document

function changeDropdownSelect(dd1,dd2)
{
			   var Index = document.getElementById(dd1).selectedIndex;
		 if(document.getElementById(dd1).options[Index].text=="Studio")
		   {
			  // alert(" i am in ");
			   var dd1value=document.getElementById(dd1).options[Index].text;
				 DDListPoint = document.getElementById(dd2);  
									  for (i = 0; i < DDListPoint.options.length; i++)
									  {
										 if (DDListPoint.options[i].text.indexOf(dd1value) == 0)
										 {
											DDListPoint.options[DDListPoint.selectedIndex].selected = false;
											DDListPoint.selectedIndex = i;                                    
											DDListPoint.options[i].selected = true;
											DDListPoint.selectedItem = DDListPoint.options[i];
											break;
										 }
									  }
									  //alert(DDListPoint.selectedItem.value)
			}
			
	
	//alert("i m calling"+SelValue);
	
	}

function filterDropdown(dd1,dd2)
{
			   var Index = document.getElementById(dd1).selectedIndex;
			  var selectedStatePk=document.getElementById(dd1).options[Index].value;

         // alert("Select "+selectedStatePk);
				 DDListPoint = document.getElementById(dd2);  
				 ind=0;
									  for (i = 0; i < DDListPoint.options.length; i++)
									  {
										  var str_val=DDListPoint.options[i].value;
										  var comm_id=str_val.split("-");
										  var state_pk=comm_id[0];
										  
										 if (state_pk == selectedStatePk)
										 {
											//alert("State pk "+state_pk +"Selected pk "+selectedStatePk);
										
											 
											DDListPoint.options[ind].value =DDListPoint.options[i].value;
											DDListPoint.options[ind].text = DDListPoint.options[i].text;
											ind++;
											
										 }
									  }

			
			
	

	
	}
	function onChangeAction(dd1,dd2,dd3)
	{         var Index = document.getElementById(dd1).selectedIndex;
			  var dd1val=document.getElementById(dd1).options[Index].value;
			  if(dd1val=="")
			  {
 reloadDropdown('<select name='+dd2 +' id='+dd2+' class=dropDown1 onchange=filterReplace("ddCommunity","ddProperty","Properties","","")>',"hddCommunities","spanCommunities");
				  reloadDropdown('<select name='+dd3 +' id='+dd3+' class=dropDown1>',"hddProperties","spanProperties");
				  }
				  else
				  {
					  		filterReplace('ddStates','ddCommunity','Communities','ddProperty','Properties');
				  }
		

		}
		
			function onChangeAction2(dd1,dd2)
	{         var Index = document.getElementById(dd1).selectedIndex;
			  var dd1val=document.getElementById(dd1).options[Index].value;
			  if(dd1val=="")
			  {
				  reloadDropdown('<select name='+dd2 +' id='+dd2+' class=dropDown1>',"hddProperties","spanProperties");
				  }
				  else
				  {
					  		filterReplace('ddCommunity','ddProperty','Properties','','');
				  }
		

		}
function filterReplace(dd1,dd2,var_name,onchange,onchange_var_name)
{
	spn="span"+var_name;
	hdd="hdd"+var_name;
	if(onchange!="")
	var ndd="<select name="+dd2 +" id="+dd2+" class=dropDown1 onchange=filterReplace('"+dd2+"','"+onchange+"','"+onchange_var_name+"','','')>";
	else
	var ndd="<select name="+dd2 +" id="+dd2+" class=dropDown1>";
	
		   var Index = document.getElementById(dd1).selectedIndex;
			  var dd1val=document.getElementById(dd1).options[Index].value;
			  if(dd1val.indexOf("-")!=-1)
			  {
				  vardd1val=dd1val.split("-");
				  dd1val=vardd1val[1];
				  
				  }

//alert ("DD ! "+dd1val);
		        reloadDropdown(ndd,hdd,spn);
		 
				 DDListPoint = document.getElementById(dd2);  
			

ind=0;
				 str_new_dd=ndd+"<option value=''>Any</option>";
									  for (i = 0; i < DDListPoint.options.length; i++)
									  {
										  var dd2val=DDListPoint.options[i].value;
										  var comm_id=dd2val.split("-");
										  dd2val=comm_id[0];
									
										 if (dd1val == dd2val)
										 {
											str_new_dd+="<option value="+DDListPoint.options[i].value+">"+DDListPoint.options[i].text+"</option>";
											ind++;
											
										 }
									  }
									  
							str_new_dd+="</select>";
			

			 document.getElementById(spn).innerHTML=str_new_dd;

	}
	function reloadDropdown(dd,hdd,spn)
	{
		ddvalues=document.getElementById(hdd).value;
		var new_dd=dd+"<option value=''>Any</option>"+ddvalues+"</select>";
		//alert ("New dropdown"+new_dd);
		document.getElementById(spn).innerHTML=new_dd;
		
		}
	function tooglediv(divhideshow)
	{
		if(document.getElementById(divhideshow).style.display=="block")
		document.getElementById(divhideshow).style.display="none";
		else
		document.getElementById(divhideshow).style.display="block";
	}
	function showhide(showdiv,hidediv)
	{
		document.getElementById(showdiv).style.display="block";
		document.getElementById(hidediv).style.display="none";
		
		}