jQuery.noConflict();

/* ------------------------------------------------------------------------------ BLOC DEFILANT */

//function panier parfait
function item_clicked(ong, bloc, url, pars){
	$(bloc).innerHTML = '<div style="margin-top:50px;margin-bottom:50px;margin-left: auto;margin-right: auto;width: 100%;text-align: center;"><img src="fileadmin/templates/img/ajax-loader.gif"  alt="" /><div style="margin-top:10px;">' + $(bloc).innerHTML + '</div></div>';
	onglet(ong,bloc);
	new Ajax.Updater({ success: bloc }, url, {method: 'post', parameters: pars});

}
function historique_change_month(){
	item_clicked(Form.Element.getValue($('historic_ong')),
				 Form.Element.getValue($('historic_bloc')),
				 Form.Element.getValue($('historic_url')),
				 Form.Element.getValue($('historic_parametre'))+'&month_choice='+Form.Element.getValue($('month_choice'))
				 );
}

window.onload = function(){
		 parseStylesheets();
}

function moveLayer(bloc,Sens){
		 var Objet = $(bloc.parentNode.parentNode.parentNode).select('.defil')[0];
		 if(parseInt(Objet.offsetTop) + (3*Sens) > 0){
		 		 Objet.style.top = "0px";
		 }
		 else{
		 		 Objet.style.top = (parseInt(Objet.offsetTop) + (3*Sens)) + "px";
		 }
		 Timer = window.setTimeout(function() { moveLayer(bloc, Sens)}, 50);
}

/* ------------------------------------------------------------------------------ GESTION BLOCS PAGE INT */
function masque(){
		 $("ong_historique").className="";
		 $("ong_panier").className="";
		 $("ong_donnees").className="";
		 $("ong_vrac").className="";
		 $("donnee_fonds").style.display="none";
		 if ($("panier_parfait"))
		 		 $("panier_parfait").style.display="none";
		 $("historique").style.display="none";
		 $("caracteristique").style.display="none";
		 $("vrac").style.display="none";
		 if ($("graph_2")) {
		 		 $("graph_2").style.display="none";
		 		 $("graph_2").hide();
		 }
}
function masque_onglet_parfait(){
		 $("ong_panier").className="";
		 $("ong_panier").style.display="none";
}
function onglet(onglet,bloc){
		 $("ong_historique").className="";
		 $("ong_panier").className="";
		 $("ong_donnees").className="";
		 $("ong_caracteristique").className="";
		 $("ong_vrac").className="";
		 $("donnee_fonds").style.display="none";
		 if ($("panier_parfait"))
		 		 $("panier_parfait").style.display="none";
		 $("historique").style.display="none";
		 $("vrac").style.display="none";
		 $("caracteristique").style.display="none";
		 $(onglet).className="on";
		 $(bloc).style.display="block";
}

function graph(img){
		 $("graph_1").style.display="none";
		 //$("graph_2").style.display="none";
		 $("graph_2").hide();
  $(img).style.display="block";
}

function onglet_over(onglet){
		 document.getElementById(onglet).className="on";
}

/*------------------------------------------------------------------------------------------ d�filement bloc gauche */
var stepref = -2;		 		 // Nbre de pixels de d�placement;
var step = stepref;
var delay = 50;
var pos;
var tid;

function getImagePosition (img) {

  if (document.layers)
  {
    return {x: img.x, y: img.y };
  }
  else {
    var coords = {x: 0, y: 0 };
    while (img) {
      coords.x += img.offsetLeft;
      coords.y += img.offsetTop;
      img = img.offsetParent;
    }
    return coords;
  }
}

function scrollContent () {
  pos += step;
  var contentHeight;
  if (document.layers) {
  	window.document.scrollBox.document.scrollContent.visibility = 'show';
    window.document.scrollBox.document.scrollContent.top = pos;
    contentHeight = window.document.scrollBox.document.scrollContent.document.height;
    boxHeight = window.document.scrollBox.clip.height;
  }
  else if (document.all) {
  	document.all.scrollContent.style.visibility = 'visible';
    document.all.scrollContent.style.top = pos + 'px';
    contentHeight = document.all.scrollContent.offsetHeight;
    boxHeight = document.all.scrollBox.offsetHeight;
  }
  else if (document.getElementById) {
  	document.getElementById('scrollContent').style.visibility = 'visible';
    document.getElementById('scrollContent').style.top = pos + 'px';
    contentHeight = document.getElementById('scrollContent').offsetHeight;
    boxHeight = document.getElementById('scrollBox').offsetHeight;
  }
  if (pos < -contentHeight)
    pos = boxHeight;
}

