var dragapproved=false
var minrestore=0
var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all


  function ram_on (id_on)
	{document.getElementById(id_on).style.border="1px solid gray";}
  function ram_off (id_off)
	{document.getElementById(id_off).style.border="1px solid gainsboro";}


function iecompattest(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function getWindowWidth(){	
	if (self.innerWidth) {
		return self.innerWidth;	
	// IE 6 Strict Mode
	} else if (document.documentElement && document.documentElement.clientHeight) {
		return document.documentElement.clientWidth;	
	// Other IE versions
	} else if (document.body) {
		return document.body.clientWidth;	
	} 
}

function drag_drop(e){
	if (ie5&&dragapproved&&event.button==1){
		posx = tempx+event.clientX-offsetx
		posy = tempy+event.clientY-offsety
	}	
	else if (ns6&&dragapproved){
		posx = tempx+e.clientX-offsetx
		posy = tempy+e.clientY-offsety
	}
	if (posx < 0) 
			posx = 0
	else if (posx + parseInt(initialwidth) > getWindowWidth()) 
		posx = getWindowWidth()-parseInt(initialwidth)

	if (posy < 217)
		posy = 217
	document.getElementById("dwindow").style.left=posx+"px"
	document.getElementById("dwindow").style.top=posy+"px"
}

function initializedrag(e){
	offsetx=ie5? event.clientX : e.clientX
	offsety=ie5? event.clientY : e.clientY
	document.getElementById("dwindowcontent").style.display="none" //extra
	tempx=parseInt(document.getElementById("dwindow").style.left)
	tempy=parseInt(document.getElementById("dwindow").style.top)
	
	dragapproved=true
	document.getElementById("dwindow").onmousemove=drag_drop
}

function loadwindow(url,width,height){
	var left = 300
	var top = 0
	loadWindowEx(url,width,height,left,top)		
}
function loadWindowEx(url,width,height,left,top){
	if (!ie5&&!ns6) {

		window.open(url,"","width=width,height=height,scrollbars=0")
	} else {		
		width += '';
		height += '';
//		left += ''
		var top_f = ns6? window.pageYOffset * 1: iecompattest().scrollTop * 1
		top_f = top_f < 217 ? 217 : top_f	
		top_f = top_f + parseInt(top)
		top_f += 'px';
//		if (left == 'center')
			left = (getWindowWidth() - width) / 2 + 'px';
		
		//document.write(width.substr(width.length-2, 2));
		width += ((width.length >2 && width.substr(width.length-2, 2) == "px" || width.substr(width.length-1, 1)=="%") ? "" : "px")
		height += ((height.length>2 && height.substr(height.length-2, 2) == "px" || height.substr(height.length-1, 1)=="%") ? "" : "px")
		left += ((left.length>2 && left.substr(left.length-2, 2) == "px" || left.substr(left.length-1, 1)=="%") ? "" : "px")
				
		initialwidth = width
		initialheight = height
		document.getElementById("dwindow").style.display = ''		
		document.getElementById("dwindow").style.width = width
		document.getElementById("dwindow").style.height = height
		document.getElementById("dwindow").style.left = left		
		document.getElementById("dwindow").style.top = top_f
		document.getElementById("cframe").src = url
	}
}

function maximize(){
	if (minrestore==0){
		minrestore=1 //maximize window
		document.getElementById("maxname").setAttribute("src","restore.gif")
		document.getElementById("dwindow").style.width=ns6? window.innerWidth-20+"px" : iecompattest().clientWidth+"px"
		document.getElementById("dwindow").style.height=ns6? window.innerHeight-20+"px" : iecompattest().clientHeight+"px"
	}
	else{
		minrestore=0 //restore window
		document.getElementById("maxname").setAttribute("src","max.gif")
		document.getElementById("dwindow").style.width=initialwidth + "px"
		document.getElementById("dwindow").style.height=initialheight + "px"
	}
	document.getElementById("dwindow").style.left=ns6? window.pageXOffset+"px" : iecompattest().scrollLeft+"px"
	document.getElementById("dwindow").style.top=ns6? window.pageYOffset+"px" : iecompattest().scrollTop+"px"
}

function closeit(){
	document.getElementById("dwindow").style.display="none"
}

function stopdrag(){
	dragapproved=false;
	document.getElementById("dwindow").onmousemove=null;
	document.getElementById("dwindowcontent").style.display="" //extra
}


