var SCR_isNav4 = (document.layers) ? 1 : 0;
var SCR_isNav6 = (document.getElementById) ? 1 : 0;
var SCR_isIE4Up = (document.all) ? 1 : 0;
var SCR_isMac = (navigator.appVersion.indexOf('Mac')!= -1)? 1:0 
var SCR_ImgPath = "images/";
var MENUBLOCKS = new Array();
var TABBLOCKS = new Array();
var FlyOutTimerObj = new Array();
var originalGlobalNav = '';
// Rollover
function move_in(which_image,img_src) {
	which_image.src = img_src;
}

function move_out(which_image,img_src) {
	which_image.src = img_src;
}

function show_hideCurrent(id,show){
	if(show)document.getElementById(id).style.display = "block";
	 else document.getElementById(id).style.display = "none";
}

function show_hideCurrentFade(id,show){
	if(show)$("#" + id).fadeIn(300);
	else $("#" + id).fadeOut(100);
}

/*
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	var printstring = '';
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}*/

function getXY(obj)
{
  var curleft = 0;
  var curtop = obj.offsetHeight + 5;
  var border;
  if (obj.offsetParent)
  {
    do
    {
      // XXX: If the element is position: relative we have to add borderWidth
      if (getStyle(obj, 'position') == 'relative')
      {
        if (border = getStyle(obj, 'border-top-width')) curtop += parseInt(border);
        if (border = getStyle(obj, 'border-left-width')) curleft += parseInt(border);
      }
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
    }
    while (obj = obj.offsetParent)
  }
  else if (obj.x)
  {
    curleft += obj.x;
    curtop += obj.y;
  }
  return {'x': curleft, 'y': curtop};
}

function getStyle(obj, styleProp)
{
  if (obj.currentStyle)
    return obj.currentStyle[styleProp];
  else if (window.getComputedStyle)
    return document.defaultView.getComputedStyle(obj,null).getPropertyValue(styleProp);
}


function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }


function changeClass(id, newclass) {
	
	var identity=document.getElementById(id);
	changeObjClass(identity, newclass)
}

function changeObjClass(obj, newclass){
	if(document.All)obj.setAttribute("className", newclass);
	else obj.className=newclass;	
}

function getTheClass(obj){
	if(document.All)return obj.getAttribute("className");
	else return obj.className
}

function toggleClass(ID,class1,class2){
	var obj = document.getElementById(ID);
	var newclass = (class1==getTheClass(obj))? class2:class1
	changeClass(ID, newclass)
}

function setupFAQItem(int,ID,group){
	 for(var i=1;i<=int;i++)
                MENUBLOCKS[ID+i] = new slideMenuDown(ID+i,group)
      
}

