function stap1(el){
	$('villel').show();
	regio = el.options[el.selectedIndex].value;
	   new Ajax.Request("ajax/getCities.php",
	   	  {
	   	  	   method: 'post',
	           postBody: 'regio='+regio,
	           onComplete : function(t,json)
	           {
					json.each(function(s){
						option = '<option value="'+s.loc_city+'">'+s.loc_city+'</option>';
						$('ville').insert({
							bottom: option
						});
					});
					$('ville').selectedIndex=0;
					$('villew').show();
					$('villel').hide();
	           }
	       }
	   );	
}
function stap2(el){
	$('sallel').show();
	ville = el.options[el.selectedIndex].value;

	   new Ajax.Request("ajax/getLocations.php",
	   	  {
	   	  	   method: 'post',
	           postBody: 'ville='+ville,
	           onComplete : function(t,json)
	           {
			   			
						json.each(function(s){
							head= s.loc_head;
							head = new String(head);
							
							option = '<option value="'+head+'">'+stripslashes(head)+'</option>';
						$('salle').insert({
							bottom: option
						});
						$('salle').selectedIndex=0;
					});
					$('sallel').hide();
					$('sallew').show();
							   	
	           }
	       }
	   );	
}
function stap3(el){
	$('detailsl').show();
	salle = el.options[el.selectedIndex].value;
	   new Ajax.Request("ajax/getInfo.php",
	   	  {
	   	  	   method: 'post',
	           postBody: 'salle='+salle,
	           onComplete : function(t,json)
	           {
					$('loc_head').update(stripslashes(json.loc_head));
					$('loc_address').update(stripslashes(json.loc_address));
					$('loc_number').update(stripslashes(json.loc_number));
					$('loc_postalcode').update(stripslashes(json.loc_postalcode));
					$('loc_city').update(stripslashes(json.loc_city));
					$('event_location').value = json.loc_id;
					if(json.loc_tel!='')$('loc_tel').update('Location: '+stripslashes(json.loc_tel)+'<br/>');
					if(json.loc_rens!='')$('loc_rens').update('Renseignement: '+stripslashes(json.loc_rens)+'<br/>');					
					if(json.loc_internet!='')$('loc_internet').update(stripslashes(json.loc_internet)+'<br/>');
					if(json.loc_tram!='')$('loc_tram').update('Tram: '+stripslashes(json.loc_tram)+'<br/>');
					if(json.loc_bus!='')$('loc_bus').update('Bus: '+stripslashes(json.loc_bus)+'<br/>');
					$('detailsl').hide();
					$('details').show();
					$('evenement').show();
			   }
			});
}
function stripslashes (str) {
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ates Goral (http://magnetiq.com)
    // +      fixed by: Mick@el
    // +   improved by: marrtins
    // +   bugfixed by: Onno Marsman
    // +   improved by: rezna
    // +   input by: Rick Waldron
    // +   reimplemented by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: stripslashes('Kevin\'s code');
    // *     returns 1: "Kevin's code"
    // *     example 2: stripslashes('Kevin\\\'s code');
    // *     returns 2: "Kevin\'s code"
    return (str+'').replace(/\\(.?)/g, function (s, n1) {
        switch (n1) {
            case '\\':
                return '\\';
            case '0':
                return '\0';
            case '':
                return '';
            default:
                return n1;
        }
    });
}
function saveLocation(red)
{
	
	   new Ajax.Request("ajax/saveLocation.php",
	   	  {
	   	  		
	   	  	   method: 'post',
			   asynchronous: false,
	           parameters: $('locForm').serialize(true),
	           onComplete : function(t)
	           {
					
	           		if(t.responseText=='')
	           		{
						alert("Vos modifications ont ete sauvegardees");	
	           		}
	           		else
	           		{
	           		
	           		}
	           }
	       }
	   );
}
function saveEvent(red)
{
	var ret ='';	
	   new Ajax.Request("ajax/saveEvent.php",
	   	  {
	   	  		
	   	  	   method: 'post',
			   asynchronous: false,
	           parameters: $('eventForm').serialize(true),
	           onComplete : function(t)
	           {
					//alert(t.responseText);
	           		if(red)
	           		{
						ret = t.responseText;			
	           		}
	           		else
	           		{
						document.location.href='index.php?action=insertions#commence';
	           		}
	           }
	       }
	   );
	   return ret;
}
function PadDigits(n, totalDigits) 
{ 
    n = n.toString(); 
    var pd = ''; 
    if (totalDigits > n.length) 
    { 
        for (i=0; i < (totalDigits-n.length); i++) 
        { 
            pd += '0'; 
        } 
    } 
    return pd + n.toString(); 
}
function updateTotal(){
	   new Ajax.Request("ajax/getTotal.php",
	   	  {
	   	  	   method: 'post',
			   postBody: 'id='+id,
			   onComplete : function(t)
	           				{
								$('total').update(CurrencyFormatted(t.responseText));							
							}		  	
		  });
}
function sendIt()
{
	id= $('event_id').value;
	new Ajax.Request("ajax/saveBestelling2.php",
	   	  {
	   	  	   method: 'post',
			   postBody: 'id='+id,
			   onComplete : function(t)
	           				{
								alert(t.responseText);							
							}		  	
		  });		
}
function sendForm()
{
	if(validate($('eventForm')))
	{
		//opslaan
	   new Ajax.Request("ajax/saveBestelling.php",
	   	  {
	   	  	   method: 'post',
			   parameters: $('eventForm').serialize(true),
			   onComplete : function(t)
	           				{
								alert(t.responseText);							
							}		  	
		  });		
	}
	{
		//niets
	}
}
function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}
function addDate()
{
	
	id = saveEvent(true);
	$('event_id').value = id;
	day = $('e_day').value;
	month = $('e_month').value;
	year = $('e_year').value;
	hour = $('e_hour').value;
	minute  = $('e_minute').value;
	price = $('price').value; 
	minute = PadDigits(minute,2)
	hour = PadDigits(hour,2)
   new Ajax.Request("ajax/saveDate.php",
	   	  {
	   	  	   method: 'post',
			   postBody: 'id='+id+'&day='+day+'&month='+month+'&year='+year+'&hour='+hour+'&minute='+minute+'&price='+price,
			   onComplete : function(t)
	           				{
								updateTotal();
								$('totalw').show();										
								span = '<span onmouseover="this.style.cursor=\'pointer\'" onclick="deleteDate('+id+','+day+','+month+','+year+','+hour+','+minute+',this);" style="color:red;text-decoration:underline;">[ Effacer ]</span>';						
								string = '<tr><td>&nbsp;</td><td>'+day+'-'+month+'-'+year+'</td><td>'+hour+':'+minute+'</td><td>'+span+'</td></tr>';
								$('datetable').insert({bottom:string});
								$('datetable').show();						
								if($('red_action').value=='event')
								{
									document.location.href='index.php?action=editEvent&id='+id+'#commence';
								}
								{
									document.location.href='index.php?action=event&id='+id+'#commence';	
								}
																
						    }
		   }
		);
	
}
function deleteDate(id,day,month,year,hour,minute,el)
{
		if (confirm('Supprimer?')) {
			new Ajax.Request("ajax/deleteDate.php", {
			
				method: 'post',
				postBody: 'id=' + id + '&day=' + day + '&month=' + month + '&year=' + year + '&hour=' + hour + '&minute=' + minute,
				onComplete: function(t){
					cell = Element.up(el);
					row = Element.up(cell);
					Element.remove(row);
					updateTotal();
				}
			});
		}
}
