/* *************************************** */
/* Open new window with specified size     */
/* *************************************** */
function opwin(url, title, width, height, left, top) {
  var w = window.open( url , title , "resizable,scrollbars,width=" + width + ",height=" + height + ",screenX=" + left + ",screenY=" + top + ",left=" + left + ",top=" + top );
  w.focus();
}

/* ************************************************/
/* Open new window resized to the picture bounds  */
/* ************************************************/
function PopupImage(img) {
  titre="";
  w=open("",'image','width=400,height=400,toolbar=no,scrollbars=no,resizable=no');  
  w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>");
  w.document.write("<SCRIPT language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+12,document.images[0].height+30); window.focus();} else { setTimeout('check()',250) } }</"+"SCRIPT>");
  w.document.write("<BODY onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0><IMG src='"+img+"' border=0>");
  w.document.write("");
  w.document.write("</BODY></HTML>");
  w.document.close();
}

function PopupPic(sPicURL) {
window.open( "popuppic.html?"+sPicURL, "Photo",
"resizable=1,HEIGHT=200,WIDTH=200,Left=20%,Top=20%");
}

/* *************************************** */
/* Set window status bar text              */
/* *************************************** */
function winstat(str) {
  if (str == '')
    window.status=' ';
  else
    window.status=str;
  return true;
}

/* *************************************** */
/* Bitwise operators for more than 32 bits */
/* *************************************** */
function Int53(x) {
     this.lo = x >>> 0;
     this.hi = Math.floor(x / 0x100000000);
}

function fromInt53(hi, lo) {
     return 0x100000000 * hi + (lo >>> 0);
}

function and53(x, y) {
     var x53 = new Int53(x);
     var y53 = new Int53(y);
     return fromInt53(x53.hi & y53.hi, x53.lo & y53.lo);
}                    

/* ************************************ */
/* Change color of plannind table cells */
/* ************************************ */
// When no checkbox is needed
function DispTme(tme) {
    for (i = 1; i <= 35; i++) {
      if (and53(tme,Math.pow(2,i)) > 0) {
        if (document.getElementById) {
          document.getElementById("tme" + i).className = "TmeChkbxSel";
        } else if (document.all) {
          document.all["tme" + i].className = "TmeChkbxSel";
        }
      }
    }
}

function DispTme(idAds, tme) {
    for (i = 1; i <= 35; i++) {
      if (and53(tme,Math.pow(2,i)) > 0) {
        if (document.getElementById) {
          document.getElementById("week_" + idAds + "_tme" + i).className = "TmeChkbxSel";
          if (document.getElementById("week_" + idAds + "_chk" + i))
         		document.getElementById("week_" + idAds + "_chk" + i).checked = true;
        } 
        else if (document.all) {
          document.all["week_" + idAds + "tme" + i].className = "TmeChkbxSel";
        }
      }
    }
}

// When a checkbox is clicked
function ChkTme(obj) {
    num = obj.name.substring(3,6);
    if (document.getElementById) {
      if (obj.checked == true)
        document.getElementById("tme" + num).className = "TmeChkbxSel";
      else
        document.getElementById("tme" + num).className = "TmeChkbx";
    }
    else if (document.all) {
      if (obj.checked == true)
        document.all["tme" + num].className = "TmeChkbxSel";
      else
        document.all["tme" + num].className = "TmeChkbx";
    }
}

// When a checkbox is clicked
function ChkTme2(obj, ads_id){
    len = obj.id.length;
    num = obj.id.substring(len-2,len);
    // number < 10 ?
    if (isNaN(num.charAt(0)))
    	num = num.charAt(1);
   
    if (document.getElementById) {
      if (obj.checked == true)
        document.getElementById("week_" + ads_id + "_tme" + num).className = "TmeChkbxSel";
      else
        document.getElementById("week_" + ads_id + "_tme" + num).className = "TmeChkbx";
    }
    else if (document.all) {
      if (obj.checked == true)
        document.all["week_" + ads_id + "_tme" + num].className = "TmeChkbxSel";
      else
        document.all["week_" + ads_id + "_tme" + num].className = "TmeChkbx";
    }
}


/* ******************************************************* */
/* Count the number of characters authorized in a textarea */
/* ******************************************************* */
//a inserer dans le textarea : onkeyup='Nb_Caract(this,10000)' onchange='Nb_Caract(this,10000)' onblur='this.value=this.value.slice(0,10000)'

function Nb_Caract(object, maxi) {
	var cpteur;
	cpteur = object.form.elements["cpt_" + object.name];
	cpteur.value = object.value.length;
	
	if (object.value.length>maxi) 
		cpteur.style.backgroundColor="#FF0000";
	else 
		cpteur.style.backgroundColor="#FFFFFF";
	
	object.focus();
}
