// centralized common file for commonly-used Javascript routines
// combining multiple .js files into one should reduce load on server and improves page load time
// created May '08 - ss

// Here are the setup parameters
// General parameters -- for top navigation
// Paths should be relative to top of site file structure -- this is automatically adjusted at generation time.
var menuBarHeight=20;
var rowHeight=18;
var dropShadow=4;
var dropShadowPopup=8;
var shrinkPopupToWindow=true;  // forces popup to be only as tall as the window despite height parameter

// 1. Solutions menu
var solutions_width=150;
var solutions_menuitems=new Array('Product Overview','Savicom Pro','Savicom CampaignPlus',
	'Savicom Publisher','Savicom DASH','Solutions FAQ');
var solutions_urls=new Array('solutions/index.html','solutions/savimail.html','solutions/campaignplus.html',
	'solutions/publisher.html','solutions/dash.html','solutions/solutions_faq.html');

// 2. Features menu
var features_width=150;
var features_menuitems=new Array('Basic Features',
	'Message Composition','Campaign Automation',
	'Integration Interface','Reporting',
	'Response Optimization','Multiuser Support',
	'Private Network','Security &amp; Support');
var features_urls=new Array('features/index.html?category=basic',
	'features/index.html?category=composition','features/index.html?category=automation',
	'features/index.html?category=integration','features/index.html?category=reporting',
	'features/index.html?category=optimization','features/index.html?category=multiuser',
	'features/index.html?category=private_network','features/index.html?category=support')

// 3. About Us menu
var aboutus_width=130;
var aboutus_menuitems=new Array('Savicom Overview','Customers','Our Team','Job Openings');
var aboutus_urls=new Array('aboutus/overview.html','aboutus/customers.html','aboutus/ourteam.html','aboutus/jobs.html');

// 4. Partners menu
var partners_width=130;
var partners_menuitems=new Array('Affiliate Program','Linking Partners','Marketing Partners');
var partners_urls=new Array('partners/affiliate.html','partners/linking.html','partners/marketingpartners.html');

// 5. Policies menu
var policies_width=150;
var policies_menuitems=new Array('Delivery Assurance','Acceptable Use Policy',
	'Privacy Policy','Global Unsubscribe');
var policies_urls=new Array('policies/email_reputation.html','policies/aup.html',
	'policies/privacy.html','policies/globalunsub.html');

// 6. Contact Us menu
var contactus_width=180;
var contactus_menuitems=new Array('How to Reach Savicom','Contact Customer Service');
var contactus_urls=new Array('contactus/index.html','contactus/customer_service.html');

// this routine is called to initialize all web pages:
function init () {
	// start logo rotation for pages that have it...
	if (typeof numLogos != 'undefined') doNext(0,0,100,-20);
	currentAff=getCookie("affiliate");
	if (! currentAff) {
		var aname=getSearchToken("affiliate");
		var expires = new Date();
		expires.setTime(expires.getTime() + (100 * 24 * 60 * 60 * 1000));
		if (aname=='') {
			aname=".";
			expires.setTime(expires.getTime() + (3650 * 24 * 60 * 60 * 1000));
		}
		setCookie("affiliate",aname,expires,"/");
	}
}

window.onload=init;

if (typeof(pathToTop)=="undefined") {
	pathToTop="/";
}

// Routine to calculate cursor's position in current window
function getPosition(e) {
	if (! e) {
		e = window.event;
	}
	var cursor = {x:0, y:0};
	if (e.pageX || e.pageY) {
		cursor.x = e.pageX;
		cursor.y = e.pageY;
	} else {
		var de = document.documentElement;
		var b = document.body;
		cursor.x = e.clientX + 
			(de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
 		cursor.y = e.clientY + 
			(de.scrollTop || b.scrollTop) - (de.clientTop || 0);
	}
	return cursor;
}

// returns screen X position of an object
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;
}

// returns screen Y position of an object
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;
}

// returns pixel height of an object
function findHeight(obj) {
	var h;
	h = obj.offsetHeight;
	return h;
}

// returns pixel width of an object
function findWidth(obj) {
	var w;
	w = obj.offsetWidth;
	return w;
}

