

var	TABN	=	0;

function isLogged2() {
	var isLogged = (getCookieValue("name") && getCookieValue("c"));
	return			isLogged;
}
function isset(varname)  {
  if(typeof( window[ varname ] ) != "undefined") return true;
  else return false;
}
function gE(e) {
	return	document.getElementById(e);
}

function runTables(id) {//in my-subscribes && my-updates
	if (set != id) {
		document.getElementById("pnl"+set).className			= 	'tab';	
		document.getElementById("pnl"+id).className				= 	'tab current';
		document.getElementById("type"+set).style.display		=	"none";
		document.getElementById("type"+id).style.display		=	"";
		set	=	id;
	}
}

function imgFit (img, maxImgWidth)
{
  if (typeof img.naturalWidth == 'undefined') {
    img.naturalHeight = img.height;
    img.naturalWidth = img.width;
  }
  if (img.width > maxImgWidth) {
    img.height = Math.round(((maxImgWidth)/img.width)*img.height);
    img.width = maxImgWidth;
    img.title = 'Click image to view full size';
    img.style.cursor = 'move';
  } else if (img.width == maxImgWidth && img.width < img.naturalWidth) {
    img.height = img.naturalHeight;
    img.width = img.naturalWidth;
    img.title = 'Click to fit in the browser window';
  }
}
function setCookiePl(n) {
	var	pLP	=	cPlayList();
	var	p	=	"";
	for (var i=0; i<pLP.length; i++) {
		if (pLP[i] == n)  {
			reindexPlayList();
			return;
		}
		p			+=	pLP[i]+",";
	}
	p				+=	n;
	setCookie("playlist", p, "/", "");
	reindexPlayList();
}

function getCookieValue(sName) {
	var aCookie = document.cookie.split("; ");
	for (var i=0; i < aCookie.length; i++) {
		var aCrumb = aCookie[i].split("=");
		if (sName == aCrumb[0])
			return unescape(aCrumb[1]);
	}
	return null;
}

function setCookie(cN, cV, cP, cE) {
	cV = escape(cV);
	if (cE == "") {
		var nowDate = new Date();
		nowDate.setHours(nowDate.getHours() + 12)
		cE = nowDate.toGMTString();
	} if (cP != "") {
		cP = ";Path=" + cP;
	}
	document.cookie = cN + "=" + cV + ";expires=" + cE + cP;
}

function vTrim(str) {
	str						=	str.replace(/^\s+/,'');
	str						=	str.replace(/\s+$/,'');
	return						str;
}

function checkMail() {
	var f					= document.formFriend;
	var wrong				= true;
	var wrong1				= true;
	if(vTrim(f.name.value).length<2) {
							alert("Please input \"Your Name:\" ");
							return  false;
	}
	for(var n=0;n<6;n++) {
	var i		=	n?n:"";
	var v		=	vTrim(f["email"+i].value);
	if(!v)			continue;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(!filter.test(v)) {
			wrong	=	true;
						break;
	} else {
		if(n==0)wrong1	=	false;
		else	wrong	=	false;
	}
	}
	if(wrong1) {
		alert("You must fill \"Your Email\" address !");
		return false;
	}
	if(wrong) {
		alert("You must fill \"Friend's Email\" address !");
		return false;
	}
	gE("tableMail2").style.display	=	"";
	gE("tableMail").style.display	=	"none";

	return			true;
}

function ucwords(str) {
     return str.toLowerCase().replace(/\w+/g,function(s){
          return s.charAt(0).toUpperCase() + s.substr(1);
     })
}


function cgAlert(msg,obj) {
	gE('cgMsg').innerHTML	=	msg;
}
var x_left = 0;
var y_top  = 10;
function showcgAlert(obj)  {
	var msg		=	'<img src="/img/loading_white.gif">';
	gE('cgMsg').innerHTML			=	msg;
	var coors 	= 	findPos(obj);
	var x = gE("popUp");
		coors[0]		+= x_left;
		coors[1]		+= y_top;
		x.style.top 	= coors[1] + 'px';
		x.style.left 	= coors[0] + 'px';
	gE("popUp").style.visibility	=	'visible';
}

function hidecgAlert() {
	gE("popUp").style.visibility	=	'hidden';
	gE('cgMsg').innerHTML			=	'';
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop 	+= obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}
function setLyr(obj,lyr)
{
	var x = document.getElementById(lyr);
	coors[0]		-= 10;
	coors[1]		+= 10;
	x.style.top 	= coors[1] + 'px';
	x.style.left 	= coors[0] + 'px';
}
function 	handleStateChange(xmlHttpReq) {	
	
	html_content	=	getNodeValue(xmlHttpReq.responseXML.documentElement, "html_content");
	eval(html_content);
}

var	isLogged				=	false;
var	isNotActivated				=	false;

	usernameC				=	getCookieValue("username");
	idC					=	getCookieValue("id");

	isNotActivated				=	(usernameC && getCookieValue("c0"));
	isLogged				=	(usernameC && getCookieValue("c"));
