﻿// JScript File
function test()
{
        alert('tyty');
}

function testDJ(msg)
{
        alert(msg);
}


//Suppression des % et *
function CleanSearchstring(searchString)
{
    searchString = searchString.replace(/(%)/g,"");
    searchString = searchString.replace(/(\*)/g,"");
    return searchString;
}



//Filtre les saisies nom numériques sur evenement onkeypress
function KeyNumericFilter()
{
  if ((window.event.keyCode<48) || (window.event.keyCode>57)) 
  {
    return false;
  }
  else
  {
    return true;
  }
}

function SiteAdressecheck()
{}

// Validation d'une adresse Mail
function eMailcheck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var errorMessage='Invalid E-mail ID';
		if (str.indexOf(at)==-1){
		  // alert(errorMessage)
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		  // alert(errorMessage)
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   // alert(errorMessage)
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   // alert(errorMessage)
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   // alert(errorMessage)
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   // alert(errorMessage)
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   // alert(errorMessage)
		    return false
		 }
 		 return true					
	}


function isUrl(s) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}


// Nomination
//-----------
//Validation du formulaire de nomination
function ValidateAllNomination()
{




    //Check les valeurs obligatoires

    if (trim(document.forms[0].ctl00$CPH_Page$TB_Prenom.value)=='')  {alert('Saisir le prenom, SVP. Il est obligatoire.');return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$TB_Nom.value)==''){alert('Saisir le nom, SVP. Il est obligatoire.');return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$TB_DateDay.value)=='') {alert('Saisir la date de naissance, SVP. Elle est obligatoire.');return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$TB_DateMonth.value)=='') {alert('Saisir la date de naissance, SVP. Elle est obligatoire.');return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$TB_DateYear.value)=='')  {alert('Saisir la date de naissance, SVP. Elle est obligatoire.');return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$TB_FoncDay.value)=='') {alert('Saisir la date de naissance, SVP. Elle est obligatoire.');return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$TB_FoncMonth.value)=='') {alert('Saisir la date de naissance, SVP. Elle est obligatoire.');return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$TB_FoncYear.value)=='')  {alert('Saisir la date de naissance, SVP. Elle est obligatoire.');return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$TB_OldJobName.value)=='') {alert("Saisir l'ancien poste, SVP. Il est obligatoire.");return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$TB_NewJobName.value)=='') {alert('Saisir le nouveau poste, SVP. Il est obligatoire.');return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$TA_Formation.value)=='') {alert('Saisir la formation, SVP. Elle est obligatoire.');return false;}
    // if (trim(document.forms[0].ctl00$CPH_Page$TA_Decoration.value)=='') {alert('Saisir la rubrique "Décoration(s)", SVP. Elle est obligatoire.');return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$TA_Parcours.value)=='') {alert('Saisir la rubrique "Parcours", SVP. Elle est obligatoire.');return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$DDLB_NominationSector.value)=='0') {alert("Saisir un secteur d'activité, SVP. Il est obligatoire.");return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$TB_Company.value)=='') {alert('Saisir la rubrique "Société", SVP. Elle est obligatoire.');return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$TB_CompanyAddress.value)=='') {alert('Saisir la rubrique "Adresse de la société", SVP. Elle est obligatoire.');return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$TB_CompanyCodePostal.value)=='') {alert('Saisir la rubrique "Code postal société", SVP. Elle est obligatoire.');return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$TB_CompanyCity.value)=='') {alert('Saisir la rubrique "Ville société", SVP. Elle est obligatoire.');return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$TB_CompanyTel.value)=='') {alert('Saisir la rubrique "Téléphone société", SVP. Elle est obligatoire.');return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$TB_CompanySite.value)=='') {alert('Saisir la rubrique "Site Internet société", SVP. Elle est obligatoire.');return false;}
    if (trim(document.forms[0].ctl00$CPH_Page$TB_CompanyMail.value)=='') {alert('Saisir la rubrique "E-Mail de la société", SVP. Elle est obligatoire.');return false;}
    // Check adresse Mail
    if (!eMailcheck(document.forms[0].ctl00$CPH_Page$TB_CompanyMail.value)) {alert("Le format de l'adresse e-mail est incorrect; veuillez corriger SVP.");return false;}
    // Check Site Adresse
    if ((trim(document.forms[0].ctl00$CPH_Page$TB_CompanySite.value)!='')&&(!isUrl(document.forms[0].ctl00$CPH_Page$TB_CompanySite.value))) {alert("Le format de l'adresse du site de la société est incorrect; veuillez corriger SVP.");return false;}

    // Check Date
    if ((parseInt(document.forms[0].ctl00$CPH_Page$TB_DateDay.value,10)<1) || (parseInt(document.forms[0].ctl00$CPH_Page$TB_DateDay.value,10)>31)) {alert('Le format de la date de naissance est incorrecte; veuillez corriger SVP.');return false;}
    if ((parseInt(document.forms[0].ctl00$CPH_Page$TB_DateMonth.value,10)<1) || (parseInt(document.forms[0].ctl00$CPH_Page$TB_DateMonth.value,10)>12)) {alert('Le format de la date de naissance est incorrecte; veuillez corriger SVP.');return false;}
    if (parseInt(document.forms[0].ctl00$CPH_Page$TB_DateYear.value,10)<1900) {alert('Le format de la date de naissance est incorrecte; veuillez corriger SVP.');return false;}
    if ((parseInt(document.forms[0].ctl00$CPH_Page$TB_FoncDay.value,10)<1) || (parseInt(document.forms[0].ctl00$CPH_Page$TB_FoncDay.value,10)>31)) { alert('Le format de la date de prise de fonction est incorrecte; veuillez corriger SVP.'); return false; }
    if ((parseInt(document.forms[0].ctl00$CPH_Page$TB_FoncMonth.value,10)<1) || (parseInt(document.forms[0].ctl00$CPH_Page$TB_FoncMonth.value,10)>12)) { alert('Le format de la date de prise de fonction est incorrecte; veuillez corriger SVP.'); return false; }
    if (parseInt(document.forms[0].ctl00$CPH_Page$TB_FoncYear.value,10)<1900) { alert('Le format de la date de prise de fonction est incorrecte; veuillez corriger SVP.'); return false; }




    //Check CV File type  
    if ((document.forms[0].ctl00$CPH_Page$IF_FileCV.value.substring(document.forms[0].ctl00$CPH_Page$IF_FileCV.value.lastIndexOf('.'),document.forms[0].ctl00$CPH_Page$IF_FileCV.value.length)!='.doc')
    && (trim(document.forms[0].ctl00$CPH_Page$IF_FileCV.value)!='')
    && (document.forms[0].ctl00$CPH_Page$IF_FileCV.value.substring(document.forms[0].ctl00$CPH_Page$IF_FileCV.value.lastIndexOf('.'),document.forms[0].ctl00$CPH_Page$IF_FileCV.value.length)!='.pdf')) 
    {alert('Le type du fichier du CV doit  etre .doc ou .pdf, veuillez corriger SVP.');return false;}
     // if (document.forms[0].ctl00$CPH_Page$IF_FileCV.value.substring(document.forms[0].ctl00$CPH_Page$IF_FileCV.value.lastIndexOf('.'),document.forms[0].ctl00$CPH_Page$IF_FileCV.value.lenght)!='pdf') {alert('Le type du fichier du CV doit  etre .doc ou .pdf, veuillez corriger SVP.');error=true;}
    var error = false;
    //Check Photo File type
   // alert(document.forms[0].ctl00$CPH_Page$IF_FilePhoto.value.lastIndexOf('.'));
   // alert(document.forms[0].ctl00$CPH_Page$IF_FilePhoto.value.length);
   // alert(document.forms[0].ctl00$CPH_Page$IF_FilePhoto.value.substring(document.forms[0].ctl00$CPH_Page$IF_FilePhoto.value.lastIndexOf('.'),document.forms[0].ctl00$CPH_Page$IF_FilePhoto.value.length));
    if ((document.forms[0].ctl00$CPH_Page$IF_FilePhoto.value.substring(document.forms[0].ctl00$CPH_Page$IF_FilePhoto.value.lastIndexOf('.'),document.forms[0].ctl00$CPH_Page$IF_FilePhoto.value.length)!='.jpeg') 
       && (trim(document.forms[0].ctl00$CPH_Page$IF_FilePhoto.value)!='')
       && (document.forms[0].ctl00$CPH_Page$IF_FilePhoto.value.substring(document.forms[0].ctl00$CPH_Page$IF_FilePhoto.value.lastIndexOf('.'),document.forms[0].ctl00$CPH_Page$IF_FilePhoto.value.length)!='.jpg'))
       {error=true;}
   
    if (error==true) {alert('Le type du fichier de la photo doit etre .jpeg ou .jpg, veuillez corriger SVP.');return false;}
   
   
   // return false;
    return true;
  }

