/* Copyright 2000-2005, Intuit Inc.  All rights reserved. 
This material contains proprietary information of Intuit Inc. 
Use, reproduction or distribution without express written permission of an 
authorized representative of Intuit Inc. is prohibited. */

////////////////////////////////////////////////////////////////////////////////
// Utility functions
////////////////////////////////////////////////////////////////////////////////
/* MM_swapImgRestore() - to be used to load hover images in menu back to normal state */
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
/* MM_preloadImages() - to be used to preload mouseover images for the top navigation */
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];}}
}
/* MM_findObj(n, d) - used by the swap function utilities */
function MM_findObj(n, d) { //v3.0
  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); return x;
}
/* MM_swapImage() - to be used to load hover images in menu */
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/* LoadVarSizedWin - creates a window with specified height and width. If there is an existing window opened using this function, the new URL called will be opened on the same window */	
function LoadVarSizedWin(vURL, vwidth, vheight){
	try {
		var win_newwin=null;	
		if (window.screen.availHeight && (vURL.indexOf('screen_contact_us.cfm') != -1 || vURL.indexOf('custhelp.com',vURL) != -1 || vURL.indexOf('answers.cfm') != -1 )) {
			if (window.screen.availHeight > vheight) {
				var height_attr=",height=" + window.screen.availHeight + "'";
			} else {
				var height_attr=",height=" + vheight + "'";
			}
		} else {
			var height_attr=",height=" + vheight + "'";
		}
		if (!win_newwin) {
			 win_newwin=window.open(vURL, 'win_newwin', 'width=' + vwidth+  height_attr+ ',status=yes,resizable=yes,scrollbars=yes,top=0,left=0')
			//win_newwin=window.open(vURL, 'win_newwin', 'width=' + vwidth+ ',height=' + vheight+ ',status=yes,resizable=yes,scrollbars=yes');
		}
		win_newwin.focus();	
    } catch (e) {}
}

/* LoadVarSizedWinNew - creates a window with specified height and width. If there is an existing window opened using this function, the new URL called will be opened on a new window */	
function LoadVarSizedWinNew(vURL, vwin_newwin, vwidth, vheight){
	try {
		width=vwidth;
        height=vheight;
		var left=Math.floor(screen.width/2 - width/2);
        var top=Math.floor(screen.height/2 - height/2);	
		vwin_newwin=window.open(vURL, vwin_newwin, 'width=' + vwidth+ ',height=' + vheight+ ',status=yes,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no,left=' + left + ',top=' + top);
		vwin_newwin.focus();		
	} catch (e) {}
}	

/* LoadNewVarSizedWin - creates a NEW window with specified height and width with tool, url and menu bars */
function LoadNewVarSizedWin(vURL, vwindowname, vwidth, vheight){
	try {
		vwindowname=window.open(vURL, vwindowname, 'width=' + vwidth+ ',height=' + vheight+ ',status=yes,resizable=yes,scrollbars=yes,toolbar=yes,location=yes,menubar=yes');
		vwindowname.focus();		
	} catch (e) {}
}			

function LoadSupportWin(call_type){
	try {
		var win_support; 
		win_support=window.open('https://'+ document.ugt_server_var + "/"+ call_type, 'win_support', 'height=450,width=662,status=no,resizable=yes,scrollbars=yes');
		win_support.focus();
	} catch (e) {}
}		

function LoadModalWindow(url, vheight, vwidth){
	try {
		var windowTop=new Array();
		windowTop.opener=top;					
		window.showModalDialog(url, windowTop, 'dialogHeight:' + vheight+ 'px;dialogWidth:' + vwidth+ 'px;center:yes; help:no; status:no; resizable:no;');
	} catch (e) {}
}		

function getElementPosition(elemID) {
	
   var offsetTrail=document.getElementById(elemID);
   var offsetLeft=0;
   var offsetTop=0;
   
   // loop to the top    
   while (offsetTrail) {
       offsetLeft += offsetTrail.offsetLeft;
       offsetTop += offsetTrail.offsetTop;
       offsetTrail=offsetTrail.offsetParent;
   }
   
   if (navigator.userAgent.indexOf("Mac") != -1 && 
       typeof document.body.leftMargin != "undefined") {
       offsetLeft += document.body.leftMargin;
       offsetTop += document.body.topMargin;
   }
   return {left:offsetLeft, top:offsetTop};
}

////////////////////////////////////////////////////////////////////////////////
// Application functions
////////////////////////////////////////////////////////////////////////////////


function hidePopupAnswer(divID) {
	
	objDiv=document.getElementById(divID); 	
	objDiv.style.display="none"; 	
	
	var shadow=document.getElementById('popupshadow');
	var pointer=document.getElementById('pointer');
	var pointerImg=document.getElementById('pointerImg');
	var pointerShadow=document.getElementById('pointerShadow');
	
	shadow.style.display="none";
	pointer.style.display="none";
	pointerShadow.style.display="none";
	
}

