var dv1;
var oft;
function pokaz_ukryj(id){
	div = document.getElementById(id);
	if (div.style.display=='none'){
		div.style.display = 'block';
	}else{
		div.style.display = 'none';
	}
}
function sg3_open_all(parent,child) {
	sd = document.getElementById(parent);
	chi = sd.childNodes;
	for(i = 0; i < chi.length; i++) {
		if(chi[i].className == child) {
			chi[i].style.display = 'block';
		}
	}
}
function sg3_close_all(parent,child) {
	sd = document.getElementById(parent);
	chi = sd.childNodes;
	for(i = 0; i < chi.length; i++) {
		if(chi[i].className == child) {
			chi[i].style.display = 'none';
		}
	}
}

function highlight_over(div,over) {
		div.style.backgroundColor = over;
}
function highlight_out(div,out) {
		div.style.backgroundColor = out;
}
function is_numeric( mixed_var ) {
    return !isNaN(mixed_var * 1);
}

function swap2(dv) {
	var d = document.getElementById(dv);
	if (dv=="libraries") {
		var b = document.getElementById('tdlibs');
		
	}
	

	
	if (d.style.display=="none") {
		d.style.display = "block";
		if (dv=="libraries") {		
			b.style.height="200";
		}	
	} else {
		if (dv=="libraries") {	
			b.style.height="0";
		}	
		d.style.display = "none";
	}
}

function showZastosowania(id)
{
  var p = document.getElementById('show_'+id);
  if(p.style.display=="block")
    p.style.display="none";
  else
    p.style.display="block";
}

function swap(dv) {
	var d = document.getElementById(dv);
	if (dv=="libraries") {
		var b = document.getElementById('tdlibs');
		
	}
	

	
	if (d.style.display=="none") {
		d.style.display = "block";
		if (dv=="libraries") {		
			b.style.height="200";
		}	
		foldifr.location.href="_actions/setfold.php?code=" + dv + "&foldtype=show";
	} else {
		if (dv=="libraries") {	
			b.style.height="0";
		}	
		d.style.display = "none";
		foldifr.location.href="_actions/setfold.php?code=" + dv + "&foldtype=hide";
	}
}	

function show(dv) {
	var d = document.getElementById(dv);
		if (dv=="libraries") {
		var b = document.getElementById('tdlibs');		
	}	
	d.style.display = "block";
		if (dv=="libraries") {		
		b.style.height="200";
	}	
		
	
}
function hide(dv) {
	var d = document.getElementById(dv);
		if (dv=="libraries") {
		var b = document.getElementById('tdlibs');		
	}	
	d.style.display = "none";
		if (dv=="libraries") {		
		b.style.height="0";
	}		
}


function set(dv, val) {
	if (val=="1") {
		show(dv);
	} else {
		hide(dv);
	}
}

function ONWHelp(Url, nazwa, wys, szer) {
   window.open(Url, nazwa, "height=" + wys + ",width=" + szer + ",status=no,resizable=no,scrollbars=yes,menubar=no,location=no");
}

function HideSearch(){
	parent.document.getElementById('cms-wyszuk').style.display='none';
}
function HideStats(){
	parent.document.getElementById('cms-stats').style.display='none';
}

//funkcja do ustawiania praw dostepu
function swapbtns(id) {

	var vl = document.getElementById('cms-rights-value-'+id);

	
	if (vl.value==1) {
		newval = 3;
	} else if (vl.value==2) {
		newval = 2;
	} else if (vl.value==3) {
		newval=1;
	}
	
	var im = document.getElementById('cms-rights-image-'+id);
	
	im.src='/cms/pix/ico.rights.'+newval+'.gif';
	vl.value = newval;

}

function swapbtnswv(id,val) {

	var vl = document.getElementById('cms-rights-value-'+id);

	if (vl.value!=2) {
		newval = val;
		
	
	
	var im = document.getElementById('cms-rights-image-'+id);
	
	im.src='/cms/pix/ico.rights.'+newval+'.gif';
	vl.value = newval;
	}

}



function pokazAdres(tag) {
        
        adr = new Array('warszawa','lodz','siedlce','lublin');
        
        for(i=0;i<adr.length;i++) {
                
                document.getElementById(adr[i]).style.display = 'none';
        }
        
        document.getElementById(tag).style.display = 'block';
        
}

function sprawdz_hasla(pass) {
        
        p = document.getElementById('pass');
        p2 = document.getElementById('pass2');
        
        if(p.value != "") {
                if(p.value !== p2.value) {
                        alert('Hasla nie są identyczne!');
                        p2.value = '';
                        p2.focus();
                }
        }
        
}

function ajax_sprawdzLogin(div,login) {
        
	
	advAJAX.download(div, 'cms/_actions/sprawdzLogin.php?login='+login);
				
}

