// +----------------------------------------------------------------------+
// | Spring                                                               |
// +----------------------------------------------------------------------+
// | Copyright (c) 2006 WS Interactive                                    |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license,       |
// | or (at your discretion) to version 3.0 of the PHP license.           |
// | The first is bundled with this package in the file LICENSE-GPL, and  |
// | is available at through the world-wide-web at                        |
// | http://www.gnu.org/copyleft/gpl.html.                                |
// | The later is bundled with this package in the file LICENSE-PHP, and  |
// | is available at through the world-wide-web at                        |
// | http://www.php.net/license/3_0.txt.                                  |
// +----------------------------------------------------------------------+
// | Author: Grégory Guérin <gregory.guerin@ws-interactive.fr>            |
// +----------------------------------------------------------------------+
//

/**
  * usefull functions for frontend sied
  * @author Grégory Guérin <gregory.guerin@ws-interactive.fr>
  */

/* USEFULL FUNCTIONS */
/**********************************************
* Browser definition                          *
**********************************************/
if (navigator.userAgent.toLowerCase().indexOf('msie') != -1 && navigator.userAgent.toLowerCase().indexOf('opera') == -1) {
	var isIE = true;
	//get IE version
	if (navigator.userAgent.toLowerCase().indexOf("msie 5.5") != -1) {
		var isIE55 = true;
	} else if (navigator.userAgent.toLowerCase().indexOf("msie 6") != -1)  {
		var isIE6 = true;
	} else if (navigator.userAgent.toLowerCase().indexOf("msie 7") != -1)  {
		var isIE7 = true;
	}
} else if (navigator.userAgent.toLowerCase().indexOf('opera') != -1) {
	var isOp = true;
} else if (navigator.userAgent.toLowerCase().indexOf('firefox') != -1 || 
		  (navigator.userAgent.toLowerCase().indexOf('mozilla') != -1 && (navigator.userAgent.toLowerCase().indexOf('rv:1.7') != -1 || navigator.userAgent.toLowerCase().indexOf('rv:1.8') != -1))) {
	var isMoz = true;
}
/**
  *	Dynamic time
  */

function ejs_server_calc(element)
{
	if (ejs_server_sec < 10)
		ejs_server_sec = "0"+Math.round(ejs_server_sec);
	else if(ejs_server_sec >= 60)
		{
		ejs_server_sec = "00";
		ejs_server_min++;
		}
	if (ejs_server_min < 10)
		ejs_server_min = "0"+Math.round(ejs_server_min);
	else if(ejs_server_min >= 60)
		{
		ejs_server_min = "00";
		ejs_server_heu++;
		}
	if (ejs_server_heu < 10)
		ejs_server_heu = "0"+Math.round(ejs_server_heu);
	else if(ejs_server_heu >= 24)
		{
		ejs_server_heu = "00";
		}
	ejs_server_texte = ejs_server_heu + ":" + ejs_server_min + ":" + ejs_server_sec;
	if (document.getElementById){
		document.getElementById(element).innerHTML=ejs_server_texte;
		}
	ejs_server_sec++;
}

function addToBookmark(url,name,message)
{
	nav = navigator.appName.substring(0,3);
	ver = navigator.appVersion.substring(0,1)
	if (nav == "Mic" && ver >= 4)
	{
		window.external.AddFavorite(url, name);
	}
	else
	{
		alert(message);
	}
}

function controlMail(email){
	var debut = email.indexOf("@");
	var taille = email.length;
	var fin = email.substr(debut,taille);
	if (debut != -1) {
		if (fin.indexOf(".") != -1) {
			return true;
		}else{
			return false;
		}
	}else{
		return false;
	}
}

function errorMessage(divId,message){
	element = document.getElementById(divId);
	
	element.innerHTML = message;
	element.style.display = "block";
}

function openImage(img,titre) {
	popup = window.open('','Image','status=no,toolbar=no,scrollbars=no,resizable=no');
  	popup.document.write("<html><head><title>"+titre+"</title></head>"); 
 	popup.document.write("<script type=\"text/javascript\">function AjustePopUp() { if (document.images[0].complete) { window.resizeTo(document.images[0].width+100,document.images[0].height+100); window.focus();} else { setTimeout('AjustePopUp()',1000) } }</"+"script>");
  	popup.document.write("<body bgcolor='#000000' style='overflow: hidden;' onload='AjustePopUp()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0>"); 
 	popup.document.write("<table onclick='javascript:self.close();' width='100%' border='0' cellspacing='0' cellpadding='0' height='100%'><tr><td valign='middle' align='center'>"); 
 	popup.document.write("<img src='"+img+"' border='0' alt='' title=''>");
 	popup.document.write("</td></tr></table></body></html>"); 
  	popup.document.close(); 
} 

/* Add event on object*/
function addEvent(obj, evType, fn)
{
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
	return true;
}
/*
function sendPassword(id,message){
	inputObject = document.getElementById(id);
	if(inputObject.value = prompt(message)){
		document.lostPasswordForm.submit();
	}
}
*/
function sendPassword(id,message){
	inputObject = document.getElementById(id);
	if(inputObject.value = prompt(message)){
		document.lostPasswordForm.submit();
	}
}

function popupAide(id){
	element = document.getElementById(id);
	
	if(element.style.display == "block"){
		element.style.display = "none";
	}else{
		element.style.display = "block";
	}
}
/**
  * Get element by id
  * @param string id, the element id to get
  * @return wanted element or false if not founded
  */
function getE(id) {
	if (e = document.getElementById(id)) { 
		return e;
	} else {
		return false;
	}
}
/**
  * Add an event on a given object
  * @param html object obj, the object to add event on
  * @param string evType, the event type to add (click, mouseover, blur, etc.)
  * @param string fcn, the function name to call on event
  * @return boolean true on success, false on failure
  */
function addEvent(obj, evType, fcn) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fcn, true);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on"+evType, fcn);
		return r;
	} else {
		return false;
	}
	return true;
}
/*add some events on menu for IE compatibility only*/
function startMenu() {
	if (isIE /* && !isIE7	*/) {
		var liMenu = document.getElementById("menus").getElementsByTagName("LI");
		
		for (var i=0; i<liMenu.length; i++) {
		  	li = liMenu[i];
			
		  	if (li.nodeName=="LI") {
		  		li.onmouseenter=function() {
			  		this.className += " over";			
		    	}
		  		li.onmouseleave=function() {
		  			this.className = this.className.replace(" over", "");
				}
			}
		}
	}
}

function openPopUpPage(href, id, width, height)
{
	if (href != "") {
		pagePopupWin = window.open(href, 'CMS_page_'+id, 'width='+width+',height='+height+',resizable=yes,menubar=no,toolbar=no,scrollbars=yes,status=no,left=0,top=0');
	}
}

addEvent(window, 'load', function(){
	startMenu();
});
