// JavaScript Document

function getWindowSize(WorH)
     {
     if (parseInt(navigator.appVersion)>3) 
          {
          if (navigator.appName=="Netscape") 
               {
               if(WorH = "H")
                    {
                    return window.innerHeight;
                    }
               else
                    {
                    return window.innerWidth;
                    }
               }
          if (navigator.appName.indexOf("Microsoft")!=-1) 
               {
               if(WorH = "H")
                    {
                    return document.body.offsetHeight;
                    }
               else
                    {
                    return document.body.offsetWidth;
                    }
               }
          }
     }
     
function popUp(URL,boxSize) 
     {
     //browser window size
     winH = getWindowSize('H');
     winW = getWindowSize('W');
     
     //screen resolution
     screenH = screen.height;
     screenW = screen.width;
     
     boxSizes = boxSize.split("x");
     //popup sizes
     popupH = boxSizes[1];
     popupW = boxSizes[0];

     //popup position
     popupPosY = (screenH / 2) - (popupH /2);
     popupPosX = (screenW / 2) - (popupW /2);
     
     
     day = new Date();
     id = day.getTime();
     eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+popupW+",height="+popupH+",left = "+popupPosX+",top = "+popupPosY+"');");
     }


function checkCompareline(id,classname,limit)
     {

     originalLimit = limit;

     limit = ((limit / 2) * 2) + 1; 

     checkamount = (document.getElementById('checkamount').value / 2) * 2;

     checked = document.getElementById('checkbox_'+id).checked;
     
     if(checked == true)
          {
          document.getElementById('checkbox_'+id).checked = false;
          document.getElementById('line_'+id).className = '';
          document.getElementById('checkamount').value = checkamount - 1;
          compileValues('',id,'checkedIds');
          }
     else
          {
          
          if(checkamount < limit)
               {
               document.getElementById('checkbox_'+id).checked = true;
               document.getElementById('line_'+id).className = classname;
               document.getElementById('checkamount').value = checkamount + 1;
               compileValues(id,'','checkedIds');
               }
          else
               {
               alert("Please do not select more than "+originalLimit+" product(s)!");
               }
          }
     
     if(document.getElementById('checkamount').value > 1)
          {
          document.getElementById('submitCompare').disabled = '';
          }
     else
          {
          document.getElementById('submitCompare').disabled = 'disabled';
          }
     }
function checkCompareForm()
     {
     if(document.getElementById('checkamount').value < 2)
          {
          alert("You need to tick products to continue!");
          return false;
          }
     else
          {
          return true;
          }
     }
function compileValues(add,rem,elId)
     {
     currentContent = document.getElementById(elId).value;
     var finalString = currentContent;
     if(rem)
          {
          currentContentArray = currentContent.split(",");
          var newArray = Array();
          i = 0;
          for(c=0;c<currentContentArray.length;c++)
               {
               if(rem != currentContentArray[c])
                    {
                    newArray[i] = currentContentArray[c];
                    i++;
                    }
               }
          finalString = newArray.join(",");
          }
     if(add)
          {
          finalString = finalString + ',' + add;
          }
     document.getElementById(elId).value = finalString;
     }
     
function closeAjaxPopup()
     {
     document.getElementById('ajaxPopupContainer').innerHTML = ''
     }
     
function checkSearch(id)
     {
     if(document.getElementById(id).value == false)
          {
          alert('You must enter a search criteria!');
          return false;
          }
     
     return true;
     }
     
function clickSearchOff(el,defaultValue)
     {
     if(el.value == '')
          {
          el.className = "searchBoxBlur";
          el.value = defaultValue;
          }
     }
     
function clickSearchOn(el,defaultValue)
     {
     if(el.value == defaultValue)
          {
          el.className = "searchBoxFocus";
          el.value = '';
          }
     }

function subCatSelect(catId)
     {
     if(catId)
          {
          window.location = siteRoot+'products/catId-'+catId+'/';
          }
     }

function downloadCatalogue(filename)
     {
     if(filename)
          {
          window.location = filename;
          }
     }

function resizeText(id,direction)
     {

     el = document.getElementById(id);
     
     if(!el.style.fontSize)
          {
          el.style.fontSize = 11+'px';
          }

     if(el.style.fontSize)
          {
          fontsize = parseInt(el.style.fontSize);
          
          if(direction == 'up' && fontsize < 18)
               {
               fontsize = fontsize + 2;
               }
          
          if(direction == 'down' && fontsize > 11)
               {
               fontsize = fontsize - 2;
               }
          
         el.style.fontSize = fontsize+'px';
          }

     }


