/* formulaire de contact */
var default_input_style_border = "1px solid #999999";
var error_input_style_border = "1px solid red";

var default_select_style_border = "1px solid #999999";
var error_select_style_border = "1px solid red";

function check_contact_form(form)
{
	erreurs = 0;
  //erreurs += select_is_selected(form.elements["contact[civilite]"]) ? 0 : 1;
  erreurs += input_not_blank(form.elements["contact[nom]"]) ? 0 : 1;
  erreurs += input_not_blank(form.elements["contact[prenom]"]) ? 0 : 1;
  erreurs += input_not_blank(form.elements["contact[ville]"]) ? 0 : 1;
  erreurs += input_not_blank(form.elements["contact[code_postal]"]) ? 0 : 1;
  erreurs += input_not_blank(form.elements["contact[email]"]) ? 0 : 1;
  //erreurs += input_not_blank(form.elements["contact[adresse]"]) ? 0 : 1;
  erreurs += input_not_blank(form.elements["contact[message]"]) ? 0 : 1;
  erreurs += select_is_selected(form.elements["contact[destinataire]"]) ? 0 : 1;
  //erreurs += input_not_blank(form.elements["contact[objet]"]) ? 0 : 1;
	if (erreurs > 0)
		alert("Merci de remplir correctement tous les champs obligatoire.");
	
	return erreurs == 0;
}

function check_agenda_form(form)
{
	erreurs = 0;
  erreurs += select_is_selected(form.elements["agenda[commision]"]) ? 0 : 1;
  //erreurs += select_is_selected(form.elements["agenda[membre_commision]"]) ? 0 : 1;
	if (erreurs > 0)
		alert("Merci de remplir correctement tous les champs obligatoire.");
	
	return erreurs == 0;
}

function input_not_blank(input)
{
	if (input.value.length > 0)
	{
		input.style.border = default_input_style_border;
		return true;
	}
	else
	{
		input.style.border = error_input_style_border;
		return false;
	}
}
	
function select_is_selected(select)
{
	if (select.value != -1)
	{
		select.style.border = default_select_style_border;
		return true;
	}
	else
	{
		select.style.border = error_select_style_border;
		return false;
	}
}

/* menu */
function change_class_active(val) {
		var a = val.childNodes[1];
		a.className= "ahover_active";
		var btn = val.childNodes[0];
		//btn.className= "puce_active";
		btn.className= "puce";
	} 
	function change_class_out(val) {
		var btn = val.childNodes[0];
		btn.className= "puce";
		var a = val.childNodes[1];
		a.className= "ahover";
	}


function getElementsByClassName(needle)	{
	  var         my_array = document.getElementsByTagName("*");
	  var         retvalue = new Array();
	  var         i;
	  var         j;
	
	  for (i = 0, j = 0; i < my_array.length; i++)
	  {
		var c = " " + my_array[i].className + " ";
		if (c.indexOf(" " + needle + " ") != -1)
		  retvalue[j++] = my_array[i];
	  }
	  return retvalue;
}

function impression() {
 window.frames[0].print();
 
 //var img=window.frames[0].document.getElementById("imprim_img").innerHTML;
 //var titre=window.frames[0].document.getElementById("imprim_titre").innerHTML;
 //var contenu=window.frames[0].document.getElementById("imprim_contenu").innerHTML;
//alert(table); 
 } 

