﻿/* -----------------------------------------------*/
/* REDTECH.COM Javascript functions	              */
/* -----------------------------------------------*/
var silverlightInstalled = 'false';

function rt_CsSwapImage(targetImage)
{
	if (targetImage) 
	{
	 	document.getElementById('rt_cs_imageViewer').setAttribute('src', targetImage);
	}
}
    
function rt_fixDate(date) 
{
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
  {
    date.setTime(date.getTime() - skew);
  }
}

function rt_setCookie(name, value) 
{
  var now = new Date();
  rt_fixDate(now);
  now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);

  var curCookie = name + "=" + escape(value) + "; expires=" + now.toGMTString() + "; path=/";

  document.cookie = curCookie;
}

function rt_getCookie(name) 
{
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  
  if (begin == -1) 
  {
    begin = dc.indexOf(prefix);
    if (begin != 0) 
    { 
    	return null;
    }
  } 
  else 
  {
    begin += 2;
  }
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
  {
    end = dc.length;
  }
  return unescape(dc.substring(begin + prefix.length, end));
  // alert(unescape(dc.substring(begin + prefix.length, end)));
}

function rt_deleteCookie(name) 
{
  if (getCookie(name)) 
  {
    document.cookie = name + "=" + "0; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function rt_showHTML()
{

	var silverlightField = document.getElementById('silverlightNav');
	var htmlVersionField = document.getElementById('htmlNav');
	var JumpToSilverlightField = document.getElementById('JumpToSilverlight');
	var JumpToHTMLField = document.getElementById('JumpToHTML');
	var InstallSilverlightField = document.getElementById('InstallSilverlight');

	if (htmlVersionField) 
	{
		htmlVersionField.style.display = 'block';  
	}
	if (silverlightField) 
	{
		silverlightField.style.display = 'none';
	}
	if (JumpToHTMLField)
	{
		JumpToHTMLField.style.display = 'none'; 
	}

	if(silverlightInstalled == 'true')	  			
	{
		if (InstallSilverlightField)
		{
			InstallSilverlightField.style.display = 'none';
		}
		if (JumpToSilverlightField)
		{
			JumpToSilverlightField.style.display = 'inline';
		}
	}
	else
	{
		if (InstallSilverlightField)
		{
			InstallSilverlightField.style.display = 'inline';
		}
	}
	
	//handle services pages
	if(location.hash.indexOf("consulting") != -1)
    {
    	window.location = "/Pages/Consulting.aspx";
    }
    if(location.hash.indexOf("creative") != -1)
    {
    	window.location = "/Pages/Creative.aspx";
    }
    if(location.hash.indexOf("technology") != -1)
    {
    	window.location = "/Pages/Technology.aspx";
    }
    if(location.hash.indexOf("staffing") != -1)
    {
    	window.location = "/Pages/Staffing.aspx";
    }
    	
    // handle whatwedo page
	if (typeof rt_showHTMLService == 'function')
	{
		rt_showHTMLService();
	}


	rt_setCookie('siteMode', 'HTMLMode');
}
    
function rt_showSilverlight() 
{
	var silverlightField = document.getElementById('silverlightNav');
	var htmlVersionField = document.getElementById('htmlNav');
	var JumpToSilverlightField = document.getElementById('JumpToSilverlight');
	var JumpToHTMLField = document.getElementById('JumpToHTML');
	var InstallSilverlightField = document.getElementById('InstallSilverlight');

	if (htmlVersionField)
	{
		htmlVersionField.style.display = 'none';  
	}
	if (silverlightField)
	{
		silverlightField.style.display = 'block';
	}
	if (JumpToHTMLField)
	{
		JumpToHTMLField.style.display = 'inline';  
	}
	if (JumpToSilverlightField)
	{
		JumpToSilverlightField.style.display = 'none'; 
	}
	if (InstallSilverlightField)
	{
		InstallSilverlightField.style.display = 'none';
	}
	
	// handle services page
	if(location.href.indexOf("Consulting.aspx") != -1)
	{
		window.location = "/Pages/services.aspx#/consulting"; 
	}
	if(location.href.indexOf("Creative.aspx") != -1)
	{
		window.location = "/Pages/services.aspx#/creative";
	}
	if(location.href.indexOf("Technology.aspx") != -1)
	{
		window.location = "/Pages/services.aspx#/technology";
	}
	if(location.href.indexOf("Staffing.aspx") != -1)
	{
		window.location = "/Pages/services.aspx#/staffing";
	}

	// handle whatwedo page
	if (typeof rt_showSilverlightService == 'function')
	{
		rt_showSilverlightService();
	}
    	
	rt_setCookie('siteMode', 'SilverlightMode');
}


// Initial function to perform detection and present user option between SL and HTML modes
function rt_pageInit()
{
	var sitemode = rt_getCookie("siteMode");
	var browser = navigator.appName; // Get browser

	if (browser == 'Microsoft Internet Explorer')
	{
		try 
		{
			var slControl = new ActiveXObject('AgControl.AgControl');
			silverlightInstalled = 'true';
		}
		catch (e) 
		{ // Error. Silverlight not installed.
		}
	}
	else 
	{
		// Handle Netscape, FireFox, Google chrome etc
		try 
		{
			if (navigator.plugins["Silverlight Plug-In"]) 
			{
				silverlightInstalled = 'true';
			}
		}
		catch (err) 
		{	// Error. Silverlight not installed.
		}
	}

			    
	if (!sitemode) 
	{
		sitemode = "SilverlightMode"; 
	}
	//alert(sitemode);
				
	if(silverlightInstalled == 'true' && sitemode == "SilverlightMode")	  			
	{
		rt_showSilverlight();
	}
	else
	{
		rt_showHTML();
	}	
}

    


