var idelement_focused='';

function isMaxLength(obj){ //maxlength 4 textareas
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if(obj.getAttribute && obj.value.length+1>mlength) return false;
}


function isMaxLength_validated(obj, e, regexp){ //maxlength 4 textareas with input validation
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""

	if(navigator.userAgent.indexOf('Gecko') != -1) charCode = e.which; else charCode = e.keyCode;
	if(charCode > 31 && obj.getAttribute && obj.value.length<mlength) {
		znak = String.fromCharCode(charCode);
		return regexp.test(znak);
	} else {
		return false;
	}

}


function input_validator(e, regexp) {
	if(navigator.userAgent.indexOf('Gecko') != -1) charCode = e.which; else charCode = e.keyCode;
	if(charCode > 31) {
		znak = String.fromCharCode(charCode);
		return regexp.test(znak);
	}
}


function get_url_params() {
	var idx=document.URL.indexOf('?');
	var url_params=new Array();
	if(idx!=-1) {
		var pairs=document.URL.substring(idx+1,document.URL.length).split('&');
		for(var i=0; i<pairs.length; i++) {
			nameVal=pairs[i].split('=');
			url_params[nameVal[0]]=nameVal[1];
	   }
	}
	return url_params;
}


function ulubione(){
	var title="bettina.pl"
	var url="http://www.bettina.pl/"

	if (window.sidebar) {
		window.sidebar.addPanel(title, url,"");
	} else if(window.opera && window.print) {
		var mbm = document.createElement('a');
		mbm.setAttribute('rel','sidebar');
		mbm.setAttribute('href',url);
		mbm.setAttribute('title',title);
		mbm.click();
	} else if(document.all) {
		window.external.AddFavorite(url,title);
	}
}



function check_email(forma) {
	if(forma.email.value.length > '0') {
		var re = new RegExp("[^@]{1,}[@]{1}[^@.]{1,}[.]{1}[^@]{1,}","gi");
		var wynik = re.test(forma.email.value);
		if (wynik == false) {
			alert('Nieprawidłowy adres E-mail!');
			forma.email.focus();
			return false;
		}
	} else {
		alert('Podaj adres E-mail!');
		forma.email.focus();
		return false;
	}
}


function show_hide(list) {
	var listElementStyle=document.getElementById(list).style; 
	if (listElementStyle.display=="none") {
		listElementStyle.display="inline";
	} else {
		listElementStyle.display="none";
	} 
}

function show_hide_block(list) {
	var listElementStyle=document.getElementById(list).style; 
	if (listElementStyle.display=="none") {
		listElementStyle.display="block";
	} else {
		listElementStyle.display="none";
	} 
}

function rozwin(list) {
	var listElementStyle=document.getElementById(list).style; 
	var tmp=list.split('kat_')
	var change=tmp[1];
	if (listElementStyle.display=="" || listElementStyle.display=="none") {
		listElementStyle.display="block";
		document.getElementById('k'+change).className='kat_selected';
	} else {
		listElementStyle.display="none";
		document.getElementById('k'+change).className='kat';
	} 
}


function link_potwierdzenie(link,pytanie) {
	var sprawdz = window.confirm(pytanie);
	if(sprawdz==true) window.location=link;
}


function usun_potwierdzenie() {
	var sprawdz = window.confirm('Na pewno usun±ć?');
	if(sprawdz==true) flash_upload_usun();
}


function search() {
	var szukaj=encodeURIComponent(document.getElementById('szukaj_main').value);
	if(szukaj.length>0 && szukaj!="%20") {
		window.location="/pcmaster/s="+szukaj;
	}
}


function toggleRows(man_id){
	var table=document.getElementById('sortable');
	var len=table.rows.length;
	var disp;

	for(i=1; i<len; i++) {
		if(table.rows[i].id!='m_'+man_id && man_id!="") disp="none"; else disp="";
		table.rows[i].style.display=disp;
	}
}


function ukryj_menu() {
	var elem1=document.getElementById('menu_cont').style; 

	if (elem1.display=="") {
		elem1.display="none";
		document.getElementById('menu_hider').className='menu_hider_right';
		document.getElementById('menu_hider').title='Pokaż menu';
	} else {
		elem1.display="";
		document.getElementById('menu_hider').className='menu_hider_left';
		document.getElementById('menu_hider').title='Ukryj menu';
	} 
}


function zaloguj(forma,sess_id) {
	advAJAX.post({
		url : "includes/logowanie.php?SID="+sess_id+"&source=top",
		parameters : { "login":forma.top_login.value, "pass":forma.top_pass.value }
	});
}


function zaloguj_center(forma,sess_id) {
	advAJAX.post({
		url : "includes/logowanie.php?SID="+sess_id+"&source=center",
		parameters : { "login":forma.center_login.value, "pass":forma.center_pass.value }
	});
}


function wyloguj(sess_id) {
	if(window.confirm('Na pewno chcesz się wylogować?')) {
		advAJAX.post({
			url : "includes/wyloguj.php?SID="+sess_id
		});
	}
}


function remove_html_element(parent_id, child_id) {
	var master_node=document.getElementById(parent_id);
	var len=master_node.childNodes.length;

	for(var i=0; i<len; i++) {
		if(master_node.childNodes[i].id==child_id) {
			master_node.removeChild(master_node.childNodes[i]);
		}
	}
}



function stripHTML(oldString) {
   var newString = "";
   var inTag = false;
   for(var i = 0; i < oldString.length; i++) {
        if(oldString.charAt(i) == '<') inTag = true;
        if(oldString.charAt(i) == '>') {
              inTag = false;
              i++;
        }
        if(!inTag) newString += oldString.charAt(i);
	}
   return newString;
}



var strefa=0;
function generate_search_url(forma) {
	var string=forma.s.value;
	var dzial=forma.s_k.value;

   if(dzial=="") dzial=0;
	if(string=="" || string==" ") return false;

   string=string.replace('"','');
   string=string.replace("'","");

	string=stripHTML(string);
	string=encodeURIComponent(string);

	document.location='szukaj,'+string+','+dzial+','+strefa+'.html';
}


















