// Top search bar
jQuery(document).ready(function() {
	jQuery('#TopSearchBar').focus(function() {
		if ( jQuery('#TopSearchBar').val() == "Merk, product, typenummer" ) {
			jQuery('#TopSearchBar').val("");
			jQuery('#TopSearchBar').css("color","#000");		
			jQuery('#TopSearchBar').css("font-style","normal");		
		}
	});
	
	jQuery('#TopSearchBar').blur(function() {
		if ( jQuery('#TopSearchBar').val() == "" ) {
			jQuery('#TopSearchBar').val("Merk, product, typenummer");
			jQuery('#TopSearchBar').css("color","#CFD1D2");		
			jQuery('#TopSearchBar').css("font-style","italic");		
		}
	});
	
	options = {
		serviceUrl:'/cat/front/ajax-list.asp?rand_no='+Math.random(),
		minChars:3,
		width:300,
		zIndex: 9999
	};
	jQuery('#TopSearchBar').autocomplete(options);	
});


// function checkSearchFrm () {
	// if  ( jQuery('#TopSearchBar').val() == "Merk, product, typenummer" || jQuery('#TopSearchBar').val() == "" ) {
		// alert("Geef een geldige zoek opdracht op");
		// jQuery('#TopSearchBar').focus();
	// }
	// else {
		
	// }	
// }
// LP related
function CheckRelated () {
	if ( jQuery("#gerelateed_sign").html() == "+" ) {
		jQuery(".footer_image").css("position","relative");
		jQuery(".footer_image").css("bottom","0");
		jQuery("#gerelateerd").show();
		jQuery("#gerelateed_sign").html("-");
	}
	else {	
		jQuery(".footer_image").css("position","absolute");
		jQuery(".footer_image").css("bottom","5px");
		jQuery("#gerelateerd").hide();
		jQuery("#gerelateed_sign").html("+");	
	}
}
// LP related link in UL van menu plaatsen.
jQuery(document).ready(function() {
	jQuery(".footer_menu ul").append('<li>'+jQuery("#Gerelateerd_link").html()+'</li>');	
	jQuery("#Gerelateerd_link").html("");
	jQuery("#Gerelateerd_link").css("height",0);
});




// function OpenMenu ( id, level ) {
	// jQuery("#cat_menu_"+id).fadeIn();
// }
// function CloseMenu ( id, level ) {
	// jQuery("#cat_menu_"+id).hide();
// }


// Bag aantal
function BagAantal (sort, artikel, mbh) {
	val = parseInt( jQuery("#aantal_"+artikel).val() );
	if ( val-1 < mbh && sort == "-") {
		alert('Minimale bestelhoeveel van '+ mbh + ' verplicht');
	}
	else {
		if ( sort == "+" ) {
			// alert( jQuery("#aantal_"+artikel).val() );
			jQuery("#aantal_"+artikel).val( parseInt( val + 1 ) );
		}
		else if ( sort == "-" && val > 1 ) {
			jQuery("#aantal_"+artikel).val( parseInt( val - 1 ) );
		}
	}
}

function checkMBH(mbh, obj) {
	if(obj.value < mbh ) { 
		obj.value=mbh; 
		alert('Minimale bestelhoeveel van '+ mbh + ' verplicht');
	}	
	return; 
}

function numbersonly(){
 if (event.keyCode < 48 || event.keyCode > 57)
  return false
}


// Lightbox init
jQuery(function() {
	jQuery('a[rel=lightbox]').lightBox();
});





// Merken select
jQuery(document).ready(function() {
	jQuery(".merken select,.cat_item_rows select").change(function() {
		document.location = jQuery(this).val();
	});
	
	/* 
		Als we op een artikelen overview zitten, en een merkenfilter hebben
		gaan we de klabnten login div verbergen omdat hier het filter geplaats wordt.	
	*/
	if ( jQuery(".cat_item_rows select").length != 0 ) {
		jQuery(".klant_login").hide();
	}
});



