//makemodifRequest(urlget, variables, divtomodif) => ajax
//
// pop up div
//
//function popup_evo(id, drag_id, position, x, y) => pop up deplaceable
//
//function popup_basic(id, position, x, y) => pop up non deplaceable
//
//function popup_close(id) => close pop id
//
// BARRE anim / pass
//
// Pass_check(refid, passtocheck) => id barre / pass
//
// getBar(refid, refpercent) => id barre / %

// retourne un objet xmlHttpRequest.
// méthode compatible entre tous les navigateurs (IE/Firefox/Opera)

function RequestXMLHTTP(){
	var httpRequest = null;

	if (window.XMLHttpRequest) { // FF,...
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType) {
			httpRequest.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject) { // IE
		try {
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e1) {httpRequest = null;}
		}
	}
	else { // XMLHttpRequest non supporté
		alert('Votre navigateur ne supporte pas les objets XMLHTTPRequest...');
	}
	return httpRequest;
}


function makemodifRequest(urlget, variables, divtomodif) {
	var httpRequest = null;
	var httpRequest = RequestXMLHTTP();
	httpRequest.onreadystatechange = function() { modifContents(httpRequest, divtomodif); };
	httpRequest.open('POST', urlget, true);
	httpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=iso-8859-1");
	httpRequest.send(variables);
//	httpRequest.open('GET', urlget+'?'+variables, true);
//	httpRequest.send(null);
}

function modifContents(httpRequest, divtomodif) {
	if (httpRequest.readyState != 4) {
		document.getElementById(divtomodif).innerHTML = '<img src=http://www.allo-heberge.com/interface/site-blue-electro/loading.gif>';
	}
	if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) {
			document.getElementById(divtomodif).innerHTML = httpRequest.responseText;
		} else {
			document.getElementById(divtomodif).innerHTML = 'Un problème est survenu lors de la requête.';
		}
	}
}

///////////////////////////
//pop up
///////////////////////////

var popup_dragging = false;
var popup_target;
var popup_mouseX;
var popup_mouseY;
var popup_mouseposX;
var popup_mouseposY;
var popup_oldfunction;


// gestion deplacements

function popup_mousedown(e)
{
  var ie = navigator.appName == "Microsoft Internet Explorer";

  popup_mouseposX = ie ? window.event.clientX : e.clientX;
  popup_mouseposY = ie ? window.event.clientY : e.clientY;
}

function popup_mousedown_window(e)
{
  var ie = navigator.appName == "Microsoft Internet Explorer";

  if ( ie && window.event.button != 1) return;
  if (!ie && e.button            != 0) return;

  popup_dragging = true;
  popup_target   = this['target'];
  popup_mouseX   = ie ? window.event.clientX : e.clientX;
  popup_mouseY   = ie ? window.event.clientY : e.clientY;

  if (ie)
       popup_oldfunction = document.onselectstart;
  else popup_oldfunction = document.onmousedown;

  if (ie)
       document.onselectstart = new Function("return false;");
  else document.onmousedown   = new Function("return false;");
}

function popup_mousemove(e)
{
  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);
  var mouseX  = ie ? window.event.clientX : e.clientX;
  var mouseY  = ie ? window.event.clientY : e.clientY;

  if (!popup_dragging) return;

  element.style.left = (element.offsetLeft+mouseX-popup_mouseX)+'px';
  element.style.top  = (element.offsetTop +mouseY-popup_mouseY)+'px';

  popup_mouseX = ie ? window.event.clientX : e.clientX;
  popup_mouseY = ie ? window.event.clientY : e.clientY;
}

function popup_mouseup(e)
{
  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);

  if (!popup_dragging) return;

  popup_dragging = false;

  if (ie)
       document.onselectstart = popup_oldfunction;
  else document.onmousedown   = popup_oldfunction;
}


// close

function popup_close(id)
{
   var element      = document.getElementById(id);
   element.style.display = 'none';
}

//pop up basique