// function doMouseOutDD(evt) -- performs mouse out event for dropdown menu -- called in parent window
//		Checks if cursor is outside of currently activedropdown, and if so, erases dropdown
// requires instantiated navigation subframe
function doMouseOutDD(evt,menuItem) {
	if (cursorOutsideDropdown(evt,menuItem)) {
		document.getElementById('d1').style.display = 'none';
	}
}

// Evaluates if the cursor is outside of the current dropdown menuitem... called in parent window
// requires instantiated navigation subframe
function cursorOutsideDropdown(evt,menuItem) {
	var cursor = {x:0, y:0};
	cursor=getPosition(evt);

	// MSIE reports cursor position values offset by +2 pixels due to interaction with menubar IFRAME 
	// This isn't corrected with document.documentElement.clientLeft/Top so we need to fix here
	// Behavior verified in MSIE 6.0 and MSIE 7.0
	
	var IE = document.all?true:false;
	if (IE) {
		cursor.x-=2;
		cursor.y-=2;
	}
	
	var mbXOrigin=findPosX(window.navframe.document.getElementById(menuItem));
	var mbYOrigin=findPosY(window.navframe.document.getElementById(menuItem));
	var mbXSize=findWidth(window.navframe.document.getElementById(menuItem));
	
	var ddXOrigin=mbXOrigin;
	var ddYOrigin=mbYOrigin+menuBarHeight+1;

	eval('ddXSize='+menuItem+'_width;');
	eval('ddYSize='+menuItem+'_menuitems.length*rowHeight;');
//alert('cursor x,y: '+cursor.x+','+cursor.y+' origin x,y: '+ddXOrigin+','+ddYOrigin+' size x,y: '+ddXSize+','+ddYSize);
	if ((cursor.x>=(ddXOrigin+ddXSize))||(cursor.y>=(ddYOrigin+ddYSize))||(cursor.x<ddXOrigin)||(cursor.y<0)) {
		return(true);
	} else {
		return(false);
	}
}



// routines for dynamic expanding/collapsing of text
function toggleHidden(idName,hideText,showText) {
  if (document.getElementById(idName).style.display == 'none') {
    document.getElementById(idName).style.display='inline';
	this.innerText=hideText;
  } else {
    document.getElementById(idName).style.display='none';
	this.innerText=showText;
  }
}

// Routines for dynamic drilldown lists... -ss May '08
function toggleFolderExpand(hdrName,listName) {
  if (document.getElementById(hdrName).className == 'expanded_hdr') {
    document.getElementById(hdrName).className='collapsed_hdr';
	document.getElementById(listName).style.display='none';
  } else {
    document.getElementById(hdrName).className='expanded_hdr';
	document.getElementById(listName).style.display='inline';
  }
}

function forceFolderExpand(hdrName,listName) {
  document.getElementById(hdrName).className='expanded_hdr';
  document.getElementById(listName).style.display='inline';
}

function toggleQuestionExpand(hdrName,listName) {
  if (document.getElementById(hdrName).className == 'expanded_q') {
    document.getElementById(hdrName).className='collapsed_q';
	document.getElementById(listName).style.display='none';
  } else {
    document.getElementById(hdrName).className='expanded_q';
	document.getElementById(listName).style.display='inline';
  }
}
// end dynamic expand/collapse routeines

// routine to pop up window for Savicom email contact form...
function contactPopUp(WinURL) {
	openPopup(document.getElementById('d2'),'d2',WinURL,520,520,false);
	return false;
}

// routine to pop up window for signups and free trials...
function signupPopUp(WinURL) {
	openPopup(document.getElementById('d2'),'d2',WinURL,570,580,false);
  	return false;
}

// routine to pop up window for signups and free trials...
function customPopUp(WinURL,w,h) {
	openPopup(document.getElementById('d2'),'d2',WinURL,w,h,false);
	return false;
}

// routine to pop up window for forgot password page...
function passwordPopUp(WinURL) {
	openPopup(document.getElementById('d2'),'d2',WinURL,650,590,false);
	return false;
}

