var popImg;

/**************************************/
/* Open POPUP						 */
/**************************************/

function pausecomp(Amount) {
	d = new Date() //today's date
	while (1) {
		mill=new Date() // Date Now
		diff = mill-d //difference in milliseconds
		if( diff > Amount ) {
			break;
		}
	}
}

/**************************************/
/* Funtion For Blink text			 */
/**************************************/
function popupWindow(url) {
	photoPage = window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

function popupWindowFull(url) {
	photoPage = window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,fullscreen=1')
}

/**************************************/
/* ARRAY() Bug IE5					 */
/**************************************/
function Array_push() {
	var A_p = 0
	for (A_p = 0; A_p < arguments.length; A_p++) {
		this[this.length] = arguments[A_p]
	}
	return this.length
}

if (typeof Array.prototype.push == "undefined") {
	Array.prototype.push = Array_push
}


/**************************************/
/* Tabulation automatique IE-Netscape */
/**************************************/
/* Usage:
 * <INPUT TYPE="text" size="2" MAXLENGTH="2" name="DANAIJJ" onKeyUp="return autoTab(this,DANAIMM, 2);">
 * <INPUT TYPE="text" size="2" MAXLENGTH="2" name="DANAIMM">
 */

if (window.Event) /* Pour netscape 4 */ {
    document.captureEvents(Event.KEYPRESS);
}
function autoTab(obj,nextobj,mlength) {
    /*if (autoTab.arguments.length == 2)
      mlength=obj
      a terminer :-D */
    if(!mlength) {
        mlength = obj.size;
    }
    if(obj.value.length>=mlength) {
        obj.value = obj.value.substr(0,mlength);
	      nextobj.focus();
	}
}

/**************************************/
/* Funtion For Blink text			 */
/**************************************/
function popupWindow(url) {
	photoPage = window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

/**********************************************/
/* Funtion for print ElementById CrossBrowser */
/**********************************************/
function getElement(psID, target) {
	//alert("psID : " + psID);
	if(!target){
		target = document;
	}

	if(target.all) {
		return target.all[psID];
	} else {
		return target.getElementById(psID);
	}
}


function getIFrame(byName) {
	for(i=0; i < frames.length; ++i) {
		if(frames[i].name == byName){
			return frames[i];
		}
	}
}

/**************************************/
/* Funtion for print page			 */
/**************************************/

function myPrint() {
	 photoWin = window.open( "", "photo", "width=600,height=450,status,scrollbars,resizable, screenX=20,screenY=40,left=2000,top=4000");
	  
	 photoWin.document.write("<html><head><link href='../css/Print.css' rel='stylesheet' type='text/css'></head><body>"+ document.getElementById("valuePrint").innerHTML + "</body></html>");
	 photoWin.print();
	 photoWin.document.close();	
	 photoWin.close();	
}


/****************************************************/
/* Donne un nombre aléatoirement entre 1000 et 9999 */
/****************************************************/
function get_random(element) {
	var ranNum = Math.round(Math.random()*10000);
	while((ranNum <= 1000) || (ranNum > 9999)){
		ranNum = Math.round(Math.random()*1000);
	}

	element.value = ranNum;
}

/****************************************************/
/* Mise en couleur de la ligne courante 		    */
/****************************************************/
var beforThis;
function rowTableOver(myThis){
	beforThis = myThis.className;
	myThis.className = beforThis + "_over";
}
function rowTableRestor(myThis){
	myThis.className = beforThis
}


/****************************************************/
/* Transforme des milli en hh:mm:ss		    */
/****************************************************/
function tempsChrono(milli) {
  var cnow=new Date();
  	cnow.setTime(milli);
  
  
  var ch=parseInt(cnow.getHours()) - 1;
  var cm=cnow.getMinutes();
  var cs=cnow.getSeconds();
  var cc=parseInt(cnow.getMilliseconds()/10);
  if (cc<10) cc="0"+cc;
  if (cs<10) cs="0"+cs;
  if (cm<10) cm="0"+cm;
  return (ch+":"+cm+":"+cs);
  
}


/*
 * Returns the current documents height.
 */
function pHeight () {
  var h;
  var test1 = document.body.scrollHeight;
  var test2 = document.body.offsetHeight;
  if (test1 > test2) {// all but Explorer Mac
    h = test1;
  } else {// Explorer Mac;
     //would also work in Explorer 6 Strict, Mozilla and Safari
    h = test2;
  }
  return h;
}

/*
 * Returns the current documents width.
 */
function pWidth() {
  var w;
  var test1 = document.body.scrollWidth;
  var test2 = document.body.offsetWidth;
  if (test1 > test2) {// all but Explorer Mac
    w = test1;
  } else {// Explorer Mac;
     //would also work in Explorer 6 Strict, Mozilla and Safari
    w = test2;
  }
  return w;
}

/*
 * Returns the current windows height.
 */
function wHeight() {
  var h;
  if (self.innerHeight) {// all except Explorer
    h = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) {
    // Explorer 6 Strict Mode
    h = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    h = document.body.clientHeight;
  } else {
    h = 0;
  }
  return h;
}

/*
 * Returns the current windows width.
 */
function wWidth() {
  var w;
  if (self.innerWidth) {// all except Explorer
    w = self.innerWidth;
  } else if (document.documentElement && document.documentElement.clientWidth) {
    // Explorer 6 Strict Mode
    w = document.documentElement.clientWidth;
  } else if (document.body) { // other Explorers
    w = document.body.clientWidth;
  } else {
    w = 0;
  }
  return w;
}



/**
 * Transforme une hh:mm:ss en milliseconde
 */
function time2ms(istr) { //take time as string, return second in +-integer
	istr = new String(istr);
	var neg = /^-/i;
	var re = /[+-]*[0]*([1-9])/g;
	var str = new String(istr);
	if(re.test(str)) str = str.replace(re,"$1"); //eliminate leading zeros & signs
	var foo = str.split(":");
	var tsec = new Number(foo[foo.length-1]);
	tsec += new Number(foo[foo.length-2])*60;
	tsec += new Number(foo[foo.length-3])*60*60;
	if(foo.length>=4) tsec += new Number(foo[foo.length-4])*60*60*24;
	tsec = tsec*1000;
	
	if(neg.test(istr)) return(0-tsec); //if negative
	else return(tsec);
}

/* ----------------------------------------------------------------------------------------------------------------*/
/** 
*   INITIALISATION DE l'AJAX 
*		function myPost()
*			ajaxInit(); 
*		
*			var url = "..........."; 
*			var post = "param=" + value ; 
*			
*			httpReq.onreadystatechange = gotStopFormation;  // function de retour
*
*		   	httpReq.open('POST', url, true); //envoi POST 
*		   	httpReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
*		   	httpReq.setRequestHeader("Content-length", post.length); // taille du post envoyé 
*		   	httpReq.setRequestHeader("Connection", "close"); 
*		   	httpReq.send(post); 
*			
*		   	return false;    // rechargement de la page 
*	}
*	
*	function gotStopFormation() { 
*		   if (httpReq.readyState == 4) { 
*		      if (httpReq.status == 200) { 
*		         var postResult = httpReq.responseText; 
*		
*		         window.opener.document.reloadMain.submit();
*					window.close();
*		      } else { 
*		         alert('Un problème est survenu avec la requête.'); 
*		      } 
*		   } 
*		}
**/    

function ajaxInit() {
    if (window.XMLHttpRequest) { // Mozilla, Safari,... 
      	httpReq = new XMLHttpRequest(); 
      	if (httpReq.overrideMimeType) { 
         	httpReq.overrideMimeType('text/xml'); 
      	} 
   	} else if (window.ActiveXObject) { // IE 
      	try { 
         	httpReq = new ActiveXObject("Msxml2.XMLHTTP"); 
      	} catch (e) { 
         	try { 
            	httpReq = new ActiveXObject("Microsoft.XMLHTTP"); 
         	} catch (e) {
         		return false;
         	} 
      	} 
   	} 
   
   if (!httpReq) { 
      return false;  // pas compatible
   } else{
   		return true;  // compatible
   }
} 


/*******************************************/

var mouse_x = 0;
var mouse_y = 0;
var page_x = 0;
var page_y = 0;
   function register_position(){
	document.onmousemove = position;
}

function position(evt){
	if(!evt) evt = window.event;	

	mouse_x = evt.clientX;
	mouse_y = evt.clientY;

	page_x = (document.all)? (evt.x):evt.pageX;
	page_y = (document.all)? (evt.y):evt.pageY;

 //  document.getElementById("coordonnees").innerHTML = "X : " + mouse_x + " "+ page_x + "  Y : " + mouse_y + " - " + page_y;

}
	

function getWidthWindow(){
	if (document.body) 		{
		var larg = (document.body.clientWidth);
	} else	{
		var larg = (window.innerWidth);
	}
	return larg;
 }
 
function getHeightWindow(){
	if (document.body) 		{
		var haut = (document.body.clientHeight);
	} else	{
		var haut = (window.innerHeight);
	}
	return haut;
 }
 
 function getWidthElementMinMarge(idFieldset, marge){
 	try{
 		var widthPX = getElement(idFieldset).style.width;
 		alert("widthPX " + idFieldset + " " + widthPX);
 		widthPX = widthPX.replace("px", "");
		var ret = widthPX - marge;
		return ret;
	}catch(e){
	}
}
 
function maximiseElementInWidth(idFieldset, marge){
 	try{
		var widthMax = getWidthWindow();
		var positionTable = getOffsetPosition(idFieldset,"Left");
		
		getElement(idFieldset).style.width = widthMax - (positionTable + marge);
		var tetete = widthMax - (positionTable + marge);
	}catch(e){
	}
}
 
function maximiseElementInHeight(idFieldset, marge){
 	try{
		var heightMax = getHeightWindow();
		var positionTable = getOffsetPosition(idFieldset,"Top");
		getElement(idFieldset).style.height = heightMax - (positionTable + marge);
	}catch(e){
	}
}	
	
 getOffsetPosition = function(inID, inTYPE) {
 var iVal = 0;
 var oObj = document.getElementById(inID);
 var sType = 'oObj.offset' + inTYPE;
 while (oObj && oObj.tagName != 'BODY') {
  iVal += eval(sType);
  oObj = oObj.offsetParent;
 }
 return iVal;
}
 
function maxWindow() {
	try{
		window.moveTo(0,0);
		
		if (document.all) {
		  top.window.resizeTo(screen.availWidth,screen.availHeight);
		} else if (document.layers||document.getElementById) {
		  if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth)  {
		    top.window.outerHeight = screen.availHeight;
		    top.window.outerWidth = screen.availWidth;
		  }
	 	}
	 }catch(e){
	 }
}

/********************************************/
/* Zone Editable 							*/
/********************************************/
function colorBorder(codeView,idZone){
	if(codeView == 1){
		getElement(idZone).className = "zoneEditableOver";
    } else{
		getElement(idZone).className = "zoneEditable";
    }
}

/********************************************/
/* Change Image 							*/
/********************************************/
function changeSRCImage(myThis,newSrc){
	try{
		myThis.src = newSrc;
	}catch(e){
	}
}