function openWindow(url,width,height) {
	var availheight=((screen.availHeight-height)/2);
	var availwidth=((screen.availWidth-width)/2);
	winStats='resizable=yes,toolbar=no,status=no,location=no,directories=no,menubar=no,';
	winStats+='scrollbars=yes,width='+width+',height='+height;
	if (navigator.appName.indexOf("Microsoft")>=0) {
		winStats+=',left='+availwidth+',top='+availheight;
	}else{
		winStats+=',screenX='+availwidth+',screenY='+availheight;
	}
	floater=window.open(url,"",winStats)
}

function openWindow(url,width,height,target) {
	var availheight=((screen.availHeight-height)/2);
	var availwidth=((screen.availWidth-width)/2);
	winStats='resizable=yes,toolbar=no,status=no,location=no,directories=no,menubar=no,';
	winStats+='scrollbars=yes,width='+width+',height='+height;
	if (navigator.appName.indexOf("Microsoft")>=0) {
		winStats+=',left='+availwidth+',top='+availheight;
	}else{
		winStats+=',screenX='+availwidth+',screenY='+availheight;
	}
	floater=window.open(url,target,winStats)
}

function termSearch(formName,letter) {
	document.forms[formName].searchText.value = letter+'*';
	document.forms[formName].submit();
}

function showHide(elementID) {
	var target = document.getElementById(elementID);
	if (target.style.visibility == 'hidden') {
		target.style.visibility = 'visible';
	}else if (target.style.visibility == '') {
		target.style.visibility = 'visible';
	}else{
		target.style.visibility = 'hidden';
	}
}

var httpRequest;
//httpRequest = getHTTPObject();

function getHTTPObject(){
  var x=null; 
  try{
    x=new ActiveXObject("Msxml2.XMLHTTP")
  }catch(e){
    try{    
      x=new ActiveXObject("Microsoft.XMLHTTP")
    } catch(oc){
      x=null  
    }
  }
  if(!x && typeof XMLHttpRequest != "undefined") {
    x=new XMLHttpRequest()
  }
  return x;

}

function ajaxManager() {
	var args = ajaxManager.arguments;
	//var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP"): new XMLHttpRequest();
	httpRequest = getHTTPObject();
	
	switch (args[0]) {
		case "load_page":
			if (httpRequest) {
			httpRequest.onreadystatechange = function()
				{
				if (httpRequest.readyState == 4 && httpRequest.status == 200)
					{
					motherElement = document.getElementById(args[3]);
					motherElement.style.visibility = 'visible';
					element = document.getElementById(args[2]);
					element.innerHTML = httpRequest.responseText;
					
					// update shoppingCartNrItems
					document.getElementById('openCart').innerHTML = document.getElementById('openCartHTML').innerHTML;
					
					}
          if (httpRequest.readyState == 2){
					motherElement = document.getElementById(args[3]);
					motherElement.style.visibility = 'visible';
					element = document.getElementById(args[2]);
					element.innerHTML = 'Loading...';
          }          
				}
			httpRequest.open("GET", args[1], true);
			httpRequest.send(null);
			}
			break;
		case "preload":
			ajaxManager('load_js', 'scripts/glide.js');
			break;
    case "evaluate":
 			if (httpRequest) {
			httpRequest.onreadystatechange = function()
				{
				if (httpRequest.readyState == 4 && httpRequest.status == 200)
					{
          //callbackFunction
          eval(args[2]);
 					}
				}
			httpRequest.open("GET", args[1], true);
			httpRequest.send(null);
			}
      break;			
	}	
}

/**
* Shows total Nr of Items (Response as html, could be also xml).
**/
function getTotalNrOfItems(){
  //response = httpRequest.responseXML.documentElement;
  //totalPrice = response.getElementsByTagName('totalPrice')[0].firstChild.data;
  //document.getElementById['shoppingCartNrItems'].innerHTML = httpRequest.responseText;  
  shoppingCartNrItems.innerHTML = httpRequest.responseText;
  
}

function toggleCategory(categoryId) {
	var wrapper = document.getElementById('children_'+categoryId);
	var image = document.getElementById('image_'+categoryId);
	if (wrapper.style.display == 'none' || wrapper.style.display == '') {
		wrapper.style.display = 'block';
		image.src = gfxFolder+'arrow_down.gif';
	}else{
		wrapper.style.display = 'none';
		image.src = gfxFolder+'arrow.gif';
	}	
}

function checkEcatalogue(categoryIdString,formName) {
	var theForm = document.forms[formName];
	var checkedMain = document.getElementById(categoryIdString);
	for (i=0;theForm.length>i;i++){	
		var element = theForm.elements[i];
		var elementid = element.id;
		if (element.id.indexOf(categoryIdString) > -1 && elementid != categoryIdString){
			if (element.checked == true && checkedMain.checked == false) {
				element.checked = false;
				element.disabled = false;
			} else {
				element.disabled = true;
				element.checked = true;
			}
		}
	}
}

function resetEcatalogue(formName) {
	var theForm = document.forms[formName];
	for (i=0;theForm.length>i;i++){
		var element = theForm.elements[i];	
		if (element.type == 'checkbox') {
			element.checked = false;
			element.disabled = false;
		}
	}
}