function ValidateBeforePost(action,fromscreen)
{


	if (action == 'secteur')
	{
	document.forms[0].ctl00$CPH_Page$Boite_Nomination_Secteur1$DDLB_NominationSecteur.value
	     if (document.forms[0].ctl00$CPH_Page$Boite_Nomination_Secteur1$DDLB_NominationSecteur.value=="0")
        {
            return false;
        }
        else
        {
        

            document.forms[0].ctl00$CPH_Page$Boite_Nomination_Secteur1$HD_SelIdSector.value=document.forms[0].ctl00$CPH_Page$Boite_Nomination_Secteur1$DDLB_NominationSecteur.value;
            var selectedIndex=document.forms[0].ctl00$CPH_Page$Boite_Nomination_Secteur1$DDLB_NominationSecteur.selectedIndex
            document.forms[0].ctl00$CPH_Page$Boite_Nomination_Secteur1$HD_SelNameSector.value=document.forms[0].ctl00$CPH_Page$Boite_Nomination_Secteur1$DDLB_NominationSecteur[selectedIndex].text;
   
           return true;
         }
    }
	
	else if (action == 'search')
	{
	 if (trim(document.forms[0].ctl00$CPH_Page$Boite_Nomination_Recherche1$TB_NominationsSearch.value)=="personne, societe")
     {
         alert('Veuillez saisir au moins un caractère pour la recherche.'); 
         return false;
     }
     else {
        return true;
     }
	}
	else if (action == 'nominationValidate')
	{
	    var res=  ValidateAllNomination();
	   return res;
	 
	}
	else if (action == 'EnvoyerArticle')
	{
	    if (ValidationEnvoieArticle())
	    {
	       return true;
    	 }
    	 else
    	 {
    	  return false;
    	 }
	}
	else if (action == 'EnvoyerReaction')
	{
	    if (ValidationReactionArticle())
	    {
	       return true;
    	 }
    	 else
    	 {
    	  return false;
    	 }
    	 
    	 
    	 
    	 return true;
	}



}

