//one-shot element popup
function alx_Popup(objectId, title, width, height, left, top)
{
	alx_stitchPopup();
	alx_detachPopup(objectId, title, width, height);
	alx_showPopup(left, top);
}


//Detach object from page
function alx_detachPopup(objectId, title, width, height)
{
	alx_initPopup();
	alx_surroundObject(objectId);
	alx_PopUpProperties.title = title;
	alx_PopUpProperties.width = width;
	alx_PopUpProperties.height = height;
}

//Show the floating object
function alx_showPopup(left, top)
{
	var popup = document.getElementById(alx_PopUpProperties.id);
	
    popup.style.left = (typeof left != 'undefined' ? left : screen.width / 4) + 'px';
    popup.style.top =  (typeof top != 'undefined' ? top : screen.height / 4) + 'px';

	var style = '';
    if (typeof alx_PopUpProperties.width != 'undefined') style += 'width:' + alx_PopUpProperties.width + 'px;';
    if (typeof alx_PopUpProperties.height != 'undefined') style += 'height:' + alx_PopUpProperties.height + 'px;';
	if (style == '') style = 'width:1px;height:1px;';
	
    if (alx_PopUpProperties.originalHTML == '')
        alx_PopUpProperties.originalHTML = popup.innerHTML;
    alx_PopUpProperties.title = 'Help Mirafori Motor Village';
    var surroundingTable = '<table class="floating" style="' + style + '" cellpadding="0" cellspacing="0" border="0">' +
        '<tr><td class="up-left"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td><td class="up" ondblclick="void(0);" onmouseover="alx_PopUp_over=true;" onmouseout="alx_PopUp_over=false;"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td><td class="up" ondblclick="void(0);" onmouseover="alx_PopUp_over=true;" onmouseout="alx_PopUp_over=false;"><img class="close-button" alt="close" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/button-close-focus.jpg" onClick="alx_hidePopup()"/><img class="max-button" alt="maximize" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/button-max-focus.jpg" onClick="alx_maximizePopup()"/><img class="min-button" alt="minimize" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/button-min-focus.jpg" onClick="alx_minimizePopup()"/></td><td class="up-right"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td></tr>' +
        '<tr><td class="left" rowspan="2">&nbsp;</td><td class="title" colspan="2" ondblclick="void(0);" onmouseover="alx_PopUp_over=true;" onmouseout="alx_PopUp_over=false;">' + alx_PopUpProperties.title + '</td><td class="right" rowspan="2">&nbsp;</td></tr>' +
        '<tr><td class="center" colspan="2">' + alx_PopUpProperties.originalHTML + '</td></tr>' +
        '<tr><td class="down-left"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td><td class="down" colspan="2">&nbsp;</td><td class="down-right"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td></tr>' +
        '</table>';

    popup.innerHTML = surroundingTable;
    popup.className = 'dimming';
    popup.style.visibility = 'visible';
    popup.style.display = 'block';
    popup.style.height='438px';
    popup.style.width='638px';
    popup.maximize='false';
    popup.minimize='false';
    popup.frameWidth='600px';

}

//Hide the floating object
function alx_hidePopup()
{
	if (document.getElementById(alx_PopUpProperties.id))
	{
	    document.getElementById(alx_PopUpProperties.id).innerHTML = alx_PopUpProperties.originalHTML;
	    //document.getElementById(alx_PopUpProperties.id).style.visibility = 'hidden';
	    document.getElementById(alx_PopUpProperties.id).style.display = 'none';
	}
}

