
// ------  Browser Detection 

var isIE=false; var isIE4=false; var isNN=false; var isNN4=false; var isNN6=false; var isDOM=false; var isMAC=false;
if (navigator.platform.toLowerCase().indexOf('mac') != -1) isMAC = true;
if (document.all) isIE = true;
if (navigator.appVersion.toLowerCase().indexOf('msie 4') != -1) isIE4 = true;
if (navigator.appName.toLowerCase().indexOf('netscape') != -1) {
	isNN = true;
	if (parseInt(navigator.appVersion) == 4) isNN4 = true;
}
if ((isNN && !isNN4) || (isIE && !isIE4)) isDOM = true;
if (isDOM && isNN) isNN6 = true;

// ------ Environment Detection

var windowWidth; var windowHeight; var windowScrollX; var windowScrollY;
function detectEnvironmentProperties() {
	windowWidth = (isNN) ? window.innerWidth : document.body.clientWidth;
	windowHeight = (isNN) ? window.innerHeight : document.body.clientHeight;
	windowScrollX = (isNN) ? window.pageXOffset : document.body.scrollLeft;
	windowScrollY = (isNN) ? window.pageYOffset : document.body.scrollTop;
}

// ------  Url functions

function parseValueFromUrl(name) {
	var url = document.location.href;
	var value = null;
	if(url.indexOf('?') != -1) {
		var pars = url.substring(url.indexOf('?') + 1, url.length);
		if(pars.lastIndexOf('#') != -1) pars = pars.substring(0, pars.lastIndexOf('#'));
		pars = pars.split('&');
		for (i=0; i<pars.length; i++) {
			var loc = pars[i].indexOf('=');
			pName = pars[i].substring(0, loc);
			pValue = unescape(pars[i].substring(loc + 1, pars[i].length));
			if (name==pName) value = pValue;
		}
	}
	return value;
}
	
// ------  Window functions
	
function openWindow(url, name, w, h, menubar, toolbar, scrollbars) {
	var x = parseInt(screen.width / 2) - parseInt(w/2);
	var y = parseInt(screen.height / 2) - parseInt(h/2);
	
	var parameters = 'toolbar=0,location=0,menubar=' + menubar + ',toolbar=' + toolbar + ',scrollbars=' + scrollbars + ',width=' + w + ',height=' + h + ',top=' + y + ',left=' + x + ',screenY=' + y + ',screenX=' + x;
	var win = window.open(url, name, parameters);
	win.focus();
	return win;
}

// ------ Image functions

function replaceImage(id, oldStr, newStr) {
	document.getElementById(id).src = document.getElementById(id).src.replace(oldStr, newStr);
}

function changeImage(id, loc) {
	document.getElementById(id).src = loc;
}

function getImageLeft(img, ly) {
	(ly != null) ? layerloc = element(ly).offsetLeft : layerloc = 0;
	loc = element(img).offsetLeft;
	if (!isNN6) loc += layerloc;
	return parseInt(loc);
}

function getImageTop(img, ly) {
	(ly != null) ? layerloc = element(ly).offsetTop : layerloc = 0;
	loc = element(img).offsetTop;
	if (!isNN6) loc += layerloc;
	return parseInt(loc);
}

function cacheImages(imgList, path) {
	if (path == null) path = '';
	var images = new Array();
	for (var i=0; i<imgList.length; i++) {
		images[i] = new Image();
		images[i].src = path + imgList[i];
	}
}	

// ------ Layer functions

function moveLayer(ly, x, y) {
	element(ly).style.left = x + 'px';
	element(ly).style.top = y + 'px';
}	

// ------ String functions

function replaceChars(str, oldChar, newChar) {
	var newStr = '';
	for (var i=0; i < str.length; i++) {
		(str.charAt(i) == oldChar) ? newStr += newChar : newStr += str.charAt(i);
	}
	return newStr;
}

function toId(s) {
	var str = s.toLowerCase();
	var badChars = '\'.-+=\\\/" &';
	var newStr = '';
	for (var i=0; i<str.length; i++) {
		if (badChars.indexOf(str.charAt(i)) == -1) newStr += str.charAt(i);
	}
	return newStr;
}

// ------ Cookies

function setCookie(name, value) {
	var d = new Date(); var then = d.getTime() + (3 * 365 * 24 * 60 * 60 * 1000); d.setTime(then); d = d.toGMTString();
	document.cookie = name + "=" + escape(value) + "; expires=" + d + "; path=/";
}

