/******************************************************************************
  SupeSite/X-Sapce - common js for SS/XS
  Copyright 2001-2006 Comsenz Inc. (http://www.comsenz.com)
*******************************************************************************/
function getbyid(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	} else if (document.all) {
		return document.all[id];
	} else if (document.layers) {
		return document.layers[id];
	} else {
		return null;
	}
}

function leadingZeros(num,totalDigits) {
    var str=new String(num);
    while (str.length<totalDigits) {
        str='0'+str;
    }
    return str;
}

//checks date in the YYYY-MM-DD HH:MI format and
//pops up a msg if date is in the future
function check_date(thedate,serveroffset,futuremsg) {
    var results,reg=/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{2})/;
    if ((results=reg.exec(thedate))) {
        var mydate=new Date;
        try {
            mydate.setYear(results[1]);
            mydate.setMonth(results[2]-1);
            mydate.setDate(results[3]);
            mydate.setHours(results[4]);
            mydate.setMinutes(results[5]);

            var compareTime=new Date;
            mydate.setMilliseconds(serveroffset-mydate.getTimezoneOffset()*60000);
/*
// Temporarily remove future date alerts until we can adjust timzone
			if (mydate>compareTime) {
                alert(futuremsg);
            } else {

            }
*/
        } catch (e) {
            //alert(e);
        }

    } else {
        //if invalid, we just ignore.
        //alert('err');
    }
}
function getTipDiv(e) {
	if(getbyid("xspace-tipDiv")) {
		divElement = getbyid("xspace-tipDiv");
	} else {
		var divElement = document.createElement("DIV");
		divElement.id = "xspace-tipDiv";
		document.body.appendChild(divElement);
	}
	divElement.className = "xspace-ajaxdiv";
	divElement.style.cssText = "width:400px;";

	var offX = 4;
	var offY = 4;
	var width = 0;
	var height = 0;
	var scrollX = 0;
	var scrollY = 0;
	var x = 0;
	var y = 0;

	if (window.innerWidth) width = window.innerWidth - 18;
	else if (document.documentElement && document.documentElement.clientWidth)
		width = document.documentElement.clientWidth;
	else if (document.body && document.body.clientWidth)
		width = document.body.clientWidth;


	if (window.innerHeight) height = window.innerHeight - 18;
	else if (document.documentElement && document.documentElement.clientHeight)
		height = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight)
		height = document.body.clientHeight;


	if (typeof window.pageXOffset == "number") scrollX = window.pageXOffset;
	else if (document.documentElement && document.documentElement.scrollLeft)
		scrollX = document.documentElement.scrollLeft;
	else if (document.body && document.body.scrollLeft)
		scrollX = document.body.scrollLeft;
	else if (window.scrollX) scrollX = window.scrollX;


	if (typeof window.pageYOffset == "number") scrollY = window.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop)
		scrollY = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop)
		scrollY = document.body.scrollTop;
	else if (window.scrollY) scrollY = window.scrollY;

	x=e.pageX?e.pageX:e.clientX+scrollX;
	y=e.pageY?e.pageY:e.clientY+scrollY;

	if(x+divElement.offsetWidth+offX>width+scrollX){
		x=x-divElement.offsetWidth-offX;
		if(x<0)x=0;
	}else x=x+offX;
	if(y+divElement.offsetHeight+offY>height+scrollY){
		y=y-divElement.offsetHeight-offY;
		if(y<scrollY)y=height+scrollY-divElement.offsetHeight;
	}else y=y+offY;

	divElement.style.left = x+"px";
	divElement.style.top = y+"px";

}

function tagshow(e, tagname) {

	getTipDiv(e);
	var x = new Ajax('statusid', 'XML');

	x.get(siteUrl+'/batch.tagshow.php?tagname='+tagname, function(s){
		divElement = getbyid("xspace-tipDiv");
		divElement.innerHTML = s.lastChild.firstChild.nodeValue;
	});
}

function joinfriend(uid,referuid) {
	var x = new Ajax('statusid', 'XML');

	if(parseInt(referuid)>0){
		referuid ='&referuid='+parseInt(referuid);
	}
	x.get(siteUrl+'/batch.common.php?action=joinfriend&uid='+uid+'&referuid='+referuid, function(s){
			alert(s.lastChild.firstChild.nodeValue);
	});
}