// This section contains all of the routines necessary for live chat integration on the web site
// these routines were formerly located in chat.js
// moved here 5/18/2008 - ss
var seWgd9;
var seWgd9s;

function insertChatButton(pageName,hideWhenUnavailable) {
  var landing=getCookie('landing');
  // qualify audience for chat button to exclude global unsub recipients...
  if (landing != "http://www.savicom.net/policies/globalunsub.html") {
    seWgd9=document.createElement("script");
    seWgd9.type="text/javascript";
    seWgd9s=(location.protocol.indexOf("https")==0?"https://secure.providesupport.com/image":"http://image.providesupport.com")+
		"/js/mindshar/safe-standard.js?ps_h=Wgd9\u0026ps_t="+new Date().getTime();
	if (hideWhenUnavailable == true) {
	  var urlPrefix=(location.protocol.indexOf("https")==0?
	  "https%3A//db.savicom.net/www":"http%3A//www.savicom.net");
	  seWgd9s+="\u0026offline-image="+urlPrefix+"/images/dotclear.gif"+
	  "\u0026online-image="+urlPrefix+"/images/sales_chat_on_small.gif";
	}
	seWgd9s+="\u0026PageLocation="+location+"\u0026Local_Time="+new Date().toLocaleString()+
		"\u0026Page="+escape(pageName)+"\u0026Orig_Referrer="+getCookie('referrer')+
		"\u0026Landing="+landing+"\u0026Login_ID="+getCookie('loginID')+"\u0026pDisp="+productDisposition;
	setTimeout("seWgd9.src=seWgd9s;document.getElementById('sdWgd9').appendChild(seWgd9)",1)
  }
}

var seWgdA;
var seWgdAs;

function insertChatBeacon(pageName) {
  var landing=getCookie('landing');
  // qualify audience for chat button to exclude global unsub recipients...
  if (landing != "http://www.savicom.net/policies/globalunsub.html") {
    seWgdA=document.createElement("script");
    seWgdA.type="text/javascript";
    seWgdAs=(location.protocol.indexOf("https")==0?
	"https://secure.providesupport.com/image":
	"http://image.providesupport.com")+
	"/js/mindshar/safe-monitor.js?ps_h=WgdA\u0026ps_t="+
	new Date().getTime()+"\u0026PageLocation="+location+"\u0026Local_Time="+new Date().toLocaleString()+
	"\u0026Page="+escape(pageName)+"\u0026Orig_Referrer="+getCookie('referrer')+"\u0026Landing="+
	landing+"\u0026Login_ID="+getCookie('loginID')+"\u0026pDisp="+productDisposition;
	setTimeout("seWgdA.src=seWgdAs;document.getElementById('sdWgdA').appendChild(seWgdA)",1)
  }
}

var sebaHv;
var sebaHvs;
function insertSupportChatButton(pageName) {
  var landing=getCookie('landing');
  // qualify audience for chat button to exclude global unsub recipients...
  if (getCookie('loginID') != "") {
    sebaHv=document.createElement("script");
    sebaHv.type="text/javascript";
    sebaHvs=(location.protocol.indexOf("https")==0?"https://secure.providesupport.com/image":"http://image.providesupport.com")+"/js/savicomsupport/safe-standard.js?ps_h=baHv\u0026ps_t="+new Date().getTime()+"\u0026PageLocation="+location+"\u0026Local_Time="+new Date().toLocaleString()+"\u0026Page="+escape(pageName)+"\u0026Orig_Referrer="+getCookie('referrer')+"\u0026Landing="+landing+"\u0026Login_ID="+getCookie('loginID');
	setTimeout("sebaHv.src=sebaHvs;document.getElementById('sdbaHv').appendChild(sebaHv)",1)
  }
}

// end live chat routines from chat.js

// This section contains all of the routines used to read and set tracking cookies on the corporate web site
// these routines were formerly located in store_ref_cookie.js, and in cookie_reader.js
// moved here 5/18/2008 - ss

