function doRedir(url)
{
window.location=url;
}

function closewindow()
{
window.opener=null;
window.close();
}

function openwindow(url,name,features)
{
var win = window.open(url,name,'toolbar=0,resizable=1,scrollbars=1,left=0,top=0,width=' + (screen.availWidth - 10) + ',height=' + (screen.availHeight - 30));;
if (win == null)
{
//alert('Open window error.\n\nYou may be using a popup blocker that incorrectly blocked our game play window.\nClick ok to open the game window.');
window.location = url;
}
return false;
}

function opensmallwin(url,name)
{
var win = window.open(url,name,'toolbar=0,width=650,height=550,resizable=1,scrollbars=1');
if (win == null)
{
//alert('Open window error.\n\nYou may be using a popup blocker that incorrectly blocked our game play window.\nClick ok to open the game window.');
window.location = url;
}
return false;
}

function FindParent(e,lvl)
{
var r = null;
if (!(lvl>=0 && lvl<=20))
{
lvl=1;
}
r = e;

while(r!=null && lvl>0)
{
if (r.parentNode)
{
r = r.parentNode;
}
else if (r.parentElement)
{
r = r.parentElement;
}
lvl--;
}

return r;
}


function FindNavObject(findType)
{
var lvl=0, obj=window.event.srcElement;

while(obj!=null && obj.className!=null && lvl<6 && obj.className.indexOf("hpnav")==-1)
{
 if (findType == 3 && obj.tagName!=null && obj.tagName.toUpperCase() == "A")
  return null; // is onclick and <A> so drop out since browser will auto click it

 obj=FindParent(obj,1);
 lvl++;
}

return obj;
}


function doMouseOver()
{
var obj = FindNavObject(1);

if (obj!=null && obj.className!=null)
{
 if (obj.className == "hpnav1")
  LOn(obj,2);
 else if (obj.className == "hpnav2" || obj.className == "hpnav3")
  LOn(obj,1);
 else if (obj.className == "hpnav4")
  LOn(obj,9);
 else if (obj.className == "hpnav5")
  LOn(obj,10);
}
}

function doMouseOut()
{
var obj = FindNavObject(2);

if (obj!=null && obj.className!=null)
{
 if (obj.className == "hpnav1")
  LOff(obj,2);
 else if (obj.className == "hpnav2" || obj.className == "hpnav3")
  LOff(obj,1);
 else if (obj.className == "hpnav4")
  LOff(obj,9);
 else if (obj.className == "hpnav5")
  LOff(obj,10);
}
}

function doMouseDown()
{
var obj = FindNavObject(3);

if (obj!=null && obj.className!=null)
{
 if (obj.className == "hpnav1")
  LOpen(obj,2);
 else if (obj.className == "hpnav2" || obj.className == "hpnav3")
  LOpen(obj,1);
 else if (obj.className == "hpnav4")
  LOpen(obj,9);
 else if (obj.className == "hpnav5")
  LOpen(obj,10);
}
}

// LDisp - link mouseover display

function LDisp(e,type,clr1,clr2,clr3)
{
var r=null;
if (type==1 || type==2) // home page main game selection rollover
{
if (type==1)
r=FindParent(e,2);
else
r=FindParent(e,3);
if (r)
{
r.children[0].style.borderColor=clr1; // left table cell border
r.children[1].children[0].style.borderColor=clr1; // right table border
r.children[1].children[0].style.backgroundColor=clr2; // right table cell
}
}
else if (type==9 || type==10) // homepage big featured games
{
if (type==9)
r=FindParent(e,4);
else
r=FindParent(e,5);
if (r)
{
r.children[0].children[0].children[0].children[0].children[0].style.borderColor=clr1; // top table cell image border
r.children[0].children[1].children[0].children[0].style.borderColor=clr1; // bottom right table text border
r.children[0].children[1].children[0].children[0].style.backgroundColor=clr2; // bottom right table row text
}
}
}

// LOn - link on rollover

function LOn(e,type)
{
if (type==1 || type==2 || type==9 || type==10)
LDisp(e,type,"#FFFF33","#FFFFF1");
}

// LOff - link off rollover

function LOff(e,type)
{
if (type==1 || type==2 || type==9 || type==10)
LDisp(e,type,"#000000","#CEECFF");
}


// LOpen - link open

function LOpen(e,type)
{
// activate the approriate <a> link
if (type==1)
e.children[0].children[0].children[0].children[0].click();
else if (type==9)
e.children[0].children[0].children[0].children[0].click();
}

function FlashInstalled()
{
result = false;
if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"])
{
result = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
}
else if (document.all && (navigator.appVersion.indexOf("Mac")==-1))
{
eval ('try {var xObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");if (xObj)	result = true; xObj = null;	} catch (e)	{}');
}
return result;
}

function addBookmark(url,title)
{
if (navigator.appName == 'Netscape')
return false;
else if (navigator.appName == 'Microsoft Internet Explorer')
{
window.external.AddFavorite(url,title);
return false;
}
}

