// file path: Z:\WEBSITES\shaadispice.com\dev\wedding-directory\ssi\directory-script.js

// #### reset form  ###

function reset_form(sForm){

		

		 _oDF = document.forms[sForm];



		 _oDF.reset();

		 _oDF.counter.value=_oDF.company_description.value.length;

		return  _oDF.counter.value;

		

}





// #### clear form varaible value ###

function cls(str){

	str.value = "";

	return;

}





// directory function for selecting state according country

function ifcountry_india_usa(oCountry, sForm)

{

	var _oDF = document.frmregister;



	if(sForm) _oDF = document.forms[sForm];



	if(oCountry.options[oCountry.selectedIndex].text == 'India')

	{

		_oDF.indianstates.disabled = false;

		_oDF.usstates[0].selected  = true;

		_oDF.usstates.disabled     = true;

		_oDF.otherstate.value      = "";

		_oDF.otherstate.disabled   = true;

		return true;

	}

	else

	{

		if(oCountry.options[oCountry.selectedIndex].text == 'USA')

		{

			_oDF.indianstates[0].selected = true;

			_oDF.indianstates.disabled    = true;

			_oDF.usstates.disabled        = false;

			_oDF.otherstate.value         = "";

			_oDF.otherstate.disabled      = true;

			return true;

		}

		else

		{

			_oDF.otherstate.disabled      = false;

			//_oDF.otherstate.focus();

			_oDF.usstates[0].selected     = true;

			_oDF.usstates.disabled        = true;

			_oDF.indianstates[0].selected = true;

			_oDF.indianstates.disabled    = true;

			return true;

		}

	}

}





function ifcountry_india_uk(oCountry, city,sForm)

{

	var _oDF;



	if(sForm){

		_oDF = document.forms[sForm];

	}

	else

	{

		_oDF = document.frmregister;

	}

	if(oCountry == 'India')

	{

		_oDF.othercountry[0].selected = true;

		_oDF.othercountry.disabled    = true;

		document.getElementById('otherRow').style.display="none";

		_oDF.indianstates.disabled = false;

		document.getElementById('stateRow').style.display="";

		_oDF.indianstates.disabled   = false;

		document.getElementById('countyRow').style.display="none";

		_oDF.county[0].selected = true;

		_oDF.county.disabled   = true;

		document.getElementById('UsastateRow').style.display="none";

		_oDF.usastates[0].selected = true;

		_oDF.usastates.disabled   = true;

		showCity('country',oCountry,city);

		//showCategory(oCountry.options[oCountry.selectedIndex].text);

		

	}

	else if(oCountry == 'United Kingdom')

	{

		_oDF.othercountry[0].selected = true;

		_oDF.othercountry.disabled    = true;

		document.getElementById('otherRow').style.display="none";

		_oDF.indianstates[0].selected = true;

		_oDF.indianstates.disabled    = true;

		document.getElementById('stateRow').style.display="none";

		document.getElementById('countyRow').style.display="";

		_oDF.county.disabled   = false;	

		document.getElementById('UsastateRow').style.display="none";

		_oDF.usastates[0].selected = true;

		_oDF.usastates.disabled   = true;

		showCity('country',oCountry, city);

		//showCategory(oCountry.options[oCountry.selectedIndex].text);

		

	}

	else if(oCountry == 'United Arab Emirates')

	{

		_oDF.othercountry[0].selected = true;

		_oDF.othercountry.disabled    = true;

		document.getElementById('otherRow').style.display="none";

		_oDF.indianstates[0].selected = true;

		_oDF.indianstates.disabled    = true;

		document.getElementById('stateRow').style.display="none";

		_oDF.county[0].selected = true;

		_oDF.county.disabled   = true;

		document.getElementById('countyRow').style.display="none";

		document.getElementById('UsastateRow').style.display="none";

		_oDF.usastates[0].selected = true;

		_oDF.usastates.disabled   = true;

		showCity('country',oCountry,city);

		//showCategory(oCountry.options[oCountry.selectedIndex].text);

	}

	else if(oCountry == 'USA')

	{

		_oDF.othercountry[0].selected = true;

		_oDF.othercountry.disabled    = true;

		document.getElementById('otherRow').style.display="none";

		_oDF.indianstates[0].selected = true;

		_oDF.indianstates.disabled    = true;

		document.getElementById('stateRow').style.display="none";

		_oDF.county[0].selected = true;

		_oDF.county.disabled   = true;

		document.getElementById('countyRow').style.display="none";

		showCity('country',oCountry,city);

		document.getElementById('UsastateRow').style.display="";

		_oDF.usastates.disabled   = false;

		showCity('country',oCountry,city);

	}

	else if(oCountry == 'Others')

	{

		_oDF.othercountry[0].selected = false;

		_oDF.othercountry.disabled    = false;

		document.getElementById('otherRow').style.display="";

		_oDF.indianstates[0].selected = true;

		_oDF.indianstates.disabled    = true;

		document.getElementById('stateRow').style.display="none";

		_oDF.county[0].selected = true;

		_oDF.county.disabled   = true;

		document.getElementById('countyRow').style.display="none";

		document.getElementById('UsastateRow').style.display="none";

		_oDF.usastates[0].selected = true;

		_oDF.usastates.disabled   = true;

		showCity('country',oCountry,city);

	}

	else

	{

		_oDF.othercountry[0].selected = true;

		_oDF.othercountry.disabled    = true;

		document.getElementById('otherRow').style.display="none";

		_oDF.indianstates[0].selected = true;

		_oDF.indianstates.disabled    = true;

		document.getElementById('stateRow').style.display="none";

		_oDF.county[0].selected = true;

		_oDF.county.disabled   = true;

		document.getElementById('countyRow').style.display="none";

		document.getElementById('UsastateRow').style.display="none";

		_oDF.usastates[0].selected = true;

		_oDF.usastates.disabled   = true;

		//showCity('country',oCountry,city);

	}

	

}



