

function toggleDisplay(elementId)
{
	var elem = document.getElementById(elementId);
	
	if (elem.style.display == 'none')
	{
		elem.style.display = 'block';
	} else {
		elem.style.display = 'none';
	}
}

function doSearchResults()
	{
		var form = document.getElementById('search');
		
		var oldTarget = form.target;
		var oldAction = form.action;
		
		form.target='searchResultsPreview';
		form.action='search_results_preview.php';
		
		form.submit();
		form.target=oldTarget;
		form.action=oldAction;
//		alert(gatherFormData(form));
		
		return true;
	}

// Form Functions  v1.0
// documentation: http://www.dithered.com/javascript/form/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)


// Convert a list of strings into a 'get' query string
function makeSearchString() {
   var args = makeSearchString.arguments;
   var searchString = "?";
   var pair;
   for (var i = 0; i < args.length; i++) {
      pair = escape(args[i++]) + "=";
      pair += escape(args[i]);
      searchString += pair + "&";
   }
   return searchString.substring(0, searchString.length - 1);
}


// Create a 'get' query string with the data from a given form
function gatherFormData(form) {
   var formData = '';
   var element;
   
   // For each form element, extract the name and value
   for (var i = 0; i < form.elements.length; i++) {
      element = form.elements[i];
      if (element.type == "text" || element.type == "password" || element.type == "textarea") formData += "'" + element.name + "', '" + escape(element.value) + "', ";
      else if (element.type.indexOf("select") != -1) {
         for (var j = 0; j < element.options.length; j++) {
            if (element.options[j].selected == true) formData += "'" + element.name + "', '" + element.options[element.selectedIndex].value + "', ";
         }
      }
      else if (element.type == "checkbox" && element.checked) formData += "'" + element.name + "', '" + element.value + "', ";
      else if (element.type == "radio" && element.checked == true) formData += "'" + element.name + "', '" + element.value + "', ";
   }
   
   // Feed strings to makeSearchString() to do 'get' query string conversion
   return (eval("makeSearchString(" + formData.substring(0, formData.length - 2) + ")"));
}


startList = function() {
	if (document.all&&document.getElementById) 
	{
		elems = getElementsByClass(document, "nav.", "UL");	// gets: ul.nav1  ul.nav2  ul.nav3
		
		for (j=0; j<elems.length; j++)
		{
			navRoot = elems[j];
			
			for (i=0; i<navRoot.childNodes.length; i++) 
			{
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") 
				{
					node.onmouseover=function()  {
						
						this.className+=" over";
						return true;
					}
					
					
					node.onmouseout=function() {
						this.className=this.className.replace(" over", "");
						return true;
					}
					
				}
			}
		}
	}
}


document.onSaveForComparisonClick = function(theLink, productId, productName)
{
	theLink.innerHTML = 'Saved for session';
	theLink.className = 'savedForComparison';
	theLink.onClick = undefined;
	

	window.commandFrame.location = 'save_for_comparison.php?product_id=' + productId;
	
	
	if (document.getElementById)
	{
		var savedProductsList = document.getElementById('savedProductsList');
		
		if (savedProductsList)
		{
			

			if (savedProductsList.firstChild.className == "none")
			{
				savedProductsList.removeChild(savedProductsList.firstChild);
			}
			
			var newItem = document.createElement('li');
			var newItemText = document.createTextNode(productName);
			
			newItem.appendChild(newItemText);
			
			savedProductsList.appendChild(newItem);
			
		}
	}
		
/*		alert(theLink.innerHTML);
		alert(productId);
*/

		
}

document.onRemoveForComparisonClick = function(theLink, productId)
{
	theLink.onClick = undefined;
	
	window.commandFrame.location = 'remove_for_comparison.php?product_id=' + productId;
	
		
/*		alert(theLink.innerHTML);
		alert(productId);
*/

		
}



function getElementsByClass(node,searchClass,tag) {
	var classElements = new Array();
	var els = node.getElementsByTagName(tag); // use "*" for all elements
	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 getWindowHeight() {
	var windowHeight=0;
	if (typeof(window.innerHeight)=='number') 
	{
		windowHeight=window.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) 
		{
			windowHeight = document.documentElement.clientHeight;
		} else {
		
			if (document.body&&document.body.clientHeight) 
			{
				windowHeight=document.body.clientHeight;
			}
		}
	}
	
	return windowHeight;
}

function setLayout()
{
	if (document.getElementById)
	{
		var header = document.getElementById('header');
		var content = document.getElementById('content');
		var footer = document.getElementById('footer');
		
		var windowHeight = getWindowHeight();
		
		if (windowHeight > 0)
		{
			content.style.height = "auto";
		
			var allHeight = header.offsetHeight + content.offsetHeight + footer.offsetHeight;
			
			if (allHeight < windowHeight)
			{
				content.style.height = (windowHeight - (header.offsetHeight + footer.offsetHeight)) + "px";
			}
		}
	}
}

onLoadFunction = function() {
	
	setLayout();
	
	window.onresize = function()
	{
		setLayout();
	}
	
	
	
//	startList();
/*
	var elems = getElementsByClass(document, 'saveForComparison', 'a');
	var i;
	for (i=0; i<elems.length; i++)
	{
			elems[i].onClick = function()
			{
				onSaveForComparisonClick(this, productId
			}
	}
*/
}
window.onload=onLoadFunction;
	
function getElementsByClass(node,searchClass,tag) {
	var classElements = new Array();
	var els = node.getElementsByTagName(tag); // use "*" for all elements
	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;
}

var popUpWin=0;
function popUpWindow(URLStr)
{ 
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = window.open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no');
}


function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}