﻿function highlightTab(tabID)
{
    for(var i = 0; i<10; i++)
    {
        if(document.getElementById('tab' + i))
        {
                document.getElementById('tab' + i).className = 'tab_off';
        }    
    }
    if(document.getElementById(tabID))
    {
        if(document.getElementById(tabID).className == 'tab_off')
        {
            document.getElementById(tabID).className = 'tab_on';
        }
    }
    hidePanel();
    showDefaultTab();
}

function showDefaultTab()
{
    var tabID = document.getElementById('defaultTabOn').value;
    highlightDefaultTab(tabID);
}

function highlightDefaultTab(tabID)
{
    if(document.getElementById(tabID))
    {
        if(document.getElementById(tabID).className == 'tab_off')
        {
            document.getElementById(tabID).className = 'tab_on';
        }
    }
}

function highlightLine(lineID, bDo)
{
    if(document.getElementById('gridLine_' + lineID))
    {
        if(bDo)
        {
            document.getElementById('gridLine_' + lineID).bgColor = '#fb5500';
        }
        else
        {
            document.getElementById('gridLine_' + lineID).bgColor = '';
        }
    }
}

function openTD(iApplciationID)
{
    window.location = 'ShowApplication.aspx?applicationID=' + iApplciationID;
}

function doAction(result)
{
    showModal1(result);
}

function doTimeout()
{
    alert('timout');
}

function doContext()
{
    alert('timout');
}

ModalPopup = function (elem,options) {
	options = options || {};
	var HasBackground = (options.HasBackground!=null)?options.HasBackground:true;
	var BackgroundColor = options.BackgroundColor || '#000000';
	var BackgroundOpacity = options.BackgroundOpacity || 60; // 1-100
	BackgroundOpacity = (BackgroundOpacity > 0) ? BackgroundOpacity : 1;
	var BackgroundOnClick = options.BackgroundOnClick || function(){};
	var BackgroundCursorStyle = options.BackgroundCursorStyle || "default";
	var Zindex = options.Zindex || 90000;
	var AddLeft = options.AddLeft || 0; //in px
	var AddTop = options.AddTop || 0; //in px

	function _Convert(val) {
		if (!val) {return;}
		val = val.replace("px","");
		if (isNaN(val)) {return 0;}
		return parseInt(val);
	}
	var popup = document.getElementById(elem);
	if (!popup) {return;}
	var winW = (document.layers||(document.getElementById&&!document.all)) ? window.outerWidth : (document.all ? document.body.clientWidth : 0);
	var winH = window.innerHeight ? window.innerHeight :(document.getBoxObjectFor ? Math.min(document.documentElement.clientHeight, document.body.clientHeight) : ((document.documentElement.clientHeight != 0) ? document.documentElement.clientHeight : (document.body ? document.body.clientHeight : 0)));
	popup.style.display = "block";
	popup.style.visibility = "visible";
	var currentStyle;
	if (popup.currentStyle)	{ 
		currentStyle = popup.currentStyle; 
	}
	else if (window.getComputedStyle) {
		currentStyle = document.defaultView.getComputedStyle(popup, null);
	} else {
		currentStyle = popup.style;
	}

	var elemW = popup.offsetWidth -
		_Convert(currentStyle.marginLeft) -
		_Convert(currentStyle.marginRight) -
		_Convert(currentStyle.borderLeftWidth) -
		_Convert(currentStyle.borderRightWidth);

	var elemH = popup.offsetHeight -
		_Convert(currentStyle.marginTop) -
		_Convert(currentStyle.marginBottom) -
		_Convert(currentStyle.borderTopWidth) -
		_Convert(currentStyle.borderBottomWidth);

	popup.style.position = "fixed";
	popup.style.left = (winW/2 - elemW/2 + AddLeft) + "px";
	popup.style.top = (winH/2 - elemH/2 + AddTop - 10) + "px";
	popup.style.zIndex = Zindex + 1;
	
	if (HasBackground) {		
		if (!ModalPopup._BackgroundDiv) {
			ModalPopup._BackgroundDiv = document.createElement('div');
			ModalPopup._BackgroundDiv.style.display = "none";
			ModalPopup._BackgroundDiv.style.width = "100%";
			ModalPopup._BackgroundDiv.style.position = "absolute";
			ModalPopup._BackgroundDiv.style.top = "0px";
			ModalPopup._BackgroundDiv.style.left = "0px";
			document.body.appendChild(ModalPopup._BackgroundDiv);
		}
		ModalPopup._BackgroundDiv.onclick =  BackgroundOnClick;
		ModalPopup._BackgroundDiv.style.background = BackgroundColor;	
		ModalPopup._BackgroundDiv.style.height = document.all ? Math.max(Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight), Math.max(document.body.offsetHeight, document.body.scrollHeight)) : (document.body ? document.body.scrollHeight : ((document.documentElement.scrollHeight != 0) ? document.documentElement.scrollHeight : 0)) + "px";
		ModalPopup._BackgroundDiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + BackgroundOpacity +")";
		ModalPopup._BackgroundDiv.style.MozOpacity = BackgroundOpacity / 100;
		ModalPopup._BackgroundDiv.style.opacity = BackgroundOpacity / 100;
		ModalPopup._BackgroundDiv.style.zIndex = Zindex;
		ModalPopup._BackgroundDiv.style.cursor = BackgroundCursorStyle;

		ModalPopup._BackgroundDiv.style.display = "";
	}

}

ModalPopup.Close = function(id) {
	if (id) {
		document.getElementById(id).style.display = "none";
		document.getElementById(id).style.visibility = "hidden";
	} 
	if  (ModalPopup._BackgroundDiv) {
		ModalPopup._BackgroundDiv.style.display = "none";
	}
}

function ModalMessage(modMessage)
{
    document.getElementById('systemMessageText').innerHTML = modMessage
}

function closeModal()
{
    ModalPopup.Close('mySystemMessage');
}

function showModal1(sModalMessage)
{
    ModalPopup('mySystemMessage');
    ModalMessage(sModalMessage);
}

function randImage()
{
    var rand_no = Math.floor((10-4)*Math.random()) + 5;
    document.getElementById('randImage').src = '/images/icon/' + rand_no + '.png';
}

function showPanel(pSection)
{
    if(pSection == 'search')
    {   
        document.getElementById('panel').style.display = '';
    }
}

function hidePanel()
{
        document.getElementById('panel').style.display = 'none';    
}

function setStatusInTable()
{
    var s = document.getElementById('statusDiv').innerHTML;
    document.getElementById('applicationStatusDiv').innerHTML = s + '<br />' + 'סטטוס פנייה';
}

function goToStatus(statusID)
{
    window.location.href = 'Default.aspx?Status=' + statusID;
}

function setDefaultTab(tabID)
{
    document.getElementById('defaultTabOn').value = tabID;
    highlightDefaultTab(tabID);
}

function fitMessagesBackground()
{
    var sHeight = document.getElementById('show_application').offsetHeight;
    document.getElementById('masterMainContent').style.height = sHeight + 100 + 'px';
}