function deletetrack(itemid) {
	var x = new Ajax('statusid', 'XML');

	x.get(siteUrl+'/batch.track.php?action=delete&itemid='+itemid, function(s){
		alert(s.lastChild.firstChild.nodeValue);
	});
}

function taghide() {
	var tip = getbyid("xspace-tipDiv");
	tip.style.display = 'none';
}

function addFirstTag() {
	var lists=new Array;
	lists=document.getElementsByTagName('ul');
	for(i=0;i<lists.length;i++){
		lists[i].firstChild.className+=' first-child';
	}
}

function setTab(area,id) {
	var tabArea=document.getElementById(area);

	var contents=tabArea.childNodes;
	for(i=0; i<contents.length; i++) {
		if(contents[i].className=='tabcontent'){contents[i].style.display='none';}
	}
	document.getElementById(id).style.display='';

	var tabs=document.getElementById(area+'tabs').getElementsByTagName('span');
	for(i=0; i<tabs.length; i++) { tabs[i].className=''; }
	document.getElementById(id+'tab').className='active';
}

function ColExpIntro(obj) {
	var thisIntro=obj.parentNode.getElementsByTagName('p')[0];
	if(thisIntro.style.display=='none'){
		thisIntro.style.display='';
	}else{
		thisIntro.style.display='none';
	}
}
function ColExpAllIntro(obj) {
	var ctrlText=document.getElementById('ColExpAllIntroText');
	var Intros=obj.parentNode.parentNode.getElementsByTagName('p');
	if(ctrlText.innerHTML=='顯示摘要'){
		ctrlText.innerHTML='隱藏摘要';
		for(i=0;i<Intros.length;i++){
			Intros[i].style.display='';
		}
	}else{
		ctrlText.innerHTML='顯示摘要';
		for(i=0;i<Intros.length;i++){
			Intros[i].style.display='none';
		}
	}
}

function OpenWindow(url, winName, width, height) {
	xposition=0; yposition=0;
	if ((parseInt(navigator.appVersion) >= 4 )) {
		xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;
	}
	theproperty= "width=" + width + ","
	+ "height=" + height + ","
	+ "location=0,"
	+ "menubar=0,"
	+ "resizable=1,"
	+ "scrollbars=1,"
	+ "status=0,"
	+ "titlebar=0,"
	+ "toolbar=0,"
	+ "hotkeys=0,"
	+ "screenx=" + xposition + "," //僅適用於Netscape
	+ "screeny=" + yposition + "," //僅適用於Netscape
	+ "left=" + xposition + "," //IE
	+ "top=" + yposition; //IE
	window.open(url, winName, theproperty);
}

function joinfavorite(itemid) {
	var x = new Ajax('statusid', 'XML');
	x.get(siteUrl + '/batch.common.php?action=joinfavorite&itemid='+itemid, function(s) {
		alert(s.lastChild.firstChild.nodeValue);
	});
}

function showajaxdiv(action, url, width) {
	var x = new Ajax('statusid', 'XML');
	x.get(url, function(s) {
		if(getbyid("xspace-ajax-div-"+action)) {
			var divElement = getbyid("xspace-ajax-div-"+action);
		} else {
			var divElement = document.createElement("DIV");
			divElement.id = "xspace-ajax-div-"+action;
			divElement.className = "xspace-ajaxdiv";
			document.body.appendChild(divElement);
		}
		divElement.style.cssText = "width:"+width+"px;";
		var userAgent = navigator.userAgent.toLowerCase();
		var is_opera = (userAgent.indexOf('opera') != -1);
		var clientHeight = scrollTop = 0;
		if(is_opera) {
			clientHeight = document.body.clientHeight /2;
			scrollTop = document.body.scrollTop;
		} else {
			clientHeight = document.documentElement.clientHeight /2;
			scrollTop = document.documentElement.scrollTop;
		}
		divElement.innerHTML = s.lastChild.firstChild.nodeValue;
		divElement.style.left = (document.documentElement.clientWidth /2 +document.documentElement.scrollLeft - width/2)+"px";
		divElement.style.top = (clientHeight + scrollTop - divElement.clientHeight/2)+"px";

	});
}


