// Opens the browser's print window
/*function printWindow() {
	window.print();
	return false;
}
*/

//Set the page domain
//document.domain = 'organization.org';

var windowStyle = "toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=470";

// Open popup window
function openWindow(theURL) { //v2.0
	var oWin = window.open(theURL, "", windowStyle);
	if (oWin==null || typeof(oWin)=='undefined') {
		alert('You have a popup blocker installed. Please, deactivate it in order to execute iWeb correctly.');
	}
	else
	{
		oWin.focus();
	}
	//window.showModalDialog(theURL, null,"toolbar:no;status:no;menubar:no;scrollbars:yes;resizable:yes;width:700;height:470");
}

function openWindow(theURL, winName) { //v2.0
	var oWin = window.open(theURL, winName, windowStyle);
	if (oWin==null || typeof(oWin)=='undefined') {
		alert('You have a popup blocker installed. Please, deactivate it in order to execute iWeb correctly.');
	}
	else
	{
		oWin.focus();
	}
}

function openRichWindow(theURL, winName, windowStyle) { //v2.0
	var oWin = window.open(theURL, winName, windowStyle);
	if (oWin==null || typeof(oWin)=='undefined') {
		alert('You have a popup blocker installed. Please, deactivate it in order to execute iWeb correctly.');
	}
	else
	{
		oWin.focus();
	}
}

// Open popup window including escape
function openWindowEscape(theURL) { 
	theURL = escape(theURL);
	window.open(theURL, "", windowStyle);
}


//*********DANIEL
function openModalWindow(anURL, winName) {
  
    var oWin;
    if (window.showModalDialog) 
    {
        oWin = window.showModalDialog(anURL, winName, windowStyle);
        
        if (oWin==null || typeof(oWin)=='undefined') 
        {
		    alert('You have a popup blocker installed. Please, deactivate it in order to execute iWeb correctly.');
	    }	    
    } 
    else 
    {
        oWin = window.open(anURL, winName, 'toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=470,directories=no,menubar=no,modal=yes');
        //window.open(anURL, winName, 'height=255,width=250,toolbar=no,directories=no,status=no, continued from previous linemenubar=no,scrollbars=no,resizable=no ,modal=yes');
        
        if (oWin==null || typeof(oWin)=='undefined') 
        {
		    alert('You have a popup blocker installed. Please, deactivate it in order to execute iWeb correctly.');
	    }    
    }
}

function openModalWindow(anURL) 
{       
    var winName = ''; 
    var oWin;
    if (window.showModalDialog) 
    {
        oWin = window.showModalDialog(anURL, winName, windowStyle);
        
        /*
        if (oWin==null || typeof(oWin)=='undefined') 
        {
		    alert('You have a popup blocker installed. Please, deactivate it in order to execute iWeb correctly.');
	    }
	    */	    
    } 
    else 
    {
        oWin = window.open(anURL, winName, 'toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=470,directories=no, continued from previous linemenubar=no, modal=yes');
        //window.open(anURL, winName, 'height=255,width=250,toolbar=no,directories=no,status=no, continued from previous linemenubar=no,scrollbars=no,resizable=no ,modal=yes');
        
        if (oWin==null || typeof(oWin)=='undefined') 
        {
		    alert('You have a popup blocker installed. Please, deactivate it in order to execute iWeb correctly.');
	    }    
    }
}
    

//*******DANIEL end


var isIweb=1

// Community Management status changed.
function CheckHiddenValue()
{
	var counter = 0;
	var statusChanged = 'false';
	
	while(document.getElementById("dlCurrentCommunities__ctl"+ counter +"_chkCurrentCommunities") != null)
	{
		if (!document.getElementById("dlCurrentCommunities__ctl"+ counter +"_chkCurrentCommunities").checked)
		{
			statusChanged = 'true';
		}
		
		counter++;
	}
	
	counter = 0;
	while(document.getElementById("dlOtherCommunities__ctl"+ counter +"_chkOtherCommunities") != null)
	{
		if (document.getElementById("dlOtherCommunities__ctl"+ counter +"_chkOtherCommunities").checked)
		{
			statusChanged = 'true';
		}
		
		counter++;
	}
	
	
	if (statusChanged == 'true')
	{
		if (window.confirm('Your settings have changed. Do you want to save these changes?'))
		{
			document.getElementById("hidConfirmResponse").value = 'true';
		}
		else
		{
			document.getElementById("hidConfirmResponse").value = 'false';
		}
	}	
}

/* FloatingDiv Start*/
function displayLoadingMessage()
{
	var loadingDiv = document.getElementById('loadingDiv');
	if (loadingDiv != null)
	{
		loadingDiv.style.display = "block";
		loadingDiv.className= "loading";
		startScroll = 1;		
	}
}