// Artikel details
jQuery(document).ready(function() {
	// Afbeelding vergroting
	// jQuery(".ExtraAfbeeldingen a img").hover(function() {
		// src = jQuery(this).attr("src").replace("/thumb50/","/thumb255/").replace("height=50","height=255").replace("width=50","width=255");
		// jQuery(".picture_link").attr("href", src);
		// jQuery(".picture_link img.big_image").attr("src", src);
	// });
	// Artikel tabs
	selected = 0
	jQuery(".artikel .tab_header_noprint").each(function() {
		if ( jQuery(this).css("display") != "none" && selected == 0 ) {		
			jQuery(this).addClass("selected");
			jQuery("#tab_"+jQuery(this).attr('id').replace("tab_header_","")).addClass("first");			
			selected = 1;
		}
		jQuery(this).click(function() {			
			id = jQuery(this).attr('id').replace("tab_header_","");
			// Headers loopen voor class
			jQuery(".artikel .tab_header_noprint").each(function() {
				// alert(id +" - "+ jQuery(this).attr('id').replace("tab_",""));
				if ( id == jQuery(this).attr('id').replace("tab_header_","") ) {
					jQuery(this).addClass("selected");
				}
				else {
					jQuery(this).removeClass("selected");
				}
			});
			// Tabs loopen voor display
			jQuery(".artikel .tab").each(function() {
				// alert(id +" - "+ jQuery(this).attr('id').replace("tab_",""));
				if ( id == jQuery(this).attr('id').replace("tab_","") ) {
					jQuery(this).show();
				}
				else {
					jQuery(this).hide();
 				}
				
				if ( id == 4 ) {
					jQuery(".print_spec").hide();
				}
				else {				
					jQuery(".print_spec").show();
				}
			});
		});
	});
});
// Print opties
function PrintSpec (id) {
	// Popup
	url = "http://www.toolprof.nl/cat/front/genPrintSpec.asp?id="+ id +"&spec="+ jQuery(".artikel .selected").attr("id").replace("tab_header_","");
	window.open(url, 'printen', "width=600,height=800,scrollbars=yes,toolbar=no,location=no");
	
	// PDF
	// document.location = '/cat/front/PrintSpec.asp?id='+ id +'&spec='+jQuery(".artikel .selected").attr("id").replace("tab_header_","");
	
	// Direct
	// window.print();
}
function PrintAll (id) {
	// Popup
	url  = "http://www.toolprof.nl/cat/front/genPrintAll.asp?id=" + id
	window.open(url, 'printen', "width=600,height=800,scrollbars=yes,toolbar=no,location=no");	
	
	// PDF	
	// document.location = '/cat/front/PrintAll.asp?id='+ id;
	
	// Direct	
	// jQuery(".tabs_noprint").hide();
	// jQuery(".tabs_print").show();
	// window.print();	
	// jQuery(".tabs_print").hide();
	// jQuery(".tabs_noprint").show();
}


function PrintSpecPdf (id) {
	// Popup
	url = "http://www.toolprof.nl/cat/front/PrintSpec.asp?id="+ id +"&spec="+ jQuery(".artikel .selected").attr("id").replace("tab_header_","");
	window.open(url, 'printen', "width=600,height=800,scrollbars=yes,toolbar=no,location=no");
}
function PrintAllPdf (id) {
	// Popup
	url  = "http://www.toolprof.nl/cat/front/PrintAll.asp?id=" + id
	window.open(url, 'printen', "width=600,height=800,scrollbars=yes,toolbar=no,location=no");	
}

// Winkelwagen
jQuery(document).ready(function() {
	loc = String(document.location);
	loc = loc.split("?");
	loc = loc[0];
	// alert(loc);
	jQuery("select[name=CountryID]").change(function() {	
		if ( jQuery(this).val() != "NL" ) {
			SelectElement = this;
			// if (confirm( jQuery("#lng_intracommunautaire").text() )) {
				// document.location = loc +'?CountryID='+jQuery(this).val()+'&intercomm=1&betaalwijze='+jQuery("select[name=betaalwijze]").val()+'&VerzendMethode='+jQuery("input[name=VerzendMethode]:checked").val()+'&btwnummer='+jQuery("input[name=btwnummer]").val(); 
			// }
			// else {
				// document.location = loc +'?CountryID='+jQuery(this).val()+'&betaalwijze='+jQuery("select[name=betaalwijze]").val()+'&VerzendMethode='+jQuery("input[name=VerzendMethode]:checked").val()+'&btwnummer='+jQuery("input[name=btwnummer]").val();
			// }
			jQuery("#intra_ja").click( function() {
				document.location = loc +'?CountryID='+jQuery(SelectElement).val()+'&intercomm=1&betaalwijze='+jQuery("select[name=betaalwijze]").val()+'&VerzendMethode='+jQuery("select[name=VerzendMethode]").val()+'&btwnummer='+jQuery("input[name=btwnummer]").val(); 
			});
			jQuery("#intra_nee").click( function() {
				document.location = loc +'?CountryID='+jQuery(SelectElement).val()+'&betaalwijze='+jQuery("select[name=betaalwijze]").val()+'&VerzendMethode='+jQuery("select[name=VerzendMethode]").val()+'&btwnummer='+jQuery("input[name=btwnummer]").val();
			});
			showIntraMessage();
		}
		else {
			document.location = loc +'?CountryID='+jQuery(this).val()+'&betaalwijze='+jQuery("select[name=betaalwijze]").val()+'&VerzendMethode='+jQuery("select[name=VerzendMethode]").val()+'&btwnummer='+jQuery("input[name=btwnummer]").val();
		}
	});

	jQuery("select[name=betaalwijze]").change(function() {
		if ( jQuery("select[name=CountryID]").val() != "NL" && jQuery("select[name=betaalwijze] option:selected").text() == "Ideal" )  {			
			if ( !confirm( jQuery("#lng_ideal_sure").text() )) {
				jQuery("select[name=betaalwijze]")[0].selectedIndex = 0;
				return;
			}	
		}		
		document.location = loc +'?CountryID='+jQuery("select[name=CountryID]").val()+'&betaalwijze='+jQuery("select[name=betaalwijze]").val()+'&intercomm='+jQuery("input[name=intercomm]").val()+'&VerzendMethode='+jQuery("select[name=VerzendMethode]").val()+'&btwnummer='+jQuery("input[name=btwnummer]").val();
	});	
	
	jQuery("select[name=VerzendMethode]").change(function() {	
		document.location = loc +'?CountryID='+jQuery("select[name=CountryID]").val()+'&betaalwijze='+jQuery("select[name=betaalwijze]").val()+'&intercomm='+jQuery("input[name=intercomm]").val()+'&VerzendMethode='+jQuery("select[name=VerzendMethode]").val()+'&btwnummer='+jQuery("input[name=btwnummer]").val();
	});
	
	jQuery(".aantalveld select").change(function() {	
		document.location = '/cat/front/bag_recalc.asp?'+ jQuery('#frmCheck').serialize();
	});
});
function BagRecalc() {
	document.location = '/cat/front/bag_recalc.asp?'+ jQuery('#frmCheck').serialize();
}
function checkBagForm() {
	if ( jQuery("select[name=betaalwijze]").val() == 0 ) {
		alert( jQuery("#lng_bestelwijze").text() );
		return false;
	}
	
	if ( jQuery("input[name=intercomm]").val() == "1" ) {
		if ( jQuery("input[name=btwnummer]").val() == '') {
			alert("U dient een BTWnummer in te vullen");
			document.frmCheck.btwnummer.focus();
			return false;
		}
	}	
	jQuery('#frmCheck').submit();
}

