function setClass(obj, cl){
	if (obj != null && obj.className!=cl) {
	  obj.className = cl;
	}
}

function makeGray (obj, state, text){
	if (state && (obj.value == '')){
		obj.value = text;
	} else if (!state && (obj.value == text)){
		obj.value = '';
	}
}


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 = 'block';
		else obj.style.display = 'none';
	}
}

function gotoURL(url, target, callback){
  
	if (!url) url = "/";

	if(typeof callback == "function")
		callback(url);

	if(target && target!='_self'){
		popupURL(url, target);
	}
	else{
		if (window.event){
			var src = window.event.srcElement;
			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, options){
	window.open(url, 'CoolWindow', options);
}

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(formObj, checkName, checkVal){
	var el = formObj.elements;
	for (count = 0; count < el.length; count++)
		if (el[count].name == checkName + '[]')
			if (!el[count].disabled) el[count].checked = checkVal;
}

function ExamAll(formObj, checkName, resName){
	var checkCount = 0;
	var boxCount = 0;
	var el = formObj.elements;
	for (count = 0; count < el.length; count++)
		if (el[count].name == checkName + '[]'){
			boxCount++;
			if (el[count].checked || el[count].disabled) checkCount++;
		}
	formObj.elements[resName].checked = (checkCount == boxCount);
}

function CheckAll(checkName, checkVal)
{
	var checkCount = 0;
	var el = document.forms[0].elements;
	for (count = 0; count < el.length; count++)
	{	  
		if (el[count].name == checkName)
		{
			if (!el[count].disabled)
			{
				el[count].checked = checkVal;
			}
			checkCount++;
		}
	}
}

function checkAllByPrefix(checkName, checkVal)
{
	var checkCount = 0;
	var el = document.forms[0].elements;
	for (count = 0; count < el.length; count++)
	{	  
		if (el[count].name != null && el[count].name.indexOf(checkName) == 0)
		{
			if (!el[count].disabled)
			{
				el[count].checked = checkVal;
			}
			checkCount++;
		}
	}
}

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].name == checkName)
		{
			boxCount++;
			if (el[count].checked || el[count].disabled) checkCount++;
		}
	}
	
	if (document.forms[0].elements[resName])
		document.forms[0].elements[resName].checked = (checkCount == boxCount);
}

function examAllByPrefix(checkName, resName)
{
	var checkCount = 0;
	var boxCount = 0;
	var el = document.forms[0].elements;
	
	for (count = 0; count < el.length; count++)
	{
		if (el[count].name != null && el[count].name.trim() != '' && el[count].name.indexOf(checkName) == 0)
		{
			boxCount++;
			if (el[count].checked || el[count].disabled) checkCount++;
		}
	}
	
	if (document.forms[0].elements[resName])
		document.forms[0].elements[resName].checked = (checkCount == boxCount);
}

function chbIsAllEmpty(formObj, checkName){
	var checkCount = 0;
	var boxCount = 0;
	var el = formObj.elements;
	for (count = 0; count < el.length; count++)
		if (el[count].name == checkName + '[]'){
			boxCount++;
			if (el[count].checked) checkCount++;
		}
	return(checkCount == 0);
}

function chbIsOnlyOne(formObj, checkName){
	var checkCount = 0;
	var boxCount = 0;
	var el = formObj.elements;
	for (count = 0; count < el.length; count++){
		if (el[count].name == checkName + '[]'){
			boxCount++;
			if (el[count].checked) checkCount++;
		}
	}
	return(checkCount == 1);
}

function disableAll(){
	for (c1 = 0; c1 < document.forms.length;  c1++){
		var formElements = document.forms[c1].elements;
		for (c2 = 0; c2 < formElements.length;  c2++) formElements[c2].disabled = true;
	}
}

// name - cookie name
// value - cookie value
// [expires] - Date object (by default cookie expires at the end of browser session)
// [path]
// [domain]
// [secure]
function setCookie(name, value, expires, path, domain, secure)
{
	var curCookie = name + "=" + escape(value) +
                ((expires) ? "; expires=" + expires.toGMTString() : "") +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                ((secure) ? "; secure" : "")

	if ( (name + "=" + escape(value)).length <= 4000)
		document.cookie = curCookie
}

