/* --------------------------------------------------------
    Fonctions globales Javascript
    global.js
   -------------------------------------------------------- */

/*
 preload_image()
 image preloading
*/
function preload_image(image_name, image_src) {
    if (document.images) {
        eval(image_name + ' = new Image()');
        eval(image_name + '.src = "' + image_src + '"');
    }
}

/*
 change_image()
 swap images
*/
function change_image(image_name, image_src) {
    if (document.images) {
        document.images[image_name].src = image_src;
    }
}

/*
 open_window()
 opens a new pop-up window
*/
function open_window(page_url, page_name, window_width, window_height, scrollbar_value, is_center) {

    var window_pos_x = 20;
    var window_pos_y = 20;

    if (is_center == 'yes') {
        window_pos_x = (screen.width / 2) - (window_width / 2);
        window_pos_y = (screen.height / 2) - (window_height / 2);
    }

    popup_window = this.open(page_url, page_name, "toolbar=no,status=no,menubar=no,location=no,scrollbars=" + scrollbar_value + ",resizable=no,width=" + window_width + ",height=" + window_height + ",screenX=" + window_pos_x + ",screenY=" + window_pos_y + ",left=" + window_pos_x + ",top=" + window_pos_y);
    popup_window.focus();
}

/*
 anti_spam_email()
 protects email from spam bots
*/

function anti_spam_email(user,domain,css) {
    var username = user;
    var hostname = domain;
	var cssname = css;
    var linktext = username + "&#064;" + hostname;
    document.write("<a href=" + "mail" + "to:" + username +"&#064;" + hostname + " class=" + cssname+">" + linktext + "</a>");
}

/*
 valide_form_newsletter()
 validates newsletter form (valid email required)
*/
function valide_form_newsletter() {

    var at = /^(.+)@(.+)\.(.+)$/;

    if (!at.test(document.form.email.value) || document.form.email.value == "") {
        alert('Votre courriel semble invalide, veuillez le corriger');
        document.form.email.focus();
        return false;
    }
}

/*
 Menu rétractable
 Modified by Dynamic Drive for format & NS4/IE4 compatibility
 Visit http://www.dynamicdrive.com/ for full source code
 SwitchMenu(obj)
*/
if (document.getElementById){ //DynamicDrive.com change
	document.write('<style type="text/css">\n')
	document.write('.divSubmenu{display: none;}\n')
	document.write('</style>\n')
}

function SwitchMenu(obj){
	if(document.getElementById){
		var objvalue = obj.substring(0,4)
		var el = document.getElementById(objvalue);
		var ar = document.getElementById("menu").getElementsByTagName("span"); //DynamicDrive.com change
			if(el.style.display != "block") { //DynamicDrive.com change
				for (var i=0; i<ar.length; i++) {
					if (ar[i].className=="divSubmenu") {//DynamicDrive.com change
						ar[i].style.display = "none";
					}
				}
				el.style.display = "block";
				if(obj.length>4) document.getElementById(obj).className="submenuon"
				change_image(objvalue+'img','./'+chemin+'php/'+lang+'/pic/menu_'+tabImg[objvalue]+'_o.gif');
				
			} else {
				el.style.display = "none";
				change_image(objvalue+'img','./'+chemin+'php/'+lang+'/pic/menu_'+tabImg[objvalue]+'.gif');
			}
	}
}

/*
 Tableau images menu
*/
var tabImg = new Array();
tabImg["sub1"] = "laboratoire";
tabImg["sub2"] = "analyses-medicales";
tabImg["sub3"] = "documentation-liens";
tabImg["sub4"] = "prelevements-pratique";
tabImg["sub5"] = "demarche-qualite";


/*
 paramsIFR()
 permutte les titres en swf
*/

function paramsIFR(chemin) {	
//<![CDATA[
	//if (sIFR != null && sIFR.replaceElement != null) {
		if(typeof sIFR == "function") {		
		//sIFR.replaceElement(named({nWidth:50,nHeight:40,sSelector:"body h1", sFlashSrc:"vandenkeere.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#FFFFFF", sHoverColor:"#CCCCCC", nPaddingTop:20, nPaddingBottom:20, sFlashVars:"textalign=center&offsetTop=6"}));
			sIFR.replaceElement("h1", chemin+"trebuchet.swf", named({sColor:"#5D6193", sBgColor:"#0284CA",sWmode:"transparent"}));
			sIFR.replaceElement(".gris", chemin+"trebuchet.swf", named({sColor:"#666666", sBgColor:"#FFFFFF",sWmode:"transparent"}));
			sIFR.replaceElement(".vert", chemin+"trebuchet.swf", named({sColor:"#009FA0", sBgColor:"#FFFFFF",sWmode:"transparent"}));
			sIFR.replaceElement(".mauve", chemin+"trebuchet.swf", named({sColor:"#433B67", sBgColor:"#FFFFFF",sWmode:"transparent"}));
			sIFR.replaceElement(".noir", chemin+"myriad.swf", named({sColor : "#000000", sBgColor:"#FFFFFF",sWmode:"transparent"}));
			sIFR.replaceElement(".blanc", chemin+"myriad.swf", named({sColor : "#ffffff", sBgColor:"#FFFFFF",sWmode:"transparent"}));
	}	
	//]]>
}
