var xmin;
var ymin;
var xmax;
var ymax;
var encours;
var i=0;

function do_verifpass(){
	if(! sx_verifPass(document.getElementById('tinputUtil').value, document.getElementById('tinputPass').value)) alert("Erreur identification");
	else{
		cacher('contentLogin');
		cacher('contentCreer');
		montrer('contentLrss');
		montrer('headerLrss');
		chdisplay('lrss','none');
		chdisplay('ajoutflux','none');

		montrer('contentPense');
		montrer('headerPense');
		chdisplay('pense','none');
		chdisplay('ajoutpense','none');		
		do_chargerflux();
		do_chargerpense();
		
	}	

}


function do_creecompte(){
	
	if( document.getElementById('tinputUtil2').value && document.getElementById('tinputPass2').value &&
		document.getElementById('tinputSerial').value && document.getElementById('tinputToken').value){
			
			if(sx_creerCompte(document.getElementById('tinputUtil2').value, document.getElementById('tinputPass2').value, document.getElementById('tinputSerial').value, document.getElementById('tinputToken').value )) {
				alert("Votre compte a bien ete cree");
				cacher('contentCreer');
			}
			
			else alert("Ce login est deja utilise");
			
			
					
		}
		
		
		else alert("Vos informations ne sont pas completes");

}

function do_chargerflux(){
	document.getElementById('lrss').innerHTML=sx_chargerFlux();	

}

function do_chargerpense(){
	document.getElementById('pense').innerHTML=sx_chargerPense();	

}

function do_ajouter(){
	if(! sx_ajouter(document.getElementById('url').value)) alert("Impossible de lire le flux");
	else{
		alert("Flux ajoute");
		document.getElementById('url').value='';
		do_chargerflux();
	}
		
}

function do_desactiver(id, actif){
	sx_desactiver(id, actif);
	do_chargerflux();
}

function do_supprimer(id){
        sx_supprimer(id);
        do_chargerflux();
}


function do_ajouterpense(){
	if(! sx_ajouterpense(document.getElementById('heure').value, document.getElementById('minute').value, document.getElementById('message').value )) alert("Message vide");
	else{
		alert("Message ajoute");
		document.getElementById('message').value='';
		do_chargerpense();
	}
		
}

function do_desactiverpense(id, actif){
	sx_desactiverpense(id, actif);
	do_chargerpense();
}

function do_supprimerpense(id){
        sx_supprimerpense(id);
        do_chargerpense();
}

function cacher(div){
	document.getElementById(div).style.display="none";


}

function montrer(div){
        document.getElementById(div).style.display="block";
}

function chdisplay(div, disp){
        document.getElementById(div).style.display=disp;
}

function invdisplay(div){
        if(document.getElementById(div).style.display=="none")  document.getElementById(div).style.display="block";
        else document.getElementById(div).style.display="none";
}

	
function opacite(div, valeur){
		document.getElementById(div).style.filter ="Alpha(Opacity=" + valeur + ")";
		document.getElementById(div).style.opacity=  valeur/100;
}	
	
function apparait(div){

	// Pour IE
	document.getElementById(div).style.filter ="Alpha(Opacity=" + i*10 + ")";

	document.getElementById(div).style.opacity=  i/10;
    document.getElementById(div).style.display="block";

	if(i<10) { i+=1; setTimeout("apparait('" + div + "')", 120); }
	else i=0;
}

function retaille(div, direction, deb, fin){

        if(direction == "w") document.getElementById(div).style.width=deb+"px";
        else document.getElementById(div).style.height=deb+"px";
    document.getElementById(div).style.display="block";

        if(deb<fin)
                if(deb+10<fin) deb+=10;
                else {
                        deb=fin;
                        if(direction == "w") document.getElementById(div).style.width=deb+"px";
                        else document.getElementById(div).style.height=deb+"px";
                }

        else if( deb-10>fin) deb-=10;
        else {
                deb=fin;
                if(direction == "w") document.getElementById(div).style.width=deb+"px";
                else document.getElementById(div).style.height=deb+"px";
        }

        if(deb!=fin) setTimeout("retaille('" + div + "', '" + direction + "', " + deb + ", " + fin + ")", 30);




}	
function dragopac(div){
	 opacite(div, 50);
}

function dragplein(div){
	opacite( div, 100);

}

function eteindre(opac){
	var i;
	var listdiv;
	listdiv = document.getElementsByTagName("div");

	for(i=0; i<listdiv.length; i++)
		opacite(listdiv[i].id, opac)
	 
}

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id, x1, y1, x2, y2) {
  
  var el;
  var x, y;
  encours=id;	
  ymin = y1;
  xmin = x1;
  xmax = x2;
  ymax = y2;
  dragopac(id);  
  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;
  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.
  
  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {
  
if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }
  
  dragplein(encours);
  if(x>xmax || x<xmin)  document.getElementById(encours).style.left=dragObj.elStartLeft + "px";
  if(y>ymax || y<ymin)  document.getElementById(encours).style.top=dragObj.elStartTop + "px";
  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}


