var start_time = new Date() ;

// One popup per page: must be in a div "pop" with inline styles "height" & "width"
// Scroll height unreliable so target form submissions to "top" anchor

var isFirstCall = true ;
var pop; var frame; var width; var topPos; var endPos;

function popupShow(speed) 
{
	if(isFirstCall)
	{
		pop = document.getElementById("pop") ;
		var height = pop.style.height.replace('px','') ;
		width = pop.style.width.replace('px','') ;
		pop.style.display = "block";

		/*
		iframe = document.getElementById('pop-shim');
		var iw = Number(pop.style.width.replace("px", "")) ;
		var ih = Number(pop.style.height.replace("px", ""));
		iframe.style.width = (iw + 4) + "px"
		iframe.style.height = (ih + 4) + "px"
		iframe.style.display = "block";

	
		var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
		var pageY=document.all? iebody.scrollTop : pageYOffset
		*/

		topPos = 0 - height ;

		if( window.innerHeight )
		{
			endPos = ((window.innerHeight/2)-(height/2));
		}
		else
		{ 
			// Workaround IE compatibilty issue...
			var innerHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight
		 	endPos = ((innerHeight/2)-(height/2));
		}

		endPos = Math.round(endPos) ;

		pop.style.visibility = "visible" ;
		isFirstCall = false ;
	}

	if (parseInt(navigator.appVersion) >= 4 && navigator.javaEnabled()) 
	{ 
		if (document.layers) document.layers.pop.left = ((window.innerWidth/2)-(width/2))+"px";
		else if (document.all) document.all.pop.style.left = ((document.body.offsetWidth/2)-(width/2))+"px";
		else pop.style.left=((window.innerWidth/2)-(width/2))+"px";

		if(topPos < endPos) 
		{ 
			topPos += speed;  
			if (document.layers) document.layers.pop.top = topPos+"px";
			else if (document.all) document.all.pop.style.top = topPos+"px";
			else pop.style.top = topPos+"px";
			setTimeout("popupShow("+ speed + ")",1);
		}
	}
}

function popupHide() 
{ 
  if (document.layers) document.layers["pop"].visibility = 'hide';
  else if (document.all) document.all["pop"].style.visibility = 'hidden';
  else if (document.getElementById) document.getElementById("pop").style.visibility = 'hidden';
}

function db(msg){ document.open(); document.write(msg); document.close();}

// Log virtual requests to Google Analytics
// Example output: /doc/price_list_1.pdf
// Standard types: doc, link
// Log locally via Ajax

function virtualLog(request_type, payload)
{
	// Do Google
	
	var path =  '/' + request_type + '/' + payload ;
	pageTracker._trackPageview(path);

	// Do Ajax

	if( request_type == 'doc' )
	{
		url = callbackURL + '/doc-log/' + payload ;
		ProcessXML( url );
	}
}

// Ajax call: adapted from Google Code University

function ProcessXML(url) 
{
	var obj;

  if (window.XMLHttpRequest) {
    obj = new XMLHttpRequest();
    // set the callback function
    obj.onreadystatechange = null;
    obj.open("GET", url, true);
    obj.send(null);
  } else if (window.ActiveXObject) {
    obj = new ActiveXObject("Microsoft.XMLHTTP");
    if (obj) {
      obj.onreadystatechange = null;
      obj.open("GET", url, true);
      obj.send();
    }
  } 
}
