/*****************************
  * Author: Steve Hardie
  * Created:  2008-03-01
  * Version:  1.4
  * Description:
  *   ctxGlobal contains various helper functions and global event handlers.
  *   		
  *
  *
  * CHANGE HISTORY:
  * Date       Changed By        Description
  * ---------- ----------------- -----------------------------------------------
  * 
  ******************************************************************************/

function centerElement(el){
		// Position in Centre
		var x,y;
		var mWidth,mHeight;
		mWidth = $(el).width();
		mHeight = $(el).height();
		

			y = (document.body.offsetHeight / 2) - (mHeight / 2);
			x = (document.body.offsetWidth / 2) - (mWidth / 2);
		
		el.style.top=y;
		el.style.left=x;
	}
	
// Mid Function
function Mid(str, start, len){
    // Make sure start and len are within proper bounds
    if (start < 0 || len < 0) return "";
    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
          iEnd = iLen;
    else
          iEnd = start + len;
    return String(str).substring(start,iEnd);
}




// ****** COOKIES *******
function setCookie(c_name,value,expiredays){
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function getCookie(c_name){
    if (document.cookie.length>0)
      {
      c_start=document.cookie.indexOf(c_name + "=");
      if (c_start!=-1)
        { 
        c_start=c_start + c_name.length+1; 
        c_end=document.cookie.indexOf(";",c_start);
        if (c_end==-1) c_end=document.cookie.length;
        return unescape(document.cookie.substring(c_start,c_end));
        } 
      }
    return "";
}

// sleep returns by calling  callback
function sleep(secs, callback) {
    setTimeout(callback, secs * 1000);
}

   
function findX(obj) { 
    var x = 0; 
    while (obj.offsetParent) { 
        x += obj.offsetLeft 
        obj = obj.offsetParent; 
    } 
    return x;
}
function findY(obj) { 
    var y = 0; 
    while (obj.offsetParent) { 
        y += obj.offsetTop 
        obj = obj.offsetParent; 
    } 
    return y;
}


