﻿MarqueeStop = false;
function SetMarqueeText(text,href)
{
    var marq = document.getElementById("marque");
   if (marq && !MarqueeStop) 
   {
        var dt = new Date();
        marq.innerHTML = "<a href='"+href + "'>" +text + "</a>";  
   } 
}
function formateComment(str)
{
   str = str.replace( /"/g, "&quot;" ).replace( /'/g, "&apos;" ); //space
   str = str.replace(/&/g,"&amp;").replace( /</g, "&lt;" ).replace( />/g, "&gt;" ).replace(/\n/g,"<br/>").replace(/ /g,"&#160;");
   return str;
}
function $()
{
	var destinDoc = arguments[1] || this.curDocument || document;
	var id = arguments[0];
	var elements = new Array();
	if( typeof id == "string" )
	{
		return destinDoc.getElementById(id);
	}
	else if( typeof id == "object" )
	{
		for( var i = 0; i < id.length; i ++ )
		{
			var element = null;
			element = destinDoc.getElementById( id[i] );
			elements.push( element );
		}
	}
	return elements;
};
String.prototype.Trim = function() 
{ 
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 
function getObjectPosition( object )
{
	var position = [];
	position["y"] = 0;
	position["x"] = 0;
	do
	{
		position["y"] += object.offsetTop;
		position["x"] += object.offsetLeft;	
	}
	while( object = object.offsetParent );
	return position;
};
function AppendChild( doc, childNode, path )
{
    if( !doc ) 
        return false;
	if(!childNode)
		return false;
    var node = path ? doc.selectSingleNode( path ) : doc;
    if( !node )
        return false;
    //node.appendChild( childNode.cloneNode(true) );
    node.appendChild( childNode );
    return true;
};
function RemoveChild( doc, removeChildDoc, path )
{
    if( !doc || !removeChildDoc ) 
        return false;
    path = path ? path : ".";
    var node = doc.selectSingleNode( path );
    if( !node )
        return false;
    node.removeChild( removeChildDoc );
    return true;
};
/**********
thisObj:object-object which trigger the alert event
msg: string-alert message
Done:1/0-complete/warning
position:array-alert div position, if null alert will float on the bottom of thisObj
**********/
function Alert(thisObj,msg,Done,position)
{
   var arrPos = [];
   var curObj = typeof(thisObj) == "object" ? thisObj : $(thisObj);
  if (!curObj) 
  {
        return;
  } 
  arrPos = getObjectPosition(curObj); 
  var msgDiv = $("msgalert");
  if (msgDiv) //already have alert div
  {
        msgDiv.style.left = arrPos['x']+"px";
        msgDiv.style.top = arrPos['y'] +curObj.offsetHeight +"px";
        if (Done) 
        {
            msgDiv.className = "Complete";
        }
        else
        {
            msgDiv.className = "Warning";
        }
        $("AlertContent").innerHTML = msg;
  }
  else//create msg div
  {
        msgDiv = document.createElement("DIV");
        msgDiv.id = "msgalert"
        msgDiv.onclick = "alert('')"
        msgDiv.style.left = arrPos['x']+"px";
        msgDiv.style.top = arrPos['y'] +curObj.offsetHeight +"px";
        if (Done) 
        {
            msgDiv.className = "Complete";
        }
        else
        {
            msgDiv.className = "Warning";
        }
        //msgDiv.innerHTML = "<div style=\"float: right;\"><img onclick=\"HideTip(this);\" style=\"margin: 7px;\" src=\"com/img/close.gif\"/></div><div id=\"AlertContent\">"+msg+"</div></div>"
        msgDiv.innerHTML = "<div id=\"AlertContent\" onclick=\"HideTip();\">"+msg+"</div></div>"
        AppendChild( document.body, msgDiv );
  }
}
/**************/
//Obj:curreyt user-comment id
function ShowReply(Obj,needAdjust)
{
    HideTip();
    var curObj = typeof(Obj) == "object" ? Obj : $(Obj);
    if (!curObj) 
    {
        return;
    } 
    
   for(var i=0; i<curObj.childNodes.length; i++)
   {
        //if(curObj.childNodes[i].nodeType = 1)
        var msg = curObj.childNodes[i].innerText || curObj.childNodes[i].text.Trim();
        
        if( msg)
        {
            msg = ">> 回复" + msg;
            break;
        }
   }
    var arrPos = []; 
    arrPos = getObjectPosition(curObj); 
    var replyDiv = $("replaydiv");
    if (replyDiv) //already have alert div
    {
        replyDiv.cmtid = Obj; 
        replyDiv.style.left = needAdjust? arrPos['x'] + 380 +"px" : arrPos['x']+"px";
        replyDiv.style.top = arrPos['y'] +curObj.offsetHeight +"px";
        replyDiv.className = replyDiv.className.replace(/hidden/g,"");
        $("replyheader").innerHTML = msg;
        $("replyusername").focus();
    }
}
function HideReply(objid)
{
    var replyDiv = $(objid);
    if (replyDiv) //already have alert div
   {
        replyDiv.className += " hidden";
        $("replyusername").value = "";
        $("replyemail").value = "";
        $("replyarea").value = "";
        $("replycodeinput").value = "";
        ChangeCheckcode('replycode');
   } 
}
function HideTip(objid)
{
    if(!objid)
   {
        objid = "msgalert";
    } 
  var msgDiv = $(objid);
  if (msgDiv) //already have alert div  
  {
        msgDiv.className = "hidden";
  }
}
function TextAreaInputLimit(evt,obj,maxAcount)
{
    if(obj.value.length < maxAcount)
   {
        return true
    } 
    evt = (evt) ? evt : window.event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode); 
   if(charCode == 8 || charCode == 9 || charCode>36 && charCode <47)
   {
        return true;
    } 
   else
   {
        obj.value = obj.value.substr(0,maxAcount);
        return false;
   } 
}
function AjaxMsg(alertid,flg)
{
    if(flg==1)
   {
        Alert(alertid,"thanks for your participation.",1);
   } 
   else
   {
        Alert(alertid,"server error, try later!",0);
   }
}
function GetCurrentTime()
{
    var oDate = new Date();
    var month = oDate.getMonth() + 1;
    if (month <= 9)
   {
         month = "0" + month
    } 
    var day = oDate.getDate();
    if (day <= 9)
     day = "0" + day;
     
    var hour = oDate.getHours() < 10 ? "0" + oDate.getHours() : oDate.getHours();
    var min = oDate.getMinutes() < 10 ? "0" + oDate.getMinutes() : oDate.getMinutes();   
    var sec = oDate.getSeconds() < 10 ? "0" + oDate.getSeconds() : oDate.getSeconds();
    var sDate = oDate.getFullYear() + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec;
    return sDate;

};
/*=======set/get /del cookie ============*/

function SetCookie(name,cvalue,day)
{
    var Days = day!=null?day:1; //cookie expire time(day)
    var exp  = new Date();   
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (cvalue) + ";expires=" + exp.toGMTString();
}
function getCookie(name)
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;

}
function delCookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
function ValidateEmail(sText)
{
    var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;
    return reEmail.test(sText) ;
};
/*=========drag function ===========*/
var dragObj = null;
function MouseCoords(ev) {
 ev = ev || window.event;
    if (ev.pageX || ev.pageY) {
        return { x: ev.pageX, y: ev.pageY };
    }
    return {
        x: ev.clientX + document.body.scrollLeft - document.body.clientLeft,
        y: ev.clientY + document.body.scrollTop - document.body.clientTop
    };
}
function Drag()
{
 document.body.onmousedown = function( evt )
  {
   evt = evt || window.event;
   var evtTarget = evt.target || evt.srcElement;
   dragObj = evtTarget.offsetParent;
   if( !dragObj || dragObj.className.indexOf( "dragable" ) < 0 ){return;}
 	 if (evtTarget.tagName == "INPUT" || evtTarget.tagName == "TEXTAREA") 
	 {
		   return; 
	 }
   HideTip();
   var mouseCoords = MouseCoords( evt );
   dragObj.xcoord = mouseCoords.x - dragObj.offsetLeft;
   dragObj.ycoord = mouseCoords.y - dragObj.offsetTop;
   document.body.onmousemove = DragThis;
  }
 document.body.onmouseup = function( evt )
  {
   dragObj = null;
   document.body.onmousemove = null;
  }
}
function DragThis( evt)
{
 if( !dragObj )
  return;
 var mouseCoords = MouseCoords( evt );
 dragObj.style.left = (mouseCoords.x - dragObj.xcoord).toString()+"px";
 dragObj.style.top = (mouseCoords.y - dragObj.ycoord).toString()+"px";
}
function ChangeMenuColor(index)
{
    menu = $("menulist");
    if(!menu)
    {
         return;
    } 
    var imgli = document.createElement("li");
}