function load_bandeaux(){
	jq('#defilement_bandeaux').innerfade({
		speed: 'slow',
		timeout: 5000,
		type: 'random'
	});
}

function load_zoomi(){
	jq('.zoomi img').zoom1().click(function(){
    	jq(this).zoom2().fadeIn().click(function(){
    		jq(this).hide(); return false; })
			.end().parent(); return false; });
}

function load_positions_bandeau(left, top)
{
	jq('#slogan').css("top", top + "px"); 
	jq('#slogan').css("left", left + "px");
}

function getRadioValue(Objet)
{
	var NbBtnRadio = document.getElementById("Hidden" + Objet.name);
	var returnValue = "";
	var NomChamp = Objet.name;
	
	if(document.getElementsByName){
		var d = document.getElementsByName(NomChamp);
		for(var i=0; i<d.length; i++) {
			if(d[i].type=='radio' && d[i].checked){
				returnValue = d[i].value;
			}
		}
	}
	else{
		for (var j = 0 ; j < NbBtnRadio.value ; j++)
		{
			if (document.form.elements[NomChamp][j].checked){
				returnValue = document.form.elements[Obj.id][j].value;
			}
		}
	}
	return returnValue;
}

function getEmailValue(Objet) 
{
	var arobase = Objet.value.indexOf('@');
	var ptAftAt = Objet.value.substring(arobase + 1,Objet.value.length).indexOf('.');
	var longueurDNS = Objet.value.substring(arobase + 1,Objet.value.length).length;	
	longueurDNS = ((longueurDNS - 1) * 1);
	var valeur = "";
	
	if (!isNaN(arobase) && !isNaN(ptAftAt))
		if (arobase > 0 && ptAftAt > 0 && ptAftAt != longueurDNS)
			valeur = Objet.value;

	return valeur;
}

function getDateValue(Objet) 
{
	var regex = new RegExp("[/-]");
	var date = Objet.value.split(regex);
	var nbJours = new Array('',31,28,31,30,31,30,31,31,30,31,30,31);
	var result = true;
	
	if ( date['2']%4 == 0 && date['2']%100 > 0 || date['2']%400 == 0 )
		nbJours['2'] = 29;
	
	if( isNaN(date['2']) )
		result=false;
	
	if ( isNaN(date['1']) || date['1'] > 12 || date['1'] < 1 )
		result=false;
	
	if ( isNaN(date['0']) || date['0'] > nbJours[Math.round(date['1'])] || date['0'] < 1 )
		result=false;
	
	return result;
}

function validateForm()
{
	var i,val,nm,errors='',args=validateForm.arguments;
	var mail;
	var radio;
	var flag=0;
	
	document.returnValue = false;
	for (i=0; i<(args.length); i+=3)
	{	
		flag=0;
		Obj = document.getElementById(args[i]);
		switch (args[i+2])
		{
			case "text" :
				val = Obj;
				break;
			case "mail" :
				val = Obj;
				mail = getEmailValue(Obj);
				break;
			case "isDate" :
				val = Obj;
				date_obj = getDateValue(Obj);
				break;
			case "fcke" :
				val = Obj;
				break;
			case "ckbx" :
				val = Obj;
				break;
			case "btrd" :
				val = Obj;
				radio = getRadioValue(Obj);
				break;
		}
			
		if (val != "")
		{
			(val.name)? nm=args[i+1] : alert("/!\\ Erreur de saisie.");
			if (val.value=="" && args[i+2] != "mail" && args[i+2] != "isDate"){
				errors += '- '+nm+' est obligatoire.\n';
			}
			else if (radio=="" && flag==0){
				errors += '- '+nm+' est obligatoire.\n';
				flag=1;
			}
			else
			{
				if (args[i+2] == "mail" && mail == "" && val.value!="")
					errors += '- '+nm+' est incorrecte.\n';
				else if (args[i+2] == "isDate" && date_obj == false && val.value!="")
					errors += '- '+nm+' est incorrecte.\n';
			}
		}
	}
	if (errors)
		alert('ERREUR\nLes Champs de ligne marqués d\'une étoile rouge\ndoivent être renseignés !\n\n'+errors);
	document.returnValue = (errors == '');	
}

function check_formular(div_class)
{
    var email = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,3}$/; 
    var number = /^[-]?\d*\.?\d*$/; 
    var trigger = true;
    jq('#'+div_class+' :input').each(function()
    {
        var valeur = jq.trim(jq(this).val());
        if(jq(this).hasClass('obligatoire'))
        {
            if(valeur == ''){
                trigger = false;
				jq(this).removeClass('input_off');
				jq(this).addClass('input_on');
            }
			else{
				jq(this).removeClass('input_on');
				jq(this).addClass('input_off');
			}
        }
		if(jq(this).hasClass('email'))
        {
			if(!valeur.match(email))
            {
                trigger = false;
				jq(this).removeClass('input_off');
				jq(this).addClass('input_on');
            }
			else{
				jq(this).removeClass('input_on');
				jq(this).addClass('input_off');
			}
		}
    });
    return trigger;
}
/** UI **/
function load_overlay (value_top)
{	
	jq("a[rel]").each(function(i) {
		jq(this).overlay
		({
			top: parseInt(value_top),
			fixed: false,
			onBeforeLoad: function() 
			{
				jQuery.ajaxSetup({cache: false});
				var wrap = this.getOverlay().find(".contentWrap");
				wrap.load(this.getTrigger().attr("href"));
			},
			mask: 
			{
				color: '#FFF',
				loadSpeed: 200,
				opacity: 0.7
			}
		});			
	});	
}