//Maximize pop up
function alx_maximizePopup()
{
	//debugger;
	if (document.getElementById(alx_PopUpProperties.id))
	{
	    var popup = document.getElementById('popup');
	    var style = '';
	    //alx_showPopup(0, 0);
	    popup.style.left='0px';
	    popup.style.top='0px';
	    
	    if (popup.maximize=='false')	    	
	    {	
	    	style = 'height:'+document.body.clientHeight+'px;width:'+document.body.clientWidth+'px';
	    	popup.style.height=document.body.clientHeight+'px';
        	popup.style.width=document.body.clientWidth+'px';
        	popup.frameWidth=document.body.clientWidth-38+'px';
        	popup.maximize='true';
	    }
	    else
	    {
	    	style = 'height:1px;width:1px';
	    	popup.style.height='438px';
    		popup.style.width='638px';
    		popup.frameWidth='600px';
    		popup.maximize='false';
	    }
	    	
	    popup.innerHTML = '<table class="floating" style="' + style + '" cellpadding="0" cellspacing="0" border="0">' +
        '<tr><td class="up-left"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td><td class="up" ondblclick="void(0);" onmouseover="alx_PopUp_over=true;" onmouseout="alx_PopUp_over=false;"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td><td class="up" ondblclick="void(0);" onmouseover="alx_PopUp_over=true;" onmouseout="alx_PopUp_over=false;"><img class="close-button" alt="close" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/button-close-focus.jpg" onClick="alx_hidePopup()"/><img class="max-button" alt="maximize" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/button-max-focus.jpg" onClick="alx_maximizePopup()"/><img class="min-button" alt="minimize" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/button-min-focus.jpg" onClick="alx_minimizePopup()"/></td><td class="up-right"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td></tr>' +
        '<tr><td class="left" rowspan="2">&nbsp;</td><td class="title" colspan="2" ondblclick="void(0);" onmouseover="alx_PopUp_over=true;" onmouseout="alx_PopUp_over=false;">' + alx_PopUpProperties.title + '</td><td class="right" rowspan="2">&nbsp;</td></tr>' +
        '<tr><td class="center" colspan="2">' + alx_PopUpProperties.originalHTML + '</td></tr>' +
        '<tr><td class="down-left"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td><td class="down" colspan="2">&nbsp;</td><td class="down-right"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td></tr>' +
        '</table>';
        popup.minimize='false';
        //popup.style.height=document.body.clientHeight+'px';
        //popup.style.width=document.body.clientWidth+'px';
        //popup.maximize='true';
	}
}

//Maximize pop up
function alx_minimizePopup()
{
	//debugger;
	if (document.getElementById(alx_PopUpProperties.id))
	{
	     var popup = document.getElementById('popup');
	     var style = 'width:'+popup.style.width+';';
	     var stylewidth = 'background-color:white;';
	     
	     //RICREANDO L'ORIGINALE
	     //if (popup.style.height=='')
	     if (popup.minimize=='true')
	     {
	     	if (popup.style.posWidth==document.body.clientWidth)
	     		style+='height:'+document.body.clientHeight;
	     	else
	     		style+='height:1px';
	
	     	popup.innerHTML = '<table class="floating" style="' + style + '" cellpadding="0" cellspacing="0" border="0">' +
	        '<tr><td class="up-left"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td><td class="up" ondblclick="void(0);" onmouseover="alx_PopUp_over=true;" onmouseout="alx_PopUp_over=false;"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td><td class="up" ondblclick="void(0);" onmouseover="alx_PopUp_over=true;" onmouseout="alx_PopUp_over=false;"><img class="close-button" alt="close" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/button-close-focus.jpg" onClick="alx_hidePopup()"/><img class="max-button" alt="maximize" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/button-max-focus.jpg" onClick="alx_maximizePopup()"/><img class="min-button" alt="minimize" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/button-min-focus.jpg" onClick="alx_minimizePopup()"/></td><td class="up-right"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td></tr>' +
	        '<tr><td class="left" rowspan="2">&nbsp;</td><td class="title" colspan="2" ondblclick="void(0);" onmouseover="alx_PopUp_over=true;" onmouseout="alx_PopUp_over=false;">' + alx_PopUpProperties.title + '</td><td class="right" rowspan="2">&nbsp;</td></tr>' +
	        '<tr><td class="center" colspan="2">' + alx_PopUpProperties.originalHTML + '</td></tr>' +
	        '<tr><td class="down-left"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td><td class="down" colspan="2">&nbsp;</td><td class="down-right"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td></tr>' +
	        '</table>';
	        popup.maximize='false';
	        popup.minimize='false';
	     }
	     //MINIMIZZANDO
	     else
	     {
			style+='height:1px';
			stylewidth += 'width:'+popup.frameWidth+' !important';
			popup.innerHTML = '<table class="floating" style="' + style + '" cellpadding="0" cellspacing="0" border="0">' +
		    '<tr><td class="up-left"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td><td class="up" ondblclick="void(0);" onmouseover="alx_PopUp_over=true;" onmouseout="alx_PopUp_over=false;"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td><td class="up" ondblclick="void(0);" onmouseover="alx_PopUp_over=true;" onmouseout="alx_PopUp_over=false;"><img class="close-button" alt="close" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/button-close-focus.jpg" onClick="alx_hidePopup()"/><img class="max-button" alt="maximize" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/button-max-focus.jpg" onClick="alx_maximizePopup()"/><img class="min-button" alt="minimize" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/button-min-focus.jpg" onClick="alx_minimizePopup()"/></td><td class="up-right"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td></tr>' +
		    '<tr><td class="left" rowspan="2">&nbsp;</td><td class="title" colspan="2" ondblclick="void(0);" onmouseover="alx_PopUp_over=true;" onmouseout="alx_PopUp_over=false;">' + alx_PopUpProperties.title + '</td><td class="right" rowspan="2">&nbsp;</td></tr>' +
		    '<tr><td class="center" colspan="2" style="' + stylewidth + '"></td></tr>' +
		    '<tr><td class="down-left"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td><td class="down" colspan="2">&nbsp;</td><td class="down-right"><img class="spacer" src="/mirafiorimotorvillage/Style%20Library/_MMV/Images/blank.gif" /></td></tr>' +
		    '</table>';
		    popup.style.height='';
		    popup.maximize='false';
		    popup.minimize='true';
	     }
        
	}
}




