﻿function GetBrowserVersion(type) 
{
    var nVer = navigator.appVersion;
    var nAgt = navigator.userAgent;
    var browserName = '';
    var fullVersion = 0;
    var majorVersion = 0;

    // In Internet Explorer, the true version is after "MSIE" in userAgent
    if ((verOffset = nAgt.indexOf("MSIE")) != -1) 
    {
        browserName = "Microsoft Internet Explorer";
        fullVersion = parseFloat(nAgt.substring(verOffset + 5));
        majorVersion = parseInt('' + fullVersion);
    }

    // In Opera, the true version is after "Opera"
    else if ((verOffset = nAgt.indexOf("Opera")) != -1) 
    {
        browserName = "Opera";
        fullVersion = parseFloat(nAgt.substring(verOffset + 6));
        majorVersion = parseInt('' + fullVersion);
    }

    // In Firefox, the true version is after "Firefox"
    else if ((verOffset = nAgt.indexOf("Firefox")) != -1) 
    {
        browserName = "Firefox";
        fullVersion = parseFloat(nAgt.substring(verOffset + 8));
        majorVersion = parseInt('' + fullVersion);
    }

    // In most other browsers, "name/version" is at the end of userAgent
    else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < (verOffset = nAgt.lastIndexOf('/'))) 
    {
        browserName = nAgt.substring(nameOffset, verOffset);
        fullVersion = parseFloat(nAgt.substring(verOffset + 1));
        if (!isNaN(fullVersion)) majorVersion = parseInt('' + fullVersion);
        else { fullVersion = 0; majorVersion = 0; }
    }

    // Finally, if no name and/or no version detected from userAgent...
    if (browserName.toLowerCase() == browserName.toUpperCase() || fullVersion == 0 || majorVersion == 0) 
    {
        browserName = navigator.appName;
        fullVersion = parseFloat(nVer);
        majorVersion = parseInt(nVer);
    }

    if (type == 'name') {
        return browserName;
    }
    else {
        return majorVersion;
    }

}

function SetFont(obj) 
{
	var font_string = 'none';
	if(location.search.toString().length > 0)
	{
		var qs_array = location.search.toString().substring(1).split('&');			
		for(var i = 0; i < qs_array.length; i ++)
		{
			if(qs_array[i].toString().split('=')[0].toString() == 'font')
			{
				font_string = qs_array[i].toString().split('=')[1].toString();
				break;
			} 
		}
	}
	
	if(font_string == 'large')
	{
	    if (GetBrowserVersion('name') == "Microsoft Internet Explorer") {
	        if (GetBrowserVersion('version') >= 7) {
	            //obj.innerHTML = "<style media=\"all\" type=\"text/css\"><!-- @import url(\"css/pg_font_ie7.css\"); --></style>";
	            if (document.createStyleSheet) {
	                window.frames['ifrm_tertiary_content'].document.createStyleSheet('css/pg_font_ie7.css');
	            } else {
	                var styles = "@import url('css/pg_font_ie7.css');";
	                var newSS = document.createElement('link');
	                newSS.rel = 'stylesheet';
	                newSS.href = 'data:text/css,' + escape(styles);
	                
	                window.frames['ifrm_tertiary_content'].document.getElementsByTagName("head");
	            }
	        }
	        else {
	            //obj.innerHTML = "<style media=\"all\" type=\"text/css\"><!-- @import url(\"css/pg_font_ie6.css\"); --></style>";
	            if (document.createStyleSheet) {
	                window.frames['ifrm_tertiary_content'].document.createStyleSheet('css/pg_font_ie6.css');
	            } else {
	                var styles = "@import url('css/pg_font_ie6.css');";
	                var newSS = document.createElement('link');
	                newSS.rel = 'stylesheet';
	                newSS.href = 'data:text/css,' + escape(styles);

	                window.frames['ifrm_tertiary_content'].document.getElementsByTagName("head");
	            }
	        }
	    }
	    else {
            obj.innerHTML = "<style media=\"all\" type=\"text/css\"><!-- @import url(\"css/pg_font.css\"); --></style>";
	    }
	}
}