function toggleFAQItem(ID,liID,class1,class2){
	MENUBLOCKS[ID].toggleMe();
	toggleClass(liID,class1,class2)
}
function swapImage(img,ID){
	
	if(document.images[ID]!=undefined)document.images[ID].src = SCR_ImgPath+ img;	
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function showPanelTabContent(ID,index, linkObj){
	var obj = document.getElementById(ID);
	if(obj!=undefined){
	var objRight = getElementsByClass("innerRight",obj,"div")
	var objLeft = getElementsByClass("innerLeft",obj,"div")
	var objects = objLeft[0].getElementsByTagName("a")
	for (var i=0;i< objects.length;i++) 
	 (i==index)?changeObjClass(objects[i], "regular on"):changeObjClass(objects[i], "regular");
	 

	objects = objRight[0].getElementsByTagName("div")
	for (var i=0;i< objects.length;i++){
	 (i==index)? changeObjClass(objects[i], "innerRightContent on"):changeObjClass(objects[i], "innerRightContent");
	 //(i==index)? objects[i].style.display="none" : show_hideCurrentFade(objects[i].id,true)
	}
	}
	void(0);
}

function showInnerTabContent(ID,index){
	showPanelTabContent(ID,index,this);
	TABBLOCKS[ID].showMe();
	void(0);	
	
}

function rolloutTab(group){
	
	for ( keyVar in TABBLOCKS ){
		if(TABBLOCKS[keyVar].group==group){
			if(TABBLOCKS[keyVar].isShowing){
				TABBLOCKS[keyVar].swapTabImage();
			}
		}
	}
}



function tabsMenu(ID,group,tabIndex){
	this.ID = ID;
	this.group = group;
	this.hide = hide;
	this.showMe = showMe;
	this.defaultContent = document.getElementById(this.ID).innerHTML
	this.resetIt = resetIt;
	this.isShowing = false;
	this.tabIndex = tabIndex;
	this.swapTabImage = swapTabImage;
	this.showAll = showAll;

	document.getElementById(this.ID).style.display = "none";
	//this.resetIt();
	
	function swapTabImage(flag){
		if(flag)changeObjClass(document.getElementById("tab"+this.tabIndex), "tNav0"+this.tabIndex+"on")
		else changeObjClass(document.getElementById("tab"+this.tabIndex), "tNav0"+this.tabIndex)
	}
	
	function hide(){
		//changeClass(this.ID, "panel")
		this.swapTabImage(false)
		document.getElementById(this.ID).style.display = "none"
		if(this.isShowing) 
		this.isShowing =false;
	}
	function showMe(){
		for ( keyVar in TABBLOCKS ){
			if(keyVar!=this.ID&&TABBLOCKS[keyVar].group==this.group){
				TABBLOCKS[keyVar].hide();
			}
		}
		this.swapTabImage(true)
		//this.resetIt();
	    document.getElementById(this.ID).style.visibility = "visible"
		//changeClass(this.ID, "panel on");
		show_hideCurrentFade(this.ID,true)
		
		//this.swapTabImage();
		this.isShowing = true;
	}
	
	function resetIt(){
		document.getElementById(this.ID).innerHTML = this.defaultContent;	
	}
	
	function showAll(){
		for ( keyVar in TABBLOCKS )
			show_hideCurrentFade(TABBLOCKS[keyVar].ID,true)
	}
	
}


function slideMenuDown(ID,group){
		this.ID=ID;
		this.Group = group;
		this.object = document.getElementById(ID);
		this.Style = document.getElementById(ID).style;
		this.moveMenu =moveMenu;
		this.openstate = parseInt(this.object.scrollHeight)
		this.orig = parseInt(this.Style.height)
		this.target = this.openstate;
		this.movieIt = movieIt;
		this.toggle = toggle;
		this.toggleMe = toggleMe;
		this.oinc = parseInt((this.openstate+1)/10);
		this.inc = -1*(this.oinc);
		this.timeID = null;

		function toggle(){
			this.inc=this.inc*-1
			if(this.inc < 0)this.target = this.orig;
			else this.target = this.openstate; 
		
			for ( keyVar in MENUBLOCKS ){
				if(keyVar!=this.ID&&MENUBLOCKS[keyVar].Group==this.Group){
					MENUBLOCKS[keyVar].inc = -1*(MENUBLOCKS[keyVar].oinc);
					MENUBLOCKS[keyVar].target = MENUBLOCKS[keyVar].orig;
					MENUBLOCKS[keyVar].moveMenu();
				}
			}
			this.moveMenu();
		}
		
		
		function toggleMe(){
			this.inc=this.inc*-1
			if(this.inc < 0)this.target = this.orig;
			else this.target = this.openstate; 
			this.moveMenu();
		}
		
		
		function moveMenu(){
			if((parseInt(this.Style.height) < this.target&&this.target >this.orig)||(parseInt(this.Style.height) > this.target&&this.target ==this.orig)) {
				this.movieIt()
				 MENUBLOCKS[this.ID].timeID = setTimeout("MENUBLOCKS['"+this.ID+"'].moveMenu();","10");
			}//else{
				//	this.Style.height = this.target+"px";
				//}
		}
		
		function movieIt(){
		 if(parseInt(this.Style.height) > (this.target*.9)&&this.inc >0){
				
				if(this.inc < 1)this.inc = 1;
			}else if(this.inc < 0&&parseInt(this.Style.height) > (this.openstate*.1) ){
			
				if(this.inc < (-1*(this.oinc)))this.inc = -1*(this.oinc);
			}
			if((parseInt(this.Style.height) + this.inc)>this.target&&this.inc >0||(parseInt(this.Style.height) + this.inc) < this.target&&this.inc < 0)this.Style.height = this.target+"px";
			else this.Style.height = (parseInt(this.Style.height) + this.inc)+"px"
		}

	}
	
	function showPanel(ID,img,xOff,yOff){
		var navItem = document.getElementById("standardOverlay");
		navItem.innerHTML = "";
		navItem.style.display = "none";
		var obj = document.getElementById(img);
		//var nav_image = document.images[img];
		var newX = findPosX( obj)-xOff;//3;
		var newY = findPosY( obj)+yOff;//9;
		var orig = document.getElementById(ID)
		var content = orig.innerHTML;
		navItem.innerHTML = content;
		navItem.style.visibility = "hidden";
		navItem.style.display = "block";

		var tmph = navItem.scrollHeight; 
		navItem.style.display = "none";
		navItem.style.visibility = "visible";
		var porth = getScrollHeight() + viewportHeight();
		//getPageSizeWithScroll()
//alert(viewportHeight()+" "+topv);
		//alert(tmph+" :"+(newY+tmph)+" : "+(parseInt(getPageSizeWithScroll())-parseInt(tmph))+" "+getPageSizeWithScroll());
		if(tmph!=undefined&&((newY+tmph)>porth)){
			newY = (parseInt(porth)-parseInt(tmph))
		}
		navItem.style.xpos = parseInt(newX);//parseInt(navItem.left);	
		navItem.style.ypos = parseInt(newY);//parseInt(navItem.top);
		
		navItem.style.left = navItem.style.xpos+"px";	
		navItem.style.top =  navItem.style.ypos+"px";
		navItem.style.visibility="visible";
		show_hideCurrentFade("standardOverlay",true);
	
	
	}
	 function viewportHeight() {
    return self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
  }
  
  function viewportWidth() {
    return self.innerWidth || (document.documentElement.clientWidth || document.body.clientWidth);
  }

	
function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return yWithScroll;
}

