﻿/* member common Javascript*/


var memberid = getCookie("LEDUser");
var domain = "ledgb.com";

//获取cookie的值

//参数：name - cookie name
//返回：cookie value(若不存在，则返回"")
function getCookie(name) {
    var search;
    search = name + "=";
    offset = document.cookie.indexOf(search);
    if (offset != -1) {
        offset += search.length;
        end = document.cookie.indexOf(";", offset);
        if (end == -1)
            end = document.cookie.length;
        end = document.cookie.indexOf("&", offset);
        if (end == -1)
            end = document.cookie.length;
        return unescape(document.cookie.substring(offset, end));
    }
    else
        return "";
}

function FriendMsgSend(newuserid)
{
    //判断是否登录会员
    if (memberid == "")
    {
       
        var url='http://www.' + domain + '/workroom/login.aspx?returnurl=' + window.location.href;
        alert('对不起,您还有没登录!');
        window.location.href = url;
    }
    else
	    window.open( 'http://www.ledgb.com/workroom/page/Friend/FriendMiniMsgSend.aspx?newuserid='+newuserid,'FriendMsg', 'toolbar=no,location=no,directories=no,status=0,menubar=no,scrollbars=no,resizable=no,copyhistory=no,Width=485,Height=226,Top=100,Left=170');
}
function FriendMsgRead(id)
{
	window.open( 'http://www.ledgb.com/workroom/page/Friend/FriendMiniMsgRead.aspx?id='+id,'FriendMsg', 'toolbar=no,location=no,directories=no,status=0,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,Width=390,Height=250,Top=100,Left=170');
}
/*Add-Friend*/
function addfriend()
{
	if(form1.txtusername.value=="")
	{
		alert("会员ID不能为空！");
	}
	else
	{
			FriendMsgSend(form1.txtusername.value);	
	}
}
//SendMsg
function MsgSend(id)
{
//判断是否登录会员
if (memberid == "")
{
   
    var url='http://www.' + domain + '/workroom/login.aspx?returnurl=' + window.location.href;
    alert('对不起,您还有没登录!');
    window.location.href = url;
}
else
	window.open( 'http://www.ledgb.com/workroom/page/Msg/MessageSend_Open.aspx?id='+id,'MsgSend', 'toolbar=no,location=no,directories=no,status=0,menubar=no,scrollbars=no,resizable=no,copyhistory=no,Width=509,Height=298,Top=100,Left=170');
}
//specify whether contents should be auto copied to clipboard (memory)
//Applies only to IE 4+
//0=no, 1=yes
var copytoclip=1;
function copyToClipboard(theField,isalert) {		
	var tempval=$(theField);		
	if (navigator.appVersion.match(/\bMSIE\b/)){
		tempval.select();		
		if (copytoclip==1){
			therange=tempval.createTextRange();
			therange.execCommand("Copy");
			if(isalert!=false)alert("复制成功。现在您可以粘贴（Ctrl+v）到Blog 或BBS中了。");
		}
		return;
	}else{
		alert("您使用的浏览器不支持此复制功能，请使用Ctrl+C或鼠标右键。");
		tempval.select();		
	}
}

	window.onresize = baiduResizeDiv;
	window.onerror = function(){}
	var divTop,divLeft,divWidth,divHeight,docHeight,docWidth,objTimer,i = 0;
	var px = document.doctype?"px":0;
	var scrollwidth = navigator.userAgent.indexOf("Firefox")>0?16:0;
	//var iframeheight = navigator.userAgent.indexOf("MSIE")>0?170-2:209-2;
	var iframeheight = navigator.userAgent.indexOf("MSIE")>0?219:232;
	String.prototype.Trim  = function(){return this.replace(/^\s+|\s+$/g,"");}
	function baidu_collapse(obj){
		ct = document.getElementById('tab_c_iframe');
		if(ct.style.display=="none"){
			ct.style.display="";
			obj.src=obj.src.replace("b.gif","a.gif");
			obj.alt="最小化";
		} else {
			ct.style.display="none";
			obj.src=obj.src.replace("a.gif","b.gif");
			obj.alt="最大化";
		}
		baiduResizeDiv();
	}

	function baiduMsg()
	{
		try{
			divTop = parseInt(document.getElementById("eMeng").style.top,10);
			divLeft = parseInt(document.getElementById("eMeng").style.left,10);
			divHeight = parseInt(document.getElementById("eMeng").offsetHeight,10);
			divWidth = parseInt(document.getElementById("eMeng").offsetWidth,10);

			var scrollPosTop,scrollPosLeft,docWidth,docHeight;
			if (typeof window.pageYOffset != 'undefined') { 
				scrollPosTop = window.pageYOffset; 
				scrollPosLeft = window.pageXOffset; 
				docWidth = window.innerWidth; 
				docHeight = window.innerHeight; 
			} else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
				scrollPosTop = document.documentElement.scrollTop;
				scrollPosLeft = document.documentElement.scrollLeft;
				docWidth = document.documentElement.clientWidth;
				docHeight = document.documentElement.clientHeight;
			} else if (typeof document.body != 'undefined') { 
				scrollPosTop = document.body.scrollTop;
				scrollPosLeft = document.body.scrollLeft;
				docWidth = document.body.clientWidth;
				docHeight = document.body.clientHeight;
			}

			document.getElementById("eMeng").style.top = parseInt(scrollPosTop,10) + docHeight + 10 + px;// divHeight
			document.getElementById("eMeng").style.left = parseInt(scrollPosLeft,10) + docWidth - divWidth - scrollwidth + px;
			document.getElementById("eMeng").style.visibility="visible";
			objTimer = window.setInterval("baidu_move_div()",10);
		}catch(e){}
	}

	function baiduResizeDiv()
	{
		i+=1;
		try{
			divHeight = parseInt(document.getElementById("eMeng").offsetHeight,10);
			divWidth = parseInt(document.getElementById("eMeng").offsetWidth,10);

			var scrollPosTop,scrollPosLeft,docWidth,docHeight; 
			if (typeof window.pageYOffset != 'undefined') { 
				scrollPosTop = window.pageYOffset; 
				scrollPosLeft = window.pageXOffset; 
				docWidth = window.innerWidth; 
				docHeight = window.innerHeight; 
			} else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
				scrollPosTop = document.documentElement.scrollTop;
				scrollPosLeft = document.documentElement.scrollLeft;
				docWidth = document.documentElement.clientWidth;
				docHeight = document.documentElement.clientHeight;
			} else if (typeof document.body != 'undefined') { 
				scrollPosTop = document.body.scrollTop;
				scrollPosLeft = document.body.scrollLeft;
				docWidth = document.body.clientWidth;
				docHeight = document.body.clientHeight;
			}

			document.getElementById("eMeng").style.top = docHeight - divHeight + parseInt(scrollPosTop,10) + px;
			document.getElementById("eMeng").style.left = docWidth - divWidth + parseInt(scrollPosLeft,10) - scrollwidth + px;
		}catch(e){}
	}

	function baidu_move_div()
	{

		var scrollPosTop,scrollPosLeft,docWidth,docHeight; 
		if (typeof window.pageYOffset != 'undefined') { 
			scrollPosTop = window.pageYOffset; 
			scrollPosLeft = window.pageXOffset; 
			docWidth = window.innerWidth; 
			docHeight = window.innerHeight; 
		} else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
			scrollPosTop = document.documentElement.scrollTop;
			scrollPosLeft = document.documentElement.scrollLeft;
			docWidth = document.documentElement.clientWidth;
			docHeight = document.documentElement.clientHeight;
		} else if (typeof document.body != 'undefined') { 
			scrollPosTop = document.body.scrollTop;
			scrollPosLeft = document.body.scrollLeft;
			docWidth = document.body.clientWidth;
			docHeight = document.body.clientHeight;
		}

		try{
			if(parseInt(document.getElementById("eMeng").style.top,10) <= (docHeight - divHeight + parseInt(scrollPosTop,10)))
			{
				window.clearInterval(objTimer);objTimer = window.setInterval("baiduResizeDiv()",1);
			}
			divTop = parseInt(document.getElementById("eMeng").style.top,10);
			document.getElementById("eMeng").style.top = divTop - 1 + px;
		}catch(e){}
	}
	function baiduMessbox(shape,color,userid){
		var styles='position:absolute;top:0px;left:0px;z-index:99999;visibility:hidden;overFlow:hidden;';
		var copic='<img src="http://ledpic.ledgb.com/www/images/msg/ico_'+color+'a.gif" align="absmiddle" class="ioc'+color+'" onClick="baidu_collapse(this)">';
		if(shape>1) window.onload = baiduMsg;
		else {styles='';copic=''}
		var s;
		if(shape==2) {
		     if (memberid != "")
		     {
		        iframeheight=iframeheight-52;
		     }
			s='<div id=eMeng style="Z-INDEX:99999;LEFT:0px;POSITION:absolute;TOP:0px;VISIBILITY:hidden;overFlow:hidden;">'
				+ '<table width="216" border="0" cellpadding="0" cellspacing="0" class="" id="tab_'+(color+3)+'" style="border:0px;">'
				+'<tr>'
				+'<td align="right"></td>'
				+'</tr>'
				+'  <tr>'
				+'    <td><table width="100%"  border="0" cellspacing="0" cellpadding="0">'
				+'        <tr>'
				+'          <td width="32" rowspan="2" valign="bottom"><img src="http://ledpic.ledgb.com/www/images/msg//ico'+(color+1)+'.gif"></td>'
				+'          <td>&nbsp;</td>'
				+'        </tr>'
				+'        <tr>'
				+'          <td align=right style="font-size:12px; background:url(http://ledpic.ledgb.com/www/images/msg//bg_'+color+'.gif);line-height:21px;height:21px;border-top:1px solid #808080;border-right:1px solid #808080;padding-right:6px;color:#FFFFFF;" onDblClick="baidu_collapse(this.firstChild.nextSibling)"><a href="http://'+userid+'.ledgb.com" target="_blank" style="text-decoration:none"><font color="#FFFFFF">欢迎光临，请多提宝贵意见</font></a> <img src="http://ledpic.ledgb.com/www/images/msg/ico_'+color+'a.gif" align="absmiddle" class="ioc'+color+'"  alt="最小化" style="cursor:pointer" onClick="baidu_collapse(this)">'
				+'		  </td>'
				+'        </tr>'
				+'      </table>'
				+'	  </td>'
				+'    </tr>'
				+ '</table>'
				+ '<iframe src="http://www.ledgb.com/workroom/page/msg/msgsend.aspx?id=' +userid+ '" width="216" height="' + iframeheight + '" frameborder="0" id="tab_c_iframe"></iframe>'+'<table width="216" border="0" cellspacing="0" cellpadding="3" height="20" style="border-left-width:1px;border-left-style:solid;border-left-color:#000;border-right-width:1px;border-right-style:solid;border-right-color:#000;border-top-width:0;border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#000000;"><tr><td bgcolor="#FFFFFF" style="width: 215px" align=right>技术支持：<a href="http://www.ledgb.com/" target="_blank">LED环球在线</a>&nbsp;&nbsp;</td></tr></table>'
				+'</div>';
		} else if(shape==3) {
			s='<div id=eMeng style="width:100%;background:#FFFFFF;'+styles+'">'
				+'  <table width="100%"  border="0" cellpadding="0" cellspacing="0" style="border:1px solid #808080;" id="tab_'+color+'">'
				+'    <tr>'
				+'      <td colspan="3" align=right style="font-size:12px; background:url(http://ledpic.ledgb.com/www/images/msg//bg_'+color+'.gif);line-height:19px;height:19px;padding-right:6px;color:#FFFFFF;" onDblClick="baidu_collapse(this.firstChild.nextSibling)">留言板'+copic
				+'</tr>'
				+'    </tr>'
				+ '</table>'
				+ ''
				+'</div>';
		}
		document.writeln(s);
	}