function getCookie(Name) {
  var search = Name + "=";
  if (document.cookie.length > 0) { // if there are any cookies
    offset = document.cookie.indexOf(search);
    if (offset != -1) { // if cookie exists 
      offset += search.length;
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if ((end == -1) || (end == "")) // null string is to fix JS bug on NS3.0 Mac
        end = document.cookie.length;
      return unescape(document.cookie.substring(offset, end));
    } else {
      return "";
    }
  } else {
    return "";
  }
}

function setCookie(name, value, expire, path, domain) {
	var secure=false;

	if (typeof domain == 'undefined') {
		domain='savicom.net';
	}
	document.cookie = name + "=" + escape(value) +
	((expire == null) ? "" : ("; expires=" + expire.toGMTString())) +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "" ) +
	((secure) ? "; secure" : "" );
}

function updateReferrer(r) {
  var expires = new Date();
  cameFrom=getCookie("referrer");
  if (cameFrom == '') {
    if (r == '')
      r = '-';
    expires.setTime(expires.getTime() + (3650 * 24 * 60 * 60 * 1000));
    setCookie("referrer",r,expires,"/");
  }
}

function saveLandingInfo(r,l) {
  var expires = new Date();
  landedAt=getCookie("landing");
  cameFrom=getCookie("referrer");
  if (cameFrom == '') {
    if (l == '')
      l = '-';
	if (r == '')
      r = '-';
    expires.setTime(expires.getTime() + (3650 * 24 * 60 * 60 * 1000));
	setCookie("referrer",r,expires,"/");
    setCookie("landing",l,expires,"/");
  }
}

saveLandingInfo(document.referrer,document.URL);

// end cookie and tracking routines from store_ref_cookie.js

// Routine to extract parameters from the "search" portion of a pages URL...
// location.search may include a section to expand... check to see if it's there:
// replaced getQueryParameter() in url_query.js and several others
function getSearchToken(tokenName) {
  var result='';
  var srchString=tokenName+'=';
  var offset;
  var end;
  var q=top.location.search;

  if (q.length>0) {
    offset=q.indexOf(srchString);
    if (offset != -1) { // if destination was found
      offset+=srchString.length;
      end=q.indexOf("&",offset);
      if ((end == -1) || (end == "")) // null string is to fix JS bug on NS3.0 Mac
        end = q.length;
      result=unescape(q.substring(offset,end));
    }
  }
  return(result);
}

// randomly selects a customer service quote to display...
function randomSupportQuote() {
  var csQuotes=new Array("i_appreciate.jpg");
  var totalQuotes=csQuotes.length;

  // randomly select quote to insert...
  var thisQuoteNumber=Math.floor(totalQuotes*Math.random());
  
  document.writeln('<img src="'+pathToTop+'images/cs_quotes/'+csQuotes[thisQuoteNumber]+'" alt="Customer quote appreciating Savicom customer service" width="182" height="183" border="0">');
}

// These routine determines the nature of the visitor to dynamically adapt the site to them
var productDisposition='';

// Gets product disposition from cookie
function getDisposition() {
	productDisposition=(getCookie('prodDisp'));
	return(productDisposition);
}

// Stores product disposition in cookie, either explicitly passed in myClass, or stored in global productDisposition variable
function setDisposition(myClass) {
	productDisposition=myClass;
	var expires = new Date();
	expires.setTime(expires.getTime() + (365 * 24 * 60 * 60 * 1000));
	setCookie('prodDisp',productDisposition,expires,"/");
}

// Stores product disposition only if not already set...
function initializeDisposition(myClass) {
	if ((myClass) && (!productDisposition)) {
		productDisposition=myClass;
		var expires = new Date();
		expires.setTime(expires.getTime() + (365 * 24 * 60 * 60 * 1000));
		setCookie('prodDisp',productDisposition,expires,"/");
	}
}


// Determines product disposition
function determineDisposition() {
	var myDisposition='';
	
	// Check to see if visitor is already has a Savicom login if so set disposition according to login type...
	var type = getCookie('loginType');
	if (type == 'm') myDisposition='cplus'; // Display CPlus upgrade messages for pro accounts
    else if (type == 'p') myDisposition='pub';
	else if (type == 'd') myDisposition='dash';
	else if (type == 'c') myDisposition='cplus';
	else if (type == 'a') myDisposition='';
	return(myDisposition);
}

