if (top.location.href != self.location.href)
  top.location.href=self.location.href;

var ie4=document.all;
var ns6=document.getElementById&&!document.all;
var strPrevious="";

function fnWriteMenu2(arrFilenames, arrNames)
{
  var strWrite="<div class='pad5' onmouseover=\"fnMenuSwitch('inline');\"><ul style='margin-left: 20px; padding: 0px; line-height: 1.5em;'>";
  
  for (var intIndex = 0 ; intIndex < arrFilenames.length ; intIndex++)
     strWrite += "<a href='"+arrFilenames[intIndex]+"' onmouseover=\"fnMenuSwitch('inline');\" onmouseout=\"fnMenuSwitch('inline');\"><li>"+arrNames[intIndex]+"</li></a>";
   
  fnFindBrowserObject('subMenu').innerHTML = strWrite + "</ul></div>";
  fnMenuSwitch('inline');
}


function fnMenuSwitch(strObject)
{ 
  if (strPrevious!="")
    fnFindBrowserStyle(fnFindBrowserObject(strPrevious)).display="none"; 
  
  //alert(strObject);
  fnFindBrowserStyle(fnFindBrowserObject(strObject)).display="inline"; 
  
  strPrevious = strObject;  
}


function fnMenuOff()
{
   if (strPrevious!="")
    fnFindBrowserStyle(fnFindBrowserObject(strPrevious)).display="none"; 
   strPrevious="";
}


function fnCheckFormElement(objFormElement, objTD1, objTD2)
{
  if (objFormElement.value=='')
  {
    fnFindBrowserStyle(fnFindBrowserObject(objTD1)).backgroundColor='#EE931D';
    fnFindBrowserStyle(fnFindBrowserObject(objTD2)).backgroundColor='#EE931D';
    objFormElement.focus();
    return(false);
  }
  else
  {
    fnFindBrowserStyle(fnFindBrowserObject(objTD1)).backgroundColor='white';
    fnFindBrowserStyle(fnFindBrowserObject(objTD2)).backgroundColor='white';
    return(true);
  }  
}


function calculateprice()
{        
  total = 0.00;
  TotalQuicks = 0.00;
  TotalExist = 0.00;
  totalPercent = 0;
  
  intCount = 0;
  
  for (index = 1 ; index<document.frmCalc.txtPrice.length ; index++)
  {
    if (document.frmCalc.txtPrice[index].value!="")
    {      
      TotalQuicks += (document.frmCalc.qprice[index].value*document.frmCalc.usage[index].value);
      TotalExist += (document.frmCalc.txtPrice[index].value*document.frmCalc.usage[index].value);
      intCount++;
    }      
  }
  
  if (intCount<5)
  {
    fnFindBrowserObject('savingDisplay').innerHTML = "<h4 style='color: red;'>Sorry</h4><br/>You must enter five or more prices of products you use annually. You have entered "+intCount+" ";
    fnFindBrowserObject('savingDisplay').innerHTML += (intCount==1) ? " product." : " products.";
  }
  else
  {
    total = TotalExist - TotalQuicks;
  
    //alert("Total: "+total+"\nTotal Quicks:"+TotalQuicks+"\nPlus: "+document.frmCalc.qprice[index].value*document.frmCalc.usage[index].value+"\nTotal Entered"+TotalExist+"\nPlus entered: "+document.frmCalc.txtPrice[index].value*document.frmCalc.usage[index].value)
  
    totalPercent = parseInt(100 - ((100/TotalExist)*TotalQuicks));
    
    //document.frmCalc.savedtotal.value = "£" + total.toFixed(2);
    if (total < 0)
      fnFindBrowserObject('savingDisplay').innerHTML = "<h4>Congratulations</h4><br/>We are unable to save you any money on the group of items that you selected at this time. Perhaps you would like to try a different combination of products or return at a later date to check out our pricing again. In the meantime thank you for your interest in Quicks.<br/><br/>";
    else
      fnFindBrowserObject('savingDisplay').innerHTML = "<h4>Quicks will save you &pound;"+total.toFixed(2)+" which is an overall saving of "+totalPercent+"%</h4><br/><br/><strong>To save more on your office supplies <a href='contactus.php'>contact us</a>.</strong><br/><br/>";
  }
}


function fnSavingCheckQuantity(intValue)
{
  intValue=parseInt(intValue)
  
  if (isNaN(intValue)) 
    intValue = 1;
  
  return(intValue);
}


function parseCurrency(fltValue)
{
  fltValue = parseFloat(fltValue)
  
  if (isNaN(fltValue))
    return("");
  else  
    return (fltValue.toFixed(2));
}


function fnFindBrowserObject(objIdent)
{ return (ie4 ? eval(objIdent) : ns6 ? document.getElementById(objIdent) : ns4 ? document.objIdent : ""); }

function fnFindBrowserStyle(objIdent)
{ return ((ie4||ns6) ? objIdent.style : objIdent); }