function addLoadEvent(func){
  var oldonload = window.onload;
  if(typeof window.onload != 'function'){
    window.onload = func;
  }
  else{
    window.onload = function(){
      oldonload();
      func();
    }
  }
}

function $(strId){
	return document.getElementById(strId);
}


function getWindowSize(){
  windowWidth =  window.innerWidth;
  windowWidth = (windowWidth)? windowWidth : document.documentElement.clientWidth;
  windowWidth = (windowWidth)? windowWidth : document.body.clientWidth;
  windowHeight =  window.innerHeight;
  windowHeight = (windowHeight)? windowHeight: document.documentElement.clientHeight;
  windowHeight = (windowHeight)? windowHeight: document.body.clientHeight;  
  return {'width': windowWidth, 'height': windowHeight};
}

function getCursor(e) {
  e = e || window.event;
  return {"x": e.clientX, "y": e.clientY};
}

// The Change Class
function changeClass(context,el) {
  var tag = el.tagName;
  var clas = el.className; 
  var link = $(context).getElementsByTagName(tag);
  for (i=0; i<link.length; i++) {
    if (link[i].className == clas+'_on') link[i].className  = clas;
    el.className = clas+'_on';
  }
}

function setOpacity(obj,xOpacity){
  var zOpacity = Math.round(xOpacity*100)/100;
  zOpacity = (zOpacity > 1)?0.99:zOpacity;
  obj.style.opacity = zOpacity;
	obj.style.MozOpacity = zOpacity;
	obj.style.KHTMLOpacity = zOpacity;
	obj.style.filter = 'alpha(opacity=' + (xOpacity*100) + ')';
};


function placeDoc(doc){  
  var photo = $(doc);
  var photoBox = $('photo_box');
  var viewPart = getSize();
  if(viewPart>photo.offsetHeight){// Si la fenetre est grande pour la photo
    if(viewPart<520){
      photoBox.style.height = viewPart+'px';     
    }else{
      photoBox.style.height = '524px';
      photo.style.top = '0';
    }             
  }else{
    photoBox.style.height = photo.offsetHeight+4+'px';
    photo.style.top = '0';
  }
}

function ajaxRequest(url, variables, action){

  var objXhr = false;

  if (window.XMLHttpRequest){objXhr = new XMLHttpRequest();}
   
  else if (window.ActiveXObject) {
    var ieXHR = new Array(
    "Msxml2.XMLHTTP.7.0","Msxml2.XMLHTTP.6.0",
    "Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0",
    "MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP");
    for (var i=0; i<ieXHR.length; i++) {
			try{
				objXhr = new ActiveXObject(ieXHR[i]);
				break;
			}catch(e){}
		}
  } 
    
	if(objXhr) {
    
    if(variables==null){objXhr.open("GET",url,true);}

    if(variables!=null){	 
      objXhr.open("POST",url,true);
      objXhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');	
    }
    
    if(action){
		  objXhr.onreadystatechange = function () {
			  if (objXhr.readyState == 4) {
				  if (objXhr.status == 200) {
            action(objXhr);
					}
				}
		  }
    }
    objXhr.send(variables);
	}else{return false}
}