//Re-attach the object to the page
function alx_stitchPopup()
{
	alx_releaseObject();
}





//--- Utils -----------------------------------------------------------------------------------

//constructor
var alx_PopUpProperties = new Object();
alx_PopUpProperties.id = 'popup';
alx_PopUpProperties.obj = null;
alx_PopUpProperties.title = '';
alx_PopUpProperties.originalHTML = '';
alx_PopUpProperties.width = null;
alx_PopUpProperties.height = null;



var alx_PopUp_initialized = false;
function alx_initPopup()
{
	if (!alx_PopUp_initialized)
	{
	    if (alx_isMozilla())
	    {
	        document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
	    }
	
	    document.onmousedown = alx_PopUp_onMouseDown;
	    document.onmousemove = alx_PopUp_onMouseMove;
	    document.onmouseup = alx_PopUp_onMouseUp;
	    alx_PopUp_initialized = true;
    }
}

//Add surrounding div
function alx_surroundObject(objectId)
{
	var obj = document.getElementById(objectId);
	var content = obj.innerHTML;
	obj.innerHTML = '';
	var newDiv = document.createElement('div');
	//newDiv.style.visibility = 'hidden';
	newDiv.style.display = 'none';
	newDiv.id = alx_PopUpProperties.id;
	obj.appendChild(newDiv);
	newDiv.innerHTML = content;
	obj.style.display = 'block';
}

//Remove surrounding div
function alx_releaseObject()
{
	var popupObj = document.getElementById(alx_PopUpProperties.id);
	
	if (popupObj)
	{
		var content = popupObj.innerHTML;
		var obj = popupObj.parentNode;
		obj.removeChild(popupObj);
		obj.innerHTML = content;
	}
}

// --- Mouse event handlers -----------------------------------------------------------------
this.alx_PopUp_over = false;

function alx_PopUp_onMouseDown(e)
{
    if (alx_PopUp_over) {
        if (alx_isMozilla()) {
            alx_PopUpProperties.obj = document.getElementById(alx_PopUpProperties.id);
            alx_PopUpProperties.X = e.layerX;
            alx_PopUpProperties.Y = e.layerY;
            return false;
        }
        else {
            alx_PopUpProperties.obj = document.getElementById(alx_PopUpProperties.id);
            alx_PopUpProperties.obj = alx_PopUpProperties.obj.style;
            alx_PopUpProperties.X = event.offsetX;
            alx_PopUpProperties.Y = event.offsetY;
        }
    }
}

function alx_PopUp_onMouseMove(e)
{
    if (alx_PopUpProperties.obj) {
        if (alx_isMozilla()) {
            alx_PopUpProperties.obj.style.top = (e.pageY - alx_PopUpProperties.Y) + 'px';
            alx_PopUpProperties.obj.style.left = (e.pageX - alx_PopUpProperties.X) + 'px';
            return false;
        }
        else {
            alx_PopUpProperties.obj.pixelLeft = event.clientX - alx_PopUpProperties.X + document.body.scrollLeft;
            alx_PopUpProperties.obj.pixelTop = event.clientY - alx_PopUpProperties.Y + document.body.scrollTop;
            return false;
        }
    }
}

function alx_PopUp_onMouseUp()
{
    alx_PopUpProperties.obj = null;
}
// --------------------------------------------------------------------------------------------
