function getReferXmlHttpRequestObject(){
    if (window.XMLHttpRequest){
        return new XMLHttpRequest();
    }else if(window.ActiveXObject){
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
}

function getStates(){
    var xmlHttpReq = false;
    var self = this;
    var strURL = "/ajxsvlt";
    if (window.XMLHttpRequest) { // Mozilla/Safari
        self.xmlHttpReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
    	//alert(self.xmlHttpReq.readyState);
        if (self.xmlHttpReq.readyState == 4) {
            updatePage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getQueryString());
}
function getQueryString() {
    var country = document.getElementById("cboCountry").value;
    qstr = 'country=' + country;
    return qstr;
}
function updatePage(str){
	//Remove existing states
	while(document.getElementById("cboState").options.length!=0) document.getElementById("cboState").options[0] = null;

	//Add new states
	states = str.split(",");
	for(stNo=0;stNo<states.length;stNo++) {
		document.getElementById("cboState").options[stNo] = new Option(states[stNo],states[stNo]);
	}
}

function getCitys(){
    var xmlHttpReq = false;
    var self = this;
    var strURL = "/ajxsvlt";
    if (window.XMLHttpRequest) { // Mozilla/Safari
        self.xmlHttpReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
    	//alert(self.xmlHttpReq.readyState);
        if (self.xmlHttpReq.readyState == 4) {
            updateStatePage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getStateQueryString());
}

function getStateQueryString() {
    var state = document.getElementById("companyState").value;
    qstr = 'companyState=' + state;
    return qstr;
}
function updateStatePage(str){
	//Remove existing City
	while(document.getElementById("companyCity").options.length!=0) document.getElementById("companyCity").options[0] = null;

	//Add new city
	states = str.split(",");
	for(stNo=0;stNo<states.length;stNo++) {
		document.getElementById("companyCity").options[stNo] = new Option(states[stNo],states[stNo]);
	}
}





