/* Global variables * [BEGIN] */

var pageContent = new Object();
var mainConfigs = new Object();
var chatScroll;
var refreshTimeout;
var datetimeTimeout;

var is_opera = /opera\/9/i.test(navigator.userAgent);
var is_gecko = /gecko/i.test(navigator.userAgent);
var is_ie    = /MSIE/.test(navigator.userAgent);


var Try = new Object();
Try.these = function() {
	var returnValue;
	for (var i = 0; i < arguments.length; i++) {
		var lambda = arguments[i];
		try {
			returnValue = lambda();
			break;
		} catch (e) {}
	}
	return returnValue;
}



/* Global variables * [END] */

/* Ajax initialisation * [BEGIN] */

/*@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 {
	var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
	try {
		var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
		var xmlhttp = false;
	}
}
@end @*/

if (!xmlhttp && typeof(XMLHttpRequest) != 'undefined') {
  var xmlhttp = new XMLHttpRequest();
}

/* Ajax initialisation * [END] */



/* Some functions * [BEGIN] */

function redirect (url) {
	document.location = url;
}

function sendRequest (method, path, sendString) {
	
    Try.these( function() {return xmlhttp.open(method, path, false)} );	
    Try.these( function() {return xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')} );	
    Try.these( function() {return xmlhttp.send(sendString)} );	
	return xmlhttp.readyState;
}

function getFormElement (formObj, elementName) {
	var collObjects = formObj.elements;
	for (i=0; i<collObjects.length; i++) {
      if (collObjects[i].name == elementName) {
         return collObjects[i];
      }
   }
   return false;
}

function toFirstLetterUpperCase (string) {
	var retString = string.substr(0, 1).toUpperCase() + string.substr(1);
	return retString;
}

function getXMLElementValue (parentXMLElement, elementName, elementOffset, attribute) {
	var xmlVal;
	if (arguments.length == 3) {
		try {
			 xmlVal = parentXMLElement.getElementsByTagName(elementName)[elementOffset].firstChild.data;
			 return xmlVal;
		}
		catch (error) {
			return null;
		}
	}
	else if (arguments.length == 4) {
		try {
			xmlVal = parentXMLElement.getElementsByTagName(elementName)[elementOffset].attributes.getNamedItem(attribute).value;
			return xmlVal;
		}
		catch (error) {
			return null;
		}
	}
	else return null;
}

function tryReplace (stringObject, search, replace) {
	try {
		while (stringObject.match(search)) {
			stringObject = stringObject.replace(search, replace);
		}
		return stringObject;
	}
	catch (error) {
		return null;
	}
}

function tryWithoutCatch (execString) {
	try {
		eval(execString);
	}
	catch (error) {
		return null;
	}
}

function truebody (){
	if(!window.opera && document.compatMode && document.compatMode!="BackCompat"){
		return document.documentElement;
	}
	else{
		return document.body;
	}
}

function setCookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}

function deleteCookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

function getCookie ( cookie_name )
{
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );

  if ( results )
    return ( unescape ( results[1] ) );
  else
    return null;
}
/* Some functions * [END] */

