function isBrowserVersion(version) {
	var agt = navigator.userAgent.toLowerCase();
	if(agt.indexOf(version.toLowerCase()) != -1)
		return true;
	else
		return false;
}

function get (STR, parent) {
	if(parent && !eval(parent)) return 'undefined'; 
	var tmpParam    = (parent ? unescape(eval(parent+".location")) : unescape(document.location.href));
	var indParam    = tmpParam.indexOf( "?" );
	var arrParams   = new Array();

	if ( indParam != -1 ) {
		var pairs = tmpParam.substring( indParam + 1, tmpParam.length ).split( "&" );
		for ( var i = 0; i < pairs.length; i++ ) {
			valParam = pairs[ i ].split( "=" );
			arrParams[ valParam[ 0 ]] = valParam[ 1 ];
		}
	}
	return arrParams[STR];
}
	
function loadXML (xml, callback) { 
	// IE
	if (window.ActiveXObject) {
		var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
		xmldoc.async = false;
		xmldoc.async = "false"; 
		if(!xmldoc.loadXML(xml)) xmldoc.load(xml);
		if(!callback) return xmldoc;
		else { xmldoc.onreadystatechange = callback};
	}

	// Mozilla
	else if (document.implementation && document.implementation.createDocument) {
		var xmldoc = document.implementation.createDocument("","",null);
		xmldoc.load(xml);
		if(!callback) return xmldoc;
		else xmldoc.onload = callback;
	}
	else
		return false;
}


function clearString(evt) {
	var e = evt?evt : event; 
	if(!e) 
		return; 
	var key = 0; 
	if (typeof(e.which)!= 'undefined') 
		key = e.which; 
	else
		key = event.keyCode;
		
	if ((key > 31 && key < 45) || 
	   (key == 47) ||
	   (e.shiftKey) ||
	   (e.shiftKey && (key > 47 && key < 58)) ||
	   (key > 57 && key < 65) || 
	   (key > 90 && key < 95) || 
	   (key > 95 && key < 97) ||
	   (key > 105 && key < 112) ||
	   (key == 194) ||
	   (key > 127 && key <= 255))
	{
		if (window.event) //IE
			e.returnValue = null;     
		else //Firefox
			e.preventDefault();
	}
}

function insertHTML(element, type, html) {
	if(typeof element.insertAdjacentHTML != 'undefined') // IE
		element.insertAdjacentHTML(type, html);
	else { // FF
		var r = document.createRange();
		r.setStartBefore(element);
		var parsedNode = r.createContextualFragment(html);
		var parent = element.parentNode;
		
		switch(type) {
			case 'beforeEnd':
				element.appendChild(parsedNode);
			break;			
			case 'afterEnd':
				if (element.nextSibling)
					parent.insertBefore(parsedNode, element.nextSibling);
				else
					parent.appendChild(parsedNode);
			break;
		}
	}
}

function makeButton (name, param, title) {
	var path = 'images/buttons/';
	var image = new Array();
	image[0] = 'images/buttons/'+name+'.gif';
	image[1] = 'images/buttons/'+name+'_hl.gif';
	
	preloader(image);
	
	return '<img src="'+path+name+'.gif" '+(param ? param : '')+' '+(title && title.trim().length > 0 ? 'title="'+title+'"' : '')+' onmouseover="this.src=\''+path+name+'_hl.gif\'" onmouseout="this.src=\''+path+name+'.gif\'" style="cursor:pointer" />';
}

function preloader(input) {
	var imageObj = new Image();
	var images   = new Array();
	if(typeof input == 'string')
		images[0] = input;
	else
		images = input;

	for(var i=0; i<images.length; i++)
		imageObj.src = images[i];     
} 

function disableSelection (target, bool) {
	if (typeof target.onselectstart != "undefined") //IE route
		target.onselectstart = (bool ? function () { return false } : function () { return true });
	else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
		target.style.MozUserSelect = (bool ? "none" : "");
	else //All other route (ie: Opera)
		target.onmousedown = (bool ? function () { return false } : function () { return true });
}

function include (src) {
	if(src.indexOf('.js') != -1) {
		var script = document.createElement('SCRIPT');
		script.setAttribute("language", "javascript");
		script.setAttribute("type", "text/javascript");
		script.setAttribute("src", src);
		document.getElementsByTagName('HEAD')[0].appendChild(script);
		script = null;
	} else if(src.indexOf('.css') != -1) {
		var link = document.createElement('link');
		link.setAttribute("type", "text/css");
		link.setAttribute("rel", "stylesheet");
		link.setAttribute("href", src);
		document.getElementsByTagName('HEAD')[0].appendChild(link);
		link = null;
	}
}

function fixIECombos (pObj, pBool) {
	var selects = pObj.getElementsByTagName("select");
	
	for(var i=0; i<selects.length; i++) {
		selects[i].style.display = (!pBool ? "none" : "");
	}
	
	selects = null;
}

function fixIEObjects (pObj, pBool) {
	var objects = pObj.getElementsByTagName("object");
	
	for(var i=0; i<objects.length; i++) {
		objects[i].style.display = (!pBool ? "none" : "");
	}
	
	objects = null;
}



String.prototype.trim = function() { return this.replace(/^\s+/, '').replace(/\s+$/, ''); };
String.prototype.nl2br = function() { return this.replace(/\r\n/g, "<br />");};
String.prototype.htmlentities = function () {

function replacechar(match) {
		if (match == "<") return "&lt;"
		else if (match == ">") return "&gt;"
		else if (match == "\"") return "&quot;"
		else if (match == "&") return "&amp;"
	}
	
	var re = /[<>"&]/g;
	var str = this.replace(re, function(m){return replacechar(m)})

	return str;
}

function getWindowCenterY (size) {
	var windowHeight = ((window.innerHeight ? window.innerHeight : (document.documentElement.offsetHeight ? document.documentElement.offsetHeight-4 : 0)) / 2)  - (size/2);
	return Math.floor(windowHeight +  document.documentElement.scrollTop);
}

function getWindowCenterX (size) {
	var windowWidth = (((window.innerWidth) ? window.innerWidth : (document.documentElement.offsetWidth ? document.documentElement.offsetWidth : 0)) / 2)  - (size/2);
	return Math.floor(windowWidth - document.documentElement.scrollLeft);
}

function getAbsoluteY (pDom) {
	if(!pDom) return;
	var dom = pDom;
	var X   = dom.offsetTop;
	dom     = dom.offsetParent;
	while(dom!=null) {
		X  += dom.offsetTop
		X  -= dom.scrollTop;
		dom = dom.offsetParent;
	}
	
	return X;
}

function getAbsoluteX (pDom) {
	if(!pDom) return;
	var dom = pDom;
	var Y   = dom.offsetLeft;
	dom     = dom.offsetParent;
	while(dom!=null) {
		Y  += dom.offsetLeft;
		Y  -= dom.scrollLeft;
		dom = dom.offsetParent;
	}
	
	return Y;
}

