﻿serverLoc = "";
myLoc = document.URL;
print_array = myLoc.split("print=true");
isPrint = (print_array[1] != null )?true:false;
myLoc_array = myLoc.split("/");
myServer_array = myLoc_array[2].split(".");
if(myServer_array[0].substring(myServer_array[0].length-3, myServer_array[0].length)=="imp"){
	serverLoc = "imp";
}else if (myLoc_array[2]=="localhost:50007"){
    serverLoc = "imp";
}else {
	serverLoc = "";
}

var strAccounting       =   'http://accounting'+serverLoc+'.paychex.com/';
var strLargebusiness    =   'http://largebusiness'+serverLoc+'.paychex.com/';
var strSmallbusiness    =   'http://smallbusiness'+serverLoc+'.paychex.com/';
var strPeo              =   'http://peo'+serverLoc+'.paychex.com/';
var strPremier          =   'http://premier'+serverLoc+'.paychex.com/';
var strResources        =   'http://resources'+serverLoc+'.paychex.com/';
var strServices         =   'http://services'+serverLoc+'.paychex.com/';
var strPaychex          =   'http://www'+serverLoc+'.paychex.com/';
var strInvestor         =   'http://investor'+serverLoc+'.paychex.com/';
var strSecurePaychex    =   'https://www'+serverLoc+'.paychex.com/';
var strPath             =   'http://www'+serverLoc+'.paychex.com/';
var imagePath           =   'http://www'+serverLoc+'.paychex.com/images/';


//javascript search
function displaysearch() {
    var searchbox = document.getElementById('searchText');
	searchbox.style.display = (searchbox.style.display == 'none' || searchbox.style.display == '') ? 'block' : 'none';
	return false;
}

function validsearch() {
    mysearch = document.getElementById("qt").value;
    if (mysearch.toLowerCase() != "enter search" && mysearch.length > 2) {
        if (serverLoc == ""){
            document.location = "http://search.paychex.com/query.html?col=www&qt=" + mysearch.toLowerCase() + "&charset=iso-8859-1";
        }else{
            document.location = "http://searchimp.paychex.com/query.html?col=wwwimp&qt=" + mysearch.toLowerCase() + "&charset=iso-8859-1";
        }
        return false;
    } else {
        alert("Please enter a search term.");
        return false;
    }
}

// sets height of flash menu layer 
function setHighDepth() {
    document.getElementById("mainNav").style.height = '240px';  
}

function setLowDepth() {
    document.getElementById("mainNav").style.height = '24px'; 
}
//collapses extra space after flash content
function setFlashHeight(myID,myHeight) {
    document.getElementById(myID).style.height = myHeight+'px';    
}

function displayAnswer(divID)
{
	if (divID!='answer1') document.getElementById('answer1').style.display = 'none';
	if (divID!='answer2') document.getElementById('answer2').style.display = 'none';
		
	var leftbox = document.getElementById(divID);
	leftbox.style.display = (leftbox.style.display != 'block') ? 'block' : 'none';
	
	return false;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
}



