var fadein = -1; // global constants
var fadeout = 9;

function FadeElement(id, iteration) {

  var obj = document.getElementById(id);
  var opacity = Math.abs(iteration) * 0.1;

    if(opacity != 0 && opacity != 1){
     setTimeout("FadeElement('"+id+"',"+(iteration - 1)+");",70);
    }else if(opacity == 0){ // If fade out finished, reset opacity and then hide by style.
     opacity = 1;
     obj.style.display = "none";
    }

  obj.style.opacity = opacity; obj.style.KhtmlOpacity = opacity; obj.style.MozOpacity = opacity; obj.style.filter = "alpha(opacity=" + Math.floor(opacity*100) + ")";
}

function collapseBox(id, chars, doStripHTML)
{
 this.id = id;
 this.contentALL = document.getElementById(id).innerHTML;
 this.contentLESS = ((doStripHTML)?this.contentALL.replace(/<\/?[^>]+(>|$)/g,""):this.contentALL).substring(0, chars);
 this.contentALL += " &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style='float:right;'>(<a href=\"javascript:"+id+".Less();\">Collapse</a>) &nbsp; </span>";
 this.contentLESS += " ... (<a href=\"javascript:"+id+".All();\">Read More</a>)";
 this.Less = function()
 {
  document.getElementById(this.id).innerHTML = this.contentLESS;
 }
 this.All = function()
 {
  document.getElementById(this.id).innerHTML = this.contentALL;
  FadeElement(this.id, fadein);
 }
 this.Less();
}

function ajaxCall(url, method, asynch, data, funct)
{
  var xmlhttp, sender;

  try{
	xmlhttp = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
  }catch(err){ return true; }

  if(xmlhttp)
  {
	switch(method)
	{
	  case 'GET': sender = (url.indexOf('?') > 0) ? url+'&'+data : url+'?'+data; break;
	  case 'POST': sender = url;
	}

	xmlhttp.open(method, sender, asynch);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.send(data);

	if(funct)
	{
	  xmlhttp.onreadystatechange = function()
	  {
	    if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
	    {

		  funct(xmlhttp.responseText);
	    }
	  }
	}
  }
}

function urlencode(str)
{
 return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}

