/**
  * Function for opening the product features window, and
  * possibly the print window
  */

/*********************************************************
   funcOpenWindow()
   strURL - String, URL that the window opens initially
   strWindowName - String, name of the window 
   intWindowHeight - Int, initial window height
   intWindowWidth - Int, initial window width
   intCanResize - Int, has three possible values:
   	1 - window is opened with no controls, but user can resize
   	0 - window is opened with no controls, but user can't resize
   	-1 - window is opened with all controls, and user can resize
   Andy Millard, 8th January 2002
**********************************************************/

//--------Google Analytics--------------------------------

var googleKEY = "UA-607690-2";
function gaSSDSLoad(acct) {
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."),
      pageTracker,
      s;
    s = document.createElement('script');
    s.src = gaJsHost + 'google-analytics.com/ga.js';
    s.type = 'text/javascript';
    s.onloadDone = false;
    function init() {
        pageTracker = _gat._getTracker(acct);
        pageTracker._trackPageview();
    }
    s.onload = function() {
        s.onloadDone = true;
        init();
    };
    s.onreadystatechange = function() {
        if (('loaded' === s.readyState || 'complete' === s.readyState) && !s.onloadDone) {
            s.onloadDone = true;
            init();
        }
    };
    document.getElementsByTagName('head')[0].appendChild(s);
}


addExtDocEvents();

addJavascript('http://www.google-analytics.com/urchin.js','head','');
function addJavascript(jsname,pos,val) {
	var th = document.getElementsByTagName(pos)[0];
	var s = document.createElement('script');
	s.setAttribute('language','JavaScript');
	s.setAttribute('src',jsname);
	s.text=val;
	th.appendChild(s);
}

setTimeout('startGA();', 500);

function startGA() {
    var arr = document.referrer.split("/");
    if (location.hostname != arr[2]) {
        //gaSSDSLoad("UA-607690-2");
        gaSSDSLoad(googleKEY);
        //_uacct= googleKEY;
        //urchinTracker();
    }
}

document[document.layers ? "onmouseup" : "onclick"] = function(e){
	var s = e ? e.target:event.srcElement;
	//alert(s.target);
}


function addExtDocEvents() {
	var as = document.getElementsByTagName("a");
	var extDoc = [".doc",".xls",".exe",".zip",".pdf",".js"];
	// add further document types as required

	for(var i=0; i<as.length; i++) {
		var tmp = as[i].getAttribute("onclick");

		// Tracking electronic documents - doc, xls, pdf, exe, zip
		if (tmp != null && tmp.indexOf('urchinTracker') > -1) continue;
		for (var j=0; j<extDoc.length; j++) {
			if (as[i].href.indexOf(extTrack[0]) != -1 && as[i].href.indexOf(extDoc[j]) != -1) {
				var splitResult = as[i].href.split(extTrack[0]);
				as[i].setAttribute("onclick",((tmp != null) ? tmp : "") +
					"urchinTracker('/downloads" +splitResult[1]+ "');");
				break;
			}
		}
	}
}

//--------------------------------------------------------


function funcOpenWindow(strURL, strWindowName, intWindowHeight, intWindowWidth, intCanResize)
{
   var objWindow;
   if (intCanResize == 1)
   {
      objWindow = window.open(strURL, strWindowName, "width=" + intWindowWidth + ",height=" + intWindowHeight + ",scrollbars=yes,screenX=0,screenY=0,top=0,left=0,marginheight=0, marginwidth=0,resizable=yes");
   }
   else if (intCanResize == -1)
   {
      objWindow = window.open(strURL, strWindowName, "width=" + intWindowWidth + ",height=" + intWindowHeight + ",scrollbars=yes,screenX=0,screenY=0,top=0,left=0,marginheight=0, marginwidth=0,resizable=yes,status=yes,toolbar=yes,menubar=yes");
   }
   else
   {
      objWindow = window.open(strURL, strWindowName, "width=" + intWindowWidth + ",height=" + intWindowHeight + ",scrollbars=yes,screenX=0,screenY=0,top=0,left=0,marginheight=0, marginwidth=0,resizable=no");
   }
   objWindow.focus();
   return objWindow;
}

/***********************************************************
************************************************************/
function PrintPage(){  
	if (window.print) {
    	window.print() ;  
	} else {
	    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
    	WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
	}
}


/***********************************************************
  funcDisplayDate()
  Andy Millard 6th November 2002
  Takes an array written out in the XSL (to allow for 
  translations), and prints the current date
************************************************************/
/*
function funcDisplayDate()
{
	var today = new Date();

	var monthArray = new Array("January", "February", "March", "April", "May", "June", "July", "August","September", "October", "November", "December");

	var currentDate = (today.getDate() + " " +  monthArray[today.getMonth()]);
	return currentDate;
}
*/

