/*

    glogal javascript file
    
    functions and declarations placed here will
    be defined for every page
    
*/

/*---------------------------------------*
 | Cross-Browser,multi-frame get element |
 *---------------------------------------*/
function getElement(id,scope) {

    if (scope == null)
        scope = "document";
    else
        scope = scope + ".document";


    if (document.all) {
        return eval(scope).all[id];
    }
    else if (document.getElementById) {
        return eval(scope).getElementById(id);
    }

}


// Variable Declarations
var radioDivs = Array();

numRDS       = 2;
radioDivs[0] = false;
radioDivs[1] = false;


// Image pre-loading


function toggleRadioDivs(index) {

    for (i = 0; i < numRDS; i++) {
        if ((i == index) && (radioDivs[i] == false)) {
            getElement("radio_div_" + i).style.visibility = "visible";
            radioDivs[i] = true;
        }
        else if (i != index) {
            getElement("radio_div_" + i).style.visibility = "hidden";
            radioDivs[i] = false;
        }
    }

}

function getXMLHttp() {
    var objXMLHttp=null

    if (window.XMLHttpRequest)
        objXMLHttp=new XMLHttpRequest();
    else if (window.ActiveXObject)
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");

    return objXMLHttp;
}

/*-----------------------------------------------------------------*
 | Purpose: This takes the string name of a FCKeditor and returns  |
 |          the XHTML for the content it contains.                 |
 *-----------------------------------------------------------------*/
function getEditorValue( instanceName ) {
    return tinyMCE.getInstanceById(instanceName).getBody().innerHTML
}

/*-----------------------------------------------------------------*
 | Purpose: This takes the string name of a FCKeditor and a string |
 |          of text (can be X/HTML) and loads it into the          |
 |          'instanceName' FCKeditor.                              |
 *-----------------------------------------------------------------*/
function setEditorValue( instanceName, newContent ){
    tinyMCE.getInstanceById(instanceName).getBody().innerHTML = newContent;
}

function getXMLData(response,elementName) {
    return response.getElementsByTagName(elementName)[0].firstChild.data
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function addunLoadEvent(func) {
	var oldonunload = window.onunload;
	if (typeof window.onunload != 'function') {
		window.onunload = func;
	}
	else {
		window.onunload = function() {
			oldonunload();
			func();
		}
	}
}
