/**
 * Library of javascript functions
 *
 * @author	Darena, Conception Graphique, www.darena.fr
 * @version 1.0
 */

// detect browser type
var dom = (document.getElementById) ? true : false;
var ns4 = (document.layers && !dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;

// set the image
function setImage(imgname, imgurl) {
	if (document.images[imgname]) {
		document.images[imgname].src = imgurl;
	}
}

// submit the form
function submitForm(theformname, theaction) {
	if (document.forms[theformname]) {
		document.forms[theformname].act.value = theaction;
		document.forms[theformname].submit();
	}
}

// submit the form with a new value
function submitFormField(theformname, theaction, thefield, thevalue) {
	if (document.forms[theformname]) {
		document.forms[theformname].elements[thefield].value = thevalue;
		document.forms[theformname].act.value = theaction;
		document.forms[theformname].submit();
	}
}

// open the link in a new window
// return false if the popup is shown, true otherwise
function openWindow(oLink, name, width, height, params) {
	var href = '';
	if (oLink.getAttribute) url = oLink.getAttribute('href');
	if (href=='') href = oLink.href;
	var all_params = '';
	all_params += 'width=' + width + ',height=' + height;
	if (params && params!='') all_params += ','+params;
	// all is ready, open the popup and focus on it
	var oPopup = window.open(href, (name && name!='' ? name : 'popup'), all_params);
	if (oPopup) oPopup.focus();
	return (oPopup?false:true);
}

// open the link in the opener window
function showLinkInOpener(href) {
	if (window.opener) {
		window.opener.document.location.href = href;
		window.opener.focus();
	} else {
		// opener don't exist, open link in new window
		window.open(href, 'popup');
	}
}

// show an element
function show(id) {
	if (ns4) {
		if (document.layers[id]) {
			document.layers[id].visibility = "show";
			document.layers[id].display = "block";
		}
	} else if (ie4) {
		if (document.all[id]) {
			document.all[id].style.visibility = "visible";
			document.all[id].style.display = "block";
		}
	} else if (dom) {
		if (document.getElementById(id)) {
			document.getElementById(id).style.visibility = "visible";
			document.getElementById(id).style.display = "block";
		}
	}
}

// hide an element
function hide(id) {
	if (ns4) {
		if (document.layers[id]) {
			document.layers[id].visibility = "hide";
			document.layers[id].display = "none";
		}
	} else if (ie4) {
		if (document.all[id]) {
			document.all[id].style.visibility = "hidden";
			document.all[id].style.display = "none";
		}
	} else if (dom) {
		if (document.getElementById(id)) {
			document.getElementById(id).style.visibility = "hidden";
			document.getElementById(id).style.display = "none";
		}
	}
}

// hide multiple div, beginning with 'pre' as prefix and a number
function hideMulti(pre, start, end) {
	var s, i;
	for (i=start; i<=end; i++) {
		s = pre+''+i;
		hide(s);
	}
}

// show a div if it is visible, hide it if it is hidden
function toggle(id) {
	if (ns4) {
		if (document.layers[id]) {
			if (document.layers[id].visibility == "hide" || document.layers[id].display == "none")
				show(id);
			else
				hide(id);
		}
	} else if (ie4) {
		if (document.all[id]) {
			if (document.all[id].style.visibility == "hidden" || document.all[id].style.display == "none")
				show(id);
			else
				hide(id);
		}
	} else if (dom) {
		if (document.getElementById(id)) {
			if (document.getElementById(id).style.visibility == "hidden" || document.getElementById(id).style.display == "none")
				show(id);
			else
				hide(id);
		}
	}
}







// hide a div after x seconds, return the timer
function hideAfter(id, sec) {
	return setTimeout("hideAfter_real('"+id+"')", sec*1000);
}
// hide a div after x seconds
function cancelHideAfter(timer) {
	if (timer != null) {
		clearTimeout(timer);
		timer = null;
	}
}
// hide a div after x seconds
function hideAfter_real(id) {
	hide(id);
}