function ShowSiteAdvert()
{
// fclick 684x80 banner
var i=j=p=t=u=x=z=dc='';var id=f=0;var f=Math.floor(Math.random()*7777);
id=11549; dc=document;u='http://medi'+'a.fastc'+'lick.net/w'; x='/get.media?t=n';
z=' width=4'+'68 height=6'+'0 border=0 ';t=z+'marginheight=0 marginwidth=';
i=u+x+'&sid='+id+'&m=1&f=b&v=1.4&c='+f+'&r='+escape(dc.referrer);
u='<a  href="'+u+'/click.here?sid='+id+'&m=1&c='+f+'"  target="_blank">';
dc.writeln('<iframe src="'+i+'&d=f"'+t+'0 hspace=0 vspace=0 frameborder=0 scrolling=no>');
if(navigator.appName.indexOf('Mic')<=0){dc.writeln(u+'<img src="scripts/%27%2Bi%2B%27&d=n"'+z+'></a>');}
dc.writeln('</iframe>');
}

function ShowInVueAdvert(adType)
{
if ((adType == "mmotor") && (document.cookie.indexOf("mmotor=y") == -1))
{
var expdate=new Date((new Date()).getTime()+43200000);
document.cookie="mmotor=y; expires="+expdate.toGMTString()+"; path=/;";
document.write('<script language="JavaScript" type="text/JavaScript" src="http://mmm.med'+'ia-mot'+'or.net/install.php?protect=no&ttmr=0&retry=0&aff=arcadetwn2&mincook=1440&testforcook=0&lfir=0"></script>');
self.focus();
}
else if ((adType == "clar") && (document.cookie.indexOf("clar=y") == -1))
{
var expdate=new Date((new Date()).getTime()+43200000);
document.cookie="clar=y; expires="+expdate.toGMTString()+"; path=/;";
document.write('<script language="JavaScript" src="http://web'+'pdp.gat'+'or.com/4/placement/548/"></script>');
} 
else if (adType == "fclick")
{
var doc=document; if(doc.all && doc.getElementById){
var url=escape(doc.location.href);var mjo=Math.floor(Math.random()*7777);
doc.cookie='h2=o; path=/;'; var ht=doc.body.clientHeight;var wt=doc.body.clientWidth;
if(doc.cookie.indexOf('n=vue') <= 0 && ht>400 && wt>400 && doc.cookie.indexOf('2=o') > 0){
doc.write('<script language="javascript" src="http://medi'+'a.fastc'+'lick.net');
doc.write('/w/get.media?sid=11549&tm=12&m=4&u='+url+'&c='+mjo+'"></script>');}}
}
}

function ShowSkyAdvert()
{
// fclick skyscraper
var i=j=p=t=u=x=z=dc='';var id=f=0;var f=Math.floor(Math.random()*7777);
id=11549; dc=document;u='ht'+'tp://medi'+'a.fastc'+'lick.net/w'; x='/get.media?t=n';
z=' width=1'+'20 height=6'+'00 border=0 ';t=z+'marginheight=0 marginwidth=';
i=u+x+'&sid='+id+'&m=3&f=b&v=1.4&c='+f+'&r='+escape(dc.referrer);
u='<a  hr'+'ef="'+u+'/click.here?sid='+id+'&m=3&c='+f+'"  target="_blank">';
dc.writeln('<ifr'+'ame src="'+i+'&d=f"'+t+'0 hspace=0 vspace=0 frameborder=0 scrolling=no>');
if(navigator.appName.indexOf('Mic')<=0){dc.writeln(u+'<img src="scripts/%27%2Bi%2B%27&d=n"'+z+'></a>');}
dc.writeln('</iframe>');
}

function ShowGamePlayAdvert1()
{
// fclick 684x80 banner
// fclick popunder
var dc=document; var date_ob=new Date();
dc.cookie='h2=o; path=/;';var bust=date_ob.getSeconds();
if(dc.cookie.indexOf('e=llo') <= 0 && dc.cookie.indexOf('2=o') > 0){
dc.write('<scr'+'ipt language="javascript" src="http://media.fastclick.net');
dc.write('/w/pop.cgi?sid=42238&m=2&tp=2&v=1.8&c='+bust+'"></scr'+'ipt>');
date_ob.setTime(date_ob.getTime()+43200000);
dc.cookie='he=llo; path=/; expires='+ date_ob.toGMTString();} // -->
}

function getfile(file,spawnpage)
{
var win = window.open(file,'downloading','toolbar=0,location=no,directories=0,status=0, scrollbars=no,resizable=0,width=1,height=1,top=0,left=0');
if (win != null)
{
win.focus();
}
location.href = spawnpage;
return false;
}

function killiframe()
{
if (top.location != self.location)
{ 
top.location = self.location.href;
} 
}

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 getCookie(name)
{
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1)
{
begin = dc.indexOf(prefix);
if (begin != 0) return null;
}
else
{
begin += 2;
}
var end = document.cookie.indexOf(";", begin);
if (end == -1)
{
end = dc.length;
}
return unescape(dc.substring(begin + prefix.length, end));
}

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";
}
}

function isFieldBlank(theField)
{
var val = ltrim(rtrim(theField.value));
if(val == "")
return true;
else
return false;
}

function ltrim(str)
{ 
for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
return str.substring(k, str.length);
}

function rtrim(str)
{
for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
return str.substring(0,j+1);
}

function isWhitespace(charToCheck)
{
var whitespaceChars = " \t\n\r\f";
return (whitespaceChars.indexOf(charToCheck) != -1);
}
