var http_request = false;
function send_request(url,method)
{
    http_request = false;
    if(window.XMLHttpRequest)
    {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType)
        {
            http_request.overrideMimeType('text/xml');
        }
    }
    else if (window.ActiveXObject)
    {
        try
        {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
            }
        }
    }
    if (!http_request)
    {
        window.alert("XMLHttpRequest");
        return false;
    }
    switch(method)
    {
        case 1: http_request.onreadystatechange = processRequest1;
        break;
        case 2: http_request.onreadystatechange = processRequest2;
        break;
		case 3: http_request.onreadystatechange = processRequest3;
        break;
		
		case 4: http_request.onreadystatechange = processRequest4;
        break;
		case 5: http_request.onreadystatechange = processRequest5;
        break;
		case 6: http_request.onreadystatechange = processRequest6;
        break;
		
		case 99: http_request.onreadystatechange = processRequest99;
        break;
    }
    http_request.open("GET",url, true);
    http_request.send(null);
}
function processRequest1()
{
    if (http_request.readyState == 4)
    {
        if (http_request.status == 200)
        {
//            document.getElementById("statusTxt").innerHTML="";
            addOptionGroup("board",http_request.responseText);
        }
        else
        {
            alert("");
        }
    }
    else
    {
//        document.getElementById("statusTxt").innerHTML="正在读取数据中……";
    }
}
function processRequest2()
{
    if (http_request.readyState == 4)
    {
        if (http_request.status == 200)
        {
//            document.getElementById("statusTxt").innerHTML="";

			if (http_request.responseText == '')
			{
				document.getElementById("f_board").style.display = 'none';
			}
			else
			{
				document.getElementById("f_board").style.display = 'block';
			}
			addOptionGroup2("f_board",http_request.responseText);
			loaddest();
        }
        else
        {
            alert("您所请求的页面有异常。");
        }
    }
    else
    {
//        document.getElementById("statusTxt").innerHTML="正则读取数据中……";
    }
}
function processRequest3()
{
    if (http_request.readyState == 4)
    {
        if (http_request.status == 200)
        {
//            document.getElementById("statusTxt").innerHTML="";
            addOptionGroup3("dest",http_request.responseText);
        }
        else
        {
            alert("您所请求的页面有异常。");
        }
    }
    else
    {
//        document.getElementById("statusTxt").innerHTML="正则读取数据中……";
    }
}





function processRequest4()
{
    if (http_request.readyState == 4)
    {
        if (http_request.status == 200)
        {
//            document.getElementById("statusTxt").innerHTML="";
            addOptionGroup("country_id",http_request.responseText);
			loadstate();
			loadcity();
        }
        else
        {
            alert("您所请求的页面有异常。");
        }
    }
    else
    {
//        document.getElementById("statusTxt").innerHTML="正则读取数据中……";
    }
}
function processRequest5()
{
    if (http_request.readyState == 4)
    {
        if (http_request.status == 200)
        {
//            document.getElementById("statusTxt").innerHTML="";
            addOptionGroup2("state_id",http_request.responseText);
        }
        else
        {
            alert("您所请求的页面有异常。");
        }
    }
    else
    {
//        document.getElementById("statusTxt").innerHTML="正则读取数据中……";
    }
}
function processRequest6()
{
    if (http_request.readyState == 4)
    {
        if (http_request.status == 200)
        {
//            document.getElementById("statusTxt").innerHTML="";
            addOptionGroup2("city_id",http_request.responseText);
        }
        else
        {
            alert("您所请求的页面有异常。");
        }
    }
    else
    {
//        document.getElementById("statusTxt").innerHTML="正则读取数据中……";
    }
}
function processRequest99()
{
    if (http_request.readyState == 4)
    {
        if (http_request.status == 200)
        {
//            document.getElementById("statusTxt").innerHTML="";
			addOptionGroup("board",http_request.responseText);
			loadcountry();
        }
        else
        {
            alert("您所请求的页面有异常。");
        }
    }
    else
    {
//        document.getElementById("statusTxt").innerHTML="正则读取数据中……";
    }
}


