//DHTML Window script- Copyright Dynamic Drive (http://www.dynamicdrive.com)
//For original full source code, documentation, and terms of usage,
//Visit http://www.dynamicdrive.com/dynamicindex9/dhtmlwindow.htm
//modified by Brian McIntyre, Ergonet and Patrick Meunier, Ergonet.
//2006 december 12th,

var dragapproved=false;
var minrestore=0;
var maxrestore=0;
var initialleft,initialtop,initialwidth,initialheight;
var ie5=document.all&&document.getElementById;
var ns6=document.getElementById&&!document.all;

function iecompattest(){
    return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function drag_drop(e){

    if (ie5&&dragapproved&&event.button==1){
        this.style.left=tempx+event.clientX-offsetx+"px";
        this.style.top=tempy+event.clientY-offsety+"px";
    }
    else if (ns6&&dragapproved){
        this.style.left=tempx+e.clientX-offsetx+"px";
        this.style.top=tempy+e.clientY-offsety+"px";
    }
}

function initializedrag(e, id){
	
	var doc = document.getElementById(id + "win");
	
    offsetx=ie5? event.clientX : e.clientX;
    offsety=ie5? event.clientY : e.clientY;
    tempx=parseInt(doc.style.left);
    tempy=parseInt(doc.style.top);

    dragapproved=true;
    doc.onmousemove=drag_drop;
}

function maximize(id){

	var doc = document.getElementById(id + "win");
	
	if (minrestore==1){
		maxrestore=0 ; //Cancel this maximise restore its a minimise restore.
		minimize(id); //Currently minimized, so restore to normal size.
	}
	else{
		if (maxrestore==0){
			maxrestore=1; //maximize window
			document.getElementById(id + "maxname").setAttribute("src","/images/restore.gif");
			doc.style.width=ns6? window.innerWidth-20+"px" : iecompattest().clientWidth+"px";
			doc.style.height = ns6 ? window.innerHeight - 20 + "px" : iecompattest().clientHeight + "px";
			//document.getElementById(id + "win").setAttribute("class", "dragPanelMax");
			//document.getElementById(id + "content").setAttribute("id", "Help_DivcontentMax");
	       
		}
		else{
			maxrestore=0; //restore window
			document.getElementById(id + "maxname").setAttribute("src","/images/maximize.gif");
			doc.style.width=initialwidth;
			doc.style.height = initialheight;
			//document.getElementById(id + "win").setAttribute("class", "dragPanel");
			//document.getElementById(id + "contentMax").setAttribute("id", "Help_Divcontent");
	    
		}
		resizeDragPanelContent(id);
		doc.style.left=ns6? window.pageXOffset+"px" : iecompattest().scrollLeft+"px";
		doc.style.top=ns6? window.pageYOffset+"px" : iecompattest().scrollTop+"px";
    }
}

function minimize(id){
	var doc = document.getElementById(id + "win");

    if (minrestore==0){
        minrestore=1; //minimize window
        document.getElementById(id + "minname").setAttribute("src","/images/restore.gif");
	    doc.style.height = document.getElementById(id + "titlebar").offsetHeight + "px";
	    document.getElementById(id + "content").style.display = "none";
	    document.getElementById(id + "iframe").style.display = "none";
	   // document.getElementById(id + "iframe").style.visibility = "hidden";
	    //document.getElementById(id + "win").style.height = 0;
	    //document.getElementById(id + "win").className = "dragPanelMin";
    }
    else{
        minrestore=0; //restore window
        document.getElementById(id + "minname").setAttribute("src","/images/minimize.gif");
        doc.style.height=initialheight;
        document.getElementById(id + "content").style.display = '';
        document.getElementById(id + "iframe").style.display = '';
       // document.getElementById(id + "win").className = "dragPanel";
    }
    resizeDragPanelContent(id);
}

function closeit(id){
    document.getElementById(id + "win").style.display="none";
    
    //correct an ie peek-a-boo bug...
    var temp1 = document.getElementById('RelativeWrapperBlock');
    if(temp1 != undefined)
    {
        temp1.className = "formBlockWrapper";
        return true;
    }
}

function stopdrag(id){
    dragapproved=false;
    document.getElementById(id + "win").onmousemove=null;
}

function resizeDragPanelContent(id){

    var height2 = parseInt(document.getElementById(id + "win").style.height);    
    height2 -= document.getElementById(id + "titlebar").offsetHeight;
    height2 -= (parseInt(document.getElementById(id + "content").style.paddingTop) + parseInt(document.getElementById(id + "content").style.paddingBottom));
	height2 -= (parseInt(document.getElementById(id + "content").style.borderTopWidth) + parseInt(document.getElementById(id + "content").style.borderBottomWidth));;
    document.getElementById(id + "content").style.height = (( height2 < 0 ) ? 0 : height2)  + "px";
    
}

//To simplifiy usage of this wondowid, place your content inside a <div id='someid'>
//Hide the div with style info or CSS ;-)
//And follow the div with an inline call to this method.
//Make sure you provide a unique identifier for id which will be provided to
//the loadwindow(1,1,20,20,'someid'). 
function generateContentDiv(id)
{
	var content = document.getElementById(id);

	var str = ('<div id="' + id + 'win" class="dragPanel" style="overflow;hidden;position:absolute;display:none;" onSelectStart="return false"><!--[if lte IE 6.5]><iframe src="javascript:false;"></iframe><![endif]-->');
	str += ('<table id="' + id + 'titlebar" onMousedown="initializedrag(event, \'' + id + '\')" onMouseup="stopdrag(\'' + id + '\')"  ondblclick="maximize(\'' + id + '\')"  class="dragPanelTitleBar" border="0" cellpadding="0" cellspacing="0">');
	str += ('<tr><td align="left" width="50%"></td><td id="' + id + 'title" align="center"');
	str += ('</td><td align="right" width="50%">');
	str += ('<img src="/images/minimize.gif" id="'+ id +'minname" onClick="minimize(\'' + id + '\')" />');
	//str += ('<img src="/images/maximize.gif" id="'+ id +'maxname" onClick="maximize(\'' + id + '\')" />');
	str += ('<img src="/images/close.gif" onClick="closeit(\'' + id + '\')" />');
	str += ('</td></tr></table>');
	str += ('<div id="' + id + 'content" class="dragPanelContent" style="padding: 3px; border-width:1px; border-style:solid; border-color: #EBEBEB;">');
	str += (content.innerHTML);
	str += ('<br><iframe id="' + id + 'iframe" style="z-index:0;position:absolute;width:0;height:0;" frameborder="0" src="javascript:false;"></iframe></div></div>');
	
	document.write(str);
}

function loadwindow(left,top,width,height, id){
	
	var doc = document.getElementById(id + "win");
    doc.style.display='';
    doc.style.width = initialwidth = width+"px";
    doc.style.height = initialheight = height+"px";
    doc.style.left = initialleft = ns6? window.pageXOffset*1+left+"px" : iecompattest().scrollLeft*1+left+"px";
    doc.style.top = inititialtop = ns6? window.pageYOffset*1+top+"px" : iecompattest().scrollTop*1+top+"px";
    
   

    resizeDragPanelContent(id);

}

function newWindow(left,top,width,height,id,title)
{
  var doc = document.getElementById(id + "title");
  doc.innerHTML = '<nobr>' + title + '</nobr>';
  loadwindow(left,top,width,height,id);
}