/**
* @author      Mario Ruis
*/



window.onload = function () {



	if (document.getElementById('imgredirect')) {
		trace();
	}


	if (document.getElementById('submitSpan')) {
	  document.getElementById('submitSpan').innerHTML = '<input type="submit" value=" &nbsp;  &nbsp; Versturen  &nbsp;  &nbsp; " />';
	}



	if (document.getElementById('fieldsToCheck')) {
		runFormCheck();
	}

  if (document.getElementById('sbxNav')) {
	document.getElementById('sbxNav').onchange = function() {
	  gotoPage(this);
	}
  }


  if (document.getElementById('fadeonload')) {
		opacity('fadeonload', 100, 0, 2400);
  }


  if (document.getElementById('slbLand')) {
	setRegios();
  }

  if (document.getElementById('gallery')) {
    initGalButtons();
    initGal('gallery');
  }





}








function initGalButtons() {


  if (document.getElementById('vorige')) {
	var btnVorige = document.getElementById('vorige');

	btnVorige.onmouseover=function(){
		this.style.cursor = 'pointer';
		btnVorige.src = thisHost+'pix/vorige_on.gif';
	}

	btnVorige.onmouseout=function(){
		btnVorige.src = thisHost+'pix/vorige.gif';
	}

	btnVorige.onclick=function(){
		navigateGal(-1);
	}
  }




  if (document.getElementById('volgende')) {
	var btnVolgende = document.getElementById('volgende');

	btnVolgende.onmouseover=function(){
		this.style.cursor = 'pointer';
		btnVolgende.src = thisHost+'pix/volgende_on.gif';
	}

	btnVolgende.onmouseout=function(){
		btnVolgende.src = thisHost+'pix/volgende.gif';
	}

	btnVolgende.onclick=function(){
		navigateGal(1);
	}
  }




  if (document.getElementById('sluiten')) {
	var btnSluit = document.getElementById('sluiten');

	btnSluit.onmouseover=function(){
		this.style.cursor = 'pointer';
		btnSluit.src = thisHost+'pix/sluiten_on.gif';
	}

	btnSluit.onmouseout=function(){
		btnSluit.src = thisHost+'pix/sluiten.gif';
	}

	btnSluit.onclick=function(){
		document.getElementById('fotogroot').style.visibility = 'hidden';
		document.getElementById('fotogroot').src = './pix/blanco.gif';
		document.getElementById('fotolijst').style.visibility = 'hidden';
		opacity('blur', 75, 0, 0);
		document.getElementById('blur').style.visibility = 'hidden';
	}
	opacity('blur', 100, 0, 0);
  }




}



function navigateGal(pos) {

    aantalPics = gallery.length-1
	currentPic = currentPic+pos


	if(currentPic < 0) {
		currentPic = aantalPics;
	}
	if(currentPic > aantalPics) {
		currentPic = 0;
	}
	document.getElementById('fotogroot').src = gallery[currentPic];

}





function gotoPage(obj) {
	window.location=thisHost+'?p='+thisP+'&s='+obj.options[obj.selectedIndex].value;
}



