// common.js
// standard helper functions for use throughout the site

// hide h1 and h2 tags
function hideHeaders()
{
 if (document.getElementsByTagName("h1")[0]) document.getElementsByTagName("h1")[0].style.display="none";
 if (document.getElementsByTagName("h2")[0]) document.getElementsByTagName("h2")[0].style.display="none";
}

// popup functions
// v2.0
function MM_openBrWindow(theURL,winName,features)
{ 
	window.open(theURL,winName,features);
}

// opens a new window and forces IE not to resize the picture
function popup(source,width,height,scrollers)
{
	var is_scroller = 0;
	var winobj = '';
	
	if(navigator.appName.indexOf("Microsoft") > -1) {}
	else { if(source.match(/\.wmv/)) { height += 46; } }

	if(scrollers == 1) is_scroller = 1;

	var dev_width = screen.availWidth-10;
	var dev_height = screen.availHeight-30;

	if(dev_width < width)
	{
		var width = dev_width;
		is_scroller = 1;
	}

	if(dev_height < height)
	{
		var height = dev_height;
		is_scroller = 1;
	}

	var X = (dev_width-width)/2;
	var Y = (dev_height-height)/2;
	var params = "width="+width+",innerWidth="+width;

	params+= ",height="+height+",innerHeight="+height;
	params+= ",left="+X+",screenX="+X;
	params+= ",top="+Y+",screenY="+Y;
	params+= ",resizable=yes";

	if(is_scroller == 1) params += ",scrollbars";

	if(source.match("info.quest.com")) { winobj = window.open(source,"_blank",params); }
	else { winobj = window.open("/images/popup.asp?path="+escape(source)+"&width="+width+"&height="+height,"_blank",params); }

	//winobj.moveTo(X, Y);
}

//basic popup window w/default size and centering- js
function popupBasic(url,popWidth,popHeight,scrollbars,popX,popY){
	//default or specified size
	popWidth = typeof(popWidth) != 'undefined' ? popWidth : 900;
  	popHeight = typeof(popHeight) != 'undefined' ? popHeight : 700;
	
	//center positioning
	var screenWidth = screen.availWidth-10;
	var screenHeight = screen.availHeight-30;
	var centerX = (screenWidth-popWidth)/2;
	var centerY = (screenHeight-popHeight)/2;
	
	//centered or specified position
  	popX = typeof(popX) != 'undefined' ? popX : centerX;
  	popY = typeof(popY) != 'undefined' ? popY : centerY;
	
	//default on scrollbars
  	scrollbars = typeof(scrollbars) != 'undefined' ? scrollbars : "yes";
	
	newwindow=window.open(url,'_blank','width='+popWidth+',height='+popHeight+',left='+popX+',top='+popY+',scrollbars='+scrollbars+',resizable=yes');
	if (window.focus) {newwindow.focus()}
	
	return false;
}

//Fix breadcrumbs - js
function makeBread(bread){
	myTable = document.getElementById('header3');
	cells = myTable.getElementsByTagName('td');
	for(i = 0; i < cells.length; i++) {
	  if(cells[i].className == 'clickpath') {
		cells[i].innerHTML = bread;
	  }
	}
}

//Add product logo to top right of page - js
function addLogo(imageAlt,imageSource){
	var pageContent = document.getElementById('pagebody');
	pageContent.innerHTML = '<img id="headerLogo" src="' + imageSource + '" alt="' + imageAlt + '" />' + pageContent.innerHTML;
}

//use to set default button
function clickButton(e, buttonid){ 
      var bt = document.getElementById(buttonid); 
      if (typeof bt == 'object'){ 
            if(navigator.appName.indexOf("Netscape")>(-1)){ 
                  if (e.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
            if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
                  if (event.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
      } 
}


function formPanel_FireDefaultButton(event, target) {
    if ((event.keyCode == 13 || event.which == 13) && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == 'textarea'))) 
    {
        var defaultButton = document.getElementById(target);
        if (defaultButton == 'undefined') defaultButton = document.all[target]; 

        if (defaultButton && typeof(defaultButton.click) != 'undefined') 
        {
            defaultButton.click();
            event.cancelBubble = true;
            if (event.stopPropagation) event.stopPropagation();
            return false;
        }
    }
    return true;
}

function trackAdCode(adcode)
{
 // loadXMLDoc - retrieves an XML document
 // arguments:
 // url: URL to a valid XML file (e.g. text/xml) on the same domain as referring HTML file.  May be a relative or full path.
 // req.open usage: req.open(http method, URL, asynchronous)
 function loadXMLDoc(url)
 {
  if (window.XMLHttpRequest)
  {
   // Native XMLHttpRequest object support
   req = new XMLHttpRequest();
   
   // check whether we should use asynchronous mode (some browsers don't fire the processReqChange if request mode is 'synchronous')
   // mode is synchronous by default because it gives us better results and doesn't mix up multiple lookups
   var async = false;
   // force asynchronous mode for camino
   async = (async || navigator.userAgent.toLowerCase().indexOf("camino") >= 0);
   // force asynchronous mode for firefox < 2.0.0.9 or >= 3
   if (navigator.userAgent.toLowerCase().indexOf("firefox") >= 0)
   {
    // firefox 1
    async = (async || (navigator.userAgent.substring(navigator.userAgent.lastIndexOf("/")+1,navigator.userAgent.indexOf(".",navigator.userAgent.lastIndexOf("/"))) == "1"));
    // firefox 2.0 - 2.0.0.9
    async = (async || (navigator.userAgent.substring(navigator.userAgent.lastIndexOf("/")+1,navigator.userAgent.lastIndexOf(".")) == "2.0.0" && parseInt(navigator.userAgent.substring(navigator.userAgent.lastIndexOf(".")+1,navigator.userAgent.length)) < 9));
    // firefox 3
    async = (async || (navigator.userAgent.substring(navigator.userAgent.lastIndexOf("/")+1,navigator.userAgent.indexOf(".",navigator.userAgent.lastIndexOf("/"))) == 3));
   }
   
   req.open("GET", url, async);
   req.send(null);
  }
  else if (window.ActiveXObject)
  {
   // IE/Windows ActiveX version of XMLHTTP support
   isIE = true;
   req = new ActiveXObject("Microsoft.XMLHTTP");
   if (req)
   {
    req.open("GET", url, false);
    req.send();
   }
  }
 }
 
 // strip out the domain name if necessary
 if (adcode.indexOf("/") > 0) adcode = adcode.substring(adcode.lastIndexOf("/")+1,adcode.length);
 
 // run the page load to track the ad code "click"
 loadXMLDoc("/"+adcode);
 
 return true;
}