// JavaScript Document

function create_CloseWndButton(parent_id){
var newElmnt=document.createElement("DIV")
var NewElementID=parent_id+'_Close'
newElmnt.id=NewElementID
document.getElementById(parent_id).appendChild(newElmnt)
document.getElementById(NewElementID).innerHTML='<img src="/img/close.png" title="Close window" onClick="close_wnd(\''+parent_id+'\')"/>'
//
document.getElementById(NewElementID).style.top='2px'
document.getElementById(NewElementID).style.right='2px';
document.getElementById(NewElementID).style.width='100%'
document.getElementById(NewElementID).style.text_align='right'
document.getElementById(NewElementID).style.height='15px'
document.getElementById(NewElementID).style.border='none'
document.getElementById(NewElementID).style.position='relative';
document.getElementById(NewElementID).style.float='right'
document.getElementById(NewElementID).style.zIndex='10'
}

document.getViewportWidth = function()
   {
    return (document.compatMode || navigator.isIE) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientWidth : document.body.clientWidth : (document.parentWindow || document.defaultView).innerWidth;
  };

document.getViewportHeight = function()
   {
    return ((document.compatMode || navigator.isIE) && !navigator.isOpera) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientHeight : document.body.clientHeight : (document.parentWindow || document.defaultView).innerHeight;
  };


function wndw_show(W,H,div_name)  {
// выводит <div>? как центрированное окно с position=fixed

	document.getElementById(div_name).style.visibility='visible';
 	document.getElementById(div_name).style.top=(document.getViewportHeight()-H)/2 + 'px';
 	document.getElementById(div_name).style.left=(document.getViewportWidth()-W)/2 + 'px';
  	//document.getElementById(div_name).style.width=W + 'px';
  	//document.getElementById(div_name).style.height=H + 'px';
	if (! document.getElementById(div_name+'_Close')) create_CloseWndButton(div_name)
}

function wndw_msg(W, H, msg)
{
// выводит <div>? как центрированное окно с position=fixed
    var WMSG=new String();
	var wmsg_id='wndw_msg'
	WMSG=msg;

    try{
		getElementById(wmsg_id)
	}
	catch(e){
		var wmsg_elmnt=document.createElement("DIV")
			wmsg_elmnt.id=wmsg_id
			document.body.appendChild(wmsg_elmnt)


		document.getElementById(wmsg_id).style.visibility='hidden';
 	document.getElementById(wmsg_id).style.top=(document.getViewportHeight()-H)/2 + 'px';
 	document.getElementById(wmsg_id).style.left=(document.getViewportWidth()-W)/2 + 'px';
  	document.getElementById(wmsg_id).style.width=W + 'px';
  	document.getElementById(wmsg_id).style.height=H + 'px';
  	document.getElementById(wmsg_id).style.position='fixed'
  	document.getElementById(wmsg_id).style.background='#FFFF00'
    document.getElementById(wmsg_id).style.border='solid 1px #DDDDDD'
 //   document.getElementById(wmsg_id).style.padding='0px'
	    document.getElementById(wmsg_id).style.zIndex='8'


	b=document.createElement("DIV")
     var b_name='b_close'
    	b.id = b_name
       document.getElementById(wmsg_id).appendChild(b)

		document.getElementById(b_name).style.width='100%'
		document.getElementById(b_name).style.height='10px'
		document.getElementById(b_name).style.border='none'
        document.getElementById(b_name).style.zIndex='10'
        document.getElementById(b_name).style.textAlign='right'


  		document.getElementById(b_name).innerHTML='<img src="/img/close.png" title="Close window" onClick="close_wndw_msg()"/>'

  		t=document.createElement("p")
  		var t_name='ttt'
  		t.id=t_name
  		document.getElementById(wmsg_id).appendChild(t)
		document.getElementById(t_name).style.width=(W-6)+'px'
		document.getElementById(t_name).style.height='100%';
	  	document.getElementById(t_name).style.background='#999999'
        document.getElementById(t_name).style.overflow='auto'
        document.getElementById(t_name).style.color='#FFFF00'
        document.getElementById(t_name).style.padding='3px'

	}

     document.getElementById(t_name).innerHTML=msg
     document.getElementById(t_name).style.overflow='auto'
	document.getElementById(wmsg_id).style.visibility='visible';

}


function close_wnd(div_name) {
	// прячет окно

	document.getElementById(div_name).style.visibility='hidden';

}

function close_wndw_msg() {
    document.getElementById('wndw_msg').style.visibility='hidden'
}


function self_close_msg(msg){
	var MSG=new String();
	var msg_id='SC_msg'
	MSG=msg;


	// добавляем тег вывода

	try{
		getElementById(msg_id)
	}
	catch(e){
		var msg_elmnt=document.createElement("DIV")
			msg_elmnt.id=msg_id
			document.body.appendChild(msg_elmnt)
//			alert ('Создали элемент')
	}

        T=document.getElementById(msg_id)
       W=200
       var H
       H=parseInt(MSG.length*10)/W +1
       H=H ? H*17 : 25

        T.style.background='#FFFF00'
        T.style.border='#f00 thin solid'
        T.style.top=(document.getViewportHeight()-H)/2 + 'px';
			T.style.left=(document.getViewportWidth()-W)/2 + 'px';
			T.style.visibility='visible';
			T.style.position='absolute'
			T.style.zindex=20
			T.style.width='200px';
			T.style.height=H.toString()+'px'
		T.innerHTML=MSG
		T.style.opacity='1'
		setTimeout('T.style.opacity="0.9"',300)
		setTimeout('T.style.opacity="0.8"',600)
		setTimeout('T.style.opacity="0.7"',900)
		setTimeout('T.style.opacity="0.6"',1200)
		setTimeout('T.style.opacity="0.5"',1500)
		setTimeout('T.style.opacity="0.4"',1800)
		setTimeout('T.style.opacity="0.3"',2100)
		setTimeout('T.style.opacity="0.2"',2400)
		setTimeout('T.style.opacity="0.1"',2700)
        setTimeout('T.style.visibility="hidden"',3000)

}


