function showPanel()
{
	var loadingPanel = document.getElementById('loading');
	
	if (loadingPanel != null)
	{
		loadingPanel.style.display = '';
	}
}

function hidePanel()
{
	var loadingPanel = document.getElementById('loading');
	
	if (loadingPanel != null)
	{
		loadingPanel.style.display = 'none';
	}
}
/***************************************************************************************/

/************************************Cookie*********************************************/

function Delete_Cookie(name, path, domain)
{
	if (Get_Cookie(name))
		document.cookie = name + "=" + 
						((path) ? ";path=" + path : "") +
						((domain) ? ";domain=" + domain : "") +
						";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function Get_Cookie(name)
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;

	if (((!start) && (name != document.cookie.substring(0, name.length))) || (start == -1))
		return null;

	var end = document.cookie.indexOf(";", len);
	if (end == -1) 
		end = document.cookie.length;

	return unescape(document.cookie.substring( len, end ));
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	Delete_Cookie(name, '/', '');

    //set time, it's in milliseconds
	var today = new Date();
	today.setTime(today.getTime());

	if (expires)
		expires = expires * 1000 * 60 * 60 * 24;

	
	var expires_date = new Date(today.getTime() + (expires));

	document.cookie = name + "=" +escape(value) +
						((expires) ? ";expires=" + expires_date.toGMTString() : "") + 
						((path) ? ";path=" + path : "") + 
						((domain) ? ";domain=" + domain : "") +
						((secure) ? ";secure" : "");
}
/***************************************************************************************/

function setClass(obj, cl){
	if (obj != null)
		if (obj.className!=cl) obj.className = cl;
}

function setClassById(objid, cl){
	if (!cl) cl = '';
	document.getElementById(objid).className = cl;
}

function changeDisplayById(objId)
{
	for (c = 0; c < changeDisplayById.arguments.length; c++){
		obj = document.getElementById(changeDisplayById.arguments[c]);
		if (obj.style.display == 'none') obj.style.display = '';
		else obj.style.display = 'none';
	}
}

function gotoURL(url)
{
	if (!url) url = "/";
	    if (window.event)
	    {
		    var src = window.event.srcElement;
		    
		    if (src == null)
		        document.location = url;
		    else
		        if((src.tagName != 'A') && ((src.tagName != 'IMG') || (src.parentElement.tagName != 'A')))
		        {
			        if (window.event.shiftKey) window.open(url);
			        else document.location = url;
	            }
	    } 
	    else 
	        document.location = url;
}


function popupURL(url){
	window.open(url,'','resizable=yes, scrollbars=yes,width=720,height=550');
}

function OpenPopup(url, params ,w ,h){
	var width = (w ? w : 366);
	var height = (h ? h : 250);
	return showModalDialog(url, params, 'dialogWidth:' + width + 'px; dialogHeight:' + height + 'px; resizable:no; status:no;help:no');
}


function OpenStandartPopup(url, n, w, h){
	var width = (w ? w : 366);
	var height = (h ? h : 250);
	var name = (n ? n : '');
	var handler = window.open(url,n,'resizable=yes, scrollbars=yes,width=' + width + ',height=' + height + '');
	handler.focus();
	return handler;
}


function getLeftPos(obj){
	var res = 0;
	while (obj){
		res += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return res;
}

function getTopPos(obj){
	var res = 0;
	while (obj){
		res += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return res;
}

function CheckAll(checkName, checkVal)
{
	var checkCount = 0;
	var el = document.forms[0].elements;
	for (count = 0; count < el.length; count++)
	{
		if (el[count].id == checkName + checkCount)
		{
			if (!el[count].disabled)
			{
				el[count].checked = checkVal;
			}
			checkCount++;
		}
	}
	var help = '_all';
	el = document.getElementById(checkName + help)
	el.checked = checkVal;
}

function GetSelected(checkName)
{
	
	var el = document.forms[0].elements;
	var arr = new Array();
	var boxCount = 0;
	for (count = 0; count < el.length; count++)
	{
		var elem = el[count];
		if (elem.id == checkName + boxCount)
		{
			boxCount++;
			if (elem.checked && !elem.disabled)
				arr.push(elem.value);
		}
	}
	return arr;
}

function ExamAll(checkName, resName)
{
	var checkCount = 0;
	var boxCount = 0;
	var el = document.forms[0].elements;
	for (count = 0; count < el.length; count++)
	{
		if (el[count].id == checkName + boxCount)
		{
			boxCount++;
			if (el[count].checked || el[count].disabled) checkCount++;
		}
	}
	
	if (document.forms[0].elements[resName])
	{
		document.forms[0].elements[resName].checked = (checkCount == boxCount);
	}
}

function exitProcedure() 
{
	if(opener)
	{
		opener.location.reload(); 
	}
	window.close(); 
}

function chbIsAllEmpty(checkName)
{
	var checkCount = 0;
	var boxCount = 0;
	var el = document.forms[0].elements;
	
	for (count = 0; count < el.length; count++)
	{
		if (el[count].name == checkName + boxCount)
		{
			boxCount++;
			if (el[count].checked) checkCount++;
		}
	}
	
	return (checkCount == 0)
}

function setCheckBox(drop_c){
	document.getElementById(drop_c).checked = false;
}

function control_perm(obj0, obj1) {
	if (obj0.checked)
		obj1.checked = false;
	else
	    obj1.checked = true;	
		
}


function SendRequest(url, callbackFunction)
{
    var xmlRequest, e;
    
    try 
    {
        xmlRequest = new XMLHttpRequest();
    }
    catch(e)
    {
        try 
        {
            xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e) {}
    }
    
    xmlRequest.open("POST", url, true);
    xmlRequest.onreadystatechange = callbackFunction;
    xmlRequest.send('empty');
    
    return xmlRequest;
}


/*Ajax PostBack*/
function doAjaxPostBack(hiddenFieldID, controlID, eventArgs) 
{
    var hiddenField = document.getElementById(hiddenFieldID);
    
    if (hiddenField)
    {
        hiddenField.value = eventArgs;
    }
    
    __doPostBack(controlID, '');
}

function forbiddenCheckBoxChecked(checkBox, message)
{
  checkBox.checked = true;
  alert(message);
}

function loadChartControlsVisibleMode(checkBoxID, rowID)
{
  var chartCheckBox = document.getElementById(checkBoxID);
  var chartPropertyControlsRow = document.getElementById(rowID);
  
  if(chartCheckBox.checked)
  {
    chartPropertyControlsRow.style["display"] = "";
  }
  else
  {
    chartPropertyControlsRow.style["display"] = "none";
  }
}

function loadPieControlsVisibleMode(checkBoxID)
{
  var chartCheckBox = document.getElementById(checkBoxID);
  var pieChartPropertyControlsRow = document.getElementById('pieChartPropertyControlsRow');
  
  if(chartCheckBox.checked)
  {
    pieChartPropertyControlsRow.style["display"] = "";
  }
  else
  {
    pieChartPropertyControlsRow.style["display"] = "none";
  }
}