﻿//company search
function companySearchSubmit(){
    var pid;
    var k; 
    var pObj = document.getElementById('pid');
    var kObj = document.getElementById('input_k');   
    if(pObj){
        pid = pObj.value; 
    }else{
        var url = window.location.href;
        var r1 = new RegExp(/Pager(\d+)\.aspx/gi);
        if(r1.test(url)){
            pid = RegExp.$1;
        }else{
            pid = GetValueFromUrl('pid'); 
        } 
    }
    
    if(kObj){
        k = kObj.value; 
    }else{
        k = GetValueFromUrl('k'); 
    } 
    var rid = document.getElementById('rid').value;
    var tid = document.getElementById('tid').value;
    
    window.location.href = '/company/search.aspx?pid=' + pid + '&rid=' + rid + '&tid=' + tid + '&k=' + escape(k);
    return false; 
}

//exhibition search
function exhibitSearchSubmit(){
    var sid;
    var sortObj = document.getElementById('sid');
    if(sortObj){
        sid = sortObj.value; 
    }else{
        var url = window.location.href;
        var r1 = new RegExp(/Pager(\d+)\.aspx/gi);
        if(r1.test(url)){
            sid = RegExp.$1;
        }else{
            sid = GetValueFromUrl('sid'); 
        } 
    }
         
    var k = document.getElementById('input_k').value;
    
    window.location.href = '/exhibit/search.aspx?sid=' + sid + '&k=' + escape(k);
    return false; 
}

//download search
function downSearchSubmit(){
    var sid;
    var sortObj = document.getElementById('sid');
    if(sortObj){
        sid = sortObj.value; 
    }else{
        var url = window.location.href;
        var r1 = new RegExp(/Pager(\d+)\.aspx/gi);
        if(r1.test(url)){
            sid = RegExp.$1;
        }else{
            sid = GetValueFromUrl('sid'); 
        } 
    }
         
    var k = document.getElementById('input_k').value;
    
    window.location.href = '/down/search.aspx?sid=' + sid + '&k=' + escape(k);
    return false; 
}

//business and product search
function pagerSearchSubmit(url){    
    SetRoleValue('ddlParentRole', 'hdRoleIds');
    var sid;
    var k; 
    var sortObj = document.getElementById('sid');
    var kObj = document.getElementById('input_k');   
    if(sortObj){
        sid = sortObj.value; 
    }else{
        var u = window.location.href;
        var r1 = new RegExp(/Pager(\d+)\.aspx/gi);
        var r2 =  new RegExp(/Pager(\d+)-(\d+)\.aspx/gi);
        if(r1.test(u)){
            sid = RegExp.$1;
        }else if(r2.test(u)){
            sid = RegExp.$1;
        } 
        else{
            sid = GetValueFromUrl('sid'); 
        } 
    }
    
    if(kObj){
        k = kObj.value; 
    }else{
        k = GetValueFromUrl('k'); 
    } 
    var rid = document.getElementById('rid').value;
    var tid = document.getElementById('tid').value;
    var hrid = document.getElementById('hdRoleIds').value;
    
    window.location.href = url + '?sid=' + sid + '&rid=' + rid + '&tid=' + tid + '&hrid=' + hrid + '&k=' + escape(k);
    return false; 
}

//role init
function pagerInit(){
    var rid= document.getElementById('rid');
    var tid= document.getElementById('tid');
    var ddlrole = document.getElementById('ddlParentRole');
    var hrid = GetValueFromUrl('hrid');
   
   //通过搜索的等级编号，找到该会员的父等级ID
    var cmd = new RemoteCommand('Platform', 'GetRoleParentId');
    cmd.SetParameter('roleId',hrid);
    var parentId = cmd.Execute().ReturnValue;
    
    //选择为父类时，只绑定父类
    if(parentId == 0){
        ddlrole.value = hrid;
    } 
    else{    
        //先绑定父类，在绑定子类
       for(var i=0;i<ddlrole.options.length;i++){
       if(ddlrole[i].value == parentId){
             ddlrole.selectedIndex=i;
             break;
             }
        }         
        SetChildRole(ddlrole, 'ddlNewRole', '== 请选择 ==');
        var ddlChildRole = document.getElementById('ddlChildRole');
        if(ddlChildRole){
            ddlChildRole.value = hrid;
        }
   }   
    //绑定地址
   if(rid.options){ 
       for(var i=0;i<rid.options.length;i++){
           if(rid[i].value==GetValueFromUrl('rid')){
                 rid.selectedIndex=i;
                 break;
             }
       }
   }
    //绑定搜索的发布时间 
   for(var i=0;i<tid.options.length;i++){
       if(tid[i].value==GetValueFromUrl('tid')){
             tid.selectedIndex=i;
             break;
         }
   }
}

