/*----------------------------------------------------------------------------------------------------------------------------*/



function locationChange(variable, value)
{
	var variables = getQueryVariables();
	var queryString = '?';
	var found = false;
	for (i = 0; i < variables.length; i++) {
		if ( variables[i][0] == variable ) {
			variables[i][1] = value;
			found = true;
		}
		if (i == 0) {
			queryString += variables[i][0] + '=' + variables[i][1];
		} else {
			queryString += '&' + variables[i][0] + '=' + variables[i][1];
		}
	}
	if (found == false) {
		if (variables.length > 0) {
			queryString = queryString + '&' + variable + '=' + value;
		} else {
			queryString = queryString + variable + '=' + value;
		}
	}
	window.location = queryString;
}

/* Get something from GET query */

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
}

function getQueryVariables() {
  var query = window.location.search.substring(1);
 var pairs = new Array();
  if (query != '') {
	  var vars = query.split("&");
	  for (var i=0; i < vars.length; i++) {
	    var pair = vars[i].split("=");
	    pairs[pairs.length] = pair;
	  }
  }
  return pairs;
}

function initContactType() {
	var val = getGETVar('contact_over');
	if (val != '') {
		document.getElementById('contact_over').value = val;
	}
}


/*----------------------------------------------------------------------------------------------------------------------------*/
/* Handle mouseover for images in topmenu */

function topMenuOver(oImg)
{
	var newSrc = oImg.src.replace('.gif','_act.gif');
	return(newSrc);
}

/*----------------------------------------------------------------------------------------------------------------------------*/
/* Handle mouseout for images in topmenu */

function topMenuOut(oImg)
{
	var newSrc = oImg.src.replace('_act.gif','.gif');
	return(newSrc);

}


/*----------------------------------------------------------------------------------------------------------------------------*/
/* Handle AJAX requests for newsletters */

function handleNewsletter(vlag,nbid)
{
	if(nbid != 'undefined')
	{
		/* Specific newsletter */
		var url = '/modules/newsletter/newsletter.php?action=newsletter&vlag='+vlag+'&nbid='+nbid;
	}
	else
	{
		/* Overview */
		var url = '/modules/newsletter/newsletter.php?action=overview&vlag='+vlag;

	}

	new Ajax.Updater('newslettercontent', url);
}

/*----------------------------------------------------------------------------------------------------------------------------*/
/* Handle AJAX requests for searches */

function handleSearch(vlag,query,start,skipbackcheck)
{

	if(query != '')
	{



	if(!skipbackcheck)
	{

		/* Check if user has pressed back button on browser, to make sure the correct AJAX call is made */
		var currentUrl = document.location.href;
		var currentUrlElements = currentUrl.split('#');
		if ((!isNaN(currentUrlElements[1])) && (!currentUrlElements[1].length == 0))
		{
			var start = currentUrlElements[1];
		}

	}


	/* Create URL */
	//var url = '/modules/search/search.php?query='+encodeURIComponent(query)+'&vlag='+vlag+'&start='+start;

	/* Request AJAX Update */
	//new Ajax.Updater('searchresults', url);

	//$("div.searchresults").load(url);

	$.ajax({
	   type: "GET",
	   url: "/modules/search/search.php",
	   data: "query="+encodeURIComponent(query)+"&vlag="+vlag+"&start="+start,
	   success: function(msg){
		 $("div#searchresults").append(msg);
	   }
	 });


	}

}

function getCookie(Name)
{
	var search = Name + "=";
	if (document.cookie.length > 0)
	{
		offset = document.cookie.indexOf(search);
		if (offset != -1)
		{
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1)
			end = document.cookie.length;
			return unescape(document.cookie.substring(offset, end));
		}
	}
}

function tjek()
{
	var t = new Date().getTime();

	if (document.inlogformulier.onthoud.checked == true)
	{
		var m = document.inlogformulier.email.value;
		var p = document.inlogformulier.password.value;

		var Verval = new Date();
		Verval.setMonth(Verval.getMonth()+6);

		document.cookie = "onthoudn="+m+"; expires=" + Verval.toGMTString();
		document.cookie = "onthoudp="+p+"; expires=" + Verval.toGMTString();
	}else{
		var Verval = new Date();
		Verval.setMonth(Verval.getMonth()-6);
		document.cookie = "onthoudn=; expires=" + Verval.toGMTString();
		document.cookie = "onthoudp=; expires=" + Verval.toGMTString();
	}

	return true;

}

function laden()
{
	var on = getCookie("onthoudn");
	var op = getCookie("onthoudp");

	if (op && on)
	{
		if(testIsValidObject(document.inlogformulier)){
			document.inlogformulier.emailLogin.value = on;
			document.inlogformulier.passwordLogin.value = op;
			document.inlogformulier.onthoud.checked = true;
		}
		if(testIsValidObject(document.inlogformulier_main)){
			document.inlogformulier_main.emailLogin.value = on;
			document.inlogformulier_main.passwordLogin.value = op;
		}

	}
}

