﻿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')
	{
		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)
{	
	//alert('in content load');

	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 == 'buy')
	{
		background_style = 'url(_images/nav/left/BG_orange.jpg) repeat-x top left';
	}
	if(content_type == 'visit')
	{
		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';
	}
	
	//to determine the directory to build the include_path
	var base_href = document.getElementsByTagName('base')[0].href;
	var sub_path = "";
	
	if(content_type == 'footer'){
		//site map is specific to spoke, others go to root
		if(content_id == 'sitemap'){
			sub_path = base_href + "_cfm/";
		}else{
			sub_path = HubRootDirectory + "/cfm/";
		}
	}else{
		sub_path = base_href + ContentDirectory + "/cfm/";
	}
	
	divContent.style.display = 'block';
	divContent.style.visibility = 'visible';
	
	var include_path = sub_path + 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/footer/text_on.png\" "
			+ "onmouseover=\"this.src='_images/footer/text_off.png';\" "
			+ "onmouseout=\"this.src='_images/footer/text_on.png';\" "
			+ "onclick=\"javascript:URLHandler ('large', 'font', 'redirect');\" "
			+ "style=\"cursor: pointer;\" />";
	}	
	else
	{
		image_holder.innerHTML = "<img id=\"nav_footer_text\" src=\"_images/footer/text_off.png\" "
			+ "onmouseover=\"this.src='_images/footer/text_on.png';\" "
			+ "onmouseout=\"this.src='_images/footer/text_off.png';\" "
			+ "onclick=\"javascript:URLHandler ('small', 'font', 'redirect');\" "
			+ "style=\"cursor: pointer;\" />";
	}
}