function ifcountry_india_uk_billing(oCountry, sForm)

{

	var _oDF = document.frmregister;



	if(sForm) _oDF = document.forms[sForm];

	if(oCountry == 'India')

	{

		_oDF.indianstates.disabled   = false;

		_oDF.county[0].selected = true;

		_oDF.county.disabled   = true;

		_oDF.usastates[0].selected = true;

		_oDF.usastates.disabled   = true;

		

	}

	else if(oCountry == 'United Kingdom')

	{

		_oDF.indianstates[0].selected = true;

		_oDF.indianstates.disabled    = true;

		_oDF.county.disabled   = false;		

		_oDF.usastates[0].selected = true;

		_oDF.usastates.disabled   = true;

		

	}

	else if(oCountry == 'USA')

	{

		_oDF.indianstates[0].selected = true;

		_oDF.indianstates.disabled    = true;

		_oDF.county[0].selected = true;

		_oDF.county.disabled   = true;

		_oDF.usastates.disabled   = false;

		

	}

	else

	{

		_oDF.indianstates[0].selected = true;

		_oDF.indianstates.disabled    = true;

		_oDF.county[0].selected = true;

		_oDF.county.disabled   = true;

		_oDF.usastates[0].selected = true;

		_oDF.usastates.disabled   = true;

	}

}



function ifcategory_other(oCategory)

{

	var _oDF = document.frmregister;



	//if(sForm) _oDF = document.forms[sForm];

	if(oCategory != 'Other')

	{

		document.getElementById('othercategory').value	= "";

		document.getElementById('othercategory').disabled    = true;

		document.getElementById('othercatRow').style.display="none";

		

	}

	else if(oCategory == 'Other')

	{

		document.getElementById('othercategory').disabled    = false;

		document.getElementById('othercatRow').style.display="";

		

	}

}



/*

function to show advance search fields on click

 * @usage  <a onclick="show_advance_search();">



*/

var showhide="show";

function show_advance_search()

{

	if(showhide=="show")

	{

		document.getElementById('advancesearch_row').style.display = "";

		showhide="hide";

	}

	else if(showhide == "hide")

	{

		document.getElementById('advancesearch_row').style.display = "none";

		showhide="show";

	}



}



function clear_text(id,def,val)

{	

	if(def == val)

	{

	document.getElementById(id).value='';	

	}

}







function show_text(id,def,val)

