var timesover=0;
var timerID = null;
//var boolFirstMenuFlag = true;
var boolTimerOn = false;
var intTimecount = 450;
var intRunCount = 0;
var intTabActive = 999;
var intNumTabs = 4;
var asTabs = new Array();
	asTabs[0] = "tab1";
	asTabs[1] = "tab2";
	asTabs[2] = "tab3";
	asTabs[3] = "tab4";
////////////////////////////////////////////////	
var ThisBoolTimerOn = false;
var ThisTimerID = null;
var IsMenu = false;

var ThisIsMenuTimer = false;
var ThisIsMenuBoolTimerOn = false;

function StopTime(){
	if (ThisBoolTimerOn){
		clearTimeout(ThisTimerID);
        ThisTimerID = null;
        ThisBoolTimerOn = false;
	}
	if(ThisIsMenuBoolTimerOn == false){
		ThisIsMenuTimer = setTimeout("MenuItemTime()",450);
		ThisIsMenuBoolTimerOn = true;
	}
}

function StartTime(id){
	/* initialize the menu to figure out which tab is set to active */
	if (ThisIsMenuBoolTimerOn){
		clearTimeout(ThisIsMenuTimer);
	    ThisIsMenuTimer = null;
	   	ThisIsMenuBoolTimerOn = false;
	}
	
	if (ThisBoolTimerOn == false && IsMenu == false) {
		ThisTimerID=setTimeout("ThisMenuOn('" + id + "')",intTimecount);
		ThisBoolTimerOn = true;
		IsMenu = true;
	}else{
		ThisMenuOn(id);
	}
}

function MenuItemTime(){
	IsMenu = false;
	ThisIsMenuBoolTimerOn = false;
}
/////////////////////////////////////////////////////////	
function doMenuOn(id) {
	StartTime(id);
}

function doInitializeMenu() {
	for (i=0; i<intNumTabs; i++)
	{
			if(document.getElementById("menuitem-" + asTabs[i]).className=="mainmenuitem active")
				intTabActive = i;
	}
}

function settimeover(){
timesover=1;
}

function ThisMenuOn(id){
	/* initialize the menu to figure out which tab is set to active */
	if (intRunCount < 1)
	{
		doInitializeMenu();
		intRunCount++;
	}

	
	//if (boolFirstMenuFlag == true)
	//{

		/*hide any menus that might be open*/
		if (document.getElementById("menuitem-" + id).className == "mainmenuitem active" && timesover==0)
		{
		//alert("active");
		timesover=1;
		}
		else
		{
		timesover=1;
		doHideAll();
		/* if statement to check if the submenu acutally exists, because the home menu doesn't have one */
		if(document.getElementById("submenu-" + id))
			document.getElementById("submenu-" + id).style.display = "block"; /*turn on the submenu*/
		
		/*change the style of the tab to the hover style*/	
		document.getElementById("menuitem-" + id).className = "mainmenuitem hover"; 
		
		for(var i=0; i < asTabs.length; i++){
			if(asTabs[i] == id && i!=0){
				//alert("asTabs=" + asTabs[i]);
				//alert("i=" + i);
				//alert("id=" + id);
				document.getElementById("menuitem-" + asTabs[i-1]).className = "mainmenuitem removeLine"; 
				
			}
		}
	
	
		/* stop the timer */
		doStopTime(); 
		}
	//}
}
function doMenuOff() {
for (i=0; i<intNumTabs; i++)
	{
			if(document.getElementById("menuitem-" + asTabs[i]).className=="mainmenuitem active")
				timesover=1;
	}
	/*start the timer */
	doStartTime(); 
	StopTime();
}
function doSubMenuOn(){
	/* stop the timer */
	doStopTime(); 
}
function doSubMenuOff(){
	 /* start the timer */
	 doStartTime();
}
function doHideAll(){

	for (i=0; i<intNumTabs; i++)
	{
		/* if statement to check if the submenu exists before we try to hide it */
		if(document.getElementById("submenu-" + asTabs[i]))
			document.getElementById("submenu-" + asTabs[i]).style.display = "none"; /* hide the submenu */
		/*set all tabs to the inactive style */
		document.getElementById("menuitem-" + asTabs[i]).className="mainmenuitem inactive";
	}
	/*set the active tab to the active style*/
	if (intTabActive < 999)
	{
		document.getElementById("menuitem-" + asTabs[intTabActive]).className="mainmenuitem removeLine";
	}
}
function doStopTime(){
	if (boolTimerOn){
		clearTimeout(timerID);
        timerID = null;
        boolTimerOn = false;
	}

}
function doStartTime(){
	if (boolTimerOn == false) {
		timerID=setTimeout( "doHideAll()" , intTimecount);
		boolTimerOn = true;
	}
}

