messageObj = new DHTML_modalMessage();	// We only create one object of this class
messageObj.setShadowOffset(5);	// Large shadow

addHandler(window, "resize", setBodyHeightToContentHeight);
addHandler(window, "scroll", setBodyHeightToContentHeight);

function displayMessage(url,per)
{

	if(per == 'login') {
		top1 = 60;
		left1 = 0;
		right1 = 20;
	} else if(per == 'uploadimg') {
		left1 = scrollLeft() + Math.ceil((getWindowWidth() - 700)/2);
	    top1 = scrollTop() + Math.ceil((getWindowHeight() - 550)/2);
	    if(getWindowHeight() < 550) top1 = 0;
		right1 = 0;
	} else {
        left1 = scrollLeft() + Math.ceil((getWindowWidth() - 400)/2);
        top1 = scrollTop() + Math.ceil((getWindowHeight() - 550)/2);
        if(getWindowHeight() < 550) top1 = 0;
		right1 = 0;
//       alert(right1);
	}


	messageObj.setSource(url);
	messageObj.setCssClassMessageBox(false);
	messageObj.setSize(1,1); // это размер первого окошка когда мы инклуд делаем :)
	messageObj.setPosition(top1,left1,right1);
	messageObj.setShadowDivVisible(false);	// Enable shadow for these boxes
	messageObj.display();

	if(per == 'login') {
		messageObj.setSize(1,1);
	} else if(per == 'uploadimg') {
		messageObj.setSize(700,350);
	} else {
		messageObj.setSize(300,350);
	}
//document.scroll(0,0);

}

function setBodyHeightToContentHeight() {
	if (messageObj.divs_content == null)
	{
	  return;
	}
	if(messageObj.right  == 0) {
		width = intval(messageObj.divs_content.style.width);
		messageObj.divs_content.style.left = scrollLeft() + Math.ceil((getWindowWidth() - width)/2)  + "px";
		messageObj.divs_content.style.top = scrollTop() + Math.ceil((getWindowHeight() - 550)/2) + "px";
	    if(getWindowHeight() < 550) messageObj.divs_content.style.top = 0;
	} else {
	   messageObj.divs_content.style.left = getWindowWidth() - 410 - 25 + "px";
	   messageObj.divs_content.style.top = 60 + "px";
	}
}
// Функция для добавления обработчика событий
function addHandler(object, event, handler, useCapture) {
    if (object.addEventListener) {
        object.addEventListener(event, handler, useCapture ? useCapture : false);
    } else if (object.attachEvent) {
        object.attachEvent('on' + event, handler);
    } else alert("Add handler is not supported");
}

function closeMessage()
{
	messageObj.close();
}

function getRealLeftPos(el) {iPos = 0; while (el!=null) {iPos += el.offsetLeft;el = el.offsetParent;}return iPos;}
function getRealTopPos(el) {iPos = 0; while (el!=null) {iPos += el.offsetTop;el = el.offsetParent;}return iPos;}
function scrollTop () {if (window.innerHeight) return window.pageYOffset; if (document.documentElement && document.documentElement.scrollTop) return document.documentElement.scrollTop; if (document.body) return document.body.scrollTop;}
function scrollLeft () {if (window.innerWidth) return window.pageXOffset; if (document.documentElement && document.documentElement.scrollLeft)return document.documentElement.scrollLeft;if (document.body) return document.body.scrollLeft;}

function getWindowWidth(){
    	var bodyWidth = document.documentElement.clientWidth;
		var bodyWidth;
		if (self.innerWidth){ // all except Explorer
		   bodyWidth = self.innerWidth;
		}  else if (document.documentElement && document.documentElement.clientWidth) {
		   // Explorer 6 Strict Mode
		   bodyWidth = document.documentElement.clientWidth;
		} else if (document.body) {// other Explorers
		   bodyWidth = document.body.clientWidth;
		}
  return bodyWidth;
}

function getWindowHeight(){
    	var bodyHeight = document.documentElement.clientHeight;
		var bodyHeight;
		if (self.innerHeight){ // all except Explorer
		   bodyHeight = self.innerHeight;
		}  else if (document.documentElement && document.documentElement.clientHeight) {
		   // Explorer 6 Strict Mode
		   bodyHeight = document.documentElement.clientHeight;
		} else if (document.body) {// other Explorers
		   bodyHeight = document.body.clientHeight;
		}
  return bodyHeight;
}

function getDocumentHeight(){var scrollHeight=-1,windowHeight=-1,bodyHeight=-1;var marginTop=0;var marginBottom=0;var mode=document.compatMode;if((mode||isIE)&&!isOpera){switch(mode){case'CSS1Compat':scrollHeight=((window.innerHeight&&window.scrollMaxY)?window.innerHeight+window.scrollMaxY:-1);windowHeight=[document.documentElement.clientHeight,self.innerHeight||-1].sort(function(a,b){return(a-b);})[1];bodyHeight=document.body.offsetHeight+marginTop+marginBottom;break;default:scrollHeight=document.body.scrollHeight;bodyHeight=document.body.clientHeight;}}else{scrollHeight=document.documentElement.scrollHeight;windowHeight=self.innerHeight;bodyHeight=document.documentElement.clientHeight;}var h=[scrollHeight,windowHeight,bodyHeight].sort(function(a,b){return(a-b);});return h[2];}
function getDocumentWidth(){var docWidth=-1,bodyWidth=-1,winWidth=-1;var marginRight=0;var marginLeft=0;var mode=document.compatMode;if(mode||isIE){switch(mode){case'CSS1Compat':docWidth=document.documentElement.clientWidth;bodyWidth=document.body.offsetWidth+marginLeft+marginRight;winWidth=self.innerWidth||-1;break;default:bodyWidth=document.body.clientWidth;winWidth=document.body.scrollWidth;break;}}else{docWidth=document.documentElement.clientWidth;bodyWidth=document.body.offsetWidth+marginLeft+marginRight;winWidth=self.innerWidth;}var w=[docWidth,bodyWidth,winWidth].sort(function(a,b){return(a-b);});return w[2];}

function intval( mixed_var, base ) {    // Get the integer value of a variable
  var tmp;
  if( typeof( mixed_var ) == 'string' ){
     tmp = parseInt(mixed_var);
     if(isNaN(tmp)){
        return 0;
    } else {
      return tmp.toString(base || 10);
    }
  } else if( typeof( mixed_var ) == 'number' ){
     return Math.floor(mixed_var);
  } else{
     return 0;
  }
}

