/* JavaScript Library Routines Used throughout the PAWS Portal Application */
/* Added By:  Brandon Bernard */
/* Date:  06/05/2008 */
    function hideElement(strElementId) {
        //alert('hideElement');
        var objElement = document.getElementById(strElementId);
        if(objElement != null) objElement.style.display = 'none';
    }

    function displayElement(strElementId) {
        //alert('showElement');
        var objElement = document.getElementById(strElementId);
        if(objElement != null) objElement.style.display = '';
    }

    function setElementDisplayState(strElementId, bState)
    {
        if (bState)
        {
            displayElement(strElementId);
        }
        else
        {
            hideElement(strElementId);
        }
    }

    function toggleElementDisplay(strElementId)
	{
		var objElement = document.getElementById(strElementId);
		if (objElement != null)
		{
			if(objElement.style.display != null && objElement.style.display == 'none')
			{
        		//window.alert('display');
				//objElement.style.display = '';
				displayElement(strElementId);
			}
			else
			{
		        //window.alert('display off');
				//objElement.style.display = 'none';
				hideElement(strElementId);
			}
		}
	}

    function addEvent(elm, evType, fn, useCapture) {
	    if (elm.addEventListener) {
		    elm.addEventListener(evType, fn, useCapture);
		    return true;
	    }
	    else if (elm.attachEvent) {
		    var r = elm.attachEvent('on' + evType, fn);
		    return r;
	    }
	    else {
		    elm['on' + evType] = fn;
	    }
    }
    
	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof(window.onload) != 'function') {
			window.onload = func;
		} 
		else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}
    
    //By:  Brandon Bernard
    //Date:  08/08/2008
    //Purpoase: Allows you to manually execute the DotNet Client Side validation 
    //          and return true/false for success or failure.
    //Note:  This custom scripts to manually call the validation prior to running custom validation that
    //       may need to be executed AFTER the DotNet validation occurs (ie. Showing BusyBoxes for Processes, etc.)
    function doDotNetPageValidation()
    {
        //Default to Valid state, assuming no validation exists
        var bIsValid = true;

        //If validation exists then execute it and return results
        if(typeof(Page_ClientValidate) == 'function') 
        {
            Page_ClientValidate();

            if(Page_IsValid)
            {
                bIsValid = true;
            }
            else
            {
                bIsValid = false;
            }
        }

        return bIsValid;
    }
    
    //By:  Brandon Bernard
    //Date:  10/08/2008
    //Purpoase: Allows you to manually quickly Trim a String by extending the base Javascript String object
    String.prototype.trim = function () {
        return this.replace(/^\s*/, "").replace(/\s*$/, "");
    }

    //By:  Brandon Bernard
    //Date:  02/02/2009
    //Purpoase: Allows you to easily simulate a maximize command in Javascript for a browser window
    function maximizeWindow(objWindow)
    {
        try
        {
            objWindow.moveTo(0, 0);
            objWindow.resizeTo(screen.availWidth, screen.availHeight);
        }
        catch(e)
        {
            window.alert(e);
        }
    }

    //By:  Brandon Bernard
    //Date:  10/14/2008
    //Purpoase: Provides Generic Allows you to manually quickly Trim a String by extending the base Javascript String object
    function ConfirmGenericCancelOperation()
    {
        try
        {
            return window.confirm('Cancelling this operation could result in loss of updates and information.\n\n Do you want to continue?');            
        }
        catch(exc)
        {
            window.alert(exc);
        }
        return false;
    }

    function clonePageContentToNewWindow(strWindowParams)
    {
        var aryElements = window.document.getElementsByTagName('html');
        var elCurrentHtml = aryElements[0];
        var objNewWindow = window.open('', 'ClonedWindow', strWindowParams);
        objNewWindow.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
        objNewWindow.document.write('<html>' + elCurrentHtml.innerHTML + '</html>');
        return objNewWindow;
    }