function printPopAcc(){
	var header = document.getElementById("header");	
	if(document.getElementById("haut") == null){
		var haut = document.getElementById("haut_intra");	
	}else{
		var haut = document.getElementById("haut");
	}
	var icone_action = document.getElementById("icone_action");	
	var right = document.getElementById("right");
	var pied = document.getElementById("pied");
	var menu = document.getElementById("menu_haut");
	
	header.style.display="none";	
	haut.style.display="none";
	icone_action.style.display="none";	
	pied.style.display="none";
	right.style.display="none";
	menu.style.display="none";
	
	//les style 
	var conteneur = document.getElementById("conteneur");
	conteneur.style.margin="0px  0px 0px 0px";
	conteneur.style.width="650px";
	
	var right = document.getElementById("left");
	right.style.margin="0px  0px 0px 20px";
	right.style.width="649px";
	
	var centre_page = document.getElementById("centre");
	centre_page.style.margin="0px  0px 0px 0px  ";
	centre_page.style.width="650px";
	
	var contenu_page = document.getElementById("contenu_centre");
	contenu_page.style.margin="0px  0px 0px 0px  ";
	contenu_page.style.width="650px";
	
	window.print();
	
	//apres impression, on refait la page
	window.setTimeout(
			function() {
				header.style.display="block";
				haut.style.display="block";
				icone_action.style.display="block";
				right.style.display="block";
				pied.style.display="block";
				
				//les style
				right.style.left="631px  ";
			},
			2000 // twenty seconds
	);
	window.location.reload();
}

function printPop(){
	var header = document.getElementById("header");	
	if(document.getElementById("haut") == null){
		var haut = document.getElementById("haut_intra");	
	}else{
		var haut = document.getElementById("haut");
	}
	var fil_ariane = document.getElementById("fil_ariane");
	var icone_action = document.getElementById("icone_action");	
	if(document.getElementById("left") == null){
		var left = document.getElementById("left_intra");	
	}else{
		var left = document.getElementById("left");
	}
	var centre_bas = document.getElementById("centre_bas");
	var pied = document.getElementById("pied");
	var menu = document.getElementById("menu_haut");
	
	menu.style.display="none";	
	header.style.display="none";	
	haut.style.display="none";
	fil_ariane.style.display="none";
	icone_action.style.display="none";	
	left.style.display="none";
	if (centre_bas != null) {
		centre_bas.style.display = "none";
	}
	pied.style.display="none";
	//les style 
	var conteneur = document.getElementById("conteneur");
	conteneur.style.margin="0px  0px 0px 0px";
	conteneur.style.width="650px";
	
	var right = document.getElementById("right");
	right.style.margin="0px  0px 0px 20px";
	right.style.width="610px";
	
	var centre_page = document.getElementById("centre");
	centre_page.style.margin="0px  0px 0px 0px  ";
	centre_page.style.width="650px";
	
	var contenu_page = document.getElementById("contenu_centre");
	contenu_page.style.margin="0px  0px 0px 0px  ";
	contenu_page.style.width="650px";
	
	window.print();
	
	//apres impression, on refait la page
	window.setTimeout(
			function() {
				header.style.display="block";
				haut.style.display="block";
				fil_ariane.style.display="block";
				icone_action.style.display="block";
				left.style.display="block";
				centre_bas.style.display="block";
				pied.style.display="block";
				
				//les style
				right.style.margin="0px  0px 0px 320px  ";
			},
			2000 // twenty seconds
	);
	window.location.reload();
}

//impresion PDF

