<!-- Fonction pop-up alway centered-->
function OpenNewWindow(url,w,h,ttl) {
	LeftPosition=(screen.width)?(screen.width-w)/2:100;
	TopPosition=(screen.height)?(screen.height-h)/2:100;
	popwin=window.open(url,ttl,'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes');
	popwin.focus();
}

//**********************************************************************
//
//  Math Functions
//
//**********************************************************************
//Get a random Number
function GetRandomNumber(max){
	return Math.round(max * Math.random());
}

//**********************************************************************
//
//  String Functions
//
//**********************************************************************
//inverse a string
function StringReverse(s){
	var str=new String();
	str="";
	for(var cmpt=str.length-1;cmpt>0;cmpt--){
		str+=s.substr(cmpt,1)
	}
	return str;
}

//Search a substring and replace with the other
var CRLF="\r\n";
function SearchReplace(str,s,r){ 
	if(s==r){ 
		return str; 
	} 
	var mtmp=new String(); 
	mtmp=str; 
	while(mtmp.indexOf(s,0)!=-1){ 
		mtmp=mtmp.replace(s,r); 
	} 
	return mtmp; 
}

//***********************************************************************
//Inverse the checked checkbox
function InverseCheckBox(f){
	for(var cmpt=0;cmpt<f.length;cmpt++){
		if(f[cmpt].type=='checkbox'){
			f[cmpt].checked=!f[cmpt].checked;
			f[cmpt].onclick;
			
		}
	}
}

//inverse all the checkboxes
function CheckAllCheckBox(f,b){
	for(var cmpt=0;cmpt<f.length;cmpt++){
		if(f[cmpt].type=='checkbox'){
			f[cmpt].checked=b;
		}
	}
}

//
var oldtext="";  
function sizetest(f, max_lenght){ 
	var textareastring=f.value; 
	if(textareastring.length <= max_lenght){ 
		oldtext=textareastring;
	}else{ 
		f.value=oldtext; 
		alert("The string maxium size is: "+max_lenght+" chars");
	}
}

//**********************************************************************
//
//  ValidateRadioButton
//
//**********************************************************************
 function checkRadio(obj) {
  for (i=0;i<obj.elements.length;i++) {
   if (obj.elements[i].type == 'radio') {
    var o = obj.elements[obj.elements[i].name];
    var check = false;
    for (x=0;x<o.length;x++) {
     check = (o[x].checked)?true:check;
    }
    if (!check){
		alert('Vous avez un block sans choix effectué')
		 return false;
	}
    i+=x;
   }
  } return true;
 }

//**********************************************************************
//
//  isRadioButtons checked by name
//
//**********************************************************************
function isRadioButtons(elm) {
    for (i=0; i<elm.length; i++) {
        if (elm[i].checked) {
            return true;
        }
    }
  return false;
 }
 
//**********************************************************************
//
//  transform US date to ISO8601 date
//
//**********************************************************************
function UStoISO8601(St) { 
	return St.replace(/([0-9]+)\/([0-9]+)\/([0-9]+)/, "$3-$2-$1") 
}


//**********************************************************************
//
//  Simple Swap Image function
//
//**********************************************************************
function init() {
  if (!document.getElementById) return

  var imgOriginSrc;
  var imgTemp = new Array();
  var imgarr = document.getElementsByTagName('img');
  for (var i = 0; i < imgarr.length; i++) {
    if (imgarr[i].getAttribute('hsrc')) {
        imgTemp[i] = new Image();
        imgTemp[i].src = imgarr[i].getAttribute('hsrc');
        imgarr[i].onmouseover = function() {
            imgOriginSrc = this.getAttribute('src');
            this.setAttribute('src',this.getAttribute('hsrc'))
        }
        imgarr[i].onmouseout = function() {
            this.setAttribute('src',imgOriginSrc)
        }
    }
  }
}