function getMsg() {
	if (GetCookie('readMsg')!='1') {
		var msgDiv = document.createElement('div');
		msgDiv.id = 'xspace-sitemsg';
		msgDiv.innerHTML = "<h6><a href='javascript:;' onclick='closeMsg();' class='xspace-close'>關閉</a>公告:</h6><div>"+siteMsg+"<p class='xspace-more'><a href='"+siteUrl+"/index.php?action_announcement' target='_blank'>MORE</a></p></div>";
		document.body.insertBefore(msgDiv,document.body.firstChild);

		showMsg();
	}
}
function floatMsg() {
	window.onscroll = function() {
		document.getElementById('xspace-sitemsg').style.bottom = '10px';
		document.getElementById('xspace-sitemsg').style.background = '#EEF0F6';
	}
}
function showMsg() {
	var vh = document.getElementById('xspace-sitemsg').style.bottom;
	if (vh=='') {vh='-180px'}
	var vhLen = vh.length-2;
	var vhNum = parseInt(vh.substring(0,vhLen));

	if (vhNum<10) {
		document.getElementById('xspace-sitemsg').style.bottom = (vhNum+5)+'px';
		showvotetime = setTimeout("showMsg()",1);
	} else {
		floatMsg();
	}
}
function closeMsg() {
	document.getElementById('xspace-sitemsg').style.display = 'none';
	CreatCookie('readMsg','1');
}