function URLHandler (type, id, action)
{
	//alert('url handler + action: ' + action);

	var href_string = location.href.toString( );
	var href_length = href_string.length;
	var search_string = location.search.toString( );
	var search_length = location.search.toString( ).length;

	var clean_href_string = href_string.substring(0, href_length - search_length);

	var blnLoad = false;
	
	if(action == 'redirect')
	{
		if(id == 'font')
		{
			//type - small,large				
			var new_qs = '';	
			if(search_length > 0)
			{
				var font = false;
				var qs_array = search_string.substring(1).split('&');
					
				for(var i = 0; i < qs_array.length; i ++)
				{
					if(qs_array[i].toString().split('=')[0].toString() == 'font')
					{
						//type
						new_qs += '&font=' + type;
						font = true;
					} 
					else
					{			
						//anything else
						new_qs += '&' + qs_array[i].toString();
					}
				}
				
				if(font == false)
				{
					new_qs += '&font=' + type;
				}
			}else{
				new_qs += '?font=' + type;
			}
		}
		else
		{
			var new_qs = '';	
			if(search_length > 0)
			{
				var qs_array = search_string.substring(1).split('&');
					
				for(var i = 0; i < qs_array.length; i ++)
				{
					if(qs_array[i].toString().split('=')[0].toString() == 'content_type')
					{
						//type
					    new_qs += '&content_type=' + type;
					    blnLoad = true;
					} 
					else if(qs_array[i].toString().split('=')[0].toString() == 'content_id')
					{
						//id
					    new_qs += '&content_id=' + id;
					    blnLoad = true;
					}
					else
					{			
						//anything else
						new_qs += '&' + qs_array[i].toString();
					}
	            }

	            if (new_qs.indexOf('content_type') < 0)
	            {
	                new_qs += '&content_type=' + type + '&content_id=' + id;
	                blnLoad = true;
	            }
			}
			else
			{
			    new_qs = '&content_type=' + type + '&content_id=' + id;
			    blnLoad = true;
			}			
		}
		
		if(new_qs != '')
		{
			location.href = clean_href_string + '?' + new_qs.substring(1, new_qs.length);
		}
		else
		{
			location.href = clean_href_string;
		}
	}
	
	if(action == 'load' && search_length > 0)
	{
		var qs_array = search_string.substring(1).split('&');
		var load_type = '';
		var load_id = '';
		for(var i = 0; i < qs_array.length; i ++)
		{
			if(qs_array[i].toString().split('=')[0].toString() == 'content_type')
			{
				//type
			    load_type = qs_array[i].toString().split('=')[1].toString();
			    blnLoad = true;
			}
			if(qs_array[i].toString().split('=')[0].toString() == 'content_id')
			{
				//id
			    load_id = qs_array[i].toString().split('=')[1].toString();
			    blnLoad = true;
			}
		}

		if (blnLoad)
		{
		    ContentLoad(load_type, load_id);
		}
	}	
}

function LoadContent (content_type, content_id)
{
	//alert('in load content');
	URLHandler(content_type, content_id, 'redirect');
}

function ContentLoad (content_type, content_id)
{	
	ResetMenus ();
	
	var divMainPgImgHolder = document.getElementById('divImageHolder');
	divMainPgImgHolder.style.display = 'none';
	divMainPgImgHolder.style.visibility = 'hidden';
//	var divNews = document.getElementById('divNewsTicker');
//	divNews.style.display = 'none';
//	divNews.style.visibility = 'hidden';
	
	var divLeft = document.getElementById('content_body_left');
	var divRight = document.getElementById('content_body_right');
	var divContent = document.getElementById('tertiary_content');
	var ifrmContent = document.getElementById('ifrm_tertiary_content');

	var background_style = "";
	if(content_type == 'life')
	{
		background_style = 'url(images/nav/left/BG_purple.jpg) repeat-x top left';
	}
	if(content_type == 'home')
	{
		background_style = 'url(images/nav/left/BG_green.jpg) repeat-x top left';
	}
	if(content_type == 'communities')
	{
		background_style = 'url(images/nav/left/BG_orange.jpg) repeat-x top left';
	}
	if(content_type == 'about' || content_type == 'campaign')
	{
		background_style = 'url(images/nav/left/BG_blue.jpg) repeat-x top left';
	}
	if(content_type == 'footer')
	{
		background_style = 'url(images/nav/left/BG_gray.jpg) repeat-x top left';
	}
	
	divContent.style.display = 'block';
	divContent.style.visibility = 'visible';
	var include_path = "cfm/" + content_type + "/" + content_id + ".cfm";
	ifrmContent.src = include_path;

	divLeft.style.background = background_style;
	divRight.style.background = background_style;
	
	//reset text footer image
	var qs_array = location.search.toString().substring(1).split('&');	
	var font_size = 'small';			
	for(var i = 0; i < qs_array.length; i ++)
	{
		if(qs_array[i].toString().split('=')[0].toString() == 'font')
		{
			//font size
			font_size = qs_array[i].toString().split('=')[1].toString();	
		} 
	}
	
	var image_holder = document.getElementById('divFooterTextButton');	
	
	if(font_size == 'small')
	{
		image_holder.innerHTML = "<img id=\"nav_footer_text\" src=\"images/content/footer/text_on.png\" "
			+ "onmouseover=\"this.src='images/content/footer/text_off.png';\" "
			+ "onmouseout=\"this.src='images/content/footer/text_on.png';\" "
			+ "onclick=\"javascript:URLHandler ('large', 'font', 'redirect');\" "
			+ "style=\"cursor: pointer;\" alt=\"Click to increase text size\" title=\"Click to increase text size\" />";
	}	
	else
	{
		image_holder.innerHTML = "<img id=\"nav_footer_text\" src=\"images/content/footer/text_off.png\" "
			+ "onmouseover=\"this.src='images/content/footer/text_on.png';\" "
			+ "onmouseout=\"this.src='images/content/footer/text_off.png';\" "
			+ "onclick=\"javascript:URLHandler ('small', 'font', 'redirect');\" "
			+ "style=\"cursor: pointer;\" alt=\"Click to decrease text size\" title=\"Click to decrease text size\" />";
	}
}