function loadtour_hotel()
{
    send_request("http://www.gomytours.com/select.asp?action=board",99);
}
function loadboard()
{
    send_request("http://www.gomytours.com/select.asp?action=board",1);
}
function loadf_board()
{
    send_request("http://www.gomytours.com/select.asp?action=f_board&board_id="+document.getElementById("board").value,2);
}
function loaddest()
{
    send_request("http://www.gomytours.com/select.asp?action=dest&board_id="+document.getElementById("board").value+"&f_board_id="+document.getElementById("f_board").value,3);
}

function loadcountry()
{
    send_request("http://www.gomytours.com/select.asp?action=country",4);
}
function loadstate()
{
    send_request("http://www.gomytours.com/select.asp?action=state&country_id="+document.getElementById("country_id").value,5);
}
function loadcity()
{
    send_request("http://www.gomytours.com/select.asp?action=city&state_id="+document.getElementById("state_id").value,6);
}

function addOption(objSelectNow,txt,val)
{
    var objOption = document.createElement("OPTION");
    objOption.text= txt;
    objOption.value=val;
    objSelectNow.options.add(objOption);
}
function addOptionGroup(selectId,optGroupString)
{
    var optGroup = optGroupString.split("**");
	arrange(optGroup); 
    var objSelect = document.getElementsByTagName("SELECT");
    var objSelectNow = objSelect[selectId];
    objSelectNow.length = 1;
    for (i=0; i<optGroup.length; i++)
    {
        if(optGroup[i]!="")
        {
            var opt = optGroup[i].split("|");
            addOption(objSelectNow, changeCase(opt[0]), opt[1]);
        }
    }
}


function addOptionGroup2(selectId,optGroupString)
{ 
	var optGroup = optGroupString.split("**");
	arrange(optGroup); 
    var objSelect = document.getElementsByTagName("SELECT");
    var objSelectNow = objSelect[selectId];
    objSelectNow.length = 1;
    for (i=0; i<optGroup.length; i++)
    {
        if(optGroup[i]!="")
        {
            var opt = optGroup[i].split("|");
            addOption(objSelectNow, changeCase(opt[0]), opt[1]);
        }
    }
}

function addOptionGroup3(selectId,optGroupString)
{ 
	var optGroup = optGroupString.split(",");
	arrange(optGroup); 
    var objSelect = document.getElementsByTagName("SELECT");
    var objSelectNow = objSelect[selectId];
    objSelectNow.length = 1;
    for (i=0; i<optGroup.length; i++)
    {
        if(optGroup[i]!="")
        {
            var opt = optGroup[i].split("|");
            addOption(objSelectNow, changeCase(optGroup[i]), changeCase(optGroup[i]));
        }
    }
}

function arrange(arr)   
{
    arr.sort();   
    var   ptr=0;   
    while(ptr<arr.length)   
	{
       if(arr[ptr]==arr[ptr+1])
	      arr.splice(ptr,1);
       else   
	      ptr++  ; 	  
	}
} 



function changeCase(tmpStr) 
{
var index;
var tmpChar;
var preString;
var postString;
var strlen;
tmpStr = tmpStr.replace(/(^\s*)|(\s*$)/g,"");
tmpStr = tmpStr.toLowerCase();
strLen = tmpStr.length;
  if (strLen > 0)  
  {
    for (index = 0; index < strLen; index++)  
	{
        if (index == 0)  
		{
            tmpChar = tmpStr.substring(0,1).toUpperCase();
            postString = tmpStr.substring(1,strLen);
            tmpStr = tmpChar + postString;
        }
        else 
		{
		    tmpChar = tmpStr.substring(index, index+1);
			if (tmpChar == " " && index < (strLen-1)) 
			{
			    tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
				preString = tmpStr.substring(0, index+1);
				postString = tmpStr.substring(index+2,strLen);
				tmpStr = preString + tmpChar + postString;
            }
        }
     }
  }
  return tmpStr;
}

