jQuery(function( $ ){
  //borrowed from jQuery easing plugin
  //http://gsgd.co.uk/sandbox/jquery.easing.php
  $.easing.elasout = function(x, t, b, c, d) {
  var s=1.70158;var p=0;var a=c;
  if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
  if (a < Math.abs(c)) { a=c; var s=p/4; }
  else var s = p/(2*Math.PI) * Math.asin (c/a);
  return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
  };
});

function bodySize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  var result = new Array(myWidth,myHeight);
  return result;
}

function evtscroll(evtid)
{
  var obj=document.getElementById(evtid);
    var curtop = obj.offsetTop || 0;
    while (obj = obj.offsetParent) {
             curtop += obj.offsetTop
    }

  var offsetY = Math.round((bodySize()[1]-document.getElementById(evtid).offsetHeight)/2);
  var offsetX = Math.round((bodySize()[0]-800)/2);
  if (offsetY<0) offsetY=0;
  if (offsetX<0) offsetX=0;
  $.scrollTo('#'+evtid,1000, {offset:{ top:-offsetY }});
  /*alert (document.getElementById(evtid).offsetTop);*/
  document.getElementById("fleche").style.top=curtop+"px";
  document.getElementById("fleche").style.display="block";
  document.getElementById("retcal").style.top=curtop+document.getElementById(evtid).offsetHeight+"px";
  /*alert (offsetX + '\r\n'+document.getElementById("retcal").offsetWidth+'\r\n'+ (offsetX+800-document.getElementById("retcal").offsetWidth));*/
  document.getElementById("retcal").style.display="block";
  document.getElementById("retcal").style.left=offsetX+790-document.getElementById("retcal").offsetWidth+"px";
}

function calscroll()
{
    document.getElementById("fleche").style.display="none";
    document.getElementById("retcal").style.display="none";
    $.scrollTo(0,1000);
}

function launchloader(){

  var obj=document.getElementById('loader');

  var offsetY = Math.round((bodySize()[1]-20)/2);
  var offsetX = Math.round((bodySize()[0]-400)/2);
  if (offsetY<0) offsetY=0;
  if (offsetX<0) offsetX=0;
  obj.style.left=offsetX+document.documentElement.scrollLeft+document.body.scrollLeft+"px";
  obj.style.top=offsetY+document.documentElement.scrollTop+document.body.scrollTop+"px";
  obj.style.display="block";
  document.getElementsByName('Submit')[0].disabled=true;
}