/**
 * DIV切换
 * hidDivs:需要隐藏的DIV.格式"#autotj .autolist"
 * showDivId:需要显示的DIV.格式"xinche"
 */
function switchDiv(hidDivs,showDivId,delClasses,onClassId,className){
	try{
    
    if(className!=""&&delClasses!=""){
        $(delClasses).removeClass(className);
    }
	if(className!=""&&onClassId!=""){
        $("#"+onClassId).addClass(className);
    }
	$(hidDivs).css("display","none");
    $("#"+showDivId).css("display","");
	}catch(e){
	}
}
/**
 * 品牌选择车系
 * url:远程数据地址
 * selectName:select标签name
 */
function switchSelect(url,id,selectName){
    try{
        $.getJSON(url+id, function(json){
            $("#"+selectName).empty();
            $("#"+selectName).append("<option value='0'>===\u8bf7\u9009\u62e9\u8f66\u7cfb===</option>");
            if(json!=null){
                var number = 0;
                var chexingId;
                $.each(json.returndata, function(i,item){
                    ++number;
                    chexingId = item.Id;
                    $("#"+selectName).append("<option value='"+item.Id+"'>"+item.seriesname+"</option>");
                });
                if(number==1){
                    switchSelectModel('http://depot.at160.com/api/api_brsecar.php?sort=autotype&retype=jsjson&jsoncallback=?&id=',chexingId,'chexing');
                }else{
                    $("#chexing").empty();
                    $("#chexing").append("<option value='0'>===\u8bf7\u9009\u62e9车\u578b===</option>");
                }
            }
        });
    }catch(e){}
}
/**
* 选择车型
 */
function switchSelectModel(url,id,selectName){
    try{
        $.getJSON(url+id, function(json){
            $("#"+selectName).empty();
            $("#"+selectName).append("<option value='0'>===\u8bf7\u9009\u62e9车\u578b===</option>");
            if(json!=null){
                $.each(json.returndata, function(i,item){
                    $("#"+selectName).append("<option value='"+item.Id+"'>"+item.typename+"</option>");
                });
            }
        });
    }catch(e){}
}
/**
* 车型搜索
*/
function searchCar(pinpai,chexi,chexing){
    var pinpaiUrl = "http://depot.at160.com/car/brand/[id].html";
    var chexiUrl = "http://depot.at160.com/car/series/[id].html";
    var chexingUrl = "http://depot.at160.com/car/autotype/[id].html";
    if($('#'+chexing).val().length==32){
        //        location.href=chexingUrl.replace("[id]", $('#'+chexing).val());
        window.open(chexingUrl.replace("[id]", $('#'+chexing).val()));
    }else if($('#'+chexi).val().length==32){
        window.open(chexiUrl.replace("[id]", $('#'+chexi).val()));
    }else if($('#'+pinpai).val().length==32){
        window.open(pinpaiUrl.replace("[id]", $('#'+pinpai).val()));
    }else{
        $("#"+pinpai).focus();
    }
}

/**
*  根据不同地区,显示新闻信息
 */
function showNews(hidDivs,showDivId,boxId,title,callback){
    $(hidDivs).css("display","none");
    $("#"+showDivId).css("display","");
    $("#"+boxId).html(title);
    try{
        callback;
    }catch(e){}
}
/**
 * url:ip地址调用
 * callback:回调函数
 * hidDivs:隐藏Div的jquery名称
 * boxId:文本显示id
 * title:文本信息
 */
function loadShowNews(url,callback,hidDivs,boxId,title){
    try{
        divOut('headtxt');
        divOut('citybox');
        divOut('selectcity');
        $.getJSON(url, function(json){
            if(json!=null){
                callback(hidDivs,json.returndata.simplename,boxId,json.returndata.cnname+title);
            }
        });
    }catch(e){}
}
/**
*   鼠标移出事件
 */
function divOut(divId){
    $("#"+divId).hover(function(){
        showBox(true);
    },function (){
        showBox(false);
    });
}