var message="Ah, Ah, Ah! You don't need to use right click.";

function clickIE4()
     {
     if (event.button==2)
          {
          //alert(message);
          return false;
          }
     }
     
function clickNS4(e)
     {
     if (document.layers||document.getElementById&&!document.all)
          {
          if (e.which==2||e.which==3)
               {
               //alert(message);
               return false;
               }
          }
     }

if (document.layers)
     {
     document.captureEvents(Event.MOUSEDOWN);
     document.onmousedown=clickNS4;
     }
else if (document.all&&!document.getElementById)
     {
     document.onmousedown=clickIE4;
     }
     
if(!al)
     {
     document.oncontextmenu=new Function("return false")
     }


function highlightrow(el)
     {
     var parentEl = el.parentNode;
     window.saveClassName = el.parentNode.className;
     parentEl.className = 'hoverRow'; 
     }

function deHighlightrow(el)
     {
     var parentEl = el.parentNode;
     parentEl.className = window.saveClassName; 
     }

function checkByParent(aId, aChecked) 
     {
     var collection = document.getElementById(aId).getElementsByTagName('INPUT');
     for (var x=0; x<collection.length; x++) 
          {
          if (collection[x].type.toUpperCase()=='CHECKBOX')
            collection[x].checked = aChecked;
          }
     }

function checker(checkId)
     {  
     if(document.getElementById(checkId).checked == true)
          document.getElementById(checkId).checked = '';
     }


function toggleDisplay(id)
     {
  
     if(document.getElementById(id).style.display == 'none')
          {
          document.getElementById(id).style.display = 'block';
          }
     else
          {
          document.getElementById(id).style.display = 'none';
          }
     
     }



function checkRequiredFields(fieldString)
     {
     //string e.g. "Field label1~Field InputId1#Field label2~Field InputId2"   
     fieldArray = fieldString.split('#');
     fieldcount = fieldArray.length;
     returnValue = true;
     for(i=0;i<fieldcount;i++)
          {
          fieldEls = fieldArray[i].split('~');
          fieldLabel = fieldEls[0];
          fieldId = fieldEls[1];
          fieldValue = document.getElementById(fieldId).value;
          if(!fieldValue || fieldValue == 'address@domain.com')
               {
               document.getElementById(fieldId).style.border = '2px solid #9e1b34';

               returnValue = false;
               }
          else
               {
               document.getElementById(fieldId).style.border = '';
               }
          }
     if(returnValue == false)
          {
          alert('You must fill in every required (*) field!');
          }
     return returnValue;
     }



function tableHighlightCross(selCell)
     {
     cellEls = selCell.split("_");
     prefix = cellEls[0];
     column = cellEls[1];
     row = cellEls[2];
     
     currentCell = document.getElementById(selCell);
     currentRow = currentCell.parentNode;
     mainTable =  currentRow.parentNode;
     allCells = mainTable.getElementsByTagName('td');
     
     //reset all cells
     for(i=0;i<allCells.length;i++)
          {
          allCells[i].style.backgroundColor = '';
          allCells[i].style.color = '';
          allCells[i].style.fontWeight = '';
          }

     //highlight colum
     allRows = mainTable.getElementsByTagName('tr');
     totalRows = allRows.length;
     for(i=1;i<totalRows;i++)
          {
          if(i % 2 == 0)
               bgcolor = '#fffde5';
          else
               bgcolor = '#eeebd4';
          
          targetCell = document.getElementById(prefix + '_' + column + '_' + i);
          targetCell.style.backgroundColor = bgcolor;
          }
          
     //highligh the row
     cellsInRow = currentRow.getElementsByTagName('td');
     for(i=0;i<cellsInRow.length;i++)
          {
          cellsInRow[i].style.backgroundColor = '#fff8aa';
          cellsInRow[i].style.color = '#000000';
          }
     currentCell.style.backgroundColor  = '#fdf493';     
     currentCell.style.cursor = 'default';
     currentCell.style.fontWeight = 'bold';
     }

function gotohash(hashLink)
     {
     window.location.hash = hashLink;
     initLightbox();
     }


