﻿function setSelectedMenu(menuId,subMenuId) {
    setClass(menuId, 'MenuSelected');
    
    // make sure the correct lnav is hsowing
    setDisplay('LNav' + menuId, 'block');

    if (subMenuId && subMenuId != '') {
        var obj = document.getElementById(subMenuId);

        // determine whether subnav has a submenu
        if (obj) {
            if (obj.className == 'exp')
                setClass(obj, 'expSelected');
            else
                setClass(obj, 'SubSelected');
        }

        /* set left nav */
        obj = document.getElementById('Sub' + subMenuId);
        
        // determine whether subnav has a submenu
        if (obj) {
            if (obj.className == 'exp')
                setClass(obj, 'expSelected');
            else {
                if (obj.className == 'col')
                    setClass(obj, 'colSelected');
                else
                    setClass(obj, 'SubSelected');
            }
        }
        
        obj = document.getElementById('DrM' + subMenuId);
        if (obj) {
            if (obj.className == 'lnavDrM')
                setClass(obj, 'lnavDrMSelected');
        }
    }
}
function findPos(obj) {
	var curleft = curtop = 0;
	if( obj == null || obj == undefined )
	    return [0,0];

	if (obj.offsetParent) {
        do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return [curleft,curtop];
}
function setContentSectionSize( size )
{
    setHeight( document.getElementById("ContentSection"), size );
    setHeight(document.getElementById("LeftNavActiveSection"), parseInt(size) - 8);
    setHeight(document.getElementById("FrameContentLeft"), size);
    setHeight( document.getElementById("FrameContentRight"), size );
}
function resizeContentSectionAdd( size )
{
    var contentHeight = document.getElementById("PageContent").clientHeight;
    setHeight( document.getElementById("PageContent"), contentHeight + size );
}
function resizeMenuSection( size )
{
    setHeight( document.getElementById("FrameMenuLeft"), size );
    setHeight( document.getElementById("FrameMenuRight"), size );
}
function positionAbsoluteObjects(){
	var pageWidth = document.getElementById("Wrapper").clientWidth;
	var clientWidth = document.body.clientWidth;
	var leftEdge = parseInt( (clientWidth/2)+(pageWidth/2) );
	
	if( leftEdge < 0 ) leftEdge = 0;

    var obj = document.getElementById("JoinNowBadge");
    if( obj != null )
	    setOffsetLeft( obj, leftEdge - (obj.clientWidth/2) - 20 );    
}
function getMarginLeft( obj )
{
    var left = obj.clientLeft;
    if( left == 0 )
    {
        left = parseInt( obj.currentStyle.marginLeft );
        if( left == "NaN" )
            left = 0;
    }
    return left;
}
function setMarginLeft( objOrId, leftOffsetIn )
{
    var leftOffset = parseInt( leftOffsetIn );

    if( typeof objOrId=="object" )
	{
	    if( objOrId != null && objOrId != undefined && getMarginLeft( objOrId ) != leftOffset )
	        objOrId.style.marginLeft = leftOffset + "px";
	    return;
	}
    if( typeof objOrId=="string" )
    {
        var obj = document.getElementById( objOrId );
	    if( obj != null && obj != undefined )
	        obj.style.marginLeft = leftOffset + "px";
	}
}
function setOffsetLeft( objOrId, leftOffsetIn )
{
    var leftOffset = parseInt( leftOffsetIn );

    if( typeof objOrId=="object" )
	{
	    if( objOrId != null && objOrId != undefined )
	        objOrId.style.left = leftOffset + "px";
	    return;
	}
    if( typeof objOrId=="string" )
    {
        var obj = document.getElementById( objOrId );
	    if( obj != null && obj != undefined )
	        obj.style.left = leftOffset + "px";
	}
}
function getHeight( obj )
{
    var height = obj.clientHeight;
    if( height == 0 )
    {
        height = parseInt( obj.currentStyle.height );
        if( height == "NaN" )
            height = 0;
    }
    return height;
}
function setHeight( objOrId, heightIn )
{
    var height = parseInt( heightIn );
    
    if( typeof objOrId=="object" )
	{
	    if( objOrId != null && objOrId != undefined )	    
            objOrId.style.height = height + "px";
	    return;
	}
    if( typeof objOrId=="string" )
    {
        var obj = document.getElementById( objOrId );
	    if( obj != null && obj != undefined )
	        obj.style.height = height + "px";
	}
}
function getWidth( obj )
{
    var width = obj.clientWidth;
    if( width == 0 )
    {
        width = parseInt( obj.currentStyle.width );
        if( width == "NaN" )
            width = 0;
    }
    return width;
}
function setWidth( objOrId, widthIn )
{
    var width = parseInt( widthIn );
    
    if( typeof objOrId=="object" )
	{
	    if( objOrId != null && objOrId != undefined && getWidth( objOrId ) != width )	    
            objOrId.style.width = width + "px";
	    return;
	}
    if( typeof objOrId=="string" )
    {
        var obj = document.getElementById( objOrId );
	    if( obj != null && obj != undefined && getWidth( obj ) != width )
	        obj.style.width = width + "px";
	}
}
function setVisibility( objOrId, visibility )
{
    if( typeof objOrId=="object" )
	{
	    if( objOrId != null && objOrId != undefined )
    	    objOrId.style.visibility = visibility;
	    return;
	}
    if( typeof objOrId=="string" )
    {
        var obj = document.getElementById( objOrId );
	    if( obj != null && obj != undefined )
    	    obj.style.visibility = visibility;
	}
}
function setDisplay( objOrId, value )
{
    if( typeof objOrId=="object" )
	{
	    if( objOrId != null && objOrId != undefined )
    	    objOrId.style.display = value;
	    return;
	}
    if( typeof objOrId=="string" )
    {
        var obj = document.getElementById( objOrId );
	    if( obj != null && obj != undefined )
    	    obj.style.display = value;
	}
}
function setClass( objOrId, className )
{
    if( typeof objOrId=="object" )
	{
	    if( objOrId != null && objOrId != undefined )
    	    objOrId.className = className;
	    return;
	}
    if( typeof objOrId=="string" )
    {
        var obj = document.getElementById( objOrId );
	    if( obj != null && obj != undefined )
    	    obj.className = className;
	}
}
function changeClass( objOrId, className )
{
    setClass( objOrId, className );
}
function changeFontColor( objOrId, color )
{
    if( typeof objOrId=="object" )
	{
	    if( objOrId != null && objOrId != undefined )
    	    objOrId.style.color = color;
	    return;
	}
    if( typeof objOrId=="string" )
    {
        var obj = document.getElementById( objOrId );
	    if( obj != null && obj != undefined )
    	    obj.style.color = color;
	}
}
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


/*
Viral : 13/3/2009 
Cookie Funcation 
*/
function AddCookie(strKey, strValue) {
    var Expires = new Date();
    
    var days = Expires.getDay();
    var mon = Expires.getMonth();
    Expires.setMonth(Expires.getMonth() + 12);
    
    document.cookie = strKey + "=" + escape(strValue) + ";expires=" + Expires;    
}

function getCookie(c_name) 
{
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}
/*End*/