SwitchLayer = ShowHide= function(id, pForceHide){
	el = V(id);
	if(undefined == el){
	  return;
	}
	if (el.style.display != 'block')	{
		el.style.display = 'block';
	}
	else	{
		el.style.display = 'none';
	}
	
	if(true == pForceHide){
	  el.style.display = 'none';
	}
}

/** 
  * Chowa i pokazuje menu ukrywajac jednoczesnie wszystkie inne poprzednio uzyte
  */
showHideMenu = function(pID){
   
  var el = V(pID);
  if(typeof last_el != 'undefined' && last_el != el){
    last_el.style.display = 'none';
  }
  
  SwitchLayer(pID);
  
  last_el = el;
}

/**
  * Otwiera tutorial w nowym oknie
  */
function openVideoTutorial(url) {
	var win_width = 820;
	var pos = window.screen.width - win_width;
	win = window.open(mainurl + 'u/tutorials/'+url,'','toolbar=0,width='+win_width+',height=620,left=' + pos + ',top=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0');	
}

/**
  * mini console.log czyli wysmienity debugger od FireBuga
  */
if('undefined' == typeof console){
  console = { log: function(pPar){
    if(1 < arguments.length){
      return;
    }
    
    var out = pPar;
    if('object' == typeof pPar){
      out = '';
      for(i in pPar){
        out = out +  "[" + i + "] => " + pPar[i] + "\n";
      }
    }
    alert(out);
  }};
}

/** Browser object detector 
  *
  *	window.ie - will be set to true if the current browser is internet explorer (any).
	* window.ie6 - will be set to true if the current browser is internet explorer 6.
	* window.ie7 - will be set to true if the current browser is internet explorer 7.
	* window.gecko - will be set to true if the current browser is Mozilla/Gecko.
	* window.opera - is set to true by opera itself.
  */
if (window.ActiveXObject) window.ie = window[window.XMLHttpRequest ? 'ie7' : 'ie6'] = true;
else if (document.getBoxObjectFor != null) window.gecko = true;

/*@@#@ PONIĹ»EJ jest kilka funkcji wykorzystywanych przez system. MoĹĽna to nazwaÄ‡ 'mini frameworkiem JS' @#@@*/
/* 
 * UsprawniajÄ… i przyspieszajÄ… pisanie kodu. Bo, zamiast document.getElementById('id') wystarczy V('id') 
 * i daje to tez mozliwoĹ›Ä‡ uĹĽycia: V('id').getChildren() wszystkich dzieci obiektu.
 */

/**
  * Skrot do pobierania elementow, odpowiednik `document.getElementById`
  */
V = function(pEl){ var el = null; if('object' == typeof pEl || 'function' == typeof pEl) el = pEl; else if('string' == typeof pEl) el = document.getElementById(pEl);  else return undefined; if(undefined != el){ for(i in V){if('prototype' != i)el[i] = eval('V.'+i);}};return el;}

/**
  * Zwraca wszystkie dzieci danego elementu pEl, rowniez dziala na V().getChildren()
  * 
  * Ale uwaga, jesli jest tylko jedno dziecko to zostanie zwrocone jako obiekt a nie tablica
  */
V.getChildren = function(pEl){pEl = V(pEl) || V(this); var all_children = []; for(i in pEl.childNodes){ if(1 == pEl.childNodes[i].nodeType) all_children.push(V(pEl.childNodes[i])); } if(1 == all_children.length)all_children =all_children[0]; return all_children; }

/**
  * Zwraca rodzica danego elementu pEl, rĂłwnieĹĽ dziaĹ‚a na V().getParent()
  */
V.getParent = function(pEl){ pEl = V(pEl) || V(this); return V(pEl.parentNode);}

/**
  * Funkcje chowajÄ…ce i pokazujÄ…ce element. Toggle robi to naprzemian
  */
