// Shorthand
var d=document;

// Reserve space for scrollbar (CSS 3)
d.write('<style type="text/css"> html { overflow-y: scroll; } </style>');

// Protect against missing JS method.
String.prototype.trim=function() { return this.replace(/^\s*/, "").replace(/\s*$/, ""); }

// Protect against missing JS method. Note: NOT prefixed with object
function getElementsByClassName(s)
{
 if(d.getElementsByClassName) return d.getElementsByClassName(s);
 else
 {
  var c=[], e=d.getElementsByTagName('*'), r=new RegExp("(^|\\s)"+s+"(\\s|$)");
  for (var i=0,j=e.length;i<j;i++) r.test(e[i].className)?c.push(e[i]):'';
  return c;
 }
}

// JS cookie functions
function setCookie(c_name,value,exdays)
{
 var exdate=new Date();
 exdate.setDate(exdate.getDate() + exdays);
 var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
 d.cookie=c_name + "=" + c_value;
}
function getCookie(c_name)
{
 var i,x,y,ARRcookies=document.cookie.split(";");
 for(i=0;i<ARRcookies.length;i++)
 {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if(x==c_name) return unescape(y);
 }
}

// Must be invoked after page has loaded, otherwise body is null
function testFont(f)
{
 var names=f.split(',');
 if(names[0] && getCookie('testFont')!=1)
 {
  var body=d.body;
  for (var i=0, len=names.length; i<len; ++i)
  {
   var name=names[i].replace(/['"<>]/g,'').trim(); // trim() method required
   var test=d.createElement('div');
   var installed=false;
   var template='<b style="display:inline !important; width:auto !important; font:normal 10px/1 \'X\',sans-serif !important">ii</b><b style="display:inline !important; width:auto !important; font:normal 10px/1 \'X\',monospace !important">ii</b>';
   var ab;
   test.innerHTML=template.replace(/X/g,name);
   test.style.cssText='position:absolute;visibility:hidden;display:block !important';
   body.insertBefore(test,body.firstChild);
   ab=test.getElementsByTagName('b');
   installed=ab[0].offsetWidth===ab[1].offsetWidth;
   if(!installed) alert('This page will look better if you have the '+name+' font installed');
   body.removeChild(test);
  }
 }
 setCookie('testFont',1,7)
}

//Anti-spam e-mail script...
function email(name,domain,subj)
{
 var addr=name+"@"+domain;
 var addrt=(subj)?addr+'?subject='+subj:addr
 d.write('<a href="mailto:'+addrt+'">'+addr+'</a>');
}

function replaceImages()
{
 var country='';
 var els = getElementsByClassName('f');
 for (var i=0, len=els.length; i<len; ++i)
 {
  switch(els[i].innerHTML)
  {
   case 'AQ':
    country='Antarctica';
    break;    
   case 'AT':
    country='Austria';
    break;    
   case 'AU':
    country='Australia';
    break;    
   case 'BH':
    country='Bahrain';
    break;    
   case 'CA':
    country='Canada';
    break;    
   case 'CN':
    country='China';
    break;    
   case 'DE':
    country='Germany';
    break;    
   case 'ES':
    country='Spain';
    break;    
   case 'FR':
    country='France';
    break;    
   case 'GB':
    country='UK';
    break;    
   case 'HK':
    country='Hong Kong';
    break;    
   case 'IE':
    country='Ireland';
    break;    
   case 'IN':
    country='India';
    break;    
   case 'JP':
    country='Japan';
    break;    
   case 'KR':
    country='Korea';
    break;    
   case 'MX':
    country='Mexico';
    break;    
   case 'NO':
    country='Norway';
    break;    
   case 'SE':
    country='Sweden';
    break;    
   case 'US':
    country='USA';
    break;    
   default:
    country='?';
  }
  els[i].innerHTML='<img src="/phpimg.php?img='+els[i].innerHTML+'.gif&x=f" title="'+country+'" alt="" />';
 }
}

// AJAX functions

function createRequestObject()
{
 var ro;
 var browser=navigator.appName;
 if(browser=="Microsoft Internet Explorer") ro=new ActiveXObject("Microsoft.XMLHTTP");
 else ro=new XMLHttpRequest();
 return ro;
}

function ajaxRecursive(Method, URL, ID, data)
{
 if (typeof ReqRecursiveTimer != 'undefined') clearTimeout(ReqRecursiveTimer);
 var httpObject=createRequestObject();
 if(httpObject!=null)
 {
  Method=Method.toUpperCase();
  var params='x='+data;
  var auri=URL; // preserve the original URL for ReqRecursiveTimer
  if(Method!="POST") auri+='?'+params+'&ms='+new Date().getTime();
  httpObject.open(Method, auri, true);
  if(Method=="POST")
  {
   httpObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   httpObject.setRequestHeader("Content-length", params.length);
   httpObject.setRequestHeader("Connection", "close");
  }
  httpObject.onreadystatechange=function()
  {
   if(httpObject.readyState==4)
   {
    if(d.getElementById(ID).style.backgroundImage)
    {
     var bi=d.getElementById(ID).style.backgroundImage;
     var url=bi.replace(/url\((.*)\)/,"$1");
     var url=url.replace(/"/g,'');
     var img='<img id="fadeimage" src="'+url+'" alt="" />';
     d.getElementById(ID).innerHTML=img;
     if(d.getElementById('imgx'))
     {
      d.getElementById(ID).style.backgroundImage='url(\''+d.getElementById('imgx').src+'\')';
      if(d.getElementById('fadeimage')) sfade('fadeimage');
     } else
     {
      var imgx=d.createElement('img');
      imgx.id='imgx';
      imgx.style.display='none';
      d.getElementById(ID).parentNode.insertBefore(imgx,d.getElementById(ID));
     }
     d.getElementById('imgx').src=httpObject.responseText;
    }
   }
  }
  if(Method=="POST") httpObject.send(params);
  else httpObject.send(null);
 }
 var ReqRecursiveTimer=setTimeout('ajaxRecursive("'+Method+'","'+URL+'","'+ID+'","'+data+'")',8000);
}

function sfade(id,opacity)
{
 if(typeof opacity=='undefined') opacity=96;
 var o=d.getElementById(id);
 if(opacity>=5)
 {
  o.style.filter="alpha(style=0,opacity:"+opacity+")"; // IE
  o.style.KHTMLOpacity=opacity/100; // Konqueror
  o.style.MozOpacity=opacity/100; // Mozilla (old)
  o.style.opacity=opacity/100; // Mozilla (new)
  opacity-=4;
  window.setTimeout("sfade('"+id+"',"+opacity+")",50);
 } else
 {
  o.style.display='none';
 }
}

function showpicture(pic)
{
 var div=d.getElementById('picture');
 div.innerHTML='<img src="'+pic+'" style="cursor:pointer" onclick=hidepicture(); alt="" title="click to remove"/>';
 var a=Math.max(document.documentElement.scrollTop, document.body.scrollTop)+0.45*(document.documentElement.clientHeight-450);
 div.style.top=a+'px';
 div.style.display='block';
}

function hidepicture()
{
 d.getElementById('picture').style.display='none';
}

