// Browser Detection
if ((document.all)&&(document.getElementById)) ie = true; else ie = false;

// Navigate Function (All Browsers)
function JumpTo(e)
{
	location.href = e;
}

// Global MouseOver (All Browsers)
function mOver(e) 
{
	if(ie) e = event.srcElement; else e = e.target;
	
	e.setAttribute("oldClass", e.className);	
	var sourceClass = e.className;
	
	if (sourceClass == "tmItem")
		e.className = "tmHL";
	else if (sourceClass == "mmItem")
		e.className = "mmHL";
	else if (sourceClass == "mmItemDisabled")
		e.className = "mmItemDisabled";
	else if (sourceClass == "mmNews")
		e.className = "mmHL";
	else if (sourceClass == "hotBoxL")
		e.className = "hotBoxLHL";
	else if (sourceClass == "jobBlockApply")
		e.className = "jobBlockApplyHL";
	else if (sourceClass == "jobBlockPrint")
		e.className = "jobBlockPrintHL";
	else if (sourceClass == "IndexLink")
		e.className = "IndexLinkHL";
	else if (sourceClass == "IndexLinkSL")
		e.className = "IndexLinkHL";
	else
		e.className = "linkUL";
}	

// Global MouseOut (All Browsers)
function mOut(e)
{
	if(ie) e = event.srcElement; else e = e.target;	
	e.className = e.getAttribute("oldClass");
}

// Email Application (All Browsers)
function JobApply(e)
{
	//location.href = 'mailto:careers@ctcinc.ca?subject=' + e;
	
	printHeader = '<html>\n';
	printHeader += '<title>' + e + '</title>\n';
	printHeader += '<head>\n';
	printHeader += '<link href="interface/css/apply.css" rel="stylesheet" type="text/css">\n';
	printHeader += '<script type="text/javascript" src="interface/scripts/global.js"></script>\n';
	printHeader += '</head>\n';
	printHeader += '<body>\n';
	printContent = '<iframe frameborder="0" width="100%" height="100%" src="applyform.aspx?ref=' + e + '" scrolling="no" ALLOWTRANSPARENCY="true"></iframe>\n';
	printFooter = '</body>\n';
	printFooter += '</html>';

	var wSize =	480;
	var hSize =	310;
	var LeftPos = (screen.width - wSize) / 2;
	var TopPos = (screen.height - hSize) / 2;		
	
	printWindow = window.open("","PrinterFriendly","width=" + wSize + ",height=" + hSize + ",top=" + TopPos + ",left=" + LeftPos + ",status=1,scrollbars=1,resizable=0");

	// open document for further output
	printWindow.document.open();

	// create document
	printWindow.document.write(printHeader + printContent + printFooter);
	
	// close the document
	printWindow.document.close(); 
}

// Printer Friendly Page Generator (All Browsers)
function DisplayJob(e)
{
	location.href = "careers.aspx?show=" + e + "&#" + e;
}

/*
// Loop Rotation (All Browsers)
// DESCIPTION:
// This function will sequentially loop thru a collection and display elements one after
// the other. Can be used in all pages and customized to each of them.
//
// USAGE:
// Create any html element and set the element style seting to "display:none" via css
// or directly on the element opening tag. Add a unique id with a incrementing number
// ex: id="test1", id="test2", id="test3"... thus creating a collection.
// Finally call the JRotation( ObjectCount , TimerInSeconds , Context ) function at the
// end of the page. Replace "ObjectCount" by the number of objects in your collection,
// "TimerInSeconds" by the amount of seconds before the moving on to the next element in the
// collection and "Context" by a unique case to be defined in the functions switch{}.

var JRotationObj = "";
var JRotationIndex = 1;
var JRotationCount = 1;
var JRotationTimer = 5;
var JRotationOld = "";
var JRotationContext = "";

function JRotation(c,t,context)
{	
	JRotationCount = c;	
	JRotationTimer = t;
	JRotationContext = context;
		
	if(JRotationContext)
	{
		switch(JRotationContext)
		{
			case "services":
				if(JRotationOld != "")
				{
					document.getElementById("index_ad"+JRotationOld).style.display = "";	
					document.getElementById("index_ref"+JRotationOld).style.display = "";	
				}
					
				document.getElementById("index_ad"+JRotationIndex).style.display = "block";	
				document.getElementById("index_ref"+JRotationIndex).style.display = "block";	
				break;
		}
	}	

	JRotationOld = JRotationIndex;
	
	if(JRotationIndex == JRotationCount)
		JRotationIndex = 1;
	else
		JRotationIndex++;	
	
	setTimeout("JRotation(JRotationCount,JRotationTimer,JRotationContext)", JRotationTimer*1000);	
}
*/

