var xmlHttp = createXmlHttpRequestObject();
var xmlHttpcalendrier = createXmlHttpRequestObject();
var xmlHttpevenement = createXmlHttpRequestObject();
var xmlHttpaffiche = createXmlHttpRequestObject();
var xmlHttprofil = createXmlHttpRequestObject();

var lista1;
var lista2;
var lista3;
var lista4;
var vu = 'peinture';
var a_cacher = 'artbio';

function createXmlHttpRequestObject(){
	var xmlHttp;
	try	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e){
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP");
		for(var i=0; i<XmlHttpVersions.length && !xmlHttp; i++){
			try{
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch(e){}
		}
	}
	if(!xmlHttp){
		alert("Blad podczas tworzenia objektu XMLHttpRequest.");
	}else {
		return xmlHttp;
	}
}

function loadListe(dest,element){
	if(element == 'alpha'){document.getElementById('ls').style.display = 'none';document.getElementById('lp').style.display = 'inline'}
	if(element == 'autres'){document.getElementById('lp').style.display = 'none';document.getElementById('ls').style.display = 'inline'}
}

function loadCalendar(dest,month,year,move){  //    <a href="ex.calendar.3.php?month='.date('n').'&year='.date('Y').'&move=">Now</a>
	//timeraffiche('up');
	//var div = document.getElementById('cald');div.style.display = "none";
	//var div = document.getElementById('gest');div.style.display = "block";
	if(xmlHttpcalendrier){
		xmlHttpcalendrier.open("GET", "calendar.php?month="+month+"&year="+year+"&move="+move);
		xmlHttpcalendrier.onreadystatechange = function()
		{
			if(xmlHttpcalendrier.readyState == 4 && xmlHttpcalendrier.status == 200) {
				var div = document.getElementById(dest);
				var agenda = xmlHttpcalendrier.responseText;
				div.innerHTML = agenda;
			}
		}
		xmlHttpcalendrier.send(null);
	}
}


function loadEvenement(dest,year,month,day,who){  //    <a href="ex.calendar.3.php?month='.date('n').'&year='.date('Y').'&move=">Now</a>
	if(xmlHttpevenement){
		xmlHttpevenement.open("GET", "list-evenement.php?pseudo=treizeplus&num="+who+"&year="+year+"&month="+month+"&day="+day);
		//xmlHttpevenement.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xmlHttpevenement.onreadystatechange = function()
		{
			if(xmlHttpevenement.readyState == 4 && xmlHttpevenement.status == 200) {
				var div = document.getElementById(dest);
				var expo = xmlHttpevenement.responseText;
				div.innerHTML = expo;
			}
		}
		xmlHttpevenement.send(null);
	}
}


function loadAffiche(dest){  //    <a href="ex.calendar.3.php?month='.date('n').'&year='.date('Y').'&move=">Now</a>
	if(xmlHttpaffiche){
		
		xmlHttpaffiche.open("POST", "randomaffiche.php");
		
		xmlHttpaffiche.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xmlHttpaffiche.onreadystatechange = function()
		{
			if(xmlHttpaffiche.readyState == 4 && xmlHttpaffiche.status == 200) {
				var div = document.getElementById(dest);
				var affichage = xmlHttpaffiche.responseText;
				div.innerHTML = affichage;
			}
		}
		xmlHttpaffiche.send("none=");
	}
}



function afficher(dest,action){
	if(dest == 'none'){dest = lista};
	var div = document.getElementById(dest);
	if(action == "up"){div.style.display = "block";}
	if(action == "down"){div.style.display = "none";}
	lista = dest;
}

function loadExpoMonth(month,year){
	alert(month+" "+year);
}

