/*----------------------------------------------------------------------------//
// Javascript pour le site client  -------------------------------------------//
//----------------------------------------------------------------------------//
// Client : GH Chemicals
// Note   : Javascript général
// Date   : mai 2010
//----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------*/
// Inclusion dynamique des fichiers externes javascripts
/*----------------------------------------------------------------------------*/
function importJavascript(src)
{
	document.write("<script type=\"text/javascript\" src=\"" + src + "\"></scr" + "ipt>");
}
function importCss(href, media)
{
	document.write('<link rel="stylesheet" type="text/css" media="' + media + '" href="' + href + '" />');
}

/*----------------------------------------------------------------------------*/
// Importations de fichiers
/*----------------------------------------------------------------------------*/
// importJavascript("/includes/js/plugins/jquery.plugin.js");
// importCss("/includes/js/plugins/jquery.plugin.css", "screen");

/*----------------------------------------------------------------------------*/
// Déclarations jQuery
/*----------------------------------------------------------------------------*/
var GHC = {};

$(document).ready(function(){
						   
	// global replace
	$('hr').replaceWith('<div class="hr">&nbsp;</div>');


	/* +-------------------------------------------------------
	   | Entête Accueil
	   +------------------------------------------------------- */
	if ($('#EnteteImage li').length > 1) {
		var e = {};
		

		/* Liste entêtes
		------------------------------------------------------- */
		e.$liste     = $('#EnteteImage ul');
		
		e.curr  = 1;
		e.max   = e.$liste.find('> li').length;

		
		/* Move
		------------------------------------------------------- */
		e.Move = function() {

			// current li
			var $liCurr = e.$liste.find('li:nth-child('+e.curr+')')
			
			// next li
			e.curr = (e.curr % e.max) + 1;
			var $liNew  = e.$liste.find('li:nth-child('+e.curr+')')


			// fade
			$liCurr
				.css('zIndex',1)
				.fadeOut(900)
			;
			
			$liNew
				.css('zIndex',2)
				.fadeIn(900)
			;
			
			return false;
		};

		e.Interval = setInterval(e.Move,6000);

		// afficher publiquement au besoin
		GHC.Entete = e;
	}
	
	
	/* +-------------------------------------------------------
	   | Input focus
	   +------------------------------------------------------- */
	$('input[type="text"], textarea')
		.bind('focus',function(){
			$(this).addClass('Focus');
			$(this).removeClass('Erreur');
		})
		.bind('blur',function(){
			$(this).removeClass('Focus');
		}
	);
		
});


















function CheckForm(formName) {
    if (typeof (Page_ClientValidate) == 'function') {
        if (!Page_ClientValidate(formName)) {
            ValidateForm(formName, true, "Erreur");
            return false;
        }
    }
    return true;
}

function ValidateForm(groupName, OnlyOneErrorByField, classError) {
    var msg = new Array();
    var ctl = new Array();
    if (classError != '') jQuery('.' + classError).removeClass(classError);
    //Ne pas oublier d'appliquer "Page_ClientValidate()" avant d'appeler cette procédure
    for (var i = 0; i < Page_Validators.length; i++) {
        if (Page_Validators[i].validationGroup == groupName && !Page_Validators[i].isvalid) {
            if (OnlyOneErrorByField) {
                var exist = false;
                for (var y = 0; y < ctl.length; y++) {
                    if (ctl[y] == Page_Validators[i].controltovalidate)
                        exist = true;
                }
                if (!exist) {
                    msg[msg.length] = Page_Validators[i].errormessage;
                    if (classError != '') jQuery('#' + Page_Validators[i].controltovalidate).addClass(classError);
                }
            }
            else {
                msg[msg.length] = Page_Validators[i].errormessage;
                if (classError != '') jQuery('#' + Page_Validators[i].controltovalidate).addClass(classError);
            }
            ctl[i] = Page_Validators[i].controltovalidate;
        }
    }
    return msg;
}