V.hide = function(pEl){ pEl = V(pEl) || V(this); pEl.setStyle('display', 'none');}
V.show = function(pEl){ pEl = V(pEl) || V(this); pEl.setStyle('display', '');}
V.toggle = function(pEl){ pEl = V(pEl) || V(this); if( 'block' != pEl.getStyle('display'))pEl.show();else pEl.hide();}

/**
  * Funkcje operujace na stylach.
  *
  * Nazwy w peĹ‚ni odzwierciedlajÄ… to co funkcje robiÄ…:
  */
  
/**
  * Zwraca wartoĹ›Ä‡ prawdziwego stylu. Takze jesli zostal on ustawiony tylko w CSS
  */
V.getStyle = function(pStyleName, pEl){ 
  pEl = V(pEl) || V(this); 
  var result = pEl.style[pStyleName];
  
  if('' != result){
    return result;
  }
  
  if (pEl.currentStyle){
    result = pEl.currentStyle[pStyleName];
  }
  else if (window.getComputedStyle){
    result = document.defaultView.getComputedStyle(pEl, null).getPropertyValue(pStyleName);
  }
  
  return result;
}
  
V.getStyles = function(pEl){ pEl = V(pEl) || V(this); return pEl.style;}
V.setStyle = function(pStyleName, pValue, pEl){ pEl = V(pEl) || V(this); pEl.style[pStyleName] = pValue;}
V.setStyles = function(pStyleObj, pEl){ pEl = V(pEl) || V(this); for(style_name in pStyleObj) pEl.setStyle(style_name, pStyleObj[style_name]);}

/**
  * Dodaje event do elementu
  */
V.addEvent = function(pType, pFn, pEl){ pEl = V(pEl) || V(this); if (pEl.addEventListener){pEl.addEventListener(pType.replace(/^on/, '').toLowerCase(), pFn, false); } else if (pEl.attachEvent){pEl.attachEvent(pType, pFn);}return pEl;};

/**
  * Dodaje dziecko do elementu pEl
  */
V.addChild = function(pObj, pEl){pEl = V(pEl) || V(this); pObj = V(pObj); pEl.appendChild(pObj); return pObj;};
V.addBefore = function(pObj, pEl){pEl = V(pEl) || V(this); pObj = V(pObj); pObj.getParent().insertBefore(pEl, pObj); return pObj;};
V.addAfter = function(pObj, pEl){pEl = V(pEl) || V(this); pObj = V(pObj); pObj.getParent().insertBefore(pEl, pObj.nextSibling); return pObj;};
V.remove = function(pEl){pEl = V(pEl) || V(this); if('function' != typeof pEl)pEl.parentNode.removeChild(pEl); return pEl;};
V.create = function(pTag, pProperties){  var pEl = V(document.createElement(pTag)); if(pProperties)pEl.setProperty(pProperties);  return pEl;};
V.setProperty = function(pProps, pEl){ pEl = V(pEl) || V(this); for(propName in pProps){ pEl.setAttribute(propName, pProps[propName]);} return pEl;};
V.getProperty = function(pPropName, pEl){ pEl = V(pEl) || V(this); return pEl.getAttribute(pPropName);};
V.removeProperty = function(pPropName, pEl){  pEl = V(pEl) || V(this); return pEl.removeAttribute(pPropName);};
V.addClass = function(pClassName, pEl){pEl = V(pEl) || V(this); if(pEl.className && !pEl.className.match(new RegExp(pClassName))) pEl.className += ' '+pClassName;  return pEl;};
V.removeClass = function(pClassName, pEl){pEl = V(pEl) || V(this); if(pEl.className && pEl.className.match(pClassName)) pEl.className = pEl.className.replace(new RegExp(pClassName, 'g'), '');  return pEl;};
V.toggleClass = function(pRemoveClass, pAddClass, pEl){pEl = V(pEl) || V(this); pEl.removeClass(pRemoveClass); pEl.addClass(pAddClass); return pEl;};