function sprawdzMarke(select) {
	
	//var selObj = document.getElementById(select);
	//alert(selObj.selectedIndex);

	return true;
}

function maskujKlawisze(AEvent, AMaska) {
    if (window.Event) {
        kodKlawisza = AEvent.which;
    } else {
        kodKlawisza = AEvent.keyCode;
    }

    if (kodKlawisza == 13) {
        return true;  // Enter
    };
    
    if (kodKlawisza == 8) {
        return true;  // Backspace
    };

    if (kodKlawisza == 0) {
        return true;  // klawisze sterujące
    };

    klawisz = String.fromCharCode(kodKlawisza);

    if (AMaska.indexOf(klawisz) == -1) {
        return false;
    } else {
        return true;
    }
}
function checkNewUserForm (as) {
	
	
	var f = new Array();
	
	var arr = as.split(";")
	for(i=0;i<arr.length;i++) {
		f[i] = document.getElementById(arr[i]);
	}
	
	/* czyszczenie zaznaczenia */
	for(i=0;i<f.length;i++) {
			f[i].style.borderColor = '#82A0CC';
			f[i].style.backgroundColor = 'white';
	}
	c=0;
	/* sprawdzanie i zaznaczanie */
	for(i=0;i<f.length;i++) {
		if(f[i].value.length>0) { } else {
			c=1;
			f[i].style.borderColor = 'red';
			f[i].style.backgroundColor = '#FFE5E5';
		}
	}
	
	if(c==1) {
		alert('Proszę uzupełnić wszystkie pola');
	} else {
		var fo = document.prof;
		fo.submit();
	}
	

	
	
}

function CheckLen(f,x,min) {
	
	cos = document.getElementById(x);
	f = document.getElementById(f);
	
	if(cos.value.length<min) {
		alert('Prosze wpisać przynajmniej '+min+' znaki.');
		cos.value = '';
		return false;
	} else { f.submit(); };

}

function CheckLenSubmit(f,x,min) {
	
	cos = document.getElementById(x);
	f = document.getElementById(f);
	
	if(cos.value.length<min) {
		alert('Prosze wpisać przynajmniej '+min+' znaki.');
		cos.value = '';
		return false;
	} else { return true; };

}

function ListShowTr(divName) {

	d = document.getElementById(divName);
		if(d.style.display == 'none') {
			d.style.display = 'block';
		}
	else if (d.style.display == 'block') {
		d.style.display = 'none';
		}
}

function ShowDiv(divName,id) {

		o = document.getElementById(divName+'od');
		
	if(o.value && o.value > 0) { // jesli jest wartosc i nie jest rowna 0
		document.getElementById(divName+o.value).style.display = 'none';
		
	}

	d = document.getElementById(divName+id);
		if(d.style.display == 'none') {
			d.style.display = 'block';
		}
	else if (d.style.display == 'block') {
		d.style.display = 'none';
		}
		
		o.value = id;
}

function TRmOver(tr,fv) {
	tr.bgColor ='#EBF5FF';
	tr.cursor = 'pointer';
}
function TRmOut(tr) {
	tr.bgColor ='#FFFFFF';
}
function TRhref(fv,select,cos) {
		if(select==true && cos) {
			location.href=fv+cos.value;
		} else {
			location.href=fv;
		}
	}


function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=300,height=200,left = 490,top = 412');");
}

