// #号和&符号转义
function StrCode(str)
{
    if(encodeURIComponent)
    {
        return encodeURIComponent(str);
    }
    if(escape)
    {
        return escape(str);
    }
    return str;
}
var site_conf = {
    'chinaagriculturenet':{
        'product':'/*-products.html',
        'company':'/*-company.html'
    },
    'china-homegarden':{
        'product':'/*-products.html',
        'company':'/*-companies.html'
    },
    'electric-equipments':{
        'product':'/sale-*.html',
        'company':'/supplier-*.html'
    },
    'textiles-leather':{
        'product':'/*-products.html',
        'company':'/*-manufacturers.html'
    },
    'china-telecommunications':{
        'product':'/*-products.html',
        'company':'/*-manufacturers.html'
    },
    'isp.org.cn':{
        'product':'/*-products.html',
        'company':'/*-manufacturers.html'
    },
    'tjskl.org.cn':{
        'product':'/sale-*/',
        'company':'/*-suppliers/'
    },
    'everychina.com':{
        'all':'/web-*/',
        'travel':'/t-*/',
        'culture':'/c-*/',
        'facts':'/e-*/',
        'business':'http://biz.everychina.com/*-products/'
    },
    'biz.everychina.com':{
        'product':'/*-products/',
        'company':'/*-companies/'
    }
}
function del_kw(kw){
    kw=kw.replace(new RegExp('[^a-zA-Z0-9\-]+','g'),'_').toLowerCase()
    kw=kw.replace(new RegExp("-+", "gi"), "_");
    kw=kw.replace(/(^[_\\^]*)/g, "").replace(/([_\\^]*$)/g, "");
    return kw
}

//判断是否中文
function checkChineseStr(str) {
    if(str.length == 0)
        return false;
    var result = false;
    var words = '';
    var wordpos = 0;
    for(i = 0; i < str.length; i++)
    {
        if(str.charCodeAt(i) > 128) {
            var strbak = str;
            if(result) {
                if((wordpos+1) == i) {
                    words = words + strbak.substring(i,i+1);
                }else{
                    words = words + "," + strbak.substring(i,i+1);
                }
                wordpos = i;
            }else{
                words = strbak.substring(i,i+1);
                wordpos = i;
            }
            result = true;
        }
    }
    if(result) {
        return words;
    }
    return false;
}

function search_action(form,website){
    if (form.kw.value == "" || form.kw.value == 0) {
        form.kw.focus();
        return false;
    }
    if(checkChineseStr(form.kw.value)){
        form.kw.focus();
        return false;
    }
    var kw = del_kw(form.kw.value)
    var static_url;
    var src = form.src.value;
    if (site_conf[website]) {
        static_url = site_conf[website][src].replace('*',kw);
        //window.open(static_url);
        window.location = static_url;
    //top.location = static_url;
    }
    return false;
}

function search_bottom(form,website){
    if (form.kw_bottom.value == "") {
        form.kw_bottom.focus();
        return false;
    }
    var kw = del_kw(form.kw_bottom.value)
    var static_url;
    var src = form.src_bottom.value;
    if (site_conf[website]) {
        static_url = site_conf[website][src].replace('*',kw);
        top.location = static_url;
    }
    return false;
}
//图片缩放
function setImgSize(theURL,sImage,stand,ctand) {
    var imgObj;
    var sizeStand=stand;
    var CStand=ctand;
    if(arguments.length>=3) {
        sizeStand=arguments[2];
    }
    imgObj=new Image();
    imgObj.src=theURL;
    if(ctand==0) {
        if((imgObj.width!=0)&&(imgObj.height!=0)) {
            if(imgObj.width>sizeStand||imgObj.height>sizeStand) {
                if(imgObj.width>imgObj.height) {
                    var iHeight=imgObj.height*sizeStand/imgObj.width;
                    sImage.height=iHeight;
                    sImage.width=sizeStand;
                }
                else {
                    var iWidth=imgObj.width*sizeStand/imgObj.height;
                    sImage.width=iWidth;
                    sImage.height=sizeStand;
                }
            }
            else {
                sImage.width=imgObj.width;
                sImage.height=imgObj.height;
            }
        }
        else {
            sImage.width=sizeStand;
            sImage.height=sizeStand;
        }
    }
    else {
        if((imgObj.width!=0)&&(imgObj.height!=0)) {
            if(imgObj.width>sizeStand||imgObj.height>CStand) {
                var wi=imgObj.width/sizeStand;
                var hi=imgObj.height/CStand;
                if(wi>hi) {
                    var iHeight=imgObj.height*sizeStand/imgObj.width;
                    sImage.height=iHeight;
                    sImage.width=sizeStand;
                }
                else {
                    var iWidth=imgObj.width*CStand/imgObj.height;
                    sImage.width=iWidth;
                    sImage.height=CStand;
                }
            }
            else {
                sImage.width=imgObj.width;
                sImage.height=imgObj.height;
            }
        }
        else {
            sImage.width=sizeStand;
            sImage.height=CStand;
        }
    }
}


