/*******************************
* Common JavaScript Functions
* Cross Browser Compatible
* Author: Kevin 
********************************/
var m_bLoggingOff = false;
var MessageWindow = null;
var bw;
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;
var IsIE = false; 

try
{
    if (checkIt('konqueror'))
    {
	    browser = "Konqueror";
	    OS = "Linux";
    }
    else if (checkIt('safari')) browser = "Safari"
    else if (checkIt('omniweb')) browser = "OmniWeb"
    else if (checkIt('opera')) browser = "Opera"
    else if (checkIt('webtv')) browser = "WebTV";
    else if (checkIt('icab')) browser = "iCab"
    else if (checkIt('msie')) { browser = "Internet Explorer"; IsIE = true; }
    else if (checkIt('firefox')) browser = "Firefox"
    else if (!checkIt('compatible'))
    {
	    browser = "Netscape Navigator"
	    version = detect.charAt(8);
    }
    else browser = "An unknown browser";

    if (!version) version = detect.charAt(place + thestring.length);

    if (!OS)
    {
	    if (checkIt('linux')) OS = "Linux";
	    else if (checkIt('x11')) OS = "Unix";
	    else if (checkIt('mac')) OS = "Mac"
	    else if (checkIt('win')) OS = "Windows"
	    else OS = "an unknown operating system";
    }
}
catch(ex)
{
}

function checkIt(string)
{
	try
	{
		place = detect.indexOf(string) + 1;
		thestring = string;
	}
	catch(e)
	{
	}
	return place;
}

function GetBrowswerVersionDetect()
{
	try
	{
		var s = detect;
		return (s);
	}
	catch(e)
	{
	}
	return "";
}

// Browsercheck
function Browsercheck()
{
	return this;
}	

    function object(o) {
        function f() {}
        f.prototype = o;
        return new f();
    }


function getall(oWindow)
{
	try
	{    
		if (oWindow == null || oWindow == 'undefined')
		{
			oWindow = window;
		}
	    
		if(IsIE)
		{
			return(oWindow.document.all);
		}
		else
		{
			return(oWindow.document.getElementsByTagName('*'));
		}
	}
	catch(e)
	{
	}
    return(null);
}

function GetObj(sTag, oWindow)
{
    return(getobj(sTag, oWindow));
}

function getobj(sTag, oWindow)
{
    try
    {
		if (oWindow == null || oWindow == 'undefined')
		{
			if(IsIE) // IE
			{
				return(document.all[sTag]);
			}
			else // Firefox
			{
				return(document.getElementById(sTag));
			}
		}
		if(IsIE)
		{
			return(oWindow.document.all[sTag]);
		}
		else
		{
			return(oWindow.document.getElementById(sTag));
		}
	}
	catch(e)
	{
	}
    return(null);
}

function GetWindowID(obj)
{
	try
	{
		if(obj.id != null && obj.id != "")
		{
			return obj.id;
		}
		else
		{
			if(obj.name != null && obj.name != "")
			{
				return obj.name;
			}
		}
	}
	catch(e)
	{
//		alert (e);
	}
	return null;
}

function getobjattr(sTag, obj, oWindow)
{
    try
    {
		if (oWindow == null || oWindow == 'undefined')
		{
			if(IsIE) // IE
			{
				return(obj.all[sTag]);
			}
			else // Firefox
			{
				return(obj.getElementById(sTag));
			}
		}
		if(IsIE)
		{
			return(oWindow.obj.all[sTag]);
		}
		else
		{
			return(oWindow.obj.getElementById(sTag));
		}
	}
	catch(e)
	{
	}
    return(null);
}


function GetHtmlFrame(sFrameNameOrID)
{
	try
	{
		return (window.parent.frames[sFrameNameOrID]);
	}
	catch(e)
	{
		return (window.parent.frames.document.getElementById(sFrameName));
	}
}

function GetEventClientY(obj)
{
    if(IsIE)
    {
		return window.event.clientY;
    }
    else
    {
		return obj.clientY;
    }
}

function GetEventClientX(obj)
{
    if(IsIE)
    {
		return window.event.clientX;
    }
    else
    {
		return obj.clientX;
    }
}


function getSearchAsArray()
{
	// Browser-sniffing variables.
	var minNav3 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 3)
	var minIE4 = (navigator.appName.indexOf("Microsoft") >= 0 && parseInt(navigator.appVersion) >= 4)
	var minDOM = minNav3 || minIE4   // Baseline DOM required for this function
	// Initialize array to be returned.
	// Unescape and strip away leading question mark.
	var input = unescape(location.search.substring(1))
	var results = null;
	if (minDOM)
	{
		results = MakeNamePairArray(input);
	}
	minNav3 = null;
	minIE4 = null;
	minDOM = null;
	input = null;
	return results
}

