﻿//用在主页的搜索的js文件 

function lTrim(str)
{
    if (str.charAt(0) == " "||str.charAt(0) == "　")
    {
        //如果字串左边第一个字符为空格
        str = str.slice(1);//将空格从字串中去掉
        //这一句也可改成 str = str.substring(1, str.length);
        str = lTrim(str); //递归调用
    }
    return str;
}

//去掉字串右边的空格
function rTrim(str)
{
    var iLength;

    iLength = str.length;
    if (str.charAt(iLength - 1) == " "||str.charAt(iLength - 1) == "　")
    {
        //如果字串右边第一个字符为空格
        str = str.slice(0, iLength - 1);//将空格从字串中去掉
        //这一句也可改成 str = str.substring(0, iLength - 1);
        str = rTrim(str); //递归调用
    }
    return str;
}

//去掉字串两边的空格
function trim(str)
{
    return lTrim(rTrim(str));
}


function $(id) 
{ 
    return document.getElementById(id); 
} 
function showpanel(id) 
{ 
  
    for(i=1;i<=4;i++)
    {
        var divid="p"+i;
        var liId="a"+i;
        if(i==id)
        {
            document.getElementById(divid).style.display="block"; 
            document.getElementById(liId).className="ff09ul_menuclick";
        }
        else 
        {
             document.getElementById(divid).style.display="none"; 
            document.getElementById(liId).className="ff09ul_menuli01";
        }
    }

} 

//----------------------------------------------------->搜索方法开始

//数字验证的正则表达式
var num_pattern = /^[0-9]*[1-9][0-9]*$/;

//第一个搜索，按照站点之间进行搜索
function searchbasestation(){
    //alert("aaa");
    //数字验证的正则表达式
    var num_pattern = /^[0-9]*[1-9][0-9]*$/;
    
    //按城市搜索的几个参数
    var checkbcity = "";
    var checkecity = "";
    //按站点搜索的几个参数
     var checkbscitycode = trim(document.getElementById("city").value);
    var checkbstation = trim(document.getElementById("bstation").value);
    var checkescitycode = trim(document.getElementById("e_city").value);
    var checkestation = trim(document.getElementById("estation").value);
    var checkstationname = "";
    
    
    if((checkbscitycode=="0"||checkbscitycode=="")&&(checkescitycode=="0"||checkescitycode==""))
    {
        alert("请选择搜索条件");
        return;
    }
    
    //判断城市和站点是否相同
     if((checkbstation=="0"||checkbstation=="")||(checkestation=="0"||checkestation=="")){
            if(checkbscitycode==checkescitycode){
                alert("城市名不能相同啊");
                return;
            }
        }else{
            if(checkbstation==checkestation){
                alert("站点不能相同啊");
                return;
            }
        }
    
    var hc = " ";
    if(document.getElementById("hc")!=null){
        hc = document.getElementById("hc").value;
    }else{
        hc = "320700";
    }
    //hc="320700";
  
    //window.location = "destinations_list.aspx?action=searchtnum&citycode="+hc+"&strwhere="+strwhere;
    //destinations_list_a1_320700_c1.html
    var siteName = "";
     if(document.getElementById('f1')){           
            siteName = "http://www.che-piao.com";
     }    
    window.location = siteName + "/d-l-s-"+checkbscitycode+"-"+checkescitycode+"-"+checkbstation+"-"+checkestation+".html";
}

//第二个搜索  按照城市进行搜索
function searchbasecity(){
    
    //按城市搜索的几个参数
    var checkbcity = trim(document.getElementById("bcity").value);//出发城市
    var checkecity = trim(document.getElementById("ecity").value);//到达城市
    
    //按站点搜索的几个参数
    var checkbstation = "";
    var checkestation = "";
    var checkbscitycode = "";
    var checkescitycode = "";
    var checkstationname = "";
    
    if(checkbcity=='出发城市（城市名、拼音或区号）'){
        checkbcity = '';
    }
    if(checkecity=='目的城市（城市名、拼音或区号）'){
        checkecity = ''
    }
    
    //如果城市是悬空的字，那么把值设为空串
    if(checkbcity=="城市名,拼音或区号"){
        checkbcity = "";
    }
    if(checkecity=="城市名,拼音或区号"){
        checkecity = "";
    }
    
    //判断如果输入的是区号，区号是否合法
    if(num_pattern.exec(checkbcity)){
        if(checkbcity.length<3){
            alert("请输入正确参数");
            return;
        }
    }
    if(num_pattern.exec(checkecity)){
        if(checkecity.length<3){
            alert("请输入正确参数");
            return;
        }
    }
    
    //判断始发站点是否为空
    if(checkbcity.length==0||checkbcity==""){
        alert("始发站不能为空啊");
        return;
    }
    
    //判断终点站是否为空
    if(checkecity==""||checkecity==null||checkecity.length==0){
        alert("终点城市不能为空啊");
        return;
    }
    
    //判断城市名是否相同
    if(checkbcity!=""&&checkbcity == checkecity){
        alert("城市名不能相同啊");
        return;
    }
    
    //var hc = document.getElementById("hc").value;
    var hc = " ";
    if(document.getElementById("hc")!=null){
        hc = document.getElementById("hc").value;
    }else{
        hc = "320700";
    } 
   
    checkbcity = getCityCodeByAll(checkbcity);
    checkecity = getCityCodeByAll(checkecity);
    var siteName = "";
     if(document.getElementById('f1')){           
            siteName = "http://www.che-piao.com";
     }
    window.location = siteName + "/d-l-s-"+checkbcity+"-"+checkecity+"-0-0.html";
    
}

