//enkele controle parameters initialiseren
var RegisteredCalls= new Array();
var Aktiveer = false;
var subNietAktief    = -1;
var subsubNietAktief = -1;
var TimerObj1 = null;
var TimerObj2 = null;
var PicCount = 0;
var PicAktief = 0;
var FotoFrameWidth = 435;
var ThumbParaW = new Array();
var hoofdframeok=false;
var subframeok=false;

function SchakelMenu(ObjNaam,ObjId,Status){
  if(Aktiveer){
	if(Status){
		if(ObjId==subNietAktief) subNietAktief = -1;
		if(ObjId==subsubNietAktief) subsubNietAktief = -1;

		document.getElementById(ObjNaam+'menu'+ObjId).className=ObjNaam+'menuholderhi';

		//indien nodig ander menu op gelijk niveau sluiten
		if(ObjNaam=='sub' && subNietAktief>0){
			Status=0;
			ObjId=subNietAktief;
		}
		if(ObjNaam=='subsub' && subsubNietAktief>0){
			Status=0;
			ObjId=subsubNietAktief;
		}

	}

	if(!Status){
		if(subNietAktief==ObjId){
			document.getElementById('submenu'+subNietAktief).className='submenuholder';
			subNietAktief = -1;

			//diepere nav ook sluiten
			if(subsubNietAktief>0) ObjId=subsubNietAktief;
		}
		if(subsubNietAktief==ObjId){
			document.getElementById('subsubmenu'+subsubNietAktief).className='subsubmenuholder';
			subsubNietAktief = -1;
		}

	}

	if(subNietAktief < 0) clearTimeout(TimerObj1);
	if(subsubNietAktief < 0 ) clearTimeout(TimerObj2);
  }
}


function RegisterObj(ObjNaam){
	this.name = ObjNaam;
	this.http = getXMLHTTPRequest();
	this.saveinprogress = false;
}


function RegisterHttpxCalls(ObjName){

	var NewCall=true;
	var CallInt = -1;

	NrCalls=RegisteredCalls.length;
	for(x=0;x < NrCalls;x++){
		if(RegisteredCalls[x].name==ObjName){
			NewCall = false;
			CallInt = x;
		}
	}

	if(NewCall){
		RegisteredCalls[NrCalls]=new RegisterObj(ObjName);
		CallInt = NrCalls;
	}

	return(CallInt);
}


function HttpxCallAktief(CallId){
	IsActief=false;

	if(CallId > -1){
		if(RegisteredCalls[CallId].http.readyState > 0 && RegisteredCalls[CallId].http.readyState < 4){
			IsActief=true;
		}
	}

	if(IsActief) alert('Even geduld aub er worden momenteel gegevens opgeslagen');

	return(IsActief);

}

function HttpxAktief(){

	IsActief=false;

	NrCalls=RegisteredCalls.length;
	for(x=0;x < NrCalls;x++){
		if(RegisteredCalls[x].http.readyState > 0 && RegisteredCalls[x].http.readyState < 4){
			IsActief=true;
		}
	}
	
	return(IsActief);
}

function getXMLHTTPRequest(){

	try {
		req = new XMLHttpRequest();

	} catch(err1) {

		try {
			req = new ActiveXObject('Msxml2.XMLHTTP');

		} catch (err2) {
			try {
				req = new ActiveXObject('Microsoft.XMLHTTP');

			} catch (err3) {
				req = false;
			}
		} 
	}

	return req;
}


function VeranderAantal(myfield, nr, Pagina){
//waarde overzetten in webshop formulier
	if(1*myfield.value < 1){
		myfield.value='';
		window.thumbvlak.document.getElementById('vinkje'+nr).className='checkb';
	} else {
		window.thumbvlak.document.getElementById('vinkje'+nr).className='checkbaktief';
	}

	window.thumbvlak.SetWebshopItems(Pagina);
}


function VeranderBestelAantal(myfield, nr, Pagina){
//waarde overzetten in webshop formulier

	window.thumbvlak.SetWebshopItems(Pagina);
}


