var ApplicationPath = "/";
var winModalWindow;
var agt=navigator.userAgent.toLowerCase();
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_mac = (agt.indexOf("mac")!=-1);

function confirm_delete(msg) 
			{
			if (confirm(msg)==true) 
			return true; 
			else 
			return false; 
		}

function IgnoreEvents(e)
{
	return false;
}

function ShowWindow(urlToOpen, title, width, height)
{
    if(DataSmartShowURL)
        DataSmartShowURL(urlToOpen, title, width, height);
    else
        alert("There is no DataSmart Generic URL Shower on the page!");
}

function HandleFocus()
{
	if (winModalWindow) {
		if (!winModalWindow.closed) {
			winModalWindow.focus();
		} else {
			window.top.releaseEvents (Event.CLICK|Event.FOCUS);
		}
	}
	return false;
}

function confirm_logout() 
			{
			if (confirm("Are you sure you wish to log off?")==true) 
			return true; 
			else 
			return false; 
		}

function checkAll(cblId)
{
    var numberOfChecked = 0;
    var allInputs = document.getElementsByTagName("input");
    for(i=0; i<allInputs.length; i++)
    {
        if( (allInputs[i].type=="checkbox") && (allInputs[i].id.indexOf(cblId) != -1) && (allInputs[i].checked == false) && (allInputs[i].disabled == false))
        {
            allInputs[i].checked=true;
            numberOfChecked++;
        }
    }
    return numberOfChecked;
}

function uncheckAll(cblId)
{
    var numberOfUnchecked = 0;
    var allInputs = document.getElementsByTagName("input");
    for(i=0; i<allInputs.length; i++)
    {
        if( (allInputs[i].type=="checkbox") && (allInputs[i].id.indexOf(cblId) != -1)  && (allInputs[i].checked == true) && (allInputs[i].disabled == false))
        {
            allInputs[i].checked=false;
            numberOfUnchecked++;
        }
    }
    return numberOfUnchecked;
}

function trimString(strToTrim)
{
    return strToTrim.replace(/^\s+|\s+$/g,"");
}

var clockID = 0;
var clockDisplayer;
var serverTime;
function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
   serverTime.setSeconds(serverTime.getSeconds() + 1);
   var dateTimeString = serverTime.getDate() < 10 ? "0" + serverTime.getDate() : serverTime.getDate();
   dateTimeString += "/";
   dateTimeString += serverTime.getMonth() < 9 ? "0" + (serverTime.getMonth() + 1) : (serverTime.getMonth() + 1);
   dateTimeString += " ";
   dateTimeString += serverTime.getHours() < 10 ? "0" + serverTime.getHours() : serverTime.getHours();
   dateTimeString += ":";
   dateTimeString += serverTime.getMinutes() < 10 ? "0" + serverTime.getMinutes() : serverTime.getMinutes();
   dateTimeString += ":";
   dateTimeString += serverTime.getSeconds() < 10 ? "0" + serverTime.getSeconds() : serverTime.getSeconds();
   clockDisplayer.innerHTML = dateTimeString;  
   clockID = setTimeout("UpdateClock()", 1000);
}
function StartClock(displayIn, year, month, day, hour, minute, second) {
   clockDisplayer = displayIn;
   serverTime = new Date(year, month, day, hour, minute, second);
   clockID = setTimeout("UpdateClock()", 500);
}

function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}

function ExpandRightBottomPanel()
{

}

function CollapseRightBottomPanel()
{

}

function after_SplitterPanelResize(resizedPanel, panelID)
{
    if(typeof resizeTab == "function")
        resizeTab(panelID);
}

function Anthem_PreCallBack() 
{
    CreateLoadingOverlay();
}

function Anthem_CallBackCancelled() 
{
	RemoveLoadingOverlay();
}

function Anthem_PostCallBack() 
{
	RemoveLoadingOverlay();
}


function CreateLoadingOverlay()
{
    //HideComboboxes();
    var imgLoading = document.createElement("img");
    imgLoading.src = ApplicationPath + "Assets/Images/loading.gif";
    imgLoading.height = 40;
    imgLoading.width = 40;
    imgLoading.id = "imgLoading";
    var overlayDiv = document.createElement("div");
    overlayDiv.id = "callbackOverlayDiv";
    document.body.appendChild(imgLoading);
    document.body.appendChild(overlayDiv);
    ResizeLoadingOverlay();
    if(typeof window.onresize == "function")
    {
        var oldOnResize = window.onresize;
        window.onresize = function(){oldOnResize();ResizeLoadingOverlay();};
    }
}

function RemoveLoadingOverlay()
{
    ShowComboboxes();
    var imgLoading = document.getElementById("imgLoading");
    document.body.removeChild(imgLoading);
    var overlayDiv = document.getElementById("callbackOverlayDiv");
    document.body.removeChild(overlayDiv);
}

function ResizeLoadingOverlay()
{
    var overlayDiv = document.getElementById("callbackOverlayDiv");
    /*var imgLoading = document.getElementById("imgLoading");
    imgLoading.style.top = (document.documentElement.clientHeight / 2) + "px";*/
    overlayDiv.style.height = document.documentElement.clientHeight + "px";
    overlayDiv.style.width = "100%";
}

function HideComboboxes()
{
    var allSelects = document.getElementsByTagName("select");
    for(i=0; i<allSelects.length; i++)
        allSelects[i].style.visibility = "hidden";
}

function ShowComboboxes()
{
    var allSelects = document.getElementsByTagName("select");
    for(i=0; i<allSelects.length; i++)
        allSelects[i].style.visibility = "visible";
}

function stopEvent(event){
    if(event.stopPropagation)
        event.stopPropagation();
    else
        event.cancelBubble=true;
}

var selectedNode;
function tree_SelectNode(node) {
    if ((typeof(node) != "undefined") && (node != null)) 
    {
        if(selectedNode != null)
        {
            selectedNode = WebForm_GetParentByTagName(selectedNode, "A");
	        WebForm_RemoveClassName(selectedNode, "selectedNode_A");
	        selectedNode = WebForm_GetParentByTagName(selectedNode, "TD");
	        WebForm_RemoveClassName(selectedNode, "selectedNode_TD");
        }
    }
    selectedNode = node;
    node = WebForm_GetParentByTagName(node, "A");
    WebForm_AppendToClassName(node, "selectedNode_A");
    node = WebForm_GetParentByTagName(node, "TD");
    WebForm_AppendToClassName(node, "selectedNode_TD");
}
