
sfHover = function() {
	var sfEls = document.getElementById("hoofdnavigatie").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

// Open de infopopup
function OpenInfoPopup(strHREF)
{
	//var strSeperator = (strHREF.indexOf('?')>0)?'&':'?';
	// + strSeperator 
	window.open(strHREF + '','Information','location=no, status=no, toolbar=no,width=727, height=680'); 
	return false;
}

// Check if window focus is lost()
function focusLost(strEl, strElValue)
{
	var oEl = document.getElementById(strEl);
	if(oEl != undefined){
		if(oEl.value == ""){
			oEl.value = strElValue;
		}
	}
}

//openen popup window
function OpenAWindow(AURL,AAttr) {
  AWindow=window.open(AURL,window.name+"X",AAttr);
  if(parseInt(navigator.appVersion)>=3) AWindow.focus();
  return false;
}

//submenu tonen en verbergen
function toggleSubmenu(strSubmenu) {
	var elems = document.getElementById('groep_subnavigatie').getElementsByTagName("UL");

	for (var j=0; j<elems.length; j++) {
		if (elems[j].id == strSubmenu) {		
			if (elems[j].style.display == 'block')
				elems[j].style.display = 'none';
			else
				elems[j].style.display = 'block';
		} else {
			elems[j].style.display = 'none';
		}
	}
}

//tonen van een foto bij een product
function showFoto(strFotoNr, intNr, intTabNr, intProductID, strTypeFoto) {
	var elemFoto = document.getElementById('foto_visual');
	var elemTabs = document.getElementById('productfotos').getElementsByTagName('A');
	var elemFilmpje = document.getElementById('filmpje');

	// Variabelen instellen
	strType	=	strTypeFoto;
	intWaarde = intProductID;
	intFotoNr = intNr;
	
	// Foto tabjes bijwerken
	for (var i = 0; i < elemTabs.length; i++) {
		if (elemTabs[i].id == 'foto_tab_'+intTabNr) {
			elemTabs[i].className = 'ACTIVE';
		} else {
			elemTabs[i].className = '';
		}
	}
	
	// Foto source instellen
	if(elemFoto!=undefined){
			elemFoto.style.visibility = "visible";
			elemFoto.style.display = "block";
	}

	//instellen filmpje layer
	if(elemFilmpje!=undefined){
			elemFilmpje.style.visibility = "hidden";
			elemFilmpje.style.display = "none";
	}

	if(elemFoto!=undefined){
		if (strType == 'families') {
			elemFoto.src = '/data/families/normaal/' + strFotoNr + '_' + intNr + '.jpg';
		} else if (strType == 'producten') {
			elemFoto.src = '/data/producten/normaal/' + strFotoNr + '_' + intNr + '.jpg';
		}
	}
}

//tonen van een filmpje bij een product
function showFilmpje(strFilmID, intNr, intTabNr) {
	var elemFoto		= document.getElementById('foto_visual');
	var elemTabs		= document.getElementById('productfotos').getElementsByTagName('A');
	var elemFilmpje = document.getElementById('filmpje');

	// Variabelen instellen
	intWaarde = strFilmID;
	intFotoNr = intNr;
	
	// Foto tabjes bijwerken
	for (var i = 0; i < elemTabs.length; i++) {
		if (elemTabs[i].id == 'foto_tab_'+intTabNr) {
			elemTabs[i].className = 'ACTIVE';
		} else {
			elemTabs[i].className = '';
		}
	}
	
	// Foto source instellen
	if(elemFoto!=undefined){
			elemFoto.style.visibility = "hidden";
			elemFoto.style.display = "none";
	}

	//Show filmpje layer
	if(elemFilmpje!=undefined){
			elemFilmpje.style.visibility = "visible";
			elemFilmpje.style.display = "block";
	}
}

//tonen van een grote foto popup
function showGroteFoto() {
	if (strType == 'producten') {
		return OpenAWindow('/popup/grote-foto.asp?intProductID='+intWaarde+'&intFotoNr='+intFotoNr, 'width=640,height=520,status=no');
	} else if (strType == 'families') {
		return OpenAWindow('/popup/grote-foto.asp?intFamilieID='+intWaarde+'&intFotoNr='+intFotoNr, 'width=640,height=520,status=no');
	}
}

/* -- FUNCTION -------------
* tonen verbergen element -- */
function showHideElement(strEl){
	var oEl = document.getElementById(strEl);
	if(oEl != undefined){
		if(oEl.style.visibility == "hidden"){
			oEl.style.visibility = "visible";
			oEl.style.display = "block";
		}
		else if(oEl.style.visibility == "visible"){
			oEl.style.visibility = "hidden";
			oEl.style.display = "none";
		}
		else{
			oEl.style.visibility = "hidden";
			oEl.style.display = "none";
		}
	}
	else{
		alert(oEl + " is undefined");
	}
}

function zetVeldDoeActie(strForm, strVeld, strVeldWaarde, blnDoeAktie)
{	
	var oVeld  = document.getElementById(strVeld);
	if(oVeld!=undefined){
		oVeld.value = strVeldWaarde;
		if(blnDoeAktie==true){
			document.getElementById(strForm).submit();
		}
	}
	return false;
}


/* -- VIDEO POPUP -- */
function ShowPopUp(strPopUp, strConfig, oPlayer )
{
	setMaskSize("popupMask");
	toggleVisibility('popupMask', true);
	toggleVisibility(strPopUp, true);

	var oSWFObject = new SWFObject("/flash/flowplayer/FlowPlayer.swf", "flashHighResPlayer", "100%", "575", "9", "#ffffff");
	oSWFObject.addParam("wmode", "opaque");
	oSWFObject.addParam("allowScriptAccess", "always");
	oSWFObject.addVariable("config", "{hideControls:true, playList: [ { url: '"+strConfig+"' } ], initialScale: 'scale', autoPlay:true }");
	oSWFObject.write("flashVideoPlayer");

	return false;
}	
/* -- // VIDEO POPUP -- */

/* -- VOORRAAD REMINDER POPUP -- */
function showVoorraadReminderInvoer(strPopup, strFrm, intProductNr){

	setMaskSize("popupMask");
	toggleVisibility('popupMask', true);
	toggleVisibility(strPopup, true);
	getVoorraadReminderForm(strFrm);
	
	//zetVeldDoeActie(strFrm, 'intProductNr', intProductNr, false);
	//zetVeldDoeActie(strFrm, 'strActie', 'init', false);
	document.frmVoorraadReminder.intProductNr.value = intProductNr;
	document.frmVoorraadReminder.strActie.value = 'init';

	return false;
}

function getVoorraadReminderForm(strFrm){
		new AJAX.Request("/ajax/voorraad-reminder-handler.asp"
		, {parameters:FORM.toString(strFrm)
		,	responseEl:"elVoorraadReminderContent"
		, preloader:false
		, responseType:"html"
	});

	var oEl = document.getElementById('elVoorraadReminderContent');
	if(oEl!=undefined){oEl.innerHTML="";}
}

function opslaanVoorraadReminder(strFrm){

	new AJAX.Request("/ajax/voorraad-reminder-handler.asp"
		, {parameters:FORM.toString(strFrm)
		,	responseEl:"elVoorraadReminderContent"
		, preloader:false
		, responseType:"html"
	});

}

/* -- // VOORRAAD REMINDER POPUP -- */


/* -- POPUP-ALGEMEEN -- */
function hidePopUp(strPopUp)
{
	setMaskSize("popupMask");
	toggleVisibility('popupMask', false);
	toggleVisibility(strPopUp, false);						
	return false;
}	

// Element zichtbaarheid switchen
function toggleVisibility(elemName, blnVisible) {
	var elem = document.getElementById(elemName);
	if (elem != undefined) {
		if (blnVisible == true) {
			elem.style.display = 'block';
		} else {
			elem.style.display = 'none';
		}
	}
	return false;
}

function setMaskSize(divMaskName)
{
	var theBody = document.getElementsByTagName("BODY")[0];
			
	var fullHeight = getViewportHeight();
	var fullWidth = 0; //getViewportWidth();
	
	// Determine what's bigger, scrollHeight or fullHeight / width
	if (fullHeight > theBody.scrollHeight) {
		popHeight = fullHeight;
	} else {
		popHeight = theBody.scrollHeight;
	}
	
	if (fullWidth > theBody.scrollWidth) {
		popWidth = fullWidth;
	} else {
		popWidth = theBody.scrollWidth;
	}
	
	var gPopupMask = document.getElementById(divMaskName);
	
	gPopupMask.style.height = (popHeight+20) + "px";
	gPopupMask.style.width = "100%";
	//gPopupMask.style.width = popWidth + "px";
}

function getViewportHeight()
{
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 

	return window.undefined; 
}
/* -- POPUP-ALGEMEEN -- */



/* -- popup catalogus 2008 -- */

var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
}