/*Cookie操作*/
function CreatCookie(sName,sValue){
	var expires = function(){ //Cookie保留時間
		var mydate = new Date();
		mydate.setTime(mydate.getTime + 3*30*24*60*60*1000);
		return mydate.toGMTString();
	}
	document.cookie = sName + "=" + sValue + ";expires=" + expires;
}
function GetCookieVal(offset) {//獲得Cookie解碼後的值
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie(sName) {//獲得Cookie
	var arg = sName + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return GetCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function DelCookie(sName,sValue){ //刪除Cookie
	document.cookie = sName + "=" + escape(sValue) + ";expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}

//顯示工具條
function hidetoolbar() {
	window.parent.document.getElementById("toolbarframe").style.display="none";
}
function showtoolbar() {
	document.getElementById("toolbarframe").style.display = "block";
}
function mngLink(obj) {
	var wrap = window.parent.document.getElementById('wrap');
	if(wrap == null) {
		alert('本按鈕僅對拖拽模板有效！');
		return false;
	}
	if (wrap.className=='') {
		wrap.className = 'hidemnglink';
		obj.innerHTML = '顯示編輯按鈕';
	} else {
		wrap.className = '';
		obj.innerHTML = '隱藏編輯按鈕';
	}
}

//複製URL地址
function setCopy(_sTxt){
	if(navigator.userAgent.toLowerCase().indexOf('ie') > -1) {
		clipboardData.setData('Text',_sTxt);
		alert ("網址「"+_sTxt+"」\n已經複製到您的剪貼板中\n您可以使用Ctrl+V快捷鍵粘貼到需要的地方");
	} else {
		prompt("請複製網站地址:",_sTxt);
	}
}

//加入收藏
function addBookmark(site, url){
	if(navigator.userAgent.toLowerCase().indexOf('ie') > -1) {
		window.external.addFavorite(url,site)
	} else if (navigator.userAgent.toLowerCase().indexOf('opera') > -1) {
		alert ("請使用Ctrl+T將本頁加入收藏夾");
	} else {
		alert ("請使用Ctrl+D將本頁加入收藏夾");
	}
}

//評分
function setRate(value) {
	getbyid('xspace-ratevalue').value = value;
	getbyid('xspace-rates').className = 'xspace-rates'+value;
}

function adclick(id) {
	var x = new Ajax('statusid', 'XML');
	x.get(siteUrl + '/batch.common.php?action=adclick&id='+id, function(s){});
}
function display(id) {
	dobj = getbyid(id);
	if(dobj.style.display == 'none' || dobj.style.display == '') {
		dobj.style.display = 'block';
	} else {
		dobj.style.display = 'none';
	}
}


//顯示隱藏媒體
function addMediaAction(div) {
	if (getbyid(div)) {
		var medias = getbyid(div).getElementsByTagName('kbd');
		for (i = 0; i < medias.length; i++) {
			if ((medias[i].className == 'showvideo') || (medias[i].className.indexOf('showflash', 0) == 0)) {
				medias[i].onclick = function(){
					showmedia(this, 400, 400)
				};
				medias[i].onclick();
			}
		}
	}
}

function extractMediaInfo(str,base,first,second) {
    var index,tempString;
    var strLen=first.length;

    index=str.lastIndexOf(first);
    if (index!=-1) {
        if (first==second) {
            index=str.lastIndexOf(first,index-strLen);
        }
        if (index!=-1) {
            tempString=str.substr(index+strLen,str.length-index-strLen);
            if (second) {
                index=tempString.indexOf(second);
                if (index!=-1) {
                    tempString=tempString.substr(0,index);
                }
            }
            str=base+tempString;
        }
    }
    return str;
}

function showmedia(Obj, mWidth, mHeight) {
	var mediaStr, smFile;
	if ( Obj.tagName.toLowerCase()=='a' ) { smFile = Obj.href; } else { smFile = Obj.title; }
	var smFileType = Obj.className.toLowerCase();

        if (smFileType=='showflash') {
            if (smFile.indexOf('youtube.com')!=-1) {
                smFileType='showflash-youtube';
                smFile=extractMediaInfo(smFile,'http://www.youtube.com/v/','v=');
            } else if (smFile.indexOf('google.com')!=-1) {
                smFileType='showflash-google';
                smFile=extractMediaInfo(smFile,'','docid=','&');
            } else if (smFile.indexOf('videoegg.com')!=-1) {
                smFileType='showflash-videoegg';
                smFile=extractMediaInfo(smFile,'','/','#');
            } else if (smFile.indexOf('myspace.com')!=-1 || smFile.indexOf('myspacetv.com')!=-1) {
                smFileType='showflash-myspace';
                smFile=extractMediaInfo(smFile,'','videoid=','&');
            } else if (smFile.indexOf('qq.com')!=-1) {
                smFileType='showflash-qq';
                smFile=extractMediaInfo(smFile,'','v=','&');
            } else if (smFile.indexOf('tudou.com')!=-1) {
                smFileType='showflash-tudou';
                smFile=extractMediaInfo(smFile,'','/','/');
            } else if (smFile.indexOf('uume.com')!=-1) {
                smFileType='showflash-uume';
                smFile=extractMediaInfo(smFile,'','/play_','?');
            } else if (smFile.indexOf('56.com')!=-1) {
                smFileType='showflash-56';
                smFile=extractMediaInfo(smFile,'','/play_','?');
} else if (smFile.indexOf('sina.com.cn')!=-1) {
                smFileType='showflash-sina-cn';
                smFile=extractMediaInfo(smFile,'','/','.');
                var index;
                index=smFile.indexOf('-');
                if (index!=-1) {
                    vStr=smFile.substr(0,index);
                    uStr=smFile.substr(index+1,smFile.length-index-1);
                }
            }

        }
	switch(smFileType){
		case "showflash":
			mediaStr="<p style='text-align: right; margin: 0.3em 0; width: 400px;'>[<a href='"+smFile+"' target='_blank'>全屏觀看</a>]</p><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='400' height='260'><param name='movie' value='"+smFile+"'><param name='quality' value='high'><param name='AllowScriptAccess' value='never'><embed src='"+smFile+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='400' height='260'></embed></OBJECT>";
			break;
        case "showflash-youtube":
            mediaStr='<object width="425" height="355"><param name="movie" value="'+smFile+'"></param><param name="wmode" value="transparent"></param><embed src="'+smFile+'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>';
            break;
        case 'showflash-qq':
            mediaStr='<object id="flashplayer" classid="clsid:D27CDB6E-AE6D-11cf- 96B8-444553540000" width="456" height="362"><param name="movie" value="http://static.video.qq.com/v1/res/qqplayerout.swf?v='+smFile+'" /><param name="allowFullScreen" value="true" /><param name="wmode" value="transparent"><param name="flashvars" value="vid='+smFile+'&cgi=http%3A//video.qq.com/bin/vrank%3Ftype%3D8%26start%3D1%26end%3D8&vhost=http://v.video.qq.com/&phost=http://p.video.qq.com/"><embed type="application/x-shockwave-flash" src="http://static.video.qq.com/v1/res/qqplayerout.swf?v='+smFile+'" width="456" height="362" id="flashplayer" name="flashplayer" quality="high" allowScriptAccess="sameDomain" allowFullScreen="true" wmode="transparent" flashvars="vid='+smFile+'&cgi=http%3A//video.qq.com/bin/vrank%3Ftype%3D8%26start%3D1%26end%3D8&vhost=http://v.video.qq.com/&phost=http://p.video.qq.com/"></embed></object>';
        case 'showflash-tudou':
            mediaStr='<object width="400" height="350"><param name="movie" value="http://www.tudou.com/v/'+smFile+'"></param><param name="allowScriptAccess" value="always"></param><param name="wmode" value="transparent"></param><embed src="http://www.tudou.com/v/'+smFile+'" type="application/x-shockwave-flash" width="400" height="350" allowFullScreen="true" wmode="transparent" allowScriptAccess="always"></embed></object>';
            break;
        case 'showflash-uume':
            mediaStr='<object width="400" height="342"><param name="movie" value="http://www.uume.com/v/'+smFile+'_UUME"></param><embed src="http://www.uume.com/v/'+smFile+'_UUME" type="application/x-shockwave-flash" width="400" height="342"></embed></object>';
            break;
        case 'showflash-sina-cn':
            mediaStr='<object width="474" height="461"><param name="wmode" value="transparent" /><param name="movie" value="http://v.blog.sina.com.cn/b/vblog_player.swf?vid='+vStr+'&uid='+uStr+'&initfull=0&cursound=null"/></param><embed src="http://v.blog.sina.com.cn/b/vblog_player.swf?vid='+vStr+'&uid='+uStr+'&initfull=0&cursound=null" wmode="transparent" type="application/x-shockwave-flash" width="474" height="461"></embed></object>';
            break;
        case 'showflash-google':
            mediaStr='<embed FlashVars="" style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId='+smFile+'"></embed>';
            break;
        case 'showflash-videoegg':
            mediaStr='<embed src="http://static.videoegg.com/videoegg/loader.swf" FlashVars="bgColor=FFFFFF&file=http://download.videoegg.com/'+smFile+'_high.flv&autoPlay=false&forcePlay=false&logo=&allowFullscreen=true&allowFlash9Fullscreen=true" quality="high" allowScriptAccess="always" bgcolor="#FFFFFF" scale="noscale" wmode="window" width="320" height="260" name="VE_Player" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
            break;
        case 'showflash-myspace':
            mediaStr='<embed src="http://lads.myspace.com/videos/vplayer.swf" flashvars="m='+smFile+'&v=2&type=video" type="application/x-shockwave-flash" width="430" height="346"></embed>';
            break;
		case "showvideo":
			mediaStr="<object width='400' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'><param name='url' value='"+smFile+"' /><embed width='400' type='application/x-mplayer2' src='"+smFile+"'></embed></object>";
	}

	var mediaDiv = document.getElementById(escape(smFile.toLowerCase()));

	if (mediaDiv) {
		Obj.parentNode.removeChild(mediaDiv);
	} else {
		mediaDiv = document.createElement("div");
		mediaDiv.id = escape(smFile.toLowerCase());
		mediaDiv.innerHTML = mediaStr;
		Obj.parentNode.insertBefore(mediaDiv,Obj.nextSibling);
	}
	return false;
}

//改變文章字體大小
function doZoom(size) {
	getbyid('articlebody').style.fontSize = size+'px';
}
//打印
function doPrint(){
	var csslink = document.getElementsByTagName('link');
	for (i=0; i<csslink.length; i++) {
		if (csslink[i].rel=='stylesheet') {
			csslink[i].disabled=true;
		}
	}

	printCSS = document.createElement("link");
	printCSS.id = 'printcss';
	printCSS.type = 'text/css';
	printCSS.rel = 'stylesheet';
	printCSS.href = siteUrl+'/css/print.css';

	var docHead = document.getElementsByTagName('head')[0];
	var mainCSS = csslink[0];
	docHead.insertBefore(printCSS,mainCSS);

	var articleTitle = document.getElementsByTagName('h1')[0];
	var cancelPrint = document.createElement("p");
	cancelPrint.id = 'cancelPrint';
	cancelPrint.style.textAlign = 'right';
	cancelPrint.innerHTML = "<a href='javascript:cancelPrint();' target='_self'>返回</a>&nbsp;&nbsp;<a href='javascript:window.print();' target='_self>打印</a>";
	getbyid('articledetail').insertBefore(cancelPrint,articleTitle);

	window.print();
}
function cancelPrint() {
	if (printCSS) {
		document.getElementsByTagName('head')[0].removeChild(printCSS);
	}

	var csslink = document.getElementsByTagName('link');
	for (i=0; i<csslink.length; i++) {
		if (csslink[i].rel=='stylesheet') {
			csslink[i].disabled=false;
		}
	}

	if (getbyid('cancelPrint')) {
		getbyid('articledetail').removeChild(getbyid('cancelPrint'));
	}
}

//添加文章中的圖片鏈接
function addImgLink(divID) {
	var msgarea = getbyid(divID);
	var imgs = msgarea.getElementsByTagName('img');
	for (i=0; i<imgs.length; i++) {
		if (imgs[i].parentNode.tagName.toLowerCase() != 'a') {
			imgs[i].title = '點擊圖片可在新窗口打開';
			imgs[i].style.cursor = 'pointer';
			imgs[i].onclick = function() { window.open(this.src); }
		}
	}
}

// Add in DHTML/JS-based rollover menus
function showSubMenu() {
	var objThis = this;
	for(var i = 0; i  < objThis.childNodes.length; i++) {
		if(objThis.childNodes.item(i).nodeName == "UL") {
			objThis.childNodes.item(i).style.display = "block";
		}
	}
}

function hideSubMenu( elementName )
{
	var objThis = this;
	for(var i = 0; i  < objThis.childNodes.length; i++) {
		if(objThis.childNodes.item(i).nodeName == "UL") {
			objThis.childNodes.item(i).style.display = "none";
			return;
		}
	}
}

function registerMenu( elementName ) {
	var elementObj = document.getElementById(elementName);
	var objLICollection = elementObj.getElementsByTagName("LI");
	for(var i = 0; i < objLICollection.length; i++) {
		var objLI = objLICollection[i];
		for(var j = 0; j  < objLI.childNodes.length; j++) {
			if(objLI.childNodes.item(j).nodeName == "UL") {
				objLI.onmouseover=showSubMenu;
				objLI.onmouseout=hideSubMenu;

				for(var j = 0; j  < objLI.childNodes.length; j++) {
					if(objLI.childNodes.item(j).nodeName == "A") {
						objLI.childNodes.item(j).className = "hassubmenu";
					}
				}
			}
		}
	}
}

function toggleMenu (elementName, toggleImgName) {
	var elementObj = document.getElementById(elementName);
	if (elementObj) {
		if (elementObj.style.display == 'none') {
			elementObj.style.display = 'block';
			if (toggleImgName) {
				toggleImgName.style.backgroundImage = 'url(./images/top/button-minus.gif)';
			}
		} else {
			elementObj.style.display = 'none';
			if (toggleImgName) {
				toggleImgName.style.backgroundImage = 'url(./images/top/button-plus.gif)';
			}
		}
		return true;
	} else {
		return false;
	}
}

function currentTime() {
    var d=new Date();
    return d.getTime();
}

var offset=(new Date()).getTimezoneOffset()/60*-1;
document.cookie='supe_tzo='+offset+';path=/;';

var languagemenustatus = false;

function languageRollover () {
	var languageArrow = document.getElementById('languagearrow');
	var languageTxt= document.getElementById('languagetxt');
	if( !languagemenustatus ) {
		if( languageArrow.className == 'languagearrowdefault' ) {
			languageArrow.className = 'languagearrowrollover';
			languageTxt.className = 'languagetxtrollover';
		} else {
			languageArrow.className = 'languagearrowdefault';
			languageTxt.className = 'languagetxtdefault';
		}
	}
	return true;
}

function toggleLanguageMenu() {
	var languageMenu = document.getElementById('languagemenu');
	var languageArrow = document.getElementById('languagearrow');
	var languageTxt= document.getElementById('languagetxt');
	if( languageMenu.style.display == 'none' ) {
		languageMenu.style.display = 'block';
		languageArrow.className = 'languagearrowonclick';
		languageTxt.className = 'languagetxtonclick';
		languagemenustatus = true;
	} else {
		languageMenu.style.display = 'none';
		languageArrow.className = 'languagearrowrollover';
		languageTxt.className = 'languagetxtrollover';
		languagemenustatus = false;
	}
	return true;
}

function barRollover (id) {
	var elementId = document.getElementById(id);
	if( id == 'tabhelp' ) {
		if( elementId.className == 'tabhelpdefault' ) {
			elementId.className = 'tabhelprollover';
		} else {
			elementId.className = 'tabhelpdefault';
		}
	} else {
		if( elementId.className == 'tabdefault' ) {
			elementId.className = 'tabrollover';
		} else {
			elementId.className = 'tabdefault';
		}
	}
	return true;
}

var searchmenustatus = false;
function searchRollover (id) {
	var elementId = document.getElementById(id);
	if( !searchmenustatus ) {
		if( elementId.className == id+'default' ) {
			elementId.className = id+'rollover';
		} else {
			elementId.className = id+'default';
		}
	}
	return true;
}
function toggleSearchMenu() {
	var searchMenu = document.getElementById('searchmenu');
	var searchArrow = document.getElementById('searcharrow');
	var searchTxt= document.getElementById('searchtxt');
	if( searchMenu.style.display == 'none' ) {
		searchMenu.style.display = 'block';
		searchArrow.className = 'searcharrowonclick';
		searchTxt.className = 'searchtxtonclick';
		searchmenustatus = true;
	} else {
		searchMenu.style.display = 'none';
		searchArrow.className = 'searcharrowrollover';
		searchTxt.className = 'searchtxtdefault';
		searchmenustatus = false;
	}
	return true;
}
function selectSearchMenu( id ) {
	var itemSearch = document.getElementById('itemsearchdefault');
	var itemUsers = document.getElementById('itemsearchusers');
	var itemBlog = document.getElementById('itemsearchblog');
	var itemForum = document.getElementById('itemsearchforum');
	var selectUsers = document.getElementById('selectsearchusers');
	var selectBlog = document.getElementById('selectsearchblog');
	var selectForum = document.getElementById('selectsearchforum');
	var formUsers = document.getElementById('usersearch');
	var formBlog = document.getElementById('messagesearch');
	var formForum = document.getElementById('forumsearch');
	var searchMenu = document.getElementById('searchmenu');
	var searchArrow = document.getElementById('searcharrow');
	var searchTxt= document.getElementById('searchtxt');
	if( id == 'users' ) {
		itemUsers.style.display = 'block';
		itemSearch.style.display = itemBlog.style.display = itemForum.style.display = 'none';
		selectUsers.style.fontWeight = 'bold';
		selectBlog.style.fontWeight = selectForum.style.fontWeight = 'normal';
		formUsers.value = 1;
		formBlog.value = formForum.value = 0;
	} else if( id == 'blog' ) {
		itemBlog.style.display = 'block';
		itemSearch.style.display = itemUsers.style.display = itemForum.style.display = 'none';
		selectBlog.style.fontWeight = 'bold';
		selectUsers.style.fontWeight = selectForum.style.fontWeight = 'normal';
		formBlog.value = 1;
		formUsers.value = formForum.value = 0;
	} else {
		itemForum.style.display = 'block';
		itemSearch.style.display = itemUsers.style.display = itemBlog.style.display = 'none';
		selectForum.style.fontWeight = 'bold';
		selectUsers.style.fontWeight = selectBlog.style.fontWeight = 'normal';
		formForum.value = 1;
		formUsers.value = formBlog.value = 0;
	}
	searchMenu.style.display = 'none';
	searchArrow.className = 'searcharrowdefault';
	searchTxt.className = 'searchtxtdefault';
	searchmenustatus = false;
	return true;
}

function hideprofileblock(block,side) {
	if( block ) {
		if( document.getElementById( block ) ) {
			document.getElementById( block ).style.display='none';
		}
		new Ajax2('/batch.common.php', {
				data:'action=hideblock&block='+block+'&side='+side,
				method:'get'
			}).request();
		
	}
}

//inserts info into track_stats table using batch.stats.php
function track_record (id, datamore, serialized, complete) {
	if( parseInt(id)>0 ) {
		if( datamore ) {
			if( !serialized ) {
				datamore = Json.toString(datamore);
			}
		} else {
			datamore = "";
		}
		if(typeof complete =='undefined') {
			complete = Class.empty;
		}
		var myAjax = new Ajax2("/batch.common.php?action=track_record",{method: 'post', data: 'id='+id+'&datamore='+datamore, onComplete:complete});
		
		myAjax.request();
	}
}

/**
* This is a function for setting the window hash withough 
* causing the browser to save history for every change
*/
function saveAnchor(anchor) {
    var oldurl=window.location.href;
    var pos=oldurl.indexOf('#');
    if (pos>=0) {
        oldurl=oldurl.substring(0,pos);
    }
    window.location.replace(oldurl+'#return-'+anchor);
}

/**
* code to set the anchor if it was saved using the saveAnchor function
* the point behind not using the anchors directly is that the 
* window.location.replace statement causes the page to shift if
* a real anchor is used.
*/
if (window.location.hash.indexOf('#return-')>=0) {
    var len=window.location.hash.length;
    var newHash=window.location.hash.substring(8,len);
    var oldurl=window.location.href;
    var pos=oldurl.indexOf('#');
    if (pos>=0) {
        oldurl=oldurl.substring(0,pos);
    }
    window.location.replace=oldurl+'#'+newHash;
}

/**
* function to save a persistent information in database
*/
function set_persistent (id, value, expire, complete) {
        if(typeof complete =='undefined') {
            complete = Class.empty;
        }
        var myAjax = new Ajax2("/batch.common.php?action=set_persistent",{
            method: 'post', 
            data: 'skey='+escape(id)+'&expire='+expire+'&value='+Json.toString(value), 
            onComplete:function(txt) {if(txt=='ok') {complete.attempt()}}
        });
        
        myAjax.request();
}
/**
* function to save a persistent information in database
*/
function get_persistent (id, complete) {
        var result='';
        if(typeof complete =='undefined') {
            complete = function(txt) {
                result = txt;
            };
        }
        var myAjax = new Ajax2("/batch.common.php?action=get_persitent",{
            method: 'post', 
            data: 'skey='+escape(id), 
            onComplete:complete.bind(this)
        });
        
        myAjax.request();
}

/**
* block/unblock item
*/
function set_item_lock (itemid, status) {


	var x = new Ajax('statusid', 'XML');
	x.get(siteUrl + '/batch.common.php?action=set_item_lock&itemid='+itemid+'&status='+status, function(s) {
		alert(s.lastChild.firstChild.nodeValue);
	});
/*
    var myXHR = new XHR({method: 'get',
        'onSuccess':function() {
            var s=myXHR.response.xml;
            alert(s.lastChild.firstChild.nodeValue);
        }}).send(siteUrl + '/batch.common.php?action=set_item_lock&itemid='+itemid+'&status='+status);*/
}

//legacy support for old ajax.js stuff
if (!window.Ajax) {
    window.Ajax=function() {
        
    }
    window.Ajax.prototype.get=function(url,callback) {
        var retVal;
        var myXHR = new XHR({async: false, method: 'get'
            });
        myXHR.send(url);
        if (callback)
            callback(myXHR.transport.responseXML);
    }
    window.ajax_json_handler=function(url,func,synchronous) {

        var obj=new Json.Remote(url,{method: "get",async:!synchronous,onComplete:function(result) {
            if (func) {
                func(result);
            }
        }}).send();
        if (synchronous) {
            obj.fireEvent('onComplete',eval(obj.transport.responseText));
        }
    }
}