function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}

function GetCookie (name) {
  var arg = name + "=";
  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 SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


/**** START Instant Messanger Popup Window **********************/
function open_im_window(user_id) 
{
	var default_width_right = 200;
	var default_width = 600;
	var default_height = 500;
	var default_pos_x = 500;
	var default_pos_y = 20;
	var min_width_right = 190;
	var min_width = 560;
	var min_height = 410;
	
	var saved_pos_x  = GetCookie("flash_im_pos_x");
	var saved_pos_y  = GetCookie("flash_im_pos_y");
	var saved_width  = GetCookie("flash_im_width1");
	var saved_height = GetCookie("flash_im_height");
	
	if (saved_pos_x==null)  saved_pos_x=default_pos_x;
	if (saved_pos_y==null)  saved_pos_y=default_pos_y;
	if (saved_width==null)  saved_width=default_width_right;
	if (saved_height==null) saved_height=default_height;
	
	saved_width=parseInt(""+saved_width);
	saved_height=parseInt(""+saved_height);
	if (saved_width<min_width_right) saved_width=min_width_right;
	if (saved_height<min_height) saved_height=min_height;
	
	var open_param = 'menubar=0, resizable=1, scrollbars=0, status=0, toolbar=0, width='+saved_width+', height='+saved_height;
	if ((saved_pos_x!=null)&&(saved_pos_y!=null))
		if (window.screenLeft!=undefined) open_param+=", left="+saved_pos_x+", top="+saved_pos_y;
									 else open_param+=", screenX="+saved_pos_x+", screenY="+saved_pos_y;
	if (user_id==undefined) window.open('/w_communicator/flash_im.php','IM', open_param);
	else window.open('/w_communicator/flash_im.php?send_user='+user_id,'IM', open_param);
	return false;
}

function flash_popup(url, title, width, height) {
	window.open(url,title, '_blank','menubar=0,resizable=1,scrollbars=0,status=0,toolbar=0,width='+width+',height='+height);
}
/**** END Instant Messanger Popup Window **********************/
