﻿/********************************* Steve Doggett *************************************
 * Created By:		Steve Doggett
 * Creation Date:	26th July 2005
 * Edited ----------------------------------------------------------------------------
 *		By:				On:
 * Description -----------------------------------------------------------------------
 *		This file contains a number of utility function
 *
 *    popupWindow(mypage, scroll, toolbar) 
 *    getWindowHeight()
 *    getWindowWidth()
 **************************************************************************************/

/****
 * Open a new browser window for viewing an Entity
 * Check whether it's already open first though. Re-use if possible.
 ****/
function popupWindow(mypage, scroll, toolbar) 
{
	var myname = 'popup';
	var myWin;
	var pcgsize = 75;
	var intHeight = getWindowHeight();
	var intWidth = getWindowWidth();
	var h = Math.round(	(pcgsize/100) * intHeight  ) ;
	var w = Math.round(	(pcgsize/100) * intWidth  );
	var wint = Math.round(	(intHeight - h)/3  );
	var winl = Math.round(	(intWidth - w)/2 );

	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes,toolbar='+toolbar;
	
 	if ( !myWin || myWin.closed )
		myWin = window.open(mypage, myname, winprops)
	else
  		myWin.location.href = myPage;

	myWin.focus();
}

/****
 * Gets the width of the browser window
 ****/
function getWindowWidth()
{
  if (parseInt(navigator.appVersion)>3) 
  {
   if (navigator.appName=="Netscape")
    return window.innerWidth;
   
   if (navigator.appName.indexOf("Microsoft")!=-1)
    return document.body.offsetWidth;
  }
}

/****
 * Gets the height of the browser window
 ****/
function getWindowHeight()
{
  if (parseInt(navigator.appVersion)>3) 
  {
   if (navigator.appName=="Netscape")
    return window.innerHeight;
   
   if (navigator.appName.indexOf("Microsoft")!=-1)
    return document.body.offsetHeight;
  }
}

///****
// * This deals with the cartoon images!
// ****/
//// Add them to an array
//var Pic = new Array()

//Pic[0] = { src: 'Graphics/cartoon1.gif', alt: 'Cartoon Image'};
//Pic[1] = { src: 'Graphics/cartoon2.gif', alt: 'Cartoon Image'};
//Pic[2] = { src: 'Graphics/cartoon3.gif', alt: 'Cartoon Image'};
//Pic[3] = { src: 'Graphics/cartoon4.gif', alt: 'Cartoon Image'};
//Pic[4] = { src: 'Graphics/cartoon5.gif', alt: 'Cartoon Image'};
//Pic[5] = { src: 'Graphics/cartoon6.gif', alt: 'Cartoon Image'};
//Pic[6] = { src: 'Graphics/cartoon7.gif', alt: 'Cartoon Image'};

//// Preload the catoon images
//var preLoad = new Array()
//for (var i = 0; i < Pic.length; i++)
//{
//   preLoad[i] = new Image()
//   preLoad[i].src = Pic[i].src
//   preLoad[i].alt = Pic[i].alt
//}

///****
// * Randomly selects a cartoon from the array and updates the page image
// ****/
//function pickCartoon()
//{
//  var idx = randomnumber(0, Pic.length-1);
//  
//  document.getElementById('imgCartoon').src = preLoad[idx].src;
//  document.getElementById('imgCartoon').alt = preLoad[idx].alt;
//}

//function randomnumber(num1, num2)
//{
//	num1 = parseInt(num1);
//	num2 = parseInt(num2);
//  return Math.ceil(Math.random()*(num2-num1));    
//}

//function sendEmailAddress()
//{
//  var emailAddress = document.getElementById('Email').value;
//  var strURL = '/Emails.asp';
//  var params = 'Action=Add&Email='+emailAddress;
//  
//  if( emailAddress != null && emailAddress != '' )
//  {
//	  var xmlhttp = XmlHttpFactory.create();
//	  xmlhttp.open('GET', strURL+'?'+params, false);
//	  xmlhttp.send(null); 
//	  
//	  document.getElementById('Newsletter').innerHTML = ''+
//	      '<div id="newsletterTop" class="newsletterTop" style="z-index: 100">Newsletter</div>'+
//	      xmlhttp.responseText;
//	}
//}

function formatCurrency(num) 
{
  num = num.toString().replace(/\$|\,/g,'');
  if(isNaN(num))
    num = "0";
    
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10)
    cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+','+
  num.substring(num.length-(4*i+3));
  return (((sign)?'':'-') + '&pound;' + num + '.' + cents);
}


//function toggleTerms()
//{
//    var node = document.getElementById('termsDiv');
//    if( node.style.display == 'block')
//        node.style.display='none';
//    else
//        node.style.display='block';
//}

function roundVal(val, places){
	var result = Math.round(val*Math.pow(10,places))/Math.pow(10,places);
	return result;
}
