var ajax_contact = new Array();

function contactform_action_erreur(){
var sContent = "";
var str="";
var form = document.contact_form;
          for ( var i = 0 ; i < document.contact_form.elements.length ; i++ ) {  
            var elem = document.contact_form.elements[i];       
            var elemName = elem.name;

              
                if ( (elemName.length > 0))
            {
                if ( (elem.type == 'text') || (elem.type == 'textarea')  || (elem.type == 'hidden'))
                {
                    sContent = sContent+ elemName+"="+elem.value+"&";
                }
           		
                else if ( elem.type == 'checkbox' )
                {
                    val="";
                    if (elem.checked == true)
                    {
                        val= 1;
                        sContent = sContent+ elemName+"="+val+"&";
                    }else{
                         val= 0;
                        sContent = sContent+ elemName+"="+val+"&";
                    
                    }
                }
                else if (form.elements[i].type == 'radio' )
                {
                    if (elem.checked)
                    {
                        sContent = sContent+ elemName+"="+elem.value+"&";
						
                    }
                }
                else if (form.elements[i].type == 'select-one' )
                {
                    str = elemName + "=";
                    for (var j = 0; j < elem.options.length; j++)
                    {
                        if (elem.options[j].selected==true)
                        {
                            str = str+ elem.options[j].value;
                            break;
                        }  
                    }
                    sContent = sContent+str+"&";
                }
                else if ( elem.type == 'select-multiple' )
                {
                    str = elemName + "|";
                    for (var j = 0; j < elem.options.length; j++)
                    {
                        if (elem.options[j].selected==true)
                            str = str+ elem.options[j].value+";";  
                    }
                    sContent = sContent+str+"|";   
                }
            }
	
}
	p_contactform_action_erreur(sContent);
}



function p_contactform_action_erreur(sContent){
	
	
	var result_contactfrom = ajax_contact.length;
	ajax_contact[result_contactfrom] = new sack();
	ajax_contact[result_contactfrom].requestFile = '../contact/insertcontactaction.php?'+sContent;
	ajax_contact[result_contactfrom].onCompletion = function(){ show_erreur_contactform(result_contactfrom)};//;	
	ajax_contact[result_contactfrom].runAJAX();

	
}

function show_erreur_contactform(result_contactfrom){
	if (ajax_contact[result_contactfrom].response == 1){
		window.reload(location.href='../content/confirmation.php');
	} else {
		if(ajax_contact[result_contactfrom].response == 3){

					

			if (document.getElementById('nom_f').value == ""){
				document.getElementById('nom_f').className = "saisie-erreur";
				alert("Votre Nom est obligatoire");
				return;
				
			}else{
				document.getElementById('nom_f').className = "saisieform";
				document.getElementById("err_result_contactfrom").innerHTML = "";
			}
		
			if (document.getElementById('prenom_f').value == ""){
				document.getElementById('prenom_f').className = "saisie-erreur";
				var txt_prenom = HTMLDecode("Pr&eacute;nom");
				alert("Votre "+txt_prenom+" est obligatoire");
				return;
			}else{
				document.getElementById('prenom_f').className = "saisieform";
				document.getElementById("err_result_contactfrom").innerHTML = "";
			}
		
			var email = document.getElementById('email_f').value;

			var str=document.getElementById('email_f').value;
			var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
			if (filter.test(str)){
				document.getElementById('email_f').className = "saisieform";
			}else{
				document.getElementById('email_f').className = "saisie-erreur";
				alert("Votre E-mail est invalide");
				return;
			}

			var char = document.getElementById('tel_f').value;
													
	
			if(isInteger(char)){
			
				if (document.getElementById('tel_f').value == ""){
					document.getElementById('tel_f').className = "saisie-erreur";
	/*				document.getElementById("err_result_contactfrom").innerHTML = "<font color='red' size='2px'>Veuillez saisir votre num&eacute;ro.</font>";	
			
	
	*/				var txt_numero = HTMLDecode(" num&eacute;ro");
					alert("Veuillez saisir votre "+txt_numero);
					return;
				}else{
					
					if(document.getElementById('tel_f').value.length<10){
	/*					document.getElementById("err_result_contactfrom").innerHTML = "<font color='red' size='2px'>Le num&eacute;ro de t&eacute;l&eacute;phone doit comporter 10 chiffres.</font>";
	*/					
						document.getElementById('tel_f').className = "saisie-erreur";
						alert(HTMLDecode("Le num&eacute;ro de t&eacute;l&eacute;phone doit comporter 10 chiffres"))
						return;
					}else{ 
						var x = document.getElementById('tel_f').value;
						x = x.substr(0,1);
						if(x!=0){
							document.getElementById('tel_f').className = "saisie-erreur";
	/*						document.getElementById("err_result_contactfrom").innerHTML = "<font color='red' size='2px'>Le num&eacute;ro de t&eacute;l&eacute;phone doit commencer par le chiffre 0.</font>";
	*/						
							alert(HTMLDecode("Le num&eacute;ro de t&eacute;l&eacute;phone doit commencer par le chiffre 0"))
							return
						}else{ 
							document.getElementById('tel_f').className = "saisieform";
							document.getElementById("err_result_contactfrom").innerHTML = "";
				
						}
					}
				}
			}else{
				document.getElementById('tel_f').className = "saisie-erreur";
	/*			document.getElementById("err_result_contactfrom").innerHTML = "<font color='red' size='2px'>Veuillez saisir votre num&eacute;ro correctement.</font>";
	*/		
				alert(HTMLDecode("Veuillez saisir votre num&eacute;ro correctement."))
				return;
			}
		
				
		

		}else if((ajax_contact[result_contactfrom].response == "mail serveur")){
			alert(HTMLDecode("Une erreur est survenu sur le serveur mail! Merci de réessayer ultérieurement"));
			return;
		}
		
	}

}



