﻿function SetRegionLink(type, the) {
    AddRegionLinkCssClass();
    the.className = 'buttom_img_0032';

    if (type == 'lingshou') {
        document.getElementById('region_lingshou_div').style.display = '';
        document.getElementById('region_liansuo_div').style.display = 'none';
        document.getElementById('region_pifa_div').style.display = 'none';
        document.getElementById('theGeDiYaoFang').innerHTML = "各地零售";
        document.getElementById('theHrefGeDiYaoFang').href = "/RegionShopList.aspx?shoptype=0";
    }
    else if (type == 'liansuo') {
        document.getElementById('region_liansuo_div').style.display = '';
        document.getElementById('region_lingshou_div').style.display = 'none';
        document.getElementById('region_pifa_div').style.display = 'none';
        document.getElementById('theGeDiYaoFang').innerHTML = "各地连锁";
        document.getElementById('theHrefGeDiYaoFang').href = "/RegionShopList.aspx?shoptype=0";
    }
    else if (type == 'pifa') {
        document.getElementById('region_pifa_div').style.display = '';
        document.getElementById('region_lingshou_div').style.display = 'none';
        document.getElementById('region_liansuo_div').style.display = 'none';
        document.getElementById('theGeDiYaoFang').innerHTML = "各地公司";
        document.getElementById('theHrefGeDiYaoFang').href = "/RegionShopList.aspx?shoptype=1";
    }
}

function AddRegionLinkCssClass() {
    document.getElementById('theLingShouRegionLinks').className = 'buttom_img_0033';
    document.getElementById('theLianSuoRegionLinks').className =  'buttom_img_0033';
    document.getElementById('thePiFaRegionLinks').className =  'buttom_img_0033';
}

/*搜索*/
function URLEncode(clearString) {
    var output = '';
    var x = 0;
    clearString = clearString.toString();
    var regex = /(^[a-zA-Z0-9_.]*)/;
    while (x < clearString.length) {
        var match = regex.exec(clearString.substr(x));
        if (match != null && match.length > 1 && match[1] != '') {
            output += match[1];
            x += match[1].length;
        } else {
            if (clearString[x] == ' ')
                output += '+';
            else {
                var charCode = clearString.charCodeAt(x);
                var hexVal = charCode.toString(16);
                output += '%u' + (hexVal.length < 2 ? '0' : '') + hexVal.toUpperCase();
            }
            x++;
        }
    }
    return output;
}

function SubmitOnEnter(myfield, e, bit) {
    var keycode;
    if (window.event)
        keycode = window.event.keyCode;
    else if (e)
        keycode = e.which;
    else
        return true;
    if (keycode == 13) {
        if (bit == 1) {
            SearchSite();
        }
        else if (bit == 2) {
            SearchYaoFangWang();
        }
        return false;
    }
    else
        return true;
}

function SearchSite() {
    var searchText = Trim(document.getElementById('searchText').value);
    if (searchText == '') {
        document.getElementById('searchText').focus();
        return;
    }
    var searchSite = '';
    var filterSearchTitle = document.getElementById('filterSearchTitle').innerHTML;

    if (filterSearchTitle == '本站') {
        document.location.href = "http://yaodian.yaofangwang.com/SearchYaoFangWang.aspx?cx=009090521981035216729%3Ak5l9aw6vyvg&cof=FORID%3A11&ie=UTF-8&q=" + document.getElementById('searchText').value + "&sa=搜索";
        return false;
    }
    else if (filterSearchTitle == '药店') {
        searchSite = '/Search.aspx?keywords=';
    }
    else if (filterSearchTitle == '药品') {
    searchSite = 'http://yao.yaofangwang.com/search.aspx?keywords=';
    }
    else if (filterSearchTitle == '药厂') {
    searchSite = 'http://yaochang.yaofangwang.com/search.aspx?keywords=';
    }
    else if (filterSearchTitle == '疾病') {
    searchSite = 'http://bing.yaofangwang.com/search.aspx?keywords=';
    }
    else if (filterSearchTitle == '医院') {
    searchSite = 'http://yiyuan.yaofangwang.com/search.aspx?keywords=';
    }
    else {
        searchSite = '/Search.aspx?keywords=';
    }
    //document.location.href = searchSite + URLEncode(Trim ( document.getElementById('searchText').value ) );
    document.location.href = searchSite + encodeURI(searchText);
}

