﻿/*********************************************************************************
** File Name    	:		Function.js
** Copyright (C) 2007 Mcan.cn All rights reserved.
** Creator			:		Jason Xu
** Create Date		:		2007-6-30 18:16
** Description		:		handle page logic function 
** Version Number	:		WHTMLBLOG 2.1
***********************************************************************************/
function ClickSex(obj)
{
	switch(obj)
	{
		case 'b':	alert("原来是男生:)");	
			break;
		case 'g':	alert("原来是女生:)");	
			break;
		default:break;
	}
}

function Jason(obj)
{
	var curLog =  $("log"+obj);
	var curComment = $("SShow"+obj);
	if(curLog.style.display=='none')
	{
		curLog.style.display='block';
	}
	else
	{
		curLog.style.display='none';
		if(curComment != null)
		{
			curComment.style.display='none';
		}
	}
	if($("DIV" + obj) != null 
	&& $("DIV" + obj) != "undefined")
	{
		HideFromObject("DIV" + obj);	
	}
}

function ShowHide(obj, objName)
{
	var DivPanel = $(objName);
	if(DivPanel.style.display == "none")
	{
		$(obj).innerText = "Hide";	
		$(obj).title = "Hide Current Panel";
		DivPanel.style.display = "";	
	}
	else
	{
		$(obj).innerText = "Show";
		$(obj).title = "Show Current Panel";
		DivPanel.style.display = "none";	
	}	
}

function ShowLog()
{
    document.write("<script src='"+blogURL+"script/mode.js'><\/script>");
	var hasHidden = false;
    for(var m=0;m < always_on_tops.length; m++)
    {
		//if(!IsHiddenLog(always_on_tops[m]))
		//{
			//end_no--;
			document.write("<script src='"+blogURL+"log/"+always_on_tops[m]+".js'><\/script>");
		//}
	}
    for(i=begin_no;i>=end_no;i--)
    {
		var hasExist = false;
		for(j=0; j < always_on_tops.length; j++)
		{
			if(i == always_on_tops[j])
			{
				hasExist = true;
			}
		}
		if(hasExist == false)
		{
			if(!IsHiddenLog(i))
			{
				logIDList[logIDIndex++]=i.toString();
				document.write("<script src='"+blogURL+"log/"+i+".js'><\/script>");
			}
		}
    }
    logIDIndex = 0;
}

function IsHiddenLog(logID)
{
	var hidden = false;
	for(var i = 0; i < always_hiden_Lists.length; i++)
	{
		if(logID == always_hiden_Lists[i])
		{
			return true;
		}
	}
	return hidden;
}
var HasExpand = false;
function ExpandList(self)
{
    var divs = document.getElementsByTagName( "div" );
    var regex = new RegExp(/^log\d+$/gi);
    for(var i = 0;i < divs.length;i++)
    {
        if(regex.test(divs[i].id))
        {
            if (HasExpand)
            {
                divs[i].style.display = "none";
            }
            else
            {
                divs[i].style.display = "block";
            }
        }
    }
    if (HasExpand == false)
    {
        self.innerHTML = "Collapse List";
        self.title = 'Collapse List';
        HasExpand = true;
    }
    else
    {
        self.innerHTML = "Expand List";
        self.title = 'Expand List';
        HasExpand = false;
    }
}
function ShowModalWindow(obj)
{
	window.showModalDialog(obj,'hehe','dialogWidth:650px; dialogHeight:500px; center:yes; status:no;location:no;');	
}

function ViewLog(logID)
{ 
	if(navigator.appName.indexOf("Explorer") > -1)
	{
        window.showModalDialog("preview.htm?logID="+logID,'hehe','dialogWidth:650px; dialogHeight:500px; center:yes; status:no;location:no;');	    
	}
	else
	{
	    window.open("preview.htm?logID="+logID, 'test', 'chrome,centerscreen,dependent=YES,dialog=YES,modal=YES,resizable=NO,scrollbars=NO,location=0,status=0,menubar=0,toolbar=0');
    }
}

function OpenWindow(obj)
{
	window.open(obj,'form','height:300px;height:500px;');	
}

function ShowHead()
{
	document.write("<script src='"+siteURL+"works/data/head.js'><\/script>");
}

function LogRule()
{
	document.write("<script src='"+blogURL+"script/log.js'><\/script>");	
}

function ShowLeftMenu()
{
	document.write("<script src='"+blogURL+"script/leftmenu.js'><\/script>");
}

function ShowCopyRight()
{
	document.write("<script src='"+siteURL+"works/data/copy_right.js'><\/script>");
}