/************************************************************************
 Andy Millard, July 2002
 This function is called whenever a user tries to view a page/file
 in a related links select box. Depending on type of file we may 
 attempt to open in the current window, or in a new window
*************************************************************************/
function funcDoRelatedLinks(strURL, blnNewWindow, strWindowName, intWindowWidth, intWindowHeight, intCanResize)
{
	if (strURL != '')
	{
		if (blnNewWindow)
		{
			// open the URL in a new window, using default 
			funcOpenWindow(strURL, strWindowName, intWindowHeight, intWindowWidth, intCanResize);
		}
		else
		{
			top.location.href=strURL;
		}
	}
	return false;
}


/*********************************************************
   startAni()
   Andy Millard, 2nd May 2002
   This is called in the onLoad event of pages that
   allow left hand images to 'automatically' rotate.
   An array should have been declared, so check 
   that it has values, and if so, start the rotation
**********************************************************/
function startAni()
{
	if (arrImage == "undefined") alert('oops');
	if (parseInt(arrImage.length) > 1)
	{
		return setTimeout("animationLoop(0)",5000);
	}
	else
	{
		return null;
	}
}

/*********************************************************
   animcationLoop()
   Andy Millard, 2nd May 2002
   This is initially called by the function above 
   (startAni). It is passed an integer, that points
   to a row in the array. If this contains a link to an
   image, then display it. We then increment the
   integer, or reset depending on how far through the
   array we are. Then call ourselves again, after
   a short delay.
**********************************************************/
function animationLoop(i)
{
	var imageCnt = i;
	var imageSrc = arrImage[imageCnt][0];
	var imageWidth = arrImage[imageCnt][1];
	var imageHeight = arrImage[imageCnt][2];
	if (imageSrc != "none")
	{
		document.roll.src = imageSrc;
		document.roll.width = eval(imageWidth);
		document.roll.height = eval(imageHeight);
	}
	
	// loop through the image array until we find an element
	// that contains an image. Do this so we don't get a big long
	// delay while displaying empty images 
	var blnLoop = true;
	var intCheck = 0;
	while (blnLoop)
	{
		intCheck++;
		if (intCheck > 10)
		{
			return;
		}
		else
		{
			if (parseInt(imageCnt) >= parseInt(arrImage.length)-1)
				{imageCnt=0;}
			else
				{imageCnt++;}
			
			if (arrImage[imageCnt] != "none")
			{
				blnLoop = false;
			}
		}
	}
	
	timer = setTimeout("animationLoop(" + imageCnt + ")", 2000);

}

/*********************************************************
   stopAni()
   Andy Millard, 2nd May 2002
   Clears the timeout event, after checking that it
   has started. It then restarts the rotation (which
   pauses before starting).
   If an image filename is passed (i.e. not "none")
   change the rotating image to this one
**********************************************************/
function stopAni(strImageFile,intImageWidth,intImageHeight)
{
	if (blnStarted)
	{
		if ((strImageFile != "") && (strImageFile != "none"))
		{
			if (document.roll)
			{
				document.roll.src = strImageFile;
				document.roll.width = intImageWidth;
				document.roll.height = intImageHeight;
			}
	
			if (arrImage != null)
			{
				clearTimeout(timer);
				timer = null;
				timer = startAni();
			}
		}
	}
}


/*********************************************************
  function validSearch()
 *********************************************************
  Author: Dave Hunter, 08 May 2002.
  Process: Validates the search, so that the user can only 
  		   search when he has entered.
  Notes: Uses the form.elements cos of the odd name for
  		 the text box (needed for atomz search).
**********************************************************/
function validSearch(formObj){
	if(formObj.elements['sp-q'].value=='Search site for ...'){
		alert('Please enter a valid search entry.');
		return false;
	}
	else if(formObj.elements['sp-q'].value==''){
		alert('Please enter a valid search entry.');
		return false;
	}
  return true;
}

/*********************************************************
  function clearValue()
 *********************************************************
  Author: Dave Hunter, 08 May 2002.
  Process: Clears the search value if its the default string.
  Notes: Uses the uses 'this' keyword so that we dont have 
  		 problems with the name of the search box or
		 referencing the form.
**********************************************************/
function clearValue(searchBox){
	if(searchBox.value=='Search site for ...'){
		searchBox.value='';
	}
}


function sendUser(formObj)
{
	var strPage = formObj.related_links.value;
	window.location.href = strPage;
	return false;
}


/*********************************************************
Standard image preloader function (comments to follow
**********************************************************/
/*
		  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 &lt; a.length; i++)
    		
    				if (a[i].indexOf("#")!=0){
    					d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
    				}
    		}
    	  }
	*/	  




