function addToFavorite(label, classname){
	var IEstring = "<a class='" + classname + "' href='javascript:window.external.addfavorite(location.href,document.title);' title='Ajouter le site aux favoris'>"+label+"<\/a>" ;
	var NSstring = "<a class='" + classname + "' href='javascript:void(0);' onclick='alert(\"Presser [Ctrl + D] pour ajouter le site aux favoris.\")'>"+label+"</a>";
	var OPstring = "<a class='" + classname + "' href='javascript:void(0);' onclick='alert(\"Presser [Ctrl + T] pour ajouter le site aux favoris.\")'>"+label+"</a>";
	var OTHstring = "<a class='" + classname + "' href='javascript:void(0);' onclick='alert(\"Vous devez ajouter manuellement le site à vos favoris.\")'>"+label+"</a>"
	var whichString = OTHstring ;
	
	var agt = navigator.userAgent.toLowerCase();
	var app = navigator.appName.toLowerCase();
	var ieAgent = agt.indexOf('msie');
	var nsAgent = app.indexOf('netscape');
	var opAgent = app.indexOf('opera');
	
	if (ieAgent!= -1) { 
		whichString = IEstring; 
	} else if (nsAgent!= -1){ 
		whichString = NSstring; 
	} else if (opAgent!= -1){
		whichString = OPstring; 
	}
	
	document.write(whichString);
}



function getQuery(queryString) {
	frm = document.getElementsByTagName("form");
    query = "(";
	// loop over the length of the forms in the document
	for(i=0;i<frm.length;i++) {
		// reference to the elements of the form
		c = frm[i].elements;
		var nbCheckBox = 0;
		if (c != null)
			nbCheckBox = c.length;
		// loop over the length of those elements
		for(j=0;j<nbCheckBox;j++) {
			// if this element is a checkbox, do our thing
			if(c[j].getAttribute("type") == "checkbox") {
			// hide the original checkbox
				if ( c[j].checked ) query += "URI:" + c[j].name.substring(7,c[j].name.length) + "/* OR ";
			}
		}
	}
	query = query.substring(0,query.length - 4);
	query += ") AND (SERVICE:KiwiSearch) AND (TYPE:URL) AND " + formatQuery(queryString);
	return query;
}

function getParamString() {
  	frm = document.getElementsByTagName("form");
  	query = "";
	// loop over the length of the forms in the document
	for(i=0;i<frm.length;i++) {
		// reference to the elements of the form
		c = frm[i].elements;
		// loop over the length of those elements
		for(j=0;j<c.length;j++) {
			// if this element is a checkbox, do our thing
			if(c[j].getAttribute("type") == "checkbox") {
			// hide the original checkbox
				if ( c[j].checked ) query += c[j].name + "=" + c[j].value + "&";
			}
		}
	}
	if ( document.getElementById("uri") != null ) {
		query += "uri=" + document.getElementById("uri").value;
	} else {
		query = query.substring(0,query.length - 1);
	}
	return query;
}

function submitrecherche(formid) {

	var form = document.getElementById(formid);
	form.query.value = formatQuery(form.query.value);
	form.submit();
}

function formatQuery (query){

		var strQuery = new String(query);
        strQuery = strQuery.replace(/À/g, "a");
        strQuery = strQuery.replace(/Á/g, "a");
        strQuery = strQuery.replace(/Â/g, "a");
        strQuery = strQuery.replace(/Ã/g, "a");
        strQuery = strQuery.replace(/Ä/g, "a");
        strQuery = strQuery.replace(/Å/g, "a");
        strQuery = strQuery.replace(/Ç/g, "c");
        strQuery = strQuery.replace(/È/g, "e");
        strQuery = strQuery.replace(/É/g, "e");
        strQuery = strQuery.replace(/Ê/g, "e");
        strQuery = strQuery.replace(/Ë/g, "e");
        strQuery = strQuery.replace(/Ì/g, "i");
        strQuery = strQuery.replace(/Í/g, "i");
        strQuery = strQuery.replace(/Î/g, "i");
        strQuery = strQuery.replace(/Ï/g, "i");
        strQuery = strQuery.replace(/Ð/g, "d");
        strQuery = strQuery.replace(/Ñ/g, "n");
        strQuery = strQuery.replace(/Ò/g, "o");
        strQuery = strQuery.replace(/Ó/g, "o");
        strQuery = strQuery.replace(/Ô/g, "o");
        strQuery = strQuery.replace(/Õ/g, "o");
        strQuery = strQuery.replace(/Ö/g, "o");
        strQuery = strQuery.replace(/Ù/g, "u");
        strQuery = strQuery.replace(/Ú/g, "u");
        strQuery = strQuery.replace(/Û/g, "u");
        strQuery = strQuery.replace(/Ü/g, "u");
        strQuery = strQuery.replace(/Ý/g, "y");
        strQuery = strQuery.replace(/à/g, "a");
        strQuery = strQuery.replace(/á/g, "a");
        strQuery = strQuery.replace(/â/g, "a");
        strQuery = strQuery.replace(/ã/g, "a");
        strQuery = strQuery.replace(/ä/g, "a");
        strQuery = strQuery.replace(/å/g, "a");
        strQuery = strQuery.replace(/ç/g, "c");
        strQuery = strQuery.replace(/è/g, "e");
        strQuery = strQuery.replace(/é/g, "e");
        strQuery = strQuery.replace(/ê/g, "e");
        strQuery = strQuery.replace(/ë/g, "e");
        strQuery = strQuery.replace(/ì/g, "i");
        strQuery = strQuery.replace(/í/g, "i");
        strQuery = strQuery.replace(/î/g, "i");
        strQuery = strQuery.replace(/ï/g, "i");
        strQuery = strQuery.replace(/ñ/g, "n");
        strQuery = strQuery.replace(/ò/g, "o");
        strQuery = strQuery.replace(/ó/g, "o");
        strQuery = strQuery.replace(/ô/g, "o");
        strQuery = strQuery.replace(/õ/g, "o");
        strQuery = strQuery.replace(/ö/g, "o");
        strQuery = strQuery.replace(/ù/g, "u");
        strQuery = strQuery.replace(/ú/g, "u");
        strQuery = strQuery.replace(/û/g, "u");
        strQuery = strQuery.replace(/ü/g, "u");
        strQuery = strQuery.replace(/ý/g, "y");
        strQuery = strQuery.replace(/ÿ/g, "y");
        //strQuery = strQuery + "*";
	return strQuery.toLowerCase();
}


