var popupObj;
var showPopUpIndicator;

function showPopUp(popupId) {
	popupObj = document.getElementById(popupId);
    popupObj.style.display = "block";
	setPopUpPosition();
    showPopUpIndicator = "true";
	
	creatingOverlays();//Initializing Overlays Layer
	setOverlaysSize();//Setting LightBox size
	setOverlaysPosition();
}
function lockScreen (){
        creatingOverlays();//Initializing Overlays Layer
	    setOverlaysSize();//Setting LightBox size
	    setOverlaysPosition();
}
function unlockScreen(){
    if(overlays != null && overlays != "undefined")
	{
	    document.body.removeChild(overlays);
	    overlays = null;
	}    
}
function ShowStoryPopup()
{
    showPopUp("storyEditPopup");
    $("#submitButton").css("display", "inline");
}

function ShowAlertPopup(alertType, autoClose, popupID)
{
    isAutoClose = autoClose;
    if (isAutoClose == null || isAutoClose == 'undefined'){
        isAutoClose = false;
    }
    if (popupID == null || popupID == 'undefined'){
        if(alertType != null && alertType != "undefined")
        {
            //popupObj.innerHTML = innerHTML;
            document.getElementById("alertType").innerHTML = alertType ;
        }
        showPopUp("alertPopup");
    }
    else {
        if(alertType != null && alertType != "undefined")
        {
            //popupObj.innerHTML = innerHTML;
            document.getElementById(popupID).innerHTML = alertType ;
        }
        showPopUp(popupID);
    }
}

function ShowIframePopup(url, popUpType, autoClose)
{
    isAutoClose = autoClose;
    if (isAutoClose == null || isAutoClose == 'undefined'){
        isAutoClose = false;
    }
    
    var width;
    var height;
    
    if(popUpType == "ModifyImage")
    {
        width = "500px";
        height = "520px";
    }
    else if(popUpType == "ModifyAlbum")
    {
        width = "550px";
        height = "750px";
    }
    else if(popUpType == "ModifyVideo")
    {
        width = "420px";
        height = "250px";
    }
    else if(popUpType == "ViewVideo")
    {
        width = "450px";
        height = "430px";
    }
     else if(popUpType == "ModifyMap")
    {
        width = "850px";
        height = "650px";
    }
    else if(popUpType == "SendToFriend")
    {
        width = "480px";
        height = "420px";
    }
    else if(popUpType == "EditGallery")
    {
        width = "600px";
        height = "430px";
    }
    $(".IUploadFrame").attr("width", width );
    $(".IUploadFrame").attr("height", height);
    $("#wrapUploadIframe").css("width", width);
    $("#wrapUploadIframe").css("height", height);
    $(".IUploadFrame").attr("src", url);
    
    showPopUp("wrapUploadIframe");
}

function hideAlbumPopup() {
    popupObj.style.display = "none";
    showPopUpIndicator = "false";
	if(overlays != null && overlays != "undefined")
	{
	    document.body.removeChild(overlays);
	    overlays = null;
	} 
	//UpdatePhotoGalleryBlock();
	
//	var frame = window.frames["uploadFrame"]
//	frame.document.body.innerHTML = "";
    //JUST ENABLE THIS SCRIPT ONLY WHEN YOU WANT TO DISABLE THE VERTICAL-SCROLLBAR
    //enable scrollbar
    //var getBody = document.getElementsByTagName("body")[0];
    //var getHtml = document.getElementsByTagName("html")[0];
    //getBody.style.overflow = null;
    //getHtml.style.overflow = null;
    return false;
}

function hidePopUp(requestConfirm) {
    
    if (requestConfirm != null && requestConfirm != 'undefined'){
        if(!confirm("Are you sure you want to close this pop up?"))
        return false;
    }
        
    if(popupObj == null)
        return false;
        
    popupObj.style.display = "none";
    showPopUpIndicator = "false";
	//document.body.removeChild(document.getElementById("lightBox"));
	if(overlays != null && overlays != "undefined")
	{
	    document.body.removeChild(overlays);
	    overlays = null;
	}    
	
	var frame = window.frames["uploadFrame"]
	if(frame != null && frame != "undefined")
	{
	    if(frame.document.body != null)
	    {
	        frame.document.body.innerHTML = "";
	    }
	}
	return false;
	
	
    //JUST ENABLE THIS SCRIPT ONLY WHEN YOU WANT TO DISABLE THE VERTICAL-SCROLLBAR
    //enable scrollbar
    //var getBody = document.getElementsByTagName("body")[0];
    //var getHtml = document.getElementsByTagName("html")[0];
    //getBody.style.overflow = null;
    //getHtml.style.overflow = null;
}

function hideStoryPopup()
{
   //  popupObj.style.display = "none";
    showPopUpIndicator = "false";
    $("#storyEditPopup").hide();
    $("#errorMessage").css("display","none");
    $("#locationErrorMessage").css("display","none");
    
    $("#storyHeadlineTextBox").attr("value","");
    $("#storyLocationTextBox").attr("value","");
    $("#currentStoryHolderIdHidden").attr("value", "")
    setEditorValue(STORY_CONTENT_RICHTEXT_ID, "");    
    document.body.removeChild(document.getElementById("lightBox"));    
    // $(".Ilightbox").attr("display", "none");
     
     $("#storyPhotoList").empty("");
     $("#storyVideoList").empty("");
     $("#storyMapList").empty("");
     currentStoryID = 0;
     return false;
}

//Centering PopUp Horizontal and Vertical
function setPopUpPosition () {
    var screenWidth = document.documentElement.clientWidth;
    var screenHeight = document.documentElement.clientHeight;//get the height of the window screen
        
    
    //Get the Scroll Top Position
    var ie = document.all; //If IE
    if (ie) {
        scrollTop = document.documentElement.scrollTop;
        scrollLeft = document.documentElement.scrollLeft;
    }
    else {
        scrollTop = window.pageYOffset;
        scrollLeft = window.pageXOffset;
    }

    //If the screen heigth is less than the PopUp's height, we can't never stop scrolling because the position of the PopUp is center, so it always has a part out of the screen at the bottom, so we can scroll over and over again. This solution here is we can set the PopUp always at the bottom of the screen
    
    if (popupObj.clientHeight > document.documentElement.clientHeight) {
        scrollTop = scrollTop + (screenHeight - popupObj.clientHeight)/2;
    }
    
    if (popupObj.clientWidth > document.documentElement.clientWidth) {
        scrollLeft = scrollLeft + (screenWidth - popupObj.clientWidth)/2;
    }
    
    //Set PopUp Position
    popupObj.style.left = (screenWidth - popupObj.clientWidth)/2 + scrollLeft + "px";
    popupObj.style.top = (screenHeight - popupObj.clientHeight)/2 + scrollTop + "px";
}

//Event
/*
window.onresize = function () {
    if (showPopUpIndicator && showPopUpIndicator == "true") {
		var ie = document.all;
		if (ie) {
			document.documentElement.scrollTop = 0;
			document.documentElement.scrollLeft = 0;
		}//Reset ScrollTop and ScrollLeft to Zero for IE
		setPopUpPosition();
        setOverlaysSize();
		setOverlaysPosition();
    }
}
window.onscroll = function () {
    if (showPopUpIndicator && showPopUpIndicator == "true") {
		setPopUpPosition();
        setOverlaysSize();
		setOverlaysPosition();
    }
}
*/