/*jslint browser: true */
/*global __doPostBack, $find, $get, jQuery, window, self */

var disableenterkey = 1;
var formdefaultbutton = null;

function enableenter(defaultbutton) {
	if (defaultbutton !== null) {
		formdefaultbutton = defaultbutton;
	}

	disableenterkey = 0;
}

function disableenter(defaultbutton) {
	disableenterkey = 1;
}

function initkeyhandler() {
	jQuery(".snelzoekbox").keypress(function(event) {
		if (event.keyCode == 13 && disableenterkey === 0 && formdefaultbutton !== null) {
			event.preventDefault();
			jQuery("input[name='" + formdefaultbutton + "']").click();
			return false;
		}
	});
}

function activateflash(idname) {
	var obj = document.getElementById(idname);
	if (obj !== null) {
		var width = obj.getAttribute('width');
		var height = obj.getAttribute('height');
		var content = obj.getAttribute('content');
		
		obj.innerHTML = '<object type="application/x-shockwave-flash" CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"  width="' + width + '" height="' + height + '" data="' + content + '"><param name="movie" value="' + content + '"><param name="quality" value="high"><EMBED SRC="' + content + '" WIDTH="' + width + '" HEIGHT="' + height + '" TYPE="application/x-shockwave-flash" PLAY="true" LOOP="true" QUALITY="high"></EMBED></object>';
	}
}
function activatemovie(idname) {
	var obj = document.getElementById(idname);
	if (obj !== null) {
		var width = obj.getAttribute('width');
		var height = obj.getAttribute('height');
		var content = obj.getAttribute('content');

		obj.innterHTML = '<object id="MSIE" classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" type="video/x-ms-wmv" width="' + width + '" height="' + height + '">'+
		'<param name="URL" value="' + content + '">' +
		'<param name="AutoStart" value="true">'+
		'<param name="ShowTracker" value="true">'+
		'<param name="ShowControls" value="true">'+
		'<param name="ShowGotoBar" value="false">'+
		'<param name="ShowDisplay" value="false">'+
		'<param name="ShowStatusBar" value="false">'+
		'<param name="AutoSize" value="false">'+
		'<param name="StretchToFit" value="true">'+
		'<\/object>' +
		'<object type="application/x-ms-wmp" id="FireFox" width="' + width + '" height="' + height + '">'+
		'<param name="URL" value="' + content + '">'+
		'<param name="AutoStart" value="true">' +
		'<param name="ShowTracker" value="true">'+
		'<param name="ShowControls" value="true">'+
		'<param name="ShowGotoBar" value="false">'+
		'<param name="ShowDisplay" value="false">'+
		'<param name="ShowStatusBar" value="false">'+
		'<param name="AutoSize" value="false">'+
		'<param name="StretchToFit" value="true">'+
		'<a></a> <!--MSIE workaround-->'+
		'<\/object>';
		//obj.innterHTML  = text;
		// <embed src="' + content + '" width=240 height=238 autostart=1 loop=0 type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/download/default.asp" showcontrols=1 showdisplay=0 showstatusbar=1 width="' + width + '" height="' + height + '" ></embed>
		//obj.innerHTML = '<embed width="' + width + '" height="' + height + '" controller="true" src="' + content + '" type="application/x-mplayer2" id="player" ><param name="movie" value="' + content + '"></embed>';
	}
}
function activatebigmovie(idname, content) {
	var obj = document.getElementById(idname);
	if (obj !== null) {
		obj.innerHTML = '<embed width="800" height="600" controller="true" src="' + content + '" type="application/x-mplayer2" id="player" /><script language=\"JavaScript\" >Player.controls.stop()=\"true\";</script>';
	}
}
function GridScroll() {
	if (document.all.ScrollHere !== null) {
		document.all.ScrollHere.scrollIntoView();
	}
}
function checkblurtextbox(idname, textvalue) {
	var box = document.getElementById(idname);
	if (box.value === '') {
		box.value = textvalue;
		box.className = 'snelzoekenblurred normaletekst snelzoekbox';
	}
}
function checkblurtextboxklein(idname, textvalue) {
	var box = document.getElementById(idname);
	if (box.value === '') {
		box.value = textvalue;
		box.className = 'kleinetekst snelzoekenblurred';
	}
}
function checkfocustextbox(idname, textvalue) {
	var box = document.getElementById(idname);
	if (box.value == textvalue) {
		box.value = '';
		box.className = 'snelzoekenfocused normaletekst snelzoekbox';
	}
}
function checkfocustextboxklein(idname, textvalue) {
	var box = document.getElementById(idname);
	if (box.value == textvalue) {
		box.value = '';
		box.className = 'kleinetekst snelzoekenblurred';
	}
}

