// JavaScript Document

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function openImage(url) {
	MM_openBrWindow('/openImage.asp?image=' + url ,'view','width=20,height=200') ;
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function URLEncode(S)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = S;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

function URLDecode(S)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = S;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while

	return plaintext;
};


function dlFile(file) {
	document.location.href = "/download/dlFile.asp?file=" + file ;
}

function dlFilePDF(codeProduit,nomFichier) {
	pageTracker._trackPageview ("/telecharger/" + nomFichier);
	if (isNaN(codeProduit)) {
		dlFile(codeProduit) ;
	} else {
		document.location.href = "dlFicheInfo.asp?codeProduit=" + codeProduit + "&nomFichier=" + nomFichier ;
	}
}

function dlTarif() {
	document.formtarif.submit() ;
}

function goContact() {
	document.location.href = "/app/fiches/contact_enr.html" ;	
}





function verif_email(str_email)
{
	var place = str_email.indexOf('@',1);
	var point = str_email.indexOf('.',place+1);
	if ((place > -1)&&(str_email.length >2)&&(point > 1))
	{
		return true ;
	}
	else
	{
		return false ;
	}
}


function envoyer_installateurs()
{
	var nb_err  = 0 ;
	var msg_err = '' ;
	var i = 0 ;
	var msg_perso = false ; 
	var nom = window.document.formulaire.nom.value ; 
	if (nom == '') {
		if (msg_perso == false) {
			nb_err++ ;
			msg_err += '- nom\n' ;
		}
	}
	var msg_perso = false ; 
	var prenom = window.document.formulaire.prenom.value ; 
	if (prenom == '') {
		if (msg_perso == false) {
			nb_err++ ;
			msg_err += '- prenom\n' ;
		}
	}

	var msg_perso = false ; 
	var adresse = window.document.formulaire.adresse.value ; 
	if (adresse == '') {
		if (msg_perso == false) {
			nb_err++ ;
			msg_err += '- Adresse\n' ;
		}
	}
	
	
	var msg_perso = false ; 
	var email = window.document.formulaire.email.value ; 
	if (verif_email(email) == false) {
		if (msg_perso == false) {
			nb_err++ ;
			msg_err += '- email\n' ;
		}
	}
//	alert('xmcl');
	var msg_perso = false ; 
	var commentaires = window.document.formulaire.commentaires.value ; 
	if (commentaires == '') {
		if (msg_perso == false) {
			nb_err++ ;
			msg_err += '- Commentaires\n' ;
		}
	}

	var msg_perso = false ; 
	var demandeur = window.document.formulaire.demandeur.value ; 
	if (demandeur == '') {
		if (msg_perso == false) {
			nb_err++ ;
			msg_err += '- Demandeur\n' ;
		}
	}

	if (nb_err == 0) {
		window.document.formulaire.submit() ;
	} else if(nb_err == 1) {
		alert('Le champ suivant est obligatoire :\n' + msg_err) ;
	} else {
		alert('Les champs suivants sont obligatoires :\n' + msg_err) ;
	}
}

	// initialise plugins
	jQuery(function(){
		jQuery('ul.menu-kme').superfish();
	});
	


// Fonction Pretty Photo -------------------

$(document).ready(function(){
$(".cShema a[rel^='prettyPhoto']").prettyPhoto({
	theme: 'facebook', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
	show_title: false
  });
});

$(document).ready(function(){
$(".cTableau:first a[rel^='prettyPhoto']").prettyPhoto({
	theme: 'light_square', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
	animationSpeed:'slow',
	slideshow:5000,
	show_title: false,
	default_width: 720,
	autoplay_slideshow: false
  });
});




/* ToolTip Jquery ------------------------------------------------------------------------------------------------ */
/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
this.screenshotPreview = function(){	
	/* CONFIG */
		
		xOffset = 125;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");								 
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


// starting the script on page load
$(document).ready(function(){
	screenshotPreview();
});

/*  ---------------------------------------------------------------------------------------------------------------- */