// name - cookie name
function getCookie(name)
{
        var prefix = name + "="
        var cookieStartIndex = document.cookie.indexOf(prefix)
        if (cookieStartIndex == -1)
                return null
        var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
        if (cookieEndIndex == -1)
                cookieEndIndex = document.cookie.length
        return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}

// name - cookie name
// [path]
// [domain]
function deleteCookie(name, path, domain)
{
	if (getCookie(name))
	{
		document.cookie = name+"="+
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                "; expires=Thu, 01-Jan-70 00:00:01 GMT"
	}
}


function preLoad() {
	if(document.images)  {
		var argLen = arguments.length;
		for(var i = 0; i < argLen; i++) {
			var arg = arguments[i];
			self[arg] = new Image();
			self[arg].src = arg;
		}
	}
}

function ch_img(obj, img ) {
	if (self[img]) {
		obj.src = self[img].src;
	}
}

function mm_act(obj,img,cl,num,selected){
	
	if ( cl == 'item act' )
		showMenu(obj, num);
	else
		hideMenu(obj, num);
	
	if ( selected ) return;
	
	while (obj) {
		obj = obj.childNodes[0];
		if ( obj && obj.tagName == 'IMG') {
			ch_img(obj,img);
			break;
		}
	}
	
	while (obj && cl!='') {
		obj = obj.parentNode;
		if ( obj && obj.tagName == 'DIV') {
			obj.className = cl;
			break;
		}
	}
}

function popup_view (url, w, h, wname) {
	scr_left = 0;
	scr_top = 0;
	wname = wname;
	new_window = window.open (url, wname , "title=image,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,width="+w+",height="+h+",top="+scr_top+",left="+scr_left);
	new_window.focus();
	return new_window;
}

function openPopupWithARgs (url, w, h, wname, openArgs) {
	scr_left = 0;
	scr_top = 0;
	new_window = window.open (url, wname , "title=image,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,width="+w+",height="+h+",top="+scr_top+",left="+scr_left);
	window.setTimeout(function() {
	  try {
	    new_window.setOpenArgs(openArgs);
	  } 
	  catch(e) {
	    new_window.close();
	  }
	}, 3000);
	new_window.focus();
	return new_window;
}

function LTrim(str)
{
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(0)) != -1) {
    var j=0, i = s.length;
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
    j++;
    s = s.substring(j, i);
  }

  return s;
}

function RTrim(str)
{
  var whitespace = new String(" \t\n\r");

  var s = new String(str);

  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {

    var i = s.length - 1;      
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
      i--;
    s = s.substring(0, i+1);
  }

  return s;
}

function Trim(str)
{
  return RTrim(LTrim(str));
}

function headerKeydown(Url, Header)
{
    var reg = /[\x21-\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5e\x60\x7b\x7d\xa3]/ig;
    var regAnd = /&/ig;
    var regS = /[\s\x2f]/ig;

    var val = Trim(Header.value.toLowerCase()).replace(reg,"").replace(regAnd,"and").replace(regS,"-").replace(/\x2D{2,}/ig,'-');
    
    //Url.value = (val.length > 0) ? val + ".aspx" : "";
    Url.value = val;
}

function checkSelection(checkName) {
	var checkCount = 0;
	var el = document.forms[0].elements;
	for (count = 0; count < el.length; count++)
	{	  
		if (el[count].name != null && el[count].name.indexOf(checkName) == 0)
		{
			if (!el[count].disabled)
			{
				if (el[count].checked) {
			    checkCount++;				  
				}
			}
		}
	}
	if (checkCount == 0) {
	  alert('You must check any item!');
	  return false;
	}
	return true;
}

function deleteConfirmation(checkName) {
  if (!checkSelection(checkName)) {
    return false;
  }
  if (!confirm('You are trying to delete item(s). \n\nAre you sure you wish to continue?')) {
    return false;
  }
  else {
    return true;
  }
}

function showConfirmation(text) {
  return confirm(text);
}

var checkedCount = 0;

function updateCheckedCount(checkBox) {
  if (checkBox.checked) {
    checkedCount += 1;
  }
  else {
    checkedCount -= 1;  
  }
}