//招聘首页搜索
function jobSearchSubmit(dateId){
    if(!dateId){
        dateId = 'date'; 
    } 
    var rid = document.getElementById('RegionTreeDropDown1').value;
    var sid1 = document.getElementById('ddlStationParent').value;
    var sid2 = document.getElementById('sltStation').value; 
    var k = document.getElementById('input_keyword').value; 
    var date = document.getElementById(dateId).value;
    if(k == '公司/职位关键字')
    {
        k = '';
    }     
    window.location.href = '/job/jobs.aspx?rid='+rid+'&sid1='+sid1+'&sid2='+sid2+'&k='+encodeURI(k)+'&date='+date;
    return false; 
}

//简历搜索
function resumeSearchSubmit(dateId){
    if(!dateId){
        dateId = 'date'; 
    } 
    var rid=document.getElementById('RegionTreeDropDown2').value;
    var sid1=document.getElementById('ddlStationParent2').value;
    var sid2=document.getElementById('sltStation2').value; 
    var date=document.getElementById(dateId).value;       
        
    window.location.href = '/job/resumes.aspx?rid='+rid+'&sid1='+sid1+'&sid2='+sid2+'&date='+date;
    return false; 
}

function JobOnSelect(o){
    if(o.value == '公司/职位关键字'){
        o.value='';
   }
}

//论坛

/*topic.aspx 页js代码 start*/
function OnSubmitReply(o){
    var cf = new CheckFormSubmit(o);
    
    var cbIsAnonymity = document.getElementById('cbIsAnonymity');
    if(!cbIsAnonymity || !cbIsAnonymity.checked){
        var tbMemberName = document.getElementById('tbMemberName');
        if(tbMemberName)
        {
            if(cf.ChkVal('tbMemberName', '', 220718)){
                return false;
            }
            
            if(cf.ChkVal('tbPassword', '', 220721)){
                return false;
            }
        }
    }
    
    if(cf.ChkVal('heContent', '', 240715)){
        return false;
    }
    
    if(dvIsVerifyCode.style.display != 'none'){
        if(cf.ChkVal('tbVerifyCode', '', 100722)){
            return false;
        }
    }
    return true;
}

function loadForumCtrl(evt, obj){
    var vmenu = document.getElementById('ctrlPanel').innerHTML;
    JsMenuShow(evt, vmenu, obj);
}

function Delete(o,tid){
    if(CheckIsCanDelete(tid)){
        if(confirm(GetResources(100747))){
            ReWriteHref(o);
            return true;
        }
    }
    return false;
}

function Deletes(o){
    if(confirm(GetResources(100747))){
        ReWriteHref(o);
        return true;
    }
    return false;
}

function Locked(o){
    ReWriteHref(o);
    return true;
}

function CheckIsCanDelete(tid){
    var cmd = new RemoteCommand('Interact', 'CheckIsCanDelete');
    cmd.SetParameter('topicId', tid);
    if(cmd.Execute().ReturnValue){
        return true;
    }
    else
    {
        alert(GetResources(240731));
        return false;
    }
}

/*topic.aspx 页js代码 end*/

/* 首页商业信息滚动效果 */
function bizAutoScroll(obj){
    $('#bizScrollDiv').find("ul:first").animate({
            marginTop:"-36px"
    },500,function(){
            $(this).css({marginTop:"0px"}).find("li:first,li:eq(1)").appendTo(this);
    });
}

/*新闻查询*/
function infoSearch(o,s,v){
    var sid =o["sid"].value;
    var k = o["k"].value;
    window.location.href = '/pub/Search.aspx?sid='+sid+'&k='+encodeURI(k);
}

