﻿    var div_id="";
    var height=0;
    var width=0;
    function BindSelectValue(values,id){
        var obj_select=$(id);
        for(var i=0;i<obj_select.length;i++){
            if(obj_select[i].value==values){
                obj_select[i].selected=true;
                break;
            }
        }
    }
    
    function BindRadioValue(values,name){
        var obj_radio=document.getElementsByName(name)
        for(var i=0;i<obj_radio.length;i++){
            if(obj_radio[i].value==values){
                obj_radio[i].checked=true;
                break;
            }
        }
    }
    
    function changeImgEdit2(id){
	    $(id).src="images/home/Edit2.gif";
	}
	function changeImgEdit1(id){
        $(id).src="images/home/Edit1.gif";
	}

	
	function FloatShow(){
	    FloatAutoSize();
	    $("hideDiv").style.display = "block";
	    $("hideDiv").style.opacity = 0.70;
	    $("hideDiv").style.filter = "alpha(opacity=70)";
	}
	
	function FloatAutoSize(){
	    $("hideDiv").style.width = window.screen.width+"px";
	     $("hideDiv").style.height = document.documentElement.offsetHeight+"px";
	    if (window.ActiveXObject) {$("hideDiv").style.height = document.body.offsetHeight+"px";}
	}
	
	function OpenLeftTop(id,width,height){
	    $(id).style.display = "block";
        $(id).style.left = (document.documentElement.clientWidth-width)/2 + "px";
        $(id).style.top = (document.documentElement.clientHeight-height)/2 + document.documentElement.scrollTop + "px";
	}
	
    window.onresize=function(){
        if ($("hideDiv").style.display == "block") {
            FloatAutoSize();
        }
        if(div_id!="" && $(div_id).style.display=="block"){
            OpenLeftTop(div_id,width,height);
        }
	}
	
	function FloatClose(){
	    $("hideDiv").style.display = "none";
	}
	
	function openPost(id,dwidth,dheight) {
	    
	    clostPostMaster();
	    if(document.location.href.indexOf("home_")==-1){
	        clostPostHome();
	    }
	    OpenLeftTop(id,dwidth,dheight);
	    FloatShow();
        
        div_id=id;
        width=dwidth;
        height=dheight;
    }

    function closePost(id) {
        $(id).style.display = "none";
        FloatClose();
    }
    
    function closePost2(id){
        $(id).style.display = "none";
        FloatClose();
    }
    
    
    function clostPostMaster(){
        $("post_box_privacy").style.display = "none";
        $("post_box_liuristate").style.display = "none";
        $("post_box_love").style.display = "none";
        $("post_box_mood").style.display = "none";
    }
    
    function clostPostHome(){
        
        $("post_box_IsStudyJapan").style.display = "none";
        $("post_box_prefessional").style.display = "none";
        
        $("post_box_MonthStudent").style.display = "none";
        $("post_box_prefessional2").style.display = "none";
        $("post_box_SXMonthStudent").style.display = "none";
        $("post_box_Iswork").style.display = "none";
        $("post_box_Riyu").style.display = "none";
        $("post_box_JPhoneType").style.display = "none";
        
        $("post_box_Jdormitoryfee").style.display = "none";
        $("post_box_Jdormitory").style.display = "none";
        $("post_box_Jdormitorystyle").style.display = "none";
        $("post_box_uvid").style.display = "none";

        $("same_box").style.display = "none";
    }
    
    function  getL(e){
        var  l=e.offsetLeft;
        while(e=e.offsetParent){
            l+=e.offsetLeft;
        }
        return  l;
    }  

    function  getT(e){
        var  t=e.offsetTop;
        while(e=e.offsetParent){
            t+=e.offsetTop;
        }
        return  t;
    }  
    function clearText2(id){
        $(id).value = "";
    }
    
    function WriteTd(id,str){
        if(id!=""){
            if($("StudyJapan").style.display=="block"){
                $(id).innerHTML=str;
            }
            if($("NoStudyJapan").style.display=="block"){
                $(id + "_0").innerHTML=str;
            }
            if($("UDStudyJapan").style.display=="block"){
                $(id + "_2").innerHTML=str;
            }
            if($("OverStudyJapan").style.display=="block"){
                $(id + "_3").innerHTML=str;
            }
        }
    }
    function WriteTd2(id,str){
        $(id).innerHTML=str;
    }
    //home.aspx
    function openSame(type,id,dwidth,dheight,puid) {
        clostPostMaster();
        clostPostHome();
        OpenLeftTop("same_box",dwidth,dheight);
        FloatShow();
        $("same_frame").src="home_FList.aspx?active=" + type + "&" + type + "=" +escape(id) + "&puid=" + puid;
        div_id="same_box";
        width=dwidth;
        height=dheight;
    }
    
    function displaydiv(){
        $("post_box_cuvid").style.display="none";
        return true;
    }
    function postTextClean(str,Luid,td_id)
    {
        //参数
        //str             判断执行那个case的条件
        //Luid            登录ID
        //td_id           写回的td
        
        
        //IsStudyJapan    判断属于那块(-1,未选择 0正在准备,1留学日本,2未定,3留学结束)
        //url             传给ajax页面的url
        //str_id          完成后需关闭的div(弹出窗口)
        //str_td          写回页面td的值
        var IsStudyJapan=-1;
        var url="";
        var str_id="post_box_" + str;
        var str_td="等待编辑";
        
        if($("StudyJapan").style.display=="block"){
            IsStudyJapan=1;
        }
        if($("NoStudyJapan").style.display=="block"){
            IsStudyJapan=0;
        }
        if($("UDStudyJapan").style.display=="block"){
            IsStudyJapan=2;
        }
        if($("OverStudyJapan").style.display=="block"){
            IsStudyJapan=3;
        }
        
        switch(str){
            case "liuristate":
                url="/ajax_home.aspx?active=liuristate&uid=" + Luid + "&liuristateid=0";
                break;
            case "love":
                url="/ajax_home.aspx?active=love&uid=" + Luid + "&love=";
                break;
            case "mood":
                url="/ajax_home.aspx?active=mood&uid=" + Luid + "&mood=";
                break;
            case "prefessional":
                url="/ajax_home.aspx?active=prefessional&uid=" + Luid + "&prefessional=";
                if(IsStudyJapan!=1){td_id= td_id + "_" + IsStudyJapan;}
                break;
            case "MonthStudent":
                url="/ajax_home.aspx?active=MonthStudent&uid=" + Luid + "&MonthStudent=0";
                if(IsStudyJapan!=1){td_id= td_id + "_" + IsStudyJapan;}
                break;
            case "SXMonthStudent":
                url="/ajax_home.aspx?active=SXMonthStudent&uid=" + Luid + "&SXMonthStudent=0";
                break;
            case "prefessional2":
                url="/ajax_home.aspx?active=prefessional2&uid=" + Luid + "&prefessional2=";
                break;
            case "Iswork":
                url="/ajax_home.aspx?active=Iswork&uid=" + Luid + "&Iswork=-1";
                if(IsStudyJapan!=1){td_id= td_id + "_" + IsStudyJapan;}
                break;
            case "Riyu":
                url="/ajax_home.aspx?active=Riyu&uid=" + Luid + "&Riyu=0";
                if(IsStudyJapan!=1){td_id= td_id + "_" + IsStudyJapan;}
                break;
            case "JPhoneType":
                url="/ajax_home.aspx?active=JPhoneType&uid=" + Luid + "&JPhoneType=-1";
                break;
            case "Jdormitory":
                url="/ajax_home.aspx?active=Jdormitory&uid=" + Luid + "&Jdormitory=-1";
                break;
            case "Jdormitorystyle":
                url="/ajax_home.aspx?active=Jdormitorystyle&uid=" + Luid + "&Jdormitorystyle=-1";
                break;
            case "Jdormitoryfee":
                url="/ajax_home.aspx?active=Jdormitoryfee&uid=" + Luid + "&Jdormitoryfee=-1";
                break;
            case "IsStudyJapan":
                url="/ajax_home.aspx?active=IsStudyJapan&uid=" + Luid + "&IsStudyJapan=-1";
                break;
            
        }
        var value=getData(url);
        if (value=="0") {
            //alert("提交成功！");
            closePost(str_id);
            WriteTd2(td_id,str_td); 
        } else {alert("提交失败！");}
    
    }
    
    function postText(str,Luid,td_id){
        var url="";
        var str_id="post_box_" + str;
        var str_td="";
        switch(str){
            case "prefessional":
                if($("txtTextprefessional").value.trim()=="请注意输入的信息不能超过16个字符哦^o^"){alert('请输入内容！');return false;}
                if(!chkFormData("txtTextprefessional","",3,16,"内容",true,true)) return false;
                url="/ajax_home.aspx?active=prefessional&uid=" + Luid + "&prefessional=" + escape($("txtTextprefessional").value);
                str_td=$("txtTextprefessional").value;
                break;
            case "MonthStudent":
                url="/ajax_home.aspx?active=MonthStudent&uid=" + Luid + "&MonthStudent=" + $("ctl00_ContentPlaceHolder1_ddl_MonthStudent").value;
                str_td=$("ctl00_ContentPlaceHolder1_ddl_MonthStudent").options[$("ctl00_ContentPlaceHolder1_ddl_MonthStudent").selectedIndex].text;
                break;
            case "SXMonthStudent":
                url="/ajax_home.aspx?active=SXMonthStudent&uid=" + Luid + "&SXMonthStudent=" + $("ctl00_ContentPlaceHolder1_ddl_SXMonthStudent").value;
                str_td=$("ctl00_ContentPlaceHolder1_ddl_SXMonthStudent").options[$("ctl00_ContentPlaceHolder1_ddl_SXMonthStudent").selectedIndex].text;
                break;
            case "prefessional2":
                if($("txtTextprefessional2").value.trim()=="请注意输入的信息不能超过16个字符哦^o^"){alert('请输入内容！');return false;}
                if(!chkFormData("txtTextprefessional2","",3,16,"内容",true,true)) return false;
                url="/ajax_home.aspx?active=prefessional2&uid=" + Luid + "&prefessional2=" + escape($("txtTextprefessional2").value);
                str_td=$("txtTextprefessional2").value;
                break;
            case "Iswork":
                if ((!$("ctl00_ContentPlaceHolder1_RBL_Iswork_0").checked) && (!$("ctl00_ContentPlaceHolder1_RBL_Iswork_1").checked)) { alert("请选择'是否准备打工?'。"); $("ctl00_ContentPlaceHolder1_RBL_Iswork_0").focus(); return false; }
                var temp4=document.getElementsByName("ctl00$ContentPlaceHolder1$RBL_Iswork"); 
                var value4="";
                for (i=0;i<temp4.length;i++){ 
                    if(temp4[i].checked) { 
                        value4=temp4[i].value;
                    } 
                } 
                switch(value4){
                    case "1":
                        str_td="是";
                        break;
                    case "0":
                        str_td="否";
                        break;
                }
                url="/ajax_home.aspx?active=Iswork&uid=" + Luid + "&Iswork="+ value4;
                break;
                
            case "Riyu":
                url="/ajax_home.aspx?active=Riyu&uid=" + Luid + "&Riyu=" + $("ctl00_ContentPlaceHolder1_ddl_Riyu").value;
                str_td=$("ctl00_ContentPlaceHolder1_ddl_Riyu").options[$("ctl00_ContentPlaceHolder1_ddl_Riyu").selectedIndex].text;
                break;
            case "JPhoneType":
                url="/ajax_home.aspx?active=JPhoneType&uid=" + Luid + "&JPhoneType=" + $("ctl00_ContentPlaceHolder1_ddl_JPhoneType").value;
                str_td=$("ctl00_ContentPlaceHolder1_ddl_JPhoneType").options[$("ctl00_ContentPlaceHolder1_ddl_JPhoneType").selectedIndex].text;
                break;
            case "Jdormitory":
                if ((!$("ctl00_ContentPlaceHolder1_RBL_Jdormitory_0").checked) && (!$("ctl00_ContentPlaceHolder1_RBL_Jdormitory_1").checked)) { alert("请选择'留日住宿状况?'。"); $("ctl00_ContentPlaceHolder1_RBL_Jdormitory_0").focus(); return false; }
                var temp2=document.getElementsByName("ctl00$ContentPlaceHolder1$RBL_Jdormitory"); 
                var value2="";
                for (i=0;i<temp2.length;i++){ 
                    if(temp2[i].checked) { 
                        value2=temp2[i].value; 
                    } 
                } 
                switch(value2){
                    case "1":
                        str_td="学校宿舍";
                        break;
                    case "0":
                        str_td="租住民宅";
                        break;
                }
                url="/ajax_home.aspx?active=Jdormitory&uid=" + Luid + "&Jdormitory="+ value2;
                break;
            case "Jdormitorystyle":
                if ((!$("ctl00_ContentPlaceHolder1_RBL_Jdormitorystyle_0").checked) && (!$("ctl00_ContentPlaceHolder1_RBL_Jdormitorystyle_1").checked)) { alert("请选择'留日住宿状况?'。"); $("ctl00_ContentPlaceHolder1_RBL_Jdormitorystyle_0").focus(); return false; }
                var temp3=document.getElementsByName("ctl00$ContentPlaceHolder1$RBL_Jdormitorystyle"); 
                var value3="";
                for (i=0;i<temp3.length;i++){ 
                    if(temp3[i].checked) { 
                        value3=temp3[i].value; 
                    } 
                } 
                switch(value3){
                    case "1":
                        str_td="合住";
                        break;
                    case "0":
                        str_td="单人";
                        break;
                }
                url="/ajax_home.aspx?active=Jdormitorystyle&uid=" + Luid + "&Jdormitorystyle="+ value3;
                break;
            case "Jdormitoryfee":
                url="/ajax_home.aspx?active=Jdormitoryfee&uid=" + Luid + "&Jdormitoryfee="+ $("ctl00_ContentPlaceHolder1_ddl_Jdormitoryfee").value;
                str_td=$("ctl00_ContentPlaceHolder1_ddl_Jdormitoryfee").options[$("ctl00_ContentPlaceHolder1_ddl_Jdormitoryfee").selectedIndex].text;
                break;
            
        }
        var value=getData(url);
        if (value=="0") {
                alert("sdf");
            //alert("提交成功！");
            closePost(str_id);
            WriteTd(td_id,str_td); 
        } else {alert("提交失败！");}
    } 
    
    function postTextMaster(str,Luid,td_id){
        var url="";
        var str_id="post_box_" + str;
        var str_td="";
        switch(str){
            case "liuristate":
                url="/ajax_home.aspx?active=liuristate&uid=" + Luid + "&liuristateid=" + $("ctl00_ddl_liuristate").value;
                str_td=$("ctl00_ddl_liuristate").options[$("ctl00_ddl_liuristate").selectedIndex].text;
                break;
            case "love":
                if($("txtTextLove").value.trim()=="请注意输入的信息不能超过22个字符哦^o^"){alert('请输入内容！');return false;}
                if(!chkFormData("txtTextLove","",3,22,"内容",true,true)) return false;
                url="/ajax_home.aspx?active=love&uid=" + Luid + "&love=" + escape($("txtTextLove").value);
                str_td=$("txtTextLove").value;
                break;
            case "mood":
                if($("txtTextMood").value.trim()=="请注意输入的信息不能超过22个字符哦^o^"){alert('请输入内容！');return false;}
                if(!chkFormData("txtTextMood","",3,22,"内容",true,true)) return false;
                url="/ajax_home.aspx?active=mood&uid=" + Luid + "&mood=" + escape($("txtTextMood").value);
                str_td=$("txtTextMood").value;
                break;
            case "privacy":
                if ((!$("ctl00_RBL_privacy_0").checked) && (!$("ctl00_RBL_privacy_1").checked) && (!$("ctl00_RBL_privacy_2").checked)) { alert("请选择'隐私设置?'。"); $("ctl00_RBL_privacy_0").focus(); return false; }
                var temp5=document.getElementsByName("ctl00$RBL_privacy"); 
                var value5="";
                for (i=0;i<temp5.length;i++){ 
                    if(temp5[i].checked) { 
                        value5=temp5[i].value;
                    } 
                } 
                url="/ajax_home.aspx?active=privacy&uid=" + Luid + "&privacy="+ value5;
                $("ctl00_RBL_privacy_" + value5).checked = true;
                break;
        }
        var value=getData(url);
        if (value=="0") {
            //alert("提交成功！");
            closePost(str_id);
            if(str_td!=""){
                WriteTd2(td_id,str_td); 
            }
        } else {alert("提交失败！");}
    }
    
    
    //home_leaveword.aspx
    function chkleaveword(id){
        if(!chkFormData(id,"",3,500,"内容",true,true)) return false;
    }
    
    function openPostLeavewordReply(o,LID,Ruid){
        closePost("post_box_leavewordDel");
        $("post_box_leavewordReply").style.display = "block";
        $("post_box_leavewordReply").style.left = (getL(o) - 370) + "px";
        $("post_box_leavewordReply").style.top = (getT(o) + o.offsetHeight  - 240) + "px";
        $("ctl00_ContentPlaceHolder1_txtLID").value=LID;
        $("ctl00_ContentPlaceHolder1_txtRuid").value=Ruid;
        $("ctl00_ContentPlaceHolder1_txtleavewordReply").focus();
    }
    function openPostDel2(o,LID,type){
        var msg="";
        if(type==1){
            msg= "删除该条留言，相应的回复也会被删除，且数据无法恢复，删除否?";
        }else{
            msg="删除数据将无法恢复，删除否?";
        }
        closePost("post_box_leavewordReply");
        $("post_box_leavewordDel").style.display = "block";
        $("post_box_leavewordDel").style.left = (getL(o) - 300) + "px";
        $("post_box_leavewordDel").style.top = (getT(o) + o.offsetHeight  - 150) + "px";
        $("ctl00_ContentPlaceHolder1_txtLID").value=LID;
        $("ctl00_ContentPlaceHolder1_txtRuid").value=type;
        $("tdMsg").innerHTML=msg;
        //$("ctl00_ContentPlaceHolder1_lnkDel2").focus();
    }
    
    function openPostFace(o,id){
        if($(id).style.display=="none"){
            $(id).style.display = "block";
            $(id).style.left = (getL(o)-400) + "px";
            $(id).style.top = (getT(o) + o.offsetHeight-10) + "px";
        }else{
            $(id).style.display = "none";
        }
    }
    
    function openPostLeavewordHome(o){
        $("post_box_QLeaveword").style.display = "block";
        $("post_box_QLeaveword").style.left = (getL(o)-400) + "px";
        $("post_box_QLeaveword").style.top = (getT(o) + o.offsetHeight-255) + "px";
    }
    
    
    function openPostGift(id,dwidth,dheight){
        $("post_box_QQType").style.display="none";
        $("post_box_OtherType").style.display="none";
	    OpenLeftTop(id,dwidth,dheight);
	    FloatShow();
        
        div_id=id;
        width=dwidth;
        height=dheight;
    }