function trim(str)
{
	str = '' + str;
	var re = /^ */;
	var res = str.replace(re, '');
	re = / *$/;
	return(res.replace(re, ''));
}

(function($) {
$.fn.collapsor = function(settings) { 
	settings = $.extend({}, $.fn.collapsor.defaults, settings);
	
	var trigger = this;
	var panel = settings.panelElement;
	
	return this.each(function() {

	$(this).click(function() {
						  
			if ($(trigger).hasClass(settings.openClass))
			{
				$(trigger).removeClass(settings.openClass);
				$(panel).hide();
			}
			else 
			{
				$(trigger).addClass(settings.openClass);
				$(panel).show();
			}
	   });
	});
};
$.fn.collapsor.defaults = {
	openClass:'main-layout-divider-expanded',
	panelElement: ''
};
})
(jQuery);

$((function(){
	$('.main-layout-divider').collapsor({panelElement:'.main-layout-first-panel'});
}));

function initMenu() {
  $('.secondary-nav ul').hide();
  $('.secondary-nav li a').click(
    function() {
      var checkElement = $(this).next();
      if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
        return false;
        }
      if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
		$('.secondary-nav a').removeClass('expanded');
		$(this).addClass('expanded');
        $('.secondary-nav ul:visible').slideUp('quick');
		 checkElement.slideDown('normal');
        return false;
        }
      }
    );
  }
$(document).ready(function() {initMenu();});

function bodySize()
{
	var $resizebleBlocks = $('.main-layout-resizable-area > td');
	var $topPanel = $('.top-panel');
	$resizebleBlocks.css ({height:'auto'});
	$resizebleBlocks.css ({ height: $('body').height()-$topPanel.height() });	
}
var winIE = (navigator.userAgent.indexOf("Opera")==-1 && (document.getElementById && document.documentElement.behaviorUrns)) ? true : false;
if (winIE) onload = bodySize;
if (winIE) onresize = bodySize;


if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

function OpenStandartPopup(url, n, w, h){
	var width = (w ? w : 400);
	var height = (h ? h : 400);
	var name = (n ? n : '');
	var handler = window.open(url,n,'resizable=yes, scrollbars=yes,width=' + width + ',height=' + height + '');
	handler.focus();
	return handler;
}

function clearDatePicker(hiddenId, hiddenValueId, textBoxId)
{
  var datePicker = document.getElementById(hiddenId);
  datePicker.value = "";
  datePicker.defaultValue = "";
  datePicker = document.getElementById(hiddenValueId);
  datePicker.value = "";
  datePicker.defaultValue = "";
  datePicker = document.getElementById(textBoxId);
  datePicker.value = "  /  /    ";
  datePicker.defaultValue = "  /  /    ";
}

function InsertValue(str_TextId, str_Text, str_HiddenId, str_Value)
{
    var objForm = window.document.forms[0];
    var objTextIdShown = objForm[str_TextId];
    if (objTextIdShown != null)
    {
        objTextIdShown.value = str_Text;
    }
    else
    {
        alert('ERROR inserting value!');
    }    
    var objHiddenControlId = objForm[str_HiddenId];
    if (objHiddenControlId != null)
      objHiddenControlId.value = str_Value;
      
    AddCommand(str_Text, str_Value);
}

function AddParametersValue(str_TextId, str_Text, str_HiddenTextId, str_HiddenText, str_HiddenId, str_Value)
{
    var objForm = window.document.forms[0];
    var objTextIdShown = objForm[str_TextId];
    if (objTextIdShown != null)
    {
        objTextIdShown.value += str_Text;
    }
    else
    {
        alert('ERROR inserting value!');
    }    
    
    var objHiddenTextIdShown = objForm[str_HiddenTextId];
    if (objHiddenTextIdShown != null)
    {
        objHiddenTextIdShown.value += str_HiddenText;
    }
    else
    {
        alert('ERROR inserting value!');
    }    

    var objHiddenControlId = objForm[str_HiddenId];
    if (objHiddenControlId != null)
    {
      objHiddenControlId.value = str_Value;
    }
    
    AddCommand(str_Text, str_HiddenText);
}

function AddContentItemValue(str_TextId, str_Text, str_HiddenTextId, str_HiddenText, str_HiddenItemId, str_ItemId)
{
    var objForm = window.document.forms[0];
    var objTextIdShown = objForm[str_TextId];
    str_Text = unescape(str_Text);
    
    if (objTextIdShown != null)
    {
        objTextIdShown.value += str_Text;
    }
    else
    {
        alert('ERROR inserting value!');
    }    
    
    var objHiddenTextIdShown = objForm[str_HiddenTextId];
    if (objHiddenTextIdShown != null)
    {
        objHiddenTextIdShown.value += str_HiddenText;
    }
    else
    {
        alert('ERROR inserting value!');
    }    

    var objHiddenControlId = objForm[str_HiddenItemId];
    if (objHiddenControlId != null)
    {
      objHiddenControlId.value = str_ItemId;
    }
    
    AddCommand(str_Text, str_HiddenText);
}

//UI
UI = function(){}

UI.Get = function UI$Get(id) {
    return document.getElementById(id);
}

UI.Hide = function UI$Hide(id) {
    var element = UI.Get(id);
    if (element) element.style.display = 'none';
}

UI.Show = function UI$Show(id) {
    var element = UI.Get(id);
    if (element) element.style.display = '';
}

UI.SetValue = function UI$SetValue(id, value) {
    var element = UI.Get(id);
    if (element) element.value = value;
}

UI.Clear = function UI$Clear(id) {
    UI.SetValue(id, '');
}

function isAnyCheckBoxChecked()
{
    var el = document.forms[0].elements;
    var checkedCount = 0;
    for (count = 0; count < el.length; count++)
	{
		if (el[count].type == 'checkbox')
		{
			if(el[count].checked)
			{
			    checkedCount++;
			}
		}
	}
	return checkedCount == 0 ? false : true;
}