function MakeNamePairArray(input)
{
	var results = new Array()
	if (input)
	{
		// Divide long string into array of name/value pairs.
		var srchArray = input.split("&")
		var tempArray = new Array()
		for (i = 0; i < srchArray.length; i++)
		{
			// Divide each name/value pair temporarily into a two-entry array.
			tempArray = srchArray[i].split("=")
			// Use temp array values as index identifier and value.
			results[tempArray[0]] = tempArray[1]
		}
	}
	tempArray = null;
	return results
}
function HideAllControls(sType, bMode, oWindow)
{
	try
	{
		var all=getall(oWindow);			
		var coll = all.tags(sType);    
		if(all != null)
		{
			if (coll.length > 0)
			{
				for (var i=0;i<coll.length;i++)
				{
					var obj = coll[i];
					if(bMode == true)
						obj.style["visibility"] = "visible";
					else
						obj.style["visibility"] = "hidden";
				}
			}
		}
		all = null;
		coll = null;
	}
	catch(e)
	{
	}
}
// http://localhost/EaglePass/PlazaMonitor/TestJSSoapClient.aspx
function SetTextField(sField, sText, oWindow)
{
	try
	{
		var obj = getobj(sField, oWindow);
		if(obj != null)
		{
			obj.value = sText;
			obj = null;
		}
	}
	catch(e)
	{
	}
}
function GetTextField(sField, oWindow)
{
	try
	{
		var obj = getobj(sField,oWindow);
		if(obj != null)
		{
			return(obj.value);
		}
	}
	catch(e)
	{
	}
	return("");
}

function GetTextFieldLength(sField, oWindow)
{
	try
	{
		var obj = getobj(sField,oWindow);
		if(obj != null)
		{
			return(obj.value.length);
		}
	}
	catch(e)
	{
	}
	return(0);
}


function SetInnerHtml(sField, sText, oWindow)
{
	try
	{
		var obj = getobj(sField, oWindow);
		if(obj != null)
		{
			obj.innerHTML = sText;
			obj = null;
		}
	}
	catch(e)
	{
	}
}
function GetInnerHtml(sField, oWindow)
{
	try
	{
		var obj = getobj(sField, oWindow);
		if(obj != null)
		{
			return (obj.innerHTML);
		}
		else
		{
			return null;
		}
	}
	catch(e)
	{
	}
}

function GetInnerHtmlLength(sField, oWindow)
{
	try
	{
		var obj = getobj(sField, oWindow);
		if(obj != null)
		{
		    s = new String(obj.innerHTML);
		    var n = s.length;
		    s = null;
		    obj = null;
			return (n);
		}
		else
		{
			return 0;
		}
	}
	catch(e)
	{
	}
}


function SetFocus(sID, oWindow)
{
	try
	{
		var obj = getobj(sID, oWindow);
		if(obj != null)
		{
			try
			{
				obj.focus();
			}
			catch(e)
			{
				// alert("error " +e);
			}
			obj = null;
		}
	}
	catch(e)
	{
	}
}
function Select(sID, oWindow)
{
	try
	{
		var obj = getobj(sID, oWindow);
		if(obj != null)
		{
			try
			{
				obj.select();
			}
			catch(e)
			{
				// alert("error " +e);
			}
			obj = null;
		}
	}
	catch(e)
	{
	}
}

function SetSelectIndex(sField, nItem, oWindow)
{
	var obj = getobj(sField, oWindow);
	if(obj != null)
	{
		try
		{
			obj.selectedIndex = nItem;
		}
		catch(e)
		{
			// alert("error " +e);
		}
		obj = null;
	}
}
function GetSelectIndex(sField, oWindow)
{
	var obj = getobj(sField, oWindow);
	if(obj != null)
	{
		try
		{
			return(obj.selectedIndex);
		}
		catch(e)
		{
			// alert("error " +e);
		}
		return 0;
	}
}
function Show(sObj, zIndex, x, y, h, w, oWindow)
{
	var obj = getobj(sObj, oWindow);
	if(obj != null)
	{
		try
		{	
			obj.style["visibility"] = "visible";
			var s;
			if(typeof(zIndex) != "undefined") obj.style["zIndex"] = zIndex;
			s = x + "px";
			if(typeof(x) != "undefined") obj.style["left"] = s;
			s = y + "px";
			if(typeof(y) != "undefined") obj.style["top"] = s;
            s = h + "px";
	        if(typeof(h) != "undefined") obj.style["height"] = s;
	        s = w + "px";
	        if(typeof(w) != "undefined") obj.style["width"] = s;
			obj.style["position"] = "absolute";
		}
		catch(e)
		{
		}
		obj = null;
	}
}