function getCookie(name) {
	var value = null; var cookies = document.cookie.split('; ');
	for (var i=0; i<cookies.length; i++) 
	{
		var loc = cookies[i].indexOf('='); 
		var cName = cookies[i].substring(0, loc); 
		var cValue = unescape(cookies[i].substring(loc+1, cookies[i].length));
		if (name==cName) value = cValue;
	}
	return value;
}

function deleteCookie(name) {
	var d = new Date(); var then = d.getTime() - (24 * 60 * 60 * 1000); d.setTime(then); d = d.toGMTString();
	document.cookie = name + "=-1; expires=" + d + "; path=/";
}

// ------ Other functions

function element(id) {
	var e;
	isIE4  ? e = document.all[id] : e = document.getElementById(id);
	return e; 
}






/*
 * url: booking_details.aspx
 * secure: auto, secure, notsecure
 */
function redirect(url, secure)
{
	if( url.indexOf("http") == 0 )
	{
		document.location = url;
	}
	else if( url.indexOf("javascript") > -1 )
	{
		eval(url.substring(url.lastIndexOf("javascript:")+3,url.length));
	}
	else
	{
		switch( secure )
		{
			case "secure":
			case "notsecure":
				var href = document.location.href;
				var path = href.substring(href.indexOf("://")+3,href.split('?')[0].lastIndexOf("/"));
				document.location = ((secure=="secure")?"https://":"http://")+path+"/"+url;
				break;
			default:
				document.location = url;
				break;
		}
	}
}




function selfHttpsCheck(pageName)
{
	if( url.indexOf("https") > -1 ) { /* ok, it's https */ } 
	else
	{
		var href = document.location.href;
		var path = href.substring(href.indexOf("://")+3,href.lastIndexOf("/"));
		document.location = "https://" + path + "/" + pageName;
	}
}

function setCountryCallMeNow(countryCode, phonePrefix, selectId)
{
	for (i = 0; i < document.getElementById(selectId).options.length; i++)
	{
	if (document.getElementById(selectId).options[i].value.toLowerCase() == countryCode.toLowerCase() && document.getElementById(selectId).options[i].value != "") 
		{
    document.getElementById(selectId).selectedIndex = i;
        }
    }
}
function calcoptions()
{
var camperprijs = document.getElementById("carprice").innerHTML * 1;
document.getElementById("carprice").innerHTML = camperprijs.toFixed(2);

var selop = document.getElementById('selop');
for (i = 0; i < selop.childNodes.length; i++) 
	{
		var n2 = selop.childNodes.item(i); // div
		if (n2.innerHTML){
		
		if (document.getElementById("oppp_pr_" + n2.innerHTML))
		{
		var prijs = document.getElementById("oppp_pr_" + n2.innerHTML).innerHTML * 1;
		prijs = prijs + (document.getElementById("totopts_pr_" + n2.innerHTML).innerHTML * 1);
		prijs = prijs.toFixed(2);
		document.getElementById("oppp_pr_" + n2.innerHTML).innerHTML = prijs;
		aantal = document.getElementById("oppp_aantal_" + n2.innerHTML).innerHTML * 1;
		document.getElementById("oppp_aantal_" + n2.innerHTML).innerHTML = aantal + 1;
		}
		else {
		var linecontent = "<div id='oppp_" + n2.innerHTML + "'>";
		linecontent = linecontent + "<div style='float:left;width:50px' id='oppp_aantal_" + n2.innerHTML + "'>1</div>";
		linecontent = linecontent + "<div style='float:left;width:300px' id='oppp_nm_" + n2.innerHTML + "'>" + document.getElementById("totopts_nm_" + n2.innerHTML).innerHTML + "</div>";
		linecontent = linecontent + "<div style='float:left;width:20px'>" + currencycode + "</div>";
		var prijs = document.getElementById("totopts_pr_" + n2.innerHTML).innerHTML * 1;
		prijs = prijs.toFixed(2);
		linecontent = linecontent + "<div style='float:left;width:50px;text-align:right' id='oppp_pr_" + n2.innerHTML + "'>" + prijs + "</div>";
		linecontent = linecontent + "<br class='clear'/> </div>";
		if (document.getElementById("totopts_prep_" + n2.innerHTML).innerHTML == 'Y' ){
		var opppp = document.getElementById("opppp").innerHTML + linecontent;
		document.getElementById("opppp").innerHTML = opppp;
		}
		else {
		var oppppnp = document.getElementById("oppppnp").innerHTML + linecontent;
		document.getElementById("oppppnp").innerHTML = oppppnp;
		}
		
		}
		
		}
	}optellen();
}