function getUrlPageForPrint (){
	if (window.location.href.indexOf('?')!=-1)
		return window.location.href + "&decorator=print";
	else return window.location.href + "?decorator=print";
}
										
function openPrintWindow(url) {
	document.body.style.cursor="wait";
  	popupWin = window.open(url, "Popup", "directories=no,toolbar=no,menubar=yes,scrollbars=yes,resizable=yes,width=620,innerWidth=615,height=580,left=5,top=10");
}

function openPopupWindow(url) {
  	popupWin = window.open(url, "Popup", "directories=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,width=400,height=400,left=5,top=10");
}

function openPopupWindow(url, width, height) {
  	popupWin = window.open(url, "Popup", "directories=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,width=" + width + ",height=" + height + ",left=5,top=10");
}

function resizeWindowWidthImg(addWidth, addHeight) {
	var img = new Image();
	img.src = window.document.images[0].src;

	//alert(img.width  + "//" + img.height);

	//var goodWidth = img.width + 50 + addWidth;
	//var goodHeight = img.height + 80 + addHeight;
	var goodWidth = img.width + 100 + addWidth;
	var goodHeight = img.height + 250 + addHeight;

	if (goodWidth > screen.availWidth)
		goodWidth = screen.availWidth-5;

	if (goodHeight > screen.availHeight)
		goodHeight = screen.availHeight-10;
		
	if (goodWidth < 190)
		goodWidth = 190;

	if (goodHeight < 30)
		goodHeight = 30;

	window.resizeTo(goodWidth, goodHeight);
	
	//document.body.style.cursor="default";
	//window.opener.document.body.style.cursor="default";
}

function showLettreInfo(type) {
											
	var mail = document.getElementById('mail');
	var poste = document.getElementById('poste');

	if(type == 'mail') {																									
		mail.style.display = 'block';
		poste.style.display = 'none';
	}
	else if(type == 'poste') {												
		mail.style.display = 'none';
		poste.style.display = 'block';
	}

}

function resizeWindow(divConteneur, maxWidth, maxHeight) {
	
	var offset = 10;
	
	var conteneur = document.getElementById(divConteneur);
		
	// Taille du conteneur
	var conteneurWidth = conteneur.offsetWidth;
	var conteneurHeight = conteneur.offsetHeight;
	
	// Taille du navigateur
	var browserWidth = document.documentElement.clientWidth;
	var browserHeight = document.documentElement.clientHeight;
	
	var newWidth = 0, newHeight = 0;
		
	// Si la largeur du conteneur est supérieur au navigateur
	if(conteneurWidth > browserWidth) {
		
		// Si la taille max est dépasser ne rien faire sinon resize de la fenetre
		if(conteneurWidth < maxWidth)
			newWidth = (conteneurWidth - browserWidth) + offset;
		else
			newWidth = browserWidth - maxWidth;
	}
	
	// Si la hauteur du conteneur est supérieur au navigateur et qu'il ne dépasse pas la hauteur max
	if(conteneurHeight > browserHeight && browserHeight < maxHeight) {
		
		// Resize si la taille du navigateur et inférieur à la taille max
		if(browserHeight < maxHeight)
			newHeight = maxHeight - browserHeight;		
	}
	
	// Resize la fenetre 
	window.resizeBy(newWidth, newHeight);	
}

function getRadioValue(radios) {
	for (i=0; i<radios.length; i++){
		if (radios[i].checked)
			return radios[i].value;
	}
	return '';
}
