// Utility Javascript for jobshark	

function imgRef(myLayer,myImage) { // creating a generic object reference
	if(document.layers) { //ns4
		obj = eval("document.layers['" + myLayer + "'].document.images['" + myImage + "']");
	}
	else if(document.all){ //MSIE
		obj = eval("document.all('" + myImage + "')");
	}
	else if(document.getElementById){//ns6+Mozilla
		obj = eval("document.getElementById('"+myImage+"')");
	}
	
	return obj;
}
				

// rollover preloads
//	  format of image object is "image name" + "_on" or "_off" ; 
//	  on image file has "_h", off image file doesn't

function loadImages() {
			resizetipsheight();
			resizetipshowheight();
}
		
loadImages();

// rollover code uses imgRef above
function RollOn(myLayer,myImage) {
	eval("imgRef(myLayer,myImage).src = " + myImage + "_on.src");
}

function RollOff(myLayer,myImage) {
	eval("imgRef(myLayer,myImage).src = " + myImage + "_off.src");
}

function NewWindow(jobshark, popwin, 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=no'
win = window.open(jobshark, popwin, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

var vHeight;

function getMainHeight(divName) 
{	
	
	var obj;
	if (document.layers)
	{
		obj = eval("document." + divName);
		vHeight = obj.clip.height - 25;
		return vHeight;
	}
	//no layer
	else
	{
		obj = eval(divName);
		vHeight = obj.clientHeight - 50;
		return vHeight;
	
	}

}

function ResizeTips(divName,tipName,imgspacer)
{	
	var obj;
	var imgheight;
	var test;
	
	if(document.layers)
	{
		obj = eval("document." + tipName);
		myImage = new Image(1, getMainHeight(divName));
		eval('myImage.src = \"/img/spacer.gif\"');
		obj.clip.height = getMainHeight(divName);
		eval('document.' + tipName + '.background.src = \"/img/grey_grad.gif\"');
		obj.document.images['imgs'].src = myImage.src;
		
	}
	
	//no layer
	else
	{
		obj = eval(tipName);
		obj.height = getMainHeight(divName);
		tiptable.height = getMainHeight(divName);
		
	}

}


/////////////

function resizetipsheight()
{	
	var obj;
	var orgheight;
	var totalheight;
	
		
	if (parent.document.layers)
	{
		if (eval(parent.document.layers['jobsearch']) && eval(parent.document.layers['tips']))
		{	
			orgheight = document.tips.clip.height;
			if (orgheight < getMainHeight('jobsearch'))
			{
				document.tips.clip.height = getMainHeight('jobsearch')-80;
			}
			eval('document.tips.background.src = \"/img/grey_grad.gif\"');
		}
		
		if (eval(parent.document.layers['companyprofiles']) && eval(parent.document.layers['tips']))
		{	
			orgheight = document.tips.clip.height;
			if (orgheight < getMainHeight('companyprofiles'))
			{
				document.tips.clip.height = getMainHeight('companyprofiles');
			}
			document.tips.clip.height = getMainHeight('companyprofiles')-80;
			eval('document.tips.background.src = \"/img/grey_grad.gif\"');
		
		}
		
		if (eval(parent.document.layers['account']) && eval(parent.document.layers['jobs']) && eval(parent.document.layers['applications']) && eval(parent.document.layers['tips']))
		{	
			orgheight = document.tips.clip.height;
			totalheight = document.account.clip.height + document.jobs.clip.height + document.applications.clip.height - 25;
			if (orgheight < totalheight)
			{
				document.tips.clip.height = totalheight-80;
			}
			eval('document.tips.background.src = \"/img/grey_grad.gif\"');
		}
	
	}
	//no layer
	else
	{
	
		if (eval("document.all('jobsearch')") && eval("document.all('tips')"))
		{	
			
			obj = eval('tips');
			obj.height = getMainHeight('jobsearch');
			tiptable.height = getMainHeight('jobsearch') -80;
			
		}
		
		if (eval("document.all('companyprofiles')") && eval("document.all('tips')"))
		{	
			obj = eval('tips');
			obj.height = getMainHeight('companyprofiles');
			tiptable.height = getMainHeight('companyprofiles') -80;
		}
		
		if (eval(document.all['account']) && eval(document.all['myjobs']) && eval(document.all['myapplications']) && eval(document.all['tipshow']))
		{	

			obj = eval('tips');
			totalheight = parseInt(getMainHeight('myjobs')) + parseInt(getMainHeight('jobs')) + parseInt(getMainHeight('myapplications')) + 150 + 80;
			
			obj.height = totalheight;
			tiptable.height = totalheight - 80;
			
		}
	
	}

}


function resizetipshowheight()
{	
	var obj;
	var orgheight;
	var totalheight;
	
		
	if (parent.document.layers)
	{
		if (eval(parent.document.layers['jobsearch']) && eval(parent.document.layers['tipshow']))
		{	
			orgheight = document.tipshow.clip.height;
			if (orgheight < getMainHeight('jobsearch'))
			{
				document.tipshow.clip.height = getMainHeight('jobsearch')-80;
			}
			eval('document.tipshow.background.src = \"/img/grey_grad.gif\"');
		}
		
		if (eval(parent.document.layers['companyprofiles']) && eval(parent.document.layers['tipshow']))
		{	
			orgheight = document.tipshow.clip.height;
			if (orgheight < getMainHeight('companyprofiles'))
			{
				document.tipshow.clip.height = getMainHeight('companyprofiles');
			}
			document.tipshow.clip.height = getMainHeight('companyprofiles')-80;
			eval('document.tipshow.background.src = \"/img/grey_grad.gif\"');
		
		}
		
		if (eval(parent.document.layers['account']) && eval(parent.document.layers['myjobs']) && eval(parent.document.layers['myapplications']) && eval(parent.document.layers['tipshow']))
		{	
	
			orgheight = document.tipshow.clip.height;
			totalheight = document.account.clip.height + document.jobs.clip.height + document.myjobs.clip.height + document.myapplications.clip.height - 25;
			if (orgheight < totalheight)
			{
				document.tipshow.clip.height = totalheight-80;
			}
			eval('document.tipshow.background.src = \"/img/grey_grad.gif\"');
		}
	
	}
	//no layer
	else
	{
		if (eval("document.all('jobsearch')") && eval("document.all('tipshow')"))
		{	
			obj = eval('tipshow');
			obj.height = getMainHeight('jobsearch');
			tipshowtable.height = getMainHeight('jobsearch')-80;
			
		}
		
		if (eval("document.all('companyprofiles')") && eval("document.all('tipshow')"))
		{	
			obj = eval('tipshow');
			obj.height = getMainHeight('companyprofiles');
			tipshowtable.height = getMainHeight('companyprofiles')-80;
		}
		
		if (eval(document.all['account']) && eval(document.all['myjobs']) && eval(document.all['myapplications']) && eval(document.all['tipshow']))
		{	
			obj = eval('tipshow');
			totalheight = parseInt(getMainHeight('myjobs')) + parseInt(getMainHeight('jobs')) + parseInt(getMainHeight('myapplications')) + 150 + 80;
			
			obj.height = totalheight;
			tipshowtable.height = totalheight - 80;
			
		}
	
	}

}


function WM_checkIn(id) {

/*
WM_checkIn()
Takes the ID of a positioned HTML element and returns an object reference.

Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)

Author: Taylor
Author Email: taylor@wired.com
Author URL: http://www.taylor.org/

Usage: WM_checkIn('id')
*/

  // This function checks for DOM strategy, then 
  // returns an object reference.
  if (document.all) {
    return document.all[id].style;
  } else if(document.layers) {
    return document.layers[id];
  }
}


/*
WM_changeVisibility()
Changes whether a layer is visible or hidden.

Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)

Author: Nadav Savio
Author Email: nadav@wired.com

usage: WM_changeVisibility('targetLayer1',[visible|hidden|toggle],'targetLayer2',[visible|hidden|toggle],...,'targetLayerN',[visible|hidden|toggle])

*/

// set hidden/visible vars for Netscape 4 compatibility
if (document.layers) {
  var hidden = "hide";
  var visible = "show";
} else {
  var hidden = "hidden";
  var visible = "visible";
}
var toggle = "toggle";

function WM_changeVisibility() {

  if (document.layers || document.all) {
    var inc, endInc=arguments.length;
    // run through the args (objects) and set the visibility of each
    for (inc=0; inc<endInc; inc+=2) {
      // get a good object reference
      var daObj = WM_checkIn(arguments[inc]);
      if (arguments[inc+1] == hidden) {
        // hide the object
        daObj.visibility = hidden;
      } else if (arguments[inc+1] == visible) {
        // show the object
        daObj.visibility = visible;
      } else if (arguments[inc+1] == toggle) {
        // toggle the object's visibility
        if (daObj.visibility == visible) {
          daObj.visibility = hidden;
        } else if (daObj.visibility == hidden) {
          daObj.visibility = visible;
        }
      }
    }
  }
}