function testIsValidObject(objToTest) {
	if (null == objToTest) {
		return false;
	}
	if ("undefined" == typeof(objToTest) ) {
		return false;
	}
	return true;

}

function getGETVar( name )
{
   name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
   var regexS = "[\\?&]"+name+"=([^&#]*)";
   var regex = new RegExp( regexS );
   var results = regex.exec( window.location.href );
   if( results == null )
                  return "";
   else    return results[1];
}

function switchSmallTabs(number)
{
	document.getElementById('liTab0').className = 'first';
	document.getElementById('divTab0').style.display = 'none';

	for (i = 1; i < 10; i++) {
		if (document.getElementById('liTab'+i) != undefined) {
			document.getElementById('liTab'+i).className = '';
		}
		if (document.getElementById('divTab'+i) != undefined) {
			document.getElementById('divTab'+i).style.display = 'none';
		}
	}
	if (number == 0) {
		document.getElementById('liTab0').className = 'first active';
	} else {
		document.getElementById('liTab'+number).className = 'active';
	}
	document.getElementById('divTab'+number).style.display = 'block';
}

function str_replace(search, replace, subject, count) {
	var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
	f = [].concat(search),
	r = [].concat(replace),
	s = subject,
	ra = r instanceof Array, sa = s instanceof Array;
	s = [].concat(s);
	if (count) {
		this.window[count] = 0;
	}

	for (i=0, sl=s.length; i < sl; i++) {
		if (s[i] === '') {
			continue;
		}
		for (j=0, fl=f.length; j < fl; j++) {
		temp = s[i]+'';
		repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
		s[i] = (temp).split(f[j]).join(repl);
		if (count && s[i] !== temp) {
			this.window[count] += (temp.length-s[i].length)/f[j].length;}
		}
	}
	return sa ? s : s[0];
}

function validEmail(emailStr){
	var filter=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(emailStr)) {
		return true;
	} else {
		return false;
	}
}

function validPhone(phoneStr){
	var filter=/^[0-9]{3}\-[0-9]{7}$/i
	if (filter.test(phoneStr)) {
		return true;
	} else {
		return false;
	}
}


var currentOfferteDivOpen = 'product';
function animateDivs(divPrefix)
{
	if (divPrefix != currentOfferteDivOpen) {
		$('#'+currentOfferteDivOpen+'Content').slideUp('fast');
		$('#'+currentOfferteDivOpen+'Header > img').attr('src','/grafix/dropdown.gif');
		$('#'+currentOfferteDivOpen+'Header').attr('class','formOfferteHeader');
		currentOfferteDivOpen = divPrefix;
		$('#'+divPrefix+'Content').slideDown('fast');
		$('#'+divPrefix+'Header > img').attr('src','/grafix/dropdown_active.gif');
		$('#'+divPrefix+'Header').attr('class','formOfferteHeaderActive');
	}
}

function checkProducts(message, message2)
{
	var found = false;
	var values = $('#table_25 tr td > input');
	for ( i  = 0; i < values.length; i++) {
		var numeric = is_numeric(values[i].value);
		if (!numeric) {
			alert(message);
			return false;
		} else if (values[i].value > 0) {
			found = true;
		}
	}
	if (found) {
		animateDivs('acc');
		return true;
	} else {
		alert(message2);
		return false;
	}
}

function checkAccessoires(message, message2)
{
	var found = false;
	var values = $('#table_26 tr td > input');
	for ( i  = 0; i < values.length; i++) {
		var numeric = is_numeric(values[i].value);
		if (!numeric) {
			alert(message);
			return false;
		}
	}
	animateDivs('data');
	return true;
}



function is_numeric (mixed_var) {
    // Returns true if value is a number or a numeric string
    if (mixed_var === '') {
        return false;
    }

    return !isNaN(mixed_var * 1);
}

