// JavaScript Document
var xmlHttp;

function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}
    
function refreshproductList() {
   var productType = document.getElementById("s_shop_state").value;
    if(productType == "" ) {
        clearproductList();
        return;
    }
	var rand = Math.random();
    var url = "city.php?state=" + productType + "&rand=" + rand;
    createXMLHttpRequest();
    xmlHttp.onreadystatechange = handleStateChange;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}
    
function handleStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
            updateproductList();
        }
    }
}

function updateproductList() {
    clearproductList();
    var productName = document.getElementById("s_shop_city");
    var results = xmlHttp.responseText;
    var option = null;
    p=results.split(",");
	option = document.createElement("option");
    option.appendChild(document.createTextNode("--- All ---"));
	option.setAttribute("value", "");
	productName.appendChild(option);
    for (var i = 0; i < p.length; i++){
           option = document.createElement("option");
           option.appendChild(document.createTextNode(p[i]));
           productName.appendChild(option);
    }
}

function clearproductList() {
    var productName = document.getElementById("s_shop_city");
    while(productName.childNodes.length > 0) {
              productName.removeChild(productName.childNodes[0]);
    }
}