function setRegios() {


	slbLand = document.getElementById('slbLand');

	var optionsSpanje = ''
	+'<table class="vraagtable">'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Costa-blanca" /></td><td>Costa Blanca</td></tr>'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Costa-brava" /></td><td>Costa Brava</td></tr>'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Costa-del-sol" /></td><td>Costa del Sol</td></tr>'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Costa-dorada" /></td><td>Costa Dorada</td></tr>'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Anders" /></td><td>Anders: <input type="text" name="Regio-spanje:_"  style="width:200px"  /></td></tr>'
	+'</table>';

	var optionsFrankrijk = ''
	+'<table class="vraagtable">'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Cote-d-Azur" /></td><td>Cote d Azur</td></tr>'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Languedoc-Roussillon" /></td><td>Languedoc-Roussillon</td></tr>'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Pays-de-la-Loire" /></td><td>Pays de la Loire</td></tr>'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Poitou-Charentes" /></td><td>Poitou-Charentes</td></tr>'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Aquitaine" /></td><td>Aquitaine</td></tr>'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Corsica" /></td><td>Corsica</td></tr>'
	+'</table>';

	var optionsItalie = ''
	+'<table class="vraagtable">'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Abruzzi" /></td><td style="width:200px">Abruzzi</td>   <td><input type="radio" style="border:0" name="Regio:" value="Puglia" /></td> <td>Puglia</td> </tr>'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Basilicata" /></td><td>Basilicata</td>                 <td><input type="radio" style="border:0" name="Regio:" value="Sardegna" /></td> <td>Sardegna</td> </tr>'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Calabria" /></td><td>Calabria</td>                     <td><input type="radio" style="border:0" name="Regio:" value="Toscana" /></td> <td>Toscana</td> </tr>'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Emilia Romagna" /></td><td>Emilia Romagna</td>         <td><input type="radio" style="border:0" name="Regio:" value="Trentino-Alto Adige" /></td> <td>Trentino-Alto Adige</td> </tr>'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Lazio" /></td><td>Lazio</td>                           <td><input type="radio" style="border:0" name="Regio:" value="Umbria" /></td> <td>Umbria</td> </tr>'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Liguria" /></td><td>Liguria</td>                       <td><input type="radio" style="border:0" name="Regio:" value="Valle-d-Aosta" /></td> <td>Valle d Aosta</td> </tr>'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Lombardia" /></td><td>Lombardia</td>                   <td><input type="radio" style="border:0" name="Regio:" value="Basilicata" /></td> <td>Basilicata</td> </tr>'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Marche" /></td><td>Marche</td>                         <td></td> <td></td> </tr>'
	+'</table>';

	var optionsZwitserland = ''
	+'<table class="vraagtable">'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Wallis" /></td><td>Wallis</td></tr>'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Ticino" /></td><td>Ticino</td></tr>'
	+'<tr><td><input type="radio" style="border:0" name="Regio:" value="Graubunden" /></td><td>Graub&uuml;nden</td></tr>'
	+'</table>';

	var optionsAnders = ''
	+'<table class="vraagtable">'
	+'<tr><td>Land en regio: &nbsp; &nbsp; </td><td><input type="text" name="Land-en-regio:_"  style="width:250px"  /></td></tr>'
	+'</table>';

	slbLand.onchange = function() {

		var land 	= this.options[this.selectedIndex].value;
		var regios	= document.getElementById('regios');

		if(land == "Spanje") 		{ regios.innerHTML = optionsSpanje; }
		if(land == "Frankrijk") 	{ regios.innerHTML = optionsFrankrijk; }
		if(land == "Italie") 		{ regios.innerHTML = optionsItalie; }
		if(land == "Zwitserland") 	{ regios.innerHTML = optionsZwitserland; }
		if(land == "Anders")	 	{ regios.innerHTML = optionsAnders; }

	}

}



function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}




function confirmDeleteIMG(formId) {

	var antwoord=confirm("Item verwijderen?");
	 if(antwoord) {
	 document.getElementById(formId).submit();
	 return true;
   } else {
	 	return false;
	  }
}




function initGal(type) {

	document.getElementById('blur').style.height = getDocHeight()+'px';


	  var btn=document.getElementById('gallery').getElementsByTagName("IMG");
	  for(var i=0;i<btn.length;i++) {

		gallery[i] = btn[i].src;

		btn[i].onmouseover=function() {
		  if(this.alt != 'na') {
		  this.style.cursor = 'pointer';
		  opacity(this.id, 100, 50, 128);

		  }
		}
		btn[i].onmouseout=function() {
		  if(this.alt != 'na') {
		  opacity(this.id, 50, 100, 768);
		  }
		}
		btn[i].onclick=function() {
		  currentPic = parseInt(this.id.substring(4))-1;
		  if(this.alt != 'na') {
		  showPic(this.id.substr(5), this.src);
		  }
		}
	  }



}


function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}


function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}