function selectContent(myClass) {
	if (myClass) setDisposition(myClass);
	if (productDisposition == 'pro') {
		makeVisible('pro');
		makeInvisible('cplus');
		makeInvisible('pub');
		makeInvisible('dash');
	} else if (productDisposition == 'cplus') {
		makeInvisible('pro');
		makeVisible('cplus');
		makeInvisible('pub');
		makeInvisible('dash');
	} else if (productDisposition == 'pub') {
		makeInvisible('pro');
		makeInvisible('cplus');
		makeVisible('pub');
		makeInvisible('dash');
	} else if (productDisposition == 'dash') {
		makeInvisible('pro');
		makeInvisible('cplus');
		makeInvisible('pub');
		makeVisible('dash');
	} else if (productDisposition == 'all') {
		// for debug only...
		makeVisible('pro');
		makeVisible('cplus');
		makeVisible('pub');
		makeVisible('dash');
	} else {
		// No product disposition... select randomly:
		var rNum=Math.floor(5*Math.random());
		if (rNum<=1) makeVisible('pro');  // Pro gets double weighting
		else makeInvisible('pro');
		if (rNum==2) makeVisible('cplus');
		else makeInvisible('cplus');
		if (rNum==3) makeVisible('pub');
		else makeInvisible('pub');
		if (rNum==4) makeVisible('dash');
		else makeInvisible('dash');
	}
}

function makeVisible(myClass) {
	if (!document.styleSheets) return;
	if (document.styleSheets[0].cssRules)
		document.styleSheets[0].insertRule('.'+myClass+' { display: inline; }',document.styleSheets[0].cssRules.length)
	else if (document.styleSheets[0].rules)
		document.styleSheets[0].addRule('.'+myClass,'{ display: inline; }');
}

function makeInvisible(myClass) {
	if (!document.styleSheets) return;
	if (document.styleSheets[0].cssRules)
		document.styleSheets[0].insertRule('.'+myClass+' { display: none; }',document.styleSheets[0].cssRules.length)
	else if (document.styleSheets[0].rules)
		document.styleSheets[0].addRule('.'+myClass,'{ display: none; }');
}

// Determine the visitor's product disposition...
getDisposition();

initializeDisposition(determineDisposition());

// Set content based on visitor's product disposition
selectContent();

// variable and routine for image hiliting...
timerID = null;

function hiLite(imgDocID,imgObjName) {
// manages mouseOver animations
// imgDocID - the name or number of the document image to be replaced
// imgObjName - the name of the image object to be swapped in
    document.images[imgDocID].src = eval(imgObjName + ".src")
    if (imgObjName.substring(imgObjName.length-1,imgObjName.length) == "1") {
      clearTimeout(timerID);
      clearCommand="document.images[\'" + imgDocID + "\'].src = " + imgObjName.substring(0 ,imgObjName.length - 1) + "0.src";
      timerID=setTimeout(clearCommand,5000);
    } 
} 

// Shows a slide show
function showTour(tourName) {
	var tourName;
	var w;
	var largeURL='';
	var smallURL='';
	var largeSize={x:0, y:0};
	var smallSize={x:0, y:0};

	if (tourName == "persmktg") {
		largeURL = pathToTop+"slideshows/persmktg/large.html";
		smallURL = pathToTop+"slideshows/persmktg/small.html";
		largeSize={x:824, y:618};
		smallSize={x:549, y:412};
	} else if (tourName == "pro") {
		largeURL = pathToTop+"slideshows/pro/large.html";
		smallURL = pathToTop+"slideshows/pro/small.html";
		largeSize={x:820, y:615};
		smallSize={x:550, y:413};
	} else if (tourName == "dash") {
 		// var largeURL = pathToTop+"slideshows/dash/large.html"; No Big version of DASH yet..
		smallURL = pathToTop+"slideshows/dash/small.html";
		smallSize={x:530, y:410};
	} else {
		alert("Slide show named \"" + tourName + "\" not found. Please notify Savicom Support.");
		return false;
	}
	smallSize.x+=56;
	if (smallSize.y < 421) smallSize.y=421;
	largeSize.x+=56;	

	if (largeURL && (willItFit(largeSize))) {
		openPopup(document.getElementById('d2'),'d2',largeURL,largeSize.x,largeSize.y,true);
	} else {
		openPopup(document.getElementById('d2'),'d2',smallURL,smallSize.x,smallSize.y,true);
	}
	return(false);
}

