//wykrywanie przegladarki
var browsertype=null;

if (document.all) 	browsertype="IE";
if (document.layers) 	browsertype="NN";
if (!document.all && document.getElementById) 	browsertype="MO";


function SendRequest(adres) {
    
    var where='tresc_srodek';
    
	var req = mint.Request();
    req.Send(adres, where);
}

function SendRequest_change_value(adres, where) {
    
    if (where == '')
    	var where='tresc_srodek';
    
	var req = mint.Request();
	
   	req.OnSuccess = function() {
   		$(where).value = this.responseText;
    }
    req.Send(adres);
}

function SendRequestForm(adres, where) {
    
    var req = mint.Request();
    alert(adres);
  
   	req.OnSuccess = function() {
   		alert(this.responseText);
   		$(where).innerHTML = this.responseText;
    }

    
    req.SendForm("form", adres);
}

/**
* funkcja ktora zmienia wyswietlanie div-ow po id
*/

function SwitchVisibility(warstwa, cell){
  var div = null;
  var div_color = new Array();
  var i=0;

  if (document.getElementById){
    div = document.getElementById(warstwa);
    while(document.getElementById(cell+i)!=null){
      div_color[i] = document.getElementById(cell+i);
      i++;
    }
  }
  else if (document.all){
    div = document.all[warstwa];
    div_color = document.all[cell];
  }
  else if (document.layers){
    div = document.layers[warstwa];
    div_color = document.layers[cell];
  }
  if (!div) {	}
  else if (div.style){
    if (div.style.display != 'none'){
      div.style.display = 'none';
      for(var k=0;k<div_color.length;k++){
        div_color[k].className='menujsoff';
      }
    }
    else{
      if (browsertype=="IE") {
        div.style.display = 'block';
      } else {
        div.style.display = 'table-row';
        }
      for(var k=0;k<div_color.length;k++){
        div_color[k].className='menujson';
      }
    }
  } else {
    if (div.visibility == 'hidden'){
      div.visibility = 'show';
    }
    else{
      div.visibility = 'hidden';
    }
  }
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}


// funkcja do ukrywania warstwy
function Hide(warstwa){

var div = null;

  if (document.getElementById){
    div = document.getElementById(warstwa);
  }
  else if (document.all){
    div = document.all[warstwa];
  }
  else if (document.layers){
    div = document.layers[warstwa];
  }

  if (!div) {	}
  else if (div.style){
    if (div.style.display != 'none'){
      div.style.display = 'none';
    }
  } else {

      div.visibility = 'hidden';
  }
}

// funkcja do pokazywania warstwy
function Show(warstwa){

var div = null;

  if (document.getElementById){
    div = document.getElementById(warstwa);
  }
  else if (document.all){
    div = document.all[warstwa];
  }
  else if (document.layers){
    div = document.layers[warstwa];

  }
  if(!div){
    }
  else if (div.style){
      if (browsertype=='IE'){

        div.style.display = 'block';
      }
      else{
        div.style.display = 'table-row';
      }
  }
  else {
      div.visibility = 'show';
    }

}

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
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 menu_show_content(name)
  {
    if (getCookie(name))
      {
        return true;
      }
    else
      {
        return false;
      }
  }
  
function menu_swich_content(name)
  {
    if (menu_show_content(name))
      {
        menu_close_content(name);
      }
    else
      {
        menu_open_content(name);
      }
  }
  

function menu_open_content(name)
  {
    setCookie(name, 'true');
  }

function menu_close_content(name)
  {
    deleteCookie(name);
  }  
function SwitchVisibilityImproved(warstwa, cell){

	
  var goon = true;
  var field;
  var i=0;
  while (goon) {
    field = document.getElementById(warstwa+'-'+i);
    if (field) {
      
      Hide(warstwa+'-'+i, cell);
      i++;
    } else {
      goon=false;
    }
  }
  if(document.getElementById(warstwa+'-'+cell))
  		Show(warstwa+'-'+cell);
}

function SwitchVisibility_twoThings(warstwa1, warstwa2){

  if(document.getElementById(warstwa1).style.display == 'none')	{
  		Show(warstwa1);
  		Hide(warstwa2);
  }
  else
  {
  		Show(warstwa2);
  		Hide(warstwa1);
  }
}

function SwitchVisibilityOnOff(warstwa, cell){

	
  var goon = true;
  var onoff = false;
  var field;
  var i=0;
  while (goon) {
    field = document.getElementById(warstwa+'-'+i);
    
    if (field) {
      if (!onoff) {
      	
      	if(field.style.display == 'none')
      		onoff = 'on'
      	else
      		onoff = 'off'
      }
      
      if(onoff == 'off')
	    Hide(warstwa+'-'+i, cell);
	  else
      	Show(warstwa+'-'+i, cell);
      i++;
    } else {
      goon=false;
    }
  }
  if(document.getElementById(warstwa+'-'+cell))
  		Show(warstwa+'-'+cell);
}

function Switch_menu_content(warstwa, cell){

	
  var goon = true;
  var field;
  var i=0;
  while (goon) {
    field = document.getElementById(warstwa+'-'+i);
    if (field) {
      menu_close_content(warstwa+'-'+i)
      i++;
    } else {
      goon=false;
    }
  }
  if(document.getElementById(warstwa+'-'+cell))
  		menu_open_content(warstwa+'-'+cell);
}

function Switch_menu_content_Improved(warstwa){

  var goon = true;
  var field;
  var i=0;
  while (goon) {
  	field = document.getElementById(warstwa+'-'+i);
    if (field) {
      if(menu_show_content(warstwa+'-'+i))	{
  		Show(warstwa+'-'+i);
      }
      else	{
        Hide(warstwa+'-'+i);
      }
      i++;
    } else {
      goon=false;
    }
  }
}

  function addRow(id){
    var tbody = document.getElementById
	(id).getElementsByTagName("TBODY")[0];
    var row = document.createElement("TR")
    var td1 = document.createElement("TD")
    td1.appendChild(document.createTextNode("column 1"))
    var td2 = document.createElement("TD")
    td2.appendChild (document.createTextNode("column 2"))
    row.appendChild(td1);
    row.appendChild(td2);
    tbody.appendChild(row);
  }
  
	function switch_class(div, idParent, classname1, classname2)	{
		var parentId = document.getElementById(idParent);
		var Tags = parentId.getElementsByTagName("div"); 
			for (var i = 0; i < Tags.length; i++) { 
			    Tags[i].className = classname1;
			    }
		div.className = classname2;
	}
	
	function switch_class_onoff(div, classname1, classname2)	{
		
		if(div.className == classname1)
			div.className = classname2;
		else
			div.className = classname1;
	}
	
	function FormSubmit(hidden, action)	{
		
		ChangeInputValueById(hidden, action)
		document.form.submit();
	}
	
	function ChangeInputValueById(hidden, action)	{
		
		var change = document.getElementById(hidden);
		change.value = action;
	}