// Cat winkelwagen numberOnly
jQuery(document).ready(function() {
	jQuery(".aantalveld input").keydown(function() {
		// alert(event.keyCode);
		if (event.keyCode >= 48 && event.keyCode <= 57) { // Gewone 1 tm 0
			return true;
		}
		else if (event.keyCode >= 96 && event.keyCode <= 105) { // Numpad 0 tm 9
			return true;
		}
		else if (event.keyCode == 8 || event.keyCode == 46) { // Backspace - Delete
			return true;
		}
		else {
			return false;
		}
	});
	
	
	jQuery(".aantalveld input").blur(function() {
		BagRecalc();
	});
});




// Afbeelding error hiden
jQuery(document).ready(function() {
	jQuery("img").error(function() {
		jQuery(this).hide();
	});
});

// Keurmerk Hover
// jQuery(document).ready(function() {
	// jQuery(".socialmedia .keurmerk img").mouseover(function() {
		// jQuery(this).attr("src","/pam/front/templates/standaard/grfx/keurmerk_hover.png")
	// });
	// jQuery(".socialmedia .keurmerk img").mouseout(function() {
		// jQuery(this).attr("src","/pam/front/templates/standaard/grfx/keurmerk.png")
	// });
// });


// Uw gegevens
jQuery(document).ready(function() {
	jQuery("DIV.uwgegevens DIV.winkelwagen_mid table.frmCheck input").focus(function() {
		jQuery(this).css("border-color","#3C3C3C");
	});
	jQuery("DIV.uwgegevens DIV.winkelwagen_mid table.frmCheck input").blur(function() {
		jQuery(this).css("border-color","#ececed");
	});
	
	jQuery("DIV.uwgegevens DIV.winkelwagen_mid table.frmCheck input[name='telefoon']").keyup(function() {
		// jQuery(this).val(  jQuery(this).val().replace('-','') );
		jQuery(this).val(  jQuery(this).val().replace(/[^0-9]/g,"") );
	});
});

function numericOnly(evt) {      
    var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
	}
    return true;
}


jQuery(document).ready(function() {
	// function test() {
		jQuery(".level_0").hover( function() {		
			jQuery(this).removeClass("level_0");
			jQuery(".level_0").each( function() {
				jQuery(this).hide();
			});		
			jQuery(this).addClass("level_0");
		});
		jQuery(".level_1").hover( function() {		
			jQuery(this).removeClass("level_1");
			jQuery(".level_1").each( function() {
				jQuery(this).hide();
			});		
			jQuery(this).addClass("level_1");
		});
		jQuery(".level_2").hover( function() {		
			jQuery(this).removeClass("level_2");
			jQuery(".level_2").each( function() {
				jQuery(this).hide();
			});		
			jQuery(this).addClass("level_2");
		});
	// }
});


