var     nConsoleLogLevel = 0;

/**
 * ConsoleLog writes to the console log if it exists.
 */
function ConsoleLog(s_mesg,i_level)
{
    if (typeof console != "undefined")
        if (typeof i_level == 'undefined' || i_level <= nConsoleLogLevel)
            console.log(s_mesg);
}

function ScrollDown(do_scroll,amt)
{
    if (do_scroll != 0)
    	window.scrollBy(0,amt);
}

function    GetScreenHeight()
{
    return (window.screen.availHeight);
}

function    GetScreenWidth()
{
    return (window.screen.availWidth);
}

/*********************************************************************
var strSearchString = '';

function SetSearchString(name)
{
   	document.SearchForm[name].value = strSearchString;
}

var objText;

function DoChange() {
   var objHTML;

   if (objText)
   {
	   var strTest = prompt("Enter new text you want to appear", objText.data);

       objText.data = strTest;
   }
   else
   {
       objHTML = document.createElement('P');
       objHTML.setAttribute('NAME', 'txtTest');
       objHTML.setAttribute('ID', 'txtTest');
       document.body.appendChild(objHTML);
       var strTest = prompt("Enter any text you want to appear", "whoops!");
       objText = document.createTextNode(strTest);
       objHTML.appendChild(objText);
       delete objHTML;
   }
}
	Last change: RR 22/05/04 5:25:44 PM
*********************************************************************/

/*
 * return a form element, by name
 */
function GetFormElement(s_name)
{
	return (document.forms[sFormName].elements[s_name]);
}
/*
 * return the type of an element, by name
 */
function GetType(elem)
{
	if (!elem)
		return ('');
	if (elem[0] != null)
			//
			// this handles radio buttons, which are returned as
			// an array of elements
			//
		return (elem[0].type);
	return (elem.type);
}
/*
 * Returns the value of a form element.
 */
function GetElementValue(elem)
{
	var		value;

	switch (GetType(elem))
	{
	case "radio":
			//
			// for radio buttons, we look for the button that is
			// currently checked, and then its value is the value
			// we need to compare with the saved value
			//
		value = -1;
		for (i_radio = 0 ; i_radio < elem.length ; i_radio++)
		{
			if (elem[i_radio].checked)
			{
				value = elem[i_radio].value;
				break;
			}
		}
		break;
	case "checkbox":
		if (elem.checked)
			value = elem.value;
		break;
	default:
		value = elem.value;
		break;
	}
	return (value);
}
/*
 * Returns the value of a form element, by name.
 */
function GetFormElementValue(s_name)
{
	return (GetElementValue(GetFormElement(s_name)));
}

	//
	// Show or hide a DIV section.
	//
function ShowHideDiv(s_id,b_show)
{
	var		elem = document.getElementById(s_id);

	if (elem)
		elem.style.visibility = (b_show) ? 'visible' : 'hidden';
}

	//
	// Return an obfuscated mail link.
	//
function ObfMailLink(s_name,s_domain,s_subj,s_text,s_extras)
{
	var		s_ret;

	s_ret = '<a ' + s_extras;
	s_ret += 'h' + 'ref="&#x6d;&#97;&#105;&#108;&#116;&#111;&#58;';		// that's "mailto:"
	s_ret += name + '@' + s_domain;
	if (s_subj != "")
		s_ret += '?subject=' + s_subj;
	s_ret += '">';
	s_ret += s_text + '</a>';
	return (s_ret);
}

function    FindCookie(allcookies,s_name)
{
    var     i_pos = allcookies.indexOf(s_name);
    var     def = null;

    if (i_pos != -1)
    {
        var     i_start = i_pos + s_name.length + 1;
        var     i_end = allcookies.indexOf(";",i_start);

        if (i_end == -1)
            i_end = allcookies.length;
        def = new Object({
                start:i_start,
                end:i_end,
                length:i_end - i_start + 1
                });
    }
    return (def);
}

function    GetCookie(s_name)
{
    var     allcookies = document.cookie;
    var     def = FindCookie(allcookies,s_name);
    var     s_value = "";

    if (def)
        s_value = decodeURIComponent(allcookies.substring(def.start,def.end));
    return (s_value);
}

function    SetCookie(s_name,s_value)
{
    document.cookie = s_name + "=" + encodeURIComponent(s_value);
}

/**
 * FindPageElement finds a form element by ID or by name, using jQuery, and
 * returns the jQuery object, or null on failure.
 */
function FindPageElement(s_id)
{
    var     j_elem;
    
    j_elem = $('#'+s_id);
    if ((j_elem = $('#'+s_id)).length == 0)
        if ((j_elem = $('[name="'+s_id+'"]')).length == 0)
            j_elem = null;
    return (j_elem);
}

/**
 * JS Function: AlertRedirect
 * Parameters:	s_url		the URL to redirect to
 *				s_mesg      an alert message to show first
 * Returns:		void
 * Author:		Russell Robinson, 20 September 2011
 * Purpose:
 *	To redirect to a different URL.
 */
function AlertRedirect(s_url,s_mesg)
{
    jQuery('document').ready(function () {
            if (s_mesg)
                alert(s_mesg);
            window.location.replace(s_url);
        });
}

/*
 * Stop a timer if there is one running.
 */  
function StopTimer(j_obj,s_name)
{
    if (j_obj.data(s_name) !== undefined)
    {
        clearTimeout(j_obj.data(s_name));
        j_obj.removeData(s_name);
    }
}
/*
 * Start any timer, and give it a name for stopping it.
 */
function StartTimer(j_obj,s_name,i_time,fn)
{
    j_obj.data(s_name,setTimeout(fn,i_time));
}

