var xhr = null;
function getXhr(){
	if(window.XMLHttpRequest) // Firefox
		xhr = new XMLHttpRequest();
	else if(window.ActiveXObject){ // Internet Explorer
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
else { 
		alert("XMLHTTPRequest is not available");
		xhr = false;
	}
}

function change_province(){
	getXhr();

	xhr.onreadystatechange = function(){

		if(xhr.readyState == 4 && xhr.status == 200){
			theselect = xhr.responseText;
			document.getElementById('province').innerHTML = theselect;
		}
	}
	xhr.open("POST","includes/employer.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	sel = document.getElementById('i_id_country');
	id_country = sel.options[sel.selectedIndex].value;
	xhr.send("id_country="+id_country);
}

function change_city(){
	getXhr();

	xhr.onreadystatechange = function(){

		if(xhr.readyState == 4 && xhr.status == 200){
			theselect = xhr.responseText;
			document.getElementById('city').innerHTML = theselect;
		}
	}
	xhr.open("POST","includes/employer.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	sel = document.getElementById('i_id_province');
	id_province = sel.options[sel.selectedIndex].value;
	xhr.send("id_province="+id_province);
}

function change_etat(){
	document.getElementById("change_form").value="1";
}
function check_change(page_suiv){
	if (document.getElementById("change_form").value=="1")
	{
	  	if (confirm("Are you sure you do not want to save changes before closing?"))
	  	//if (confirm("Etes-vous bien sûr de vouloir quitter la page avant de sauvegarder ?"))
	  	{		
			document.location.href=page_suiv;
		}	  
	}
	else document.location.href=page_suiv;
}

/////////////  POPUP
var newWin = null;
function closeWin(){
	if (newWin != null){
	if(!newWin.closed)
		newWin.close();
	}
}

function ouvre(strURL,strType,strWidth,strHeight) {
	closeWin();
	var strOptions="";
	if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth;
	if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
	if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
	newWin = window.open(strURL, 'newWin', strOptions);
	win_x=(screen.width/2)-(strWidth/2);
    win_y=(screen.height/2)-(strHeight/2);
    newWin.moveTo(win_x,win_y);
	newWin.focus();
}
/////////////  FIN POPUP

//	Return true if the parameter empty
function isEmpty(tmp_str)
{
	var new_msg = false;
	var inputStr = "";
	inputStr = ""+tmp_str;
    if (inputStr.length  <= 0)
	{
	    new_msg = true;
	}
	return (new_msg);
}

//  Return true if the parameter is an Integer
function isInteger(tmp_str)
{
  var new_msg = true;
  inputStr = tmp_str.toString();
  for (var i = 0; i < inputStr.length; i++)
  {
    var oneChar = inputStr.charAt(i);
    if ((oneChar < "0" || oneChar > "9"))
    {
      new_msg = false;
    }
  }
  return (new_msg);
}

//  Return true if the parameter is a Number
function isNumber(tmp_str)
{
  var new_msg = true;
  inputStr = tmp_str.toString();
  for (var i = 0; i < inputStr.length; i++)
  {
    var oneChar = inputStr.charAt(i);
    if ((oneChar < "0" || oneChar > "9") && oneChar!=".")
    {
      new_msg = false;
    }
  }
  if (inputStr.charAt(inputStr.length-1)==".") return (false);
  return (new_msg);
}

//  Return true if the first parameter has a size of the second parameter
function verif_length(tmp_str,longueur)
{
  var inputStr = "";
  inputStr = ""+tmp_str;
    if (inputStr.length  <= longueur)
	{
      return(true);
	}
	else
	{
		return (false);
	
	}
}

//Return true if the parameter is an English date (aaaa/mm/jj)
function isDate_fr(tmp_str)
{
     var new_msg = true;
     inputStr = tmp_str.toString();
     if (inputStr.length != 10)
     {
          new_msg = false;
     }
     for (var i = 0; i < inputStr.length; i++)
     {
          var oneChar = inputStr.charAt(i);
          if (i == 2 || i == 5)
          {
               if (oneChar == "/"){}
               else
               {
               		new_msg = false;
               }
          }
          else
          {
               if ((oneChar < "0" || oneChar > "9"))
               {
               		new_msg = false;
               }
          }
     }
     if ((inputStr.substr(0,2) > "0") && (inputStr.substr(0,2) < "32") && (inputStr.substr(3,2) > "0") && (inputStr.substr(3,2) < "13")){}
     else
     {
          new_msg = false;
     }
     return (new_msg);
}


//Return true if the parameter is a French date (jj/mm/aaaa)
function isDate_en(tmp_str)
{
     var new_msg = true;
     inputStr = tmp_str.toString();
     
     if (inputStr.length != 10)
     {
          new_msg = false;
     }
     for (var i = 0; i < inputStr.length; i++)
     {
          var oneChar = inputStr.charAt(i);
          if (i == 4 || i == 7)
          {
               if (oneChar == "/"){}
               else
               {
               		new_msg = false;
               }
          }
          else
          {
               if ((oneChar < "0" || oneChar > "9"))
               {
                	new_msg = false;
               }
          }
     }
     if ((inputStr.substr(8,2) > "0") && (inputStr.substr(8,2) < "32") && (inputStr.substr(5,2) > "0") && (inputStr.substr(5,2) < "13")){}
     else
     {
          new_msg = false;
     }
     return (new_msg);
}

// Return true if the radio button is checked
function isRadioChecked(l_radio)
{
    var length_radio;
    var returnIsNoChecked;
    length_radio = l_radio.length;
    returnIsNoChecked = false;
    for(i=0;i<length_radio;i++)
    {
        if(l_radio[i].checked == true)
        {
            returnIsNoChecked = true;
        }
    }
    return returnIsNoChecked;
}

// Return the value of the checked radio button
function valueRadioChecked(l_radio)
{
    var length_radio;
    var returnValue = "999";
    length_radio = l_radio.length;
    for(i=0;i<length_radio;i++)
    {
        if(l_radio[i].checked == true)
        {
            returnValue = l_radio[i].value;
        }
    }
    return returnValue;
}

// Return true if the checkbox is checked
function isCheckboxChecked(l_chbox)
{
    var returnIsNoChecked;
    returnIsNoChecked = false;
    if(l_chbox.checked == true)
     {
          returnIsNoChecked = true;
     }
    return returnIsNoChecked;
}

// Return true if the parameter is an valid email
function isEmail(tmp_str)
{
     var new_msg = true;
     var int_pos = 0;
     var inputStr = tmp_str.toString();
     int_pos = inputStr.indexOf("@",int_pos);
     if((int_pos > 0) && (inputStr.indexOf(".",int_pos) > 1+int_pos))
     {
          for (var i = 0; i < inputStr.length; i++)
          {
               var oneChar = inputStr.charAt(i);	
               if (ascEmail(oneChar))
               {
               	new_msg = false;
               }
          }
     }
     else
     {
          new_msg = false;
     }
     return (new_msg);
}


// Return false if the character parameter is valid for an email
function ascEmail(each_char)
{
     var is_ok = true;
     var n = 0;
     var char_str = charSetStrEmail();
     for (i = 0; i < char_str.length; i++)
     {
          if (each_char == char_str.substring(i, i+1))
          {
               is_ok = false;
               break;
          }
     }
     return (is_ok);
}

// Return a string of valid character for an email
function charSetStrEmail()
{
     var str;
     str = "'.0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ_-abcdefghijklmnopqrstuvwxyz";
     return str;
}


function VerifyNumeric( nbr ) {
	var car = nbr.charAt( 0 ) ;
	var sep = 0 ;

	for( var i = 0 ; i < nbr.length ; i++ ) {
		car = nbr.charAt(i) ;
		if( ( car < '0' || car > '9' ) && car != '.' && car != '+' && car != '-' )
			return false ;
		if( ( car == '+' || car == '-' ) && i )
			return false ;
		if( car == '.' )
			sep++ ;
	}

	if( sep > 1 )
		return false ;

	return true ; 
}


function VerifyFormatNumeric (nombre, nb_entier, nb_flottant){
	var tab = new Array();
	
	if (!VerifyNumeric(nombre)) {
		return false;
	}
	var tab = nombre.split(".");

	if (tab[0].length > nb_entier) {
		return false;
	}

	if (tab[1] != null) {	
		if (tab[1].length > nb_flottant) {
			return false;
		}
	}
	return true;
}

function VerifyAlphaNumeric(each_char)
{
     var ChaineAVerifier = each_char.toUpperCase();
     var is_ok = true;
     var n = 0;
     var j;
     
     var CaracteresPossibles = "',.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-ÀÁÂÃÆÇÈÉËÊÌÎÍÏÑÒÓÕÔÖÙÛÚÜ ";
     for (j = 0; j < ChaineAVerifier.length; j++) {
	CaractereAVerifier = ChaineAVerifier.charAt(j) ;
	if (CaracteresPossibles.search(CaractereAVerifier) == -1) {
		is_ok = false;
		break;
	}  
     }
     return (is_ok);
}

function VerifyAlphabetic( nbr ) {
	var car = nbr.charAt( 0 ) ;
	var sep = 0 ;

	for( var i = 0 ; i < nbr.length ; i++ ) {
		car = nbr.charAt(i) ;
		if(  car < 'A' || car > 'z' )
			return false ;
	}

	return true ; 
}

function VerifyInteger( nbr ) {
	var car = nbr.charAt( 0 ) ;
	var sep = 0 ;

	for( var i = 0 ; i < nbr.length ; i++ ) {
		car = nbr.charAt(i) ;
		if( car < '0' || car > '9' )
			return false ;
	}

	if( sep > 1 )
		return false ;

	return true ; 
}