function MM_reloadPage(init) {  //reloads the window if Nav4 resized
    if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
        document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
    else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_jumpMenu(targ,selObj,restore,win){ //v3.0jv
    if(selObj.options[selObj.selectedIndex].value!="") {  
        if(win=="_blank"){
            window.open(selObj.options[selObj.selectedIndex].value);
           if (restore) selObj.selectedIndex=0;
        }else{
           eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
           if (restore) selObj.selectedIndex=0;
        }
    }
}
function GoForLogin(el)
{
    var SIndex = document.getElementById(el).options.selectedIndex;
    var GoFor = document.getElementById(el).options[SIndex].value;
		var GoForClass = document.getElementById(el).options[SIndex].className;
    if(GoFor=="") {
        alert("Please make a selection.");
    } else if (GoFor=="location_alert") {
			 alert("There are currently no opportunities in this location. Please make another selection.");
		} else if (GoForClass=="local") {
			document.location = GoFor;
		} else {
        window.open(GoFor);        
    }
}

/*------------- for each individual link ------------------*/
function expandlinks(clicked) {
	//find the answer content
	elem = clicked.parentNode.nextSibling;
	while(elem.innerHTML == null){
		elem = elem.nextSibling;
	}
	//toggle it
	if(elem.className=='on'){
		elem.className='off';
		clicked.parentNode.className='off';
	}else{
		elem.className='on';
		clicked.parentNode.className='on';
	}
	//find the bluebox id
	thisSection=clicked.parentNode.parentNode;
	
	//check for box with multiple expand
	if(clicked.parentNode.nodeName=="H1"){
	    //cycle through whitespace to the div after <h1> tag
	    innerhideShow=clicked.parentNode.nextSibling;
	    while(innerhideShow.innerHTML == null){ innerhideShow = innerhideShow.nextSibling; }
	    //cycle through whitespace to find div (.child) 
	    innerhideShow = innerhideShow.firstChild;
	    while(innerhideShow.innerHTML == null){ innerhideShow = innerhideShow.nextSibling; }
	    //cycle through whitespace to find div (.right) 
	    innerhideShow = innerhideShow.firstChild;
	    while(innerhideShow.innerHTML == null){ innerhideShow = innerhideShow.nextSibling; }
	    //cycle through whitespace to the <a> tag 
	    innerhideShow = innerhideShow.firstChild;
	    while(innerhideShow.innerHTML == null){ innerhideShow = innerhideShow.nextSibling; }
	    //send <a> tag node information to the expandall function
	    expandall(innerhideShow,true);
	}
	
	//find parent div (.boxtop)
	hideShow=clicked.parentNode.parentNode.previousSibling;
	while(hideShow.innerHTML == null){ hideShow = hideShow.previousSibling; }
    if(hideShow.className=="child"){
        //cycle through whitespace to the div (.right)
        hideShow=hideShow.firstChild;
        while(hideShow.innerHTML == null){ hideShow = hideShow.nextSibling; }
	    rightDiv = hideShow;
	    //cycle through whitespace to the <a> tag
	    hideShow=hideShow.firstChild;
	    while(hideShow.innerHTML == null){ hideShow = hideShow.nextSibling; }
    } else {
	    //cycle through whitespace to the h1
	    hideShow=hideShow.firstChild;
	    while(hideShow.innerHTML == null){ hideShow = hideShow.nextSibling; }
	    //cycle through whitespace to the div (.right)
	    hideShow = hideShow.nextSibling;	
	    while(hideShow.innerHTML == null){ hideShow = hideShow.nextSibling; }
	    rightDiv = hideShow;
	    //cycle through whitespace to the <a> tag
	    hideShow=hideShow.firstChild;
	    while(hideShow.innerHTML == null){ hideShow = hideShow.nextSibling; }
	}
	
	//keep track of open tabs
	var opencounter =0;
	//find all divs in selected section
	var divs=thisSection.getElementsByTagName('div');
	//cycle through and find all open subjects
	
	for (var i = 0, j = divs.length; i < j; i++) {
	    if (divs[i].className == "on"){			
		    opencounter++;	
		}						
	}
	//if every subject is open, option to hide all
	if (opencounter == divs.length){
		hideShow.innerHTML="";
		hideShow.innerHTML="Hide All";
		rightDiv.className = "righton"
	}else{
		//otherwise option to show all.
		hideShow.innerHTML="";
		hideShow.innerHTML="Show All";
		rightDiv.className = "rightoff"
	}
	
}

/*------- for the hide all  / show all btns -----------------*/
function expandall (clicked,hasChild) {

    section = clicked.parentNode.parentNode.nextSibling;
    rightDiv = clicked.parentNode;
	while(section.innerHTML == null){
		section = section.nextSibling;
	}
	var h1s=section.getElementsByTagName('h1');
	
	//checks to see if it's a multiple expandable box and handles primary links if it is
	if(h1s.length > 0){
	    if(clicked.innerHTML=="Hide All"){
		    //supposedly fixes MAC IE5 bug
		    clicked.innerHTML="";
		    clicked.innerHTML="Show All";
		    rightDiv.className = 'rightoff';
		    //cycle through and close open tabs
		    for (var i = 0, j = h1s.length; i < j; i++) {
                if(h1s[i].className == "on"){
                    h1s[i].className = 'off';
                    h2s = h1s[i].nextSibling;
                    while(h2s.innerHTML == null){ h2s = h2s.nextSibling; }
                    h2s.className = 'off';
                }
            }	
        } else{
		    //otherwise open all tabs
		    clicked.innerHTML="";
		    clicked.innerHTML="Hide All";
		    rightDiv.className = 'righton';
		    /////
		    for (var i = 0, j = h1s.length; i < j; i++) {
                if(h1s[i].className == "off"){
                    h1s[i].className = 'on';
                    h2s = h1s[i].nextSibling;
                    while(h2s.innerHTML == null){ h2s = h2s.nextSibling; }
                    h2s.className = 'on';
                    
                    //find inner show alls
                    innerrigthDiv = h2s.firstChild;
                    while(innerrigthDiv.innerHTML == null){ innerrigthDiv = innerrigthDiv.nextSibling; }
                    innerrigthDiv = innerrigthDiv.firstChild;
                    while(innerrigthDiv.innerHTML == null){ innerrigthDiv = innerrigthDiv.nextSibling; }
                    innerrigthDiv = innerrigthDiv.firstChild;
                    while(innerrigthDiv.innerHTML == null){ innerrigthDiv = innerrigthDiv.nextSibling; }
                    //run second function to reset the secondary expandable links   
                    expandall_private(innerrigthDiv,true);
                }
            }
	    }
	//else if it's a standard expandable box, a second function is run
	} else {	
	    expandall_private(clicked,hasChild);
    }
}

function expandall_private (clicked,hasChild) {

    section = clicked.parentNode.parentNode.nextSibling;
    rightDiv = clicked.parentNode;
	while(section.innerHTML == null){
		section = section.nextSibling;
	}
	var divs=section.getElementsByTagName('div');
	var h2s=section.getElementsByTagName('h2');

    if(clicked.innerHTML=="Hide All" || hasChild){
        //supposedly fixes MAC IE5 bug
        clicked.innerHTML="";
        clicked.innerHTML="Show All";
        rightDiv.className = 'rightoff';
        //cycle through and close open tabs
        for (var i = 0, j = divs.length; i < j; i++) {
            if(divs[i].className == "on"){
                divs[i].className = 'off';
                h2s[i].className = 'off';
            }
        }	
    } else{
        //otherwise open all tabs
        clicked.innerHTML="";
        clicked.innerHTML="Hide All";
        rightDiv.className = 'righton';
        /////
        for (var i = 0, j = divs.length; i < j; i++) {
            if(divs[i].className == "off"){
                divs[i].className = 'on';
                h2s[i].className= 'on';
            }
        }
    }
}

var safeList=["paychex","smallbizpayroll","benetrac","advantagepayroll","stromberg","taleo","tekgroup","webex","surveymonkey","shareholder"];

function initLinks() {
  for (i in document.links) {
    link = document.links[i];
    if (link.rel && link.rel.indexOf('external')!=-1) {
      link.onclick = onExternalLinkActivate;
      link.onkeypress = onExternalLinkActivate;
    }
  }
}

function onExternalLinkActivate() {
	externalServer = this.href.split("/");
	externalServer = externalServer[2].split(".");
	for(w in safeList){
		if(externalServer[1]==safeList[w]){
			isSafe=true;
			break;
		} else {
			isSafe=false;
		}
	}
	if(isSafe){
  	window.open(this.href);
	}else{
		window.open(this.href);
		noWarningArray = document.cookie.split('noWarning');
		if(noWarningArray.length <= 1){
			warningWin = window.open(strPaychex+'popups/warning.aspx','warning','width=384,height=205'); warningWin.focus();
		}
	}
  return false;
}


//home page scripts

// center section controls
function showLearn(clicked,display){
    if(display=="show"){
        elem = clicked.parentNode.nextSibling;
	    while(elem.innerHTML == null){ elem = elem.nextSibling; }
	    elem.className='on';
	} else if (display=="hide"){
	    elem = clicked.parentNode.parentNode;
	    elem.className='off';
	} else if (display=="swap"){
	    elem = clicked.previousSibling;
	    while(elem.innerHTML == null){ elem = elem.previousSibling; }
	    if(elem.className=='on') { elem.className='off'; }
	    section = elem.parentNode;
	    var sectionNum = section.id.split("_");
	    sectionNum = sectionNum[1];
	    if (document.getElementById("trcontent_"+sectionNum).style.display!="none"){
	    	document.getElementById("link_"+sectionNum).style.display = "block";		
	        document.getElementById("trcontent_"+sectionNum).style.display = "none";   
	    } else {
	        document.getElementById("trcontent_"+sectionNum).style.display = "block";
		    document.getElementById("link_"+sectionNum).style.display = "none";
	    }
	}
}

function rssInit(){
    counter=0;
    for(z=0;z<rssItems;z++){
        document.getElementById("newsitem"+z).style.display = 'none';
    }
    document.getElementById("newsitem"+counter).style.display = '';
    TimeoutID = setTimeout("runTicker()",5000);
}

//end home page scripts

//set again for external sites
var hasRightVersion;
var version = swfobject.getFlashPlayerVersion();
if(hasRightVersion==null){  
    hasRightVersion = (document.getElementById && (version.major >= 6)) ? true : false;
    nonmodernBrowser = false;
}

var addOnload = new Array();
window.onload = function(){
    if(!hasRightVersion && !isPrint && !nonmodernBrowser){
        setNav();
    }
    if(addOnload.length>0) {
        for (m=0; m<addOnload.length; m++){
            eval(addOnload[m]);
        }
    }
    initLinks();
}


//tool tips
var docX, docY;
var moveme=false;
var elem;
var origX, origY;
var pageW;
var overFlow;

function moveTip(e){
    if(moveme){
        if(e) {
            if( typeof( e.pageX ) == 'number' ) {
                docX = e.pageX;
                docY = e.pageY;
            } else {
                docX = e.clientX;
                docY = e.clientY;
            }
        } else {
            e = window.event;
            docX = e.clientX;
            docY = e.clientY;
            if( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) ) {
                docX += document.documentElement.scrollLeft;
                docY += document.documentElement.scrollTop;
            } else if( document.body && ( document.body.scrollTop || document.body.scrollLeft ) ) {
                docX += document.body.scrollLeft;
                docY += document.body.scrollTop;
            }
        }
        overFlow = (docX+elem.offsetWidth+10 > document.body.clientWidth) ? docX+elem.offsetWidth-document.body.clientWidth+10 : 0; //extra ten for the width of scrollbars if present
        docX = docX-offX+10-overFlow;
        docY = docY-offY+10;
        elem.style.left = docX+'px';
        elem.style.top = docY+'px';
        elem.style.visibility = 'visible';
    }
}
function tip(clicked) {
    document.onmousemove = moveTip;
	//find the answer content
	elem = clicked.parentNode.nextSibling;
	while(elem.innerHTML == null){
		elem = elem.nextSibling;
	}
	//toggle it
	if(elem.className=='tipon'){
		elem.className='tipoff';
		elem.style.left = '0px';
		elem.style.top = '0px';
		moveme=false;
		elem.style.visibility = 'hidden';
	}else{
	    elem.style.visibility = 'hidden'; //prevent flicker in IE
		elem.className='tipon';
		myPos = findPos(elem);
		offX = myPos[0];
		offY = myPos[1];
		moveme = true;
	} 
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
	    do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
        return [curleft,curtop];
    }
}
function blankField (input) {
    input.value = "";
    return true;
}
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
    var keyCode = (isNN) ? e.which : e.keyCode; 
    var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
    if(input.value.length >= len && !containsElement(filter,keyCode)) {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input)+1) % input.form.length].focus();
    }
function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
        if(arr[index] == ele)
            found = true;
        else
            index++;
    return found;
}
function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
        if (input.form[i] == input)index = i;
        else i++;
    return index;
}
return true;
}


//media center functions
function newsSearch(){
	if (document.getElementById('keywords').value == '') {
		alert("Please enter a keyword.");
		return false;
	}else{
		document.getElementById('aspnetForm').action = 'http://media.paychex.com/search_results.cfm';
    document.getElementById('aspnetForm').method = 'post';
    document.getElementById('aspnetForm').submit();
		return false;
	}
}
function newsLogin(){
	if (document.getElementById('login_id').value == '' || document.getElementById('site_pass').value == '') {
		if(document.getElementById('login_id').value == ''){alert("Please enter your username.");}
		if(document.getElementById('site_pass').value == ''){alert("Please enter your password.");}
		return false;
	}else{
		document.getElementById('aspnetForm').action = 'http://media.paychex.com/login.cfm';
    document.getElementById('aspnetForm').method = 'post';
    document.getElementById('aspnetForm').submit();
		return false;
	}
}

try { document.execCommand('BackgroundImageCache', false, true); }
catch(e) {}