function init_ticker () {
  var imgCoords = getImagePosition(document.placeHolder);
  if (document.getElementById) {
    //document.getElementById('scrollBox').style.left = imgCoords.x + 'px';
   // document.getElementById('scrollBox').style.top = imgCoords.y + 'px';
    //document.getElementById('scrollBox').style.visibility = 'visible';
  }
  else if (document.layers) {
    document.scrollBox.left = imgCoords.x;
    document.scrollBox.top = imgCoords.y;
    document.scrollBox.clip.width = 145;
    document.scrollBox.clip.height = 100;
    //document.scrollBox.visibility = 'show';
  }
  $('scrollBox').style.visibility = 'visible';
  pos = 82;
  tid = setInterval('scrollContent()', delay);
}

/*------------------------------------------------------------------------------------------ deplier */
function depilSeminar(id, maxSeminar) {
		 var num = id;
		 var semiOther = "";
		 for (i=0; i<maxSeminar; i++){
		 		 if(i == num){
		 		 		 var semi = "semi"+num;
		 		 		 document.getElementById('num'+i).style.display="block";
		 		 		 document.getElementById(semi).style.background="#F2F2F2";
		 		 		 document.getElementById(semi).onmouseout="this.style.background='#F2F2F2';";

		 		 }else{
		 		 		 semiOther = "semi"+i;
		 		 		 document.getElementById('num'+i).style.display="none";
		 		 		 document.getElementById(semiOther).style.background="#FFFFFF";
		 		 		 document.getElementById(semiOther).onmouseout="this.style.background='#FFFFFF';"

		 		 }
		 }
}

/**
 *		 Whatever:hover - V1.42.060206 - hover & active
 *		 ------------------------------------------------------------
 *		 (c) 2005 - Peter Nederlof
 *		 Peterned - http://www.xs4all.nl/~peterned/
 *		 License  - http://creativecommons.org/licenses/LGPL/2.1/
 *
 *		 Whatever:hover is free software; you can redistribute it and/or
 *		 modify it under the terms of the GNU Lesser General Public
 *		 License as published by the Free Software Foundation; either
 *		 version 2.1 of the License, or (at your option) any later version.
 *
 *		 Whatever:hover is distributed in the hope that it will be useful,
 *		 but WITHOUT ANY WARRANTY; without even the implied warranty of
 *		 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *		 Lesser General Public License for more details.
 *
 *		 Credits and thanks to:
 *		 Arnoud Berendsen, Martin Reurings, Robert Hanson
 *
 *		 howto: body { behavior:url("csshover.htc"); }
 *		 ------------------------------------------------------------
 */