function SchakelShopitem(ObjNr,Pagina){
  if(parent.hoofdframeok && parent.subframeok){
	ObjNr=1*ObjNr;
	//zet de focus
	window.parent.document.getElementById('infokeuze'+parent.PicAktief).className='infonietaktief';
	parent.PicAktief=ObjNr;
	window.parent.document.getElementById('infokeuze'+ObjNr).className='infoaktief';
	parent.tekstvlak.scrollTo((ObjNr * FotoFrameWidth),0);
  }
}


function FocusItem(ObjNr){

	document.getElementById('infokeuze'+parent.PicAktief).className='infonietaktief';
	parent.PicAktief=ObjNr;
	document.getElementById('infokeuze'+parent.PicAktief).className='infoaktief';
	tekstvlak.scrollTo((ObjNr * FotoFrameWidth),0);
	CalcThumbPos();
}

function UpdateShopitem(CurObj,ObjNr,Pagina){
  if(parent.hoofdframeok && parent.subframeok){
	if(CurObj.className.indexOf('aktief')==-1){
		document.WebShopForm.shopitem[ObjNr].checked=true;
		CurObj.className='checkbaktief';
		window.parent.document.WebShopForm.elements['aantal'+ObjNr].value=1;
		SchakelShopitem(ObjNr,Pagina);

	} else {
		document.WebShopForm.shopitem[ObjNr].checked=false;
		CurObj.className='checkb';
		window.parent.document.WebShopForm.elements['aantal'+ObjNr].value=0;
	}
  }
	SetWebshopItems(Pagina);
}

function SetWebshopItems(pagina){//Tussentijdse opslag keuzes

	if(HttpxAktief()){
		alert('Even geduld aub er worden momenteel gegevens verwerkt');

	} else {
		CallId = RegisterHttpxCalls('MyWebshopItems');
		var keuzepara='';
		var aantalpara='';
		if(document.WebShopForm.aktie.value=='bestellen'){
			for(ec=0;ec < window.parent.document.WebShopForm.elements.length;ec++){
				CheckNaam=window.parent.document.WebShopForm.elements[ec].name;
				if(CheckNaam.substr(0,6)=='aantal'){
					Aantal=window.parent.document.WebShopForm.elements[ec].value;
					Nr=CheckNaam.substring(6,CheckNaam.length);
					if(Aantal > 0){
						if(keuzepara.length) keuzepara+=',';
						keuzepara+=Nr;

						if(aantalpara.length) aantalpara+=',';
						aantalpara+=Aantal;
					}
				}
			}

		} else {

			for(c=0;c < document.WebShopForm.shopitem.length-1;c++){
				Aantal = 1*window.parent.document.WebShopForm.elements['aantal'+c].value;

				if(Aantal > 0){
					document.WebShopForm.shopitem[c].checked=true;

					if(keuzepara.length) keuzepara+=',';
					keuzepara+=c;

					if(aantalpara.length) aantalpara+=',';
					aantalpara+=Aantal;

				} else {
					document.WebShopForm.shopitem[c].checked=false;
				}

			}

		}

		Url='index.php?ID='+pagina+'&module=webshopxml&keuzes='+keuzepara+'&aantal='+aantalpara;

		if(!HttpxCallAktief(CallId)){
			RegisteredCalls[CallId].http.open('GET',Url,true);
			RegisteredCalls[CallId].http.onreadystatechange = httpWebshopItems;
			RegisteredCalls[CallId].http.send(null);
		}
	}

}

function httpWebshopItems(){

	CallId = RegisterHttpxCalls('MyWebshopItems');

	if(RegisteredCalls[CallId].http.readyState == 4){

		if(RegisteredCalls[CallId].http.status == 200){//de resultaten inlezen
			var BestelTekst='';
			var resultaat = RegisteredCalls[CallId].http.responseXML.getElementsByTagName('webshopdata')[0];
			SubTotaal=resultaat.getAttribute('subtotaal');
			var bestelknopclass='bestelnietaktief';

			for(i=0;i < resultaat.childNodes.length;i++){
				Aantal=resultaat.childNodes[i].getAttribute('aantal');
				Prijs=resultaat.childNodes[i].getAttribute('prijs');
				if(1*Aantal > 0 && Prijs.length > 0)
					bestelknopclass='bestelaktief';

			}
			if(SubTotaal.length > 0)
				BestelTekst='&euro;&nbsp;'+SubTotaal;

			if(document.WebShopForm.aktie.value=='bestellen'){
				window.parent.document.getElementById('totaal').innerHTML='';
				window.parent.document.getElementById('totaal').innerHTML=BestelTekst;

			} else {
				window.parent.document.getElementById('bestelknop').className=bestelknopclass;
			}

		}
	}

}



