var PhoneArray = ['400-000-8888', '400-000-8888', '400-000-8888', '400-000-8888', '400-000-8888', '400-000-8888', '400-000-8888', '400-000-8888', '400-000-8888','400-000-8888','400-000-8888','400-000-8888','400-000-8888'];

function GetPhone400() {
    document.write(GetPhone());
}

function GetLink400() {
    var ph400 = GetPhone();   
     document.write("<a href=\"javascript:void(0)\" onclick=\"openwindow('"+ph400+"','')\" class=\"btn_tel\" title=\"免费咨询\"></a>");
     
}

function GetImg400() {
    var ph400 = GetPhone();
    document.write("<a href=\"javascript:void(0)\" onclick=\"openwindow('"+ph400+"','')\" >"+ph400+"</a>");
      
}

//地图使用
function GetCity400(tel) {
    var ph400 = GetPhone();
    return "<a href=\"javascript:void(0)\" onclick=\"openwindow('"+ph400+"','"+tel+"')\"><img src=\"http://jhcity.zgjhjy.com/images/baidubtntel.png\"  border=\"0\" style=\"margin-left:5px;\"></a>";
     
}

//课程使用
function GetCityCourse400(tel) {
    var ph400 = GetPhone();
    openwindow(ph400,tel);
   
}
//咨询使用
function GetCityZXP400(tel) {
    var ph400 = GetPhone();
    openwindow(ph400,tel);
   
}
//底部电话使用
function GetCityDi400(tel) {
    var ph400 = GetPhone();
    document.write("<a href=\"javascript:void(0)\" onclick=\"openwindow('"+ph400+"','"+tel+"')\"><span class=\"f_red\">"+ph400+"</span> 转 <span class=\"f_red\">" + tel + "</span></a>"); 
}

//弹出电话使用
function GetCityPiao400(tel) {
    var ph400 = GetPhone();
    document.write("<a href=\"javascript:void(0)\" onclick=\"openwindow('"+ph400+"','"+tel+"')\">"+ph400+"<i>转</i>" + tel + "</a>");
     
}




function GetPhone() {
    //获得来源地址和当前页面地址
    //var cUrl = document.referrer;
    var rqUrl = window.location.href;

    var f = GetParam(rqUrl, "f").toLowerCase();
    var k = GetParam(rqUrl, "k").toLowerCase();

//alert(window.location.href);
if(rqUrl.toLocaleLowerCase().indexOf("bj.zgjhjy.com") > 0 ) {
 return caozuo(9);
} 
if(rqUrl.toLocaleLowerCase().indexOf("guangzhou.zgjhjy.org") > 0 ||rqUrl.toLocaleLowerCase().indexOf("shanghai.zgjhjy.org") > 0||rqUrl.toLocaleLowerCase().indexOf("wuhan.zgjhjy.org") > 0||rqUrl.toLocaleLowerCase().indexOf("chongqing.zgjhjy.org") > 0) {
 return caozuo(11);
} 
    //第一版 先判断参数
    if (f == "") {
        if (cookie("phone400") != "")
            return getCookie("phone400");
        else
            return caozuo(1);
    }
    else {
        if (f == "baidusem") { //百度
            if (k == "pinpai") //品牌                
                return caozuo(0);
            else if (k == "jingjia")
                return caozuo(7);     
            else
                return caozuo(1);
        }
        else if( f=="baiduads")
        {
            return caozuo(2);
        }
        else if (f == "googlesem") {
                return caozuo(2);           
        }
        else if (f == "koubei") {
            if (k == "")
                return caozuo(3);
            else
                return caozuo(1);
        }
        else if (f == "sogousem") {
            return caozuo(4);
        }
        else if (f == "360sem") {
            return caozuo(5);
        }
        else if (f == "bianji") {
            return caozuo(6);
        }
        else if (f == "baidumedia") {
            return caozuo(8);
        }
        else if (f == "bjsem") {
            return caozuo(9);
        }
        else if (f == "allyes") {
            return caozuo(10);
        }
        else if (f == "emar") {
            return caozuo(11);
        }
        else {
            return caozuo(1);
        }
    }
}

function caozuo(id) {
    delCookie("phone400");
    addCookie("phone400", PhoneArray[id], 0);
    return PhoneArray[id];
}

function GetParam(url, n) {
    if (!/\?/.test(url)) return '';
    var ret = "";
    var str = url.split("?")[1];
    var args = str.split("&");
    for (var i = 0; i < args.length; i++) {
        str = args[i].split('=');
        if (str.length < 2) continue;
        if (str[0] == n) ret = str[1];
    }
    return ret;
}

//获得coolie 的值
function cookie(name) {
    var cookieArray = document.cookie.split("; "); //得到分割的cookie名值对    
    var cookie = new Object();
    for (var i = 0; i < cookieArray.length; i++) {
        var arr = cookieArray[i].split("=");       //将名和值分开   
        if (arr[0] == name) return unescape(arr[1]); //如果是指定的cookie，则返回它的值    
    }
    return "";
}

function delCookie(name)//删除cookie
{
    document.cookie = name + "=;expires=" + (new Date(0)).toGMTString();
}

function getCookie(objName) {//获取指定名称的cookie的值
    var arrStr = document.cookie.split("; ");
    for (var i = 0; i < arrStr.length; i++) {
        var temp = arrStr[i].split("=");
        if (temp[0] == objName) return unescape(temp[1]);
    }
}

function addCookie(objName, objValue, objHours) {      //添加cookie
    var str = objName + "=" + escape(objValue);
    if (objHours > 0) {                               //为时不设定过期时间，浏览器关闭时cookie自动消失
        var date = new Date();
        var ms = objHours * 3600 * 1000;
        date.setTime(date.getTime() + ms);
        str += "; expires=" + date.toGMTString();
    }
    document.cookie = str;
}


//function getCookie(name)//取cookies函数       
//{
//    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
//    if (arr != null) return unescape(arr[2]); return null;
//}

function delCookie(name)//删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
