var MainMenuLastObj;
function do_over(obj,color) {
	if (obj != MainMenuLastObj) {
		obj.style.backgroundColor = '#' + color;
		obj.style.color = 'black'; obj.style.cursor = 'hand';
	}
}
function do_out(obj) { 
	if (obj != MainMenuLastObj) { obj.style.backgroundColor = ''; obj.style.color = ''; }
}


//Returns an integer representing the width of the browser window (without the scrollbar).
function getWindowWidth() {
    return (document.layers||(document.getElementById&&!document.all)) ? window.outerWidth : (document.all ? document.body.clientWidth : 0);
}

//Returns an integer representing the height of the browser window (without the scrollbar).
function getWindowHeight() {
    return window.innerHeight ? window.innerHeight :(document.getBoxObjectFor ? Math.min(document.documentElement.clientHeight, document.body.clientHeight) : ((document.documentElement.clientHeight != 0) ? document.documentElement.clientHeight : (document.body ? document.body.clientHeight : 0)));
}

//Returns an integer representing the scrollWidth of the window.
function getScrollWidth() {
    return document.all ? Math.max(Math.max(document.documentElement.offsetWidth, document.documentElement.scrollWidth), document.body.scrollWidth) : (document.body ? document.body.scrollWidth : ((document.documentElement.scrollWidth != 0) ? document.documentElement.scrollWidth : 0));
}

//Returns an integer representing the scrollHeight of the window.
function getScrollHeight() {
    return document.all ? Math.max(Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight), Math.max(document.body.offsetHeight, document.body.scrollHeight)) : (document.body ? document.body.scrollHeight : ((document.documentElement.scrollHeight != 0) ? document.documentElement.scrollHeight : 0));
}


function HeightResizer(id){
    if( document.getElementById(id) ){
        document.getElementById(id).style.height = Math.max(getWindowHeight(),getScrollHeight())+'px';
        window.onresize = "HeightResizer("+id+")";
    }
}


function SwitchDivDisplay(DivID, msgSHOW, msgHIDE){
    CurrentState = document.getElementById(DivID).style.display ;
    if( CurrentState == 'none' ){
        document.getElementById(DivID+'DisplaySwitcher').innerHTML = '<img src="/images/24x24/window-close.png" width="16" height="16" alt="'+msgHIDE+'" title="'+msgHIDE+'" />';
        document.getElementById(DivID).style.display = 'inline';
        // location.href = "#Anc_" + DivName;
        DC2_AJAX_Exec(DC2_DefaultFormActionURL+'SetOption&Option='+DivID+'&Value=1',DC2_DefaultTarget,'',DC2_DefaultFormActionURL, DC2_DefaultFormName);
    }else{
        document.getElementById(DivID+'DisplaySwitcher').innerHTML = '<img src="/images/24x24/window-open.png" width="16" height="16" alt="'+msgSHOW+'" title="'+msgSHOW+'" />';
        document.getElementById(DivID).style.display = 'none';
        DC2_AJAX_Exec(DC2_DefaultFormActionURL+'SetOption&Option='+DivID+'&Value=0',DC2_DefaultTarget,'',DC2_DefaultFormActionURL, DC2_DefaultFormName);
    }
}


function ToggleDivDisplay(DivID){
    CurrentState = document.getElementById(DivID).style.display ;
    if( CurrentState == 'none' ){
        document.getElementById(DivID).style.display = 'inline';
    } else {
        document.getElementById(DivID).style.display = 'none';
    }
}


function setCaretPosition(elemId, caretPos) {
    var elem = document.getElementById(elemId);

    if(elem != null) {
        if(elem.createTextRange) {
            var range = elem.createTextRange();
            range.move('character', caretPos);
            range.select();
        }
        else {
            if(elem.selectionStart) {
                elem.focus();
                elem.setSelectionRange(caretPos, caretPos);
            }
            else
                elem.focus();
        }
    }
}


function redirect(url) {
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
        var referLink = document.createElement('a');
        referLink.href = url;
        document.body.appendChild(referLink);
        referLink.click();
    } else {
        location.href = url;
    }
}



