var thisNode;
var node;
var advSky;
var thisPage;
var jb_page_name;
var jb_hierarchy;
var jb_application;
var jb_user_type;
var popup = false;
var popupWidth = 0;
var popupHeight = 0;
var brandingUrl;
var brandingKeywords;
var clearBrandingParam;

var popupwin = null;
var first = true ;
var previous_url ;

function setNode(s) {
	node = s;
}

function setThisNode(n) {
	thisNode = n;
}

function setAdvSky(s) {
	advSky = s;
}

function setThisPage(s) {
	thisPage = s;
}

function setJBPageName(s) {
	jb_page_name = s;
}

function setJBHierarchy(s) {
	jb_hierarchy = s;
}

function setJBApplication(s) {
	jb_application = s;
}

function setJBUserType(s) {
	jb_user_type = s;
}

function setIsPopup(bool) {
	popup = bool;
}

function setBrandingUrl(s) {
	brandingUrl = s;
}

function setPopupWidth(w) {
	popupWidth = w;
}

function setPopupHeight(h) {
	popupHeight = h;
}

function setClearBrandingParam(s) {
	clearBrandingParam = s;
}

function setBrandingKeywords(s) {
	brandingKeywords = s;
}

function getThisNode() {
	return thisNode;
}

function getNode() {
	return node;
}

function getAdvSky() {
	return advSky;
}

function getThisPage() {
	return thisPage;
}

function getJBPageName() {
	return jb_page_name;
}

function getJBHierarchy() {
	return jb_hierarchy;
}

function getJBApplication() {
	return jb_application;
}

function getJBUserType() {
	return jb_user_type;
}

function isPopup() {
	return popup;
}

function getBrandingUrl() {
	return brandingUrl;
}

function getPopupWidth() {
	return popupWidth;
}

function getPopupHeight() {
	return popupHeight;
}

function getClearBrandingParam() {
	return clearBrandingParam;
}

function getBrandingKeywords() {
	return brandingKeywords;
}

/**
 * Sets all of the page JS variables.
 * Removes the code from the header. SEO Happy.
 */
function setupPage(thisNode, thisPage) {
	setThisNode(thisNode);
	setNode(thisNode);
	setThisPage(thisPage);

	try {
	  document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}
}
function setupOmniture(pageName, hierarchy, app, userType) {
	setJBPageName(pageName);
	setJBHierarchy(hierarchy);
	setJBApplication(app);
	setJBUserType(userType);
}
function setupBranding(popup, url, width, height, clear, keywords) {
	setIsPopup(popup);
	setBrandingUrl(url);
	setPopupWidth(width);
	setPopupHeight(height);
	setClearBrandingParam(clear);
	setBrandingKeywords(keywords);
}

function brandingPopup() {
	if(isPopup) {
		winId = window.open(getBrandingUrl(),'newwin','width=' + getPopupWidht() + ',height=' + getPopupHeight() + ',status');
		if (!winId.opener) {
			winId.opener = self;
		}
	} else {
		submitSearchBox(document.JobSearchDisplayForm.keyword, getBrandingKeywords());
	}
}

//Called from Popup
function keepBrand() {
	eval('document.JobSearchDisplayForm.' + getClearBrandingParam()).value = false;
	submitSearchBox(document.JobSearchDisplayForm.keyword, getBrandingKeywords());
}

//Called from Popup
function removeBrand() {
	eval('document.JobSearchDisplayForm.' + getClearBrandingParam()).value = true;
	submitSearchBox(document.JobSearchDisplayForm.keyword, getBrandingKeywords());
}

function randomNumber(min, max) {
	return Math.floor(Math.random()*(max - min + 1)) + min;
}

function randomBoolean() {
	var v = randomNumber(0,1);
	if (v == 1) {
		return true;
	}
	return false;
}

function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function 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--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, 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 shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}
	return currentOpac;
}

function fadeOutInObjectGroupChange(id1a, id1b, id2a, id2b, millisec) {
	if (ie) {
		toggleDisplay(id1a);
		toggleDisplay(id2a);
		toggleDisplay(id1b);
		toggleDisplay(id2b);
	} else {
		//speed for each frame
		var speed = Math.round(millisec / 100);
		var timer = 0;
	
		for(i = 100; i >= 0; i--) {
			setTimeout("changeOpac(" + i + ",'" + id1a + "')",(timer * speed));
			setTimeout("changeOpac(" + i + ",'" + id1b + "')",(timer * speed));
			timer++;
		}
		
		setTimeout("toggleDisplay('" + id1a + "')",(timer * speed));
		setTimeout("toggleDisplay('" + id2a + "')",(timer * speed));
		setTimeout("toggleDisplay('" + id1b + "')",(timer * speed));
		setTimeout("toggleDisplay('" + id2b + "')",(timer * speed));
		
		for(i = 0; i <= 100; i++) {
			setTimeout("changeOpac(" + i + ",'" + id2a + "')",(timer * speed));
			setTimeout("changeOpac(" + i + ",'" + id2b + "')",(timer * speed));
			timer++;
		}
	}
}