function optellen()
{
var totaalprijs = document.getElementById("carprice").innerHTML * 1;
var optellen = document.getElementById('opppp');
for (i = 0; i < optellen.childNodes.length; i++) 
{
var n2 = optellen.childNodes.item(i); // div
		if (n2.id){
var optieid = (n2.id.substring(5,800));
document.getElementById("oppp_pr_" + optieid).innerHTML
totaalprijs = totaalprijs + document.getElementById("oppp_pr_" + optieid).innerHTML * 1;
}}
totaalprijs = totaalprijs.toFixed(2);
var linecontent = "<div id='total'>";
		linecontent = linecontent + "<div style='font-weight:bold;float:left;width:50px' id='totalprice'>&#160;</div>";
		linecontent = linecontent + "<div style='font-weight:bold;float:left;width:300px' id='totalname'>"+ totalprepaidtxt +"</div>";
		linecontent = linecontent + "<div style='font-weight:bold;float:left;width:20px'>" + currencycode + "</div>";
		linecontent = linecontent + "<div style='font-weight:bold;float:left;width:50px;text-align:right' id='totalpricepp'>" + totaalprijs + "</div>";
		linecontent = linecontent + "<br class='clear'/> </div>";
		
		var opppp = document.getElementById("opppp").innerHTML + linecontent;
		document.getElementById("opppp").innerHTML = opppp;
// alert (totaalprijs);
optellennp();
}

function optellennp()
{
var totaalprijs = 0;
var optellen = document.getElementById('oppppnp');
for (i = 0; i < optellen.childNodes.length; i++) 
{
var n2 = optellen.childNodes.item(i); // div
		if (n2.id){
var optieid = (n2.id.substring(5,800));
document.getElementById("oppp_pr_" + optieid).innerHTML
totaalprijs = totaalprijs + document.getElementById("oppp_pr_" + optieid).innerHTML * 1;

}}
totaalprijs = totaalprijs.toFixed(2);
var linecontent = "<div id='total'>";
		linecontent = linecontent + "<div style='font-weight:bold;float:left;width:50px' id='totalprice'>&#160;</div>";
		linecontent = linecontent + "<div style='font-weight:bold;float:left;width:300px' id='totalname'>" + totalnonprepaidtxt + "</div>";
		linecontent = linecontent + "<div style='font-weight:bold;float:left;width:20px'>" + currencycode + "</div>";
		linecontent = linecontent + "<div style='font-weight:bold;float:left;width:50px;text-align:right' id='totalpricenpp'>" + totaalprijs + "</div>";
		linecontent = linecontent + "<br class='clear'/> </div>";
		
		var opppp = document.getElementById("oppppnp").innerHTML + linecontent;
		document.getElementById("oppppnp").innerHTML = opppp;

var totalpricepp = document.getElementById("totalpricepp").innerHTML * 1;
var totalpricenpp = document.getElementById("totalpricenpp").innerHTML * 1 ;
var totalprice = totalpricenpp + totalpricepp;


var linecontent = "<div id='total'>";
totalprice = totalprice.toFixed(2);
		linecontent = linecontent + "<div style='font-weight:bold;float:left;width:50px' id='totalprice'>&#160;</div>";
		linecontent = linecontent + "<div style='font-weight:bold;float:left;width:300px' id='totalname'>" + totaltxt + "</div>";
		linecontent = linecontent + "<div style='font-weight:bold;float:left;width:20px'>" + currencycode + "</div>";
		linecontent = linecontent + "<div style='font-weight:bold;float:left;width:50px;text-align:right' id='totalpricett'>" + totalprice + "</div>";
		linecontent = linecontent + "<br class='clear'/> </div>";
document.getElementById("totalpricess").innerHTML = linecontent;


if (document.getElementById("totalpricenpp").innerHTML == "0.00") document.getElementById("oppppnp").style.display = "none";
else  document.getElementById("oppppnp").style.diplay = "block";

}