/*
switchVis switches visibility, using the display property.
using the display property the element doesn't take any screen space.
*/
function switchVis(idName){	
	var el = document.getElementById(idName);
	if( el.style.display != 'none' )
		el.style.display = 'none';
	else
		el.style.display = '';
}



function getSelectValue(el){
	return el.options[el.selectedIndex].value; 
}

/*
function removes the last portion of a path string
assumes a document.location.href
http://www.domain.nl/shop/test/file.asp results in file.asp results in 
*/
function removeFileName(path){
	//reverse the string
	var revPath = path.split("").reverse().join("");
	//return first part of the string until the last slash
	return path.substring(0,revPath.length-revPath.indexOf("/"));
}


/*
function removes a selected option from the select list.
*/
function remOption(sel){
	for(i=0;i<sel.options.length;i++){
		if(sel.options[i].selected)
			sel.options[i] = null;	
	}
}

/*
function adds a selected option to the select list.
*/
function addOption(sel, strText, strValue){	
	sel.options[sel.options.length] =  new Option(strText,strValue, false);
	return false;
}

function resizeImage(img, maxheight, maxwidth){		
	var newImg = new Image();
	newImg.src = img.src;
	
	//find out what to adjust, height or width		
	if(newImg.height > newImg.width){			
		//if height is leading: adjust width
		img.width = (maxheight / newImg.height) * newImg.width;
	}
	else{
		//if width is leading: adjust height
		img.height = (maxwidth / newImg.width) * newImg.height;
	}		
}

var navClicked = false;
function nav(page, keywords, params, direction, totalItems){
	if(navClicked == false){
		navClicked = true;
		document.getElementById('btnNext').disabled = true;
		document.getElementById('btnBack').disabled = true;
		url = "default.asp?pt=catalogus&pagenr="+page+"&direction="+direction+"&keywords="+keywords+""+params+"&total="+totalItems;		
		document.location.href = url;
	}
}

function searchKeyWords(sId){
	var sKeywords = document.getElementById(sId).value;
	document.location.href='default.asp?pt=catalogus&keywords='+sKeywords;
	return false;
}

function handleEnter(event,sInputId) {
  var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
 if (keyCode == 13) {
   if(sInputId == 'searchBox') searchKeyWords(sInputId);
 }
 return false;
}

function isNumber(input)
{
	if(input.value.length > 0 && !input.value.match(/^[0-9]+$/g))
	{
	   input.value = input.value.replace(/[^0-9]*/g,'');
	}
}

function isNumberFraction(input)
{
	if(input.value.length > 0 && !input.value.match(/^[0-9,]+$/g))
	{
//	   input.value = input.value.replace(/[^0-9.,]*/g,'');
	   input.value = input.value.replace(/[^0-9,]*/g,'');
	}
}