function ShowMenu(ObjNaam,ObjId){
	if(Aktiveer) SchakelMenu(ObjNaam,ObjId,1);
}


function VerbergMenu(ObjNaam,ObjId){
  if(Aktiveer){
	if(ObjNaam=='sub'){
		subNietAktief = ObjId;
		TimerObj1 = setTimeout("SchakelMenu('"+ObjNaam+"',"+ObjId+",0);",600);

	}
	if(ObjNaam=='subsub'){
		subsubNietAktief = ObjId;
		TimerObj2 = setTimeout("SchakelMenu('"+ObjNaam+"',"+ObjId+",0);",600);
	}
  }
}


function OpenVenster(waarheen,breedte,hoogte){
	DetailVenster = window.open(waarheen,'Detail','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizeable=yes,width='+breedte+',height='+hoogte);
	DetailVenster.focus();
}


function NaarExterneSite(waarheen){

	ExterneSiteVenster = window.open(waarheen,'_blank');
	ExterneSiteVenster.focus();

}


function GaNaarUrl(waarheen){

	MijnSiteVenster = window.open(waarheen,'_top');

}



function VerstuurContact(Vorm){
 	var FoutBericht='';
 	if(Vorm.Naam.value=='') FoutBericht+=' - Naam ';
 	if(Vorm.Email.value.length=='' || Vorm.Email.value.indexOf('@')==-1) FoutBericht+=' - E-mail ';
 	if(Vorm.Opmerkingen.value=='') FoutBericht+=' - Opmerking of vraag ';

 	if(FoutBericht.length){
 		alert('Controleer de volgende velden: '+FoutBericht);
 	} else {
 		Vorm.submit();
 	}
}

function VerstuurBestelling(Vorm){
 	var FoutBericht='';
 	if(Vorm.Naam.value=='') FoutBericht+=' - Naam ';
	if(Vorm.Adres.value=='') FoutBericht+=' - Adres ';
	if(Vorm.PCWoonplaats.value=='') FoutBericht+=' - Postcode & woonplaats ';
	if(Vorm.Telefoon.value=='') FoutBericht+=' - Telefoon ';
	if(Vorm.Email.value.length=='' || Vorm.Email.value.indexOf('@')==-1) FoutBericht+=' - E-mail ';

	if(!Vorm.Betalingswijze[0].checked && !Vorm.Betalingswijze[1].checked) FoutBericht+=' - Betalingswijze ';

 	if(FoutBericht.length){
 		alert('Controleer de volgende velden: '+FoutBericht);
 	} else {
 		Vorm.submit();
 	}
}


function ChkScrollBestellst(){
	MaxY=214;
	if(document.getElementById('bestellingen').offsetHeight <= MaxY){
		//dan scroll elementen uitschakelen
		document.getElementById('bestelscrollup').className='bestelscrollnietaktief';
		document.getElementById('bestelscrolldown').className='bestelscrollnietaktief';
	}
}

function BestelScrollNaar(curRichting){
	var Snelheid = 5;


	BestelObj=document.getElementById('bestellst');

	HoogteTotaal = document.getElementById('bestellingen').offsetHeight;

	MaxVerschil=HoogteTotaal - 200;

	HuidigePos = parseInt(BestelObj.style.top);
	if(isNaN(HuidigePos)) HuidigePos=0;

	NieuwePos = HuidigePos + curRichting*Snelheid;

	if(NieuwePos <= 0){
		if(curRichting>0){//beneden
			BestelObj.style.top= NieuwePos + 'px';
			if(curRichting!=0) setTimeout('BestelScrollNaar(2)',30);
		}

		if(curRichting < 0){//omhoog
			if(NieuwePos > -1 * MaxVerschil){
				BestelObj.style.top= NieuwePos + 'px';
				if(curRichting!=0) setTimeout('BestelScrollNaar(-2)',30);
			}
		}

	}

}


function BestellingVerstuurd(){
	window.parent.document.getElementById('bestelknop').className='bestelnietaktief';
	window.parent.document.getElementById('bestellst').innerHTML='';

}

