/* The following  functions selOption(), selCityOptions() and searchOption() are created/modified by  Arun S Prakash */
function selOption()
{
 option_code = document.forms[0].option.value;
 document.forms[0].state.length =1;
 if(option_code == "D") /*Direct Network*/
 {
 	document.forms[0].state.options[0].selected=true;
	document.forms[0].city.options[0].text ='Select City';
	document.all("city").title	=	"City";
 	document.forms[0].city.options[0].selected = true;
	 for (i=0; i<document.forms[0].hid_state.length; i++)
	 {
	  if (document.forms[0].hid_state[i].value.substring(3)== "A")
	  {
	   var anOption = new Option(document.forms[0].hid_state[i].text,document.forms[0].hid_state[i].value.substring(0,2))
	   document.forms[0].state.options.add(anOption);
	  }
	 }
 }
 else 				 /*Agent Network*/
 {
 	document.forms[0].state.options[0].selected=true;
	document.forms[0].city.options[0].text ='Select Agent';
	document.all("city").title	=	"Agent";
 	document.forms[0].city.options[0].selected = true;
	 for (i=0; i<document.forms[0].hid_state.length; i++)
	 {
	  if (document.forms[0].hid_state[i].value.substring(3)== "N")
	  {
	   var anOption = new Option(document.forms[0].hid_state[i].text,document.forms[0].hid_state[i].value.substring(0,2))
	   document.forms[0].state.options.add(anOption);
	  }
	 }
 }
}
function selCityOptions()
{
 state_code = document.forms[0].state.value
 option_code = document.forms[0].option.value
 document.forms[0].city.length =1;
 if(option_code == "D") /*Direct Network*/
 {
  for (i=0; i<document.forms[0].hid_city.length; i++)
  {
  if (state_code == document.forms[0].hid_city[i].value.substring(5,7) && document.forms[0].hid_city[i].value.substring(8) =='A')
  {
   var anOption = new Option(document.forms[0].hid_city[i].text,document.forms[0].hid_city[i].value.substring(0,4))
   document.forms[0].city.options.add(anOption)
  }
 }
}
else					/*Agent Network*/
{
 for (i=0; i<document.forms[0].hid_city.length; i++)
 {
  if (state_code == document.forms[0].hid_city[i].value.substring(5,7) && document.forms[0].hid_city[i].value.substring(8) =='N')
  {
   var anOption = new Option(document.forms[0].hid_city[i].text,document.forms[0].hid_city[i].value.substring(0,4))
   document.forms[0].city.options.add(anOption)
  }
 }
}
}
function searchOption()
{
    var flag = true;
	option_code = document.forms[0].option.value
	if(option_code == 'D')	/* Direct Network */
		flag = serachBranch()
	else					/* Agent Network */
		flag = searchSubAgent()
	return flag;
}

function selCity()
{
 state_code = document.forms[0].state.value;
 document.forms[0].city.length=1;
 for (i=0; i<document.forms[0].hid_city.length; i++)
 {
  if (state_code == document.forms[0].hid_city[i].value.substring(5))
  {
   var anOption = new Option(document.forms[0].hid_city[i].text,document.forms[0].hid_city[i].value.substring(0,4))
   document.forms[0].city.options.add(anOption)
  }
 }
}
function serachBranch()
{
 var flag = validate()
 if (flag==false)
 {
	return;
 }
 state_name = document.forms[0].state[document.forms[0].state.selectedIndex].text;
 branch_code = document.forms[0].city[document.forms[0].city.selectedIndex].value;
 win=open("branch_search.jsp?branch_code="+branch_code+"&state_name="+state_name,"branchsearch","toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,top=5,left=5,width=550,height=250");

}

function searchSubAgent()
{

 if (validate()==false)
 {
  return false;
 }
 state_name = document.forms[0].state[document.forms[0].state.selectedIndex].text
 branch_code = document.forms[0].city[document.forms[0].city.selectedIndex].value

 win=open("subagent_search.jsp?branch_code="+branch_code+"&state_name="+state_name,"subagentsearch","toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no,top=5,left=5,width=550,height=250")
 return false;
}