//tonen filters
var _activeFilter = "";
function showFilter(filter){
	_activeFilter != "" ? jQuery('#'+_activeFilter).hide() : null;
	jQuery('#'+filter).show();
	_activeFilter = filter;
	return false;
}

function hideFilter(filter){
	_activeFilter != "" ? jQuery('#'+_activeFilter).hide() : null;
	_activeFilter = "";
	return false;
}

function resetPrijsFilter(form, contentPlaceholder, filter, sliderID){
	var sliderWidget = jQuery("#"+sliderID);
	sliderWidget.slider("values", 0, sliderWidget.slider( "option", "min" ));
	sliderWidget.slider("values", 1, sliderWidget.slider( "option", "max" ));
	jQuery("#frmFilters input[name="+filter+"]").val('_@ll_');
	jQuery( "#prijs_filter_waarde" ).html( "&euro;&nbsp;" + formatCurrency(sliderWidget.slider( "values",0 )) + "&nbsp;-&nbsp;"+ formatCurrency(sliderWidget.slider( "values",1 )) );
	setFiltersVoorUrl();
	sendAjax(form, contentPlaceholder);
	return false;
}

function uncheckFilter(filterName, filterValue, form, contentPlaceholder){
	jQuery('input[name='+filterName+']:checkbox[value='+filterValue+']').removeAttr('checked');
	if(jQuery('input[name='+filterName+']:checkbox:checked').length == 0){
		jQuery('input[name='+filterName+']:checkbox').first().attr('checked','checked');
	}
	setFiltersVoorUrl();
	sendAjax(form, contentPlaceholder);
	return false;
}