function CheckHerkomst(BasisUrl,ParaChk,ExtraPara,MaxY){
//ivm afvangen links die rechtstreeks de content oproepen
	if(window.name!=ParaChk){
		document.location.href=BasisUrl;
	} else {

		if(MaxY > 0){
			//hoogte venster opvragen
			if(document.getElementById('websitecontent').offsetHeight <= MaxY){
				//de scroll optie uitschakelen
				parent.SchakelScroll();
			}
		}

		if(ParaChk=='tekstvlak'){
			parent.hoofdframeok=true;

			if(ExtraPara > 0){
				parent.PicCount = ExtraPara;
				parent.PicAktief = 0;
			}
		}

		if(ParaChk=='thumbvlak'){
			parent.subframeok=true;

			parent.ThumbParaW=ExtraPara.split(',');
		}
	}
}

function SchakelScroll(){
	document.getElementById('scrollknoppen').className='scrollnietaktief';
}

function SchakelStijl(ObjNaam,stijl){
	document.getElementById(ObjNaam+'a').className=stijl;
	document.getElementById(ObjNaam+'b').className=stijl;
}

function SchakelImg(ObjNaam,plaatje){
	document.getElementById(ObjNaam).src=plaatje;
}


var MuisAktie=0;


function ScrollNaar(Aktie){

	if(Aktie > -2 && Aktie < 2) MuisAktie=Aktie;

	if(MuisAktie > 0){
		DoScrollNaar();
		setTimeout('ScrollNaar(2)',30);

	} else if(MuisAktie < 0){
		DoScrollTerug();
		setTimeout('ScrollNaar(-2)',30);

	}

}

function DoScrollNaar(){

	window.tekstvlak.scrollBy(0,10);
}

function DoScrollTerug(){

	window.tekstvlak.scrollBy(0,-10);
}


function CalcThumbPos(){

	var VensterBreedte=585;
	var NewPos = 0;
	var TotaalW = 0;
	for(c=0;c < ThumbParaW.length;c++){
		if(c) TotaalW+=10;//de spacing
		TotaalW+=1*ThumbParaW[c];
		if(c < PicAktief) NewPos=TotaalW;
	}

	if(TotaalW > VensterBreedte){

		var NewThumbPos=NewPos - Math.floor(VensterBreedte/2);

		if(NewThumbPos > 0){
			window.thumbvlak.scrollTo(NewThumbPos,0);
		} else {
			window.thumbvlak.scrollTo(0,0);
		}
	}

}



function DoScrollLeft(){
  if(hoofdframeok && subframeok){
	document.getElementById('infokeuze'+PicAktief).className='infonietaktief';

 	if(PicAktief <= PicCount && PicAktief>0){
		PicAktief--;
		document.getElementById('infokeuze'+PicAktief).className='infoaktief';
		window.tekstvlak.scrollBy(-1*FotoFrameWidth,0);
	} else {
		PicAktief=PicCount-1;
		document.getElementById('infokeuze'+PicAktief).className='infoaktief';
		window.tekstvlak.scrollBy(FotoFrameWidth*PicCount,0);		
	}
	CalcThumbPos();
  }
}

function DoScrollRight(){
  if(hoofdframeok && subframeok){
	document.getElementById('infokeuze'+PicAktief).className='infonietaktief';

	if(PicAktief>=0 && PicAktief < PicCount - 1){
		PicAktief++;
		document.getElementById('infokeuze'+PicAktief).className='infoaktief';
		window.tekstvlak.scrollBy(FotoFrameWidth,0);
	} else {
		PicAktief=0;
		document.getElementById('infokeuze'+PicAktief).className='infoaktief';
		window.tekstvlak.scrollTo(0,0);
	}
	CalcThumbPos();
  }
}


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;
	} else if((("0123456789").indexOf(keychar) > -1)){// numbers
		return true;
	} else {
		return false;
	}
}

function StartScripts(){
//initdefaults

	//para voor uitklap menu
	subNietAktief    = -1;
	subsubNietAktief = -1;
	Aktiveer = true;
	TimerObj1 = null;
	TimerObj2 = null;

	//para voor content frame met grote afbeeldingen
//	PicCount = 0;
	PicAktief = 0;

	//para voor thumbs frame met kleine afbeeldingen
//	ThumbParaW=new Array();

}