///////////////////////////////////////////
// new popup 2/9/2006 mstraka  
////////////////////////////////////////
function showPopupAnswer(divID, hrefID, setWidth){
	// close all other answers popups 
	var collDiv=document.getElementsByTagName("DIV"); 
	var strID=new String(); 
	
	for (i=0; i < collDiv.length; i++) {		
		if (typeof collDiv[i].id != "undefined") {
			strID=collDiv[i].id; 
		}
		else {
			strID=""; 
		}		
		if ((strID.indexOf("ans") != -1) && (typeof collDiv[i].style.display != "undefined") && (collDiv[i].style.display == "block")) {
			collDiv[i].style.display="none";
		} 
	}
	//get elements.
	var shadow=document.getElementById('popupshadow');
	var pointer=document.getElementById('pointer');
	var pointerImg=document.getElementById('pointerImg');
	var pointerShadow=document.getElementById('pointerShadow');

	thelink=document.getElementById(hrefID);
	popupBox=document.getElementById(divID); 
	
	//width is an optional argument
	if(setWidth){
	 popupBox.style.width=setWidth+'px';
	}
	else {
	 popupBox.style.width='210px';
	}
	
	//adjust shadow location for Firefox 
	var IE=document.all?true:false;
	var fireFoxAdj=0;
	if(!IE){ fireFoxAdj=5; }
	
	if(popupBox.style.display == "block"){
		popupBox.style.display="none";
		shadow.style.display="none";
		pointer.style.display="none";
		pointerShadow.style.display="none";
	}
	else {
	//first size the shadow
		popupBox.style.display="block";
		shadow.style.display="block";
		pointer.style.display="block";
		pointerShadow.style.display="block";
	
		var popup_wdth=popupBox.clientWidth;
		var popup_ht=popupBox.clientHeight;
		
		shadow.style.width=eval(popup_wdth + 14)+'px';
		shadow.style.height=eval(popup_ht + 14)+'px';

		var linkPos=new Object(); 
		linkPos=getElementPosition(hrefID);
		
		//var link_tp=thelink.offsetTop;
		var link_tp=linkPos.top;
		//var link_lft=thelink.offsetLeft;
		var link_lft=linkPos.left;
		var link_wdth=thelink.offsetWidth;
		
		var pointer_wdth=pointerImg.width;
		//setting the left edge of the popup
		var setLeft=link_lft + link_wdth + pointer_wdth - 9;

		var body_wdth=document.body.clientWidth;
		var body_ht=document.body.clientHeight;
		var pointing='left'; //be default the popup is to the right of the link, pointing left
		var pointVert='up';  //by defautl the popup arrow is pointing up
		
		//switch popup to the left if link is too close to right edge of page 
		//OR if it is too close to the left		
		
		//originally 				
		// if((500 < (setLeft + popup_wdth + pointer_wdth + 4)) && (link_lft > 280)){
		if(setLeft > 500){
			
			pointing='right';
			if ((link_lft - popup_wdth - pointer_wdth - 180) < 0){
				setLeft=link_lft; 	 
			} else {
				setLeft=link_lft - popup_wdth - pointer_wdth - 180;			
			}
			
		} else { 
			pointing='left';
			setLeft=link_lft;
		}
		var halfHeight=popup_ht/2;
		var halfHeight=Math.round(halfHeight);
		
		var setTop=link_tp - halfHeight;
		if ((setTop + popup_ht) > body_ht){
				setTop=link_tp - popup_ht + 10;//keep popup bottom above the bottom of the frame
				pointVert='down'; //since we are at the bottom edge of the frame, point the arrow down to the link
		}
		//keep popup top below the top of the frame
		if (setTop < 205) {
			setTop=205; 
			link_tp=305;		
		}		
		var setLeftShad=setLeft-7;
		var setTopShad=setTop-7;
		
		popupBox.style.left=setLeft+'px';
		popupBox.style.top=setTop+'px';
		shadow.style.left=setLeftShad+fireFoxAdj+'px';
		shadow.style.top=setTopShad + fireFoxAdj+'px';

		//position pointer 
		// var pointer_top=link_tp+7;
		var pointer_top=link_tp+7;
		var pointer_left;
		var pointer_shadow_left_offset=-7;
		var pointer_shadow_top_offset=-7;;
		if (pointing == 'right'){
			if(pointVert == 'up'){
				pointer_left=setLeft + popup_wdth -1; //left edge of popup + width of popup -1;
				pointerImg.src="/images/_bb/popup_rt_wedge_up_white.gif";
				pointerShadow.src="/images/_bb/popup_rt_wedge_up_black.gif";
				pointer_shadow_left_offset=-5;
				pointer_shadow_top_offset=-5;
			}
			else {//right down
				pointer_left=setLeft + popup_wdth -1; //left edge of popup + width of popup -1;
				pointerImg.src="/images/_bb/popup_rt_wedge_down_white.gif";
				pointerShadow.src="/images/_bb/popup_rt_wedge_down_black.gif";
				pointer_top=link_tp - pointerImg.height;
				pointer_shadow_left_offset=-11;
				pointer_shadow_top_offset=-26;
			}
		}
		else { //pointing left
			if(pointVert == 'up'){
				pointer_left=setLeft - pointer_wdth + 1; //left edge of poput - width of image + 1
				pointerImg.src="/images/_bb/popup_lft_wedge_up_white.gif";
				pointerShadow.src="/images/_bb/popup_lft_wedge_up_black.gif";
				pointer_shadow_left_offset=-6;
				pointer_shadow_top_offset=-5;
			}
			else { //left down
				pointer_left=setLeft - pointer_wdth + 1; //left edge of poput - width of image + 1
				pointerImg.src="/images/_bb/popup_lft_wedge_down_white.gif";
				pointerShadow.src="/images/_bb/popup_lft_wedge_down_black.gif";
				pointer_top=link_tp - pointerImg.height;
				pointer_shadow_left_offset=-15;
				pointer_shadow_top_offset=-25;
			}
		}
		pointer.style.left=pointer_left+'px';
		pointer.style.top=pointer_top+'px';		
		pointerShadow.style.left=eval(pointer_left + pointer_shadow_left_offset + fireFoxAdj)+'px';
		pointerShadow.style.top=eval(pointer_top + pointer_shadow_top_offset + fireFoxAdj)+'px';
		pointerShadow.style.width=eval(pointerImg.width + 16) + 'px';
		pointerShadow.style.height=eval(pointerImg.height + 28) + 'px';
	}
}