var allCheckedChildren = null;

function checkAllChild(id, checked) {
  var cell = document.getElementById('subItems' + id);
  if (cell != null) {  
    checkChild(cell, checked);
  }
}

function checkChild(element, checked) {
  if (element.tagName != 'TABLE' && element.tagName != 'TBODY' && element.tagName != 'TR' && element.tagName != 'TD' && element.tagName != 'DIV') {
    return;
  }
  if (element.childNodes != null) {
    var i = 0;
    for (i = 0; i < element.childNodes.length; i++) {
      if (element.childNodes[i].type == 'checkbox') {
        element.childNodes[i].checked = checked;        
        element.childNodes[i].disabled = checked;
      }      
      checkChild(element.childNodes[i], checked);      
    }    
  }  
}

function deleteFromTreeConfirmation() {
  if (checkedCount <= 0) {
    alert('You must check any item!');  
    return false;
  }
  if (!confirm('You are trying to delete item(s). \n\nAre you sure you wish to continue?')) {
    return false;
  }
  else {
    return true;
  }
}

function checkedChanged(id, list)
{
    if (typeof list[id] != "undefined" && list[id].checked)
    {
        for (var i=0; i<list.length; ++i)
        {
            if (i != id)
            {
                list[i].checked = false;
            }
        }
    }
}

function isIE() {
  return (navigator.userAgent.indexOf('MSIE') != -1 && navigator.userAgent.indexOf('Opera') == -1);
}

function isOpera() {
  return (navigator.userAgent.indexOf('Opera') != -1);
}

function isFirefox() {
  return (navigator.userAgent.indexOf('Firefox') != -1 && navigator.userAgent.indexOf('Opera') == -1);
}

function isMozila() {
  return (navigator.userAgent.indexOf('Mozila') != -1 && navigator.userAgent.indexOf('Opera') == -1 && navigator.userAgent.indexOf('MSIE') == -1);
}

var isModified = false;
var isNew = false;
var saveButtonId = '_saveButton_';
var textAreas = '';
var isValid = true;

function tabMenuRedirect(url, postBackReference) {
  if (isNew || isModified || !isValid) {
    if (confirm('You should save your changes before proceeding to the next step!')) {
      eval(postBackReference);
    }
  }
  else {
    window.location = url;
  }
}

function changeSaveButtonEnabled(enable) {
  saveButton = document.getElementById(saveButtonId);
  if (saveButton != null) {
    if (enable) {
      saveButton.disabled = '';
      saveButton.setAttribute('class', 'buttons');
      isModified = true;
    }
    else {
      saveButton.disabled = 'disabled';
      saveButton.setAttribute('class', 'buttons-disabled');      
    }
  }
}

function addTextArea(textAreaId) {
  if (textAreas.length > 0) {
    textAreas += ",";
  }
  textAreas += textAreaId;
}

function getFrameContent(frame) {
  return frame.contentDocument;
}

function fckEditorOnFocus(editorInstance) {
  changeSaveButtonEnabled(true);
}

function initializetextArea(textAreaId) {
  if (isOpera()) {
    for (i = 0; i < 10; i++) {
      textAreaId = textAreaId.replace('_', '$');
    }
    textArea = document.getElementById(textAreaId);    
    if (textArea == null) {
      return true;
    }
    textArea.setAttribute('onkeyup','changeSaveButtonEnabled(true)');
    return true;
  }
  if (window.FCKeditorAPI == null) {
    return false;
  }
  var editorInstance = FCKeditorAPI.GetInstance(textAreaId) ; 
  if (editorInstance != null) {
    editorInstance.Events.AttachEvent( 'OnFocus', fckEditorOnFocus ) ;
  }  
  return true;
}

function setTabItemVisibility(idElement, visible) {
  element = document.getElementById(idElement);
  if (element == null) {
    return false;
  }
  if (visible) {
    displayValue = '';
  }
  else {
    displayValue = 'none';
  }
  element.style.display = displayValue;
  tabRow = document.getElementById('TabMenuTableRow');
  var i = 0;
  var offSet = 1;
  if (isFirefox()) {
    offSet = 2;
  }
  for (;i < tabRow.childNodes.length; i++) {
    if (tabRow.childNodes[i] == element) {
      if (i > offSet) {
        tabRow.childNodes[i - offSet].style.display = displayValue;
      }
      else {
        tabRow.childNodes[i + offSet].style.display = displayValue;     
      }
      return true;      
    }
  }
  return true;  
}