function load_overlay_photo(value_top)
{	
	jq(".div_photo_slide a[rel]").each(function(i) {
		jq(this).overlay
		({
			top: parseInt(value_top),
			fixed: false,
			onBeforeLoad: function() 
			{
				jQuery.ajaxSetup({cache: false});
				var wrap = this.getOverlay().find(".contentWrap");
				wrap.load(this.getTrigger().attr("href"));
			},
			mask: 
			{
				color: '#FFF',
				loadSpeed: 200,
				opacity: 0.7
			}
		});			
	});	
} 

function close_overlay()
{
	jq('a[rel]').each( function(){
		jq(this).overlay().close();
	});
	jq('.contentWrap').empty();
	jq('#exposeMask').hide();
}

function load_date()
{
	jq(".date_cal").datepicker({dateFormat: 'dd/mm/yy', monthNames: ['Janvier','Fevrier','Mars','Avril','Mai','Juin','Juillet','Aout','Septembre','Octobre','Novembre','Decembre'], dayNamesMin: ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'] });
}
/*** FIN UI ***/

function load_carousel(){
	if (jq('#SELECTION ul li').length>2){
		jq('#SELECTION ul').carouFredSel({
			direction: "up",
			pauseOnHover: "true",
			items: {
				visible: 2
			},
			scroll: {
				items: 1,
				pauseOnHover: "resume",
				mousewheel: 1
			},
			auto: {
				delay: 2000,
				pauseDuration: 4000
			}
		});	
	}
}

/**** annonce ***/
function load_etiq(id_etiq, img, cpt){
	cpt = parseInt(cpt);
	tab_lettre = new Array('a','b','c','d','e','f','g');
	lettre = jq('#hid_'+id_etiq).val().toLowerCase();
	valeur = parseInt(jq('#hid_val_'+id_etiq).val());
	total = tab_lettre.length;
	
	if (cpt<total){
		jq('#p_'+id_etiq).css('background', 'url(/images/DIAGNOSTIC/etiquette_'+img+'_'+tab_lettre[cpt]+'.png) no-repeat'); 
		if (lettre != tab_lettre[cpt]){
			window.setTimeout(function(){
				load_etiq(id_etiq, img, (cpt+1))
			},700);
		}
		else{
			cpt = total;
			if (valeur == 0)
				valeur = lettre;
			var div = jq('<div class="diag'+lettre.toUpperCase()+'">'+valeur+'</div>').hide();
			jq('#p_'+id_etiq).append(div);
			div.fadeIn(2000)
		}
	}
}

function remove_lieu(){
	jq('.ul_lieu .li_item span.close').click(function(){
		var id_li = jq(this).parent().attr('id');
		var num_id = id_li.substring(7, id_li.length);
		jq(this).parent().remove();
		jq('#hid_lieu'+num_id).remove();
		jq('#hid_lblieu'+num_id).remove();
		set_height_lieu();
	});
}

function set_height_lieu() {
	var height_ul = parseInt(jq('.ul_lieu').height());
	if (height_ul>=120)
		jq('.ul_lieu').height(120);
	else
		jq('.ul_lieu').height('auto');
}
/**** fin annonce ***/

/**** FONCTIONS PHPJS ****/
function strip_tags(html){
	if(arguments.length < 3) {
		html=html.replace(/<\/?(?!\!)[^>]*>/gi, '');
	} else {
		var allowed = arguments[1];
		var specified = eval("["+arguments[2]+"]");
		if(allowed){
			var regex='</?(?!(' + specified.join('|') + '))\b[^>]*>';
			html=html.replace(new RegExp(regex, 'gi'), '');
		} else{
			var regex='</?(' + specified.join('|') + ')\b[^>]*>';
			html=html.replace(new RegExp(regex, 'gi'), '');
		}
	}
	var clean_string = html;

	return clean_string;
}

function strlen (string) {
    var str = string + '';
    var i = 0,        chr = '',
        lgth = 0;
 
    if (!this.php_js || !this.php_js.ini || !this.php_js.ini['unicode.semantics'] || this.php_js.ini['unicode.semantics'].local_value.toLowerCase() !== 'on') {
        return string.length;    }
 
    var getWholeChar = function (str, i) {
        var code = str.charCodeAt(i);
        var next = '',            prev = '';
        if (0xD800 <= code && code <= 0xDBFF) { 
            if (str.length <= (i + 1)) {
                throw 'High surrogate without following low surrogate';
            }            next = str.charCodeAt(i + 1);
            if (0xDC00 > next || next > 0xDFFF) {
                throw 'High surrogate without following low surrogate';
            }
            return str.charAt(i) + str.charAt(i + 1);        } else if (0xDC00 <= code && code <= 0xDFFF) { 
            if (i === 0) {
                throw 'Low surrogate without preceding high surrogate';
            }
            prev = str.charCodeAt(i - 1);            if (0xD800 > prev || prev > 0xDBFF) { 
                throw 'Low surrogate without preceding high surrogate';
            }
            return false; 
        }        return str.charAt(i);
    };
 
    for (i = 0, lgth = 0; i < str.length; i++) {
        if ((chr = getWholeChar(str, i)) === false) {            continue;
        } 
        lgth++;
    }
    return lgth;
}
/**** FIN FONCTIONS PHPJS ****/
