var accordion;

var longChoise=new Array();
longChoise['Lid']='lid';
longChoise['Niet lid']='nietlid';
longChoise['Ringencommissaris']='comm';

window.addEvent('load', function()
{
	var radioNummers=new Array();
	radioNummers['lid']=0;
	radioNummers['nietlid']=1;
	radioNummers['comm']=2;

	accordion = new Accordion('h3.atStart', 'div.atStart', {
		opacity: true,
		onActive: function(toggler, element){
			toggler.setStyle('color', 'blue');
			
			radioNummer=radioNummers[toggler.id];
						
			$('index_form').LoNRadio[radioNummer].checked=true;
			accordion.display(radioNummers[radioNummer]);

			$('index_form').action=toggler.id+'_bestel.php';
			
			$('LoN').value=toggler.id;
		},
	 
		onBackground: function(toggler, element){
			toggler.setStyle('color', '#222222');
		},
		display: false
	}, $('accordion'));
	
	$$('input.togglerRadio').each(function(el){
		el.addEvent('click', function (){
			accordion.display(radioNummers[this.getProperty('ringenvalue')]);
			$('LoN').value=this.getProperty('ringenvalue');
		});
	});

});
var check_lid= function (){
	function createRequestObject() { 
	
	   var req; 
	
	   if(window.XMLHttpRequest){ 
		  req = new XMLHttpRequest(); 
	   } else if(window.ActiveXObject) { 
		  req = new ActiveXObject("Microsoft.XMLHTTP"); 
	   } else { 
		  alert('Uw systeem is verouderd, u kunt geen gebruik maken van het ringenbestelsysteem'); 
	   } 
	
	   return req; 
	
	}
	document.getElementById('lid_status').src = 'images/busy.gif';
	
	post_vals="nummer="+document.getElementById('lid_fokkersnummer').value;

	var http = createRequestObject() ;
	http.open('POST', 'check_lid.php', true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.setRequestHeader('Content-length', post_vals.length);
	http.onreadystatechange = function (){
		if(http.readyState == 4 && http.status == 200){
			if(http.responseText) {
		
				
				//alert(http.responseText);

				var xmlDoc=http.responseXML.documentElement;

				document.getElementById('lid_Naam').value          = xmlDoc.getElementsByTagName('naam')[0].childNodes[0].nodeValue;
				document.getElementById('lid_Adres').value         = xmlDoc.getElementsByTagName('adres')[0].childNodes[0].nodeValue;
				document.getElementById('lid_Postcode').value      = xmlDoc.getElementsByTagName('postcode')[0].childNodes[0].nodeValue;
				document.getElementById('lid_Woonplaats').value    = xmlDoc.getElementsByTagName('plaats')[0].childNodes[0].nodeValue;

				//Land hoeft niet ingevuld te zijn.
				if (xmlDoc.getElementsByTagName('land')[0].childNodes.length > 0)
					document.getElementById('lid_Land').value = xmlDoc.getElementsByTagName('land')[0].childNodes[0].nodeValue;
				else
					document.getElementById('lid_Land').value = 'Nederland';
				

				//Email hoeft niet ingevuld te zijn.
				if (xmlDoc.getElementsByTagName('email')[0].childNodes.length > 0)
					document.getElementById('lid_Email').value = xmlDoc.getElementsByTagName('email')[0].childNodes[0].nodeValue;
				else
					document.getElementById('lid_Email').value = '';
				
				document.getElementById('form_submit').disabled="";

				document.getElementById('lid_status').src = 'images/tick.png'; 

			} else { 
				document.getElementById('lid_status').src = 'images/exclamation.png'; 
				document.getElementById('form_submit').disabled="disabled";
			}
		} else { 
			//busy
		} 
	}
	http.send(post_vals);
	

}

var check_comm= function (){
	

	function createRequestObject() { 
	
	   var req; 
	
	   if(window.XMLHttpRequest){ 
		  req = new XMLHttpRequest(); 
	   } else if(window.ActiveXObject) { 
		  req = new ActiveXObject("Microsoft.XMLHTTP"); 
	   } else { 
		  alert('Je browser ondersteund geen AJAX... koop een nieuwe'); 
	   } 
	
	   return req; 
	
	}
	

	document.getElementById('comm_status').src = 'images/busy.gif';
	
	post_vals="nummer="+document.getElementById('comm_code').value;

	var http = createRequestObject() ;
	http.open('POST', 'check_ver.php', true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.setRequestHeader('Content-length', post_vals.length);
	http.onreadystatechange = function (){
		if(http.readyState == 4 && http.status == 200){
			if(http.responseText != '') {
		

				var xmlDoc=http.responseXML.documentElement;
				
				if (xmlDoc.getElementsByTagName('naam')==null){
					document.getElementById('comm_status').src = 'images/exclamation.png'; 
				}

				document.getElementById('comm_Vereniging').value = xmlDoc.getElementsByTagName('naam')[0].childNodes[0].nodeValue;
								
				document.getElementById('comm_status').src = 'images/tick.png'; 


				document.getElementById('comm_fokkersnummer').disabled = ''; 
				document.getElementById('check_comm_twee').disabled = ''; 
				
				document.getElementById('comm_Naam').disabled="";;
				document.getElementById('comm_Adres').disabled="";;
				document.getElementById('comm_Postcode').disabled="";;
				document.getElementById('comm_Plaats').disabled="";;
				document.getElementById('comm_Land').disabled="";;
				document.getElementById('comm_Email').disabled="";;
			} else { 
				document.getElementById('comm_status').src = 'images/exclamation.png'; 
				alert('Let op!\n\nEen verenigingscode bestaat uit hoogstens 1 of 2 letters gevolgd door 1 of 2 cijfers. In totaal 3 karakters.');
			}
		} else { 
			//busy
		} 
	}
	http.send(post_vals);
	

}

var check_comm_twee= function (){
	function createRequestObject() {  var req; 
	   if(window.XMLHttpRequest){ 
		  req = new XMLHttpRequest(); 
	   } else if(window.ActiveXObject) { 
		  req = new ActiveXObject("Microsoft.XMLHTTP"); 
	   } else { 
		  alert('Je browser ondersteund geen AJAX... koop een nieuwe'); 
	   } 
	   return req; 
	}
	document.getElementById('comm_status_twee').src = 'images/busy.gif';
	
	fokkersnummer=document.getElementById('comm_fokkersnummer').value;
	
	if (fokkersnummer != 'X00-1234567')
	{
		post_vals="nummer="+fokkersnummer;
		
		var http = createRequestObject() ;
		http.open('POST', 'check_lid.php', true);
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.setRequestHeader('Content-length', post_vals.length);
		http.onreadystatechange = function (){
			if(http.readyState == 4 && http.status == 200){
				if(http.responseText != '') {
					var xmlDoc=http.responseXML.documentElement;
					
					if (!xmlDoc.getElementsByTagName('naam')){
						document.getElementById('comm_status_twee').src = 'images/exclamation.png'; 
					}
					else
					{
						document.getElementById('comm_Naam').value      = xmlDoc.getElementsByTagName('naam')[0].childNodes[0].nodeValue;
						document.getElementById('comm_Adres').value     = xmlDoc.getElementsByTagName('adres')[0].childNodes[0].nodeValue;
						document.getElementById('comm_Postcode').value  = xmlDoc.getElementsByTagName('postcode')[0].childNodes[0].nodeValue;
						document.getElementById('comm_Plaats').value    = xmlDoc.getElementsByTagName('plaats')[0].childNodes[0].nodeValue;

						//Land hoeft niet ingevuld te zijn.
						if (xmlDoc.getElementsByTagName('lid_Land')[0]){
							document.getElementById('comm_Land').value = xmlDoc.getElementsByTagName('land')[0].childNodes[0].nodeValue;
						}else{
							document.getElementById('comm_Land').value = 'Nederland';
						}
						
						comm_email=document.getElementById('comm_Email');
						form_submit=document.getElementById('form_submit');
						
						if(xmlDoc.getElementsByTagName('email')[0].childNodes.length > 0)
						{
							comm_email.value = xmlDoc.getElementsByTagName('email')[0].childNodes[0].nodeValue;
							form_submit.disabled="";
						}
						else
						{
							comm_email.value = "Gebruik van emailadres is verplicht";
							comm_email.style.border = "2px solid #ff0000";
							form_submit.disabled="disabled";
							comm_email.onclick=function(){if(comm_email.value=='Gebruik van emailadres is verplicht'){ comm_email.value='';} }
							comm_email.onkeyup=function(){if(comm_email.value!=''){form_submit.disabled=''; }else{ form_submit.disabled='disabled'; } }
						
						}						
						document.getElementById('comm_status_twee').src = 'images/tick.png'; 
					}
				} else { 
					document.getElementById('comm_status_twee').src = 'images/exclamation.png';
					document.getElementById('form_submit').disabled="disabled";
				}
			} else { 
				//busy
			} 
		}
		http.send(post_vals);
	}else{//als fokkerskaarnummer het nummer is voor nietleden!
		comm_Naam     = document.getElementById('comm_Naam');
		comm_Adres    = document.getElementById('comm_Adres');
		comm_Postcode = document.getElementById('comm_Postcode');
		comm_Plaats   = document.getElementById('comm_Plaats');
		comm_Land     = document.getElementById('comm_Land');
		comm_Email    = document.getElementById('comm_Email');
		
		
		comm_Naam.disabled="";     comm_Naam.value="";     comm_Naam.style.border="1px solid #ffcc00";
		comm_Adres.disabled="";    comm_Adres.value="";    comm_Adres.style.border="1px solid #ffcc00";
		comm_Postcode.disabled=""; comm_Postcode.value=""; comm_Postcode.style.border="1px solid #ffcc00";
		comm_Plaats.disabled="";   comm_Plaats.value="";   comm_Plaats.style.border="1px solid #ffcc00";
		comm_Land.disabled="";     comm_Land.value="";     comm_Land.style.border="1px solid #ffcc00";
		comm_Email.disabled="";    comm_Email.value="";    comm_Email.style.border="1px solid #ffcc00";

		document.getElementById('form_submit').disabled="";

		document.getElementById('comm_status_twee').src = 'images/textfield_rename.png';
	}
	

}


var lid='';

function enableForm(formName){
	var forms=new Array(3);
	forms["comm"]=new Array(5);
	 forms["comm"]='Naam,Adres,Postcode,Woonplaats,Land'.split(',');
	
	for(x=0;x<forms[formName].length;x++){
		document.getElementById(forms[formName][x]).enabled=true;
	}
		

}

function checkForm(){

	theform=document.getElementById('index_form');
	formtype=$('LoN').value;
	switch(formtype){
	
		case 'lid':
		
			if (document.getElementById('lid_Email').value == ''){
				ok = confirm ("U heeft geen email adres ingevuld...\nU kunt nu geen bevestiging van uw bestelling ontvangen");
				if (ok)	theform.submit();
			}else{
				theform.submit();
			}
		break;
		case 'comm':
			if (document.getElementById('comm_fokkersnummer').value == 'X00-1234567')
			{
				ids=new Array();
				ids[0]='comm_Naam';
				ids[1]='comm_Adres';
				ids[2]='comm_Postcode';
				ids[3]='comm_Plaats';
				ids[4]='comm_Land';
				ids[5]='comm_Email';
				
				err=false;
				
				for(x=0;x<ids.length;x++)
				{
					if (document.getElementById(ids[x]).value == '')
					{
						document.getElementById(ids[x]).style.border="1px solid #f00";
						err=true;
					}else{
						document.getElementById(ids[x]).style.border="1px solid #0f0";
					}
				}
				
				if (!err) theform.submit();
			
			}else
			{
				theform.submit();
			}
		break;
		
		case 'nietlid':
			err=false;
			ids=new Array();
			ids[0]=new Array('nietlid_Naam','notempty');
			ids[1]=new Array('nietlid_Adres','notempty');
			ids[2]=new Array('nietlid_Postcode','notempty');;
			ids[3]=new Array('nietlid_Plaats','notempty');;
			ids[4]=new Array('nietlid_Land','notempty');
			ids[5]=new Array('nietlid_Email','email');
			
			for(x=0;x<ids.length;x++)
			{
				switch(ids[x][1]){
				case 'notempty':
					if (document.getElementById(ids[x][0]).value == '')
					{
						document.getElementById(ids[x][0]).style.border="1px solid #f00";
						err=true;
					}else{
						document.getElementById(ids[x][0]).style.border="1px solid #0f0";
					}
				break;
				case 'email':
					var x = document.getElementById(ids[x][0]);
					var filter  = /^([a-zA-Z0-9_\.\-]{2,})\@(([a-zA-Z0-9\-]){2,})\.([a-zA-Z0-9]{2,4})+$/;
					if (!filter.test(x.value)){
						err=true;
						x.style.border="1px solid #f00";
					}else{
						x.style.border="1px solid #0f0";
					}
				break;
				}
				
			}
			if (!err) theform.submit();
		break;
	
	}
}