///////////////////////////////////////////
// grey popup 
////////////////////////////////////////
function hideGreyPopupAnswer(divID) {
    
    objDiv=document.getElementById(divID);
    if(objDiv !=null && objDiv!='undefined') {
    	objDiv.style.display="none";  
    }
    
}
var popupWindowDivID = null;
///////////////////////////////////////////
// new popup 2/9/2006 mstraka  
////////////////////////////////////////
function showGreyPopupAnswer(divID, hrefID, setWidth){
	hideGreyPopupAnswer(popupWindowDivID);
    // close all other answers popups 
    var collDiv=document.getElementsByTagName("DIV"); 
    var strID=new String(); 
    
    for (i=0; i < collDiv.length; i++) {        
        if (typeof collDiv[i].id != "undefined") {
            strID=collDiv[i].id; 
        }
        else {
            strID=""; 
        }       
        if ((strID.indexOf("ans") != -1) && (typeof collDiv[i].style.display != "undefined") && (collDiv[i].style.display == "block")) {
            collDiv[i].style.display="none";
        } 
    }
    thelink=document.getElementById(hrefID);
    popupBox=document.getElementById(divID); 
    popupWindowDivID = divID;
    //width is an optional argument
    if(setWidth){
     popupBox.style.width=setWidth+'px';
    }
    else {
     popupBox.style.width='210px';
    }
    
    //adjust shadow location for Firefox 
    var IE=document.all?true:false;
    var fireFoxAdj=0;
    if(!IE){ fireFoxAdj=5; }
    
    if(popupBox.style.display == "block"){
        popupBox.style.display="none";
    }
    else {
    //first size the shadow
        popupBox.style.display="block";
    
        var popup_wdth=popupBox.clientWidth;
        var popup_ht=popupBox.clientHeight;

        var linkPos=new Object(); 
        linkPos=getElementPosition(hrefID);
        
        //var link_tp=thelink.offsetTop;
        var link_tp=linkPos.top;
        //var link_lft=thelink.offsetLeft;
        var link_lft=linkPos.left;
        var link_wdth=thelink.offsetWidth;
        
        //setting the left edge of the popup
        var setLeft=link_lft + link_wdth + 20;

        var body_wdth=document.body.clientWidth;
        var body_ht=document.body.clientHeight;
        
        //switch popup to the left if link is too close to right edge of page 
        //OR if it is too close to the left     
        
        //originally                
        // if((500 < (setLeft + popup_wdth + pointer_wdth + 4)) && (link_lft > 280)){
		// alert(setLeft);
		 
		//check if popup should be positioned to the left of the link
		if(((setLeft + popup_wdth > body_wdth) && (link_lft - popup_wdth > 100)) //if popup is off screen (requiring side scroll)
				|| ((setLeft + popup_wdth > 1220) && (body_wdth > 1200 && body_wdth <= 1400)) //if screen is wide
				|| ((setLeft + popup_wdth > 1320) && (body_wdth > 1400 && body_wdth <= 1600)) //if screen is wider
				|| ((setLeft + popup_wdth > 1400) && (body_wdth > 1600))) //if screen is really wide
		{  
			setLeft=link_lft - popup_wdth;
        }
		// alert(setLeft);
        var halfHeight=popup_ht/2;
        var halfHeight=Math.round(halfHeight);
        
        var setTop=link_tp - halfHeight;
        if ((setTop + popup_ht) > body_ht){
                setTop=link_tp - popup_ht + 10;//keep popup bottom above the bottom of the frame
                pointVert='down'; //since we are at the bottom edge of the frame, point the arrow down to the link
        }
        //keep popup top below the top of the frame
        if (setTop < 205) {
            setTop=205; 
            link_tp=305;      
        }       
        
        popupBox.style.left=setLeft+'px';
        popupBox.style.top=setTop+'px';
    }
}