function popOrder(URL) {
	window.open(URL, 'order', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=740,height=600,left = 100,top = 100');
}


function BorderColor(x) {
	
	
	
	function colorButton() {
		buttC = document.getElementById('przelicz');
		buttC.style.color = 'red';
	}
	function activButton() {
		buttA = document.getElementById('tdGotoweButt');
		buttFake = document.getElementById('tdGotoweFake');
		
		buttA.style.display = 'none';
		buttFake.style.display = 'block';
	}
	
	
	
	
	var d = document.getElementById('ilosc_'+x);
	d.style.borderColor = "red";
	d.style.backgroundColor = "pink";
	d.style.borderSize = "2";
	
	colorButton();
	activButton();
	
}

function OpenImage(file) {
	window.open("/cms/openimage.php?id="+file, "obrazek", "toolbar=no , menubar=0, status=no, top=250, left=225" );
}
function get_akt(id,title){
	window.open('/cms/mod_news/aktualnosci_popup.php?path='+id, 'title'+id, 'height=540, width=660, status=no, toolbar=no, menubar=yes, location=no, scrollbars=yes');
}
function get_content(id,title){
	window.open('/cms/mod_content/content_popup.php?path='+id, 'title'+id, 'height=540, width=660, status=no, toolbar=no, menubar=no, location=no, scrollbars=yes');
}




function ONWGal(Url, nazwa, wys, szer) {
   window.open(Url, nazwa, "height=" + wys + ",width=" + szer + ",status=no,resizable=no,scrollbars=yes,menubar=no,location=no");
}
function showButton(wybor) {
	document.getElementById(wybor).style.display = "block";
}

function czyNull(id) {
	if(id == null || id == 'null') {
		return false;
	} else
		return true;
}


function wpiszWartoscDiv(tag,response) {
	
	var div = document.getElementById(tag);
	div.innerHTML = response;
}

function wpiszLoadDiv(tag) {
	
	var info = 'trwa ładowanie';
	
	var div = document.getElementById(tag);
	div.innerHTML = info;
}

function showDiv(tag) {
	var div = document.getElementById(tag);
	div.style.display = 'block';
}

function showLoadDiv(tag) {
	var div = document.getElementById(tag);
	div.style.display = 'block';
      
}
function showHideDiv(tag, tag2,tag3) {
	var div = document.getElementById(tag);
        var div2 = document.getElementById(tag2);
	
	div.style.display = 'block';
        div2.style.display = 'none';
        
	
	if(tag3) {
		var div3 = document.getElementById(tag3);
			
		if(div3.style.display == 'none') {
			div3.style.display = 'block'
		} else {
			div3.style.display = 'none'
		}
		
	}
       
	
	
        
        
}
function hideLoadDiv(tag) {
	var div = document.getElementById(tag);
	div.style.display = 'none';
}


function clearDiv(tag) {
	
	var div = document.getElementById(tag);
	div.innerHTML = '';
}

function productAsk(nr) {
	
	window.open('cms/_actions/productAsk.php?nr='+nr, 'katun'+nr, "height=600,width=800,status=no,resizable=no,scrollbars=yes,menubar=no,location=no");
	
}


function updateSub(div,id) {
	
	
	advAJAX.download(div, 'cms/_actions/selectSub.php?id='+id+'&div='+div);
				
}

function updateSubCat(div,id,cl) { // AKTUALNY DIV z KTOREGO POCHODZI -- INDEKS
        
		var selekty = new Array ('c2','c3');  
		var nazwa = new Array('class2','class3');
		
		for(i=0; i < selekty.length; i++ ) {
			
			makeDiv = selekty[i];
			
			
			
			if(makeDiv != div)  {
				
			var selObj = document.getElementById(nazwa[i]);
			var selIndex = selObj.selectedIndex;
			var recent = selObj.options[selIndex].value;
			
			
			
				
				advAJAX.download(makeDiv, 'cms/_actions/select_meskato2.php?make='+makeDiv+'&id='+id+'&from='+div+'&recent='+recent);
				
				
				
				/*if(div == 'c1') {
					advAJAX.get({
						url : 'cms/_actions/select_meskato2.php?make='+makeDiv+'&id='+id+'&from='+div,
						onLoading : function(obj) { showLoadDiv('load'); },
						onComplete : function(obj) { hideLoadDiv('load'); showDiv('cx'); hideLoadDiv('c1') },
						onSuccess : function(obj) { wpiszWartoscDiv(makeDiv,obj.responseText); },
						onError : function(obj) { alert("Error: " + obj.status); }
						
					    });
				} else {
					advAJAX.get({
						url : 'cms/_actions/select_meskato2.php?make='+makeDiv+'&id='+id+'&from='+div,
						//onLoading : function(obj) { showLoadDiv('load'); },
						//onComplete : function(obj) { hideLoadDiv('load'); showDiv('cx'); hideLoadDiv('c1') },
						onSuccess : function(obj) { wpiszWartoscDiv(makeDiv,obj.responseText); },
						onError : function(obj) { alert("Error: " + obj.status); }
						
					    });
				}*/
			}
			
		}
	
}

function updateSubCat_BAK(wybor,sel) {
	
	document.getElementById(wybor).style.display = "block";
	advAJAX.download(wybor, 'cms/_actions/select_meskato.php?mark='+sel);
}


function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.newsletterEmail.value)){
return (true)
}
alert("Niepoprawny adres e-mail.Proszę wpisac ponownie")
return (false)
}


function updateMainSearch(from,to) { // AKTUALNY DIV z KTOREGO POCHODZI -- INDEKS
        
	var selObj = document.getElementById(from);
	var selIndex = selObj.selectedIndex;
	var recent = selObj.options[selIndex].value;
	
	if(from == "sel_1") {
		document.getElementById('cos_nowe').style.display = 'block';
	} else 	if(from == "sel_2") {
		document.getElementById('sel_1').disabled = true;
		document.getElementById('button-s').disabled = false;
		
	
	} else 	if(from == "sel_3") {
		document.getElementById('sel_2').disabled = true;
	}
	
	advAJAX.download(to, 'cms/_actions/selectMainSearch.php?recent='+recent+'&to='+to+'&from='+from);
		
		
		
	
}
