var maxLen = 4000;

function TextAreaMax(form)
{
 if ( form.F_LM.value.length > maxLen)
  form.F_LM.value = form.F_LM.value.substring(0, maxLen);
 else
  form.remLen.value = maxLen - form.F_LM.value.length;
}


 function setMsgBlanc()
{
document.cv_form4.F_LM.value = "";
document.cv_form4.remLen.value = maxLen
}

function copyclpb()
{
document.cv_form4.F_LM.select();
document.execCommand('Copy');
}

function pasteclpb()
{
document.cv_form4.F_LM.select();
document.execCommand('Paste');
document.cv_form4.remLen.value = maxLen - document.cv_form4.F_LM.value.length;
}


function test_suffix (form)
{
if (form.value !="")
{
str_to_test=form.value ;
str_to_test=str_to_test.toLowerCase(); // minuscules 

if((str_to_test.indexOf(".docx") != -1 || str_to_test.indexOf(".doc") != -1)|| str_to_test.indexOf(".rtf") != -1 || str_to_test.indexOf(".xls") != -1 || str_to_test.indexOf(".txt") != -1 || str_to_test.indexOf(".jpg") != -1 || str_to_test.indexOf(".jpeg") != -1 || str_to_test.indexOf(".gif") != -1 || str_to_test.indexOf(".pdf") != -1)
{
return true;
}
else {

if(str_to_test.indexOf(".wps") != -1)

{
alert("Le format Works n'est pas un standard\n\nMERCI DE CONVERTIR VOTRE CV AU FORMAT \"doc\" AVANT DE L\'ENVOYER !");
// dommage, le contenu de la boite input type=file ne peut être effacé
}

else {

if(str_to_test.indexOf(".zip") != -1)

{
alert("Par mesure de sécurité, les fichiers zip ne sont pas acceptés.\n\nVEUILLEZ DECOMPRESSER VOTRE FICHIER AVANT DE L\'ENVOYER !");

}
//else {

//if(str_to_test.indexOf(".docx") != -1)

//{
//alert("Le nouveau format Word (docx) n'est pas un standard\nLes recruteurs risquent de ne pas pouvoir l'ouvrir\n\n MERCI DE CONVERTIR VOTRE CV AU FORMAT \"doc\" AVANT DE L\'ENVOYER !");
//}
else
{
alert("Le format de votre document n'est pas standard !\n\nLes formats acceptés sont les suivants : \n\ndoc, docx, rtf, xls, txt, jpg, gif, pdf\n\nVeuillez le convertir avant de l'envoyer.");
}}}}}


function CheckForm4 (){

    var errorMsg = "";
    var errorMsgLong = "";

    if (document.cv_form4.gere_js.value == 1) // ne s'applique que dans repondre.asp
	{
	
	if (document.cv_form4.cv_email.value =="")
	{
	errorMsg +="Votre adresse email est nécessaire pour qu'on puisse vous répondre\n";
	document.cv_form4.cv_email.focus();
	}
	
	
	if (document.cv_form4.cv_email.value !="")
	{
	testm = false ;
	var string1=document.cv_form4.cv_email.value ;
	string1 = trim(string1) ;// fonction Trim ci-dessous
	
	for (var j=1 ; j<(string1.length) ; j++) {
			if (string1.charAt(j)=='@') { 
				if (j<(string1.length-4)){ 
					for (var k=j ; k<(string1.length-2) ; k++) { 
				if (string1.charAt(k)=='.') testm = true; 
			} 
			} 
			} 
			} 
	
	
 	 if ((string1.indexOf("@")==-1) || (string1.length < 8) || (string1.indexOf(".")==-1) || (string1.indexOf(" ")  != -1) || (string1.indexOf("www")  != -1) || (string1.indexOf("http")  != -1) || (testm==false))
  	{
  	     
	errorMsg +="Votre adresse email n'est pas valide\n";
	document.cv_form4.cv_email.focus();
		
		}
		}
	}
	    
	if (document.cv_form4.F_LM.value =="")
	{
		errorMsg +="\nLa lettre de motivation est essentielle !\nMerci de bien vouloir la renseigner.";
		document.cv_form4.F_LM.focus();
	}
	
	
	if (document.cv_form4.F_PJ.value =="")
		{
			errorMsg +="\n\nCliquer sur \"Parcourir\" pour rechercher votre CV sur votre disque dur";
			document.cv_form4.F_PJ.focus();
	}
	
	
	
	// pour gestion candidatures mais en traitant candidature4.asp !!
	
	//if (document.cv_form4.F_PJ.value =="" && document.cv_form4.check_use_cv.checked==false)
	//{
	//	errorMsg +="\n\nCliquer sur \"Parcourir\" pour rechercher votre CV sur votre disque dur";
	//	document.cv_form4.F_PJ.focus();
	//}

	//if (document.cv_form4.F_PJ.value !="" && document.cv_form4.check_use_cv.checked==true)
	//{
	//	errorMsg +="\n\nMerci de choisir d'utiliser votre C.V. \n\nou d'en télécharger un nouveau";
	//	document.cv_form4.F_PJ.focus();
	//}
	

if ((errorMsg != "")){
                msg = "__________________________________\n\n";
                msg += "Veuillez rectifier ci-dessous et\nsoumettre à nouveau le formulaire.\n";
                msg += "__________________________________\n\n";
                
                errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
                return false;
        }

       return true;
}


function CheckForm4LM (){

    var errorMsg = "";
    var errorMsgLong = "";

        
	if (document.cv_form4.F_LM.value =="")
	{
		errorMsg +="\nLa lettre de motivation est essentielle !\nMerci de bien vouloir la renseigner.";
		document.cv_form4.F_LM.focus();
	}
	
	if ((errorMsg != "")){
                            
                errorMsg += alert(errorMsg + "\n" + errorMsgLong);
                return false;
        }

       return true;
}


function CheckForm4CV (){

    var errorMsg = "";
    var errorMsgLong = "";

        
	if (document.cv_form4.F_PJ.value =="")
	{
		errorMsg +="\nCliquer sur \"Parcourir\" pour rechercher votre CV sur votre disque dur";
		document.cv_form4.F_PJ.focus();
	}
	
	if ((errorMsg != "")){
                            
                errorMsg += alert(errorMsg + "\n" + errorMsgLong);
                return false;
        }

       return true;
}


function trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   // a rajouter si on veut supprimer des espaces intérieurs à la chaine
   //var obj = /  /g;  
   //while (temp.match(obj)) { temp = temp.replace(obj, " "); }
   return temp;
}