///////////////////////////////////////////
// showInterrupt - used in the payroll bundle popup. hide shadows and pointers
////////////////////////////////////////
function showInterrupt(divID, hrefID){
	// close all other answers popups 
	var collDiv=document.getElementsByTagName("DIV"); 
	var strID=new String(); 
	
	for (i=0; i < collDiv.length; i++) {		
		if (typeof collDiv[i].id != "undefined") {
			strID=collDiv[i].id; 
		}
		else {
			strID=""; 
		}		
		if ((strID.indexOf("ans") != -1) && (typeof collDiv[i].style.display != "undefined") && (collDiv[i].style.display == "block")) {
			collDiv[i].style.display="none";
		} 
	}
	//get elements.
	// thelink=document.getElementById(hrefID);
	popupBox=document.getElementById(divID); 	

	//adjust shadow location for Firefox 
	// var IE=document.all?true:false;
	// var fireFoxAdj=0;
	// if(!IE){ fireFoxAdj=5; }
	
	if(popupBox.style.display == "block"){
		popupBox.style.display="none";
	}
	else {	
		popupBox.style.display="block";
	} 
}

///////////////////////////////////////////
// hideInterrupt - used in the payroll bundle popup. hide shadows and pointers
////////////////////////////////////////
function hideInterrupt(divID) {	
	objDiv=document.getElementById(divID); 	
	objDiv.style.display="none"; 	
}

///////////////////////////////////////////
// showFAQ - used to set visibility and link colors on FAQ
////////////////////////////////////////
function showFAQ(quesID,divID) {

    // check if we're just closing it
    closeFlag=false;

    // close all other FAQ popups 
    var collDiv=document.getElementsByTagName("DIV"); 
    var strID=new String(); 
	// alert(collDiv.length + collDiv[40].id);
    
    for (i=0; i < collDiv.length; i++) {        
        if (typeof collDiv[i].id != "undefined") {
            strID=collDiv[i].id; 
        }
        else {
            strID=""; 
        }       
        if ((strID.indexOf("faq") != -1) && (typeof collDiv[i].style.display != "undefined") && (collDiv[i].style.display == "block")) {
            collDiv[i].style.display="none";
            // if the quesID/divID combination is the same as the active combo, then it's a CLOSE function, and we'll skip the last two steps
            if (collDiv[i].id == divID)
            {
              document.getElementById(quesID).firstChild.src="/images/plus.png";
              closeFlag=true;
            }
        } 
    }

    // re-color all other FAQ questions
    var collAnchor=document.getElementsByTagName("IMG"); 
    var strID=new String(); 
    
    for (i=0; i < collAnchor.length; i++) {        
        if (typeof collAnchor[i].id != "undefined") {
            strID=collAnchor[i].id; 
        }
        else {
            strID=""; 	
        }       
         if (strID.indexOf("qImage") != -1) {
            collAnchor[i].src="/images/plus.png";
        } 
    }
    
    if (!closeFlag)
    {
      //document.getElementById(quesID).style.color="#666666";
      document.getElementById(divID).style.display="block";
      document.getElementById(quesID).firstChild.src="/images/minus.png";
    }   
}
function AutoResizeWindow(){
	try {
		if (window.parent.resize_iframe != null) {
			window.parent.resize_iframe();
		}	
	} catch (ignored) {}
}
///////////////////////////////////////////
//toggleFAQ - used to set visibility and link colors on FAQ
////////////////////////////////////////
function toggleFAQ(questionID, answerID) {

	var answer = document.getElementById(answerID);
	var question = document.getElementById(questionID);
	
	if (answer.style.display == 'none')
	{
		answer.style.display = 'block';
		question.src="/images/minus.png";
	}
	else
	{
		answer.style.display = 'none';
		question.src="/images/plus.png";
	}
}

