// JavaScript Document

var ie = 0;
var ie6 = 0;

if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
	var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
	ie = 1;
 	if (ieversion>=8)
  		ie6 = 0;
 	else if (ieversion>=7)
		ie6 = 0;
	else if (ieversion>=6)
		ie6 = 1;
	}
	
	

jQuery(document).ready(function(){


/* Rollover */
 $('a#bt_identifier img').bind('mouseenter', function(){
 $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) );
 });

 $('a#bt_identifier img').bind('mouseleave', function(){
 $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) );
 });


 $('a.bt_aide img').bind('mouseenter', function(){
 $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) );
 });

 $('a.bt_aide img').bind('mouseleave', function(){
 $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) );
 });


 $('a.bt_idee img').bind('mouseenter', function(){
 $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) );
 });

 $('a.bt_idee img').bind('mouseleave', function(){
 $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) );
 });


 $('a.bt_savoir img').bind('mouseenter', function(){
 $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) );
 });

 $('a.bt_savoir img').bind('mouseleave', function(){
 $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) );
 });
 
 
 $('a#bt_info img').bind('mouseenter', function(){
 $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) );
 });

 $('a#bt_info img').bind('mouseleave', function(){
 $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) );
 });


 $('a.bt_retour img').bind('mouseenter', function(){
 $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) );
 });

 $('a.bt_retour img').bind('mouseleave', function(){
 $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) );
 });
 
 
 $('input#bt_envoyer_dem').bind('mouseenter', function(){
 $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) );
 });

 $('input#bt_envoyer_dem').bind('mouseleave', function(){
 $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) );
 });
 
 
 $('input#bt_ok').bind('mouseenter', function(){
 $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) );
 });

 $('input#bt_ok').bind('mouseleave', function(){
 $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) );
 });


 $('a.bt_inscription img').bind('mouseenter', function(){
 $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) );
 });

 $('a.bt_inscription img').bind('mouseleave', function(){
 $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) );
 });
 

/*$("#bt_identifier").fancybox({
				'width'				: 464,
				'height'			: 258,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe',
				'onClosed'			: function() {
   parent.location.reload(true);

} 
			});*/



 
});
/* Généralités */

PEPS = {};

PEPS.rollover = 
{
   
   newimage: function( src )
   { 
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_on' + src.match(/(\.[a-z]+)$/)[0]; 
   },
    chgimage: function( src )
   { 
      return src.search(/_on/i); 
   },

   oldimage: function( src )
   { 
      return src.replace(/_on\./, '.'); 
   }
};

// Example:
// simplePreload( '01.gif', '02.gif' ); 
function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

function validEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false)
		return false;
	else
		return true;
}

function ucfirst( str ) {
    str += '';
    var f = str.charAt(0).toUpperCase();
    return f + str.substr(1, str.length-1);
}

function strtoupper( str ) {
    return (str+'').toUpperCase();
}

function strtolower( str ) {
    return (str+'').toLowerCase();
}

function focusError(field) {
	$('#'+field).css('background', '#ff8080');
}

function focusOk(field) {
	$('#'+field).css('background', '');
}

function focusConnexion(field) {
	if (field == 'identifiant')
		{
		if ($('#identifiant').attr('value') == 'e-mail')
			$('#identifiant').attr('value', '');
		}
	else if (field == 'mot_de_passe')
		{
		if ($('#mot_de_passe').attr('value') == 'mot de passe')
			{
			$('#mot_de_passe').attr('value', '');
			//if (!ie)
				//$('#mot_de_passe').attr('type', 'password');
			}
		}
}

function blurConnexion(field) {
	if (field == 'identifiant')
		{
		if ($('#identifiant').attr('value') == '')
			$('#identifiant').attr('value', 'e-mail');
		}
	else if (field == 'mot_de_passe')
		{
		if ($('#mot_de_passe').attr('value') == '')
			{
			//if (!ie)
				//$('#mot_de_passe').attr('type', 'text');
			$('#mot_de_passe').attr('value', 'mot de passe');
			}
		}
}

function validerConnexion() {
	if (($('#identifiant').attr('value') == '') || ($('#identifiant').attr('value') == 'e-mail'))
		alert('Veuillez saisir un identifiant valide !');
	else if (($('#mot_de_passe').attr('value') == '') || ($('#mot_de_passe').attr('value') == 'mot de passe'))
		alert('Veuillez saisir un mot de passe valide !');
	else
		$('#formIdentification').submit();
}