function TestBackground()
{

// aspnetForm.style.backgroundColor='#ffffff'
}


function PopupCentre(page,largeur,hauteur,options) {
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}



function PopupCentre1() {
	

	hauteur=950;
	largeur=660;
 	resizeTo(largeur,hauteur);
	moveTo((screen.width-largeur)/2,(screen.height-hauteur)/2);

	}

	
function ConfirmEnvoi(titre)
{
	var ParentWindow=window.opener;
	ParentWindow.execScript(RetourEnvoi(ParentWindow,titre));
}

function RetourEnvoi(object,titre)
{
	object.document.forms[0].ctl00$CPH_Page$HD_RedirectEnvoyer.value=titre;
	object.document.forms[0].submit();
}

// Fin Nomination
//-----------




function trim(string) { 
    return string.replace(/(^\s*)|(\s*$)/g,''); 
} 


function ITrim( chaine ){
	return (chaine.indexOf('  ')==-1)?chaine:ITrim( chaine.substring( 0 , chaine.indexOf('  ') )+chaine.substring( chaine.indexOf('  ') +1 ) )
}

function LTrim( chaine ){
	return (chaine.charAt(0)==' ')?LTrim( chaine.substring( 1 )):chaine
}

function RTrim( chaine ){
	return (chaine.charAt( chaine.length - 1 )==' ')?RTrim( chaine.substring( 0 , chaine.length - 1 )):chaine
}

function Trim( chaine ){
	return LTrim( RTrim( ITrim( chaine ) ) )
}


function Date_FR_to_US(value) {
    return value.charAt(6)+value.charAt(7)+value.charAt(8)+value.charAt(9)+'/'+value.charAt(3)+value.charAt(4)+'/'+value.charAt(0)+value.charAt(1)
}

function Date_US_to_FR(value) {
    return value.charAt(8)+value.charAt(9)+'/'+value.charAt(5)+value.charAt(6)+'/'+value.charAt(0)+value.charAt(1)+value.charAt(2)+value.charAt(3)
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}


// LIEN  WALLPAPER
function Click_Pub(event,lien_gauche,lien_droite) {
	event = window.event || event;
	var obj = event.srcElement || event.target;
	while (obj.id=='' || obj.id==undefined) {     
		obj=obj.parentNode;
	}
	if ((obj.id.indexOf('td_gauche')>-1) && (lien_gauche!='')) {
		window.open(lien_gauche);
	}
	if ((obj.id.indexOf('td_droite')>-1) && (lien_droite!='')) {
		window.open(lien_droite);
	}
	
}

// CURSOR WALLPAPER
function Cursor_Pub(event) {		
	event = window.event || event;
	var obj = event.srcElement || event.target;
	while (obj.id=='' || obj.id==undefined) {     
		obj=obj.parentNode;
	}
	if (obj.id.indexOf('td_gauche')>-1) {
		obj.style.cursor = 'pointer';
	}
	else if (obj.id.indexOf('td_droite')>-1) {
		obj.style.cursor = 'pointer';
	}
	else {
		obj.style.cursor = 'default';
	}
}