//used to open videos in success stories.
function MM_openBrWindow(theURL,winName,features) { //v2.0
var winl = (screen.width - 705) / 2;
var wint = (screen.height - 100) / 2;
window.open(theURL,winName,features + ",top="+wint+", left="+winl);
}

function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function popExpertSeriesPresentation() {
	NewWindow('http://scope.telus.com/asp/ip_check.asp?vidpath=/mediasol/expert_series_nick_bontis/presentation/','centerpopup1','801','466','yes');
}


function locWin(locTitle,locURL,locOptions) {

var picWinHTML = '<html>';
picWinHTML += '<head><title>' + locTitle + '</title></head>';
picWinHTML += '<script language="JavaScript" type="text/javascript">self.focus();</script>';
picWinHTML += '<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">';
picWinHTML += '<div align="center"><img src="' + locURL + '" alt="' + locTitle + '" border="0"></div>';
picWinHTML += '</body>';
picWinHTML += '</html>';

var picWin = window.open('','NULL',locOptions);
picWin.document.open();
picWin.document.write(picWinHTML);
picWin.document.close();

}

//LW
function toggleRow(target,numrows,status)   {

     if (numrows > 1) {
     	for(var i=1; i<=numrows; i++) {
	     	var what = target + i;
	     	obj=(document.all) ? document.all[what] : document.getElementById(what);
		 	if (obj != null && typeof(obj) != "undefined") {
	     		if (status == "show") {
			    	obj.style.display='inline';
				} else {    
					obj.style.display='none';
				}
			}
     	}
     } else {
     
     	obj=(document.all) ? document.all[target] : document.getElementById(target);
     	if (obj != null && typeof(obj) != "undefined") {
	    	if (status == "show") {
		    	obj.style.display='inline';
		 	} else {    
			 	obj.style.display='none';
		 	}	 
	 	}
     }
}

function setCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function getCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return -1; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

function exitSurvey() {
var cookieName = "telusExitSurvey";
var cookieValue = getCookie(cookieName);
var url = "http://www.maritzsurveys.com/bvbin/bvigate.dll?SID=501&LID=EN&NOJ=1&referer=" + document.location.hostname + document.location.pathname;
var popup = false;

if (window.screenTop>10000) {
	if (cookieValue != null && cookieValue == 0) {
		popup = false;
	} else if (cookieValue != null && cookieValue > 0) {
		setCookie(cookieName, cookieValue-1, 45);
		popup = true;
	} else {
		setCookie(cookieName, 3, 45);
		popup = true;
	}
}

if (popup)
	window.open(url,"telus_survey","width=800,height=500,screenX=0,screenY=0,left=100,top=100,menubar=no,location=no,scrollbars=yes,directories=no,resizable=yes,fullscreen=no");

return false;

}

function exitTelusSurvey(e) { 
        var strLocation; 
        var targ; 
        var errorlevel = 0; 

        if (!e) var e = window.event
        if (e.target) {
                targ = e.target
        }
        else if (e.srcElement) {
                targ = e.srcElement;
                strLocation = String(targ);
        }
        var tname
        tname = targ.tagName;
        
        if (strLocation != "[object]") {
                errorlevel = 0;
                //if (strLocation.match("www.telus.com") == null && strLocation.match("www.telus.ca") == null) {
                if (strLocation.match("telus.com") == null) {
                        errorlevel = 1;
                }
        }
        
        if (errorlevel == 1) {
                url = "http://www.maritzsurveys.com/bvbin/bvigate.dll?SID=501&LID=EN&NOJ=1&referer=" + document.location.hostname + document.location.pathname;

                window.open(url,"telus_survey","width=800,height=500,screenX=0,screenY=0,left=100,top=100,menubar=no,location=no,scrollbars=yes,directories=no,resizable=yes,fullscreen=no");

                return false;
        }
}
//LW: Uncomment out below codes when the event is finished.
//window.onunload=exitSurvey;