function showPic(fotoNr, fotoSrc) {

		var extraMarginTop = 82+f_scrollTop();

		document.getElementById('fotolijst').style.marginTop = extraMarginTop+'px'

		document.getElementById('fotogroot').src = fotoSrc;

		//effecten
		document.getElementById('blur').style.visibility = 'visible';
		opacity('blur', 0, 75, 100);
		setTimeout("document.getElementById('fotolijst').style.visibility = 'visible'", 10);
		setTimeout("document.getElementById('fotogroot').style.visibility = 'visible'", 10);
}






function popitup(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=350,height=600');");
return false;
}







function doRefresh() {
  window.location.reload();
}



function changePic(strId, strNewSrc) {
	document.getElementById(strId).src = strNewSrc;
}


function clearField(fieldId) {
  	var field = document.getElementById(fieldId);
  	field.value='';
}


function runFormCheck() {

	var fieldsToCheck = document.getElementById("fieldsToCheck").value;
	var submitId = document.getElementById("submitButtonId").value;
	var aantalCorrecteVelden	  = 0;
	var aantalCorrecteVeldenNodig = document.getElementById("fieldsToBeCorrect").value;
	var veld = fieldsToCheck.split("__");

	for ( var i in veld ) {
			var params = veld[i].split("|");

			/**************************************************************
			* @param text  Voor text velden
			*/
			if (params[1] == "text") {
				waardeIn = document.getElementById(params[0]).value.length;

				// IS DE LIMIT EEN MINIMUM OF MAXIMUM
				if(params[2].substring(0,3) == 'min') {
					if (params[2].substring(4) <= parseInt(waardeIn)) {
						aantalCorrecteVelden++;
					}
				} else {
					if (parseInt(waardeIn) >= params[2].substring(4)) {
						aantalCorrecteVelden++;
					}
				  }
			}
			/**************************************************************/



			/**************************************************************
			* @param text  Voor email adressen
			*/
			if (params[1] == "email") {
				if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById(params[0]).value)){
					aantalCorrecteVelden++;
				}
			}
			/**************************************************************/



			/**************************************************************
			* @param text  Voor checkboxen
			*/
			if (params[1] == "checkbox") {
				if (document.getElementById(params[0]).checked == true){
					aantalCorrecteVelden++;
				}
			}
			/**************************************************************/



	 } // einde for


	/**************************************************************
	* @param text  Submit button instellen
	*/
	if (aantalCorrecteVelden == aantalCorrecteVeldenNodig){
		document.getElementById(submitId).disabled = false;
	}
	else {
		document.getElementById(submitId).disabled = true;
	}
	/**************************************************************/


}






function valideerEmail(fieldId, submitId) {

field = document.getElementById(fieldId);

	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(field.value)){
		document.getElementById(submitId).disabled = false;
	}
	else {
		document.getElementById(submitId).disabled = true;
	}
}


function checkMinStrLength(fieldId, submitId, waardeMin) {

waardeIn = document.getElementById(fieldId).value.length;

if  ( parseInt(waardeIn) > waardeMin) {
		document.getElementById(submitId).disabled = false;
	} else {
   		document.getElementById(submitId).disabled = true;
	}
}



function setIntLength(waarde, maxwaarde, obj) {

	if ( parseInt(waarde) > maxwaarde) {
   		obj.value = maxwaarde;
   		alert("Het maximum aantal is "+maxwaarde);
	}
}



function setFloatInput(obj) {

	if((obj.value == '') || (!IsNumeric(obj.value)) ) {
		obj.value = 0
	}

}





function numbersOnly(evt){

  evt = (evt) ? evt : event;

  var c = (evt.charCode) ? evt.charCode :

 ((evt.keyCode) ?
 	evt.keyCode : ((evt.wich) ? evt.wich : 0));

   if (c > 31 && (c < 48 || c > 57)) {
    alert("Vul a.u.b. een getal in.");
    return false;
   }

   return true;
}


function IsNumeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;

}
















function opacity(id, opacStart, opacEnd, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;

	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}