function removeFile(UploadRowId, PreviewRowId, StateId) {
  uploadRow = document.getElementById(UploadRowId);
  previewRow = document.getElementById(PreviewRowId);  
  stateField = document.getElementById(StateId);
  if (uploadRow == null || previewRow == null || stateField == null) {
    return;
  }
  uploadRow.style.display = '';
  previewRow.style.display = 'none';
  stateField.value = 'True';
}

function findLink(parentElement, text) {
  if (parentElement.childNodes != null) {
    var i = 0;
    for (i = 0; i < parentElement.childNodes.length; i++) {
      if (parentElement.childNodes[i].tagName == 'A' && parentElement.childNodes[i].innerHTML == text) {
        return parentElement.childNodes[i];
      }
      else {
        result = findLink(parentElement.childNodes[i], text);
        if (result != null) {
          return result;
        }
      }      
    }
    return null;    
  }  
}

function changeTreeNodeVisibility(linkElement, visibile) {
  if (linkElement == null) {
    return;
  }
  temp = linkElement;
  while (temp != null && temp.tagName != 'TABLE') {
    temp = temp.parentNode;
  }
  if (temp != null) {
    if (visibile) {
      temp.style.display = '';
    }
    else {
      temp.style.display = 'none';
    }
  }
}

function hideElement(id) {
  hidedEelement = document.getElementById(id);
  if (hidedEelement != null) {
    hidedEelement.style.display = 'none';
  }
}


function doCustomPostBack(controlID, eventArgs) {
  document.getElementById('CustomPostBackEventArgs').value = eventArgs;
  __doPostBack(controlID, '');
}

function doAjaxControlPostBack(containerID, controlID, eventArgs) {
  document.getElementById('CustomPostBackEventArgs' + containerID).value = eventArgs;
  __doPostBack(controlID, '');
}

function initLoadingHint(){
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(showLoadingHint);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(hideLoadingHint);
}
 
 
function showLoadingHint()
{
  setClass(document.getElementById('LoadingHint'), 'PreloaderImageActive');
  loadingHintBackground = document.getElementById('LoadingBackground'); 
  if (loadingHintBackground != null)
  {  
    loadingHintBackground.style.display = '';
    loadingHintBackground.style.width = document.body.offsetWidth + 'px';
    loadingHintBackground.style.height = document.body.offsetHeight + 'px';
    loadingHintBackground.width = 10;
    loadingHintBackground.height = 10;
  }
}

var goOnPageTop = false;

function hideLoadingHint()
{  
  if (goOnPageTop)
  {
	  window.setTimeout(function() {
	    try {
	      scroll(0,0);
	    } 
	    catch(e) {
	      new_window.close();
	    }
	  }, 1000);
	  goOnPageTop = false;
	}
  setClass(document.getElementById('LoadingHint'), 'PreloaderImageInactive');
  loadingHintBackground = document.getElementById('LoadingBackground'); 
  if (loadingHintBackground != null)  
  {
    loadingHintBackground.style.display = 'none';
    loadingHintBackground.style.width = '0px';
    loadingHintBackground.style.height = '0px';
  }  
}

function keyUpHandler (eventArgs, containerID, controlID, postBackEventArgs) {
    key = eventArgs.which;
    if (key == 13) {
      doAjaxControlPostBack(containerID, controlID, postBackEventArgs);
      return false;
    }
    return true;
}

function MyClass()
{
        this.UpdateEditorFormValue = function()
        {
                for ( i = 0; i < parent.frames.length; ++i )
                        if ( parent.frames[i].FCK )
                                parent.frames[i].FCK.UpdateLinkedField();
        }
        this.UpdateEditorFormValueParent = function(site)
        {
                for ( i = 0; i < site.parent.frames.length; ++i )
                {
                        if ( site.parent.frames[i].FCK ) {
                                site.parent.frames[i].FCK.UpdateLinkedField();
                        }
                }
        }
}

var MyObject = new MyClass();

