	var city_arr = new Array();

	var us_state_Arr  = new Array("Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming","Others");

	city_status    = 0;
	state_status   = 0;
	country_status = 0;

function select_field(fld,value) {
	var selected_val = 0;
	for(i=0;i<eval('document.frm.select_'+fld+'.options.length'); i++) {
		eval('document.frm.select_'+fld+'.options['+i+'].selected=false');
	}
	
	for(i=0;i<eval('document.frm.select_'+fld+'.options.length'); i++) {
		v= eval('document.frm.select_'+fld+'.options['+i+'].value');
		if (v == value) {
			eval('document.frm.select_'+fld+'.options['+i+'].selected=true');
			selected_val = 1;
			break;
		}//if
	}//for loop

	if (selected_val == 0) {
		fld_length = eval('document.frm.select_'+fld+'.options.length');
		v= eval('document.frm.select_'+fld+'.options['+(fld_length-1)+'].value');
		if (v == "Others") {
			  eval('document.frm.select_'+fld+'.options['+(fld_length-1)+'].selected=true');
  			  eval('document.frm.'+fld+'_text.value="'+value+'"');
		}//if
	}//if
}//select_field
	
function enb(fld)
{
 
	v = eval('document.frm.select_'+fld+'.options[document.frm.select_'+fld+'.selectedIndex].value');
	if( fld=='country' )
	{
			if(v=='united states of america')
			{
				var state_arr_length = us_state_Arr.length;
				ex_len = document.frm.select_state.length;
				for(k=(ex_len - 1); k > 0; k--)
				{
					document.frm.select_state.options[k] = null;
				}
				for(i=0;i<state_arr_length;i++)
				{
				 option0 = new Option(us_state_Arr[i], us_state_Arr[i]);
				 document.frm.select_state.options[document.frm.select_state.length]=option0;
				}
				//option0 = new Option("Others", "Others");
				//document.frm.select_state.options[document.frm.select_state.length]=option0;
				//ex_len = document.frm.select_city.length;
				//for(k=(ex_len - 1); k > 0; k--)
				//{
				//	document.frm.select_city.options[k] = null;	
				//}
				//option0 = new Option("Others", "Others");
				//document.frm.select_city.options[document.frm.select_city.length]=option0;
				if(document.frm.state_text.value !='')
				 {
						len = document.frm.select_state.length;
						document.frm.select_state.options[(len -1)].selected = true 
					 //   len = document.frm.select_city.length;
					//	document.frm.select_city.options[(len -1)].selected = true
				 }

			}
		 	else
			 {
				ex_len = document.frm.select_state.length;
				for(k=(ex_len - 1); k > 0; k--)
				{
					document.frm.select_state.options[k] = null;
				}
				//option0 = new Option("Others", "Others");
				//document.frm.select_state.options[document.frm.select_state.length]=option0;
				if(document.frm.state_text.value !='')
				 {
						len = document.frm.select_state.length;
						document.frm.select_state.options[(len -1)].selected = true 
				 }

				//ex_len = document.frm.select_city.length;
				//for(k=(ex_len - 1); k > 0; k--)
				//{
					//document.frm.select_city.options[k] = null;
				//}
				//option0 = new Option("Others", "Others");
				//document.frm.select_city.options[document.frm.select_city.length]=option0;
				//if(document.frm.city_text.value !='')
				 //{
					//	len = document.frm.select_city.length;
						//document.frm.select_city.options[(len -1)].selected = true
				 //}
			}
		

	}
	local_state_match = 0;
	if( fld =='state' )
	{
	    st=eval('document.frm.select_'+fld+'.options[document.frm.select_'+fld+'.selectedIndex].value');
		//var state_arr_length = state_arr.length;
		//for(i=0;i<state_arr_length;i++)
		{
		//	if( state_arr[i]==st )
			{
				local_state_match = 1;
				//var city_arr_length = city_arr[i].length;
				//ex_len = document.frm.select_city.length;
				for(k=(ex_len - 1); k > 0; k--)
				{
					//document.frm.select_city.options[k] = null;	
				}

				//for(j=0;j<city_arr_length;j++)
				{
					//option0 = new Option(city_arr[i][j], city_arr[i][j]);
				//	document.frm.select_city.options[document.frm.select_city.length]=option0;
				}
			//	option0 = new Option("Others", "Others");
			//	document.frm.select_city.options[document.frm.select_city.length]=option0;

				//if(document.frm.city_text.value !='')
				 {
				//		len = document.frm.select_city.length;
				//		document.frm.select_city.options[(len -1)].selected = true 
				 }
			}
		}
		if(local_state_match == 0 )
		{
			//ex_len = document.frm.select_city.length;
			for(k=(ex_len - 1); k > 0; k--)
			{
			//	document.frm.select_city.options[k] = null;	
			}
		 	//option0 = new Option("Others", "Others");
		//	document.frm.select_city.options[document.frm.select_city.length]=option0;

			if(document.frm.city_text.value !='')
			 {
				//	len = document.frm.select_city.length;
			//		document.frm.select_city.options[(len -1)].selected = true 
			 }

		}

	}

	if(v=='Others')
	{
		eval(fld+'_status=1');
	}
	else
	{
		eval(fld+'_status=0');
		eval('document.frm.'+fld+'_text.value=""');	
	}

        if (document.frm.select_country.value == 'india')
        {
            city_status = 0;
            state_status = 0;
        } else if (document.frm.select_country.value == 'united states of america' ) {
            // not much to do here
        } else {

            document.frm.select_state.options[1].selected = true;
           // document.frm.select_city.options[1].selected = true;

            state_status = 1;
            city_status = 1;

        }

}

 function  sel_state()
 {
	v_to_select = document.frm.sel_state.value;
	fld			= document.frm.sel_country.value;
	c_to_select	= document.frm.sel_city.value;

	v_to_select_org = document.frm.sel_state.value;
	c_to_select_org	= document.frm.sel_city.value;

	fld			= fld.toLowerCase();
	v_to_select = v_to_select.toLowerCase();
	c_to_select	= c_to_select.toLowerCase();

    state_flag = 0;
    city_flag  = 0;
    if( fld == 'united states of america' || fld == 'india' )
    {
      if ( fld == 'united states of america')
		 arr = 'us_state_Arr';
      else	
		if( fld == 'india' )
			//arr = 'state_arr';

		//var state_arr_length = eval(arr +'.length');
		i =1;
		//for(i=0;i<state_arr_length;i++)
		{
			// option0 = new Option( eval(arr + '['+ i + ']') ,  eval( arr + '['+ i +']') );
		//	 document.frm.select_state.options[document.frm.select_state.length]=option0;
			 if( eval( arr + '['+ i + ']').toLowerCase() == v_to_select )
			 {
				
				state_flag = 1;
				document.frm.select_state.options[(i+1)].selected = true;	
				if(fld=='india')
				{
					var city_arr_length = city_arr[i].length;
					for(j=0;j<city_arr_length;j++)
					{
					// option0 = new Option(city_arr[i][j], city_arr[i][j]);
					// document.frm.select_city.options[document.frm.select_city.length]=option0;
					 if( city_arr[i][j].toLowerCase() == c_to_select )
					   {
						//document.frm.select_city.options[(j+1)].selected = true;
						city_flag = 1;
					   }
					}
		//			option0 = new Option("Others", "Others");
					//document.frm.select_city.options[document.frm.select_city.length]=option0;
					if(city_flag==0)
					{
						//len = document.frm.select_city.length;
						//document.frm.select_city.options[(len - 1)].selected = true
					}
				}
			}
		}
//		option0 = new Option("Others", "Others");
//		document.frm.select_state.options[document.frm.select_state.length]=option0;
		if(state_flag == 0)
		{
				len = document.frm.select_state.length;
				document.frm.select_state.options[(len-1)].selected = true
			//	option0 = new Option("Others", "Others");
			//	document.frm.select_city.options[document.frm.select_city.length]=option0;
				if(city_flag==0)
				{
				//	len = document.frm.select_city.length;
				//	document.frm.select_city.options[(len - 1)].selected = true
				}
	    }
  }
	if(state_flag == 0)
	{
		document.frm.state_text.value = v_to_select_org;
		state_status = 1;

	}
	else
	{
		state_status = 0;
	}
	if(city_flag == 0)
	 {
					document.frm.city_text.value = c_to_select_org;
					city_status  = 1;
	 }
	 else
	 {
					city_status  = 0;
	 }

 }

function trim(inputString) {
	if (typeof inputString != "string"){ return inputString; }
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") {
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") {
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	while (retValue.indexOf("  ") != -1) {
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
	}
	return retValue;
}

