/* Javascript toolkit by Poly9 */

function Utils() {};

Utils.GetXmlHttp = function() {
  	var xmlhttp=false;
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		// JScript gives us Conditional compilation, we can cope with old IE versions.
		// and security blocked creation of the objects.
		 try {
		  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e) {
		  try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		  } catch (E) {
		   xmlhttp = false;
		  }
		 }
		@end @*/
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		  xmlhttp = new XMLHttpRequest();
		}
	return xmlhttp;
} 

Utils.GetWindowWidthHeight = function()
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

  return {'width' : myWidth, 'height' : myHeight};
}

Utils.Dump = function()
{
	var str = '';
	for(var v in arguments[0])
		str += v + ' = ' + arguments[0][v] + '\n';
	return str;
}
Utils.debugMode = false;
Utils.Debug = function()
{
	if (!Utils.debugMode) return;
	if (!Utils.debugDiv) {
		var debugDiv = document.createElement('div');
		debugDiv.style.position = 'absolute';
		debugDiv.style.top = '0px';
		debugDiv.style.right = '0px';
		debugDiv.style.width = '400px';
		debugDiv.style.height = '200px';
		debugDiv.style.zIndex = 100000;
		debugDiv.style.background = 'white';
		debugDiv.style.border = '1px solid black';
		var imgClose = document.createElement('div');
		imgClose.style.position = 'absolute';
		imgClose.style.top = '0px';
		imgClose.style.right = '0px';
		imgClose.innerHTML = '<b><a href="javascript:;" onclick="Utils.debugDiv.style.display = \'none\'">X</a></b>';
		debugDiv.appendChild(imgClose);
		Utils.debugDiv = debugDiv;
		document.body.appendChild(Utils.debugDiv);		
	}
	if (typeof a == 'object')
		Utils.debugDiv.innerHTML += Utils.Dump(arguments[0]).replace(/\n/g,'<br/>') + '<br/>';
	else
		Utils.debugDiv.innerHTML += arguments[0] + '<br/>';	
}

Array.prototype.contains = function (element) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == element) {
            return true;
        }
    }
    return false;
};

String.prototype.trim = function()
{
	return this.replace(/^\s*(.*?)\s*$/, "$1");
}