function checkFriendsOnline() {
	var url = forumPrefix + "ajax.php";
	var params = "action=checkFriendsOnline&random="+Math.round(999999*Math.random())+"&sid="+sid;
	var method = "get";
	var forcecall = false;
	ajaxCall(url, params, method, forcecall);
}

function currentTimestamp() {
	var oDate = new Date();
	var tsm = oDate.getTime() + tdms;
	ts = Math.max(tsm/1000);
	return ts;
}

function doCMpopup(url, winname, w, h, resize) {
	var height, width;
	if (document.all)
	    height = document.body.offsetHeight, width = document.body.offsetWidth;
	else if (document.layers)
	    height = window.innerHeight, width = window.innerWidth;
		
	var y = (height/4)-0, x = (width/4)-0;
	
	newPopup = window.open(url,winname,"width="+w+",height="+h+",toolbar=0,scrollbars=0,directories=0,status=0,menubar=0,location=0,resizable=" + resize + ",top=" + y + ",screenY=" + y + ",left=" + x + ",screenX=" + x);
}

function removeChildren(obj) {
	while (obj.firstChild) {
		obj.removeChild(obj.firstChild);
	}
}

/*
function readSessionCookie(name) {
  var search = name + "="
  var returnvalue = false;
  return false;
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) { 
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}
*/

function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = ";expires="+date.toGMTString();
    } else {
		var expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

/*
function createSessionCookie(name, value) {
	document.cookie=name+"="+value"; path=/";
}
*/

function readCookie(name) {
  var ca = document.cookie.split(';');
	var nameEQ = name + "=";
	for(var i=0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') {
			c = c.substring(1, c.length); //delete spaces
		}
		if (c.indexOf(nameEQ) == 0) {
			return c.substring(nameEQ.length,c.length);
		}
    }
	return null;
}

function showDivAlert(divName) {
	pageBlur();
	var v = new Viewport();
	var oDivAttention = document.getElementById(divName);
	oDivAttention.style.display = 'block';
	w = oDivAttention.offsetWidth;
	h = oDivAttention.offsetHeight;
	xc = Math.round((v.windowX/2)-(w/2)+v.scrollX);
	yc = Math.round((v.windowY/2)-(h/2)+v.scrollY);
	oDivAttention.style.left = xc + "px";
	oDivAttention.style.top  = yc + "px";
}

function cancelDivAlert(divName) {
	var oDivAttention = document.getElementById(divName);
	oDivAttention.style.display = 'none';
	pageFocus();
}

function pageBlur() {
	var oDivBlur = document.getElementById('divPageBlur');
	var v = new Viewport();
	oDivBlur.style.height = v.pageY + 'px';
	oDivBlur.style.width = v.pageX + 'px';
	oDivBlur.style.display = 'block';
	//alert(v.pageY);
}

function pageFocus() {
	var oDivBlur = document.getElementById('divPageBlur');
	oDivBlur.style.display = 'none';
}

/* -----------------------------------------------------
 * JS Viewport 0.1
 * By Daniel MacDonald [http://www.danielpmacdonald.com]

 * Copyright (c) 2007 Daniel MacDonald
 * Licensed under the GNU General Public License
 * http://creativecommons.org/licenses/GPL/2.0/

 > var v = new Viewport();
 > v.windowX // returns width of browser window
 > v.windowY // returns height of browser window
 > v.scrollX // returns horizontal scroll offset
 > v.scrollY // returns vertical scroll offset
 > v.pageX // returns total width of page
 > v.pageY // returns total height of page
 * ----------------------------------------------------- 
*/

function Viewport(){
    this.windowX = (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth;
    this.windowY = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight;
    this.scrollX = (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft;
    this.scrollY = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop;
    this.pageX = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth;
    this.pageY = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
}

function checkPUB() {
	pub = readCookie('pub');
	if (!pub) {
		createCookie('pub', 'v', 1);
		doCMpopup('popupchecker.php?new=t', 10, 10, 0);
		window.setTimeout("checkPUB()", 3000);
	} else if (pub == 'v') {
		showDivAlert('alertPopupBlock');
		createCookie('pub', 't', 7);
	}
}

function reviewForm() {
	document.formName.parse.value = 'tr';
	document.formName.submit();
}
