
// for all pages, perform any actions that need to occur AFTER a page has loaded:
//window.onload = fn_performGlobalActions;

// browser data information:
var agt = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

// site root path:
var siteRoot =  "http://xarios.com";

function fn_performGlobalActions ()
{
	fn_browserFixes();
}

function fn_browserFixes ()
{
	// netscape:
	if (document.layers && is_major == 4) fn_netscape4Fix();
}

function fn_netscape4Fix ()
{
	// *** PROBLEM ***
	// On versions 4 of Netscape, CSS support is rubbish, therefore a lot of gui
	// elements are all over the place - take up of this browser is miminal anyway
	// therefore not really justifying the extra work to make it compatible
	
	// *** SOLUTION ***
	// Redirect the user to another page that informs the user of the essential information
	// about the company
	window.location.href = siteRoot + "/InvalidBrowser.aspx";
}

function fn_statusBarMsg (text)
{
	window.status = text;
	return true;
}


function fn_ajaxTestMethod ()
{
    alert("ajax method being called...");
    AjaxTest.ServerSideAjaxTest(fn_ajaxTestMethod_callback);
}

function fn_ajaxTestMethod_callback (response)
{
    alert("ajax method response...");
    
    if (response.error != null)
    {
        // error message here
        alert("error");
    }
    else
    {
        alert("the response from the web server is...\n\n" + response.value);
	}
}

function fn_loadRecorderDemo ()
{
    document.getElementById('frmRecDemo').submit();
}

function popup(src, window_id, w, h)
{
    var titleBarHeight = 30;
	var xPos = (window.screen.width - w) / 2;
	var yPos = (window.screen.height - h + titleBarHeight) / 2;

	var windowFeatures = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable=yes,'
						+'width=' +w+ ',height=' +h+ ', left=' +xPos+ ',top=' +yPos;

	var newWin = window.open(siteRoot + src, window_id, windowFeatures);
}

// fn_showHelp
// content: the text that will be displayed in the tooltip
// levels: number of levels current page is from the root of the site
function fn_showHelp (top, content, levels, imgObject)
{
    var ref = document.getElementById('helpDiv');
    var path = "";
    var top = 0;
    var left = 0;
    
    for (i=0;i<levels;i++)
    {
        path += "../";
    }
	
    if (ref && imgObject)
    {
        while (imgObject.offsetParent)
		{
			top += imgObject.offsetTop;
			left += imgObject.offsetLeft;
			imgObject = imgObject.offsetParent;
		}
		
		ref.innerHTML = "<table><tr><td valign=top width='20'><img src='" + path + "Images/Information2.gif' width='16' height='16' /></td><td style='text-align: justify;'>" + content + "</td></tr></table>";
		ref.style.top = top;
		ref.style.left = left + 20;
        ref.style.display = "block";
    }
}

function fn_hideHelp ()
{
    var ref = document.getElementById('helpDiv');
	
    if (ref) ref.style.display = "none";
}

String.prototype.trim = function()
{ 
    // Strip leading and trailing white-space 
    return this.replace(/^\s*|\s*$/g, ""); 
} 


String.prototype.normalize_space = function()
{ 
    // Replace repeated spaces, newlines and tabs with a single space 
    return this.replace(/^\s*|\s(?=\s)|\s*$/g, ""); 
} 


function GetCoords(obj){
    var x = obj.offsetLeft;
    var y = obj.offsetTop;
    
    while(obj.offsetParent){
        x += obj.offsetLeft;
        y += obj.offsetTop;
        obj = obj.offsetParent;
    }
    return [x,y];
}


function fn_forceTextAreaMaxLength(textarea)
{
    if(textarea.maxlength && textarea.value.length >= textarea.maxlength)
    {
        textarea.value = textarea.value.substr(0, textarea.maxlength);
    }
}

function fn_setMaxTextLength(textarea, maxlength)
{
    textarea.maxlength = maxlength;
    textarea.onkeyup = function()
    {
        fn_forceTextAreaMaxLength(textarea);
    }
}



function fn_makeFieldsetExpandable(fieldsetId, initiallyHidden){
    // To make a fieldset expandable, it must have a child <legend> and all other content should be wrapped in a single <div>
    var fieldset = document.getElementById(fieldsetId);
    if(!fieldset) return;
    var legend = fieldset.getElementsByTagName("legend")[0];
    if(!legend) return;

    if(legend.innerText) legend.label = legend.innerText;
    else legend.label = legend.textContent;

    legend.onmouseover = function(){
        this.style.cursor = 'pointer';
        this.style.cursor = 'hand';
    }
    legend.onmouseout = function(){
        this.style.cursor = 'default';
    }

    legend.onclick = function(){
        var fieldset = this.parentNode;
        var mainDiv = fieldset.getElementsByTagName("div")[0];
        if(mainDiv.style.display == 'none') fieldset.expand();
        else fieldset.collapse();
    }

    // Add expand and collapse functions to the fieldset object:
    fieldset.expand = function(){
        var mainDiv = this.getElementsByTagName("div")[0];
        var legend = this.getElementsByTagName("legend")[0];
        mainDiv.style.display = 'block';
        legend.innerHTML = legend.label;
    }

    fieldset.collapse = function(){
        var mainDiv = this.getElementsByTagName("div")[0];
        var legend = this.getElementsByTagName("legend")[0];
        mainDiv.style.display = 'none';
        legend.style.height = 0;
        legend.innerHTML = legend.label + "&nbsp; <i style=\"color: #999999; font-size: 10px; text-transform: lowercase; \">(click to expand)</i>";
    }

    if(initiallyHidden) fieldset.getElementsByTagName("legend")[0].onclick();
}




function fn_setDropDownListValue(dropDownList, value){  
    for(var i = 0; i < dropDownList.options.length; i++){
        if(dropDownList.options[i].value == value){
            dropDownList.selectedIndex = i;
            break;
        }
    }
}

function fn_getDropDownListValue(dropDownList)
{
    return dropDownList.options[dropDownList.selectedIndex].value;
}

function fn_getDropDownListText(dropDownList)
{
    return dropDownList.options[dropDownList.selectedIndex].text;
}


function fn_getRadioButtonListValue(radioButtonList)
{
    var options = radioButtonList.getElementsByTagName("input");
    
    for(var i = 0; i < options.length; i++)
    {
        if (options[i].checked) return options[i].value;
    }
}



function fn_getSelection()
{
    var text = "";
    if (window.getSelection)
        text = window.getSelection();
    
    else if (document.getSelection)
        text = document.getSelection();
    
    else if (document.selection)
        text = document.selection.createRange().text;

    return text;
}


function cancelEvent(e) 
{
    if (!e) e = window.event;
    e.returnValue = false;
	if (e.preventDefault) e.preventDefault();
}

function stopEvent(e) 
{
    if (!e) e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
}