﻿function LoadSpecialSort(eName, val){
    var ids = val.split(',');
    var len = ids.length;
    var obj = null;
    
    for(i=0; i<len; i++){
        if(ids[i].length == 0){
            continue;
        }
        
        obj = document.getElementById(eName +'_'+ ids[i]);
        if(obj){
            obj.checked = true;
        }
    }    
}
/* region dropdownlist control */
function RegionCountryChange(val){
    RegionBindData('countryId', val, 'Province');
}
function RegionProvinceChange(val){
    RegionBindData('provinceId', val, 'City');
}
function RegionBindData(pName, pValue, name){
    var cmd = new RemoteCommand('Region', name);
    cmd.SetParameter(pName, pValue);

    var xml = cmd.Execute().ReturnValue;
    var oXml = LoadXmlDoc(xml);
    
    var nodelist1 = null;
    if(document.all)
    {
        nodelist1 = oXml.selectNodes('/region/'+ name.toLowerCase());
    }
    else
    {
        nodelist1 = oXml.documentElement.getElementsByTagName(name.toLowerCase());
    }
    
    var names = '';
    switch(name){
        case 'Province':
            names += 'Province,City';
            break;
        case 'City':
            names += 'City';
            break;
    }
    
    var ddl = null;
    var ddls = names.split(',');
    var length = ddls.length - 1;
    for(i=length; i>-1; i--){
        ddl = document.getElementById('ddl'+ ddls[i]);
        ddl.options.length = 1;
	    ddl.options[0].selected = true;
    }
    
    var value = null;
    var text = null;
    var length = nodelist1.length;
    for(i=0; i<length; i++){
        value = nodelist1[i].getAttribute("id");
        text = nodelist1[i].getAttribute("name");
        ddl.options[i+1] = new Option(text, value);
    }
}
/* golf dropdownlist contro */
function GolfCityChange(val){
    GolfBindData('cityId', val, 'Club');
}
function GolfClubChange(val){
    GolfBindData('clubId', val, 'Court');
}
function GolfBindData(pName, pValue, name){
    var cmd = new RemoteCommand('Golf', name);
    cmd.SetParameter(pName, pValue);

    var xml = cmd.Execute().ReturnValue;
    var oXml = LoadXmlDoc(xml);
    
    var nodelist1 = null;
    if(document.all)
    {
        nodelist1 = oXml.selectNodes('/golf/'+ name.toLowerCase());
    }
    else
    {
        nodelist1 = oXml.documentElement.getElementsByTagName(name.toLowerCase());
    }
    
    var names = '';
    switch(name){
        case 'Club':
            names += 'Club,Court';
            break;
        case 'Court':
            names += 'Court';
            break;
    }
    
    var ddl = null;
    var ddls = names.split(',');
    var length = ddls.length - 1;
    for(i=length; i>-1; i--){
        ddl = document.getElementById('ddl'+ ddls[i]);
        ddl.options.length = 1;
	    ddl.options[0].selected = true;
    }
    
    var value = null;
    var text = null;
    var length = nodelist1.length;
    for(i=0; i<length; i++){
        value = nodelist1[i].getAttribute("id");
        text = nodelist1[i].getAttribute("name");
        ddl.options[i+1] = new Option(text, value);
    }
}

/*
改变省份，列表城市
新增加
王海洋
*/
function RegionProvinceChangeCity(val, cityControlName){
    RegionBindDataCity('provinceId', val, 'City', cityControlName);
}
function RegionBindDataCity(pName, pValue, name, cityControlName){
    var cmd = new RemoteCommand('Region', name);
    cmd.SetParameter(pName, pValue);

    var xml = cmd.Execute().ReturnValue;
    var oXml = LoadXmlDoc(xml);
    
    var nodelist1 = null;
    if(document.all)
    {
        nodelist1 = oXml.selectNodes('/region/'+ name.toLowerCase());
    }
    else
    {
        nodelist1 = oXml.documentElement.getElementsByTagName(name.toLowerCase());
    }
    
    var names = '';
    switch(name){
        case 'Province':
            names += 'Province,City';
            break;
        case 'City':
            names += 'City';
            break;
    }
    
    var ddl = null;
    var ddls = names.split(',');
    var length = ddls.length - 1;
    ddl = document.getElementById(cityControlName);
    for(i=length; i>-1; i--){
        ddl.options.length = 1;
	    ddl.options[0].selected = true;
    }
    
    var value = null;
    var text = null;
    var length = nodelist1.length;
    for(i=0; i<length; i++){
        value = nodelist1[i].getAttribute("id");
        text = nodelist1[i].getAttribute("name");
        ddl.options[i+1] = new Option(text, value);
    }
}
function CheckValid(strCity,strProvince,strIsTraining,strNotIsTraining,isTraining,courtName,greenFee1,greenFee2 )
{
        var province = window.document.getElementById(strProvince).value;
        var city =  window.document.getElementById(strCity).value;
        var CourtName =  window.document.getElementById(courtName).value;
        var GreenFee1 = window.document.getElementById(greenFee1).value;
        var GreenFee2 = window.document.getElementById(greenFee2).value;
        var Training;
        

        if(window.document.getElementById(strIsTraining)==null)
        {
            if(isTraining=="True")
            {
                Training=1;
            }
            else
            {
                Training=0;
            }
        }
        else
        {
            if( window.document.getElementById(strIsTraining).checked == true)
                Training = 1;
            else
                Training = 0;
        }
        
        if(province == 0 && city ==0 && CourtName.length == 0 && GreenFee1.length == 0 && GreenFee2.length ==0)
        {
            alert("请输入搜索条件!");
            return false;
        }
        if( GreenFee1.length != 0 )
        {
            if(!isNumber(GreenFee1))
            {
                alert("请正确输入果岭费!");
                return false;
            }
        }
        
        if( GreenFee2.length != 0 )
        {
            if(!isNumber(GreenFee2))
            {
                alert("请正确输入果岭费!");
                return false;
            }
        }
        if(GreenFee1.length !=0 &&  GreenFee2.length != 0 )
        {
            if(GreenFee1 > GreenFee2)
            {
                alert("请正确输入果岭费,结束费大于开始费!");
                return false;
            }
        }
        var url ="Golf/Court.aspx?ProvinceId="+province+"&CityId="+city+"&IsTraining=" + Training + "&CourtName=" + CourtName + "&GreenFee1="+GreenFee1+"&GreenFee2=" +GreenFee2;
        window.open(url);
        return true;
}


//验证是否为数字
function isNumber(oNum)
{
    if(!oNum)
        return false;
    var strP=/^\d+(\.\d+)?$/;
    if(!strP.test(oNum))
        return false;
    try
    {
        if(parseFloat(oNum)!=oNum) return false;
    }
    catch(ex)
    {
        return false;
    }
    return true;
}