function get_html_translation_table (table, quote_style) {
    // Returns the internal translation table used by htmlspecialchars and htmlentities
    //
    // version: 909.322
    // discuss at: http://phpjs.org/functions/get_html_translation_table
    // +   original by: Philip Peterson
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: noname
    // +   bugfixed by: Alex
    // +   bugfixed by: Marco
    // +   bugfixed by: madipta
    // +   improved by: KELAN
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Frank Forte
    // +   bugfixed by: T.Wild
    // +      input by: Ratheous
    // %          note: It has been decided that we're not going to add global
    // %          note: dependencies to php.js, meaning the constants are not
    // %          note: real constants, but strings instead. Integers are also supported if someone
    // %          note: chooses to create the constants themselves.
    // *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
    // *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}

    var entities = {}, hash_map = {}, decimal = 0, symbol = '';
    var constMappingTable = {}, constMappingQuoteStyle = {};
    var useTable = {}, useQuoteStyle = {};

    // Translate arguments
    constMappingTable[0]      = 'HTML_SPECIALCHARS';
    constMappingTable[1]      = 'HTML_ENTITIES';
    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
    constMappingQuoteStyle[2] = 'ENT_COMPAT';
    constMappingQuoteStyle[3] = 'ENT_QUOTES';

    useTable       = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
    useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';

    if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
        throw new Error("Table: "+useTable+' not supported');
        // return false;
    }

    entities['38'] = '&amp;';
    if (useTable === 'HTML_ENTITIES') {
        entities['160'] = '&nbsp;';
        entities['161'] = '&iexcl;';
        entities['162'] = '&cent;';
        entities['163'] = '&pound;';
        entities['164'] = '&curren;';
        entities['165'] = '&yen;';
        entities['166'] = '&brvbar;';
        entities['167'] = '&sect;';
        entities['168'] = '&uml;';
        entities['169'] = '&copy;';
        entities['170'] = '&ordf;';
        entities['171'] = '&laquo;';
        entities['172'] = '&not;';
        entities['173'] = '&shy;';
        entities['174'] = '&reg;';
        entities['175'] = '&macr;';
        entities['176'] = '&deg;';
        entities['177'] = '&plusmn;';
        entities['178'] = '&sup2;';
        entities['179'] = '&sup3;';
        entities['180'] = '&acute;';
        entities['181'] = '&micro;';
        entities['182'] = '&para;';
        entities['183'] = '&middot;';
        entities['184'] = '&cedil;';
        entities['185'] = '&sup1;';
        entities['186'] = '&ordm;';
        entities['187'] = '&raquo;';
        entities['188'] = '&frac14;';
        entities['189'] = '&frac12;';
        entities['190'] = '&frac34;';
        entities['191'] = '&iquest;';
        entities['192'] = '&Agrave;';
        entities['193'] = '&Aacute;';
        entities['194'] = '&Acirc;';
        entities['195'] = '&Atilde;';
        entities['196'] = '&Auml;';
        entities['197'] = '&Aring;';
        entities['198'] = '&AElig;';
        entities['199'] = '&Ccedil;';
        entities['200'] = '&Egrave;';
        entities['201'] = '&Eacute;';
        entities['202'] = '&Ecirc;';
        entities['203'] = '&Euml;';
        entities['204'] = '&Igrave;';
        entities['205'] = '&Iacute;';
        entities['206'] = '&Icirc;';
        entities['207'] = '&Iuml;';
        entities['208'] = '&ETH;';
        entities['209'] = '&Ntilde;';
        entities['210'] = '&Ograve;';
        entities['211'] = '&Oacute;';
        entities['212'] = '&Ocirc;';
        entities['213'] = '&Otilde;';
        entities['214'] = '&Ouml;';
        entities['215'] = '&times;';
        entities['216'] = '&Oslash;';
        entities['217'] = '&Ugrave;';
        entities['218'] = '&Uacute;';
        entities['219'] = '&Ucirc;';
        entities['220'] = '&Uuml;';
        entities['221'] = '&Yacute;';
        entities['222'] = '&THORN;';
        entities['223'] = '&szlig;';
        entities['224'] = '&agrave;';
        entities['225'] = '&aacute;';
        entities['226'] = '&acirc;';
        entities['227'] = '&atilde;';
        entities['228'] = '&auml;';
        entities['229'] = '&aring;';
        entities['230'] = '&aelig;';
        entities['231'] = '&ccedil;';
        entities['232'] = '&egrave;';
        entities['233'] = '&eacute;';
        entities['234'] = '&ecirc;';
        entities['235'] = '&euml;';
        entities['236'] = '&igrave;';
        entities['237'] = '&iacute;';
        entities['238'] = '&icirc;';
        entities['239'] = '&iuml;';
        entities['240'] = '&eth;';
        entities['241'] = '&ntilde;';
        entities['242'] = '&ograve;';
        entities['243'] = '&oacute;';
        entities['244'] = '&ocirc;';
        entities['245'] = '&otilde;';
        entities['246'] = '&ouml;';
        entities['247'] = '&divide;';
        entities['248'] = '&oslash;';
        entities['249'] = '&ugrave;';
        entities['250'] = '&uacute;';
        entities['251'] = '&ucirc;';
        entities['252'] = '&uuml;';
        entities['253'] = '&yacute;';
        entities['254'] = '&thorn;';
        entities['255'] = '&yuml;';
    }

    if (useQuoteStyle !== 'ENT_NOQUOTES') {
        entities['34'] = '&quot;';
    }
    if (useQuoteStyle === 'ENT_QUOTES') {
        entities['39'] = '&#39;';
    }
    entities['60'] = '&lt;';
    entities['62'] = '&gt;';


    // ascii decimals to real symbols
    for (decimal in entities) {
        symbol = String.fromCharCode(decimal);
        hash_map[symbol] = entities[decimal];
    }

    return hash_map;
}