function fadeOutInInnerHTMLChange(id, html, millisec) {
	if (ie) {
		changeObjectInnerHTML(id,html);
	} else {
		//speed for each frame
		var speed = Math.round(millisec / 100);
		var timer = 0;
	
		for(i = 100; i >= 0; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
		
		setTimeout("changeObjectInnerHTML('" + id + "','" + html + "')",(timer * speed));
		
		for(i = 0; i <= 100; i++) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

function changeObjectInnerHTML(id, html) {
	document.getElementById(id).innerHTML = html;
}

function toggleDisplay(id) {
	var obj = document.getElementById(id);
	if (obj.style.display == 'none') {
		obj.style.display = '';
	} else {
		obj.style.display = 'none';
	}
}

function flexAdHeight(objId) {
	return document.getElementById(objId).offsetHeight;
}

function columnHeightHack() {
	var col1 = document.getElementById('jobsFeatureEvents');
	var col2 = document.getElementById('jobsFeatureCareer');
	var col3 = document.getElementById('jobsFeatureEmployers');
	var col1H = col1.offsetHeight;
	var col2H = col2.offsetHeight;
	var col3H = col3.offsetHeight;
	var size = col1H;
	if (col2H > size) {
		size = col2H;
	}
	if (col3H > size) {
		size = col3H;
	}
	col1.style.height = size + 'px';
	col2.style.height = size + 'px';
	col3.style.height = size + 'px';
}

function winopen(url) {
   if (first) {
	   popupwin = window.open(url, "", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=740,height=595,left=50,top=50");
	   popupwin.focus();
	   first = false ;
   } else {
	   if ( popupwin != null && !popupwin.closed && previous_url == url ) { popupwin.focus(); }
	   else {
		   if (popupwin.closed) {
			   popupwin = window.open(url, "", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=740,height=595,left=50,top=50");
			   popupwin.focus();
		   } else {
			   popupwin.location = url;
			   popupwin.focus();
		   }
	   }           }
   previous_url = url ;
}

//Omniture Object For Purchase Variables
function omniPurchase(jb_products,
                      prop39_flow,
					  prop37_industry,
					  prop38_function,	
					  prop36_location,
					  prop35_career, 
					  prop41_compsize, 
					  evar5_career,
					  evar6_location,
					  evar7_industry,
					  evar8_function, 
					  evar9_flow,
					  evar10_employer,
					  evar11_compsize, 
					  evar12_salesChannel,
					  evar31_coupon,	
					  evar32_jobneworedit) 
{
  //product
      this.jb_products = jb_products;
  //props
      this.prop39_flow = prop39_flow;
	  this.prop37_industry = prop37_industry;
	  this.prop38_function = prop38_function;	
	  this.prop36_location = prop36_location;
	  this.prop35_career = prop35_career; 
	  this.prop41_compsize = prop41_compsize; 
  //evars
	  this.evar5_career = evar5_career;
	  this.evar6_location = evar6_location;
	  this.evar7_industry = evar7_industry;
	  this.evar8_function = evar8_function; 
	  this.evar9_flow = evar9_flow;
	  this.evar10_employer = evar10_employer;
	  this.evar11_compsize = evar11_compsize; 
	  this.evar12_salesChannel = evar12_salesChannel;
	  this.evar31_coupon = evar31_coupon;	
	  this.evar32_jobneworedit = evar32_jobneworedit;
}

// link for viewing all jobs froma particular company
function viewJobs(employerId,ts,newwin) {
   employerId = escape(employerId);
   urlToOpen = "JobSearchServlet?action=search&employerid="+employerId+"&"+ts;

   if(!newwin)
   {
     document.location.href = urlToOpen;
   }
   else
   {
   	 window.opener.location = urlToOpen;
  	 this.close();
   }
}



// Omniture CCSS tracking 
function trackOmnitureCCSS(event,product,pFlow,omniAcct)
{
    //s=s_gi(omniAcct);
    var ccssProduct = ';1007;1;;;';;
   
	s.linkTrackVars='prop35,prop36,prop37,prop38,eVar9,eVar10,eVar12,eVar26,eVar32,events,products';
    s.linkTrackEvents='event18';
	s.events = 'event18';
	s.eVar9=pFlow.evar9_flow;
	s.eVar10=pFlow.evar10_employer;
	s.eVar12=pFlow.evar12_salesChannel;
	s.eVar32=pFlow.evar32_jobneworedit;
	
	if (pFlow.jb_products != "") {
 	  s.products = pFlow.jb_products + ',' + ccssProduct;
 	}else{  
      s.products = ccssProduct;
      s.eVar26 = 'Newpaper';
      s.events += ',scOpen,prodview';
    }

	if (product == 'Combo') {
		s.prop35=prop35_career; 
		s.prop36=prop36_location;
		s.prop37=prop37_industry;
		s.prop38=prop38_function;	
 	}
 
	s.tl(event,'o','CCSS');
}
