
// ------  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;
}

function getURLParameters() 
{
	var sURL = window.document.URL.toString();
	
	if (sURL.indexOf("?") > 0)
	{
		var arrParams = sURL.split("?");
			
		var arrURLParams = arrParams[1].split("&");
		
		var arrParamNames = new Array(arrURLParams.length);
		var arrParamValues = new Array(arrURLParams.length);
		
		var i = 0;
		for (i=0;i<arrURLParams.length;i++)
		{
			var sParam =  arrURLParams[i].split("=");
			arrParamNames[i] = sParam[0];
			if (sParam[1] != "")
				arrParamValues[i] = unescape(sParam[1]);
			else
				arrParamValues[i] = "No Value";
		}
		
		for (i=0;i<arrURLParams.length;i++)
		{
			document.getElementById('labelquote').style.display = 'block';
			document.getElementById('insquote').style.display = 'block';
			document.getElementById('quoteid').value = "HC" + arrParamValues[i];
		}
	}
	else
	{
	document.getElementById('quoteid').value = "niet van toepassing";
	}
}
	
// ------  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=,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;
}

function openWindow2(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,resizable=yes,location=0,menubar=0,scrollbars=1,width=600,height=600,top=100,left=100,screenY=,screenX=';
	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 popUp(URL) 
{
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=300');");
}
