/*
	Interactive Services - Site Javascript Functions
*/

// we need to figure out the current section of the site a given page is in
var currentSection = 0;

// shortened names for each section of the site, use these for images
var menuSections = ["home","sol","design","app","about","careers"];

// use the page title to figure out what section we're in
var ti = document.title.toLowerCase();
if (ti.indexOf(": solutions :") > -1) {
	currentSection = 2;
} else if (ti.indexOf(": design services :") > -1) {
	currentSection = 3;
} else if (ti.indexOf(": application :") > -1) {
	currentSection = 4;
} else if (ti.indexOf(": about :") > -1) {
	currentSection = 5;
} else if (ti.indexOf(": careers :") > -1) {
	currentSection = 6;
} else if (ti.indexOf(":") == -1) {
	currentSection = 1;
}

// create the getElementById method in case we have any older browsers that don't support it
if(!document.getElementById){
	if(document.all)
		document.getElementById=function(){
			if(typeof document.all[arguments[0]]!="undefined")
				return document.all[arguments[0]]
			else
				return null
		}
	else if(document.layers)
		document.getElementById=function(){
			if(typeof document[arguments[0]]!="undefined")
				return document[arguments[0]]
			else
				return null
		}
}

// display the "ON" state of the current section on the menu
function updateCurrentMenuImage()
{
	if (currentSection > 0) {
		var newsrc = "/_images/m" + currentSection + "_" + menuSections[currentSection-1] + "_btn_on.jpg";
		document["menu_" + menuSections[currentSection-1]].src= newsrc;
	}
}

// Set the page title on the page (Above the flash content)
function updatePageTitle()
{
	if (document.title.indexOf(":") > -1 && currentSection > 1) {
		var s = document.title.split(":");
		var newhtml = "<div id='menu_title_" + (currentSection-1) + "'>" + s[s.length-1] + "</div>";
		document.getElementById("page_title").innerHTML = newhtml;	
	} 
}

// image swapper for rollovers on the nav menu
function islMenuRollover( imgName, imgNum, state )
{
    	var thisSection = parseInt(imgNum.charAt(1));
    	if (thisSection == currentSection) {
    		state = "on";	
    	}
    	var newsrc = "/_images/" + imgNum + "_" + imgName + "_btn_" + state + ".jpg";
    	document["menu_" + imgName].src= newsrc;
}



// ***************************************************
// ************ dropdown menu functionality **********
// ***************************************************

sfHover = function() {
	var sfEls = document.getElementById("menu_nav").getElementsByTagName("td");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


// ***************************************************
// ************ Quick Links Menu *********************
// ***************************************************

function islQuickLinkChange(obj)
{
	// on change handler for the quick links menu
	//alert("Quick link change " + obj.options[obj.selectedIndex].value);
	if (obj.selectedIndex > 0) {
		var newlink = obj.options[obj.selectedIndex].value;
		if (newlink.length > 1 && newlink != "#") {
			location.replace("/" + newlink);
		}
	}
}

// ***************************************************
// ************ generic functions ********************
// ***************************************************

/**
	Carry out any javascript functions prior to loading the flash content
*/
function loadPage()
{
			
}

/**
	Carry out any javascript functions prior to unloading the page
*/
function unloadPage()
{
			
}

// use this script to include all courseware specific javascript functions

function testJS( msg )
{
	alert(msg);	
}

function getFlashVariable( vName )
{
	var x = document.flashMovie.GetVariable( vName );
	return x;
}

// ***************************************************
// ************ window functions *********************
// ***************************************************

/**
   function to calculate the x position of a new window so that it appears centered on screen
   @param nWidth integer specifying the width of the new window being opened
   @return integer specifying the x position for the ne window
*/
function getNewWinX( nWidth )
{
	var iLeft = screen.width/2 - nWidth/2
	return iLeft;	
}

/**
   function to calculate the y position of a new window so that it appears centered on screen
   @param nHeight integer specifying the height of the new window being opened
   @return integer specifying the y position for the ne window
*/
function getNewWinY( nHeight )
{
	var iTop = screen.height/2 - nHeight/2;
	return iTop;	
}

/**
   function to open a new window
*/
function openWindow(file_path,width,height)
{
	
	var theURL = file_path;
	
	var winParams = "toolbars=no,location=no,status=yes,resizeable=yes";
	winParams += ",width=" + width + ",height=" + height;
	winParams += ",left=" + openX + ",top=" + openY;
	
	islWin = window.open( theURL , "extra" , winParams);
}

/**
   function to open a PDF
*/
function islOpenPDF(file_name)
{
	var theURL = "/_resources/" + file_name;
	
	islWin = window.open( theURL );
}

// ***************************************************
// ************ cookie functions *********************
// ***************************************************

/**
   function to create a cookie
   @param name the name of the cookie to be created
   @param value the value of the cookie
   @param days (optional) the number of days for which the cookie should exist
   @return nothing
*/
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else var expires = "";
	document.cookie = name+"="+ escape(value)+expires+"; path=/";
}

/**
   function to read the value of a given cookie
   @param name the name of the cookie to be read
   @return the value of the given cookie or empty string "" if the cookie can't be found
*/
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return "";
	
}

/**
   function to erase a given cookie
   @param name the name of the cookie to be read
   @return nothing
*/
function eraseCookie(name)
{
	createCookie(name,"",-1);
}

