var myObj, divid;
var w=0, h=0; //width, height of the div
var divObj;

divid = 'container';

IE5=NN4=NN6=OPA=false
if(navigator.userAgent.toLowerCase().indexOf("opera")+1)OPA=true
else if(document.all)IE5=true
else if(document.layers)NN4=true
else if(document.getElementById)NN6=true


// Opera doesn't have an onresize event so you have to call rePos all the time.
if(OPA) setInterval("rePos()",1000)
function GetPosObj(){
	if(NN4) myObj=document.container
	else if (myObj=document.getElementById(divid) ) myObj = myObj.style;
}

function DoCntCenter(){
    divObj = document.getElementById(divid)
    if (divObj) {
        w = parseInt(divObj.offsetWidth);
        h = parseInt(divObj.offsetHeight);
        if (w>0 && h>0) initialize();
      }
}
function initialize() {
	rePos();
}

function rePos(w, h) {
    if (typeof divObj == 'undefined') {
        divObj = document.getElementById(divid);
   }
    if (typeof divObj != 'undefined' && !(w>0 && h>0)) {
	        w = parseInt(divObj.offsetWidth);
            h = parseInt(divObj.offsetHeight);
       }

   if (typeof divObj != 'undefined') {
          // compute center coordinate
        if( typeof( window.innerWidth ) == 'number' ) {
            //Non-IE
            myWidth = window.innerWidth-30;
            myHeight = window.innerHeight;
          } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth-15;
            myHeight = document.documentElement.clientHeight+15;
          } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
            //IE 4 compatible
            myWidth = document.body.clientWidth;
            myHeight = document.body.clientHeight;
          }
            
	    xc=Math.round((myWidth/2)-(w/2))
	    yc=Math.round((myHeight/2)-(h/2))

	    // reposition div // if the content centered if there is no space for centering the div
	    if (xc<0) xc=0;
	    if (yc<0) yc=0;
    	
    	GetPosObj();
//	    if (myObj) {     
            if(this.NN4) {
                xc = parseInt(myObj.left);
                yc = parseInt(myObj.top);
                myObj.moveTo(xc,yc)
            } 
            else if(OPA){ 
                    myObj.left = xc + "px"
                    myObj.top = yc + "px"
                 }
                else {
                        myObj.left = xc + "px";
                        myObj.top = yc + "px";
                    }
//            myObj.visibility = "visible";
//        }
	}
	
}


/*
var oldf = window.onload;
if (typeof oldf != 'function') {
    window.onload = initialize;
}
else {
     window.onload = function() {
         oldf();
          ();
     }
}
*/
 // call rePos() whenever page is resized
var oldOnres = window.onresize;
if (typeof window.onresize != 'function') {
    window.onresize = rePos;
}
else {
     window.onresize = function() {
         oldOnres();
         rePos();
     }
}