function envoyerInscription() {
	var bOk = true;
	var vFields = '';
	
	if ($('#utilisateur_prenom').attr('value') == '')
		{
		bOk = false;
		focusError('utilisateur_prenom');
		vFields += ((vFields != '')?', ':'') + 'Prénom';
		}
	else
		focusOk('utilisateur_prenom');
	
	if ($('#utilisateur_nom').attr('value') == '')
		{
		bOk = false;
		focusError('utilisateur_nom');
		vFields += ((vFields != '')?', ':'') + 'Nom';
		}
	else
		focusOk('utilisateur_nom');
		
	if ($('#utilisateur_code_postal').attr('value') == '')
		{
		bOk = false;
		focusError('utilisateur_code_postal');
		vFields += ((vFields != '')?', ':'') + 'Code postal';
		}
	else
		focusOk('utilisateur_code_postal');
		
	if ($('#utilisateur_ville').attr('value') == '')
		{
		bOk = false;
		focusError('utilisateur_ville');
		vFields += ((vFields != '')?', ':'') + 'Ville';
		}
	else
		focusOk('utilisateur_ville');
	
	if (!validEmail($('#utilisateur_email').attr('value')))
		{
		bOk = false;
		focusError('utilisateur_email');
		vFields += ((vFields != '')?', ':'') + 'E-Mail (format incorrect)';
		}
	else
		focusOk('utilisateur_email');
	
	if ($('#utilisateur_mot_de_passe').attr('value') == '')
		{
		bOk = false;
		focusError('utilisateur_mot_de_passe');
		vFields += ((vFields != '')?', ':'') + 'Mot de passe';
		}
	else
		focusOk('utilisateur_mot_de_passe');
	
	if (!bOk)
	{
		alert('Les champs suivants sont obligatoires : ' + vFields);
		return(false);
	}
	else
		{
		$('#utilisateur_prenom').value = ucfirst($('#utilisateur_prenom').attr('value'));
		$('#utilisateur_nom').value = strtoupper($('#utilisateur_nom').attr('value'));
		$('#utilisateur_societe').value = strtoupper($('#utilisateur_societe').attr('value'));
		$('#utilisateur_ville').value = strtoupper($('#utilisateur_ville').attr('value'));
		$('#utilisateur_email').value = strtolower($('#utilisateur_email').attr('value'));
		//$('#formInscription').submit();
		return(true);
		}
}

function envoyerContact() {
	var bOk = true;
	var vFields = '';
	
	if ($('#nom').attr('value') == '')
		{
		bOk = false;
		focusError('nom');
		vFields += ((vFields != '')?', ':'') + 'Nom';
		}
	else
		focusOk('nom');
		
	if ($('#prenom').attr('value') == '')
		{
		bOk = false;
		focusError('prenom');
		vFields += ((vFields != '')?', ':'') + 'Prénom';
		}
	else
		focusOk('prenom');
		
	if ($('#societe').attr('value') == '')
		{
		bOk = false;
		focusError('societe');
		vFields += ((vFields != '')?', ':'') + 'Société';
		}
	else
		focusOk('societe');
			
	if (!validEmail($('#email').attr('value')))
		{
		bOk = false;
		focusError('email');
		vFields += ((vFields != '')?', ':'') + 'E-Mail (format incorrect)';
		}
	else
		focusOk('email');
		
	/*
	if ($('#question').attr('value') == '')
		{
		bOk = false;
		focusError('question');
		vFields += ((vFields != '')?', ':'') + 'Question';
		}
	else
		focusOk('question');
	*/
	
	if (!bOk)
	{
		alert('Les champs suivants sont obligatoires : ' + vFields);
		return(false);
	}
	else
		return(true);
	//$('#formContact').submit();
}

