﻿var lastMouseX;
var lastMouseY;
var curPopupWindow = null;

    function toggle(id,id2, img)
    {
        var ex = "./Images/plus.png";
        var im = "./Images/minus.png";
	    
	    var display = 'none';	    	    
	    var src =  ex;	     	        
	    
	    var el = document.getElementById(id);
	    if (el.style.display == 'none'){	     
	     display = '';
	     src = im;
	     }
	     
	    var image = document.images[img];
	    image.src = src; 
	    el.style.display = display;
	    var el2 = document.getElementById(id2);
	    if (el2 != null)
	    el2.style.display = display;	    	    
    }
    
function openBOPicker(e,boType,idCtrl,nameCtrl, dopost) {
				//setLastMousePosition(e);
			openPopup(
			'./Tools/bopicker.aspx?tp='+boType+'&idCtrl='+idCtrl+'&nameCtrl='+nameCtrl+'&dopost='+dopost,
			'BOPicker', 
			600, 
			300, 
			'width=600,height=300,scrollbars=yes,toolbar=no,status=no,directories=no,menubar=no,resizable=yes', 
			true);
    }    
 /**
 * Calls through to the openPopupFocus() with closeOnLoseFocus set to true.
 */
function openPopup(url, name, pWidth, pHeight, features, snapToLastMousePosition) {
    openPopupFocus (url, name, pWidth, pHeight, features, snapToLastMousePosition, true);
}

/**
 * Handles popup windows.
 * If snapToLastMousePosition is true, then the popup will open up near the mouse click.
 * If closeOnLoseFocus is true, then it will close when the user clicks back into the browser window that opened it.
 */
function openPopupFocus(url, name, pWidth, pHeight, features, snapToLastMousePosition, closeOnLoseFocus) {
    closePopup();

    if (snapToLastMousePosition) {
        if (lastMouseX - pWidth < 0) {
            lastMouseX = pWidth;
        }
        if (lastMouseY + pHeight > screen.height) {
            lastMouseY -= (lastMouseY + pHeight + 50) - screen.height;
        }
        lastMouseX -= pWidth;
        lastMouseY += 10;
        features += ",screenX=" + lastMouseX + ",left=" + lastMouseX + ",screenY=" + lastMouseY + ",top=" + lastMouseY;
    }

    if (closeOnLoseFocus) {
        curPopupWindow = window.open(url, name, features, false);
        curPopupWindow.focus ();
    } else {
        // assign the open window to a dummy var so when closePopup() is called it won't be assigned to curPopupWindow
        win = window.open(url, name, features, false);
        win.focus ();
    }
}

function closePopup() {
    if (curPopupWindow != null) {

        if (!curPopupWindow.closed) {
            curPopupWindow.close();
        }
        curPopupWindow = null;
    }
}

function cleanTwoControls(ctrl,hdnCtrl,post){
	document.aspnetForm[ctrl].value = '';
	document.aspnetForm[hdnCtrl].value = '';
	if (post)
	    document.aspnetForm.submit();
}