function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}


function HTMLDecode(ligne) {
	ligne = ligne.replace(/&hellip;/g,"...");
	ligne = ligne.replace(/&quot;/g,String.fromCharCode(34));
	ligne = ligne.replace(/&amp;/g,String.fromCharCode(38));
	ligne = ligne.replace(/&lt;/g,String.fromCharCode(60));
	ligne = ligne.replace(/&gt;/g,String.fromCharCode(62));
	ligne = ligne.replace(/&nbsp;/g,String.fromCharCode(160));
	ligne = ligne.replace(/&iexcl;/g,String.fromCharCode(161));
	ligne = ligne.replace(/&cent;/g,String.fromCharCode(162));
	ligne = ligne.replace(/&pound;/g,String.fromCharCode(163));
	ligne = ligne.replace(/&curren;/g,String.fromCharCode(164));
	ligne = ligne.replace(/&yen;/g,String.fromCharCode(165));
	ligne = ligne.replace(/&brvbar;/g,String.fromCharCode(166));
	ligne = ligne.replace(/&sect;/g,String.fromCharCode(167));
	ligne = ligne.replace(/&uml;/g,String.fromCharCode(168));
	ligne = ligne.replace(/&copy;/g,String.fromCharCode(169));
	ligne = ligne.replace(/&ordf;/g,String.fromCharCode(170));
	ligne = ligne.replace(/&laquo;/g,String.fromCharCode(171));
	ligne = ligne.replace(/&not;/g,String.fromCharCode(172));
	ligne = ligne.replace(/&shy;/g,String.fromCharCode(173));
	ligne = ligne.replace(/&reg;/g,String.fromCharCode(174));
	ligne = ligne.replace(/&macr;/g,String.fromCharCode(175));
	ligne = ligne.replace(/&deg;/g,String.fromCharCode(176));
	ligne = ligne.replace(/&plusmn;/g,String.fromCharCode(177));
	ligne = ligne.replace(/&sup2;/g,String.fromCharCode(178));
	ligne = ligne.replace(/&sup3;/g,String.fromCharCode(179));
	ligne = ligne.replace(/&acute;/g,String.fromCharCode(180));
	ligne = ligne.replace(/&micro;/g,String.fromCharCode(181));
	ligne = ligne.replace(/&para;/g,String.fromCharCode(182));
	ligne = ligne.replace(/&middot;/g,String.fromCharCode(183));
	ligne = ligne.replace(/&cedil;/g,String.fromCharCode(184));
	ligne = ligne.replace(/&sup1;/g,String.fromCharCode(185));
	ligne = ligne.replace(/&ordm;/g,String.fromCharCode(186));
	ligne = ligne.replace(/&raquo;/g,String.fromCharCode(187));
	ligne = ligne.replace(/&frac14;/g,String.fromCharCode(188));
	ligne = ligne.replace(/&frac12;/g,String.fromCharCode(189));
	ligne = ligne.replace(/&frac34;/g,String.fromCharCode(190));
	ligne = ligne.replace(/&iquest;/g,String.fromCharCode(191));
	ligne = ligne.replace(/&times;/g,String.fromCharCode(215));
	ligne = ligne.replace(/&divide;/g,String.fromCharCode(247));
	ligne = ligne.replace(/&AElig;/g,String.fromCharCode(198));
	ligne = ligne.replace(/&Aacute;/g,String.fromCharCode(193));
	ligne = ligne.replace(/&Acirc;/g,String.fromCharCode(194));
	ligne = ligne.replace(/&Agrave;/g,String.fromCharCode(192));
	ligne = ligne.replace(/&Aring;/g,String.fromCharCode(197));
	ligne = ligne.replace(/&Atilde;/g,String.fromCharCode(195));
	ligne = ligne.replace(/&Auml;/g,String.fromCharCode(196));
	ligne = ligne.replace(/&Ccedil;/g,String.fromCharCode(199));
	ligne = ligne.replace(/&ETH;/g,String.fromCharCode(208));
	ligne = ligne.replace(/&Eacute;/g,String.fromCharCode(201));
	ligne = ligne.replace(/&Ecirc;/g,String.fromCharCode(202));
	ligne = ligne.replace(/&Egrave;/g,String.fromCharCode(200));
	ligne = ligne.replace(/&Euml;/g,String.fromCharCode(203));
	ligne = ligne.replace(/&Iacute;/g,String.fromCharCode(205));
	ligne = ligne.replace(/&Icirc;/g,String.fromCharCode(206));
	ligne = ligne.replace(/&Igrave;/g,String.fromCharCode(204));
	ligne = ligne.replace(/&Iuml;/g,String.fromCharCode(207));
	ligne = ligne.replace(/&Ntilde;/g,String.fromCharCode(209));
	ligne = ligne.replace(/&Oacute;/g,String.fromCharCode(211));
	ligne = ligne.replace(/&Ocirc;/g,String.fromCharCode(212));
	ligne = ligne.replace(/&Ograve;/g,String.fromCharCode(210));
	ligne = ligne.replace(/&Oslash;/g,String.fromCharCode(216));
	ligne = ligne.replace(/&Otilde;/g,String.fromCharCode(213));
	ligne = ligne.replace(/&Ouml;/g,String.fromCharCode(214));
	ligne = ligne.replace(/&THORN;/g,String.fromCharCode(222));
	ligne = ligne.replace(/&Uacute;/g,String.fromCharCode(218));
	ligne = ligne.replace(/&Ucirc;/g,String.fromCharCode(219));
	ligne = ligne.replace(/&Ugrave;/g,String.fromCharCode(217));
	ligne = ligne.replace(/&Uuml;/g,String.fromCharCode(220));
	ligne = ligne.replace(/&Yacute;/g,String.fromCharCode(221));
	ligne = ligne.replace(/&aacute;/g,String.fromCharCode(225));
	ligne = ligne.replace(/&acirc;/g,String.fromCharCode(226));
	ligne = ligne.replace(/&aelig;/g,String.fromCharCode(230));
	ligne = ligne.replace(/&agrave;/g,String.fromCharCode(224));
	ligne = ligne.replace(/&aring;/g,String.fromCharCode(229));
	ligne = ligne.replace(/&atilde;/g,String.fromCharCode(227));
	ligne = ligne.replace(/&auml;/g,String.fromCharCode(228));
	ligne = ligne.replace(/&ccedil;/g,String.fromCharCode(231));
	ligne = ligne.replace(/&eacute;/g,String.fromCharCode(233));
	ligne = ligne.replace(/&ecirc;/g,String.fromCharCode(234));
	ligne = ligne.replace(/&egrave;/g,String.fromCharCode(232));
	ligne = ligne.replace(/&eth;/g,String.fromCharCode(240));
	ligne = ligne.replace(/&euml;/g,String.fromCharCode(235));
	ligne = ligne.replace(/&iacute;/g,String.fromCharCode(237));
	ligne = ligne.replace(/&icirc;/g,String.fromCharCode(238));
	ligne = ligne.replace(/&igrave;/g,String.fromCharCode(236));
	ligne = ligne.replace(/&iuml;/g,String.fromCharCode(239));
	ligne = ligne.replace(/&ntilde;/g,String.fromCharCode(241));
	ligne = ligne.replace(/&oacute;/g,String.fromCharCode(243));
	ligne = ligne.replace(/&ocirc;/g,String.fromCharCode(244));
	ligne = ligne.replace(/&ograve;/g,String.fromCharCode(242));
	ligne = ligne.replace(/&oslash;/g,String.fromCharCode(248));
	ligne = ligne.replace(/&otilde;/g,String.fromCharCode(245));
	ligne = ligne.replace(/&ouml;/g,String.fromCharCode(246));
	ligne = ligne.replace(/&szlig;/g,String.fromCharCode(223));
	ligne = ligne.replace(/&thorn;/g,String.fromCharCode(254));
	ligne = ligne.replace(/&uacute;/g,String.fromCharCode(250));
	ligne = ligne.replace(/&ucirc;/g,String.fromCharCode(251));
	ligne = ligne.replace(/&ugrave;/g,String.fromCharCode(249));
	ligne = ligne.replace(/&uuml;/g,String.fromCharCode(252));
	ligne = ligne.replace(/&yacute;/g,String.fromCharCode(253));
	ligne = ligne.replace(/&yuml;/g,String.fromCharCode(255));
	ligne = ligne.replace(/&#8482;/g,String.fromCharCode(153));
	ligne = ligne.replace(/&trade;/g,String.fromCharCode(153));
	ligne = ligne.replace(/&Trade;/g,String.fromCharCode(153));
	ligne = ligne.replace(/\'/g,"'");
	ligne = ligne.replace(/&rsquo;/g,String.fromCharCode(180));
	return ligne;
}
