
function divFlip(divId)
{
	if(document.getElementById(divId).style.display=='none') 
	{
		document.getElementById(divId).style.display='block';
	}
	else
	{
		document.getElementById(divId).style.display='none';
	}
}
function divHide(divId)
{
	document.getElementById(divId).style.display='none';
}
function divShow(divId)
{
	document.getElementById(divId).style.display='block';
}
function NewWindow(sUrl, sTitle, sWidth, sHeight, sScrollable) 
{
	var iLeft = (screen.width - sWidth) / 2;
	var iTop = (screen.height - sHeight) / 2;

	var oNewWindow = window.open(sUrl, sTitle, 'height='+sHeight+',width='+sWidth+',top='+iTop+',left='+iLeft+',scrollbars='+sScrollable+',resizable=yes');

	if (oNewWindow && oNewWindow.open && !oNewWindow.closed)
	{
		oNewWindow.window.focus();
	}
	return oNewWindow;
}

var oPoppedWindow = null;

function ClosePoppedWindows()
{
	if (oPoppedWindow && oPoppedWindow.open && !oPoppedWindow.closed)
	{
		oPoppedWindow.close();
	}
}

function ResourceManager(return_function)
{	
	var height = 520;
	var width = 725;
	var scroll = 'no';
	
	win = NewWindow('ResourceManager.aspx?select_function='+return_function,'dep_search',width,height,scroll);
}

function ContentEditor(sIdContent, sPage, sCode, iSortOrder)
{
	if (isNaN(iSortOrder))
		iSortOrder = 100;
		
	sQuery = '?';
	if (sIdContent != null)
		sQuery += 'id_content=' + sIdContent + '&';
	sQuery += 'page=' + sPage + '&code=' + sCode + '&sort_order=' + iSortOrder;
	
	var sUrlNoProt = document.location.href.substring(document.location.protocol.length + 2);
	var aUrl = sUrlNoProt.split('/');
	
	var sBase = document.location.protocol + "//" + document.location.host;
	if (sBase.indexOf('localhost') > -1)
	    sBase += '/' + aUrl[1];
	    
	win = NewWindow(sBase + "/Utility/ContentEditor.aspx" + sQuery,'content_editor','725','600','yes');
}

function popup_ForgotPassword()
{
	oPoppedWindow = NewWindow("",'pu_forgot_password',450,300,"no");
}

function ChangeCheckBoxState(id, checkState)
{
    var cb = document.getElementById(id);
    if (cb != null)
       cb.checked = checkState;
}
function ChangeAllCheckBoxStates(checkState)
{
    // Toggles through all of the checkboxes defined in the CheckBoxIDs array
    // and updates their value to the checkState input parameter
    if (CheckBoxIDs != null)
    {
        for (var i = 0; i < CheckBoxIDs.length; i++)
           ChangeCheckBoxState(CheckBoxIDs[i], checkState);
    }
}
function ChangeHeaderAsNeeded()
{
    // Whenever a checkbox in the GridView is toggled, we need to
    // check the Header checkbox if ALL of the GridView checkboxes are
    // checked, and uncheck it otherwise
    if (CheckBoxIDs != null)
    {
        // check to see if all other checkboxes are checked
        for (var i = 1; i < CheckBoxIDs.length; i++)
        {
            var cb = document.getElementById(CheckBoxIDs[i]);
            if (!cb.checked)
            {
                // Whoops, there is an unchecked checkbox, make sure
                // that the header checkbox is unchecked
                ChangeCheckBoxState(CheckBoxIDs[0], false);
                return;
            }
        }
        
        // If we reach here, ALL GridView checkboxes are checked
        ChangeCheckBoxState(CheckBoxIDs[0], true);
    }
}