// Following are the library of DHTML popup routines..

// stores the amount of formatting overhead for the DHTML popup
var popupOverhead={x:24, y:34};
var popupHeaderHeight=22;

// Opens a DHTML popup...
// obj - pointer to <DIV> element... set using document.getElementById('name') or the like...
// objID is the ID given to the DIV element in the tag
// url is the URL of the page to be inserted into the popup
// width and height are the size of the internal popup window...
function openPopup(obj,objID,url,width,height,fixedSize) {
	return(generatePopupHTML(obj,objID,url,'',width,height,fixedSize));
}

// Same as openPopup, except with "source"
function openPopupSource(obj,objID,source,width,height,fixedSize) {
	return(generatePopupHTML(obj,objID,'',source,width,height));
}

function generatePopupHTML(obj,objID,url,source,width,height,fixedSize) {
	var code='';
	var mac=false;
	var targetPosition={x:0, y:0};
	var wSize={x:0, y:0};
	
	// check to see if we need to squeeze the popup in the window...
	wSize=getWindowSize();
	if ((!fixedSize) && shrinkPopupToWindow && ((height+popupHeaderHeight+8)>wSize.y)) {
		height-=(height+popupHeaderHeight+8-wSize.y);
	}
		
	// Check for minimum/maximum sizes
	if (width < 200) width=200;
	if (width > 1400) width=1400;
	if (height < 200) height=200;
	if (height > 1200) height=1200;

	var size={x:width, y:height};

	targetPosition=getPopupOrigin(size);
	if (navigator.platform.indexOf("Mac") != -1) {
		mac=true;
	}

	var outsideWidth=width+popupOverhead.x;
	var outsideHeight=height+popupOverhead.y;
	
	if (mac) {
		closeBtn0 = new Image(16,16);
		closeBtn0.src = pathToTop+"images/dhtml_popup/mac_close.gif";
		closeBtn1 = new Image(16,16);
		closeBtn1.src = pathToTop+"images/dhtml_popup/mac_close_hilite.gif";
	} else {
		closeBtn0 = new Image(43,18);
		closeBtn0.src = pathToTop+"images/dhtml_popup/windows_close.gif";
		closeBtn1 = new Image(43,18);
		closeBtn1.src = pathToTop+"images/dhtml_popup/windows_close_hilite.gif";
	}
	code+='<div id="popup_windowframe" style="z-index: 100; position: absolute; left: '+targetPosition.x+'; top: '+targetPosition.y+';">';
	code+='<table width="'+outsideWidth+'" border="0" cellpadding="0" cellspacing="0">';
	code+='<tr>';
	var w2=Math.floor(outsideWidth/2);
	var w3=outsideWidth-w2;
	code+='<td width="'+w2+'" background="'+pathToTop+'images/dhtml_popup/top_windowbar_left.gif">';
	if (mac) {
		code+='<a href="#" onClick="closePopup(document.getElementById(\''+objID+'\')); return(false)" onMouseOver="hiLite(\'doc_closebtn\',\'closeBtn1\')" onMouseOut="hiLite(\'doc_closebtn\',\'closeBtn0\')">';
		code+='<img src="'+pathToTop+'images/dhtml_popup/mac_close.gif" name="doc_closebtn" id="doc_closebtn" alt="Close" width="16" height="16" border="0" vspace="3" hspace="10"></a>';
	} else {
		code+='<img src="'+pathToTop+'images/dotclear.gif" alt="" width="'+w2+'" height="'+popupHeaderHeight+'" border="0">';
	}
	code+='</td>';
	code+='<td width="'+w3+'" background="'+pathToTop+'images/dhtml_popup/top_windowbar_right.gif" style="background-position: right;" align="right">';
	if (! mac) {
		code+='<a href="#" onClick="closePopup(document.getElementById(\''+objID+'\')); return(false)" onMouseOver="hiLite(\'doc_closebtn\',\'closeBtn1\')" onMouseOut="hiLite(\'doc_closebtn\',\'closeBtn0\')">';
		code+='<img src="'+pathToTop+'images/dhtml_popup/windows_close.gif"  name="doc_closebtn" id="doc_closebtn" alt="Close" width="43" height="18" border="0" vspace="2" hspace="10"></a>';
	} else {
		code+='<img src="'+pathToTop+'images/dotclear.gif" alt="" width="'+w3+'" height="'+popupHeaderHeight+'" border="0">';
	}
	code+='</td></tr><tr>';
	code+='<td background="'+pathToTop+'images/dhtml_popup/windowbg_left.gif"><img src="'+pathToTop+'images/dotclear.gif" alt="" width="'+w2+'" height="'+height+'" border="0"></td>';
	code+='<td background="'+pathToTop+'images/dhtml_popup/windowbg_right.gif" style="background-position: right;"><img src="'+pathToTop+'images/dotclear.gif" alt="" width="'+w3+'" height="'+height+'" border="0"></td>';
	code+='</tr><tr>';
	code+='<td background="'+pathToTop+'images/dhtml_popup/windowbottom_left.gif"><img src="'+pathToTop+'images/dotclear.gif" alt="" width="'+w2+'" height="12" border="0"></td>';
	code+='<td background="'+pathToTop+'images/dhtml_popup/windowbottom_right.gif" style="background-position: right;"><img src="'+pathToTop+'images/dotclear.gif" alt="" width="'+w3+'" height="12" border="0"></td>';
	code+='</tr></table></div>';
	
	var x=Math.floor(popupOverhead.x/2)+targetPosition.x;
	var y=popupHeaderHeight+targetPosition.y
	var w4=width-Math.floor(popupOverhead.x/2)*2;
	code+='<div id="popup_contents" style="z-index: 101; position: absolute; left: '+x+'; top: '+y+'; height: '+height+'; width: '+width+'">';
	if (url) {
		code+='<iframe src="'+url+'" height="'+height+'" width="'+width+'" frameborder="0"></iframe>';
	} else {
		if (! source) {
			source='No URL or HTML source specified in call to generatePopupHTML';
		}
		code+=source;
	}
	code+='</div>';
	
	// display drop shadow...
	var dsXOrigin=targetPosition.x+dropShadowPopup;
	var dsYOrigin=targetPosition.y+dropShadowPopup;
	code+='<div id="popup_shadow" style="z-index: 99; position: absolute; left: '+dsXOrigin+'; top: '+dsYOrigin+';">';
	code+='<table width="'+outsideWidth+'" border="0" cellpadding="0" cellspacing="0">';
	code+='<tr><td colspan="3" width="'+outsideWidth+'" align="right"><img src="'+pathToTop+'images/dhtml_popup/top_windowbar_right_shadow.gif" alt="" width="28" height="'+popupHeaderHeight+'" border="0" class="dropshadow"></td></tr>';
	code+='<tr><td colspan="3" width="'+outsideWidth+'"><img src="'+pathToTop+'images/blackpixel.gif" alt="" width="'+outsideWidth+'" height="'+height+'" border="0" class="dropshadow"></td></tr>';
	code+='<tr><td width="14"><img src="'+pathToTop+'images/dhtml_popup/windowbottom_left_shadow.gif" alt="" width="14" height="12" border="0" class="dropshadow"></td>';
	var w1=outsideWidth-28;
	code+='<td width="'+w1+'"><img src="'+pathToTop+'images/blackpixel.gif" alt="" width="'+w1+'" height="12" border="0" class="dropshadow"></td>';
	code+='<td width="14"><img src="'+pathToTop+'images/dhtml_popup/windowbottom_right_shadow.gif" alt="" width="14" height="12" border="0" class="dropshadow"></td>';
	code+='</tr></table></div>'+"\n";

	// freeze page widthwise scrolling to prevent bottom scrollbar from showing up and wasting valuable Y-axis real estate...
	document.body.style.overflowX="hidden";

	// fade the page behind the screen...
	code+='<div class="pagefade" id="pagefade" style="z-index: 98; position: absolute; top: 0; left: 0; width: 0; height: 0;">';
	code+='</div>';
	
	obj.innerHTML=code;
	obj.style.zIndex = "100";
	obj.style.position="absolute";
	targetPosition=adjustForScrolling(targetPosition);
	obj.style.left="0px";
	obj.style.top="0px";
	obj.style.display='block';
	
	// now reset the size of the page fade since the browsers will know how long it is...
	// window.onresize=resizePageFade(); -- this doesn't seem to work...
	resizePageFade();
}