function GetWeatherTips(img)
{
	var imageTip = "";
	switch(img)
	{
	    case "a1":imageTip = "Sunny";
	        break;
        case "a2":imageTip = "Cloudy";
	        break;
        case "a3":imageTip = "Rainy";
	        break;
        case "a4":imageTip = "Windy";
	        break;
        case "a5":imageTip = "Snowy";
	        break;
        case "a6":imageTip = "Rainbow";
	        break;
        case "a7":imageTip = "Dew";
	        break;
        case "top":imageTip = "top";
	        break;
	}
    return imageTip;
}

function WriteBlankSpace(count)
{
	var i = 0;
	while(i < count)
	{
		document.write("&nbsp;");
		i++;
	}
}

function ShowPostTable(logID)
{
	HidePostGetTable(logID);
	ShowFromObject("SShow"+logID);
}

function CheckCommentContent(logID, checkControl)
{
	var emptyFilter = /^\s+$/g;		
	if(checkControl == "")
	{		
		var userName = getFormValues("username"+logID);
		var content = getFormValues("body"+logID);
		if(userName == "" || userName.match(emptyFilter) != null)
		{
			alert("User name is required!");	
			return false;
		}
		if(content == "" || content.match(emptyFilter) != null)
		{
			alert("Comment is required!");	
			return false;
		}
	}
	if(checkControl == "Login")
	{
		//show mask div
		userPassword = getFormValues("Login"+logID);
		if(userPassword == "" || userPassword.match(emptyFilter) != null)
		{
			alert("Password is required!");	
			$("Login"+logID).focus();
			return false;
		}				
	}
	return true;		
}

function ShowCommentStatus(opType,logID)
{
	ShowFromObject("STATUS" + logID);
	if(opType == "post")
	{
		$("STATUS" + logID).innerHTML = "<p class='pStatus'><img src='"+blogURL+"faces/status.gif' border=0> Submiting log comment,Please wait...</p>";
	}
	else if(opType == "get")
	{
		$("STATUS" + logID).innerHTML = "<p class='pStatus'><img src='"+blogURL+"faces/status.gif' border=0> Getting and retrieving log comment,Please wait...</p>";
	}
	else if(opType == "delete")
	{
		$("STATUS" + logID).innerHTML = "<p class='pStatus'><img src='"+blogURL+"faces/status.gif' border=0> Delete and retrieving log comment,Please wait...</p>";
	}	
	else if(opType == "Login")
	{
		$("STATUS" + logID).innerHTML = "<table height='100'><tr><td><input type='password' id='Login"+logID+"' onkeydown='Login(\"LoginSubmit"+logID+"\")'> <input type='button' value='Login' id='LoginSubmit"+logID+"' onclick='CommentLogin("+logID+")'></td></tr></table>";
	}
	else if(opType == "Mask")
	{
		$("STATUS" + logID).innerHTML = "<div id='divMask' class='MaskDiv' oncontextmenu='return false'></div><div class='choose'><div id='DivLogin' class='LoginDiv' align='center' onmousedown='move(this,event);'><table border='0' cellpadding='0' cellspacing='0' width='100%'><tr class='TitleTR'><td align='left'>&nbsp;Login</td><td align='right'><span onclick='HideLoginMask();' title='close' style='cursor:pointer'>×</span>&nbsp;</td></tr><tr><td colspan='2' style='height:100px'><input type='password' id='Login"+logID+"' onkeydown='Login(\"LoginSubmit"+logID+"\")' style='border:#93c3f3 1px solid;width:90px'> <input type='button' value='Login' id='LoginSubmit"+logID+"' onclick='CommentLogin("+logID+")' style='border-style:groove'></td></tr></table></div></div>";
	}
}

function Login(obj)
{
	if(event.keyCode == 13)
	{
		$(obj).focus();
		event.keyCode = 13;
	}
}

function Sleep(obj,iMinSecond)
{ 
	if (window.eventList==null) 
	{
		window.eventList=new Array(); 
	}
	var ind=-1;
	for (var i=0;i<window.eventList.length;i++)
	{ 
   		if (window.eventList[i]==null) 
   		{
    		window.eventList[i]=obj;   
	    	ind=i;  
			break;  
   		} 
	} 
	if(ind==-1)
	{  
   		ind=window.eventList.length;  
	  	window.eventList[ind]=obj;
	}	 
	setTimeout("GoOn(" + ind + ")",iMinSecond);
}
 
