    if (!Array.indexOf) {
        Array.prototype.indexOf = function(arrayElement) {
            for (var i = 0; i < this.length; i++) {
                if (this[i] == arrayElement) {
                    return i;
                }
            }
            return -1;
        }
    }

    if (!Array.moveElement) {
        Array.prototype.moveElement = function(oldIndex, newIndex) {
            var mvElem = this[oldIndex];
            this.splice(oldIndex, 1);
            var tempArr = [];
            var j = 0;
            for (var i = 0; i < this.length + 1; i++) {
                if (i == newIndex) {
                    tempArr[i] = mvElem;
                    j = 1;
                }
                else {
                    tempArr[i] = this[i - j];
                }
            }
            for (var i = 0; i < tempArr.length; i++) {
                this[i] = tempArr[i];
            }
        }
    }


    if (!Array.insertElement) {
        Array.prototype.insertElement = function(element, index) {
            var tempArr = [];
            var j = 0;
            for (var i = 0; i < this.length + 1; i++) {
                if (i == index) {
                    tempArr[i] = element;
                    j = 1;
                }
                else {
                    tempArr[i] = this[i - j];
                }
            }
            for (var i = 0; i < tempArr.length; i++) {
                this[i] = tempArr[i];
            }
        }
    }


function evalJsonText(text) {
	return eval('(' + text + ')');
}

function getElement(id) {
	if(typeof(id) == 'string')
		return document.getElementById(id);
	else
		return id;
}
var $ge = getElement;
var $ = getElement;

// takes a date object and returns a date formatted like Wednesday, June 21, 2006
function getFormattedDate(date) {	
	var s = days[date.getDay()] + ", " + months[date.getMonth()] + " " + date.getDate() + ", " + date.getFullYear(); 
	return s;
}

function toggleCheck(id, checked) {
	var a = $ge(id);
	if(a != null) a.checked = checked;
}

function toggleCbs(cb,table) {
	var tb = $ge(table);		
	if(tb != null) {
		var cbs = tb.getElementsByTagName("input");
		for(i=0;i<cbs.length;i++) {
			if(cbs[i]!=cb && cbs[i].type=="checkbox" && isVisible(cbs[i])) {
				cbs[i].checked = cb.checked;
			}
		}			
	}
}

function toggleEnabled(id, enabled) {
	var a = $ge(id);
	if (a != null) { a.disabled = !enabled; if (a.wm && a.wm.toggleDisabled) a.wm.toggleDisabled(!enabled); }
}

function toggleVisible(id, visible) {
	var a = $ge(id);
	if(a != null) { if(visible) a.style.display = ""; else a.style.display = "none"; }
}

function toggleVisibility(id, visible) {
	var a = $ge(id);
	if(a != null) 
	{ 
		if(visible==null) toggleVisible(a,(a.style.display != ""));		
		else if(visible) a.style.visibility = "visible"; 
		else a.style.visibility = "hidden"; 
	}
}

// takes a control ID and assigns the value property with the provided value
function assignValue(id, value) {	
	var a = $ge(id);
	if(a != null) a.value = value;
}

// takes a control ID and appends a text node with the provided value
function assignText(id, text) {
	var a = $ge(id);

	if(a != null) {		
		for(var i = a.childNodes.length - 1; i >= 0; i--) 
			a.removeChild(a.childNodes[i]);
		
		a.appendChild(document.createTextNode(text));
	}
}

function assignHtml(id, html) { 
	var a = $ge(id);
	if(a!=null && a.innerHTML) {
		a.innerHTML = html;
	}
}

function getValue(id) {
	var a = $ge(id);
	if(a != null) {
		var tag = a.tagName.toLowerCase();
		if(tag == "select") {
			for(var j=0; j<a.options.length; j++)
				if(a.options[j].selected)
					return a.options[j].value;
		}
		else if(tag == "input") {
			var type = a.type.toLowerCase();
			
			if(type == "checkbox") { if(a.checked) return "on";  }
			else if(type == "text" || type == "hidden" || type == "password") { return a.value; }
		}
		return "";
	}
	else
		return "";
}
$gv = getValue;

function getText(id) {
	var a = $ge(id);
	
	if(a != null) return a.innerHTML;
	else return null;
}

function getXmlNodeText(el) {
	
	var text= "";
	if (el != null)	{
		if(el.childNodes) {
			for (var i = 0; i<el.childNodes.length; i++) {
				var childNode = el.childNodes[i];
				if(childNode.nodeValue != null) {
					text = text + childNode.nodeValue;
				}
			}
		}
	}
	return text;
}




function getChecked(id) {
	var a = $ge(id);
	if(a != null) return a.checked;
	else return false;
}

function appendChildCell(tr) {	
	var td = document.createElement("TD");
	tr.appendChild(td);
	return td;
}

function isVisible(id) {
	var a = $ge(id); 
	if(a!=null && a.style.display!="none" && a.style.visibility!="hidden") return true;
	else return false;
}