function setRelatedPosition(parentControlID, controlID) {
    parentControl = document.getElementById(parentControlID);
    control = document.getElementById(controlID);
    if (control != null && parentControl != null)  {
      leftOffset = control.offsetWidth + 180;
      topOffset = 0;
      control.style.left = control.offsetLeft + leftOffset + 'px';
      control.style.top = control.offsetTop + topOffset + 'px';
    }
}

function switchEditors(editorDivID, sType)
{
  oNode = document.getElementById(editorDivID);
  if (oNode != null) {
    var i=0;
    for (i=0;i<oNode.childNodes.length;i++) {
      childNode = oNode.childNodes.item(i);
      editor = FCKeditorAPI.GetInstance(childNode.name);
      if (editor && editor.EditorDocument && editor.EditMode == FCK_EDITMODE_WYSIWYG) {
        editor.EditorDocument.designMode = sType;
      }
      switchElementEditors(childNode,sType);
    }
  }
}

function switchElementEditors(oNode, sType) {
    var i=0;
    for (i=0;i<oNode.childNodes.length;i++) {
      childNode = oNode.childNodes.item(i);
      editor = FCKeditorAPI.GetInstance(childNode.name);
      if (editor && editor.EditorDocument && editor.EditMode == FCK_EDITMODE_WYSIWYG) {
        editor.EditorDocument.designMode = sType;
      }
      switchElementEditors(childNode,sType);
    }
}

function changeFileUploadImage(fileName, uploadClientID, imagePreviewID, uploadButtonID, deleteButtonID, hiddenFieldID, imageBaseDirectory) {
  previewImage = document.getElementById(uploadClientID + imagePreviewID);
  uploadButton = document.getElementById(uploadClientID + uploadButtonID);
  deleteButton = document.getElementById(uploadClientID + deleteButtonID);
  fileNameHiddenField = document.getElementById(uploadClientID + hiddenFieldID);
  if (previewImage != null && uploadButton != null && deleteButton != null && fileNameHiddenField != null) {
    fileNameHiddenField.value = fileName;
    previewImage.src = imageBaseDirectory + fileName;
    uploadButton.style.display = 'none';
    deleteButton.style.display = 'block';
  }
}

function changeFileUploadLinkName(fileName, uploadClientID, fileNameLinkID, uploadButtonID, deleteButtonID, hiddenFieldID, fileBaseDirectory) {
  fileNameLink = document.getElementById(uploadClientID + fileNameLinkID);
  uploadButton = document.getElementById(uploadClientID + uploadButtonID);
  deleteButton = document.getElementById(uploadClientID + deleteButtonID);
  fileNameHiddenField = document.getElementById(uploadClientID + hiddenFieldID);
  if (fileNameLink != null && uploadButton != null && deleteButton != null && fileNameHiddenField != null) {
    fileNameHiddenField.value = fileName;
    fileNameLink.href = fileBaseDirectory + fileName;
    fileNameLink.innerHTML = fileName;
    uploadButton.style.display = 'none';
    deleteButton.style.display = 'block';
  }  
}

// If NS -- that is, !IE -- then set up for mouse capture
if (!isIE) {
 document.captureEvents(Event.MOUSEMOVE)
 document.captureEvents(Event.MOUSECLICK)
}

// Temporary variables to hold mouse x-y pos.s
var tempX = 0;
var tempY = 0;

window.onmouseover = onMouseMove;

function onMouseMove(eventArgs) {
  if (!eventArgs) {
    eventArgs = window.event;
  }
  if (isIE) { // grab the x-y pos.s if browser is IE
    tempX = eventArgs.clientX + document.body.scrollLeft;
    tempY = eventArgs.clientY + document.body.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    tempX = eventArgs.pageX;
    tempY = eventArgs.pageY;
  }  
  // catch possible negative values in NS4
  if (tempX < 0) {
    tempX = 0;
  }
  if (tempY < 0) {
    tempY = 0;
  }  
  loadingHint = document.getElementById('LoadingHintArea'); 
  if (loadingHint != null)
  {  
    loadingHint.style.left = tempX + 5 + 'px';
    loadingHint.style.top = tempY + 5 + 'px';    
  }  
  return true;
}