function MoveObj(sObj, x, y, zIndex, oWindow)
{
    var obj = getobj(sObj, oWindow);
	if(obj != null)
	{
		try
		{	
			obj.style["visibility"] = "visible";
			var s;
			if(typeof(zIndex) != "undefined") obj.style["zIndex"] = zIndex;
			s = x + "px";
			if(typeof(x) != "undefined") obj.style["left"] = s;
			s = y + "px";
			if(typeof(y) != "undefined") obj.style["top"] = s;
			obj.style["position"] = "absolute";
		}
		catch(e)
		{
		}
		obj = null;
	}
}

function getPosition(elementId)
{
    var element = document.getElementById(elementId);
    var left = 0;
    var top = 0;
    	
    if (element != null)
    {
        // Try because sometimes errors on offsetParent after DOM changes.
        try
        {
            while (element.offsetParent)
            {
                // While we haven't got the top element in the DOM hierarchy
                // Add the offsetLeft
                left += element.offsetLeft;
                // If my parent scrolls, then subtract the left scroll position
                if (element.offsetParent.scrollLeft) {left -= element.offsetParent.scrollLeft; }
    	
                // Add the offsetTop
                top += element.offsetTop;
                // If my parent scrolls, then subtract the top scroll position
                if (element.offsetParent.scrollTop) { top -= element.offsetParent.scrollTop; }
    	
                // Grab
                element = element.offsetParent;
            }
        }
        catch (e)
        {
            // Do nothing
        }
    	
        // Add the top element left offset and the windows left scroll and subtract the body's client left position.
        left += element.offsetLeft + document.body.scrollLeft - document.body.clientLeft;
    	
        // Add the top element topoffset and the windows topscroll and subtract the body's client top position.
        top += element.offsetTop + document.body.scrollTop - document.body.clientTop;
    }
    return {x:left, y:top};
}

function mouseCoords(ev)
{
	if(ev.pageX || ev.pageY)
	{
		return {x:ev.pageX, y:ev.pageY};
	}
	return	{x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,y:ev.clientY + document.body.scrollTop  - document.body.clientTop};
}

function Hide(sObj, bZeroPosition, oWindow)
{
	var obj = getobj(sObj, oWindow);
	if(obj != null)
	{
		try
		{
			obj.style["visibility"] = "hidden";
			if(typeof(bZeroPosition) != 'undefined')
			{
				if(bZeroPosition == true)
				{
					obj.style["top"] = 0;
					obj.style["left"] = 0;
					obj.style["width"] = 0;
					obj.style["height"] = 0;
					obj.style["position"] = "absolute";
				}
			}
		}
		catch(e)
		{
		}
		obj = null;
	}
}
function opacity(id, opacStart, opacEnd, millisec)
{
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id)
{
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function GetTime(nFormat)
{
	var timeValue = "";
	try
	{
		var now = new Date()
		var nMonth = now.getMonth()
		var nDay = now.getDate()
		var nYear = now.getYear()
		var hours = now.getHours()
		var minutes = now.getMinutes()
		var seconds = now.getSeconds()
		if(nFormat == 0) timeValue = "" + (nMonth+1) + "/" + (nDay) + "/" + nYear + " "
		
		if(hours == 0)
			timeValue += "12"
		else
			timeValue += "" + ((hours > 12) ? hours - 12 : hours)	
			
		timeValue += ((minutes < 10) ? ":0" : ":") + minutes
		if(nFormat > 0) timeValue += ((seconds < 10) ? ":0" : ":") + seconds
		timeValue += (hours >= 12) ? "pm" : "am"
		now = null;
	    nMonth = null;
		nDay = null;
		nYear = null;
		hours = null;
		minutes = null;
		seconds = null;
	}
	catch(e)
	{
	}
	return timeValue;
}

function ToLower(s)
{
    return (s.toLowerCase());
}
function Trim(s)
{
	try
	{
		return (Rtrim(Ltrim(s)));
	}
	catch(e)
	{
	}
	return s;
}
function Ltrim(s)
{
	try
	{
		var s1 = String(s);
		return (s1.replace(/^\s+/g, ""));
	}
	catch(e)
	{
	}
	return s;
}
function Rtrim(s)
{
	try
	{
		var s1 = String(s);
		return (s1.replace(/\s+$/g, ""));
	}
	catch(e)
	{
	}
	return s;
}

String.prototype.contains=function(substr)
{
	return new RegExp(substr,"i").test(this);
}

function KGPlayAudio(s)
{
    return;
    
    var thissound = null;
	try
	{
		thissound=document.getElementById("KGAudio");
		if(thissound != null) thissound.PlaySound(s);
	}
	catch(e)
	{
	}
	finally
	{
		thissound = null;
	}
//	return s;
}