// copyright 1999 Idocs, Inc. http://www.idocs.com
// Distribute this script freely but keep this notice in place
function numbersonly(myfield, e, dec) {
	var key;
	var keychar;

	if (window.event) {
		key = window.event.keyCode;
	}
	else if (e) {
		key = e.which;
	} else {
		return true;
	}

	keychar = String.fromCharCode(key);

	// control keys
	if ((key === null) || (key === 0) || (key === 8) || (key === 9) || (key === 13) || (key === 27)) {
		return true;
	}

	// numbers
	else if ((("0123456789").indexOf(keychar) > -1)) {
		return true;
	}

	// decimal point jump
	else if (dec && (keychar === ".")) {
		myfield.form.elements[dec].focus();
		return false;
	}
	else {
		return false;
	}
}
function openfaq() {
	var newwin = window.open("../../prijsbemiddeling_faq.aspx", "FAQ", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=640,height=300");
	if (newwin.opener === null) { newwin.opener = self; }
}

/* These functions don't seem to be in use. Perhaps they are used from banners? */
function openanwb() {
	var newwin = window.open("../../ANWB/Default.aspx", "ANWB", "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=750,height=530");
	if (newwin.opener === null) { newwin.opener = self; }
}

function opendeltalloyd() {
	var newwin = window.open("../../deltalloyd/Default.aspx", "DeltaLloyd", "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=770,height=530");
	if (newwin.opener === null) { newwin.opener = self; }
}
function openweening() {
	var newwin = window.open("../../weening/Default.aspx", "Weening", "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=600,height=800");
	if (newwin.opener === null) { newwin.opener = self; }
}
function openeerdmans() {
	var newwin = window.open("../../eerdmans/Default.aspx", "Eerdmans", "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=800,height=1024");
	if (newwin.opener === null) { newwin.opener = self; }
}
/* End functions not in use */

function nop() {
}

function hidelargefoto() {
	jQuery('#largeFoto').hide();
	jQuery('#filmpje').show();
	jQuery('#skyscraper1').show();
}

function checkComma(textbox) {
	if (textbox.value.length > 0 && textbox.value.indexOf(",") == -1) {
		textbox.value += ",00";
	}
}
function checkInput(textbox) {
	if (textbox.value.indexOf(".") == -1) {
		textbox.value[textbox.value.indexOf('.')] = ',';
	}
}

function setLabelStatus(label, bericht) {
	var el = document.getElementById(label);
	if (el !== null) {
		el.innerHTML = bericht;
	}
}

function limitTextbox(max, tekstbox, label) {

	var limit = max;
	var o = $get(tekstbox);

	var stripped = o.value.replace(/(<([^>]+)>)/ig, "");

	if (stripped.length >= limit) {
		o.value = o.value.substr(0, limit);
		setLabelStatus(label, ',0 over');
		event.cancelBubble = true;
		event.returnValue = false;
	} else {
		setLabelStatus(label, ', ' + (limit - stripped.length) + ' over');
	}
}

function clearDDType(ddbtypeid, tbtypeid, ddbmerkid) {
	if ($get(tbtypeid).value.length > 0) {
		$get(ddbtypeid).disabled = true;
	} else {
		if ($get(ddbmerkid).disabled === false) {
			$get(ddbtypeid).disabled = false;
		}
	}
}
function clearType(ddbid, tbid) {
	if ($get(ddbid).selectedindex > 0) {
		$get(tbid).value = '';
	}
}
function clearMerk(ddbmerkid, tbmerkid) {
	if ($get(ddbmerkid).selectedindex > 0) {
		$get(tbmerkid).value = '';
	}
}
function clearDDMerk(tbmerkid, ddbmerkid) {
	if ($get(tbmerkid).value.length > 0) {
		$get(ddbmerkid).disabled = true;
	} else {
		$get(ddbmerkid).disabled = false;
	}
}
function checkBeschrijving(prijsbeschrijvingid, tbprijsid, chkprijsid) {
	if ($get(prijsbeschrijvingid).selectedIndex > 0) {
		$get(tbprijsid).value = '';
		$get(chkprijsid).selectedIndex = 1;
	}
}
function checkPrijs(prijsbeschrijvingid, tbprijsid) {
	if ($get(tbprijsid).value.length > 0) {
		$get(prijsbeschrijvingid).selectedIndex = 0;
	}
}
function clearAll() {
	$get('voorbeeld').style.display = 'none';
}
function highlight1_15(obj) {
	obj.src = '/img/restyle/formaten/Formaten_actief_01.gif';
	$get('voorbeeld').src = "/img/restyle/formaten/1_15_voorbeeld.gif";
	$get('voorbeeld').style.display = 'block';
}
function unhighlight1_15(obj) {
	obj.src = '/img/restyle/formaten/Formaten_inactief_01.gif';
	$get('voorbeeld').style.display = 'none';
	clearAll();
}
function highlight2_15(obj) {
	obj.src = '/img/restyle/formaten/Formaten_actief_02.gif';
	$get('voorbeeld').src = "/img/restyle/formaten/2_15_Liggend_voorbeeld.gif";
	$get('voorbeeld').style.display = 'block';
}

function unhighlight2_15(obj) {
	obj.src = '/img/restyle/formaten/Formaten_inactief_02.gif';
	clearAll();
}
function highlight2_15v(obj) {
	obj.src = '/img/restyle/formaten/Formaten_actief_04.gif';
	$get('voorbeeld').src = "/img/restyle/formaten/2_15_Staand_voorbeeld.gif";
	$get('voorbeeld').style.display = 'block';
}
function unhighlight2_15v(obj) {
	obj.src = '/img/restyle/formaten/Formaten_inactief_04.gif';
	clearAll();
}
function highlight4_15(obj) {
	obj.src = '/img/restyle/formaten/Formaten_actief_05.gif';
	$get('voorbeeld').src = "/img/restyle/formaten/4_15_voorbeeld.gif";
	$get('voorbeeld').style.display = 'block';
}
function unhighlight4_15(obj) {
	obj.src = '/img/restyle/formaten/Formaten_inactief_05.gif';
	clearAll();
}
function highlight6_15(obj) {
	obj.src = '/img/restyle/formaten/Formaten_actief_06.gif';
	$get('voorbeeld').src = "/img/restyle/formaten/6_15_voorbeeld.gif";
	$get('voorbeeld').style.display = 'block';
}
function unhighlight6_15(obj) {
	obj.src = '/img/restyle/formaten/Formaten_inactief_06.gif';
	clearAll();
}
function highlight9_15(obj) {
	obj.src = '/img/restyle/formaten/Formaten_actief_03.gif';
	$get('voorbeeld').src = "/img/restyle/formaten/9_15_voorbeeld.gif";
	$get('voorbeeld').style.display = 'block';
}
function unhighlight9_15(obj) {
	obj.src = '/img/restyle/formaten/Formaten_inactief_03.gif';
	clearAll();
}
function highlight1_8(obj) {
	obj.src = '/img/restyle/formaten/Formaten_actief_07.gif';
	$get('voorbeeld').src = "/img/restyle/formaten/1_8_voorbeeld.gif";
	$get('voorbeeld').style.display = 'block';
}
function unhighlight1_8(obj) {
	obj.src = '/img/restyle/formaten/Formaten_inactief_07.gif';
	clearAll();
}
function highlight1_16(obj) {
	obj.src = '/img/restyle/formaten/Formaten_actief_08.gif';
	$get('voorbeeld').src = "/img/restyle/formaten/1_16_voorbeeld.gif";
	$get('voorbeeld').style.display = 'block';
}
function unhighlight1_16(obj) {
	obj.src = '/img/restyle/formaten/Formaten_inactief_08.gif';
	clearAll();
}
function showPopup(popup) {
	var p = $find(popup);
	p.show();

	//$get('tabnavigatie').style.display = 'none';
	//$get('navigatiemenu').style.display = 'none';
	jQuery('#skyscraper1').hide();
	jQuery('#filmpje').hide();

}
function hideMailPopup(popup) {
	//$get('tabnavigatie').style.display = 'block';
	//$get('navigatiemenu').style.display = 'block';
	jQuery('#skyscraper1').show();
	jQuery('#filmpje').show();

	var p = $find(popup);
	p.hide();
}
function selectAll(naam, aanzetten, uitzetten) {
	document.getElementById(uitzetten).style.display = "none";
	document.getElementById(aanzetten).style.display = "block";
	var select = "." + naam + ":enabled";

	jQuery(select).each(function() {
		jQuery(this).attr('checked', true);
	});
}
function check(obj) {
	obj.checked = true;
}
function deselectAll(naam, aanzetten, uitzetten) {
	document.getElementById(uitzetten).style.display = "none";
	document.getElementById(aanzetten).style.display = "block";
	var select = "." + naam + ":enabled";

	jQuery(select).each(function() {
		jQuery(this).attr('checked', false);
	});
}
function uncheck(obj) {
	obj.checked = false;
}
var currentNewsItem = 0;
function showNextNewsItem() {
	if ((typeof (window["currentNewsItems"])) == "undefined") {
		return;
	}

	if (currentNewsItem < currentNewsItems.length - 1) {
		currentNewsItem += 1;
	}
	else {
		currentNewsItem = 0;
	}

	jQuery("#news-link").fadeOut(500, function() { jQuery(this).html(currentNewsItems[currentNewsItem]); });
	jQuery("#news-link").fadeIn(500);
	setTimeout(showNextNewsItem, 8000);
}

function initAdverterenSelectieAndereSitesPopup() {
	jQuery(".adverterenAndereSitesI").mouseover(function() {
		jQuery(".adverterenSelectieAndereSites").fadeIn('fast');
	});

	jQuery(".adverterenAndereSitesI").mouseout(function() { jQuery(".adverterenSelectieAndereSites").fadeOut('fast'); });
}

function initGoogleAnalyticsEventHandlers() {
	jQuery(".printpdf").click(function() {
		pageTracker._trackPageview("/Dynamic/AdvertentieShowPDF");
		globalTracker._trackPageview("/Dynamic/AdvertentieShowPDF");
	});
}

jQuery(document).ready(function() {
	initkeyhandler();
	initAdverterenSelectieAndereSitesPopup();
	initGoogleAnalyticsEventHandlers();
});

function enableEnterInTextarea(object, evt) {
	disableenterkey = 0;

	if (window.event) {
		if (window.event.keyCode == 13) {
			evt.cancelBubble = true;
		}
	}
	else {
		if (evt.keyCode == 13) {
			evt.stopPropagation();
		}
	}
	return true;
}

function SubmitMarineSearchQuery(txtBoxID) {
	var searchTxtBox = document.getElementById(txtBoxID);
	window.open('https://www.marinestore.nl/advanced_search_result.php?search_in_description=1&keywords=' + searchTxtBox.value.replace(" ", "%2b"));
}
function showGoogleMap(googleMapUrl) {
	// $get('tabnavigatie').style.display = 'none';
	// $get('navigatiemenu').style.display = 'none';
	jQuery('#skyscraper1').hide();
	jQuery('#filmpje').hide();
	var googleMessage = '<div id="google_content"><div class="google_top"><div style="float:right;"><img src="/img/restyle/sluit_icon.gif" onclick="hidePopup()" class="sluit"/></div><iframe id="iframe_google" src="' + googleMapUrl + '" frameborder="0" scrolling=no></iframe></div></div>';
	jQuery.blockUI({ message: googleMessage,
		css: {
			border: 'none',
			backgroundColor: '#000',
			color: '#fff',
			width: '680px',
			top: '10%',
			left: '15%'
		},
		overlayCSS: {
			border: 'none',
			backgroundColor: '#000',
			opacity: .5,
			color: '#fff'
		}
	});
	jQuery('#google_content').corners("4px transparent");
	pageTracker._trackPageview("/Dynamic/AdvertentieShowGoogleMaps");
	globalTracker._trackPageview("/Dynamic/AdvertentieShowGoogleMaps");
}
function showVirtualTour(virtualTourUrl) {
	jQuery('#skyscraper1').hide();
	jQuery('#filmpje').hide();
	var googleMessage = '<div id="virtualtour_content"><div class="virtualtour_top"><div style="float:right;"><img src="/img/restyle/sluit_icon.gif" onclick="hidePopup()" class="sluit"/></div><iframe id="iframe_virtualtour" src="' + virtualTourUrl + '" frameborder="0" scrolling=no></iframe></div></div>';
	jQuery.blockUI({ message: googleMessage,
		css: {
			border: 'none',
			backgroundColor: '#000',
			color: '#fff',
			width: '480px',
			top: '10%',
			left: '15%'
		},
		overlayCSS: {
			border: 'none',
			backgroundColor: '#000',
			opacity: .5,
			color: '#fff'
		}
	});
	jQuery('#virtualtour_content').corners("4px transparent");
	pageTracker._trackPageview("/Dynamic/AdvertentieShowVirtualTour");
	globalTracker._trackPageview("/Dynamic/AdvertentieShowVirtualTour");
}
function hidePopup() {
	jQuery.unblockUI();
	jQuery('#skyscraper1').show();
	jQuery('#filmpje').show();
}