window.onerror = new Function('return true;');

var dragapproved=false;
var dragtype=0;

var fElement;
var z;
var x;
var y;

var maxZorder=1;

var IE = document.all?true:false;

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE);

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// variables to hold mouse x-y pos.s
var mouseX=0;
var mouseY=0;

// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {
	var tempX = 0;
	var tempY = 0;

	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} 
	else 
	{  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	
	// catch possible negative values in NS4
	if (tempX < 0)
		{tempX = 0}
	else if(tempX>document.body.clientWidth)
		{tempX = document.body.clientWidth}
		
	if (tempY < 0){tempY = 0}  
  
	mouseX = tempX;
	mouseY = tempY;
	
	if (dragapproved)
	{
		if(dragtype==0)
		{	
			z.style.left=temp1+mouseX-x;
			z.style.top=temp2+mouseY-y;		
		}
		else if(dragtype==1)
		{
			z.style.height=temp4+mouseY-y;		
		
			temp4=parseInt(z.style.height);

			x=mouseX;
			y=mouseY;		
		}
		else if(dragtype==2)
		{
			z.style.width=temp3+mouseX-x;		
		
			temp3=parseInt(z.style.width);

			x=mouseX;
			y=mouseY;		
		}
		else if(dragtype==3)
		{
			z.style.left=mouseX;		
			z.style.width=document.body.clientWidth-temp5-mouseX;		
			
			temp1=parseInt(z.style.left);
			temp3=parseInt(z.style.width);

			x=mouseX;
			y=mouseY;		
		}
		else if(dragtype==4)
		{
			z.style.width=temp3+mouseX-x;		
			z.style.height=temp4+mouseY-y;		
		
			temp3=parseInt(z.style.width);		
			temp4=parseInt(z.style.height);

			x=mouseX;
			y=mouseY;		
		}
		else if(dragtype==5)
		{
			z.style.left=mouseX;		
			z.style.width=document.body.clientWidth-temp5-mouseX;		
			z.style.height=temp4+mouseY-y;		
		
			temp1=parseInt(z.style.left);
			temp3=parseInt(z.style.width);		
			temp4=parseInt(z.style.height);

			x=mouseX;
			y=mouseY;		
		}
		
		return false
	}
	
	return true
}


function maximizeZorder()
{
	z.style.zIndex=maxZorder++;
}

function drags(dragElement,dType,frameElement)
{

	dragtype=dType;

	hideFrames('none');
	dragapproved=true;
	    
	z=dragElement;

	maximizeZorder();
	
	temp1=parseInt(z.style.left);
	temp2=parseInt(z.style.top);
	temp3=parseInt(z.style.width);
	temp4=parseInt(z.style.height);
	
	temp5=document.body.clientWidth-temp1-temp3;

	x=mouseX;
	y=mouseY;

	document.onmouseup=dragEnd;

}

document.onselectstart=new Function('return false');

function dragEnd()
{
	dragapproved=false;
	
	hideFrames('');
//	if(fElement!=null)
//			fElement.style.display='';
}

function hideFrames(mode)
{
    if(frames.length>0)
    {
        var ipos;
        for(ipos=0;ipos<frames.length;ipos++)
        {
            if(frames[ipos].name.length>0)
            {
                if(IE)
                    eval('document.all.' + frames[ipos].name).style.display=mode;
                else
                    document.getElementById(frames[ipos].name).style.display=mode;
            }
        }
    }
}

