function printPage() {
	var url = document.location.href+'/action/print/';
	var newokno = window.open( url, 'Drukowanie' );
}

function toggleProvinces( script ) {
	var prov = getValue( 'province' );
	if( prov.length > 0 ){
		document.location.href = '/'+script+'/'+prov;
	}
}

function calPopup( id, width, height ) {
	if ( newokno ){ newokno.close(); }
	width  +=20;
	height +=20;
	var opcje = "scrollbars=yes,width="+width+",height="+height;	
	var url = document.root_folder+'/popup_photo/id/'+id+'/';
	var newokno = window.open( url, 'Zdjecie', opcje );
}


function callRegisterKey(evn, url, email) {
	if (window.event && window.event.keyCode == 13) {
	  callRegister( url, email );
	} else if (evn && evn.keyCode == 13) {
	  callRegister( url, email );
	}
}


function callRegister( url, email ) {
	var em = getValue( email );
	if( typeof( email ) == 'undefined' ) {
		em = 'test';
	}
	if( emailcheck( em ) || ( em == 'test' ) ) {
		if ( newokno ){ newokno.close(); }		
		if( em == 'test' ) {
			var ur = '/'+url;
		} else {
			var ur = '/'+url+'/'+em;
		}
		var width = 870;
		var height = 740;
		var opcje = "scrollbars=yes,width="+width+",height="+height;	
		var newokno = window.open( ur, 'Rejestracja', opcje );		
	} else {
		alert( 'Proszę wprowadzić poprawny adres e-mail' );
	}
}

	function emailcheck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}


function gotoCategory( mainUrl ) {
	var u = '/'+mainUrl+'/'+getValue( 'sel_prodcat' )+'/'+getValue( 'sel_prodsubcat' );
	document.location.href = u;
}

function toggleCategoryUrl() {
	var pid = getValue( 'sel_prodcat' );
	if( pid != '' && pid != '0' ) {
		var ajax = new myAjax();
		ajax.action = 'toggleCategoriesUrl';
		ajax.post( 'pid='+pid, 'sel_prodsubcat_div' );
	}
}

function toggleCategory() {
	var pid = getValue( 'sel_prodcat' );
    var folder = getValue( 'folder_id' );


	var ajax = new myAjax();
	ajax.action = 'toggleCategories';
	ajax.post( 'pid='+pid+'&folder='+folder, 'sel_prodsubcat_div' );
//		ajax.onLoad = function() {alert( this.response);}
	
}

function toggleSubcategory() {
	var pid = getValue( 'sel_prodsubcat' );
	var folder = getValue( 'folder_id' );
	if( pid  != '' ) {
		var ajax = new myAjax();
		ajax.action = 'toggleProducts';
		ajax.post( 'pid='+pid+'&folder='+folder, 'sel_products_div' );
	}
}

function toggleSubcategoryCeretherm() {
	var pid = getValue( 'sel_ceretherm' );
	var folder = getValue( 'folder_id' );
    if( pid  != '' ) {
		var ajax = new myAjax();
		ajax.action = 'toggleSystemsCeretherm';
		ajax.post( 'pid='+pid+'&folder='+folder, 'sel_products_div' );
	}
    //alert('pid='+pid+', folder='+folder);
}

function toggleProducts() {
	var pid = getValue( 'sel_products' );
	if( pid != '' && pid != '0' ) {
		show( 'search_button' );
	} else {
		hide( 'search_button' );
	}
    //alert('pid='+pid);
}

function searchFiles( folder ) {
	var pid = getValue( 'sel_products' );
	if( pid != '' && pid != '0' ) {
		var ajax = new myAjax();
		ajax.action = 'getProductFiles';
		ajax.post( 'pid='+pid+'&folder='+folder, 'download' );
	}
}

function saveNewPassword() {
	var op = get( 'old_pass' ).value;
	var np = get( 'new_pass' ).value;
	var npr = get( 'new_pass_repeat' ).value;
	var ajax = new myAjax();
	ajax.action = 'saveNewPassword';
	ajax.post( 'op='+op+'&np='+np+'&npr='+npr );
	ajax.onLoad = function() {
		var d = get( 'passwordMessage' );
		switch( this.response ) {
			case 'ok':
				putHtml( d, 'Zapisano nowe hasło' );
				break;
			case 'not_empty':
				putHtml( d, 'Hasło nie może być puste' );
				break;
			case 'bad_compare':
				putHtml( d, 'Hasło nie zgadza się z powtórzeniem hasła' );
				break;
			case 'bad_pass':
				putHtml( d, 'Stare hasło jest nieprawidłowe' );
				break;
			default:
				putHtml( d, this.response );
				break;
		}
	}
}

function sifr_replace() {
	if(typeof sIFR == "function"){
		sIFR.replaceElement(named({ sSelector:"div#login_panel div.sifr_l_ht", sFlashSrc:"/swf/sifr_century_gothic.swf", sColor:"#ffffff", sLinkColor:"#ffffff", sHoverColor:"#ffffff", sBgColor:'transparent', sWmode:'transparent' }));
	}
}

function searchFKey( e ) {
	if ( ( e && e.which == 13) || ( window.event && window.event.keyCode == 13 ) ) {
		searchF( 'searcher' );
	}
}

function searchF( target ) {
	get( target ).value = trim( getValue( target ) );
	var t = getValue( target );
	t = t.split( ' ' ).join( '+' );
	if( t.length < 2 ) {
		alert( 'Wyszukiwany tekst musi mieć conajmniej 2 znaki' );
	} else {
		document.location = '/szukaj/'+t;//+'/kategoria/'+o;
	}
}


function publicLogin() {
	var l 	= getValue( 'public_login' );
	var p	= getValue( 'public_password' );
	get( 'loginMessage' ).value = '';
	var ajax = new myAjax();
	var pstr = 'login='+l+'&pass='+p+'&cn=Client';
	ajax.action = 'publicLogin';
	ajax.post ( pstr, 'loginMessage' );
	ajax.onLoad = function() {
		if( this.response == 'ok' ) {
			document.location.reload();
        //document.location.href = 'zalogowany';
        
        
		}
	}
    
}

function showSubSectionMenu(id)
{
	document.getElementById(id).style.display="block";
}

function hideSubSectionMenu(id)
{
    document.getElementById(id).style.display="none";
}


function showPerformer( elem ){
	//alert( elem.value );
	if( elem.value == "performer" ) {
		str = '<select name="performer" id="performer" onchange="showPerformerList(this);"><option value="glazurnicze">prace glazurnicze</option><option value="hydroizolacyjne">prace hydroizolacyjne</option><option value="ociepleniowe">prace ociepleniowe</option><option value="posadzkarskie">prace posadzkarskie</option><option value="inne">inne prace</option></select>';
		$("#performer-container").html( str );
		//$("#performer-container").html("<input type=\"text\" name=\"performer\" value=\"\" />");
	} else {
		$("#performer-container").html("");
		$("#performer-list-container").html("");
	}
}

function showPerformerList( elem ){
	
	if( elem.value == "inne" ) {
		$("#performer-list-container").html("<input type=\"text\" name=\"performer-other\" value=\"wpisz jakie?\" />");
	} else {
		$("#performer-list-container").html("");
	}
}

$(document).ready(function(){
  // Your code here...
	//alert( 'test' );
	if( document.getElementById("sector").value != "performer") {
		$("#performer-container").html("");
		$("#performer-list-container").html("");
	} else {
		if( document.getElementById("performer").value != "inne") {
			$("#performer-list-container").html("");
		}
	}
});