function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}


	function showMenu(ID,img,xOff,yOff){
		SustainMenu(ID);
		var obj = document.getElementById(img);
		//var nav_image = document.images[img];
		var newX = findPosX( obj)-xOff;//3;
		var newY = findPosY( obj)+yOff;//9;
		
		var ttt = getXY(obj)
		//alert(ttt.x+" "+ttt.y)
		//newX = ttt.x;
		//newY = ttt.y;
		//var navItem = document.getElementById(ID)
	//alert(newX+" "+newY)
		var navItem = document.getElementById(ID).style;
	
		navItem.xpos = parseInt(newX);//parseInt(navItem.left);	
		navItem.ypos = parseInt(newY);//parseInt(navItem.top);
		
		navItem.left = navItem.xpos+"px";	
		navItem.top =  navItem.ypos+"px";
		navItem.visibility="visible";
		show_hideCurrentFade(ID,true);
	
		if(obj.src!=undefined)
	    	obj.src = obj.src.replace("_off","_on");
	
	}
	
	function hidePanel(){
		var navItem = document.getElementById("standardOverlay").style;
		navItem.display="none";
	}
	
	function SustainMenu(ID){
		clearTimeout(FlyOutTimerObj[ID]);
		FlyOutTimerObj[ID] = null;
	}
	
	function HideMenu(ID,other){
		FlyOutTimerObj[ID] = window.setTimeout("hideIt('"+ID+"','"+other+"')",400);
	}
	
	function hideIt(ID,other){
		navItem = document.getElementById(ID).style;
		navItem.visibility="hidden";
		if(ID !="product_sub_nav")navItem.display="none";
		var obj = document.getElementById(other);
		//alert(other+" "+originalGlobalNav+" "+obj)
		if(obj!=undefined){
			
			if(obj.src!=undefined){
				if(other.toLowerCase()!=originalGlobalNav.toLowerCase())obj.src = obj.src.replace("_on","_off");
				
			}
		}
	}
	
	function SCR_showMenu(ID,img,xOff,yOff){

		navItem = document.getElementById(ID).style;
		//var obj = document.getElementById(img);
		var obj = document.images[img];
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ 
 			var ieversion=new Number(RegExp.$1) 
 			//if (ieversion>=8||(ieversion>=7&&document.documentMode!=undefined))xOff++;
			//if ((ieversion==7&&document.documentMode!=undefined))xOff++;
		}
		var newX = findPosX( obj)-xOff;//3;
		var newY = findPosY( obj)+yOff;//9;
		//alert(newX+" "+newY)
		navItem.xpos = parseInt(newX);//parseInt(navItem.left);	
		navItem.ypos = parseInt(newY);//parseInt(navItem.top);
		
		navItem.left = navItem.xpos+"px";	
		navItem.top =  navItem.ypos+"px";
		SCR_changeOpac(0, ID)
		navItem.visibility="visible";
		SCR_fadeINOUT(true,ID,30,95,300)
	}