// Random Rotation (All Browsers)
// DESCIPTION:
// This function will randomly display elements part of a collection when the page
// is loaded. Can be used is all pages and customized to each of them. 
//
// USAGE:
// Create any html element and set the element style seting to "display:none" via css
// or directly on the element opening tag. Add a unique id with a incrementing number
// ex: id="test1", id="test2", id="test3"... thus creating a collection.
// Finally call the JRandom(ObjectCount,Context) function at the end of the page.
// Replace "ObjectCount" by the number of objects in your collection and "Context" by
// a unique case to be defined in the functions switch{}.

var JRandomObj = "";
var JRandomIndex = 1;
var JRandomCount = "";
var JRandomContext = "";

function JRandom(c,context)
{	
	JRandomCount = c;	
	JRandomContext = context;
	JRandomIndex = Math.round(Math.random()*JRandomCount);
	
	if(JRandomIndex == 0)
		JRandomIndex = 1;	

	if(show != "")
	{
		if(Number(show) <= JRandomCount && Number(show) > 0)
			JRandomIndex = show;
		else
			JRandomIndex = 1;
	}
		
	if(JRandomContext)
	{
		switch(JRandomContext)
		{
			case "services":
				document.getElementById("index_ref"+JRandomIndex).style.display = "block";				
				document.getElementById("index_menu"+JRandomIndex).className = "IndexLinkSL";				
				break;
				
			case "solutions":
				document.getElementById("index_ref"+JRandomIndex).style.display = "block";				
				document.getElementById("index_menu"+JRandomIndex).className = "IndexLinkSL";				
				break;				
		}
	}
}

// Show / Hide Display (All Browsers)
function JShowHide(e,i,c)
{
	if(ie) e = event.srcElement; else e = e.target;	
	
	switch(c)
	{
		case "services":
			document.getElementById("index_ref"+JRandomIndex).style.display = "";			
			document.getElementById("index_menu"+JRandomIndex).className = "IndexLink";		
			document.getElementById("index_ref"+i).style.display = "block";
			e.setAttribute("oldClass", "IndexLinkSL");
			e.className = "IndexLinkSL";
			JRandomIndex = i;
			break;
			
		case "solutions":
			document.getElementById("index_ref"+JRandomIndex).style.display = "none";			
			document.getElementById("index_menu"+JRandomIndex).className = "IndexLink";		
			document.getElementById("index_ref"+i).style.display = "block";
			e.setAttribute("oldClass", "IndexLinkSL");
			e.className = "IndexLinkSL";
			JRandomIndex = i;
			break;
	}
}