/* 顶部搜索聚焦事件 */
function searchOnfocus(o){
    var k = o.value;
    if(k.substring(0,3) == "请输入"){
        o.value = '';
    }
    o.style.color='#000';
}

/* 顶部搜索提交验证 */
function checkTopSearch(frm, url){
    var o = document.getElementById("top_search");
    var v = o.value;
    if(o){ 
	    if(v.substring(0,3) =="请输入" || v.substring(0,3) == ""){
		    alert('请输入搜索条件');
		    o.focus();
		    return false;
	    }else{
	        frm.action = url;
	    } 
	}
}

/* 顶部搜索指定搜索action */
function searchCheck(o){
    var fromObj = document.getElementById('searchfrm');
    var typeObjs = document.getElementsByName('type');
    var type;
    for(var i = 0; i< typeObjs.length; i++){
        if (typeObjs[i].checked)
        {
            type = typeObjs[i].value;
            break;
        }
    }
    
    var span = document.getElementById('spanid');
    span.innerHTML= '';
     if(type=='1'){
        return checkTopSearch(o, '/Search.aspx');
    }
    if(type=="2"){
        return checkTopSearch(o, '/product/Search.aspx');
    }
    if(type=='3'){
        return checkTopSearch(o, '/pub/Search.aspx');
    }
    if(type=='4'){
        span.innerHTML='<input type=\"hidden\" name=\"sid\" value=\"4\" />';
        return checkTopSearch(o, '/biz/Search.aspx');
    }
     if(type=='5'){
        return checkTopSearch(o, '/Company/Search.aspx');
    }
}
/*综合搜索更多链接*/
function moreSearch(o, url){
    var k = GetValueFromUrl('k');
    if(url.indexOf('?') > -1){
        o.href = url + "&k=" + k; 
    }else{
        o.href = url + "?k=" + k; 
    }  
}

//各模块信息举报弹出窗口操作
function ShowOpenReport(tid,o,title){
    var cmd = new RemoteCommand('Platform', 'CheckUserIsLogin');
    var val = cmd.Execute().ReturnValue;
    var url =  HttpUrl();
    if(!val)
    {
        ReWriteUrl('/Member/Login.aspx');
    }

    var title=escape(title);
    ShowOpenWindow(650, 350,'/Interact/Report/InfoAct.aspx?tid=' + tid + '&id=' + o + '&title=' + title + '&url=' + escape(url), 86, 'hidden')
}

//留言

/*Commets.aspx 页js代码 start*/

//引用
function ShowReferInfo(infoId,id){
    ShowOpenWindow(600, 300, '/Interact/Comment/ReferAct.aspx?id=' + infoId + '&refid='+ id, 0, 'auto;overflow-x:hidden');
}

//删除
function InfoDelete(id){
     if(confirm(GetResources(100710))){
         HttpUrlCommand('/MyOffice/Interact/Comment/Actions.aspx?t=infopageact&act=delinfo&id='+id);
         LoadInfoPage();
     }
}

//支持
function InfoSupport(id){
   
    var cmd = new RemoteCommand('Interact', 'UpdateSupport');
    cmd.SetParameter('infoId', id);
    if(cmd.Execute().ReturnValue == true){
        alert(GetResources(100775));
        return false;
    }
    
    cmd.Execute();
    LoadInfoPage();  
    
    return true;  
}

//反对
function InfoObject(id){
     var cmd = new RemoteCommand('Interact', 'UpdateObject');
     cmd.SetParameter('infoId', id);
     if(cmd.Execute().ReturnValue == true){
        alert(GetResources(100775));
        return false;
    }
    
     cmd.Execute();
     LoadInfoPage()
     
     return true;
}

function InfoReply(infoId,id){
    ShowReplyInfo(infoId,id);
}

function ShowReplyInfo(infoId,id){
    var memberId = HttpUrlCommand('/Global/MemberId.aspx?', null, null);
    if(memberId == '4492A54C3CFC1E57' || memberId.length > 16){
        alert(GetResources(100703));
        return false;
    }
    
    var cmd = new RemoteCommand('Interact', 'CmtCheckIsEnableToReply');
    cmd.SetParameter('memberId', memberId);
    cmd.SetParameter('replyInfoId', id);
    
    var rval = cmd.Execute().ReturnValue;
    if(rval != null){
        alert(rval);
        return false;
    }
       
    ShowOpenWindow(600, 300, '/Interact/Comment/ReplyAct.aspx?id=' + infoId + '&repid='+ id + '&' + tokenKey(), 0, 'auto;overflow-x:hidden');
}

