var MAX_INT = 2147483648;//2,147,483,648
var MAX_MONEY = 922337203685476;//922,337,203,685,477.5807

//-----------------------------------------------------------------------------------------------------------------
function preloadImage(url)
{
    var img=new Image();
    img.src=url;
}

//-----------------------------------------------------------------------------------------------------------------
// Will call LoadFunction once the entire page is loaded
// - LoadFunction - string - function to be called when the page is loaded
//-----------------------------------------------------------------------------------------------------------------
function CrossBrowser_AttachLoadEvent(LoadFunction)
{
	try
	{
		if (window.addEventListener)
			eval("window.addEventListener('load', " + LoadFunction + ", false)");
		else
			eval("window.attachEvent('onload', " + LoadFunction + ")");
	}
	catch(e)
	{ ; }	
}

//-----------------------------------------------------------------------------------------------------------------
function toBit(p_value)
{
    var ReturnValue=0;

    try{
        switch(p_value)
        {
            case true:
            case "true":
            case "1":
                ReturnValue=1;
                break;
        }
    }catch(e){;}
    
    return ReturnValue;
}

//-----------------------------------------------------------------------------------------------------------------
function isblank(s) {
	for(var i=0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}

//-----------------------------------------------------------------------------------------------------------------
function cookie_create(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

//-----------------------------------------------------------------------------------------------------------------
function cookie_read(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

//-----------------------------------------------------------------------------------------------------------------
function cookie_erase(name) {
	cookie_create(name,"",-1);
}


//-----------------------------------------------------------------------------------------------------------------
function CrossBrowser_GetXML(URL, PostXML) 
{
	var xmlhttp=CrossBrowser_GetXMLHTTPRequest(URL, PostXML);
	if(xmlhttp)
		return xmlhttp.responseXML;
	else
		return null;
}


//-----------------------------------------------------------------------------------------------------------------
function CrossBrowser_GetXMLHTTPRequest(URL, PostXML) 
{
	try
	{
		var XMLRequest = false;
		var PostGet="Get";
		if(PostXML!=null)
			PostGet="POST";
		// branch for native XMLHttpRequest object
		if (window.XMLHttpRequest)
		{
			XMLRequest = new XMLHttpRequest();
			//XMLRequest.onreadystatechange = CrossBrowser_XMLRequestReady;
			XMLRequest.open(PostGet, URL, false);
            XMLRequest.setRequestHeader("If-None-Match",Date());
            XMLRequest.setRequestHeader("Cache-Control","no-cache,max-age=0");
            XMLRequest.setRequestHeader("Pragma","no-cache");
			XMLRequest.send(PostXML);  
		}
		// branch for IE/Windows ActiveX version
		else if (window.ActiveXObject)
		{
			XMLRequest = new ActiveXObject("Msxml2.XMLHTTP.3.0");
			if (XMLRequest) {
				//XMLRequest.onreadystatechange = CrossBrowser_XMLRequestReady;
				XMLRequest.open(PostGet, URL, false);
                XMLRequest.setRequestHeader("If-None-Match",Date());
                XMLRequest.setRequestHeader("Cache-Control","no-cache,max-age=0");
                XMLRequest.setRequestHeader("Pragma","no-cache");
				XMLRequest.send(PostXML);
			}
		}
		return XMLRequest;
	}
	catch(e)
	{return null; }	
}


//-----------------------------------------------------------------------------------------------------------------
String.prototype.trim = function() {return this.replace(/^\s+|\s+$/g,"");}
//-----------------------------------------------------------------------------------------------------------------
String.prototype.ltrim = function() {return this.replace(/^\s+/,"");}
//-----------------------------------------------------------------------------------------------------------------
String.prototype.rtrim = function() {return this.replace(/\s+$/,"");}

if( document.implementation.hasFeature("XPath", "3.0") )
{
	XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
	{
		if( !xNode ) { xNode = this; } 

		var oNSResolver = this.createNSResolver(this.documentElement)
		var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
		var aResult = [];
		for( var i = 0; i < aItems.snapshotLength; i++)
		{
			aResult[i] =  aItems.snapshotItem(i);
		}
		
		return aResult;
	}
	XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
	{
		if( !xNode ) { xNode = this; } 

		var xItems = this.selectNodes(cXPathString, xNode);
		if( xItems.length > 0 )
		{
			return xItems[0];
		}
		else
		{
			return null;
		}
	}

	Element.prototype.selectNodes = function(cXPathString)
	{
		if(this.ownerDocument.selectNodes)
		{
			return this.ownerDocument.selectNodes(cXPathString, this);
		}
	}

	Element.prototype.selectSingleNode = function(cXPathString)
	{	
		if(this.ownerDocument.selectSingleNode)
		{
			return this.ownerDocument.selectSingleNode(cXPathString, this);
		}
	}

}