function creatWindow(wName,wTitle,wWidth,wHeight,wLock,wMode,fName,fSrc,scroll)
{	
    var scrollStr="scrolling=auto";
    if(scroll==0)
    	scrollStr="scrolling=no";
    			 
	var wLeft=0;
	var wTop=0;
		
	if(wMode==0)
		{wLeft=parseInt(wID.style.width);wTop=0;}
	else if(wMode==1)
		{wLeft=(document.body.clientWidth-wWidth)/2;wTop=0;}
	else if(wMode==2)
	{wLeft=document.body.clientWidth-wWidth;wTop=0;}
	else if(wMode==3)
		{wLeft=parseInt(wID.style.width);wTop=(document.body.clientHeight-wHeight)/2;}
	else if(wMode==4)
		{wLeft=(document.body.clientWidth-wWidth)/2;wTop=(document.body.clientHeight-wHeight)/2;}
	else if(wMode==5)
		{wLeft=document.body.clientWidth-wWidth;wTop=(document.body.clientHeight-wHeight)/2;}
	else if(wMode==6)
		{wLeft=parseInt(wID.style.width);wTop=document.body.clientHeight-wHeight;}
	else if(wMode==7)
		{wLeft=(document.body.clientWidth-wWidth)/2;wTop=document.body.clientHeight-wHeight;}
	else if(wMode==8)
		{wLeft=document.body.clientWidth-wWidth;wTop=document.body.clientHeight-wHeight;}
	else if(wMode==9)
	{	
		wLeft=parseInt(wID.style.width)+1;wTop=1;
		
		wWidth=document.body.clientWidth-wLeft-1;
		wHeight=document.body.clientHeight-wTop-36;
	}

	if (mHTML.dir=="rtl")
		wLeft=document.body.clientWidth-wLeft-wWidth;
		
	var winHTML="<span id='" + wName 
		+ "' style='position:absolute;left:" + wLeft + ";top:" + wTop + ";"
		+ "width:" + wWidth + ";height:" + wHeight + ";z-index:" + maxZorder++ + ";' dir=ltr>"
		+ "<table border=0 cellpadding=0 cellspacing=0 width=100% height=100%>"
		+ "<tr><td style='height:24px'>"
		+ "<table border=0 cellpadding=0 cellspacing=0 width=100%>"
		+ "<tr><td width=11><img src=image.ashx?/members/window/HeaderLeft.png></td>"
		+ "<td width=2000 background=image.ashx?/members/window/HeaderCenter.gif>" 
		+ "<table width=100% border=0 cellpadding=0 cellspacing=0><tr>"
		+ "<td width=8><img style='cursor:hand;cursor:pointer' src=image.ashx?/members/window/Reload.gif width=8 height=9 onClick='reloadWin(\"" + fName + "\",\"" + fSrc + "\")'></td>"
		+ "<td onmousedown=drags(" + wName + ",0,document.all." + fName + ") onDblClick='maxWin(\"" + wName +"\")' valign=bottom align=center noWrap style='color:#000022;cursor:default;font-family:Tahoma;font-size:10pt;'>" + wTitle + "</td>"
		+ "<td  align=right width=48 nowrap>"
		
	if (wLock==false)
	winHTML+="<img style='cursor:hand;cursor:pointer' src=image.ashx?/members/window/Minimize.gif width=8 height=9 onClick='minWin(\"" + wName +"\")'>&nbsp;"
		+ "<span style='display:none' id='restore_" + wName + "'><img style='cursor:hand;cursor:pointer' src=image.ashx?/members/window/Restore.gif width=8 height=9 onClick='restoreWin(\"" + wName +"\")'>&nbsp;</span>"
		+ "<span id='max_" + wName + "'><img style='cursor:hand;cursor:pointer' src=image.ashx?/members/window/Maximize.gif width=8 height=9 onClick='maxWin(\"" + wName +"\")'>&nbsp;</span>"
		
	winHTML+="<img style='cursor:hand;cursor:pointer' src=image.ashx?/members/window/Close.gif width=8 height=9 onClick='closeWin(" + wName +")'>"
		+ "</td></tr></table>"
		+ "</td><td width=11><img src=image.ashx?/members/window/HeaderRight.png></td></tr>"
		+ "</table></td></tr><tr><td>"
		+ "<table border=0 cellpadding=0 cellspacing=0 width=100% height=100%>"
		+ "<tr><td onmousedown=drags(" + wName + ",3,document.all." + fName + ") style='width:1;cursor:e-resize' bgcolor=#D0D4DD><img src='image.ashx?/members/images/f.gif' width=1 height=1></td>"
		+ "<td bgcolor=#ffffff colspan=2>"
		+ "<iframe id='" + fName + "' name='" + fName + "' src='" + fSrc + "' " + scrollStr + " marginwidth=1 style='width:100%;height:100%' marginheight=1 border=0 frameborder=0></iframe></td>"
		+ "<td onmousedown=drags(" + wName + ",2,document.all." + fName + ") style='width:1;cursor:e-resize' bgcolor=#D0D4DD><img src='image.ashx?/members/images/f.gif' width=1 height=1></td></tr></table></td></tr>"
		+ "<tr><td style='height:10px'>"
		+ "<table border=0 height=10 cellpadding=0 cellspacing=0 width=100%>"
		+ "<tr><td onmousedown=drags(" + wName + ",5,document.all." + fName + ") style='width:11px;height:10px;cursor:ne-resize;background-image:url(image.ashx?/members/window/FooterLeft.png)'></td>"
		+ "<td colspan=2 bgcolor=#F4F4F4 width=1800 onmousedown=drags(" + wName + ",1,document.all." + fName + ") style='cursor:n-resize' background=image.ashx?/members/window/FooterCenter.gif align=right>"
		+ "</td><td onmousedown=drags(" + wName + ",4,document.all." + fName + ") style='width:10;cursor:nw-resize;background-image:url(image.ashx?/members/window/FooterRight.png)'></td></tr>"
		+ "</tr></table></td></tr></table></span>";

		var oDiv=document.createElement("DIV");
		document.body.appendChild(oDiv);	
		oDiv.innerHTML=winHTML;				
}

