function wizytowka(id, w, h) {
	window.open('/popup/?act=wizytowka&id='+id, '', 'menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=no, resizable=no, width='+w+', height='+h+', left=150, top=150');
}

function oiw (w, h, src)
{
   window.open ('/popup/?act=show_popup_photo&src='+src+'&w='+w+'&h='+h, '', 'menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=no, resizable=no, width='+w+', height='+h+', left=150, top=150');
}

function polec(url, w) {
	window.open('/popup/?act=polec&w=' + w + '&link=' + url, '', 'menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=no, resizable=no, width=300, height=280, left=400, top=400');
}

function oiw_imp (w, h, src, id_imp)
{
   window.open ('/popup/?act=show_popup_photo&src='+src+'&w='+w+'&h='+h, '', 'menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=no, resizable=no, width='+w+', height='+h+', left=150, top=150');
}
function addcomm (idt, idk)
{
   window.open ('/popup/?act=show_popup_opinia&idt='+idt+'&idk='+idk, 'add_c', 'menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=no, resizable=no, width=300, height=280, left=400, top=400');
}

function addcommrep (idt, idk, p)
{
   window.open ('/popup/?act=show_popup_opinia&idt='+idt+'&idk='+idk+'&p='+p, 'add_c', 'menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=no, resizable=no, width=300, height=280, left=400, top=400');
}

function editcomm(id) 
{
   window.open ('/popup/?act=edit_opinia&id='+id, 'edit_c', 'menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=no, resizable=no, width=300, height=280, left=400, top=400');
}

function addvote (idt, idk)
{
   window.open ('/popup/?act=show_popup_glos&idt='+idt+'&idk='+idk, 'add_v', 'menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=no, resizable=no, width=160, height=120, left=600, top=300');
}

function cennik (idt, idk, typ)
{
   window.open ('/popup/?act=show_popup_cennik&idt='+idt+'&idk='+idk+'&typ='+typ, 'cennik', 'menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=no, width=295, height=500, left=600, top=300');
}

function change_style (theRow, newColor)
{
 var theCells = null;

    if (typeof(theRow.style) == 'undefined') { return false; }
    if (typeof(document.getElementsByTagName) != 'undefined') { theCells = theRow.getElementsByTagName('td'); }
    else if (typeof(theRow.cells) != 'undefined') { theCells = theRow.cells; }
    else { return false; }
	
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    
	if (typeof(window.opera) == 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') { domDetect    = true; }
    else { domDetect    = false; }
	
    if (newColor) {
        var c = null;
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
        }   } 
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
    }   }   }
  return true;
}

function change_class(theRow, newClass) {
 var theCells = null;

    if (typeof(theRow.style) == 'undefined') { return false; }
    if (typeof(document.getElementsByTagName) != 'undefined') { theCells = theRow.getElementsByTagName('td'); }
    else if (typeof(theRow.cells) != 'undefined') { theCells = theRow.cells; }
    else { return false; }
	
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    
	if (typeof(window.opera) == 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') { domDetect    = true; }
    else { domDetect    = false; }
	
    if (newClass) {
        var c = null;
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('class', newClass, 0);
        }   } 
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.className = newClass;
    }   }   }
  return true;
}

 function show(id){
   document.getElementById(id).style.visibility="visible";
}

function hide(id){
   document.getElementById(id).style.visibility="hidden";
}

function showhide(id) {
   switch (document.getElementById(id).style.visibility) {
      case '': document.getElementById(id).style.visibility="visible"; break
      case 'hidden': document.getElementById(id).style.visibility="visible"; break
      case 'visible': document.getElementById(id).style.visibility="hidden"; break
   }
}

function showmenu(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
if (d) {d.style.display='block';}
}

function zliczaj(nr_l, nr_t, maxlen) {
  with(document.forms[0]) {

    var count = document.getElementById(nr_t).value.length;

    prawdziwa = count;

    document.getElementById(nr_l).value = maxlen - count;

    if (count>maxlen) {
        document.getElementById(nr_t).value = document.getElementById(nr_t).value.substring(0,maxlen);
        document.getElementById(nr_l).value = 0;
        alert("Maksymalna długość to " + maxlen +"!");
    }
  } 
}

function setCheckboxesRange(the_form, selector, basename, min, max)
{
	var do_check = document.forms[the_form].elements[selector].checked;
	for (var i = min; i < max; i++) {
        if (typeof(document.forms[the_form].elements[basename + i]) != 'undefined') {
            document.forms[the_form].elements[basename + i].checked = do_check;
        }
        if (typeof(document.forms[the_form].elements[basename + i + 'r']) != 'undefined') {
            document.forms[the_form].elements[basename + i + 'r'].checked = do_check;
        }
    }

    return true;
}

function miasta_multi_select(select, forbiden) {
	var is_forbiden_selected = false;
	for(i=0;i<select.options.length;i++) {
		if(i == forbiden && select.options[i].selected) {
			is_forbiden_selected = true;
			break;
		}
	}
	if(is_forbiden_selected) {
		for(i=0;i<select.options.length;i++) {
			if(i!=forbiden) {
				select.options[i].selected = true;
			}
		}
		select.options[forbiden].selected = false;
	}
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

var auto_expand_idk = 0;
var auto_expand_ida = 0;

function auto_expand() {
	if(auto_expand_idk > 0 && auto_expand_ida > 0) {
		rozwinnext(auto_expand_idk, auto_expand_ida);
	}
}

function rozwinnext(idk, ida) {
	setTimeout("rozwin("+idk+", "+ida+");", 10);
}

function rozwin(idk, ida) {
	document.getElementById('comment_child_'+idk).style.display='block';
	document.getElementById('img_'+idk).src='/gfx/ico_minus.gif';
	xajax_get_comment_children(idk, ida);
}

function validate_podpisform() {
	var f = document.podpisform;
	var fields = new Array();
	var comments = new Array();
	var flag = true;
	var email = /\b(^(\S+@)([a-zA-Z0-9\-]+\.)+(com|net|edu|mil|gov|org|int|info|([a-zA-Z]{2}))$)\b/i

	fields[0] = f.imie; comments[0] = 'Uzupełnij pole "Imię"';
	fields[1] = f.nazwisko; comments[1] = 'Uzupełnij pole "Nazwisko"';
	fields[2] = f.uczelnia; comments[2] = 'Uzupełnij pole "Uczelnia"';
	fields[3] = f.miasto; comments[3] = 'Wybierz miasto w którym studiujesz';
	fields[4] = f.email; comments[4] = 'Podaj poprawny adres e-mail';

	for(var i=0;i<5 && (flag == true);i++) {
		fields[i].style.background = '#fff';
		if(fields[i].value == "" || fields[i].value == "undefined" || fields[i].value == 0 || fields[i].value == "-" || fields[i].value == " ") {
			alert(comments[i]);
			fields[i].style.background = '#ffec82';
			fields[i].focus();
			flag = false;
		} else if(i==4 && !email.test(f.email.value)) {			
			alert(comments[i]);
			fields[i].style.background = '#ffec82';
			fields[i].focus();
			flag = false;
		} else {
			flag=true;
		}
	}
	return flag;
}

function podpisForm() {
	alert('cos');
	$("#dodaj_podpis").slideUp('slow');
}

////AJAX
function addOption(selectId, txt, val)
{
    var objOption = new Option(txt, val);
    document.getElementById(selectId).options.add(objOption);
}