function LoadInfoPage(){
    var o =document.getElementById('divInfoContent');
    HttpUrlCommand(HttpUrl(), page_callback);
    
     CreatLoadingLayer(o);
    function page_callback(res){
        var re1 = new RegExp('<dl\\sid="divInfoContent"\\sclass="cmt_list1">([\\s\\S]+?)</dl>', 'img');
        if(re1.test(res) == true){
            o.innerHTML = RegExp.$1;
        }else{
            o.innerHTML = 'Loading Data Error';           
            return;
        }

       PageInit();
    }  
}

function PageInit(){
    var divs = document.getElementsByTagName('div');
    for(var i=0;i<divs.length;i++){
        if(divs[i].id=='divReplyContent'){
            if(divs[i].innerHTML != ''){
                if(document.all){
                    divs[i].style.display ='block';
                }else{
                    divs[i].style.display ='table-row';
                }
            }
        }
    }
}

function InfoConfirm(id,t){
    if(t){
        HttpUrlCommand('/MyOffice/Interact/Comment/Actions.aspx?t=infopageact&act=infoconfirmpass&id='+id);
    }
    else{
        HttpUrlCommand('/MyOffice/Interact/Comment/Actions.aspx?t=infopageact&act=infoconfirmfail&id='+id);
    }
     
     LoadInfoPage();
}

