/*----- detection focus flash -----*/
document.onclick=function(){
	if(window.document.menu_flash)
   window.document.menu_flash.SetVariable("focus_out", "true");
}
/*---------------------------------*/


function trim(string)
{
return string.replace(/(^\s*)|(\s*$)/g,'');
}

function valide_form_upload_image(){
	//if (trim(document.getElementById('legende').value) != '')
		document.form_upload_image.submit();
	//else
	//	alert('Le champ l?gende est obligatoire');
}

function supprimer_image(id){

	bool = confirm('?tes-vous sur de vouloir supprimer cette image?');

	if(bool){
		document.getElementById('id').value = id;
		document.getElementById('action').value = "suppression";
		document.form_modif_image.submit();
	}
}

function modifier_image(id){

	document.getElementById('id').value = id;
	document.getElementById('action').value = "modification";
	document.form_modif_image.submit();
}

function up_image(id){

	document.getElementById('id').value = id;
	document.getElementById('action').value = "up";
	document.form_modif_image.submit();
}

function down_image(id){

	document.getElementById('id').value = id;
	document.getElementById('action').value = "down";
	document.form_modif_image.submit();
}


/**
*	Ajout pour le formulaire de contact
*	Script vol? sur la page en ligne de la cap
*/

/**
  *    fonction qui permet de tester les champs du formulaire de newsletter
  *
  *    @param tab tableau contenant les erreurs ?ventuelles
  *    @return true si champ ok false sinon
  */
function testChampContact(tab){
    var tmpBool;

    var erreur=tab[0];
    var focus=tab[1];

    if(document.getElementById('inputRS').value==''){
        erreur += '\n- Raison Sociale\n';
        focus = (focus == '') ?  document.getElementById('inputRS') : focus;
    }

    if(document.getElementById('inputName').value==''){
        erreur += '- Nom \n';
        focus = (focus == '') ?  document.getElementById('inputName') : focus;
    }


	if(document.getElementById('inputFirstName').value==''){
        erreur += '- Prenom \n';
        focus = (focus == '') ?  document.getElementById('inputFirstName') : focus;
    }

    if(document.getElementById('inputFonction').value==''){
        erreur += '- Fonction \n';
        focus = (focus == '') ?  document.getElementById('inputFonction') : focus;
    }

    if(document.getElementById('inputMsg').value==''){
        erreur += '- Message \n';
        focus = (focus == '') ?  document.getElementById('inputMsg') : focus;
    }

    if(document.getElementById('inputTel').value==''){
        erreur += '- Telephone et/ou email \n';
        focus = (focus == '') ?  document.getElementById('inputTel') : focus;
    }

    tab[0] = erreur;
    tab[1] = focus;

    return (document.getElementById('inputRS').value != '')&&

    	   (document.getElementById('inputName').value != '')&&
           (document.getElementById('inputFirstName').value != '')&&
           (document.getElementById('inputFonction').value != '')&&
			(document.getElementById('inputTel').value != '')&&
           (document.getElementById('inputMsg').value != '');
  }

/**
  *    fonction qui permet de tester les champs du formulaire de contact
  *
  *    @param tab tableau contenant les erreurs ?ventuelles
  *    @return true si champ ok false sinon
  */
function testChamp(tab){
    var tmpBool;

    var erreur=tab[0];
    var focus=tab[1];

    if(document.getElementById('inputName').value==''){
        erreur += '- nom \n';
        focus = (focus == '') ?  document.getElementById('inputName') : focus;
    }

    if(document.getElementById('inputFirstName').value==''){
        erreur += '- prenom \n';
        focus = (focus == '') ?  document.getElementById('inputFirstName') : focus;
    }

    if(document.getElementById('inputEmail').value==''){
        erreur += '- email \n';
        focus = (focus == '') ?  document.getElementById('inputEmail') : focus;
    }

    if(tmpBool = (document.getElementById('selectCommune').selectedIndex==0)){
        erreur += '- commune \n';
        focus = (focus == '') ?  document.getElementById('selectCommune') : focus;
    }

    tab[0] = erreur;
    tab[1] = focus;

    return (document.getElementById('inputName').value != '')&&
           (document.getElementById('inputFirstName').value != '')&&
           !tmpBool&&
           (document.getElementById('inputEmail').value != '');
  }

/**
  *    fonction qui permet de tester si le champ email est valide ou pas
  *
  *    @return true si champ ok false sinon
  */
 function testEmail(){
    var utilisateur = "([a-zA-Z0-9][a-zA-Z0-9_.-]*|\"([^\\\\\x80-\xff\015\012\"]|\\\\[^\x80-\xff])+\")";
    var domaine = "([a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,5}";
    var email = "^"+utilisateur+"\@"+domaine+"$";

    var regex = new RegExp(email) ;

    bool = regex.test(document.getElementById('inputEmail').value)

    return bool;
  }

 function PrmUrl(){
 var prm = new Array();
 var tmp = unescape(window.location.search).substr(1).split("&");
 var inter;
 for ( i=0; i<tmp.length; i++)
 {
  inter=tmp[i].indexOf("=");
  if ( inter>=0 )
    {
     prm[tmp[i].substr(0,inter)]=tmp[i].substr(inter+1)
    }
  else {
     prm[tmp[i]]="";
    }
 }
 return prm;
}


/**
*	Fonction qui complete la valeur du champ du moteur de recherche
*/
function getSearchValue()
{

	var cible = "Recherche par mots-cl?s";
 	var partie = cible.substr(0,18);

 	var texteRef = document.getElementById('fieldSearch').value.substr(0,18);

 	if (partie == texteRef)
 	{
		document.getElementById('fieldSearch').value = '';
 	}

}

/* target = blank */
window.onload = function (){
 if(document.getElementsByTagName('a')){
	var get_link=document.getElementsByTagName('a');
	 for (i=0;i<get_link.length;i++){

	  if (get_link[i].getAttribute("rel")=="external"||get_link[i].getAttribute("rel")=="document"){
	   get_link[i].setAttribute('target','_blank');
	   get_link[i].title = 'S\'ouvre dans une nouvelle fen\u00E8tre';
	   get_link[i].innerHTML = get_link[i].innerHTML + '\u00a0[\u2197]';
	  }
	 }
  }
}


$(document).ready(function() { 

	$("a.thickbox").fancybox({
		'zoomSpeedIn': 0,
		'zoomSpeedOut': 0,
		'hideOnContentClick': true, 
		'overlayShow': true/*,
		'frameWidth':$(window).width(),
		'frameHeight':$(window).height()*/
	});
	
}); 