function isLess(a,b) { return (a<b); }
function isLessEq(a,b) { return (a<=b); }
function isGreat(a,b) { return (a>b); }
function isGreatEq(a,b) { return (a>=b); }
function and() { var isTrue = true; for(i=0;i<and.arguments.length;i++) isTrue = isTrue && and.arguments[i]; return isTrue; }
function getDatePart(d) { return new Date((d.getMonth()+1) + "/" + d.getDate() + "/" + d.getFullYear()); }
function getAspDateString(d) { return (d.getMonth()+1) + "/" + d.getDate() + "/" + d.getFullYear(); }
function addDays(d,n) { var x = new Date(d.toString()); x.setDate(x.getDate()+n); return x; }
function subDays(d,n) { var x = new Date(d.toString()); x.setDate(x.getDate()-n); return x; }
function dayDiff(a,b) { return Math.floor((a-b)/86400000); }
function appendToQuery(query,name,value) { if(query!="") {query+="&";} query+=name+"="+value; return query; }

function createXmlRequest() {
	var req = null;
	
    if(window.XMLHttpRequest) 
    {
    	try { req = new XMLHttpRequest(); } 
    	catch(e) { req = null; }    
    } 
    else if(window.ActiveXObject) 
    {
       	try { req = new ActiveXObject("Msxml2.XMLHTTP"); } 
       	catch(e) 
       	{ 
       		try { req = new ActiveXObject("Microsoft.XMLHTTP"); } 
       		catch(e) { req = null; }
		}
    }
	
	return req;
}

function transformXml(xslPath, xmlFile, elementIdToAppendTo) {
	var element = document.getElementById(elementIdToAppendTo);
	var xslTransform = null;
	var trans = null;
	var req = null;
		
	if(window.XSLTProcessor) {	
		// get the XSL
		xslTransform = new XSLTProcessor();
		req = createXmlRequest();
		req.open("GET", xslPath, false);
		req.send(null);
		xslTransform.importStylesheet(req.responseXML);
			
		var doc = document.implementation.createDocument("", "", null);		
		var clone = doc.importNode(element, true);
		
		doc.appendChild(clone);
		var fragement = xslTransform.transformToFragment(xmlFile, document);
		element.innerHTML = "";
		element.appendChild(fragement);	
	}
	else if(window.ActiveXObject) {		
		xslTransform = new ActiveXObject("Microsoft.XMLDOM");
		xslTransform.async = false;
		xslTransform.load(xslPath);		
		var output = xmlFile.transformNode(xslTransform);					
		element.innerHTML = output;
	}
	else {	
		element.innerHTML = xmlRequest.responseText;		
	}
}

function createXmlDoc(xmlText) {
	var xml = null;	
	if(document.implementation && document.implementation.createDocument) { 
		if(xmlText != null && window.DOMParser) xml = (new DOMParser()).parseFromString(xmlText,"text/xml");
		else xml = document.implementation.createDocument("", "", null); 
	}
	else if(window.ActiveXObject) { 
		xml = new ActiveXObject("Microsoft.XMLDOM"); 
		if(xmlText != null) xml.loadXML(xmlText);
	}
	return xml;
}

function loadXml(path) {
	var xml = createXmlDoc();
	
	if(xml!=null) {		
		xml.async=false;
		xml.load(path);
	}

	return xml;
}

function getXml(xmlNode) {
	if(xmlNode == null) return "";
	else if(xmlNode.nodeType == 3) return xmlNode.nodeValue;
	
	var value = "<" + xmlNode.nodeName;
	
	if(xmlNode.attributes) {
		for(i=0; i<xmlNode.attributes.length; i++) {
			value += " " + xmlNode.attributes[i].nodeName + "=\"" + xmlNode.attributes[i].value + "\"";				
		}
	}
	
	value += ">";
	if(xmlNode.nodeValue != null) value += xmlNode.nodeValue;
	
	if(xmlNode.childNodes) { 			
		for(var node = xmlNode.firstChild; node != null; node = node.nextSibling) { 
			value += getXml(node);
		}
	}
	
	value += "</" + xmlNode.nodeName + ">";
	return value;
}

function getMousePoint(evnt) {
    if(evnt.pageX || evnt.pageY){
        return {x:evnt.pageX, y:evnt.pageY};
    }
    return {
        x:evnt.clientX + document.body.scrollLeft - document.body.clientLeft,
        y:evnt.clientY + document.body.scrollTop  - document.body.clientTop
    };
}

function getMouseOffset(target, mousePos){
    var docPos = getPosition(target);	            
    return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
}

function getPosition(e,parentPoint){
    var left = e.offsetLeft;
    var top  = e.offsetTop;
    e = e.offsetParent;

    if(parentPoint) { 
        left += parentPoint.x;
        top += parentPoint.y;
    } else {
        while (e){
            left += e.offsetLeft;
            top  += e.offsetTop;
            e     = e.offsetParent;
        }
    }

    return {x:left, y:top};
}
            
function getCenterOfObject(obj) {
    if(obj) return { x:obj.offsetLeft + (obj.offsetWidth/2), y:obj.offsetTop + (obj.offsetHeight/2)};
    else return { x:0, y:0 };
}

function makeRequest(url, verb, body, callback, context) {
	var req = new Sys.Net.WebRequest();
	req.set_url(url);
	req.set_httpVerb(verb);
	if (body !== null && body !== "") req.set_body(body);
	if (context != null) req.set_userContext(context);
	req.add_completed(callback);
	req.invoke();
	return req;
}