function resizePageFade() {
	var pSize={x:0, y:0};
	pSize=getPageSize();
	document.getElementById('pagefade').style.width=2000;
	document.getElementById('pagefade').style.height=pSize.y;
}

// shuts down the popup
function closePopup(obj) {
	obj.style.display='none';
	document.body.style.overflowX="scroll";
}

// calculates the x,y origin of the popup based on the size and assumes popup will be centered in page
function getPopupOrigin(size) {
	var origin={x:0, y:0};
	origin=getWindowSize();
	origin.x-=(size.x+popupOverhead.x);
	origin.y-=(size.y+popupOverhead.y);
	origin.x=Math.floor(origin.x/2);
	origin.y=Math.floor(origin.y/2);
	if (origin.x < 0) origin.x=0;
	if (origin.y < 0) origin.y=0;
	if (typeof document.body.scrollTop != 'undefined') {
		origin.x+=document.body.scrollLeft;
		origin.y+=document.body.scrollTop;
	} else {
		origin.x+=document.body.pageXOffset;
		origin.y+=document.body.pageYOffset;
	}
	return(origin);
}

// sees if a popup with internal size "size" will fit in the current window
function willItFit(size) {
	var wSize={x:0, y:0};
	wSize=getWindowSize();
	if ((wSize.x>=(size.x+popupOverhead.x)) && (wSize.y>=(size.y+popupOverhead.y))) {
		return(true);
	} else {
		return(false);
	}
}