/** 
  * zwraca element formularz o podanym name/id
  */
$F = function(pEl){ if('object' == typeof pEl && 'FORM' == pEl.tagName) return V(pEl); else if('string' == typeof pEl) return V(document.forms[pEl]); else return null;}

/** 
  * zwraca element formularza formularz o podanym name/id i pozwala na odwolywanie sie do jego wlasciwosci. 
  */
$FE = function(pFormEl, pEl){ pFormEl = $F(pFormEl); pEl = V(pEl) || pEl;  
  if('string' == typeof pEl){ 
    pEl = {id: pEl}; 
  } 
  pEl = pFormEl.elements[pEl.id || pEl.name]; 
  if(pEl.length && 'number' == typeof pEl.length && !pEl.tagName){
    for(i in pEl){
      if(parseInt(i) >= 0){
        pElC = V(pEl[i]);
        if('block' == pElC.getStyle('display')){ 
          return pElC; 
        }
      }
    }
    return pEl;
  }
  else{ 
    return V(pEl); 
  }
}

function goToGoVemma(pAction, pSubAction, pParams){
	
	pParams = pParams || false;
	
	var form = document.createElement('form');
	form.target = '_blank';
	form.id = 'goToGoVemma';
	form.action = config_vemmamail + '?_task='+pAction+'&_action='+pSubAction;
	form.style.visibility = 'hidden';
	form.method = 'post';
	
	var _autologin = document.createElement('input');
	_autologin.type = 'hidden';
	_autologin.name = '_autologin';
	_autologin.value = 'vs';
	
	var _user = document.createElement('input');
	_user.type = 'hidden';
	_user.name = '_user';
	_user.value = session_main_webmail;
	
	var _pass = document.createElement('input');
	_pass.type = 'hidden';
	_pass.name = '_pass';
	_pass.value = session_vs_password;
	
	form.appendChild(_autologin);
	form.appendChild(_user);
	form.appendChild(_pass);
	
	if(false != pParams){
		var params_count = pParams.length;
		for(var i=0; i < params_count; i++){
			var field = document.createElement('input');	
			field.type = 'hidden';
			field.name = pParams[i][0];
			field.value = pParams[i][1];
			form.appendChild(field);
		}
	}
	
	document.body.appendChild(form);

	form.submit();
	document.body.removeChild(form);
		
}

function finderSendEmailByGoVemma(pId){
	
	advAJAX.post({
			url:mainurl+'ajax/getEmailById.php',
			id:pId,
			onLoading:function(){
				
			},
			onSuccess:function(obj){
				goToGoVemma('mail', 'compose', [['_to', obj.responseText]]);
			}
	});
}
	
function finderSendInvitationByGoVemma(pId){

	advAJAX.post({
			url:mainurl+'ajax/getEmailById.php',
			id:pId,
			onLoading:function(){
				
			},
			onSuccess:function(obj){
				
				var subject = system_var_subject;
				var message = system_var_message;

				goToGoVemma('mail', 'compose', [['_to', obj.responseText], ['_subject', subject], ['_message', message]]);
			}
	});
	
}

function finderCreateConference(pId){

	var form_obj = document.createElement('form');
	form_obj.action = mainurl + 'meeting/panel/conference/create/'; 
	form_obj.method = 'POST';
	form_obj.target = '_blank';
	form_obj.id = 'post_form';
	
	var input_obj = document.createElement('input');
	input_obj.type = 'hidden';
	input_obj.name = 'contacts[0][user_id]';
	input_obj.value = pId;
	form_obj.appendChild(input_obj);
	
	var input_obj = document.createElement('input');
	input_obj.type = 'hidden';
	input_obj.name = 'contacts[0][group_id]';
	input_obj.value = '-1';
	form_obj.appendChild(input_obj);
	
	document.body.appendChild(form_obj);
	form_obj.submit();

	document.body.removeChild(form_obj);
}