var csshoverReg = /(^|\s)(([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(hover|active)/i,
currentSheet, doc = window.document, hoverEvents = [], activators = {
		 onhover:{on:'onmouseover', off:'onmouseout'},
		 onactive:{on:'onmousedown', off:'onmouseup'}
}
/*
function parseStylesheets() {
		 if(!/MSIE (5|6)/.test(navigator.userAgent)) return;
		 window.attachEvent('onunload', unhookHoverEvents);
		 var sheets = doc.styleSheets, l = sheets.length;
		 for(var i=0; i<l; i++)
		 		 parseStylesheet(sheets[i]);
}
*/
var firstCall = true;
function parseStylesheets() {
    if(!/MSIE (5|6)/.test(navigator.userAgent)) return;
    var sheets = doc.styleSheets, l = sheets.length;

    if(firstCall){
        window.attachEvent('onunload', unhookHoverEvents);
        window.parseStylesheets = parseStylesheets;
        firstCall = false;
    } else {
        hoverEvents = [];
        unhookHoverEvents();
    }

    for(var i=0; i<l; i++)
        parseStylesheet(sheets[ i ]);
}

		 function parseStylesheet(sheet) {
		 		 if(sheet.imports) {
		 		 		 try {
		 		 		 		 var imports = sheet.imports, l = imports.length;
		 		 		 		 for(var i=0; i<l; i++) parseStylesheet(sheet.imports[i]);
		 		 		 } catch(securityException){}
		 		 }

		 		 try {
		 		 		 var rules = (currentSheet = sheet).rules, l = rules.length;
		 		 		 for(var j=0; j<l; j++) parseCSSRule(rules[j]);
		 		 } catch(securityException){}
		 }

		 function parseCSSRule(rule) {
		 		 var select = rule.selectorText, style = rule.style.cssText;
		 		 if(!csshoverReg.test(select) || !style) return;

		 		 var pseudo = select.replace(/[^:]+:([a-z-]+).*/i, 'on$1');
		 		 var newSelect = select.replace(/(\.([a-z0-9_-]+):[a-z]+)|(:[a-z]+)/gi, '.$2' + pseudo);
		 		 var className = (/\.([a-z0-9_-]*on(hover|active))/i).exec(newSelect)[1];
		 		 var affected = select.replace(/:(hover|active).*$/, '');
		 		 var elements = getElementsBySelect(affected);
		 		 if(elements.length == 0) return;

		 		 currentSheet.addRule(newSelect, style);
		 		 for(var i=0; i<elements.length; i++)
		 		 		 new HoverElement(elements[i], className, activators[pseudo]);
		 }

function HoverElement(node, className, events) {
		 if(!node.hovers) node.hovers = {};
		 if(node.hovers[className]) return;
		 node.hovers[className] = true;
		 hookHoverEvent(node, events.on, function() { node.className += ' ' + className; });
		 hookHoverEvent(node, events.off, function() { node.className = node.className.replace(new RegExp('\\s+'+className, 'g'),''); });
}
		 function hookHoverEvent(node, type, handler) {
		 		 node.attachEvent(type, handler);
		 		 hoverEvents[hoverEvents.length] = {
		 		 		 node:node, type:type, handler:handler
		 		 };
		 }

		 function unhookHoverEvents() {
		 		 for(var e,i=0; i<hoverEvents.length; i++) {
		 		 		 e = hoverEvents[i];
		 		 		 e.node.detachEvent(e.type, e.handler);
		 		 }
		 }

function getElementsBySelect(rule) {
		 var parts, nodes = [doc];
		 parts = rule.split(' ');
		 for(var i=0; i<parts.length; i++) {
		 		 nodes = getSelectedNodes(parts[i], nodes);
		 }		 return nodes;
}
		 function getSelectedNodes(select, elements) {
		 		 var result, node, nodes = [];
		 		 var identify = (/\#([a-z0-9_-]+)/i).exec(select);
		 		 if(identify) {
		 		 		 var element = doc.getElementById(identify[1]);
		 		 		 return element? [element]:nodes;
		 		 }

		 		 var classname = (/\.([a-z0-9_-]+)/i).exec(select);
		 		 var tagName = select.replace(/(\.|\#|\:)[a-z0-9_-]+/i, '');
		 		 var classReg = classname? new RegExp('\\b' + classname[1] + '\\b'):false;
		 		 for(var i=0; i<elements.length; i++) {
		 		 		 result = tagName? elements[i].all.tags(tagName):elements[i].all;
		 		 		 for(var j=0; j<result.length; j++) {
		 		 		 		 node = result[j];
		 		 		 		 if(classReg && !classReg.test(node.className)) continue;
		 		 		 		 nodes[nodes.length] = node;
		 		 		 }
		 		 }

		 		 return nodes;
		 }

/* leftMenu */
function initLeftMenu(){
	if(document.getElementById("col_gauche")==null){
		window.setTimeout("initLeftMenu()", 100);
		return;
	}
	ocol = document.getElementById("col_gauche").getElementsByTagName("UL");
	lmo = null;
	for(i=0;i<ocol.length;i++){
		if(ocol[i].className=='leftMenu'){
			lmo = ocol[i];
			break;
		}
	}
	if ((lmo == null) || (lmo == undefined) || (lmo == "undefined"))
	  return;

	licol = lmo.getElementsByTagName("LI");

	for(i=0;i<licol.length;i++){
		lio = licol[i];
		lio.evt = lio.getElementsByTagName("A")[0];
		lio.chld = 0;
		if(lio.getElementsByTagName("UL").length>0)
			lio.chld = 1;
		lio.onmouseover = function(){
			if(this.chld)
				this.evt.className = 'on';
		}
		lio.onmouseout = function(e){
			if(document.all){
				if(this.contains(event.toElement))
					return;
			}
			else if(e){
				if(e.relatedTarget!=null){
					o = e.relatedTarget;
					while(o.tagName!="HTML"){
						if(o.parentNode==this)
							return;
						o = o.parentNode;
					}
				}
			}
			if(this.chld)
				this.evt.className = '';
		}
	}
}

initLeftMenu();

function verifForm(id, form_name,error_nom, error_prenom, error_media, error_email, error_tel, error_population, error_province, error_accept_condition, error_mail_non_valide, error_dni) {
	var erreur = "";

	if(eval("document.getElementById('nom" + id + "').value==''")) {
		erreur= erreur+error_nom;
	}
	if(eval("document.getElementById('prenom" + id + "').value==''")) {
		erreur = erreur+'\n'+error_prenom;
	}
	if(eval("document.getElementById('media" + id + "').selectedIndex==0")) {
		erreur= erreur+'\n'+error_media;
	}
	if(eval("document.getElementById('email" + id + "').value==''")) {
		erreur=erreur+'\n'+error_email;
	}
	if ((!(eval("document.getElementById('email" + id + "').value").match(/^[\w\-]+(\.[\w\-]+)*@[\w\-]+(\.[\w\-]+)*\.[\w\-]{2,}$/))) && (eval("document.getElementById('email" + id + "').value!=''"))) {
		erreur= erreur+'\n'+error_mail_non_valide;
	}
	if(eval("document.getElementById('tel" + id + "').value==''")) {
		erreur= erreur+'\n'+error_tel;
	}
	if(eval("document.getElementById('population" + id + "').value==''")) {
		erreur= erreur+'\n'+error_population;
	}
	if(eval("document.getElementById('province" + id + "').selectedIndex==0")) {
		erreur= erreur+'\n'+error_province;
	}
	if(error_dni) {
		if(eval("document.getElementById('dni" + id + "').value==''")) {
			erreur= erreur+'\n'+error_dni;
		}
	}
	if(!eval("document.getElementById('accept_condition" + id + "').checked")) {
		erreur= erreur+'\n'+error_accept_condition;
	}

	if(erreur=="") document.forms[form_name].submit();
	else alert(erreur);
}

// DISCLAIMER

function showStep2(){
	$('form2').className = 'visible';
	$('fl').className = 'visible';
	$('fulltermtext').hide();
	if($('ex1').checked){
		$('priv').show();
		$('prof').hide();
	}else{
		$('prof').show();
		$('priv').hide();
	}
}

function showStep3(id){
	if($('ex3').checked){
		$('form3').className = 'visible';
		$('validation').disabled = false;
		if(id && $('ex2').checked){
			var link = id + '?height=400&width=400';
			TB_show('titre',link);
		}
	}else{
		$('form3').className = 'opaque';
		$('validation').disabled = true;
	}
}

function checkDisclaimer(){
	return ($('ex1').checked || $('ex2').checked) && $('ex3').checked;
}

function seefullterm(id){
	/*$("prof").hide();
	$("priv").hide();
	$("fulltermtext").show();*/
	var link = id + '?height=600&width=900';
	TB_show('titre',link);
}

/*--------------------------------------------------------------------
disclaimer HK
---------------------- deplier */

function myTickboxReady(id){
	//var test = id + '&height=400&width=400';
	//alert(id);
	//var test = 'index.php?id=1972&height=400&width=400&url='+id;
	//alert(id)
	var link = id + '?height=400&width=400';
	TB_show('titre',link);
}


function myTickboxReadyClose(){
	TB_remove();
}

function myTickboxReadyv2(id){
	var link = id + '&height=400&width=400';
	TB_show('titre',link);
}