function envoyerCompte() {
	var bOk = true;
	var vFields = '';
	
	if ($('#utilisateur_prenom').attr('value') == '')
		{
		bOk = false;
		focusError('utilisateur_prenom');
		vFields += ((vFields != '')?', ':'') + 'Prénom';
		}
	else
		focusOk('utilisateur_prenom');
	
	if ($('#utilisateur_nom').attr('value') == '')
		{
		bOk = false;
		focusError('utilisateur_nom');
		vFields += ((vFields != '')?', ':'') + 'Nom';
		}
	else
		focusOk('utilisateur_nom');
		
	if ($('#utilisateur_code_postal').attr('value') == '')
		{
		bOk = false;
		focusError('utilisateur_code_postal');
		vFields += ((vFields != '')?', ':'') + 'Code postal';
		}
	else
		focusOk('utilisateur_code_postal');
		
	if ($('#utilisateur_ville').attr('value') == '')
		{
		bOk = false;
		focusError('utilisateur_ville');
		vFields += ((vFields != '')?', ':'') + 'Ville';
		}
	else
		focusOk('utilisateur_ville');
	
	if (!validEmail($('#utilisateur_email').attr('value')))
		{
		bOk = false;
		focusError('utilisateur_email');
		vFields += ((vFields != '')?', ':'') + 'E-Mail (format incorrect)';
		}
	else
		focusOk('utilisateur_email');
	
	if ($('#utilisateur_mot_de_passe').attr('value') == '')
		{
		bOk = false;
		focusError('utilisateur_mot_de_passe');
		vFields += ((vFields != '')?', ':'') + 'Mot de passe';
		}
	else
		focusOk('utilisateur_mot_de_passe');
	
	if (($('#utilisateur_nouveau_mot_de_passe').attr('value') != '') && ($('#utilisateur_nouveau_mot_de_passe').attr('value') != $('#utilisateur_confirmation_mot_de_passe').attr('value')))
		{
		bOk = false;
		focusError('utilisateur_nouveau_mot_de_passe');
		focusError('utilisateur_confirmation_mot_de_passe');
		
		msg2 = 'Le champ "Confirmation mot de passe" ne correspond pas au champ "Nouveau mot de passe" !';
		}
	else if ($('#utilisateur_nouveau_mot_de_passe').attr('value') == '') {
		focusOk('utilisateur_nouveau_mot_de_passe');
		focusOk('utilisateur_confirmation_mot_de_passe');
	}
	
	if (!bOk) {
		msg = '';
		
		if (vFields != '') {
			msg += 'Les champs suivants sont obligatoires : ' + vFields;
			
			if (msg2 != '') {
				msg += "\n" + msg2;
			}
		}
		else {
			if (msg2 != '') {
			msg = msg2;
			}
		}
			
		alert(msg);
		return(false);
	}
	else
		{
		$('#utilisateur_prenom').value = ucfirst($('#utilisateur_prenom').attr('value'));
		$('#utilisateur_nom').value = strtoupper($('#utilisateur_nom').attr('value'));
		$('#utilisateur_societe').value = strtoupper($('#utilisateur_societe').attr('value'));
		$('#utilisateur_ville').value = strtoupper($('#utilisateur_ville').attr('value'));
		$('#utilisateur_email').value = strtolower($('#utilisateur_email').attr('value'));
		//$('#formInscription').submit();
		return(true);
		}
}

function construction_choix2(etat) {
	if (etat == 'on')
		{
		$('#construction-choix-2-liste').css('display', 'block');
		$('#construction-choix-2').css('display', 'none');
		}
	else if (etat == 'off')
		{
		$('#construction-choix-2-liste').css('display', 'none');
		$('#construction-choix-2').css('display', 'block');
		}
}

function scrollGlossaireTo(lettre) {
	$('#glossaire-contenu').scrollTo($('#glossaire-contenu-' + lettre), 1500);
}

function scrollGlossaireToWord(id) {
	$('#glossaire-contenu').scrollTo($('#glossaire-id-' + id), 1500);
}

function logo_kiriola() {
	$('#modalDialog').dialog('destroy');
	init_modal_dialog_noheight();
	
	$('#modalDialog').html('<p><a href="javascript:open_kiriola();" title="Kiriola Communication - Agence de Communication Lyon"><img src="images/logo-kiriola.jpg" width="408" height="212" border="0" alt="Kiriola Communication - Agence de Communication Lyon" /></a></p><p><b>Kiriola Communication, Agence de Communication à Lyon</b><br />Le GVIO<br />Batiment D<br />69760 Limonest<br />Tél : 04 78 35 13 14</p><p><a href="javascript:open_kiriola();" title="Kiriola Communication - Agence de Communication Lyon">http://www.kiriola.eu/</a></p>');
	
	$('#modalDialog').dialog('open');
}

function open_kiriola() {
	window.open('http://www.kiriola.eu/');
	$('#modalDialog').dialog('close');
}

