var bodyDir='ltr'; var antiDir='rtl'; var winScrollX=0; var winScrollY=0; var winWidth=0; var winHeight=0;
if(document.body && document.body.dir){bodyDir=document.body.dir;}
else if(document.getElementById('winBox.js')){bodyDir=document.getElementById('winBox.js').getAttribute('direction');}
if(bodyDir =='rtl'){antiDir='ltr';}

document.write('<div id="hideAllDIV" style="display: none; position: absolute; top: 0px; left: 0px; padding:0; margin:0; background: #000; opacity: 0.4; -moz-opacity: 0.4; -khtml-opacity: 0.4; filter: alpha(opacity=40); width: 100%; height: 100%;  z-index: 5555; overflow:hidden;"></div>');
//document.write('<div id="winBox" style="direction: '+bodyDir+'; display: none; position: absolute; background-color: #053F85; color: #333; border: 1px solid #636D61; z-index: 9999;"><table style="float:bottom;" border="0"><tr><td id="winBoxTitle" style="border: 0px;"></td><td style="border: 1px solid #000; background-color:#fff; padding:2px; cursor: pointer; width: 10px;" onclick="hideWinBox();">x</td></tr></table><div style="padding:0px 0px 0px 0px; height: 100%;" id="winBoxMain"></div></div>');
//document.write('<div id="winBox" style="direction: '+bodyDir+'; text-align:justify; display: none; position: absolute; background-color: #053F85; color: #333; border: 1px solid #636D61; z-index: 9999;"><table border="0" cellpadding="0" cellspacing="0"><tr><td id="winBoxTitle" style="padding:0px 10px 0px 10px;"> </td><td dir="'+antiDir+'"><p style="border: 1px solid #000; background-color:#fff; padding:2px; cursor: pointer; width: 10px;" onclick="hideWinBox();">x</p></td></tr><tr><td colspan="2"><div style="padding: 0px 10px 10px 10px;" id="winBoxMain"></div></td></tr></table></div>');
document.write('<div id="winBox" style="direction: '+bodyDir+'; text-align:justify; display: none; position: absolute; border: 0px ; z-index: 9999;"></div>');
var hideAllDIV=document.getElementById('hideAllDIV');
var winBox=document.getElementById('winBox');

function getWinBoxTitle(){
	return document.getElementById('winBoxTitle');
}
function getWinBoxContent(){
	//return document.getElementById('winBoxMain');
	return winBox;
}
function showWinBox(autoclose){
	if(navigator.appVersion.indexOf("MSIE")!=-1){setSelectsVisibility('hidden');}
	
	if(autoclose){hideAllDIV.onclick=new Function("hideWinBox();");}
	else{hideAllDIV.onclick=new Function("return false;");}
	
	getScrollXY();
	prepareBack('100%', 'hidden');
	
	getWinSize();
	
	hideAllDIV.style.display='block';
	hideAllDIV.style.width=winWidth+winScrollX+'px';
	hideAllDIV.style.height=winHeight+winScrollY+'px';
	winBox.style.display='block';
	winBox_W=getWinBoxContent().offsetWidth;
	if(winBox_W > winWidth-30){winBox_W=winWidth - 40;}
	winBox.style.width=winBox_W+'px';
	winBox.style.left= parseInt((winWidth-winBox.offsetWidth)/2)+'px';
	winBox.style.top='10px';
	winBox.focus();
	
	setScrollXY(0, 0);
}
function hideWinBox(refreshMe){
	prepareBack("auto", "auto", '1');
	if (refreshMe) parent.window.location.href = parent.window.location.href;
	if(navigator.appVersion.indexOf("MSIE")!=-1){setSelectsVisibility('visible');}
	parent.document.getElementById('hideAllDIV').style.display='none';
	parent.document.getElementById('winBox').style.display='none';
	var ifm = parent.document.getElementById('winBox').getElementsByTagName("iframe"); 
	for (var i = 0; i < ifm.length; i++){
		parent.document.getElementById('winBox').removeChild(ifm[i]);
	}
	//alert(winBox.style.display);
	//while (winBox.childNodes[0]){
	//	winBox.removeChild(winBox.childNodes[0]);
	//}
	//var winBoxTitle=getWinBoxTitle();
	//	while (winBoxTitle.childNodes[0]){
	// winBoxTitle.removeChild(winBoxTitle.childNodes[0]);
	//
	//var winBoxContent=getWinBoxContent();
	//while (winBoxContent.childNodes[0]){
	//    winBoxContent.removeChild(winBoxContent.childNodes[0]);
	//}
	
	
}

function prepareBack(height, overflow, useParent){
	if (useParent == '1') {
  	  bod = parent.document.getElementsByTagName('body')[0];
  	  htm = parent.document.getElementsByTagName('html')[0];
  }
	else {
		  bod = document.getElementsByTagName('body')[0];
		  htm = document.getElementsByTagName('html')[0];
	}
    bod.style.height = height;
    bod.style.overflow = overflow;
        
    htm.style.height =height;
    htm.style.overflow = overflow;
    
    setScrollXY(winScrollX, winScrollY);
}
function setSelectsVisibility(visibility){
    selects = document.getElementsByTagName('select');
    for(i = 0; i < selects.length; i++) {
        selects[i].style.visibility = visibility;
    }
}
//#------------------------------------------------------------
function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	winScrollX=scrOfX; winScrollY=scrOfY;
//	return [ scrOfX, scrOfY ];
}
//#------------------------------------------------------------
function setScrollXY(ScrollX, ScrollY) {
  window.scrollTo(ScrollX, ScrollY);
} 
//#------------------------------------------------------------
function getWinSize() {
	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;
	}
	winWidth=myWidth; winHeight=myHeight;
}
//#------------------------------------------------------------
function getBounds(el){ // return absolute left top width height of object
	var Left = el.offsetLeft;
	var Top = el.offsetTop;
	var parent = el;
	while (parent = parent.offsetParent){
		Left += parent.offsetLeft;
		Top += parent.offsetTop;
	}
//	alert('left: '+Left+', top: '+Top+', width: '+el.offsetWidth+', height: '+el.offsetHeight);
	return {left: Left, top: Top, width: el.offsetWidth, height: el.offsetHeight};
}