{	

	if(val == "")

	{

	document.getElementById(id).value=def;	

	}

	else if(def != val)

	{

	advance_search(id);

	}

}



function search_form(id)

{

	if(document.getElementById(id).value !='')

	{

		if(id == "city")

		{

			//--Disable other controls

			document.getElementById('city').disabled =false;

			document.getElementById('county').disabled = true;

			

			//----clear values

			document.getElementById('county').value = "";

		}

		else if(id == "county")

		{

			//--Disable other controls

			document.getElementById('city').disabled =true;

			document.getElementById('county').disabled = false;



			//----clear values

			document.getElementById('city').value = "";

		}

	}

	else

	{

		document.getElementById('city').disabled =false;

		document.getElementById('county').disabled = false;

		//----clear values

		document.getElementById('city').value = "";

		document.getElementById('county').value = "";

	}

}

function advance_search(id)

{	

	document.getElementById('type').value = id;

	document.getElementById('searchval').value = document.getElementById(id).value;



	if(document.getElementById(id).value == "")

	{

		document.getElementById('pincode').disabled  = false;

		document.getElementById('locality').disabled = false;

		document.getElementById('keyword').disabled  = false;

	}

	else

	{

		if(id == "pincode")

		{

			//--Disable other controls

			document.getElementById('locality').disabled =true;

			document.getElementById('keyword').disabled = true;

			

			//----clear values

			document.getElementById('locality').value = "";

			document.getElementById('keyword').value = "";

		}

		else if(id == "locality")

		{

			//--Disable other controls

			document.getElementById('pincode').disabled =true;

			document.getElementById('keyword').disabled = true;



			//----clear values

			document.getElementById('pincode').value = "";

			document.getElementById('keyword').value = "";

		}

		else if(id == "keyword")

		{

			//--Disable other controls

			document.getElementById('pincode').disabled =true;

			document.getElementById('locality').disabled = true;



			//----clear values

			document.getElementById('pincode').value = "";

			document.getElementById('locality').value = "";

		}

		

	}

}



/**

 * counter for textarea

 *

 * @author Ritchie

 * @param  string  sForm      form name

 * @param  string  sTextArea  textarea name

 * @param  string  sTextInput counter name

 * @param  integer iMaxLimit  max number for counter

 *

 * @usage  <textarea onKeyUp="calcCharLeft('frmregister', 'company_description', 'counter', 150)">

*/

function calcCharLeft(sForm, sTextArea, sTextInput, iMaxLimit)

{

	var _oDF        = document.forms[sForm];

	var _oTxtA      = _oDF.elements[sTextArea];

	var _iMaxLength = (!iMaxLimit) ? 100 : iMaxLimit;

	var _iCharLeft  = _oTxtA.value.length;



	_oDF.elements[sTextInput].value = _iCharLeft;



	if(_iCharLeft > _iMaxLength)

	{

		_oTxtA.value = _oTxtA.value.substring(0, _iMaxLength);

		_oDF.elements[sTextInput].value = _iMaxLength;

		alert('You can enter only '+_iMaxLength+' characters.');

	}

}



/* --- Ajax function to show city list accoring to selected country-----*/

function showCity(type,str,city)

{

if (str.length==0)

  { 

  document.getElementById("cityid").innerHTML="";

  return;

  }

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)

  {

  alert ("Your browser does not support AJAX!");

  return;

  } 

var url="/wedding-directory/ssi/city-array.php";

url=url+"?value="+str;

url=url+"&type="+type;

url=url+"&city="+city;

xmlHttp.onreadystatechange=stateChanged;

xmlHttp.open("GET",url,true);

xmlHttp.send(null);

}



function GetXmlHttpObject()

{

  var xmlHttp=null;

  try

    {

    // Firefox, Opera 8.0+, Safari

    xmlHttp=new XMLHttpRequest();

    }

  catch (e)

    {

    // Internet Explorer

    try

      {

      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

      }

    catch (e)

      {

      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

      }

    }

  return xmlHttp;

}



function stateChanged() 

{

	if (xmlHttp.readyState==4)

	{ 

		document.getElementById('cityid').innerHTML=xmlHttp.responseText;

	}

	else

	{

		document.getElementById('cityid').innerHTML="";

	}

}