// calculates the current window internal size...
function getWindowSize() {
	var size={x:0, y:0};
	if (window.innerWidth) {
		size.x=window.innerWidth;
		size.y=window.innerHeight;
	} else {
		size.x=document.body.clientWidth;
		size.y=document.body.clientHeight;
	}
	// alert(size.x+':'+size.y);
	return(size);
}

function getPageSize() {
	var size={x:0, y:0};
	if	(window.innerHeight && window.scrollMaxY) {
		// Firefox
		size.x = window.innerWidth + window.scrollMaxX;
		size.y = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) {
		// all but Explorer Mac
		size.x = document.body.scrollWidth;
		size.y = document.body.scrollHeight;
	} else {
		// works in Explorer 6 Strict, Mozilla (not FF) and Safari
		size.x = document.body.offsetWidth + document.body.offsetLeft; 
		size.y = document.body.offsetHeight + document.body.offsetTop;
	}
	// alert(size.x+':'+size.y);
	return(size);
}

// This function adjusts absolute coordinates to account for scrolling 
function adjustForScrolling(loc) {
	var de = document.documentElement;
	var b = document.body;
	loc.x += (de.scrollLeft || b.scrollLeft);
 	loc.y += (de.scrollTop || b.scrollTop);
	return(loc);
}

// closes a popup window...
function closeMyself() {
	if (amIDynamicPopup()) {
		// In DHTML popup...
		closePopup(parent.document.getElementById('d2'));
	} else {
		// assume we're in old school popup...
		window.close();
	}
}

// checks to see if currently in DHTML popup
function amIDynamicPopup() {
	if (parent.document.getElementById('d2')) return(true);
	else return(false);
}
// end of DHTML routines

// pops up an image in a popup window...
function enlargeImage(Image,ww,wh) {
	var s='';
	s+='<center><img src="'+Image+'" alt="" border="0"></center>';
    openPopupSource(document.getElementById('d2'),'d2',s,ww,wh,true);
}