function convertToWindow(sID,wName,wTitle,wWidth,wHeight,wLock,wMode)
{				

	var wLeft;
	var wTop;
	
	if(wMode==0)
		{wLeft=parseInt(wID.style.width);wTop=0;}
	else if(wMode==1)
		{wLeft=(document.body.clientWidth-wWidth)/2;wTop=0;}
	else if(wMode==2)
		{wLeft=document.body.clientWidth-wWidth;wTop=0;}
	else if(wMode==3)
		{wLeft=parseInt(wID.style.width);wTop=(document.body.clientHeight-wHeight)/2;}
	else if(wMode==4)
		{wLeft=(document.body.clientWidth-wWidth)/2;wTop=(document.body.clientHeight-wHeight)/2;}
	else if(wMode==5)
		{wLeft=document.body.clientWidth-wWidth;wTop=(document.body.clientHeight-wHeight)/2;}
	else if(wMode==6)
		{wLeft=parseInt(wID.style.width);wTop=document.body.clientHeight-wHeight;}
	else if(wMode==7)
		{wLeft=(document.body.clientWidth-wWidth)/2;wTop=document.body.clientHeight-wHeight;}
	else if(wMode==8)
		{wLeft=document.body.clientWidth-wWidth;wTop=document.body.clientHeight-wHeight;}
	else if(wMode==9)
	{	
		wLeft=parseInt(wID.style.width);
		wTop=0;
		
		wWidth=document.body.clientWidth-wLeft;
		wHeight=document.body.clientHeight-wTop-34;
	}

	if (mHTML.dir=="rtl")
		wLeft=document.body.clientWidth-wLeft-wWidth;
		
	var winHTML="<div id='" + wName + "' style='position:absolute;left:" 
		+ wLeft + ";top:" + wTop + ";z-index:" + maxZorder++ + ";"
		+ "width:" + wWidth + ";height:" + wHeight + "' dir=ltr>"
		+ "<table border=0 cellpadding=0 cellspacing=0 width=100% height=100%>"
		+ "<tr onmousedown=drags(" + wName + ",0)><td style='height:24px'>"
		+ "<table border=0 cellpadding=0 cellspacing=0 width=100%>"
		+ "<tr><td width=11><img src=image.ashx?/members/window/HeaderLeft.png></td>"
		+ "<td width=2000 background=image.ashx?/members/window/HeaderCenter.gif>" 
		+ "<table width=100% border=0 cellpadding=0 cellspacing=0><tr><td width=30></td>"
		+ "<td ";
	if (wLock==false)
		winHTML+=" onDblClick='maxWin(\"" + wName +"\")' ";
		
	winHTML+="valign=bottom align=center noWrap style='color:#000022;cursor:default;font-family:Tahoma;font-size:10pt;'>" + wTitle + "</td>"
		+ "<td  align=right width=48 nowrap>";
		
	if (wLock==false)
	winHTML+="<img style='cursor:hand;cursor:pointer' src=image.ashx?/members/window/Minimize.gif width=8 height=9 onClick='minWin(\"" + wName +"\")'>&nbsp;"
		+ "<span style='display:none' id='restore_" + wName + "'><img style='cursor:hand;cursor:pointer' src=image.ashx?/members/window/Restore.gif width=8 height=9 onClick='restoreWin(\"" + wName +"\")'>&nbsp;</span>"
		+ "<span id='max_" + wName + "'><img style='cursor:hand;cursor:pointer' src=image.ashx?/members/window/Maximize.gif width=8 height=9 onClick='maxWin(\"" + wName +"\")'>&nbsp;</span>"
		
	winHTML+="<img style='cursor:hand;cursor:pointer' src=image.ashx?/members/window/Close.gif width=8 height=9 onClick=\"" + sID.id + ".style.display='none'\">"
		+ "</td></tr></table>"
		+ "</td><td width=11><img src=image.ashx?/members/window/HeaderRight.png></td></tr>"
		+ "</table></td></tr><tr><td>"
		+ "<table border=0 cellpadding=0 cellspacing=0 width=100% height=100%>"
		+ "<tr><td width=1 bgcolor=#D0D4DD></td>"
		+ "<td bgcolor=#F4F4F4>"
		+ sID.innerHTML
		+ "</td><td width=1 bgcolor=#D0D4DD></td></tr></table></td></tr>"
		+ "<tr><td style='height:10px'>"
		+ "<table border=0 height=10 cellpadding=0 cellspacing=0 width=100%>"
		+ "<tr><td width=11><img src=image.ashx?/members/window/FooterLeft.png></td>"
		+ "<td width=2000 background=image.ashx?/members/window/FooterCenter.gif align=right>"
		+ "</td><td width=10><img src=image.ashx?/members/window/FooterRight.png></td></tr>"
		+ "</tr></table></td></tr></table></div>";

		sID.innerHTML=winHTML;				
}

