//Global utils script
var last = null;
function switchEvents(id){
	if (last != null) {
		document.getElementById(last).style.display = 'none';
	}
	last = id;
	document.getElementById(id).style.display = 'block';
}
var lastTab = null;
var lastInBox = null;

function switchTab(inBoxId,TabId){
	if (lastInBox != null) {
		document.getElementById(lastInBox).style.display = 'none';
	}
	lastInBox = inBoxId;
	document.getElementById(inBoxId).style.display = 'block';

	if (lastTab != null) {
		document.getElementById(lastTab).style.color = '#333';
	}
	lastTab = TabId;
	document.getElementById(TabId).style.color = '#a00';
}
function hideID(id){
	document.getElementById(id).style.display = 'none';
}
function showID(id){
	document.getElementById(id).style.display = 'block';
}
function insertEventAdress(_name,_street,_locality,_region,_pcode,_info){
	document.forms['form_event']['__DIREventData_locationname'].value = _name;
	document.forms['form_event']['__DIREventData_locationstreet'].value = _street;
	document.forms['form_event']['__DIREventData_locationlocality'].value = _locality;
	document.forms['form_event']['__DIREventData_locationregion'].value = _region;
	document.forms['form_event']['__DIREventData_locationpcode'].value = _pcode;
// 	document.forms['event']['__DIREventData_locationinfo'].value = _info;
}

var startTime = new Array(0,0,0);
var endTime = new Array(0,0,0);
var timerLimits = new Array(23,59,59);
function setStartTime(hrs,min,sec){
	startTime[0] = hrs;
	startTime[1] = min;
	startTime[2] = sec;
}

function setEndTime(hrs,min,sec){
	endTime[0] = hrs;
	endTime[1] = min;
	endTime[2] = sec;
}
function incTimer(timer,part){
	if(timer == 'end'){
		if(endTime[part] == timerLimits[part]){
			endTime[part] = 0;
		}else{
			endTime[part] = endTime[part] + 1;
		}
	}
	if(timer == 'start'){
		if(startTime[part] == timerLimits[part]){
			startTime[part] = 0;
		}else{
			startTime[part] = startTime[part] + 1;
		}
	}
}
function decTimer(timer,part){
	if(timer == 'end'){
		if(endTime[part] == 0){
			endTime[part] = timerLimits[part];
		}else{
			endTime[part] = endTime[part] - 1;
		}
	}
	if(timer == 'start'){
		if(startTime[part] == 0){
			startTime[part] = timerLimits[part];
		}else{
			startTime[part] = startTime[part] - 1;
		}
	}
}
function setElementTimer(formulaire,element,timer){
	if(timer == 'end'){
		hrs = endTime[0];
		if(hrs < 10){
			hrs='0'+hrs;
		}
		min = endTime[1];
		if(min < 10){
			min='0'+min;
		}
		sec = endTime[2];
		if(sec < 10){
			sec='0'+sec;
		}
		timerString = hrs+':'+min+':'+sec;
		document.forms[formulaire][element].value = timerString;
	}
	if(timer == 'start'){
		hrs = startTime[0];
		if(hrs < 10){
			hrs='0'+hrs;
		}
		min = startTime[1];
		if(min < 10){
			min='0'+min;
		}
		sec = startTime[2];
		if(sec < 10){
			sec='0'+sec;
		}
		timerString = hrs+':'+min+':'+sec;
		document.forms[formulaire][element].value = timerString;
	}
}
var NS =false;
var IE = false;

if (window.ActiveXObject){ //ActiveX
	IE=true;
}
if(window.XMLHttpRequest){ //GEKO
	NS=true;
}


if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
var xp = 0;
var yp = 0;
function getMouseXY(e) {

	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX+ document.body.scrollLeft;
		tempY = event.clientY+ document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}
	return true;
}

function moveOut(id){
    var object = document.getElementById(id).style;
	object.top = '-1000px';
	object.left ='-1000px';

}
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;;
        }

    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }

}
//Action check! ask realy act?
function didYouMean(url,what){
	var userSaid = confirm(what)
	if(userSaid == true){
		window.location=url;
		alert("L'opération s'est terminée avec succès!");
	}else{
		alert("Opération annulé!");
	}
}
//checkSwitch Functions
function checkSwitch(conteneur,element,formulaire){
	if(document.forms[formulaire][element].checked  ==  true ){
		document.getElementById(conteneur).style.display = 'block';
	}else{
		document.getElementById(conteneur).style.display = 'none';
	}
}
//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function showPopUpNote(id){
	document.getElementById(id).style.top = tempY+-40+'px';
	document.getElementById(id).style.left = tempX+30+'px';
	opacity(id, 0, 90, 1000);
	
}

function hidePopUpNote(id){
	opacity(id, 90, 0, 500);
	setTimeout("moveOut('"+id+"')",100);
}