function setFilter(form, filter, contentPlaceholder, checkboxChecked){
	if(checkboxChecked.value=="_@ll_"){
		jQuery('input[name='+checkboxChecked.name+']:checkbox').not(checkboxChecked).removeAttr('checked');
	}
	else{
		jQuery('input[name='+checkboxChecked.name+']:checkbox').first().removeAttr('checked');
	}
	
	if(jQuery('input[name='+checkboxChecked.name+']:checkbox:checked').length == 0){
		jQuery('input[name='+checkboxChecked.name+']:checkbox').first().attr('checked','checked');
	}
	setFiltersVoorUrl();
	sendAjax(form, contentPlaceholder);
}

function setFiltersVoorUrl(){
	var urlFilterString = "";
	var first = true;
	var oLevertijdFilter = jQuery("input[name='strFilterLevertijd']:checkbox:checked");
	if(oLevertijdFilter.length>0 && oLevertijdFilter[0].value!="_@ll_"){
		first == true ? urlFilterString += "#" : urlFilterString += "&";
		urlFilterString += "strFilterLevertijd="
		oLevertijdFilter.each(function(){
			urlFilterString += this.value +","
		});
		first = false;
	}
	
	var oMerkFilter = jQuery("input[name='strFilterMerk']:checkbox:checked");
	if(oMerkFilter.length>0 && oMerkFilter[0].value!="_@ll_"){
		first == true ? urlFilterString += "#" : urlFilterString += "&";
		urlFilterString += "strFilterMerk="
		oMerkFilter.each(function(){
			urlFilterString += this.value +","
		});
		first = false;
	}

	var oPrijsFilter = jQuery("input[name='strFilterPrijs']");
	if(oPrijsFilter[0].value!="" && oPrijsFilter[0].value!="_@ll_"){
		first == true ? urlFilterString += "#" : urlFilterString += "&";
		urlFilterString += "strFilterPrijs=" + oPrijsFilter[0].value;
		first = false;
	}
	//console.log(urlFilterString);
	window.location.hash = urlFilterString;

}

function getFiltersInUrl(form, contentPlaceholder){
	if(window.location.hash!="" && window.location.hash!="#"){
		var hash = window.location.hash.substring(1,window.location.hash.length);
		var arrParams = hash.split('&');
		if(arrParams.length>0){
			sendAjax(form, contentPlaceholder);
		}
		/*for (var i=0; i<arrParams.length ; i++)
		{
			var arrParamValues = arrParams[i].split('='); 
			for (var j=0; j<arrParamValues.length ; j++){
				//console.log(arrParamValues[1]);
			}
		}*/
	}
}

var _activeAjaxRequest = null;
function sendAjax(form, contentPlaceholder){
	if(_activeAjaxRequest!=null){
		_activeAjaxRequest.abort();
		//console.log(_activeAjaxRequest);
	}
	_activeAjaxRequest = jQuery.ajax({
		url: '/ajax/filter-handler.asp'
		,data: jQuery('#'+form).serialize()
		,cache: false
		,type: 'POST'
		,dataType: 'html'
		,success: function(data, textStatus, jqXHR){
			jQuery('#'+contentPlaceholder).html(data);
		}
		,error: function(jqXHR, textStatus, errorThrown){
			jQuery('#'+contentPlaceholder).html('<div>error</div>');	
		}
		,beforeSend:function(jqXHR, settings){
			jQuery('#'+contentPlaceholder).html('<div>laden</div>');
			//hideFilter(filter);
		}
	});	
}

jQuery(
	function (){
		jQuery('.filter_opties').mouseleave(function(){hideFilter(this.id)});
		getFiltersInUrl('frmFilters', 'content_families');
	}
);

function formatCurrency(value){
	value = value.toString();
	var a = value.split(".");
	if(a.length>1){
		if(a[1].length==1){
			value+="0";
		}
	}
	else if(a.length==1){
		value+=".00";
	}
	return value.replace(".",",");
}