function closeWin(wName)
{
	eval(wName + ".style.display='none'");
	eval(wName + ".innerHTML=''");
	eval(wName + ".removeNode(true)");
}

function reloadWin(fName,fSrc)
{
	//var rndStr="?rnd=" + Math.round(Math.random()*1000,0);			
	eval("document.all." + fName + ".src=\"" + fSrc + "\"");
}

function createIcon(iName,iTitle,iImage,wName,mode)
{			
	var floatMode="left";
	if (mHTML.dir=="rtl")
		floatMode="right";
				
	var winHTML="<span id='" + iName + "' style='cursor:hand;cursor:pointer;float:" + floatMode + ";width:64;height:82;display:" + mode + "'"
		+ " onClick='showWindow(\"" + wName +"\",\"" + wName +"\")'>"
		+ "<table border=0 cellpadding=0 cellspacing=0 width=100% height=100% style='table-layout:fixed;'>"
		+ "<tr><td style='height:64px'>"
		+ "<img src=icon/" + iImage + ".png border=0 /></td></tr>"
		+ "<tr><td valign=top align=center style='font-family:Tahoma;font-size:7.5pt;line-height:.9;height:22px'>" + iTitle + "</td></tr></table></span>"
		
	wID.innerHTML=wID.innerHTML+winHTML;
}