function popupIdentification() {
	$('#modalDialog').dialog('destroy');
	init_modal_dialog_noheight_2();
	
	var html;
	
	html = '<form name="formIdentification" id="formIdentification" method="post" onsubmit="return(false);">';
	html += '<table align="center">';
	html += '<tr><td colspan="2" style="margin:0;padding:0 0 10px 0;color:#9c9e9f;font-size:50px;font-weight:normal;text-align: center">S\'identifier</td></tr>';
    html += '<tr><td style="font-family: Verdana, Geneva, sans-serif;font-weight:normal;font-size:12px;text-align:right;">E-mail : <input type="text" name="identifiant" id="identifiant" value="" class="input_type_text" size=30 /></td><td valign="middle" rowspan="2"><input type="image" id="bt_ok" src="images/bouton_ok.gif" alt="OK" title="OK" width="38" height="36" onclick="identification()" /></td></tr>';
    html += '<tr><td style="font-family: Verdana, Geneva, sans-serif;font-weight:normal;font-size:12px;text-align:right;">Mot de passe : <input type="password" name="mot_de_passe" id="mot_de_passe" value="" class="input_type_text" size=30 /></td></tr>';                 
 	html += '</table>';
	html += '</form>';
	
	$('#modalDialog').dialog('option', 'buttons', {
					"Fermer": function() {
                        $(this).dialog("close");
                    },
					"S'inscrire": function() {
                        document.location = 's-inscrire.html';
                    }
                });
    $('#modalDialog').html(html);
    $('#modalDialog').dialog('open');
}

function identification() {
	$.ajax({
                type: 'POST',
                url: baseUrl + '/ajax-identification.php',
                data: $('#formIdentification').serialize(),
                dataType: 'json',
                async: true,
                success: function(resultat){
                        if (resultat != 1) {
                           alert('Votre identification n\'est pas correcte');
                        }
                        else {
                        	document.location = document.location;
                        }
                }
            });
			
	return false;
}

function init_modal_dialog_noheight() {
	$('#modalDialog').dialog({ 
		modal: true, 
		overlay: { 
			opacity: 0.5, 
			background: 'black'
		},
		autoOpen: false,
		bgiframe: true,
		width: 680,
		position: 'center',
		title: 'GrDF Solegaz'
	});
}

function init_modal_dialog_noheight_2() {
	$('#modalDialog').dialog({ 
		modal: true, 
		overlay: { 
			opacity: 0.5, 
			background: 'black'
		},
		autoOpen: false,
		bgiframe: true,
		width: 450,
		position: 'center',
		title: 'GrDF Solegaz'
	});
}

function init_modal_dialog_extend() {
    if ($('#modalDialog').dialog('isOpen') == '[object Object]') {

    }
    else {
        $('#modalDialog').dialog('destroy');
    }

    $('#modalDialog').dialog({
        modal: true,
        overlay: {
            opacity: 0.5,
            background: 'black'
        },
        autoOpen: false,
        width: 650,
        height: 400,
        position: 'top',
        title: 'GrDF Solegaz'
    });
}

function mentions_legales() {
    var html = '';

    init_modal_dialog_extend();

    $('#modalDialog').dialog('option', 'buttons', {
        "Fermer": function() {
            $(this).dialog("close");
        }
    });

    html += '<h4>Responsable de la publication (loi n°2004-575 article 6 - III - 1 b et c)</h4>';
    html += '<p>Ce site est la propriété de GrDF, Société Anonyme au capital de 1.800.000.000 euros, immatriculée au Registre du Commerce et des Sociétés de Paris sous le numéro 444 786 511, dont le siège social est situé 6 rue Condorcet 75 009 PARIS.</p>';
    html += '<h4>Hébergeur du site (loi n°2004-575 article 6 - III - 1 d)</h4>';
    html += '<p>Le site Internet est hébergé par la société KIRIOLA dont le siège social est situé 49 chemin Vert 69760 LIMONEST.</p>';
    html += '<h4>Création / conception du site</h4>';
    html += '<p>Le site Internet a été conçu par la société KIRIOLA dont le siège social est situé 49 chemin Vert 69760 LIMONEST</p>';
    html += '<h4>Modification des mentions légales</h4>';
    html += '<p>GrDF se réserve le droit de modifier la présente notice à tout moment. L\'utilisateur s\'engage donc à la consulter régulièrement.</p>';
    html += '<h4>Droit applicable en cas de litige</h4>';
    html += '<p>Le droit applicable au site Internet de GrDF est le droit français.</p>';
    html += '<h4>Attribution de juridiction</h4>';
    html += '<p>Pour tout éventuel litige, il est fait attribution exclusive de juridiction aux tribunaux compétents du ressort de la Cour d\'appel de Paris.</p>';
    html += '<p>Avertissement : les informations relatives au Conseil d\'administration et à ses membres ne peuvent en aucun cas être utilisées à des fins de prospection commerciale. Toute exploitation de ces informations doit faire l\'objet d\'une demande écrite auprès de GrDF Secrétariat Général, 6 rue Condorcet 75009 Paris.</p>';

    $('#modalDialog').html(html);

    $('#modalDialog').dialog('open');
}

