// JavaScript Document

/** Function to return a XMLHttpRequest **/
function getXMLHttp()
{
var xmlHttp = null;
	if(window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}

	if(window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
		}
return xmlHttp;
}


/** Function to load states using ajax on country changes **/
function load_states(country_short_name, frm)
{

show_loading_box("Loading States...");
state_drp = frm.state;
state_drp.options.length = 0;
state_drp.style.display="none";


	var xmlHttp = new getXMLHttp();
	xmlHttp.onreadystatechange = function(){
	if(xmlHttp.readyState == 4 && xmlHttp.status ==200){

				xmlDom = xmlHttp.responseXML;
				
				state_elements = xmlDom.getElementsByTagName("state");
				state_drp.options.length = 0;
				state_drp.options[0] = new Option("All Sates/ Provinces", "-1");
				for(i=0; i<state_elements.length; i++){
						state_id_element = state_elements[i].getElementsByTagName("stateID");
						state_name_element = state_elements[i].getElementsByTagName("stateName");
						state_id = state_id_element[0].firstChild.nodeValue;
						state_name = state_name_element[0].firstChild.nodeValue;
						state_drp.options[state_drp.options.length] = new Option(state_name, state_id);
				}
				state_drp.style.display="block";

				if(document.getElementById("loading_box") != null)
					hide_loading_box();
			}
		}
	xmlHttp.open('GET', 'ajax_response.php?cmd=LOAD_STATES&country_short_name='+country_short_name, true);
	xmlHttp.send(null);
}

function load_states1(country_short_name, frm,defaultValue)
{

	show_loading_box("Loading States...");
	state_drp = frm.state;
	state_drp.options.length = 0;
	state_drp.style.display="none";

	var xmlHttp = new getXMLHttp();
	xmlHttp.onreadystatechange = function(){
	if(xmlHttp.readyState == 4 && xmlHttp.status ==200){

				xmlDom = xmlHttp.responseXML;
				state_elements = xmlDom.getElementsByTagName("state");
				state_drp.options.length = 0;
				state_drp.options[0] = new Option("All Sates/ Provinces", "-1");
				var sel=0;

				for(i=0; i<state_elements.length; i++){
						state_id_element = state_elements[i].getElementsByTagName("stateID");
						state_name_element = state_elements[i].getElementsByTagName("stateName");
						state_selected_element = state_elements[i].getElementsByTagName("stateValue");
						state_id = state_id_element[0].firstChild.nodeValue;
						state_name = state_name_element[0].firstChild.nodeValue;

						state_selected = state_selected_element[0].firstChild.nodeValue;
							alert("rajnish");
						if(state_selected=="selected")
						{
							sel=i;
						}
						state_drp.options[state_drp.options.length] = new Option(state_name, state_id);
				}
			
				state_drp.style.display="block";
				state_drp.selectedIndex=sel;
				if(document.getElementById("loading_box") != null)
					hide_loading_box();
			}
		}
		alert('ajax_response.php?cmd=LOAD_STATES&country_short_name='+country_short_name+"&defaultValue="+defaultValue);
	xmlHttp.open('GET', 'ajax_response.php?cmd=LOAD_STATES&country_short_name='+country_short_name+"&defaultValue="+defaultValue, true);
	xmlHttp.send(null);
}


function show_loading_box(text)
{
	
	if(document.getElementById("loading_box") == null)
	{
		var div = document.createElement("DIV");
				div.id="loading_box";
				div.className="loading_box";
		var textNode = document.createTextNode(text);
				div.appendChild(textNode);

		document.getElementById("state_loading").appendChild(div);
		document.getElementById("state_loading").style.display="block";
	}
}

function hide_loading_box()
{
	document.getElementById("state_loading").removeChild(document.getElementById("loading_box"));
	document.getElementById("state_loading").style.display = "none";
}
function SaveAjaxCompanyInfo()
{
	//alert("testing oneas");
}

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;
}





