// call google analytics code
function g_analytics(userid) {
       __utmSetVar(userid); _uff = 0;  _uacct = "UA-817093-7"; urchinTracker();
}
     
function strrev(str){if(!str)return '';var revstr='';for(i=str.length-1;i>=0;i--)
revstr+=str.charAt(i);return revstr;}
var sdomain=strrev(document.domain);function create_httpobject(objName){try{window[objName]=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");}
catch(e){window[objName]=false;}
return window[objName];}

var time1 = 0;
var time2 = 0;
function populate_httpdiv(urlval,divval,retry){
		try{
			var objname=divval+'_obj';window[objname]=create_httpobject(divval+'_obj');
			if(window[divval+'_obj']){
				window[objname].onreadystatechange=function(){
						if(window[objname].readyState==4){
							if(window[objname].status==200){
								time1 = (new Date()).getTime();
								while(true){
									if(document.getElementById(divval))	{
										document.getElementById(divval).innerHTML=window[objname].responseText;
										break;
									}
									time2 = (new Date()).getTime();
									if((time2-time1)>120000)//timeout in miliseconds for the infinite loop
										break;
								}
							}else {
								if(retry>1){
								retry=retry-1;
								populate_httpdiv(urlval,divval,retry);
								}	else	{
								document.getElementById(divval).innerHTML="<font color='white'>.</font>";
								}
							}
					    }
					}
					window[objname].open('get',urlval,true);
					window[objname].send(null);
				}
		}
	catch(e){document.getElementById(divval).innerHTML="";
}}
function gamesearch(typeval){var gameid=document.searchgame.gid.value;gameid_arr=gameid.split("||");if(gameid=='0'){alert('Please select game !');}
else{if(gameid_arr[1]=='m'){document.location.href=gameid_arr[0];}
else if(typeval==1){document.location.href='http://www.zapak.com'+gameid_arr[0];}
else{document.location.href=gameid_arr[0];}
return false;}}
//*********For remember username and password
function set_cookie( name, value, expires) 
{
	var domain=null;
	var today = new Date();
	today.setTime( today.getTime() );

	if (expires)
		expires = expires * 1000 * 60 * 60 * 24;

	var expires_date = new Date(today.getTime() + (expires));
	document.cookie = name + "=" +escape( value ) +
	((expires) ? ";expires=" + expires_date.toGMTString() : "")+
	((domain) ? ";domain=" + domain : "");
}

function get_cookie(name) 
{
	var start = document.cookie.indexOf(name + "=");
	var len = start + name.length + 1;
	if ((!start) && (name != document.cookie.substring(0, name.length)))
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf(";", len);
	if (end == -1) 
		end = document.cookie.length;
	return unescape( document.cookie.substring(len, end));
}

function delete_cookie(name) {
if(get_cookie(name)) 
	document.cookie = name + "=;expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
function create_httploginobject(objName) {
	try {
		window[objName] = window.XMLHttpRequest?new XMLHttpRequest():
		new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (e) {
		window[objName] = false; 
	}
	return window[objName];
}

function isrememberchkd()
{
	var Username = get_cookie('username');
	var password = get_cookie('ssapresu');
//	var Isloggedin= get_cookie('loginexist');

	var remme= get_cookie('remember');
   	var topbardval =new Date();
	var topbardvalTime = topbardval.getTime();
	if (remme!=null && remme!="" && password!=null && password!="")
    	{
//    		var authurl = '/autoauthenticateuser.z?tval='+topbardvalTime;
			makehttpcall(authurl,Username);
    	} else {
    }
}

function makehttpcall(urlval,uid) {
	try {
		var objname = 'http_obj';
		window[objname] = create_httploginobject(objname);
		if (window[objname] ) {
			window[objname].onreadystatechange=function() {
                if (window[objname].readyState==4)
                { 
					if (window[objname].status==200) 
					{
						document.getElementById("autologin").innerHTML= '<strong>Hi '+uid+'</strong>&nbsp;| <a href="/myaccount.z">My Account</a> | <a href="/mefb.z?mode=compose&type=feedback">Feedback</a> | <a href="/help.z?pid=7">Help</a> | <a href="/loggout.z">Signout</a>';
					} else {}
				} else{}
			}
			window[objname].open('get',urlval,true);
			window[objname].send(null);
		}
	}
	catch (e) {	return false;}	
}

var intPopulateID = 0;
var searchCount = 0;
function populate_dropbox(vtype, cnt) {  	
	if( document.getElementById('search_box') != undefined)
	{
		populate_httpdiv('/cgsearchlist.z?vtype='+vtype,'search_box',2);
		window.clearInterval(intPopulateID);					
	}else if(searchCount >= cnt){
		window.clearInterval(intPopulateID);
	}else{
		searchCount = searchCount + 1;
		if (intPopulateID == 0)
		   intPopulateID = window.setInterval("populate_dropbox('"+vtype+"',"+cnt+");",1000);
	}				
}

function TrackEnter(e){
	var type = '<xsl:value-of select="ActionParams/@type" />';	
	var keynum;
	if(window.event) // IE
	{
		keynum = e.keyCode
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which
	}
	if (keynum == 13)
	{
		if(type == 1)
			gamesearch(1);
		else
			gamesearch(0);
	}
}

function call_http_multiple(urlval,method,divval,retry, callback) { //delete this fn later
	var objname=divval+'_obj'; 
	objname=create_httpobject(divval+'_obj');
	if(objname){
		objname.onreadystatechange=function() {
				if(objname.readyState==4) {
					if(objname.status==200) {
							callback(objname);
					}
					else{
						if(retry>1)			{ 
							retry=retry-1;
							call_http_multiple(urlval,divval,retry, callback);
						}else {
							document.getElementById(divval).innerHTML="<font color='white'>.</font>";
						}
					}
				}
		}
		objname.open(method,urlval,true);
		objname.send(null);
	}
}
function call_http_get(urlval,divval,retry, callback) {
	var objname=divval+'_obj'; 
	objname=create_httpobject(divval+'_obj');
	if(objname){
		objname.onreadystatechange=function() {
				if(objname.readyState==4) {
					if(objname.status==200) {
							callback(objname);
					}
					else{
						if(retry>1)			{ 
							retry=retry-1;
							call_http_multiple(urlval,divval,retry, callback);
						}else {
							document.getElementById(divval).innerHTML="<font color='white'>.</font>";
						}
					}
				}
		}
		objname.open('get',urlval,true);
		objname.send(null);
	}
}

function findMyDivPostion(){ 
	  var obj=document.getElementById("lnkHome"); 
	  var curleft = obj.offsetLeft; 
	  var curtop=obj.offsetTop; 

	  while(obj.offsetParent)   {
		   curleft=curleft + (obj.offsetParent.offsetLeft); 
		   curtop=curtop + (obj.offsetParent.offsetTop); 
		   obj=obj.offsetParent; 
	  } 
	return curleft;
} 

/*************************************************/
//CHANGE THE LINK HREF VALUE AS CURRENT PAGE CODE
/*************************************************/
var IE = document.all?true:false;
function checkie(){
if (!IE){  
   var curPage=window.location;
   //alert(document.getElementById("lnkLogo").innerHTML);
   document.getElementById("lnkLogo").innerHTML='<a title="Zapak!"  style="width:66px;height:59px;font-size:0px;line-height:0px;top:10px;left:10px;display:block;position:absolute;background:url('+TINY_IMG_PATH+'/zapak_logo_sm.gif);" href="'+ curPage +'"><strong>Zapak!</strong></a>';
}
}
/*************************************************/
//CHANGE THE LINK HREF VALUE AS CURRENT PAGE CODE
/*************************************************/

function adjustLink(){
	checkie();	
	document.getElementById("dvHomePage").style.visibility="visible";
	document.getElementById("dvHomePage").style.display="inline";
	var curleft=findMyDivPostion();
	document.getElementById("dvHomePage").style.left=curleft-120;
}
         
function homePageSet(obj){
	obj.style.behavior='url(#default#homepage)';
	//obj.setHomePage('http://www.zapak.com');
	url=window.location.href;
	obj.setHomePage(url);
}

function findMyDivPostion1() { 
  var obj=document.getElementById("lnkHome"); 
  var curleft = obj.offsetLeft; 
  var curtop=obj.offsetTop; 

  while(obj.offsetParent)   {
   curleft=curleft + (obj.offsetParent.offsetLeft); 
   curtop=curtop + (obj.offsetParent.offsetTop); 
   obj=obj.offsetParent; 
  } 
	//alert("your span was found at " + curleft +":" + curtop);
	return curleft;
	 
}


if (!IE) document.captureEvents(Event.MOUSECLICK)
document.onclick = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
	tempX = event.clientX + document.body.scrollLeft;
	tempY = event.clientY + document.body.scrollTop;
}
else {  // grab the x-y pos.s if browser is NS
     
	 tempX = e.pageX;
	 tempY = e.pageY;
	 lnkLeft=findMyDivPostion1();
	 //alert(tempX + ":" + lnkLeft);
	 //alert((lnkLeft+200));
	 if(tempX >= lnkLeft && tempX <=(lnkLeft+150))	 {
	  
	 }
	 else	 {
		if(document.getElementById("dvHomePage").style.visibility=="visible")		{
		 document.getElementById("dvHomePage").style.visibility="hidden"; 
		 document.getElementById("dvHomePage").style.display="none";
		}
		else	{
		 //alert("No");
		} 
	 } 
	}  
}

/*************************************************/
//DVHOME HIDE CODE ... WHEN CLICK ON CLOSE X
/*************************************************/
function hideme(){
    if(document.getElementById("dvHomePage").style.visibility=="visible")    {
        document.getElementById("dvHomePage").style.visibility="hidden"; 
		document.getElementById("dvHomePage").style.display="none";
    }
}
function updaterating(count,rate,article)
				{
					var inc = 1;
					while(rate)
					{
						document.getElementById('rating'+count+inc+article).src='/zapak/images/stars/filled_star.gif';
						rate--;
						inc++;
					}
				}
/*************************************************/
//DVHOME HIDE CODE ... WHEN CLICK ON CLOSE X
/*************************************************/                                                  
function MM_openBrWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}  
/***********New header implementation with More option ************/  
var more=0;
var show;
function more_opt(show,tab_id)
{//alert(tab_id);
if (more == 0)
{
document.getElementById(show).style.display='';       
  if(document.getElementById(show).innerHTML == '')
  {
  
// populate_httpdiv('/cgmoreoption.zpk?vtype=01090701','more_option',2);
		 more = 1;
		var objname='more_option';window[objname]=create_httpobject('more_option');
		window[objname].onreadystatechange=function()
		{
			if(window[objname].readyState==4 && window[objname].status==200)
			{
				document.getElementById('more_option').innerHTML=window[objname].responseText;
				document.getElementById('more_tab').innerHTML='<table width="100%" border="0" cellspacing="0" cellpadding="0" class="nav_bg12"><tr><td class="nav_bgsp1" align="left" background="/zapak/landing/images/tab/btn_bg.jpg" valign="top" width="7" ><span class="nav_bg1"><img src="/zapak/landing/images/tab/more_tabL.gif" height="27" width="7"/></span></td><td class="more_nav" align="center" background="/zapak/landing/images/tab/more_bg.jpg" width="50"><a style="cursor:pointer" onclick="more_opt(\'more_option\',\''+tab_id+'\')">Close <img src="/zapak/landing/images/tab/more_arrow_up.gif" style="margin-left: 3px;" height="10" width="9"/></a></td><td class="nav_bg1" align="left" valign="top" width="8"><img src="/zapak/landing/images/tab/more_tabR.gif" height="27" width="8"/></td></tr></table>';
				document.getElementById("genre_section").style.display="none";  
				document.getElementById(tab_id).className='nav_bg12'; 
				
			}
			else
			{
				document.getElementById('more_tab').innerHTML= '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="nav_bg12"><tr><td class="nav_bgsp1" align="left" background="/zapak/landing/images/tab/btn_bg.jpg" valign="top" width="7" ><span class="nav_bg1"><img src="/zapak/landing/images/tab/more_tabL.gif" height="27" width="7"/></span></td><td class="more_nav" align="center" background="/zapak/landing/images/tab/more_bg.jpg" width="50">Loading..</td><td class="nav_bg1" align="left" valign="top" width="8"><img src="/zapak/landing/images/tab/more_tabR.gif" height="27" width="8"/></td></tr></table>';
			}
		}
		window[objname].open('get','/cgmoreoption.zpk?vtype=01090701',true);
		window[objname].send(null);
		
  }
  else
  {
       
	more = 1;
	document.getElementById("more_tab").innerHTML='<table width="100%" border="0" cellspacing="0" cellpadding="0" class="nav_bg12"><tr><td class="nav_bgsp1" align="left" background="/zapak/landing/images/tab/btn_bg.jpg" valign="top" width="7" ><span class="nav_bg1"><img src="/zapak/landing/images/tab/more_tabL.gif" height="27" width="7"/></span></td><td class="more_nav" align="center" background="/zapak/landing/images/tab/more_bg.jpg" width="50"><a style="cursor:pointer" onclick="more_opt(\'more_option\',\''+tab_id+'\')">Close <img src="/zapak/landing/images/tab/more_arrow_up.gif" style="margin-left: 3px;" height="10" width="9"/></a></td><td class="nav_bg1" align="left" valign="top" width="8"><img src="/zapak/landing/images/tab/more_tabR.gif" height="27" width="8"/></td></tr></table>';
	document.getElementById("genre_section").style.display="none";  
	document.getElementById(tab_id).className='nav_bg12';     
 }
}
else
{

document.getElementById(show).style.display='none'; 
document.getElementById("genre_section").style.display=""; 
          more = 0;
document.getElementById("more_tab").innerHTML='<table width="100%" border="0" cellspacing="0" cellpadding="0" class="nav_bg12"><tr><td class="nav_bgsp1" align="left" background="/zapak/landing/images/tab/btn_bg.jpg" valign="top" width="7" ><span class="nav_bg1"><img src="/zapak/landing/images/tab/more_tabL.gif" height="26" width="7"/></span></td><td class="more_nav" align="center" background="/zapak/landing/images/tab/more_bg.jpg" width="50"><a style="cursor:pointer" onclick="more_opt(\'more_option\',\''+tab_id+'\')">More <img src="/zapak/landing/images/tab/more_arrow_down.gif" style="margin-left: 3px;" height="10" width="9"/></a></td><td class="nav_bg1" align="left" valign="top" width="8"><img src="/zapak/landing/images/tab/more_tabR.gif" height="26" width="8"/></td></tr></table>'; 
document.getElementById(tab_id).className=''; 
}

}