function SearchYaoFangWang() {
    document.location.href = "http://yaodian.yaofangwang.com/SearchYaoFangWang.aspx?cx=009090521981035216729%3Ak5l9aw6vyvg&cof=FORID%3A11&ie=UTF-8&q=" + URLEncode(Trim ( document.getElementById('txtSearchYaoFangWang').value ) )+ "&sa=搜索";
}

//TAB疾病目录切换
function doClick1(o) {
    o.className = "t_buttonbg_a";
    var j;
    var id;
    var b;
    for (var i = 1; i <= 3; i++) {
        id = "bb" + i;
        j = document.getElementById(id);
        b = document.getElementById("b" + i);
        if (id != o.id) {
            j.className = "t_buttonbg_b";
            b.style.display = "none";
        } else {
            b.style.display = "";
        }
    }
}

//删除左右两边的空格
function Trim( text ){  
 return text.replace(/(^\s*)|(\s*$)/g, "");
}

//单点登录
function GetXmlHttpObject(handler) {
    var objXmlHttp = null;
    if (navigator.userAgent.indexOf("Opera") >= 0) {
        alert("不支持Opera浏览器");
        return false;
    }
    if (navigator.userAgent.indexOf("MSIE") >= 0) {
        var strName = "Msxml2.XMLHTTP";
        if (navigator.appVersion.indexOf("MSIE 5.5") >= 0) {
            strName = "Microsoft.XMLHTTP";
        }
        try {
            objXmlHttp = new ActiveXObject(strName);
            objXmlHttp.onreadystatechange = handler;
            return objXmlHttp;
        }
        catch (e) {
            alert("Error. Scripting for ActiveX might be disabled");
            return false;
        }
    }
    if (navigator.userAgent.indexOf("Mozilla") >= 0) {
        objXmlHttp = new XMLHttpRequest();
        objXmlHttp.onload = handler;
        objXmlHttp.onerror = handler;
        return objXmlHttp;
    }
}

function ChckCheckUserLogin() {
    var textUserName = document.getElementById('textUserName').value;
    var textPassword = document.getElementById('textUserPass').value;
    if (Trim(textUserName) == "") {
        alert('用户名不可为空');
        document.getElementById('textUserName').focus();
        return false;
    }
    if (Trim(textPassword) == "") {
        alert('密码不可为空');
        document.getElementById('textUserPass').focus();
        return false;
    }
    var url = "/CheckUserLogin.aspx?username=" + URLEncode(Trim(textUserName)) + "&encpass=" + Trim( textPassword );
    xmlHttp = GetXmlHttpObject(stateChanged);
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function stateChanged() {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        var result = xmlHttp.responseText;
        var textUserName = document.getElementById('textUserName');
        var textPassword = document.getElementById('textUserPass');
        if (result == "false") {
            document.location.href = "http://reg.yaofangwang.com/Default.aspx?lsLogin=0";
            return;
        }
        else {
            document.location.href = "http://reg.yaofangwang.com/CheckUserLogin.aspx?enc=" + result + "&userName=" + URLEncode(Trim(textUserName.value)) + "&fromto=" + encodeURI( window.location.href );
        }
    }
}

//锁屏幕
function skm_LockScreen(str) {
    scroll(0, 0);
    var back = document.getElementById('skm_LockBackground');
    var pane = document.getElementById('skm_LockPane');
    var text = document.getElementById('skm_LockPaneText');

    if (back)
        back.className = 'LockBackground';
    if (pane)
        pane.className = 'LockPane';
    if (text)
        text.innerHTML = str;
}