function SCR_fadeINOUT(flag,ID,start,stop,time){
		SCR_opacity(ID, start, stop, time)
}

function SCR_opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            window.setTimeout("SCR_changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
		window.setTimeout("SCR_removeit('"+id+"')",100);
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            window.setTimeout("SCR_changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
} 

function SCR_removeit(id){
	var navItem = document.getElementById(id).style;
	navItem.visibility="hidden";
}

function SCR_changeOpac(opacity, id) {
	//document.forms[0].show.value="|"+id+"|"
	if(id!=null&&id!=''){
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
	}	
}

function SCR_SustainMenu(ID){
		clearTimeout(FlyOutTimerObj[ID]);
		FlyOutTimerObj[ID] = null;
	}
	
	function SCR_HideThisMenu(ID){
		FlyOutTimerObj[ID] = window.window.setTimeout("SCR_hideIt('"+ID+"')",400);
	}
	
	function SCR_hideIt(ID){
		navItem = document.getElementById(ID).style;
		navItem.visibility = "hidden";
		SCR_changeOpac(0, ID)
	}

function loadFlashVideoMovie(file){
		var obj = document.getElementById("shell_FlashVideoContainer").style;
		obj.visibility = "hidden";
		obj.display = "block";
		var currentB = parseInt(getScrollHeight()) + parseInt(viewportHeight());
		
		//getScrollHeight() + viewportHeight();
		
		var currentT = parseInt(getScrollHeight());
		var currentW = parseInt(viewportWidth());
		var newX = (currentW/2) - (275)
		var newY = getScrollHeight()+ ((currentB - currentT)/2) - (200)
		//alert(newX+" "+newY+" "+currentB+" "+currentT+" "+currentW+" h"+obj.height)
		obj.left = (newX+15)+"px";
		obj.top = (newY - 30)+"px";
		
		var flashvars		= {'CFG':'/App_Themes/careers/xml/video/'+file+'.txt'};
		var params			= {"wmode":"transparent"};
		var attributes		= {'id':'flashSWFshell'};
			
			swfobject.embedSWF("/App_Themes/careers/flash/video_panel.swf", "flashSWFshell", "100%", "100%", "9.0.0", false, flashvars, params, attributes);
		}


function loadAddHokFlashVideoMovie(file,length,n,d){
		var obj = document.getElementById("shell_FlashVideoContainer").style;
		obj.visibility = "hidden";
		obj.display = "block";
		var currentB = parseInt(getScrollHeight()) + parseInt(viewportHeight());
		
		//getScrollHeight() + viewportHeight();
		
		var currentT = parseInt(getScrollHeight());
		var currentW = parseInt(viewportWidth());
		var newX = (currentW/2) - (275)
		var newY = getScrollHeight()+ ((currentB - currentT)/2) - (200)
		//alert(newX+" "+newY+" "+currentB+" "+currentT+" "+currentW+" h"+obj.height)
		obj.left = (newX+15)+"px";
		obj.top = (newY - 30)+"px";
		
		var flashvars		= {'CFG':'/cmspages/careers/genericvideo.aspx'+encodeURIComponent('?f='+file+'&l='+length+'&n='+escape(n)+'&d='+escape(d))};
		var params			= {"wmode":"transparent"};
		var attributes		= {'id':'flashSWFshell'};
			
			swfobject.embedSWF("/App_Themes/careers/flash/video_panel.swf", "flashSWFshell", "100%", "100%", "9.0.0", false, flashvars, params, attributes);
		}

function close_video_player(){
	var obj = document.getElementById("shell_FlashVideoContainer");
		//obj.innerHTML = '';
		obj.style.display = "none";
}


function passtohrs() {
      theForm.__VIEWSTATE.value='';
      theForm.encoding='application/x-www-form-urlencoded';
     // theForm.action='https://sobeys.hua.hrsmart.com/ats/career_center.php';
	   theForm.action='https://sobeysdev.hua.hrsmart.com/ats/career_center.php';
      theForm.submit();
}