//第三个搜索  按照车次号进行搜搜

function searchbasetnumid(){
    var simtnumid = trim(document.getElementById("simtnumId").value);
    
    if(simtnumid=='输入车次号（例：0518.A001）'){
        simtnumid = '';
    }
    
    if(simtnumid==""||simtnumid==null||simtnumid.length==0){
       alert("请输入车次号");
       return;
    }    
     var siteName = "";
     if(document.getElementById('f1')){           
            siteName = "http://www.che-piao.com";
     }
    window.location = siteName + "/d-ls-s-"+escape(simtnumid)+".html";
}

//第四个搜索，按照站点搜索
function searchbasestation2(){
    var stationName = '';
    if(document.getElementById("stationname")){
        stationName = document.getElementById("stationname").value;
    }
    else{
        if(document.getElementById("Text2")){
            stationName = document.getElementById("Text2".value);
        }
    }
    
    
   
    if(stationName == '输入车站名'){
        stationName = '';
    }    
    if(stationName == ''){
        alert("请输入车站名称关键字");
        return;
    }        
    var siteName = "";
     if(document.getElementById('f1')){           
            siteName = "http://www.che-piao.com";
     }
    var url = siteName + "/s-s-"+encodeURI(stationName)+".html";    
	
    window.location.href = url;    
}
function GetCityCodeByStationName(){   
    if(http_request.readyState==4){
	    if(http_request.status==200){
		    var code=http_request.responseText;
		    window.location = "/d-l-s-"+code+"-0-0-0.html";
	    }else{
		    alert("您所请求的页面有异常。");
	    }
    }
}
//----------------------------------------------------->搜索方法结束




//---------------------------始发站的下拉框联动---------------------------------------------------

 //省份的下拉框值改变时
 //市的下拉框的值跟着改变
function changsheng(va,cityControlName)
{       
    if(va!='0')
    {
        var f=document.getElementById(cityControlName);
        var citysArr = getCitysByProvinceCode(va);     
        if(f.options.length > 1){//clear olditems
            for(var i=f.options.length-1;i>0;i--){
                f.options.remove(i);
            }
        }
        for(var i=0;i<citysArr.length;i++){
            f.add(new Option(citysArr[i][1],citysArr[i][0]));
        }
    }
    
}

//市的下拉框的值改变时
function changshi(va)
{
    if(va!='0')
    { 
        var qu = document.getElementById("bstation");       
        //改变市时，提交ajax请求      
        if(document.getElementById('f1')){           
            siteName = "http://www.che-piao.com";
            var url=siteName + "/ashxfile/Getcities.ashx?type=shi&id="+va; 
	        f1.send_request("GET",url,null,"text",populateClass4);
        }else{
            
            var url="/ashxfile/Getcities.ashx?type=shi&id="+va;             
	        send_request("GET",url,null,"text",populateClass4);
        }   
    }
}
//站点信息跟着变
function populateClass4(){
     var f=document.getElementById("bstation");
     if(document.getElementById('f1')){        
        if(f1.http_request.readyState==4){
	        if(f1.http_request.status==200){
		        var list=f1.http_request.responseText;
		        var classList=list.split("|");
		        f.options.length=1;
		        for(var i=0;i<classList.length;i++){
			        var tmp=classList[i].split(",");
			        f.add(new Option(tmp[1],tmp[0]));
		        }
	        }else{
		        alert("您所请求的页面有异常。");
	        }
        }
     }else{       
        if(http_request.readyState==4){
	        if(http_request.status==200){
		        var list=http_request.responseText;
		        var classList=list.split("|");
		        f.options.length=1;
		        for(var i=0;i<classList.length;i++){
			        var tmp=classList[i].split(",");
			        f.add(new Option(tmp[1],tmp[0]));
		        }
	        }else{
		        alert("您所请求的页面有异常。");
	        }
        }
    }
}


//-------------终点站联动----------------------------------------------------------------------


//市的下拉框的值改变时
function e_changshi(va)
{
    if(va!='0')
    {
        var qu = document.getElementById("estation");
        var siteName = "";
        if(document.getElementById('f1')){
            siteName = "http://www.che-piao.com";
            var url=siteName + "/ashxfile/Getcities.ashx?type=shi&id="+va;
	        f1.send_request("GET",url,null,"text",e_populateClass4);
	    }else{
	        var url="/ashxfile/Getcities.ashx?type=shi&id="+va;
	        send_request("GET",url,null,"text",e_populateClass4);
	    }
    }
}
//站点信息跟着变
function e_populateClass4(){
    var f=document.getElementById("estation");
    if(document.getElementById('f1')){
        if(f1.http_request.readyState==4){
	        if(f1.http_request.status==200){
		        var list=f1.http_request.responseText;
		        var classList=list.split("|");
		        f.options.length=1;
		        for(var i=0;i<classList.length;i++){
			        var tmp=classList[i].split(",");
			        f.add(new Option(tmp[1],tmp[0]));
		        }
	        }else{
		        alert("您所请求的页面有异常。");
	        }
        }
    }else{
        if(http_request.readyState==4){
	        if(http_request.status==200){
		        var list=http_request.responseText;
		        var classList=list.split("|");
		        f.options.length=1;
		        for(var i=0;i<classList.length;i++){
			        var tmp=classList[i].split(",");
			        f.add(new Option(tmp[1],tmp[0]));
		        }
	        }else{
		        alert("您所请求的页面有异常。");
	        }
        }
    }
}
	
	

