/* GAiello 11-19-2007 -  got this off the web */

//
// global variables
//
var isMozilla;
var objDiv = null;
var originalDivHTML = "";
var DivID = "";
var over = false;



/* GAiello - below my addition to get mouse CoOrdinates */
var IE = document.all?true:false;
var xPos=0;	
var yPos = 0;


//
// dinamically add a div to 
// dim all the page
//
function buildDimmerDiv()	{
	// GAiello -05-20-2008 - extra code to cover the IE background
	if	(IE) {
		w =	(window.screen.width - 20); //Internet Explorer
	}
	else {
		w =	(window.innerWidth - 95); // FireFox Amaro - changes this property for Moz and Safari Mac
	}
	
	//GAiello - to make sure it covers the whole page
	var bgImageHeight = window.screen.height;
	if (document.body.parentNode.scrollHeight > window.screen.height)	{
		bgImageHeight = document.body.parentNode.scrollHeight;
	}
	if (document.body.scrollHeight > bgImageHeight) {
		bgImageHeight = document.body.scrollHeight;
	}
	
    //document.write('<div id="dimmer" class="dimmer" style="zIndex:0; width:'+ w + 'px; height:' + bgImageHeight +'px"></div>');  // GAiello - I took 100, to get rid of the horizontal scrollbar, and changed to use document.body.parentNode.scrollHeight
}

function displayFloatingDiv(divId, title, width, height, left, top, blnclosebtn)	{
	DivID = divId;

	//document.getElementById('dimmer').style.display="block";
	
	IE6patch("hidden"); //GAiello - 12-17-2007
	
	//GAiello - to make sure it covers the whole page
	var bgImageHeight = window.screen.height;
	if (document.body.parentNode.scrollHeight > window.screen.height)	{
		bgImageHeight = document.body.parentNode.scrollHeight;
	}
	
	//GAiello - added position="absolute" & zIndex=100, to poisiton over the Header 
	//Note: Z-index only works on elements that have been positioned (eg position:absolute;)!
	//document.getElementById('dimmer').style.position="absolute";
	///document.getElementById('dimmer').style.zIndex=1000;
	
	//document.getElementById('dimmer').style.height = bgImageHeight +'px';	
	//document.getElementById('dimmer').style.left = 0;
	
	
    document.getElementById(divId).style.width = width + 'px';
    document.getElementById(divId).style.height = height + 'px';
    document.getElementById(divId).style.left = left + 'px';
    document.getElementById(divId).style.top = top + 'px';
	
	var addHeader;
	
	if (originalDivHTML == "")
	    originalDivHTML = document.getElementById(divId).innerHTML;
	
	if (title != "") {
		
		if (blnclosebtn == true || blnclosebtn == null) {
			strClose = '<a href="javascript:hiddenFloatingDiv(\'' + divId + '\');void(0);"><img alt="Close..." title="Close..." src="/images/dimmingDIV/btnDimClose.jpg" border="0"></a>';	
		}
		else  {
			strClose = "&nbsp;";	
		}
		
		addHeader = '<table border="0" cellpadding="0" cellspacing="0" style="width:' + width + 'px" class="floatingHeader">' +
	            '<tr><td ondblclick="void(0);" onmouseover="over=true;" onmouseout="over=false;" class="tdHeader">&nbsp;&nbsp;' + title + '</td>' + 
	            '<td style="width:18px" align="right">' + strClose + '</td></tr></table>';
	} else {
		
		addHeader="";
	}
    // add to your div an header	
	document.getElementById(divId).innerHTML = addHeader + originalDivHTML;
	
	document.getElementById(divId).className = 'dimming';
	document.getElementById(divId).style.display="block";
	
}



function hiddenFloatingDiv(divId)	{
	document.getElementById(divId).innerHTML = originalDivHTML;
	document.getElementById(divId).style.display="none";
	//document.getElementById('dimmer').style.display="none";
	
	DivID = "";
	
	IE6patch("visible"); //GAiello - 12-17-2007
}


function MouseDown(e)	{
    if (over)
    {
        if (isMozilla) {
            objDiv = document.getElementById(DivID);
            X = e.layerX;
            Y = e.layerY;
            return false;
        }
        else {
            objDiv = document.getElementById(DivID);
            objDiv = objDiv.style;
            X = event.offsetX;
            Y = event.offsetY;
        }
    }
}


function MouseMove(e)	{
    if (objDiv) {
        if (isMozilla) {
            objDiv.style.top = (e.pageY-Y) + 'px';
            objDiv.style.left = (e.pageX-X) + 'px';
            return false;
        }
        else	{
            objDiv.pixelLeft = event.clientX-X + document.body.scrollLeft;
            objDiv.pixelTop = event.clientY-Y + document.body.scrollTop;
            return false;
        }
    }
	
	/* GAiello - below my addition to get mouse CoOrdinates */
	if (IE) { // grab the x-y pos.s if browser is IE
		xPos = event.clientX + document.body.scrollLeft;
		yPos = event.clientY + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is FF
		xPos = e.pageX;
		yPos = e.pageY;
	}
	
}

function MouseUp()	{
    objDiv = null;
}


function initdimmer()	{
    // check browser
    isMozilla = (document.all) ? 0 : 1;


    if (isMozilla) //FF
    {
        document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
    }

    document.onmousedown = MouseDown;
    document.onmousemove = MouseMove;
    document.onmouseup = MouseUp;

    // add the div
    // used to dim the page
	buildDimmerDiv();	
	
}


// GAiello - patch for IE 6 - it can't handle the selectboxes properly with the floating div

function IE6patch(strVisibility) {
	for(i=0; i<document.getElementsByTagName('select').length; i++) {
		document.getElementsByTagName('select')[i].style.visibility = strVisibility; //hide all select boxes
	};
	if (document.getElementById("autocomplete")) {
		document.getElementById("autocomplete").style.visibility = strVisibility; // serach box in header
	}
}


function dimmerDisablePage(loader)	{	//GAiello -07-11-2008 - created just to disable page, rather than showing a popup

	if (loader){
//		var ovrK = $('dimmer');
//		ovrK.style.opacity = .90;
//		ovrK.style.MozOpacity = .90;
//		ovrK.style.KhtmlOpacity = .90;
//		ovrK.style.filter = "alpha(opacity=" + 90 + ")";
		
		Element.insert(document.body, '<div id="loadingBlock" align="center"><b>Please Wait...</b></div>');
		$('loadingBlock').style.top = document.body.scrollTop + 120;
	}

	//document.getElementById('dimmer').style.display = "block";	// work-around to get Riches stuff working w/o having to go back and recode
	
	IE6patch("hidden"); //GAiello - 12-17-2007
	
	//GAiello - to make sure it covers the whole page
	var bgImageHeight = window.screen.height;
	if (document.body.parentNode.scrollHeight > window.screen.height)	{
		bgImageHeight = document.body.parentNode.scrollHeight;
	}
	if (document.body.scrollHeight > bgImageHeight) {
		bgImageHeight = document.body.scrollHeight;
	}
	
	//GAiello - added position="absolute" & zIndex=100, to poisiton over the Header 
	//Note: Z-index only works on elements that have been positioned (eg position:absolute;)!
	//document.getElementById('dimmer').style.position="absolute";
	//document.getElementById('dimmer').style.zIndex=1000;
	
	//document.getElementById('dimmer').style.height = bgImageHeight +'px';
	if (document.getElementById("processing")) {	//if ajax image exists
		document.getElementById("processing").style.display="block";
	}

}

initdimmer();