function popup_basic(id, position, x, y)
{
  var element      = document.getElementById(id);

  var width        = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth;
  var height       = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;

  element.style.position = "absolute";
  element.style.display  = "block";

  if (position == "mouse")
  {
    element.style.left = ((document.documentElement.scrollLeft+popup_mouseposX+x)-(document.documentElement.clientWidth-document.body.clientWidth)/2)+'px';
    element.style.top  = (document.documentElement.scrollTop +popup_mouseposY+y)+'px';
  }
  if (position == "manu")
  {
    element.style.left = (document.documentElement.scrollLeft+x)+'px';
    element.style.top  = (document.documentElement.scrollTop +y)+'px';
  }
}

// pop up evoluée

function popup_evo(id, drag_id, position, x, y)
{
  var element      = document.getElementById(id);
  var drag_element = document.getElementById(drag_id);

  var width        = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth;
  var height       = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;

  element.style.position = "absolute";
  element.style.display  = "block";

  if (position == "mouse")
  {
    element.style.left = ((document.documentElement.scrollLeft+popup_mouseposX+x)-(document.documentElement.clientWidth-document.body.clientWidth)/2)+'px';
    element.style.top  = (document.documentElement.scrollTop +popup_mouseposY+y)+'px';
  }
  if (position == "manu")
  {
    element.style.left = (document.documentElement.scrollLeft+x)+'px';
    element.style.top  = (document.documentElement.scrollTop +y)+'px';
  }

  drag_element['target']   = id;
  drag_element.onmousedown = popup_mousedown_window;
}


// events

if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent   ('onmousedown', popup_mousedown);
else document.addEventListener('mousedown', popup_mousedown, false);

if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent   ('onmousemove', popup_mousemove);
else document.addEventListener('mousemove', popup_mousemove, false);

if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent   ('onmouseup', popup_mouseup);
else document.addEventListener('mouseup', popup_mouseup, false);

function Pass_check(refid, passtocheck) {
  var secu = 0;

  if (document.getElementById(passtocheck).value.match(/[a-z]/)) {
    secu++;
  }
  if (document.getElementById(passtocheck).value.match(/\d+/)) {
    secu++;
  }

  if (document.getElementById(passtocheck).value.match(/(\d.*\D)|(\D.*\d)/)) {
    secu+=2;
  }

  if (document.getElementById(passtocheck).value.match(/(.*[0-9].*[0-9].*[0-9])/)) {
    secu++;
  }
  if (document.getElementById(passtocheck).value.match(/(.*[a-z].*[a-z].*[a-z])/)) {
    secu++;
  }

  if (document.getElementById(passtocheck).value.length <= 3) {
  } else if (document.getElementById(passtocheck).value.length <= 5) {
    secu++;
  } else if (document.getElementById(passtocheck).value.length <= 6) {
    secu+=2;
  } else if (document.getElementById(passtocheck).value.length <= 8) {
    secu+=3;
  } else{
    secu+=4;
  }

 secu=secu*10

 if(secu<0)secu=0;
 var colorg = Math.round(secu*5.1);
 var colorr = 500-colorg;
 var colorb = 16;
 if(colorr < 0)colorr=0;
 if(colorr > 255)colorr=255;
 if(colorg < 0)colorg=0;
 if(colorg > 255)colorg=255;

 document.getElementById(refid).style.backgroundColor = "rgb("+ colorr +"," + colorg + "," + colorb + ")";
 document.getElementById(refid).style.width = secu + "%";
}

function getBar(refid, refpercent) {

 var colorr = Math.round(refpercent*5.1);
 var colorg = 500-colorr;
 var colorb = 16;
 if(colorr < 0)colorr=0;
 if(colorr > 255)colorr=255;
 if(colorg < 0)colorg=0;
 if(colorg > 255)colorg=255;

 document.getElementById(refid).style.backgroundColor = "rgb("+ colorr +"," + colorg + "," + colorb + ")";
 document.getElementById(refid).style.width = refpercent + "%";
}