function afficherTexte(action,dest2,dest3,dest4,dest5,dest1,dest6){
	if(dest1 == 'none'){dest1 = lista1}
	if(dest2 == 'none'){dest2 = lista2}
	if(dest3 == 'none'){dest3 = lista3}
	if(dest4 == 'none'){dest4 = lista4}
	if(dest5 == 'none'){dest5 = lista5}
	if(dest6 == 'none'){dest6 = lista6}
	var div1 = document.getElementById(dest1);
	var div2 = document.getElementById(dest2);
	var div3 = document.getElementById(dest3);
	var div4 = document.getElementById(dest4);
	var div5 = document.getElementById(dest5);
	var div6 = document.getElementById(dest6);
	if(action == "up"){div1.style.display = "block";} if(action == "down"){div1.style.display = "none";}
	if(action == "up"){div2.style.display = "block";} if(action == "down"){div2.style.display = "none";}
	if(action == "up"){div3.style.display = "block";} if(action == "down"){div3.style.display = "none";}
	if(action == "up"){div4.style.display = "block";} if(action == "down"){div4.style.display = "none";}
	if(action == "up"){div5.style.display = "block";} if(action == "down"){div5.style.display = "none";}
	if(action == "up"){div6.style.display = "block";} if(action == "down"){div6.style.display = "none";}
	lista1 = dest1;
	lista2 = dest2;
	lista3 = dest3;
	lista4 = dest4;
	lista5 = dest5;
	lista6 = dest6;
}

function loadGestion(dest){ 
	//window.clearInterval(ID_affiche);
	var div = document.getElementById('gest');div.style.display = "none";
	var div = document.getElementById('cald');div.style.display = "block";
	var log;
	var pas;
	
	if(xmlHttprofil){
		xmlHttprofil.open("POST", "admin/login.php");
		xmlHttprofil.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xmlHttprofil.onreadystatechange = function()
		{
			if(xmlHttprofil.readyState == 4 && xmlHttprofil.status == 200) {
				var div = document.getElementById(dest);
				var map = xmlHttprofil.responseText;
				div.innerHTML = map;
			}
		}
		xmlHttprofil.send("login="+log+"&pass="+pas);
	}
}

function ldmember(dest,action){
	var div = document.getElementById(dest);
	var site = '<iframe id="gestionframe" src="frame.php?action='+action+'" scrolling="no">';
	div.innerHTML = site;
	
}

//.firstChild.nodeValue
function artdossier(a_montrer){
	if(a_montrer != a_cacher){
		document.getElementById(a_cacher).style.display ='none';
		document.getElementById(a_montrer).style.display ='block';
		a_cacher = a_montrer;
	}

}


function add_more_upload() {
	var new_total = Math.round(document.formgest.TOTAL_FILE.value) + 1;
	document.getElementById('attach_'  + document.formgest.TOTAL_FILE.value).innerHTML = "<input type='file' size='60' name='theFile[" +  new_total  + "]' /></p><p id='attach_" + new_total  + "'>";
	document.formgest.TOTAL_FILE.value++;
}


//////////////////
function checkForm()
{
	// the variables below are assigned to each
	// form input 
	var gname, gemail, gurl, gmessage, gnum;
	with(window.document.guestform)
	{
		gname    = txtName;
		gemail   = txtEmail;
		gurl     = txtUrl;
		gmessage = mtxMessage;
		gnum	 = txtNumber;
	}
	
	// if name is empty alert the visitor
	if(trim(gname.value) == '')
	{
		alert('Please enter your name');
		gname.focus();
		return false;
	}
	// alert the visitor if email is empty or the format is not correct 
	else if(trim(gemail.value) != '' && !isEmail(trim(gemail.value)))
	{
		alert('Please enter a valid email address or leave it blank');
		gemail.focus();
		return false;
	}
	// alert the visitor if message is empty
	else if(trim(gmessage.value) == '')
	{
		alert('Please enter your message');
		gmessage.focus();
		return false;
	}
	else if(trim(gnum.value) == '')
	{
		alert('Please enter a number then you see');
		gnum.focus();
		return false;
	}
	else
	{
		// when all input are correct 
		// return true so the form will submit		
		return true;
	}
}

/*
Strip whitespace from the beginning and end of a string
Input  : a string
Output : the trimmed string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}


/*
Check if a string is in valid email format. 
Input  : the string to check
Output : true if the string is a valid email address, false otherwise.
*/
function isEmail(str)
{
	var regex = /^[-_.a-z0-9]+@(([-a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
	return regex.test(str);
}
var gbsituation = 'jeden';
function changebook(){
	if(gbsituation == 'jeden'){
		document.getElementById('gbook').style.display = 'block';
		document.getElementById('gbin1').style.display = 'none';
		document.getElementById('gbin2').style.display = 'inline';
		gbsituation = 'dva';
	}
	else if(gbsituation == 'dva'){
		document.getElementById('gbook').style.display = 'none';
		document.getElementById('gbin1').style.display = 'inline';
		document.getElementById('gbin2').style.display = 'none';
		gbsituation = 'jeden';
	}
}