function InfoLocked(id,t){
    if(t){
        HttpUrlCommand('/MyOffice/Interact/Comment/Actions.aspx?t=infopageact&act=infohidden&id='+id);
    }
    else{
        HttpUrlCommand('/MyOffice/Interact/Comment/Actions.aspx?t=infopageact&act=infoshow&id='+id);
    }
    
    LoadInfoPage();
}
/*Commets.aspx 页js代码 end*/
function contrast_init(path){
    var contrast_off = $('.contrast_off');
    var contrast_ifm = $('.contrast_ifm');
    var iframe = $('iframe', contrast_ifm);
    var off_width = contrast_off.width();
    var off_height = contrast_off.height();
    var ifm_width = contrast_ifm.width();
    var ifm_height = contrast_ifm.height();
    var cookie_id = contrast_cookie_id(path);

    function load(exhibit){
        var outer_left = $('#outer').position().left;
        var outer_width = $('#outer').width();
        var scrol_top = $(window).scrollTop();
        var doc_height = $(window).height();
        
        var off_left = (outer_left + outer_width - off_width) +'px';
        var off_top = (doc_height - off_height) / 2 + scrol_top  +'px';
        contrast_off.css('left', off_left).css('top', off_top);
        
        var ifm_left = (outer_left + outer_width - ifm_width) +'px';
        var ifm_top = (doc_height - ifm_height) / 2 + scrol_top  +'px';
        contrast_ifm.css('left', ifm_left).css('top', ifm_top);
        
        if(exhibit == true){
            var ids = GetCookie(cookie_id);
            if(/\d/.test(ids)){
                show();
            }
        }
    }
    function show(){
        var pos = $(contrast_off).position();
        var ifm_right = (pos.left + off_width - ifm_width) +'px';
        contrast_ifm.css('left', ifm_right);
        contrast_ifm.show();

        var ids = GetCookie(cookie_id);
        if(/\d/.test(ids) && (typeof(iframe.attr('src')) == 'undefined' || iframe.attr('src') == '')){
            iframe.attr('src', path +'Contrasts.aspx?id='+ ids +'&token='+ tokenKey());
        }
    }
    
    $(window).bind('resize',function(){load(false);});
    $(window).bind('scroll',function(){load(false);});
    
    $('h1', contrast_ifm).click(function(){
        contrast_ifm.hide();
    });
    $('.contrast_go', contrast_ifm).click(function(){
        var ids = GetCookie(cookie_id);
        if(/\d/.test(ids) == false){
            alert(GetResources(100799));
        }else{
            window.open(path +'Contrast.aspx?id='+ ids);
        }
    });
    $('.contrast_del', contrast_ifm).click(function(){
        SetCookie(cookie_id, '');
        iframe.attr('src', path +'Contrasts.aspx?token='+ tokenKey());
        contrast_ifm.hide();
    });
    
    $(contrast_off).click(function(){
        show();
    });
    
    load(true);
}
function contrast_add(path, id){
    var hasnew = false;
    var cookie_id = contrast_cookie_id(path);
    var ids = GetCookie(cookie_id);
    if(id > 0){
        if(ids.indexOf(','+ id +',') == -1){
            hasnew = true;
            ids += ','+ id +',';
            ids = ids.replace(/,,/g, ',');
            SetCookie(cookie_id, ids);
        }
    }else{
        $('.contrast_go', contrast_ifm).click();
    }
    
    var contrast_ifm = $('.contrast_ifm');
    if(contrast_ifm.attr('style').indexOf('block') == -1){
        contrast_ifm.show();
    }
    
    var iframe = $('iframe', contrast_ifm);
    if(/\d/.test(ids) && ((typeof(iframe.attr('src')) == 'undefined' || iframe.attr('src') == '') || hasnew == true)){
        iframe.attr('src', path +'Contrasts.aspx?id='+ ids +'&token='+ tokenKey());
    }
}
function contrast_remove(path, id, t){
     var ids= GetValueFromUrl('id');
     var cookie_id = contrast_cookie_id(path);
     if(ids.length > 0){
        if(ids.substring(ids.length-1) != ','){
            ids = ids + ',';
        }
     }
     if(ids.indexOf(','+ id +',') > -1){       
        ids = ids.replace(',' + id + ',',',');
     }
     SetCookie(cookie_id, ids);
     window.location.href= (t == 1) ? (path +'Contrasts.aspx?id=' + ids) : (path +'Contrast.aspx?id=' + ids);
}
function contrast_cookie_id(path){
    return path.toLowerCase().replace(/\//gi, '') + '_id';
}
function contrast_fix(){
    var list = $('.contrast_list');
    var lis = $('.head li').size();
    for(var i=0; i<lis; i++){
        var mxh = 0;
        $('ul', list).each(function(){
            var ch = $('li:eq('+ i +')', $(this)).height();
            if(ch > mxh){
                mxh = ch;
            }
        });
        $('ul', list).each(function(){
            $('li:eq('+ i +')', $(this)).height(mxh);
        });
    }
}

//地区下拉联动，只支持省和市
function relateRegionChange(o, val){
    $(o).nextAll().remove();
    if(!val){
        document.getElementById('rid').value = $(o).val();
    }
    var cmd = new RemoteCommand('Platform', 'GetRegions');
    cmd.SetParameter('parentId', $(o).val());
    var strRegions = cmd.Execute().ReturnValue;
    if(strRegions != null && $(o).val() > 0){
        var sltObj = $('<select id="regionCity" name="regionCity" onchange="setRelateRegion()"></select>');
        $('<option value="0">==所有城市==</option>').appendTo(sltObj);
        sltObj.appendTo($(o).parent());
        regions = strRegions.split('|');
        for(var i = 0; i < regions.length; i++){
            regionValue = regions[i].split(',')[0];
            regionName = regions[i].split(',')[1];
            if(regionValue == val){
                $('<option value="' + regionValue + '" selected>' + regionName + '</option>').appendTo(sltObj);
            }else{
                $('<option value="' + regionValue + '">' + regionName + '</option>').appendTo(sltObj);
            }
        }
    }
}
//地区下拉联动初始化
function relateRegionInit(){
    var rid = GetIdFromUrl('rid');
    var cmd = new RemoteCommand('Platform', 'GetRegionParentId');
    cmd.SetParameter('regionId', rid);
    var parentId = cmd.Execute().ReturnValue; 
    if(parentId > 1){ 
        $('#regionProvince').val(parentId);
    }else{
        $('#regionProvince').val(rid);
    }
    relateRegionChange($('#regionProvince'), rid);
    setRelateRegion();
}  
//地区下拉联动绑定隐藏域的值
function setRelateRegion(){
    var val = $('#regionCity').val(); 
    if(val > 0){
         document.getElementById('rid').value = val;
    }else{
         document.getElementById('rid').value = $('#regionProvince').val();
    } 
}
