/**showSubmenu(id)
 *
 */ 
function showSubmenu(id){
    if(($('submenu1').style.display!="none")&&(id!='submenu1')){
      jQuery('#submenu1').slideUp('slow');
    }
    if(($('submenu2').style.display!="none")&&(id!='submenu2')){
      jQuery('#submenu2').slideUp('slow');
		}
    if(($('submenu3').style.display!="none")&&(id!='submenu3')){
      jQuery('#submenu3').slideUp('slow');
    }
    if(($('submenu4').style.display!="none")&&(id!='submenu4')){
      jQuery('#submenu4').slideUp('slow');
    }
    if(($('submenu5').style.display!="none")&&(id!='submenu5')){
      jQuery('#submenu5').slideUp('slow');
    }
  if($(id).style.display=="none"){
    jQuery('#'+id).slideDown('slow');
  }else{
  }
}


/**showHideBox(id,idtxtopcja,show,hide)
 * pokazuje ukrywa box
 * @param id id pola do rozwiniecia
 * @param idtxtopcja id pola zawierajacego txt show/hide
 * @param show 
 * @param hide   
 */ 
function showHideBox(id){
  if($(id).style.display=="none"){
    jQuery('#'+id).slideDown('slow');
  }else{
    jQuery('#'+id).slideUp('slow');
  }
}

/**hideBox(id,idtxtopcja,show)
 * pokazuje ukrywa box
 * @param id id pola do rozwiniecia
 * @param idtxtopcja id pola zawierajacego txt show/hide
 * @param show 
 */ 
function hideBox(id,idtxtopcja,show){
    if($(id).style.display=="block"){
      jQuery('#'+id).slideUp('slow');
      $(idtxtopcja).innerHTML=show;
    }
}

/**showHideBox2(id)
 * pokazuje ukrywa box- rozwija z boku i gory
 * @param id id pola do rozwiniecia
 * @param idtxtopcja id pola zawierajacego txt show/hide
 * @param show 
 * @param hide   
 */ 
function showHideBox2(id,idtxtopcja,show,hide){
  if($(id).style.display=="none"){
    jQuery('#'+id) .show('slow');
    $(idtxtopcja).innerHTML=hide;
  }else{
    jQuery('#'+id) .hide('slow');
    $(idtxtopcja).innerHTML=show;
  }
}




function zmienStyl(url) {
  j=document.styleSheets.length;
  for(i=0;i<j;i++){
    if(document.styleSheets[i].title){
      alert(document.styleSheets[i].title);
      
      document.styleSheets[i].disabled = false;
    }
  }
  //document.styleSheets[0].href = './theme.classic.main2.css';
}









/**showalert(content,oklabel)
 * funkcja pokazuje okno alerta za pomoca biblioteki prototype window.
 * @param content - tresc alertu
 * @param oklabel - napis na inpucie ok
 */ 
function showalert(content,oklabel){
  Dialog.alert(
      content,
      {className:"alert",
       width:400,
       height:100,
       showEffect: Element.show,
       hideEffect: Element.hide,
       okLabel: oklabel,
       ok: closeAllModalWindows
      }
    );
  WindowCloseKey.init();
}

function closeAllModalWindows() {
    Windows.closeAllModalWindows();
    return true;
  }


function showInfo(content){
  Dialog.info(
    content,
    {
      showEffect: Element.show,
      hideEffect: Element.hide,
      showProgress: true
    }
    );
}

/**format(liczba, lmpp)
 * formatuje liczbe
 * @param liczba
 * @param lmpp liczba miejsc po przecinku
 * @return liczba   
 */ 
function format(liczba, lmpp) {
  ile = ""+Math.round(liczba*Math.pow(10,lmpp))/Math.pow(10,lmpp);
  if (ile.indexOf(".")<0) ile+=".0";
  while ((ile.length-ile.indexOf(".")-1)<lmpp) ile = ile+"0";
  return ile;
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


/**Trim(TheString)
 * Funkcja usuwajaca spacje z ciagu znakow
 * @param TheString
 * @return TheString  
 */ 
function trim(TheString){
	var len;

	len = TheString.length;
 	while(TheString.substring(0,1) == " "){ //trim left
 		TheString = TheString.substring(1, len);
  		len = TheString.length;
	}

 	while(TheString.substring(len-1, len) == " "){ //trim right
 		TheString = TheString.substring(0, len-1);
  		len = TheString.length;
 	}
 	return TheString;
}


/**countLength(id,idc,ileznakow)
 * licznik dlugosci tekstu mozliwego do wpisania
 * @param id - id inputa sprawdzanego
 * @param idc - id inputa wktory wpisuje ilosc pozostalych znakow
 * @param ileznakow - ile znakow mozliwych do wpisania    
 */
function countLength(id,idc,ileznakow) {
  var messageLength = ileznakow - document.getElementById(id).value.length;
  if (messageLength >= 0) {
    document.getElementById(idc).value=messageLength;
  } else {
    document.getElementById(idc).value=0;
  }
}