function getHTTPObject() {
	var xmlhttp;
	/*@cc_on
	@if (@_jscript_version >= 5)
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
			xmlhttp = false;
			}
		}
	@else
	xmlhttp = false;
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		xmlhttp.overrideMimeType("text/xml"); 
		} catch (e) {
			xmlhttp = false;
		}
	}
	return xmlhttp;
}



function to_pdf(){
	var http = getHTTPObject();
	
	
		
	var timeoutId;
	maDate = new Date();
	heure = maDate.getTime();
	http.open("POST","/fileadmin/templates/script/xhtml2pdf/print_cesr.php", true);
	http.onreadystatechange = function() {
		if (http.readyState == 4) {
			if (http.status == 200){
				window.clearTimeout(timeoutId);
				var htmlDoc = http.responseText;
				
				window.open('/fileadmin/templates/script/xhtml2pdf/pdf_creer/ceser_'+heure+'.pdf');
			}
		}
	}
	http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	http.send("heure="+heure);
	timeoutId = window.setTimeout(
		function() {
			switch (http.readyState) {
				case 1:
				case 2:
				case 3:
					http.abort();
					document.getElementById("statut").innerHTML = "<h2>Error Loading Data</h2>";
					alert("Oops. There was an error retreiving data from the server. Please try again in a few moments.");
					break;
				default:
					break;
			}
		},
		20000 // twenty seconds
	);
}


function printPDF_acc(){
	

       /*var right = document.getElementById("right");
	
	 var header = document.getElementById("header");
	  var haut = document.getElementById("haut");
	   var menu_haut = document.getElementById("menu_haut");
	    var pied = document.getElementById("pied");
	
	right.style.display="none";
	
	header.style.display="none";
	haut.style.display="none";
	menu_haut.style.display="none";
	pied.style.display="none";*/
	
	/*document.getElementById("left").style.backgroundImage=url("/fileadmin/templates/images/bg_breadcrumbs.png");
	document.getElementsByClassName("titre_actu").style.backgroundImage=url("/fileadmin/templates/images/bg_breadcrumbs.png");*/
	
	
	
	

	var article = document.getElementById("left");

	html = "<!DOCTYPE html";
	html +=' PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"';
	html +=' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
	html += " <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\">";

	html += "<head><meta http-equiv=\"Content-Type\" content=\"text/HTML; charset=iso-8859-15\"  /><title>CESER</title></head>";
	html += "<body><p>"+article.innerHTML+"</p></body></html>";
	
	
	//alert(html);
	var http = getHTTPObject();
	var timeoutId;
	http.open("POST","/fileadmin/templates/script/xhtml2pdf/write_to_disk.php", true);
	http.onreadystatechange = function() {
		if (http.readyState == 4) {
			if (http.status == 200){
				window.clearTimeout(timeoutId);
				var htmlDoc = http.responseText;
				
				to_pdf();
			}
		}
	}
	http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	http.send("html="+escape(html));
	timeoutId = window.setTimeout(
		function() {
			switch (http.readyState) {
				case 1:
				case 2:
				case 3:
					http.abort();
					document.getElementById("statut").innerHTML = "<h2>Error Loading Data</h2>";
					alert("Oops. There was an error retreiving data from the server. Please try again in a few moments.");
					break;
				default:
					break;
			}
		},
		20000 // twenty seconds
	);
	
	
}

function printPDF(){
	var titre_page = document.getElementById("titre");
	var chapo = document.getElementById("chapo");
	var article = document.getElementById("txt");

	/*html = "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\">";*/
	
	/*html +=" PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"";
	html +=" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";*/
	
	html = "<!DOCTYPE html";
    html +=' PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"';
    html +=' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
	html += " <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\">";

	html += "<head><meta http-equiv=\"Content-Type\" content=\"text/HTML; charset=iso-8859-15\"  /><title>CESER</title></head>";
	html += "<body><h1>"+titre_page.innerHTML+"</h1><p><strong class=\"chapo\">"+chapo.innerHTML+"</strong><br />"+article.innerHTML+"</p></body></html>";
	//html += "<body><h2>test</h2></body></html>";
	
	var http = getHTTPObject();
	var timeoutId;
	http.open("POST","/fileadmin/templates/script/xhtml2pdf/write_to_disk.php", true);
	http.onreadystatechange = function() {
		if (http.readyState == 4) {
			if (http.status == 200){
				window.clearTimeout(timeoutId);
				var htmlDoc = http.responseText;
				to_pdf();
			}
		}
	}
	http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	http.send("html="+escape(html));
	timeoutId = window.setTimeout(
		function() {
			switch (http.readyState) {
				case 1:
				case 2:
				case 3:
					http.abort();
					document.getElementById("statut").innerHTML = "<h2>Error Loading Data</h2>";
					alert("Oops. There was an error retreiving data from the server. Please try again in a few moments.");
					break;
				default:
					break;
			}
		},
		
		20000 // twenty seconds
	);
	
}