self.onError=null;
currentX = currentY = 0;  
whichIt = null;           
lastScrollX = 0; lastScrollY = 0;
NS = (document.layers) ? 1 : 0;
IE = (document.all) ? 1: 0;
FF = (NS || IE) ? 0 : 1;
startScroll = 0;

function timerHandler() {
	if (startScroll == 1)
	{
		if(IE) { diffY = document.body.scrollTop; diffX = document.body.scrollLeft; }
		if(FF) { diffY = document.body.scrollTop; diffX = document.body.scrollLeft; }
		if(NS) { diffY = self.pageYOffset; diffX = self.pageXOffset; }
		if(diffY != lastScrollY) {
			percent = .1 * (diffY - lastScrollY);
			if(percent > 0) percent = Math.ceil(percent);
			else percent = Math.floor(percent);
			if(IE) document.all.loadingDiv.style.pixelTop += percent;
			if(FF) 
			{ 
				posY = 0;
				if (document.getElementById('loadingDiv').style.top != '')
					posY = parseInt(document.getElementById('loadingDiv').style.top, 10);
				document.getElementById('loadingDiv').style.top = posY + percent + "px";
			}
			if(NS) document.loadingDiv.top += percent;
			lastScrollY = lastScrollY + percent;
		}
		if(diffX != lastScrollX) {
			percent = .1 * (diffX - lastScrollX);
			if(percent > 0) percent = Math.ceil(percent);
			else percent = Math.floor(percent);
			if(IE) document.all.loadingDiv.style.pixelLeft += percent;
			if(FF) 
			{
				posX = 0;
				if (document.getElementById('loadingDiv').style.left != '')
					posX = parseInt(document.getElementById('loadingDiv').style.left, 10);				
				document.getElementById('loadingDiv').style.left = posX + percent + "px";
			}
			if(NS) document.loadingDiv.left += percent;
			lastScrollX = lastScrollX + percent;
		}
	}
}

if(NS || IE || FF) action = window.setInterval("timerHandler()",1);


/* FloateingDiv End */

/***********************************************************************************************
    Firefox: reenable disabled buttons in case the users clicks on the browser "Back" button. 
***********************************************************************************************/
// The clicked button will save itself here:
var disabledButton;
// This will run when leaving the page in Firefox only (BasePage "onpagehide" event):
function reEnableButton() {
    if (disabledButton) {
        disabledButton.OnClick = function() { return false; };
        disabledButton.disabled = false;
    }
}

// Function to show a modal message inline.
function showInlineModalMessage(message) {
    var overlay = document.getElementById('overlay');
    var inlineModalBox = document.getElementById('inlineModalBox');
    var messageSpan = document.getElementById('inlineModalMessage');
    messageSpan.innerHTML = message;
    if (!insideIframe()) {
        addClass(overlay, 'filled-overlay');
    }
    overlay.style.display = 'block';
    inlineModalBox.style.display = 'block';
    return false;
}

// Function to show a modal message inline.
function hideInlineModalMessage() {
    var overlay = document.getElementById('overlay');
    var inlineModalBox = document.getElementById('inlineModalBox');
    if (overlay) overlay.style.display = 'none';
    if (inlineModalBox) inlineModalBox.style.display = 'none';
    return false;
}


// This function will try to call 'doRedirect()' function if it exists.
function tryRedirect() {
    if (typeof doRedirect == 'function') {
        stopRedirect = false;
        doRedirect();
    }
    else {
        hideInlineModalMessage();
    }
}


/***********************************************************************************************
    Util functions
***********************************************************************************************/
// Returns true if the current page is inside an iFrame, false otherwise.
function insideIframe() {
    return window != window.parent
}

// Adds a css class to an element.
function addClass(element, value) {
    if (!element.className) {
        element.className = value;
    } else {
        var newClassName = element.className;
        newClassName += " ";
        newClassName += value;
        element.className = newClassName;
    }
}


/***********************************************************************************************
    Event handling
***********************************************************************************************/
var timerID = 0;
var stopRedirect = false;
addEventHandlers();

function onLoadHandler() {
    if (insideIframe()) {
        timerID = setTimeout('doResize()', 100);
    }
    else { 
        // Show header and footer
        var header = document.getElementById('ISGHeader')
        if (header) header.style.display = 'block';
        var footer = document.getElementById('ISGFooter')
        if (footer) footer.style.display = 'block';
    }
    if (!stopRedirect) tryRedirect();
}

function onResizeHandler() {
    if (insideIframe()) {
        doResize();
    }
}

// Add handlers ------------------------------------------------------------
function addEventHandlers()
{
	if (window.addEventListener)
	{
		window.addEventListener("resize", onResizeHandler, false);
		window.addEventListener("load", onLoadHandler, false)
	}
	else if (window.attachEvent)
	{
		window.attachEvent("onresize", onResizeHandler);
		window.attachEvent("onload", onLoadHandler, false)
	}
	else
	{
		window.onResize = onResizeHandler
		window.onLoad = onLoadHandler
	}
}



