﻿/* for Mozilla/Opera9 */
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, false);
}
/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
    if (window.location.protocol != 'https:')
    {
    	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
    	var script = document.getElementById("__ie_onload");
    	script.onreadystatechange = function() {
        	if (this.readyState == "complete") {
            		init(); // call the onload handler
        	}
    		};
    }
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            init(); // call the onload handler
        }
    }, 10)
}

/* for other browsers */
window.onload = init;

/* Golbal scoped vars */
var ProductImage;

/* dom loaded call */
function init() {
    // quit if this function has already been called
	if (arguments.callee.done) return;
// flag this function so we don't do the same thing twice
	arguments.callee.done = true;
// kill the timer
	if (_timer) clearInterval(_timer);
		
  /* Clear inputs */
  inputs = document.getElementsByTagName('input') ;
  for (i = 0; i < inputs.length; i++) {
    if (inputs[i].getAttribute('value')) {
      inputs[i].onfocus = clearIt ;
    }
  }
  
  /* product thumbs */
  if (getElementsByClass('ProductImage', null, 'img')[0]) {
    ProductImage = getElementsByClass('ProductImage', null, 'img')[0] ;
    ProductImage.onclick = open;
    
    ProductImage.style.cursor = 'hand';
    ProductImage.style.cursor = 'pointer';
      	
    extraThumbs = getElementsByClass('extraThumbs', null, 'div')[0] ;
    extraThumbLnk = extraThumbs.getElementsByTagName('a') ;
    for (var i=0; i < extraThumbLnk.length; i++) {
      //extraThumbLnk[i].onmouseover = toggle ;
      extraThumbLnk[i].onclick = toggle ;
    }
  }
  
  /* FAQ Navigation */
  var path = window.location.pathname.toLowerCase() ;
  if (path.indexOf('faq') != -1) {
		
		var h1 = document.getElementsByTagName('h1')[0] ;
		var ul = document.createElement('ul') ;
		ul.className = 'faq' ;
		var h2s = document.getElementsByTagName('h2') ;
		
		for (var i=0; i < h2s.length; i++) {
			var li = document.createElement('li') ;
			ul.appendChild(li) ;
			var lnk = document.createElement('a') ;
			lnk.setAttribute('href', '#faq' + i) ;
			li.appendChild(lnk) ;
			var txt = document.createTextNode(h2s[i].firstChild.data) ;
			lnk.appendChild(txt) ;
			
			var a = document.createElement('a') ;
			a.setAttribute('id', 'faq' + i) ;
			a.appendChild(document.createTextNode(' ')) ;
			h2s[i].appendChild(a) ;
			
			var lnkTop = document.createElement('a') ;
			lnkTop.setAttribute('href', '#top') ;	
			lnkTop.className = 'btnTop' ;
			lnkTop.appendChild(document.createTextNode('Back to top')) ;
			h2s[i].parentNode.appendChild(lnkTop) ;
		}
		
		insertAfter(h1.parentNode, ul, h1) ;
		var aTop = document.createElement('a') ;
		aTop.setAttribute('id', 'top') ;
		var body = document.getElementsByTagName('body')[0] ;
		body.insertBefore(aTop, body.firstChild) ;
  }
  
  
}

/* page functions */
function clearIt() {
  if ((this.value == this.getAttribute('value')) && (this.getAttribute('type') == 'text')) {
    this.value = '' ;
  }
}
function toggle() {
  smlImg = getChild(this) ;
  smlSrc = smlImg.src ;
  lrgSrc = smlSrc.substring(0,smlSrc.lastIndexOf('.')) + ".thumb?w=283";
  ProductImage.src = lrgSrc
  return false;
}
function open() {
  smlSrc = this.src ;
  lrgSrc = smlSrc.substring(0,smlSrc.lastIndexOf('.')) + ".thumb?w=500";
  ShowPopup(lrgSrc,lrgSrc,540,540,true);
  return false;
}

/* common methods */
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function getChild(startParent) {
  EndChild = startParent.firstChild ;
  while(EndChild.nodeType != 1){
    EndChild = EndChild.nextSibling ;
  }
  return EndChild;
}

function insertAfter(parent, node, referenceNode) {
  parent.insertBefore(node, referenceNode.nextSibling);
}