﻿// JScript 文件
var screenAvailWidth=window.screen.availWidth;
var screenAvailHeight=window.screen.availHeight;

var profile_seccode_invalid = '验证码输入错误，请重新填写。';
	var profile_secanswer_invalid = '验证问答回答错误，请重新填写。';
	var profile_username_toolong = '对不起，您的用户名超过 15 个字符，请输入一个较短的用户名。';
	var profile_username_tooshort = '对不起，您输入的用户名小于3个字符, 请输入一个较长的用户名。';
	var profile_username_illegal = '用户名包含敏感字符或被系统屏蔽，请重新填写。';
	var profile_passwd_illegal = '密码空或包含非法字符，请重新填写。';
	var profile_passwd_notmatch = '两次输入的密码不一致，请检查后重试。';
	var profile_email_illegal = 'Email 地址无效，请重新填写。';

	
	function checkusername() {
		var username = $F('txtUserName');
		var cu = $('checkusername');
		var unlen = username.replace(/[^\x00-\xff]/g, "**").length;

		if(unlen < 3 || unlen > 15) {
			warning(cu, unlen < 3 ? profile_username_tooshort : profile_username_toolong);
			return;
		}
        new Ajax.Updater('checkusername','Tools/Ajax.aspx',{parameters:{Action:'checkuser',uid:username}});
	}
	

	function checkpassword() {
		var password = $F('txtPwd');
		var cp = $('checkpassword');
		if(password == '' || /[\'\"\\]/.test(password)) {
			warning(cp, profile_passwd_illegal);
			return false;
		} else {
			cp.style.display = 'none';
			if(!confirm) {
				checkpassword2(true);
			}
			return true;
		}
	}
	
	function checkpassword2(txtPwd) {
		var password = $F('txtPwd');
		var password2 = $F('txtRPwd');
		var cp2 = $('checkpassword2');
		if(password2 != '') {
			checkpassword(true);
		}
		if(password == '' || password2 == '') {
			cp2.style.display = 'none';
			return;
		}
		if(password != password2) {
			warning(cp2, profile_passwd_notmatch);
		} else {
			cp2.style.display = 'none';
		}
	}
	
	function checkpassword3() {
		var password = $F('txtPwd');
		var cp = $('checkpassword');
		if(password == '' || /[\'\"\\]/.test(password)) {
			warning(cp, profile_passwd_illegal);
			return false;
		} else {
			cp.style.display = 'none';
			if(!confirm) {
				checkpassword4(true);
			}
			return true;
		}
	}
	function checkpassword4() {
		var password = $F('newPwd');
		var password2 = $F('checkPwd');
		var cp2 = $('checkpassword4');
		if(password2 != '') {
			checkpassword3(true);
		}
		if(password == '' || password2 == '') {
			cp2.style.display = 'none';
			return;
		}
		if(password != password2) {
			warning(cp2, profile_passwd_notmatch);
		} else {
			cp2.style.display = 'none';
		}
	}
	    function Editor(id)
    {
        window.open("BlogPost.aspx?logsId="+id+"");
    }
    
    function CheckMine(id)
    {
        window.open('Default.aspx?uid='+id);
        //window.location.href='Default.aspx?uid='+id+'';
    }
     //检验是否有权限 logid ：文章id号，uid：用户id
    function CheckRight(logid,uid)
    {
         var hasRight=false;
            new Ajax.Request('Tools/Ajax.aspx?Action=HasRight',{
            method:'post',
            parameters:{logsid:logid,uid:uid},
            onComplete:function(transport)
            {
                if(transport.responseText=='success')
                {
                   hasRight= true;
                }
                else
                {
                    hasRight= false;
                }
            }
            });
            return hasRight;
    }
    //@显示/关闭详细信息；
	function ShowParInfo()
	{
	  var ele= document.getElementById('particularInof').style.display;
	  if(ele=='')
	  {
	        document.getElementById('particularInof').style.display='none';
	  }
	  if(ele=='none')
	  {
	  document.getElementById('particularInof').style.display='';
	  }
	}
	//打开节点
	function ShowElement(id)
	{
	        $(id).style.display='';
	}
	//隐藏节点
	function HiddenElement(id)
	{
	         $(id).style.display='none';
	}
	//预览头像
	function Preview(imgSrc)
	{
	    var ary=imgSrc.split(".");
	    var ImgType="jpg.jpeg.png.gif.bmp".split(".");
	    var isImage=false
	    for(i=0;i<4;i++)
	    {
	       // alert(ImgType[i].toString());
	        if(ImgType[i].toString()==ary[ary.length-1].toString().toLowerCase())
	        {
	            isImage=true;
	            break;
	        }
	    }
	    if(isImage)
	    {
	        $('HeadImage').src = imgSrc; 
	        ShowElement('HeadImage');
	    }
	    else
	    {
	         $('checkImg').style.display="";
             $('checkImg').innerHTML="图像格式不正确，只能上传图片类型！";
             $('isUpload').value="-1";
	        HiddenElement('HeadImage');
	    }

	}
	//上传头像；
	function UploadHeadImage()
	{
	    if(CheckImgSize()&&$('isUpload').value!="-1")
	    {
	        $('formImg').action="Tools/UploadHeadImg.aspx";
	        $('formImg').submit();
	    //    alert('图片修改成功');
	        showUserPanel();
//            lightbox.prototype.deactivate();
	        return 1;
        }
        return -1;
	}
	//检验头像大小
	function CheckImgSize()
	{
	  var   s   =   $("HeadImage").src;
      if(s=="")
      {
        return  false;
      }    
      var img = new Image();    
      img.src = s;    
      if(img.fileSize>51200)
      {
         return  false;   
      } 
      return true;
	}
	
	function checkemail() {
		var email = $F('txtEmail');
		var ce = $('checkemail');
		// 正则表达式对象
		var re = new RegExp("^[\\-\\.\\w]+@[\\.\\-\\w]+(\\.\\w+)+$", "");

		// 验证是否刚好匹配
		var yesorno = re.test(email);
		
		if(yesorno)
			ce.innerHTML = '';
		else
			warning(ce,profile_email_illegal);
	}
	
	
	/**
	 * 显示错误
	 * @param {Object} 显示错误的元素
	 * @param {string} 错误提示
	 */
	function warning(cp, wartext){
		cp.innerHTML = wartext;
	}


    function userlogin(){
        var uid = $F('txtUserName');
        var pwd = $F('txtPwd');
        var codeimg = $F('txtCode');
        var time = $F('rbtnCookies');
        if(uid=='' || pwd=='' || codeimg==''){
            alert('请填写完整！');
            return;
        }
        
        new Ajax.Request('Tools/Ajax.aspx?Action=userlogin',{
            method: 'post',
            parameters:{userName:uid, userPwd:pwd, expires:time, code:codeimg},
            onComplete: function(transport){
                if(transport.responseText == 'success'){
                     showUserPanel();
                     lightbox.prototype.deactivate();
                }
                else{
                    alert(transport.responseText);
                }
            }
        });
    }
     /// 修改用户信息
   function SaveInfo()
   {
        var oldPwd=$F('oldPwd');
        var newPwd=$F('newPwd');
        var checkPwd=$F('checkPwd');
        var Email=$F('txtEmail');
        var qq=$F('txtQQ');
        var Intro=$F('txtIntro');
        var cp1=$('checkpassword');
       var isUploadImg=$F('isUpload');
//        alert(isUploadImg);
//        return;
//        while(isUploadImg=="")
//        {    
//            isUploadImg=$F('isUpload');
//        }
        
        if(isUploadImg=="-1")
        {
           alert("头像上传失败,将会使用您上一次上传的头像！！");
           return;
        }
         //$('checkImg').style.display="none";
        if(newPwd!=checkPwd)
        {
            var cp2 = $('checkpassword4');
            cp2.style.display='';
            cp2.innerHTML='两次输入密码不相同，请重新输入';
           return;
        }
        
        if(oldPwd!="")
        {
           
        //var imgsrc=($F('HeadImageUpload').value.split('.'))[($F('HeadImageUpload').value.split('.')).length-1].toString();
        new Ajax.Request('Tools/Ajax.aspx?Action=ChangeInfo',{
        method:'post',
        parameters:{opwd:oldPwd,npwd:newPwd,email:Email,QQ:qq,intro:Intro,headSrc:isUploadImg},
        onComplete:function(transport)
        {
            if(transport.responseText == 'success')
            {
                alert('修改信息成功！');
                showUserPanel();
                lightbox.prototype.deactivate();
            }
            else
            {
                if(transport.responseText == 'pwdFalse')
                {
                   cp1.style.display='';
                   cp1.style.innerHTML='密码不正确，请重新输入！！';
                }
               return;
            }
        }
        });
        }
        else
        {
          if(oldPwd=="")
          {
              alert('验证密码失败，请重新输入原密码！');
          }
        }
   }
   function UploadHeaderImage()
   {
         if(UploadHeadImage()==-1)
        {
          $('checkImg').style.display="";
          $('checkImg').innerHTML="头像不合要求，请重新选择！";
          return;
        }
        else
        {
          $('checkImg').style.display="";
          $('checkImg').innerHTML="头像上传成功";
          showUserPanel();
       }
   }
    
    
    ///
    
     function DeleteByUid(id,uid)
    {
//        if(CheckRight(id,uid)==false){
//            alert('没有权限！');
//            return;
//        }
//        else
//        {
            new Ajax.Request('Tools/Ajax.aspx?Action=Delete',{
                method: 'post',
                parameters:{logsid:id,uid:uid},
                onComplete: function(transport){
                    if(transport.responseText == 'success'){
                         alert("删除成功");
                    }
                    else{
                        alert(transport.responseText);
                    }
                }
            });
//        }
    }
    
    function DeleteCommentinfo(CommenId,userid,logid)
    {
        new Ajax.Request('Tools/Ajax.aspx?Action=DeleteCommen',{
        method:"post",
        parameters:{cid:CommenId,uid:userid,logsid:logid},
        onComplete:function(transport)
        {
            if(transport.responseText=='success')
            {
                alert("删除成功");
                var thisurl=window.location.href;
                alert(thisurl);
                window.location.href=thisurl;
            }
            else
            {
                 alert(transport.responseText);
            }
        }
        
        });
    }
    
    function userout(){
        new Ajax.Request('Tools/Ajax.aspx?Action=userout',{
            onComplete: function(transport){
                showUserPanel();
            }
        });
    }
    
    	function Changepassword()
	{
	     new Ajax.Request('Tools/Ajax.aspx?Action=changepassword',{
            onComplete: function(transport){
               alert('修改密码成功');
            }
        });
	}
	
    function showUserPanel(){
        new Ajax.Updater('UserPanel', 'Tools/Ajax.aspx?Action=userpanel',
        {
            onComplete: function init(re){
                addLightboxMarkup();
                lbox = document.getElementsByClassName('lbOn sideA');
	            for(i = 0; i < lbox.length; i++) {
		            valid = new lightbox(lbox[i]);
            	}
            }
        }
        );
    }

//设置字体大小
function SetFont(size){
	$("logPanel").style.fontSize=size;
}

function leftPosition(width)
{ 
 var left,width;
 if(document.body.clientWidth<width)left = "0px";
 else left = ((document.body.clientWidth-width)/2) + "px";
 return left;
} 

function topPosition(height)
{ 
 var top,height;
 if(document.body.clientHeight<height)top = "0px";
 else top = ((screenAvailHeight-height)/2) + "px";
 return top;
}

//显示DIV
function displayLayer(layerID){
	if ( $(layerID) != null){
		var dv = $(layerID);
		hiddenLayerOther(layerID);
		if ( dv.style.visibility == "hidden" ) {
			GetCenterXY_ForLayer(dv);
			dv.style.visibility = "visible";
		}
		document.body.onmousemove = function (event){drag(event,dv)};
		document.body.onmouseup = function(){objX = 0;objY=0};
	}
	return false;
}

//隐藏DIV
function hiddenLayer()
{
	var argArr = hiddenLayer.arguments;
	for(var i=0;i<argArr.length;i++){
		if ( $(argArr[i])!=null ) 
		{
			$(argArr[i]).style.visibility = "hidden";
		}
	}
}

//查找网页内宽度太大的图片进行缩放以及PNG纠正
 function ReImgSize(){
  for (i=0;i<document.images.length;i++)
   {
   if (document.all){
	if (document.images[i].width>550)
	 {
       document.images[i].width="550"
       try{
	       document.images[i].outerHTML='<a href="'+document.images[i].src+'" target="_blank" title="在新窗口打开图片">'+document.images[i].outerHTML+'</a>'
  	 	}catch(e){}
  	 }
   }
  else{
	if (document.images[i].width>400) {
	  document.images[i].title="在新窗口打开图片"
	  document.images[i].style.cursor="pointer"
	  document.images[i].onclick=function(e){window.open(this.src)}
	}
  }
  }
 }

//显示媒体
function MediaShow(strType,strID,strURL,intWidth,intHeight)
{
    var MediaTemp=new Array();
	var tmpstr;
	if (MediaTemp[strID]==undefined) MediaTemp[strID]=false; else MediaTemp[strID]=!MediaTemp[strID];
	if(MediaTemp[strID]){
			if ( document.all )	{
	         	$(strID).outerHTML = '<div id="'+strID+'"></div>';
			}
			else
			{
	         	$(strID).innerHTML = '';
			}
		//document.images[strID+"_img"].src="images/mm_snd.gif" 	;	
		$(strID+"_text").innerHTML="在线播放";	
	}else{
		//document.images[strID+"_img"].src="images/mm_snd_stop.gif";		
		$(strID+"_text").innerHTML="关闭在线播放";
		switch(strType){
			case "swf":
				tmpstr='<div style="height:6px;overflow:hidden"></div><object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+intWidth+'" height="'+intHeight+'"><param name="movie" value="'+strURL+'" /><param name="quality" value="high" /><param name="AllowScriptAccess" value="never" /><embed src="'+strURL+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+intWidth+'" height="'+intHeight+'" /></object>';
				break;
			case "wma":
				tmpstr='<div style="height:6px;overflow:hidden"></div><object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"  id="MediaPlayer" width="450" height="70"><param name=""howStatusBar" value="-1"><param name="AutoStart" value="False"><param name="Filename" value="'+strURL+'"></object>';
				break;
			case "wmv":
				tmpstr='<div style="height:6px;overflow:hidden"></div><object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902" type="application/x-oleobject" standby="Loading..." width="'+intWidth+'" height="'+intHeight+'"><param name="FileName" VALUE="'+strURL+'" /><param name="ShowStatusBar" value="-1" /><param name="AutoStart" value="true" /><embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="'+strURL+'" autostart="true" width="'+intWidth+'" height="'+intHeight+'" /></object>';
				break;
			case "rm":
				tmpstr='<div style="height:6px;overflow:hidden"></div><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="'+intWidth+'" height="'+intHeight+'"><param name="SRC" value="'+strURL+'" /><param name="CONTROLS" VALUE="ImageWindow" /><param name="CONSOLE" value="one" /><param name="AUTOSTART" value="true" /><embed src="'+strURL+'" nojava="true" controls="ImageWindow" console="one" width="'+intWidth+'" height="'+intHeight+'"></object>'+
                '<br/><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="'+intWidth+'" height="32" /><param name="CONTROLS" value="StatusBar" /><param name="AUTOSTART" value="true" /><param name="CONSOLE" value="one" /><embed src="'+strURL+'" nojava="true" controls="StatusBar" console="one" width="'+intWidth+'" height="24" /></object>'+'<br /><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="'+intWidth+'" height="32" /><param name="CONTROLS" value="ControlPanel" /><param name="AUTOSTART" value="true" /><param name="CONSOLE" value="one" /><embed src="'+strURL+'" nojava="true" controls="ControlPanel" console="one" width="'+intWidth+'" height="24" autostart="true" loop="false" /></object>';
				break;
			case "ra":
				tmpstr='<div style="height:6px;overflow:hidden"></div><object classid="clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA" id="RAOCX" width="450" height="60"><param name="_ExtentX" value="6694"><param name="_ExtentY" value="1588"><param name="AUTOSTART" value="true"><param name="SHUFFLE" value="0"><param name="PREFETCH" value="0"><param name="NOLABELS" value="0"><param name="SRC" value="'+strURL+'"><param name="CONTROLS" value="StatusBar,ControlPanel"><param name="LOOP" value="0"><param name="NUMLOOP" value="0"><param name="CENTER" value="0"><param name="MAINTAINASPECT" value="0"><param name="BACKGROUNDCOLOR" value="#000000"><embed src="'+strURL+'" width="450" autostart="true" height="60"></embed></object>';
				break;
			case "qt":
				tmpstr='<div style="height:6px;overflow:hidden"></div><embed src="'+strURL+'" autoplay="true" loop="false" controller="true" playeveryframe="false" cache="false" scale="TOFIT" bgcolor="#000000" kioskmode="false" targetcache="false" pluginspage="http://www.apple.com/quicktime/" />';
		}
		$(strID).innerHTML = tmpstr;
	}
	$(strID+"_href").blur();
}