// Printer Friendly Page Generator (All Browsers)
function printerFriendly(e)
{
	pageLocation = location.href;
	var i = pageLocation.indexOf(".aspx");
	pageLocation = location.href.substring(0,i+5) + "?show=" + e;
	
	switch(lang)
	{
		case "fr":
			PageTitle = "Version pour Impression - " + e;
			SendToPrinter = "Imprimer cette page";
			PrintPage = "Imprimer sur cette page : ";
			BookmarkTitle = "CT Consultants Ref&eacute;rence Emploi - " + e;
			AddBookmark = "Sauvegarder dans vos Favoris";
			break;
			
		default:
			PageTitle = "Printer Friendly Version - " + e;		
			SendToPrinter = "Print this page";
			PrintPage = "Printed from this page : ";
			BookmarkTitle = "CT Consultants Job Reference - " + e;
			AddBookmark = "Add to Bookmarks";
			break;
	}	
	
	printHeader = '<html><title>' + PageTitle + '</title><head><link href="interface/css/print.css" rel="stylesheet" type="text/css">';
	printHeader += '<script type="text/javascript" src="interface/scripts/global.js"></script></head><body>';
	printHeader += '<table width="100%" cellpadding="0" cellspacing="0" style="margin-bottom: 10px;"><tr><td class="jobPrinter" onclick="window.print()">';
	printHeader += '<img src="interface/images/printer.gif" style="margin-right: 5px;">' + SendToPrinter + '</td>';
	printHeader += '<td width="100%">&nbsp;</td>';
	printHeader += '<td class="jobPrinter" onclick="opener.Bookmark(\'' + BookmarkTitle + '\',\'' + pageLocation + '\')">';
	printHeader += '<img src="interface/images/bookmark.gif" style="margin-right: 5px;">' + AddBookmark + '</td></tr></table>';	
	printHeader += '<table width="100%" cellpadding="0" cellspacing="0">';
	printContent = document.getElementById('CTCJobPosting').innerHTML.toString().replace("'","\'");
	printFooter =  '</table>';
	//printFooter += '<div class="jobPrinterinfo">' + PrintPage + pageLocation + '</div>';
	printFooter += '</body></html>';

	var wSize =	640;
	var hSize =	480;
	var LeftPos = (screen.width - wSize) / 2;
	var TopPos = (screen.height - hSize) / 2;		
	
	printWindow = window.open("","PrinterFriendly","width=" + wSize + ",height=" + hSize + ",top=" + TopPos + ",left=" + LeftPos + ",status=1,scrollbars=1,resizable=1");

	// open document for further output
	printWindow.document.open();

	// create document
	printWindow.document.write(printHeader + printContent + printFooter);
	
	// close the document
	printWindow.document.close(); 
}

function Bookmark(title,url)
{	
	if (window.sidebar)
	    window.sidebar.addPanel(title, url,"");		
	else if( document.all )
		window.external.AddFavorite(url, title);
	else
	    return true;
}

/*
Floating Menu script-  Roy Whittle (http://www.javascript-fx.com/)
Script featured on/available at http://www.dynamicdrive.com/
This notice must stay intact for use
*/

//Enter "frombottom" or "fromtop"
var verticalpos="fromtop"
						
function SlideMenu()
{
	var startX = 0,	
	startY = 0;
	offsetY = 300;
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	
	function ml(id)
	{
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		
		if(d.layers)
			el.style=el;

		el.sP=function(x,y){this.style.left=x;this.style.top=y;};
		el.x = startX;
		
		if (verticalpos=="fromtop")
			el.y = startY;		
		else
		{
			el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
			el.y -= startY;
		}
		
		return el;
	}
	
	function rs()
	{
		if (fltObjProp.offsetHeight > document.body.clientHeight)
		{
			fltJobIndex.className = "jobBlockIndexRS";			
			if(ie) offset = 150; else offset = 170;			
			fltJobIndex.style.height = document.body.clientHeight - offset;				
		}
	}
	
	window.stayTopLeft=function()
	{
		if (verticalpos=="fromtop")
		{
			var pY = ns ? pageYOffset : document.body.scrollTop;
			ftlObj.y += (pY + startY - ftlObj.y)/8;
		}
		else
		{
			var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
			ftlObj.y += (pY - startY - ftlObj.y)/8;
		}
		
		if(ftlObj.y > offsetY)
			ftlObj.sP(ftlObj.x, ftlObj.y - offsetY);	
		
		setTimeout("stayTopLeft()", 8);
		rs();

	}

	ftlObj = ml("slideMenu");
	fltObjProp = document.getElementById("slideMenu");
	fltJobIndex = document.getElementById("jobIndex");
	
	stayTopLeft();
}

/*
if (window.Event)
  document.captureEvents(Event.MOUSEDOWN);
  
function noRightClick(evt) {
  if (window.Event) {
    if (evt.which==2 || evt.which==3) {
      return false;
    }
  }
  return true;
}

document.onmousedown = noRightClick;

function noContextMenu(evt) {
  if (window.Event) {
    evt.cancelBubble = true;
    evt.returnValue = false;
  } else {
    event.cancelBubble = true;
    event.returnValue = false;
  }
  return false;
}

document.oncontextmenu = noContextMenu;
*/