/*
// Menun scrollen
Scroll = 14 * 10; // a * b => a is het aantal pixels hoogte van een item,  b is het aantal items die moeten scrollen
jQuery(document).ready(function($) {	
	// $(".submenumid").each(function() {
		// alert( this.scrollHeight );
	// });
	$(".submenubot_scroll, .submenubot").click(function(e) {
		$(this).parent().children().each(function() {
			if ( $(this).attr("class") == "submenumid" ) {			
				NewScrollTop   = this.scrollTop + Scroll;
				this.scrollTop = this.scrollTop + Scroll;
				
				if ( this.scrollTop != 0 ) {				
					// show UP									
					$("#up_"+ $(this).attr("id").replace("mid_","")).removeClass("submenutop").addClass("submenutop_scroll");
				}	
				
				// alert(this.scrollTop +"-"+ NewScrollTop );
				if ( this.scrollTop != NewScrollTop ) {
					// hide DOWN									
					$("#down_"+ $(this).attr("id").replace("mid_","")).removeClass("submenubot_scroll").addClass("submenubot");
				}				
			}
		});		
		// event.cancelBubble = true;
		e.stopPropagation();
	});	
	$(".submenutop_scroll,.submenutop").click(function(e) {
		$(this).parent().children().each(function() {
			if ( $(this).attr("class") == "submenumid" ) {
				this.scrollTop = this.scrollTop - Scroll;				
				if ( this.scrollTop == 0 ) {
					// hide UP
					$("#up_"+ $(this).attr("id").replace("mid_","")).removeClass("submenutop_scroll").addClass("submenutop");
				}				
				// show DOWN									
				$("#down_"+ $(this).attr("id").replace("mid_","")).removeClass("submenubot").addClass("submenubot_scroll");						
			}
		});		
		// event.cancelBubble = true;
		e.stopPropagation();
	});
});
*/


// For each menu you create, you must create a matching "FSMenu" JavaScript object to represent
// it and manage its behaviour. You don't have to edit this script at all if you don't want to;
// these comments are just here for completeness. Also, feel free to paste this script into the
// external .JS file to make including it in your pages easier!

// Here's a menu object to control the above list of menu data:
var listMenu = new FSMenu('listMenu', true, 'display', 'block', 'none');

// The parameters of the FSMenu object are:
//  1) Its own name in quotes.
//  2) Whether this is a nested list menu or not (in this case, true means yes).
//  3) The CSS property name to change when menus are shown and hidden.
//  4) The visible value of that CSS property.
//  5) The hidden value of that CSS property.
//
// Next, here's some optional settings for delays and highlighting:
//  * showDelay is the time (in milliseconds) to display a new child menu.
//    Remember that 1000 milliseconds = 1 second.
//  * switchDelay is the time to switch from one child menu to another child menu.
//    Set this higher and point at 2 neighbouring items to see what it does.
//  * hideDelay is the time it takes for a menu to hide after mouseout.
//    Set this to a negative number to disable hiding entirely.
//  * cssLitClass is the CSS classname applied to parent items of active menus.
//  * showOnClick will, suprisingly, set the menus to show on click. Pick one of 4 values:
//     0 = All levels show on mouseover.
//     1 = Menu activates on click of first level, then shows on mouseover.
//     2 = All levels activate on click, then shows on mouseover.
//     3 = All levels show on click only (no mouseover at all).
//  * hideOnClick hides all visible menus when one is clicked (defaults to true).
//  * animInSpeed and animOutSpeed set the animation speed. Set to a number
//    between 0 and 1 where higher = faster. Setting both to 1 disables animation.

//listMenu.showDelay = 0;
//listMenu.switchDelay = 125;
// listMenu.hideDelay = -1;
//listMenu.cssLitClass = 'highlighted';
//listMenu.showOnClick = 0;
//listMenu.hideOnClick = true;
listMenu.animInSpeed = 0;
listMenu.animOutSpeed = 0;

// if ( css_browser_selector(navigator.userAgent) == "ie ie7 win js" || css_browser_selector(navigator.userAgent) == "ie ie8 win js" ) {
	// listMenu.hideDelay = 0;
// }

var arrow = null;
if (document.createElement && document.documentElement) {
	// arrow = document.createElement('span');
	// arrow.appendChild(document.createTextNode('>'));
	// Feel free to replace the above two lines with these for a small arrow image...
	arrow = document.createElement('img');
	arrow.src = '/pam/front/templates/standaard/grfx/menu_sub.png';
	arrow.style.borderWidth = '0';
	arrow.className = 'subind';
}
addReadyEvent(new Function('listMenu.activateMenu("listMenuRoot", arrow)'));

function getTimeString() {
	var today=new Date();
	return today.getHours()+':'+today.getMinutes()+':'+today.getSeconds();
}
