

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
/*
The isEmpty and isWhitespace functions were taken straight from Netscape's JavaScript development site, http://developer.netscape.com.
*/


// whitespace characters
var whitespace = " \t\n\r";

/****************************************************************/

// Check whether string s is empty.
function isEmpty(s)
{ return ((s == null) || (s.length == 0)) }

/****************************************************************/

function isWhitespace (s)
{
   var i;

   // Is s empty?
   if (isEmpty(s)) return true;

   // Search through string's characters one by one
   // until we find a non-whitespace character.
   // When we do, return false; if we don't, return true.

   for (i = 0; i < s.length; i++)
   {
	// Check that current character isn't whitespace.
	var c = s.charAt(i);

	if (whitespace.indexOf(c) == -1) return false;
   }

   // All characters are whitespace.
   return true;
}

/****************************************************************/

function ForceEntry(val, str) {
   var strInput = new String(val.value);

   if (isWhitespace(strInput)) {
	alert(str);
	return false;
   } else
	return true;

}

/****************************************************************/

function CheckSelection(val, str) {
	var isSelected = val.selectedIndex
	if (isSelected == 0) {
		alert(str);
		return false;}
	else{
		return true;
	}
}

function validateEmailForm(theForm) {
	if (theForm.email.value == "")
	{
		alert("Please enter your email address");
		theForm.email.focus();
		return(false);
	}
	else if (!isEmail(theForm.email.value))
	{
		alert("Please enter your email address in the correct format");
		theForm.email.focus();
		return(false);
	}
	return(true);
}
function validateForm(theForm) {
	if (theForm.email.value == "")
	{
		alert("Please enter your email address");
		theForm.email.focus();
		return(false);
	}
	else if (!isEmail(theForm.email.value))
	{
		alert("Please enter your email address in the correct format");
		theForm.email.focus();
		return(false);
	}
	return(true);
}


function isEmail(formInput)
{
	var atpos, dotpos, lastpos;
		apos = formInput.indexOf("@");
		dotpos = formInput.lastIndexOf(".");
		lastpos = formInput.length-1;
		if (apos < 1 || dotpos - apos < 2 || lastpos - dotpos > 3 || lastpos - dotpos < 2)
		{
			return(false);
		}
		return(true);
}

function emailForm_submit()
{	if (document.emailForm.email.value == "")
	{
		alert("Please enter your email address");
		document.emailForm.email.focus();
	}
	else if (!isEmail(document.emailForm.email.value))
	{
		alert("Please enter your email address in the correct format");
		document.emailForm.email.focus();
	}
	else{
	document.emailForm.submit();
	}
}

 
/*function SubmitSearchForm()
{
  var keywords=	document.getElementById("searchTerm").value;
  if(document.getElementById("search_option").checked == true)
  {
   document.location.href="../asp/search.asp?keywords=" + keywords;
  }
  else
  if(document.getElementById("search_option2").checked == true)
  {
   document.location.href="http://www.robusdirect.com/catalogue/search.php?searchterm=" + keywords;
  }
  return true;
}
*/