function GoOn(ind)
{ 
	var obj=window.eventList[ind];
	window.eventList[ind]=null;
	if (obj.NextStep)
	{
  		obj.NextStep();
	}
	else obj();
}
 /*End*/
 
 function FormatLogContent(TheTEXT)
 {
		var test = /Image\((.*?)\)/g;		
		//TheTEXT = TheTEXT.replace(test,"<iframe src=\"$1\" width=\"100%\" scrolling=\"no\" height=\"100%\" frameBorder=0></iframe>");		
		TheTEXT = AnalysisIMG(TheTEXT);
		TheTEXT = AnalysisURL(TheTEXT);
		TheTEXT = AnalysisMedia(TheTEXT);
		return TheTEXT;
 } 

 function AnalysisMedia(TheTEXT)
 {
	var swf = /playSwf\[\s*'(.+)\s*',\s*'(.*)'\s*\]/gi;
	TheTEXT = TheTEXT.replace(swf, "<div style='text-align:center;'><script>playSwf('$1','$2');</script></div>");
	return TheTEXT;
 }
 
 function AnalysisIMG(TheTEXT)
 {
	var imgFunction = /[imgIMG]{3}[\(\[].*?[\)\]]/i; //img(http://,234,432)
	var imgPath = TheTEXT.match(imgFunction);
	if(imgPath != null)
	{
			var relativeRegex = /([imgIMG]{3}[\(\[])([^:\/\\\.]*)(\.gif|\.jpg|\.bmp|\.png)[,]\s*(\d+)\s*[,]\s*(\d+)[\]\)]/g;
			var absoluteRegex = /([imgIMG]{3}[\(\[])(http:\/\/.*?\.(?:gif|jpg|bmp|png))[,]\s*(\d+)\s*[,]\s*(\d+)[\]\)]/gi;
			TheTEXT = TheTEXT.replace(relativeRegex, "$1"+blogURL+"faces/$2$3,$4,$5]");
			var localIMG = /(img|Img|IMG)\//g;
			TheTEXT = TheTEXT.replace(localIMG, ""+blogURL+"img/");
			var heightRegex = /height=\s*\"\s*0\s*\"/gi;
			var widthRegex = /width=\s*\"\s*0\s*\"/gi;
			TheTEXT = TheTEXT.replace(absoluteRegex, "<img src='$2' border=0 width=\"$3\" height=\"$4\" alt='click to view original image' style='cursor:pointer' onclick='window.open(this.src)' onmouseover=\"this.className='overImg'\" onmouseout=\"this.className='outImg'\">");
			//copyValue(); Click to copy Image URL
			TheTEXT = TheTEXT.replace(widthRegex, "");
			TheTEXT = TheTEXT.replace(heightRegex, "");
	}
	return TheTEXT;
 }

 function AnalysisURL(TheTEXT)
 {
	var URLRegex = /url\[(https?|ftp|gopher|news|telnet|mms|rtsp|www)(:\/\/[a-z0-9/\-_+=.~!%@?#%&;:$\\()|]+)\]/gi;
	TheTEXT = TheTEXT.replace(URLRegex, "<a href='$1$2' title='open this link' target='_blank' style='border-bottom:dotted 1px gray'><strong>$1$2</strong></a>");
	TheTEXT = TheTEXT.replace(/url\[(https?|ftp|gopher|news|telnet|mms|rtsp|www)(:\/\/[a-z0-9/\-_+=.~!%@?#%&;:$\\()|]+),?(.*)?\]/gi, "<a href='$1$2' title='open this link' target='_blank' style='border:dotted 1px gray'><strong>$3</strong></a>");
	return TheTEXT;
 }
 
function getFormValues(obj)
{
	return $(obj).value;
}

function SetFormValues(obj,data)
{
	$(obj).value = data;
}

function HideFromObject(obj)
{
	$(obj).style.display = "none";
}

function ShowFromObject(obj)
{
	$(obj).style.display = "";
}

function DisplayByInnerHTML(logID, logTitle)
{	
	//发表评论
	var sb = new SBuilder();
    sb.append("<form name=form1>");
	sb.append("&nbsp;Post Comment&nbsp;(Note: <font color='red'>* </font>is required)<br />&nbsp;&nbsp;");
	sb.append("<div class='postInput'><label class='postLabel' for='username"+logID+"'>Name:</label>");
	sb.append("<input type='text' name='username"+logID+"' size='22' class='postInputBox'>&nbsp;<font color='red'>*</font><br />");
	sb.append("</div>");
	sb.append("<div class='postInput'><label class='postLabel'>Sex:</label>");
	sb.append("<img border='0px' src='"+blogURL+"faces/face01.gif' onclick={face.value='"+blogURL+"images/face01.gif';ClickSex('b');} style='cursor:hand' alt='Boy'>&nbsp;<img border='0' src='"+blogURL+"faces/face05.gif' onclick={face.value='"+blogURL+"images/face05.gif';ClickSex('g');} style='cursor:hand' alt='Girl'><br />");
	sb.append("<input type='hidden' name='face' id='face'>");
	sb.append("</div>");
	sb.append("<div class='postInput'><label class='postLabel' for='email"+logID+"'>Email:</label>");
	sb.append("<input type='text' name='email"+logID+"' size='22' class='postInputBox'><br />");
	sb.append("</div>");			
	sb.append("<div class='postInput'><label class='postLabel' for='homeurl"+logID+"'>Homepage:</label>");
	sb.append("<input type='text' name='homeurl"+logID+"' size='22' value='http://' class='postInputBox'><br />");
	sb.append("</div>");
	sb.append("<div class='postInput'><label class='postLabel' for='QQ"+logID+"'>QQ:</label>");
	sb.append("<input type='text' name='QQ"+logID+"' size='22' class='postInputBox'><br />");
	sb.append("</div>");
	//faces picture
	sb.append("<div class='postInput'><label class='postLabel'>Faces:</label>");
	sb.append("<div style='cursor:pointer' onclick='AddFaces("+logID+")'>");
	sb.append("<img src='"+blogURL+"faces/angry.gif' border='0' alt='angry'");
	sb.append("<img src='"+blogURL+"faces/confused.gif' border='0' alt='confused'>");
	sb.append("<img src='"+blogURL+"faces/cool.gif' border='0' alt='cool'>");
	sb.append("<img src='"+blogURL+"faces/cry.gif' border='0' alt='cry'>");
	sb.append("<img src='"+blogURL+"faces/eek.gif' border='0' alt='eek'>");
	sb.append("<img src='"+blogURL+"faces/fd.gif' border='0' alt='fd'>");
	sb.append("<img src='"+blogURL+"faces/ft.gif' border='0' alt='ft'>");
	sb.append("<img src='"+blogURL+"faces/heart.gif' border='0' alt='heart'>");
	sb.append("<img src='"+blogURL+"faces/lol.gif' border='0' alt='lol'>");
	sb.append("<img src='"+blogURL+"faces/lovely.gif' border='0' alt='lovely'>");
	sb.append("<img src='"+blogURL+"faces/music.gif' border='0' alt='music'>");
	sb.append("&nbsp;<a onclick=\"OpenWindow('image.htm?logID="+logID+"')\" title='more pictures' style='cursor:hand'>More...</a></div></div>");
	sb.append("<div class='postInput'><label class='postLabel' for='QQ"+logID+"'>Content:</label>");
	sb.append("<textarea rows='5' id='body"+logID+"' cols='37' style='border-style:groove;background-color: #EBEBED;' title='img[URL,Width,Height]'></textarea>&nbsp;<font color='red'>*</font><br />");
	sb.append("</div>");			
	sb.append("<div class='postInput'><label class='postLabel'></label>");
	sb.append("<input type='checkbox' id='seniorEdit"+logID+"' onclick=''><label for='seniorEdit"+logID+"' style='width:200px;'>Senior Edit mode</label>");
	sb.append("</div>");			
	sb.append("<div class='postInput'><label class='postLabel'></label>");
	sb.append("<input type='button' onclick=\"postNewMsg("+logID+",'"+logTitle+"')\" value='Submit' name='submit'>");
	sb.append("&nbsp;<input type='reset' value='Reset' name='reset'><input type='hidden' name='menu' value='addto'>");
	sb.append("</div>");
    sb.append("</form>");
    $("SShow" + logID).innerHTML = sb.toString();
    ShowPostTable(logID);
    //ShowFromObject("SShow" + logID);
}

function HidePostGetTable(logID)
{
	HideFromObject("SShow" + logID);
	HideFromObject("DIV" + logID);
	HideFromObject("STATUS" + logID);
}

function IsSupportComment()
{
	var support = false;
	//var page = window.location;
	pageURL = pageURL.toString();
	if(pageURL.match(wwwMcanSite) != null)
	{
		support = true;
	}
	return support;
}

function postNewMsg(logID,logTitle)
{
	if(!CheckCommentContent(logID, ""))
	{
		return;	
	}
	HidePostGetTable(logID);		
	ShowCommentStatus("post",logID);
	Sleep(this,500);
	this.NextStep=function()
	{ 		
		var data;		
		var content = HTMLEncode(getFormValues("body"+logID));
		data="logID="+escape(logID)+"&logTitle="+escape(logTitle)+"&username="+escape(getFormValues("username"+logID))+"&email="+escape(getFormValues("email"+logID))+"&homeurl="+escape(getFormValues("homeurl"+logID))+"&QQ="+escape(getFormValues("QQ"+logID))+"&body="+escape(content);
		postdata(logID,data);
	}
}

function HTMLEncode(obj)
{
	obj = obj.replace(/\&/g,"#amp;");
	obj = obj.replace(/[ ]/g,"#nbsp;");
	obj = obj.replace(/\</g,"#lt;");
	obj = obj.replace(/\>/g,"#gt;");
	obj = obj.replace(/\"/g,"#quot;");
	obj = obj.replace(/\r\n/g,"#br;");
	obj = obj.replace(/\n/g,"#br;");
	return obj;
}

function HTMLDecode(obj)
{
	obj = obj.replace(/#nbsp;/g," ");
	obj = obj.replace(/#lt;/g,"<<span>");
	obj = obj.replace(/#gt;/g,"</span>>");
	obj = obj.replace(/#quot;/g,"\"");
	obj = obj.replace(/#br;/g,"<br>");
	obj = obj.replace(/#amp;/g,"&");
	return obj;	
}

/* Common */
function $(id)
{
	return document.getElementById(id);	
}
function echo(obj,html)
{
	$(obj).innerHTML=html;
}
function copyValue(vars,note)
{
	note=note||'Copy successfully!\r\n' + vars;
	window.clipboardData.setData('text',vars);
	if(note)
	{
		alert(note);
	}
}
//empty check
function IsEmptyObject(obj)
{
    var undefineRegex = /undefined/gi;
    if(typeof obj == "undefined" || obj == undefined 
    || obj == "" || obj == null)
    {
        return true;
    }
    return false;
}

function createxmlhttp()
{
	var xmlhttp=false;
	try	
	{
  		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} 
	catch (e) 
	{
  		try 
  		{
   			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  		} 
		catch (e) 
		{
   			xmlhttp = false;
 		}
 	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
	{
  		xmlhttp = new XMLHttpRequest();
		if (xmlhttp.overrideMimeType)
		{
			xmlhttp.overrideMimeType('text/xml');
		}
	}
	return xmlhttp;	
}

function getdata(logID)
{
	if(IsSupportComment() == false)
	{
		//alert("browse comment error, please visit from www.mcan.cn/blog");
		//window.location.href = pageURL.replace(mcanSite, "www.mcan.cn");
	}
	HidePostGetTable(logID);
	ShowCommentStatus("get",logID);
	Sleep(this,600);
	this.NextStep=function()
	{		
		var xmlhttp=createxmlhttp();
		if(!xmlhttp)
		{
			alert("你的浏览器不支持XMLHTTP！！");
			return;
		}
		xmlhttp.onreadystatechange=requestdata;
		xmlhttp.open("GET","Comment.asp?clientType=Get&logID="+logID,true);
		xmlhttp.setRequestHeader("If-Modified-Since","0");
		xmlhttp.send(null);
		function requestdata()
		{
			if(xmlhttp.readyState==4)
			{
				if(xmlhttp.status==200)
				{
						ShowFromObject("DIV" + logID);
						commentContent = xmlhttp.responseText;
						commentContent = AnalysisIMG(commentContent);															
						$("DIV" + logID).innerHTML = HTMLDecode(commentContent);
						HideFromObject("STATUS" + logID);
						GetCommentCount(logID);
				}
			}			
		}
	}
}
function postdata(logID,data)
{
	var xmlhttp=createxmlhttp();
	if(!xmlhttp)
	{
		alert("你的浏览器不支持XMLHTTP！！");
		return;
	}
	xmlhttp.onreadystatechange=requestdata;
	xmlhttp.open("POST", "Comment.asp?clientType=Post", true);
	xmlhttp.setRequestHeader("If-Modified-Since","0");
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send(data);
	function requestdata()
	{
		if(xmlhttp.readyState==4)
		{
			if(xmlhttp.status==200)
			{
				getdata(logID);
			}
		}
	}
}
//Get current log comment count
function GetCommentCount(logID)
{
//    try
//    {
//        var count = '0';
	    var xmlhttp=createxmlhttp();
	    if(!xmlhttp)
	    {
		    alert("你的浏览器不支持XMLHTTP！！");
		    return;
	    }
	    xmlhttp.onreadystatechange=requestdata;
	    xmlhttp.open("GET","Comment.asp?clientType=Count&logID="+logID,true);
	    xmlhttp.setRequestHeader("If-Modified-Since","0");
	    xmlhttp.send(null);
	    function requestdata()
	    {
		    if(xmlhttp.readyState==4)
		    {
			    if(xmlhttp.status==200)
			    {
                    $("Comment" + logID).innerText = xmlhttp.responseText;
                    $("Comment" + logID).textContent = xmlhttp.responseText;
			    }
		    }			
	    }
//	}
//	catch(e){
//	    alert(e.message);
//	    count = '0';
//	}
}

var serverInfo = "";
//login for delete comment
function CommentLogin(logID)
{
	if(!CheckCommentContent(logID, "Login"))
	{
		return;
	}
	var xmlhttp=createxmlhttp();
	if(!xmlhttp)
	{
		alert("你的浏览器不支持XMLHTTP");
		return;
	}
	xmlhttp.onreadystatechange=requestdata;
	xmlhttp.open("GET","Comment.asp?clientType=Login&password="+userPassword,true);
	xmlhttp.setRequestHeader("If-Modified-Since","0");
	xmlhttp.send(null);
	function requestdata()
	{
		if(xmlhttp.readyState==4)
		{
			if(xmlhttp.status==200)
			{
				if(xmlhttp.responseText == "success")
				{
					alert("Login successfully!");
					//refresh comment list for delete operation
					getdata(logID);							
				}
				else
				{
					alert("Login faily,please check your password!");
				}
			}
		}			
	}
}

//delete log comment
function DeleteComment(commentID, logID)
{
	HidePostGetTable(logID);
	ShowCommentStatus("delete",logID);
	Sleep(this,600);
	this.NextStep=function()
	{		
		var xmlhttp=createxmlhttp();
		if(!xmlhttp)
		{
			alert("你的浏览器不支持XMLHTTP！！");
			return;
		}
		xmlhttp.onreadystatechange=requestdata;
		xmlhttp.open("POST","comment.asp?clientType=Delete&commentID="+commentID,true);//+"&password="+passwordValue
		xmlhttp.setRequestHeader("If-Modified-Since","0");
		xmlhttp.send(null);
		function requestdata()
		{
			if(xmlhttp.readyState==4)
			{
				if(xmlhttp.status==200)
				{
					serverInfo = xmlhttp.responseText;
					if(serverInfo == "fail")
					{
							/*ShowCommentStatus("Login", logID);
							alert("Please input your password!");
							$("Login" + logID).focus();*/

							//add div mask effection
							ShowCommentStatus("Mask", logID);
							ShowLoginMask();
							$("Login" + logID).focus();
					}
					else
					{
							getdata(logID);
					}
				}
			}			
		}
	}
}

function ShowLoginMask()//frameURLPreix
{
	//window.top.scrollTo(0,0);
	var width = document.documentElement.scrollWidth;
	if(width > 1024)
	{
		width -= 300;
	}
	else
	{
		width -= 150;
	}
    $("divMask").style.height=document.body.scrollHeight;
    $("divMask").style.width=width;
    $("divMask").style.display = 'block';
    $("DivLogin").style.display = 'block';
	ScrollDiv();
    window.onscroll=ScrollDiv;
    window.onresize=ScrollDiv;
    window.onload=ScrollDiv;
}  
function HideLoginMask()
{
    $("divMask").style.display="none";
    $("DivLogin").style.display="none";
}        
function ScrollDiv()
{
	var scroll = $("DivLogin");
	if(!IsEmptyObject(scroll))
	{
		scroll.style.top=(document.documentElement.scrollTop+
		(document.documentElement.clientHeight-scroll.offsetHeight)/2)+"px";
		scroll.style.left=(document.documentElement.scrollLeft+
		(document.documentElement.clientWidth-scroll.offsetWidth)/2 - 150)+"px";
	}
}

//add faces image
function AddFaces(logID)
{
    if(event.srcElement.alt != null)
    {
	    $("body" + logID).value += "img["+event.srcElement.alt+".gif,0,0]";
	}
}

/* Mouse Drag */
function move(element,event)
{
	var x=parseInt(element.style.left);
	var y=parseInt(element.style.top);
	var deltaX=event.clientX-x;
	var deltaY=event.clientY-y;
	if(document.addEventListener)
	{
		document.addEventListener("mousemove",moveHandler,true);
		document.addEventListener("mouseup",upHandler,true);
	}else if(document.attachEvent)
	{//IE5+
		document.attachEvent("onmousemove",moveHandler);
		document.attachEvent("onmouseup",upHandler);
	}else
	{//IE4
		var oldonmousemove=document.onmousemove;
		var oldonmouseup=document.onmouseup;
		document.onmousemove=moveHandler;
		document.onmouseup=upHandler;
	}
	if(event.preventDefault)
	{
		event.preventDefault();
	}else{//IE
		event.returnValue=false;
	}

	function moveHandler(e)
	{
		if(!e)
		{//IE
			e=window.event;
		}
		element.style.left=(e.clientX-deltaX)+"px";
		element.style.top=(e.clientY-deltaY)+"px";
		if(e.stopPropagation)
		{
			e.stopPropagation();
		}else
		{//IE
			e.cancelBubble=true;
		}
	}
	
	function upHandler(e){
		if(!e){
			e=window.event;
		}
		if(document.removeEventListener){
			document.removeEventListener("mouseup",upHandler,true);
			document.removeEventListener("mousemove",moveHandler,true);
		}else if(document.detachEvent){//IE5+
			document.detachEvent("onmouseup",upHandler);
			document.detachEvent("onmousemove",moveHandler);
		}else{//IE4
			document.onmouseup=oldonmouseup;
			document.onmousemove=oldonmousemove;
		}
		if(e.stopPropagation){
			e.stopPropagation();
		}else{//IE
			e.cancelBubble=true;
		}
	}
}

/* float advertisement */
function addfollowmark(name, x, y) {
  i = objs.length;
  objs[i] = document.getElementById(name);
  objs_x[i] = x;
  objs_y[i] = y;
}
function followmark() 
{
	for(var i=0; i<objs.length; i++)
	{
		var fm = objs[i];
	    var fm_x = typeof(objs_x[i]) == 'string' ? eval(objs_x[i]) : objs_x[i];
		var fm_y = typeof(objs_y[i]) == 'string' ? eval(objs_y[i]) : objs_y[i];
	    if (fm.offsetLeft != document.body.scrollLeft + fm_x)
		{
	      var dx = (document.body.scrollLeft + fm_x - fm.offsetLeft) * step_ratio;
		  dx = (dx > 0 ? 1 : -1) * Math.ceil(Math.abs(dx));
	      fm.style.left = fm.offsetLeft + dx;
	    }
		var diffY;
		if (document.documentElement && document.documentElement.scrollTop)
			 diffY = document.documentElement.scrollTop;
		else if (document.body)
			 diffY = document.body.scrollTop;
 
		if (fm.offsetTop != diffY  + fm_y)
		{
	      var dy = (diffY  + fm_y - fm.offsetTop) * step_ratio;
	      dy = (dy > 0 ? 1 : -1) * Math.ceil(Math.abs(dy));
		  fm.style.top = fm.offsetTop + dy;
		}
	    fm.style.display = '';
  }
}
function ShowAdvertisement()
{
	document.write("<DIV id=ad_01 class='adv01'>");
	//play('adv1.swf',75,300);
	GoogleAdvertisement();
	document.write("</DIV><DIV id=ad_02 class='adv02'>");
	document.write("</DIV>");
	//addfollowmark("ad_01", 5, 180);
	//addfollowmark("ad_02", "document.body.clientWidth-105", 180);
	//setInterval('followmark()',20);	//Interval invoke, make the process better
}
function GoogleAdvertisement()
{
	document.write("<script type='text/javascript'>");
	document.write("google_ad_client = 'pub-7984514544768104';");
	document.write("google_ad_slot = '8226151777';");
	document.write("google_ad_width = 110;");
	document.write("google_ad_height = 300;");
	document.write("</script>");
	document.write("<script type='text/javascript' ");
	document.write("src='http://pagead2.googlesyndication.com/pagead/show_ads.js'>");
	document.write("</script>");
}
function Alimama()
{
    document.write("<script type='text/JavaScript'>");
    document.write("alimama_pid='mm_11385425_1266297_2724035';");
    document.write("alimama_titlecolor='0000FF';");
    document.write("alimama_descolor ='000000';");
    document.write("alimama_bgcolor='FFFFFF';");
    document.write("alimama_bordercolor='E6E6E6';");
    document.write("alimama_linkcolor='008000';");
    document.write("alimama_bottomcolor='FFFFFF';");
    document.write("alimama_anglesize='0';");
    document.write("alimama_bgpic='0';");
    document.write("alimama_icon='0';");
    document.write("alimama_sizecode='21';");
    document.write("alimama_width=120;");
    document.write("alimama_height=600;");
    document.write("alimama_type=2;");
    document.write("</script>");
    document.write("<script src='http://a.alimama.cn/inf.js' type=text/javascript> ");
    document.write("</script>");
}
/* Show Media */
function getExtension(path)
{
	var index = path.lastIndexOf(".");
	var ext = path.substr(index + 1, path.length - index).toLowerCase();
	return ext;
}
function play(path, style)
{
	var ext = getExtension(path);
	switch (ext)
	{
		case "swf":
			playSwf(path,style);
			break;
		case "rm":
		case "ram":
			playRm(path);
			break;
		case "mp3":
		case "wma":
			playWm(path,style);
			break;
		case 'rmvb':
		case 'rm':
			playRmvb(path);
			break;
		case 'mp3':
		case 'wmv':
			playWmv(path);
			break;
		default:
			playWm(path);
	}
}
function playSwf(path, style)
{
	document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" style='"+style+"'><param name=\"movie\" value=\"" + path + "\"><param name=\"quality\" value=\"high\"><embed src=\"" + path + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"468\" height=\"60\"></embed></object>");
}
function playRm(path)
{
	document.write("<object classid='clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA' id=Player name=player width='480' height='66'><param name='_ExtentX' value='12383'><param name='_ExtentY' value='1667'><param name='AUTOSTART' value='1'><param name='SHUFFLE' value='0'><param name='PREFETCH' value='0'><param name='NOLABELS' value='0'><param name='SRC' value='" + path + "'><param name='CONTROLS' value='StatusBar,ControlPanel'><param name='LOOP' value='1'><param name='NUMLOOP' value='0'><param name='CENTER' value='0'><param name='MAINTAINASPECT' value='0'><param name='BACKGROUNDCOLOR' value='#000000'><embed src='" + path + "' width='280' autostart='true' height='66'></embed></object>");
}
function playWm(path, style)
{
	document.write("<object id=\"NSPlay\" style='"+style+"' classid=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715\" standby=\"Loading Microsoft Windows Media Player components...\" type=\"application/x-oleobject\" hspace=\"5\"><param name=\"AutoRewind\" value=0><param name=\"FileName\" value=\"" + path + "\"><param name=\"ShowControls\" value=\"1\"><param name=\"loop\" value=\"0\"><param name=\"PlayCount\" value=\"1\"><param name=\"ShowPositionControls\" value=\"0\"><param name=\"ShowAudioControls\" value=\"1\"><param name=\"ShowTracker\" value=\"1\"><param name=\"ShowDisplay\" value=\"0\"><param name=\"ShowStatusBar\" value=\"1\"><param name=\"ShowGotoBar\" value=\"0\"><param name=\"ShowCaptioning\" value=\"0\"><param name=\"AutoStart\" value=0><param name=\"Volume\" value=\"-1\"><param name=\"AnimationAtStart\" value=\"0\"><param name=\"TransparentAtStart\" value=\"0\"><param name=\"AllowChangeDisplaySize\" value=\"1\"><param name=\"AllowScan\" value=\"0\"><param name=\"EnableContextMenu\" value=\"1\"><param name=\"ClickToPlay\" value=\"1\"></object>");
}
function playRmvb(path)
{
document.write('<table cellpadding=0 cellspacing=0><tr><td>');
document.write("<OBJECT ID=video1 CLASSID='clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA' HEIGHT=400 WIDTH=480><param name='_ExtentX' value='12383'><param name='_ExtentX' value='9313'><param name='_ExtentY' value='7620'><param name='AUTOSTART' value='1'><param name='SHUFFLE' value='0'><param name='PREFETCH' value='0'><param name='NOLABELS' value='0'><param name='SRC' value='" + path + "'><param name='CONTROLS' value='ImageWindow'><param name='CONSOLE' value='Clip1'><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='" + path + "' type='audio/x-pn-realaudio-plugin' CONSOLE='Clip1' CONTROLS='ImageWindow' HEIGHT='313' WIDTH='460' AUTOSTART='1'></embed></object>");
document.write('</td></tr><tr><td>');
document.write('<object id=video1 classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" height=60 width=480>');
document.write('<param name="controls" value="ControlPanel,StatusBar">');
document.write('<param name="console" value="Clip1">');
document.write('<embed type="audio/x-pn-realaudio-plugin" console="Clip1" controls="ControlPanel,StatusBar" height=60 width=480 autostart=true></embed>');
document.write('</object>');
document.write('</td></tr></table>');
}
function playWmv(path)
{
	document.write('<object id=\'NSPlay\' width=480 height=400 classid=\'CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\' codebase=\'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715\' standby=\'Loading Microsoft Windows Media Player components...\' type=\'application/x-oleobject\' hspace=\'5\'><param name=\'AutoRewind\' value=1><param name=\'FileName\' value=\'' + path + '\'><param name=\'ShowControls\' value=\'1\'><param name=\'loop\' value=\'0\'><param name=\'PlayCount\' value=\'0\'><param name=\'ShowPositionControls\' value=\'0\'><param name=\'ShowAudioControls\' value=\'1\'><param name=\'ShowTracker\' value=\'1\'><param name=\'ShowDisplay\' value=\'0\'><param name=\'ShowStatusBar\' value=\'1\'><param name=\'ShowGotoBar\' value=\'0\'><param name=\'ShowCaptioning\' value=\'0\'><param name=\'AutoStart\' value=1><param name=\'Volume\' value=\'-1\'><param name=\'AnimationAtStart\' value=\'0\'><param name=\'TransparentAtStart\' value=\'0\'><param name=\'AllowChangeDisplaySize\' value=\'0\'><param name=\'AllowScan\' value=\'0\'><param name=\'EnableContextMenu\' value=\'0\'><param name=\'ClickToPlay\' value=\'0\'></object>');
}
function Loading()
{
    $("loading").style.display = "none";
}
//setTimeout( function(){if($("loading").style.display != "none"){window.location.reload();}}, 10000);//延迟10秒刷新播放器