function SubmitSearchForm()
{
  var keywords=	document.getElementById("searchTerm").value;
  
  if (document.getElementById("search_option").value == "search_option")
  {
   document.location.href="../asp/search.asp?keywords=" + keywords;
  }
  else
  if (document.getElementById("search_option").value == "search_option2")
  {
   document.location.href="http://www.ledgrouprobus.com/catalogue/catalogue/search.php?searchterm=" + keywords;
  }
  return true;
}
/******************************************************************************
/*   Energy Saving Calculator Script - Developed April 2009
/*   amcconnell@led.ie
/*****************************************************************************/
function startCalc(){
  interval = setInterval("calc()",1);
}
function calc(){
  
  //Energy Consumption Calculation - EURO
  hoursperday = document.esrCalculator.HoursPerDay.value;
  daysperweek = document.esrCalculator.DaysPerWeek.value; 
  weeksperyear = document.esrCalculator.WeeksPerYear.value; 
  document.esrCalculator.TotalHrsPerYear.value = ((hoursperday * 1) * (daysperweek * 1) * (weeksperyear * 1));
  
  //Energy Consumption Calculation - POUNDS
  Phoursperday = document.esrCalculator.PHoursPerDay.value;
  Pdaysperweek = document.esrCalculator.PDaysPerWeek.value; 
  Pweeksperyear = document.esrCalculator.PWeeksPerYear.value; 
  document.esrCalculator.PTotalHrsPerYear.value = ((Phoursperday * 1) * (Pdaysperweek * 1) * (Pweeksperyear * 1));
  
  
  //Current Fitting - Energy Cost Per Year
  CFWattage = document.esrCalculator.CF_wattage.value;
  ElectricCost =  document.esrCalculator.ElectricCost.value;
  TotalHoursYear = document.esrCalculator.TotalHrsPerYear.value; 
  document.esrCalculator.CF_EnergyCostYr.value = (((CFWattage *1)*(ElectricCost *1)*(TotalHoursYear *1))/ 1000);
  
  //Current Fitting - Energy Cost Per Year - POUNDS
  PCFWattage = document.esrCalculator.PCF_wattage.value;
  PElectricCost =  document.esrCalculator.PElectricCost.value;
  PTotalHoursYear = document.esrCalculator.PTotalHrsPerYear.value; 
  document.esrCalculator.PCF_EnergyCostYr.value = (((PCFWattage *1)*(PElectricCost *1)*(PTotalHoursYear *1))/ 1000);
  
  //Alt Fitting - Energy Cost Per Year
  AFWattage = document.esrCalculator.AF_wattage.value;
  document.esrCalculator.AF_EnergyCostYr.value = (((AFWattage *1)*(ElectricCost *1)*(TotalHoursYear *1))/ 1000);

  //Alt Fitting - Energy Cost Per Year POUNDS
  PAFWattage = document.esrCalculator.PAF_wattage.value;
  document.esrCalculator.PAF_EnergyCostYr.value = (((PAFWattage *1)*(PElectricCost *1)*(PTotalHoursYear *1))/ 1000);
  
  //Current Fitting Purchase Cost Per Year
  CFPrice = document.esrCalculator.CF_price.value;
  CFGuarantee = document.esrCalculator.CF_guarantee.value;
  CFLampLife = document.esrCalculator.CF_lamplife.value;
  CFPricebyHours = ((CFPrice * 1) * (TotalHoursYear * 1));
  CFGuaranteeByTotalHours = ((CFGuarantee * 1) * (TotalHoursYear * 1));
  CFLampLifeCond = CFLampLife2();
  function CFLampLife2(){ 
  
   if (CFLampLife <= CFGuaranteeByTotalHours){
    CFLampLifeCond = CFGuaranteeByTotalHours;
	}
	else {
	CFLampLifeCond = CFLampLife;
	} 
	return CFLampLifeCond;
	} 
  document.esrCalculator.CF_PurchaseCostYr.value = ((CFPricebyHours * 1)/(CFLampLifeCond * 1));

  //Current Fitting Purchase Cost Per Year  - POUNDS
  PCFPrice = document.esrCalculator.PCF_price.value;
  PCFGuarantee = document.esrCalculator.PCF_guarantee.value;
  PCFLampLife = document.esrCalculator.PCF_lamplife.value;
  PCFPricebyHours = ((PCFPrice * 1) * (PTotalHoursYear * 1));
  PCFGuaranteeByTotalHours = ((PCFGuarantee * 1) * (PTotalHoursYear * 1));
  PCFLampLifeCond = PCFLampLife2();
  function PCFLampLife2(){ 
  
   if (PCFLampLife <= PCFGuaranteeByTotalHours){
    PCFLampLifeCond = PCFGuaranteeByTotalHours;
	}
	else {
	PCFLampLifeCond = PCFLampLife;
	} 
	return PCFLampLifeCond;
	} 
  document.esrCalculator.PCF_PurchaseCostYr.value = ((PCFPricebyHours * 1)/(PCFLampLifeCond * 1));

  // Active Fitting Purchase Cost Per Year
  AFPrice = document.esrCalculator.AF_price.value;
  AFGuarantee = document.esrCalculator.AF_guarantee.value;
  AFLampLife = document.esrCalculator.AF_lamplife.value;
  AFPricebyHours = ((AFPrice * 1) * (TotalHoursYear * 1));
  AFGuaranteeByTotalHours = ((AFGuarantee * 1) * (TotalHoursYear * 1));
  AFLampLifeCond = AFLampLife2();
  function AFLampLife2(){ 
  
   if (AFLampLife <= AFGuaranteeByTotalHours){
    AFLampLifeCond = AFGuaranteeByTotalHours;
	}
	else {
	AFLampLifeCond = AFLampLife;
	} 
	return AFLampLifeCond;
	} 
  document.esrCalculator.AF_PurchaseCostYr.value = ((AFPricebyHours * 1)/(AFLampLifeCond * 1));
  
    // Active Fitting Purchase Cost Per Year ~ POUNDS
  PAFPrice = document.esrCalculator.PAF_price.value;
 PAFGuarantee = document.esrCalculator.PAF_guarantee.value;
  PAFLampLife = document.esrCalculator.PAF_lamplife.value;
  PAFPricebyHours = ((PAFPrice * 1) * (PTotalHoursYear * 1));
  PAFGuaranteeByTotalHours = ((PAFGuarantee * 1) * (PTotalHoursYear * 1));
  PAFLampLifeCond = PAFLampLife2();
  function PAFLampLife2(){ 
  
   if (PAFLampLife <= PAFGuaranteeByTotalHours){
    PAFLampLifeCond = PAFGuaranteeByTotalHours;
	}
	else {
	PAFLampLifeCond = PAFLampLife;
	} 
	return PAFLampLifeCond;
	} 
  document.esrCalculator.PAF_PurchaseCostYr.value = ((PAFPricebyHours * 1)/(PAFLampLifeCond * 1));
  
	// Current Fitting ReLamp Cost Per Year
	CFLampCost = document.esrCalculator.CF_lampcost.value;
	CFRelampInterval = ((TotalHoursYear * 1)/ (CFLampLife *1));
	CFRelampCostYr = CFLampCost2();
	function CFLampCost2() {
		if (CFRelampInterval < 1) {
		CFRelampCostYr = 0;
		}
		else {
		CFRelampCostYr = ((CFRelampInterval * 1)* (CFLampCost *1));
	}
	return CFRelampCostYr;
	}
	document.esrCalculator.CF_RelampCostYr.value = (CFRelampCostYr * 1);

	// Current Fitting ReLamp Cost Per Year - POUNDS
	PCFLampCost = document.esrCalculator.PCF_lampcost.value;
	PCFRelampInterval = ((PTotalHoursYear * 1)/ (PCFLampLife *1));
	PCFRelampCostYr = PCFLampCost2();
	function PCFLampCost2() {
		if (PCFRelampInterval < 1) {
		PCFRelampCostYr = 0;
		}
		else {
		PCFRelampCostYr = ((PCFRelampInterval * 1)* (PCFLampCost *1));
	}
	return PCFRelampCostYr;
	}
	document.esrCalculator.PCF_RelampCostYr.value = (PCFRelampCostYr * 1);
	
//Alternate ReLamp Cost Per Year
AFLampCost = document.esrCalculator.AF_lampcost.value;
AFRelampInterval = ((TotalHoursYear * 1)/ (AFLampLife *1));
AFRelampCostYr = AFLampCost2();
function AFLampCost2() {
if (AFRelampInterval < 1) {
AFRelampCostYr = 0;
}
else {
AFRelampCostYr = ((AFRelampInterval * 1)* (AFLampCost *1));
}
return AFRelampCostYr;
}
document.esrCalculator.AF_RelampCostYr.value = (AFRelampCostYr * 1);

//Alternate ReLamp Cost Per Year - POUNDS
PAFLampCost = document.esrCalculator.PAF_lampcost.value;
PAFRelampInterval = ((PTotalHoursYear * 1)/ (PAFLampLife *1));
PAFRelampCostYr = PAFLampCost2();
function PAFLampCost2() {
if (PAFRelampInterval < 1) {
PAFRelampCostYr = 0;
}
else {
PAFRelampCostYr = ((PAFRelampInterval * 1)* (PAFLampCost *1));
}
return PAFRelampCostYr;
}
document.esrCalculator.PAF_RelampCostYr.value = (PAFRelampCostYr * 1);

// CF Relamp Labour Cost Per Year
	CFLabourCost = document.esrCalculator.CF_labourcost.value; 
 	CFLabourCostYr = CFLabourCost2();
	function CFLabourCost2() {
		if (CFRelampInterval < 1) {
		CFLabourCostYr = 0;
		}
		else {
		CFLabourCostYr = ((CFRelampInterval * 1)* (CFLabourCost *1));
	}
	return CFLabourCostYr;
	}
	document.esrCalculator.CF_RelampLabourCostYr.value = (CFLabourCostYr * 1);
	
	// CF Relamp Labour Cost Per Year - POUNDS
	PCFLabourCost = document.esrCalculator.PCF_labourcost.value; 
 	PCFLabourCostYr = PCFLabourCost2();
	function PCFLabourCost2() {
		if (PCFRelampInterval < 1) {
		PCFLabourCostYr = 0;
		}
		else {
		PCFLabourCostYr = ((PCFRelampInterval * 1)* (PCFLabourCost *1));
	}
	return PCFLabourCostYr;
	}
	document.esrCalculator.PCF_RelampLabourCostYr.value = (PCFLabourCostYr * 1);

	// AF Relamp Labour Cost Per Year
	AFLabourCost = document.esrCalculator.AF_labourcost.value; 
 	AFLabourCostYr = AFLabourCost2();
	function AFLabourCost2() {
		if (AFRelampInterval < 1) {
		AFLabourCostYr = 0;
		}
		else {
		AFLabourCostYr = ((AFRelampInterval * 1)* (AFLabourCost *1));
	}
	return AFLabourCostYr;
	}
	document.esrCalculator.AF_RelampLabourCostYr.value = (AFLabourCostYr * 1);
	
		// AF Relamp Labour Cost Per Year = POUNDS
	PAFLabourCost = document.esrCalculator.PAF_labourcost.value; 
 	PAFLabourCostYr = PAFLabourCost2();
	function PAFLabourCost2() {
		if (PAFRelampInterval < 1) {
		PAFLabourCostYr = 0;
		}
		else {
		PAFLabourCostYr = ((PAFRelampInterval * 1)* (PAFLabourCost *1));
	}
	return PAFLabourCostYr;
	}
	document.esrCalculator.PAF_RelampLabourCostYr.value = (PAFLabourCostYr * 1);
	
	// CF Cost of Ownership Per Year
	CFEnergyCostYr = document.esrCalculator.CF_EnergyCostYr.value;
	CFPurchaseCostYr = document.esrCalculator.CF_PurchaseCostYr.value;
	document.esrCalculator.CF_Ownership.value = ((CFEnergyCostYr * 1)+(CFPurchaseCostYr * 1)+(CFRelampCostYr * 1)+(CFLabourCostYr * 1));
	
	// CF Cost of Ownership Per Year - POUNDS
	PCFEnergyCostYr = document.esrCalculator.PCF_EnergyCostYr.value;
	PCFPurchaseCostYr = document.esrCalculator.PCF_PurchaseCostYr.value;
	document.esrCalculator.PCF_Ownership.value = ((PCFEnergyCostYr * 1)+(PCFPurchaseCostYr * 1)+(PCFRelampCostYr * 1)+(PCFLabourCostYr * 1));
	
	// AF Cost of Ownership Per Year
	AFEnergyCostYr = document.esrCalculator.AF_EnergyCostYr.value;
	AFPurchaseCostYr = document.esrCalculator.AF_PurchaseCostYr.value;
	document.esrCalculator.AF_Ownership.value = ((AFEnergyCostYr * 1)+(AFPurchaseCostYr * 1)+(AFRelampCostYr * 1)+(AFLabourCostYr * 1));
	
	// AF Cost of Ownership Per Year - POUNDS
	PAFEnergyCostYr = document.esrCalculator.PAF_EnergyCostYr.value;
	PAFPurchaseCostYr = document.esrCalculator.PAF_PurchaseCostYr.value;
	document.esrCalculator.PAF_Ownership.value = ((PAFEnergyCostYr * 1)+(PAFPurchaseCostYr * 1)+(PAFRelampCostYr * 1)+(PAFLabourCostYr * 1));
	
	//Savings By Fitting Per Year
	CFOwnership = document.esrCalculator.CF_Ownership.value;
	AFOwnership = document.esrCalculator.AF_Ownership.value;
	document.esrCalculator.SavingsFittingYr.value = ((CFOwnership * 1)-(AFOwnership * 1));
	
	//Savings By Fitting Per Year - POUNDS 
	PCFOwnership = document.esrCalculator.PCF_Ownership.value;
	PAFOwnership = document.esrCalculator.PAF_Ownership.value;
	document.esrCalculator.PSavingsFittingYr.value = ((PCFOwnership * 1)-(PAFOwnership * 1));
	
	//TOTAL SAVINGS PER YEAR
	SavingsFittingYr = document.esrCalculator.SavingsFittingYr.value;
	TotalNoLamps = document.esrCalculator.TotalNoLamps.value;
	document.esrCalculator.TotalSavingsYr.value = ((SavingsFittingYr * 1)*(TotalNoLamps * 1));
	
	//TOTAL SAVINGS PER YEAR - POUNDS
	PSavingsFittingYr = document.esrCalculator.PSavingsFittingYr.value;
	PTotalNoLamps = document.esrCalculator.PTotalNoLamps.value;
	document.esrCalculator.PTotalSavingsYr.value = ((PSavingsFittingYr * 1)*(PTotalNoLamps * 1));


/***********************************************************************************************
	//PAYBACK PERIOD YEARS 
	FPriceDiff = ((AFPrice * 1)-(CFPrice * 1));
	EnergyCostDiff = ((
	
	document.esrCalculator.PaybackPeriodYrs.value = ((FPriceDiff * 1))/);
************************************************************************************************/			
}
function stopCalc(){
  clearInterval(interval);
}	
//April 2009 - Getting the currency to format correctly
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)?'':'-') +  num + '.' + cents);
}

/******************************************************************************
/*   END OF Energy Saving Calculator Script - Developed April 2009
/*   amcconnell@led.ie
/*****************************************************************************/

/******************************************************************************
/* CSS POP-UP WINDOW SCRIPT - Developed June 2009
/* amcconnell@led.ie
/*****************************************************************************/
function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}
// Pop-Up default code
function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-300;//150 is half popup's height
	popUpDiv.style.top = popUpDiv_height + 'px';
}
function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/2-555;//150 is half popup's width
	popUpDiv.style.left = window_width + 'px';
}
// end of default code


function popup(windowname) {
	blanket_size(windowname);
	window_pos(windowname);
	toggle('blanket');
	toggle(windowname);		
}
/******************************************************************************
/* End of CSS POP-UP WINDOW SCRIPT - Developed June 2009
/* amcconnell@led.ie
/*****************************************************************************/

    function HTMLEncode(str){
     var aStr = str.split(''),
         i = aStr.length,
         aRet = [];

     while (--i) {
      var iC = aStr[i].charCodeAt();
       if (iC < 65 || iC > 127 || (iC>90 && iC<97)) {
        aRet.push('&#'+iC+';');
       } else {
        aRet.push(aStr[i]);
       }
    }
    return aRet.reverse().join('');
   }

