
function Di(t,v){if(!~~(v=t.value+1))t.value=(v=parseFloat(v))?v:''}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function changeColor(color){
  var el=event.srcElement
  if (el.tagName=="INPUT"&&el.type=="submit")
  event.srcElement.style.backgroundColor=color
}

function setBgImage(element,imageFile) {
  element.style.backgroundImage="url("+imageFile+")";
  element.style.color="#002E46";
}

function setBgImageOver(element,imageFile) {
  element.style.backgroundImage="url("+imageFile+")";
  element.style.color="#000000";
}

function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=no,menubar=no' );
}

function setCheckboxes(the_form, do_check)
{

    var elts      = document.forms[the_form].elements;
    var elts_cnt  = elts.length;

	for (var i = 0; i < elts_cnt; i++) {
		if (elts[i].type=="checkbox") elts[i].checked = do_check;
    } // end for

    return true;
}

/**
 * Sets/unsets the pointer in browse mode
 *
 * @param   object   the table row
 * @param   object   the color to use for this row
 * @param   object   the background color
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, thePointerColor, theNormalBgColor)
{
    var theCells = null;

    if (thePointerColor == '' || 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 currentColor = null;
    var newColor     = null;
    // Opera does not return valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
                     ? theNormalBgColor
                     : thePointerColor;
        for (var c = 0; c < rowCellsCnt; c++) {
            theCells[c].setAttribute('bgcolor', newColor, 0);
        } // end for
    }
    else {
        currentColor = theCells[0].style.backgroundColor;
        newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
                     ? theNormalBgColor
                     : thePointerColor;
        for (var c = 0; c < rowCellsCnt; c++) {
            theCells[c].style.backgroundColor = newColor;
        }
    }

    return true;
} // end of the 'setPointer()' function

			

function jak_w_nazwie_wlasnej(ciag)
{
var fraza=ciag;
var frazaTab=fraza.split(' ')
for(var i=0;i<frazaTab.length;i++){
	frazaTab[i]=frazaTab[i].substr(0,1).toUpperCase()+frazaTab[i].substr
(1).toLowerCase();
}
fraza=frazaTab.join(' ');
return(fraza);
}


function round (n) {
n = Math.round(n * 100) / 100;
n = (n + 0.001) + '';
return n.substring(0, n.indexOf('.') + 3);
}


function validateemail(pole) {
if(pole.indexOf("@")==-1 || pole.indexOf(".")==-1) return false;
return true;
}



function CheckMaxChars(textField, maxChars)
{
        var tmplen;
        var tmpvalue = new String(textField.value);
        tmplen=textField.value.length;
        tmpvalue=tmpvalue.substr(0,maxChars);
        if (tmplen > maxChars)
        {
                textField.value = tmpvalue;
                window.alert('Wielko¶ć pola ograniczona jest do ' + maxChars + ' znaków');
        }

} 

function ucfirst(str) {
    str += '';
    var f = str.charAt(0).toUpperCase();
    return f + str.substr(1);
}

function MD_Imprezy(link, miasto)
{
	if (link!='?')
	{
		$("#MDListaImprez").html('<p id="ladowanie">trwa ładowanie....</p>');
		$("#imprezy #miasto").attr('href', 'http://'+link+'.miastodzieci.pl');
		$("#imprezy #miasto").html(miasto);

		$("#MDlink1").attr('href', 'http://'+link+'.miastodzieci.pl/sale.php');
		$("#MDlink2").attr('href', 'http://'+link+'.miastodzieci.pl/place.php');
		$("#MDlink3").attr('href', 'http://'+link+'.miastodzieci.pl/restauracje.php');
		$("#MDlink4").attr('href', 'http://'+link+'.miastodzieci.pl/muzea.php');

		$("#imprezy #wiecej").attr('href', 'http://'+link+'.miastodzieci.pl/wydarzenia.php');

		$.ajax({
		url: 'includes/imprezy.inc.php',
		type: 'GET',
		data: {miasto: link},
		success: function(responseText){
		$("#MDListaImprez").html(responseText);

		}});   
	}
}

function print_r( array, return_val ) {
    // *     example 1: print_r(1, true);
    // *     returns 1: 1
    var output = "", pad_char = " ", pad_val = 4;
    var formatArray = function (obj, cur_depth, pad_val, pad_char) {
        if (cur_depth > 0) {cur_depth++;}
        var base_pad = repeat_char(pad_val*cur_depth, pad_char);
        var thick_pad = repeat_char(pad_val*(cur_depth+1), pad_char);
        var str = "";
        if (obj instanceof Array || obj instanceof Object) {
            str += "Array\n" + base_pad + "(\n";
            for (var key in obj) {
                if (obj[key] instanceof Array) {str += thick_pad + "["+key+"] => "+formatArray(obj[key], cur_depth+1, pad_val, pad_char);}
                else {str += thick_pad + "["+key+"] => " + obj[key] + "\n";}
            }str += base_pad + ")\n";
        } else if(obj == null || obj == undefined) {str = '';
        } else {str = obj.toString();}
        return str;
    };
    var repeat_char = function (len, pad_char) {
        var str = "";
        for(var i=0; i < len; i++) {str += pad_char;};
        return str;
    };
    output = formatArray(array, 0, pad_val, pad_char);
    if (return_val !== true) {document.write("<pre>" + output + "</pre>");return true;}
    else {return output;}
}


function DodajPodglad()
{
	if ($("#wystaw #nazwa").val()=='') { alert('Podaj prawidłow± nazwę'); return 0; }
	if ($("#wystaw #opis").val()=='') { alert('Podaj prawidłowy opis'); return 0; }
	if ($("#wystaw #tagi").val()=='') { alert('Podaj prawidłowe słowa'); return 0; }

//	if ($("#wystaw #producent").val()=='') { alert('Podaj producenta'); return 0; }
//	if ($("#wystaw #rozmiar").val()=='') { alert('Wybierz rozmiar z listy'); return 0; }

//	if ($("#wystaw #wiek").val()=='') { alert('Wybierz przedział wiekowy z listy'); return 0; }
	if ($("#wystaw input[@id='wartosc']:checked").val()==null) { alert('Wybierz punkty'); return 0; }
	if ($("#wystaw #stan").val()=='') { alert('Wybierz stan przedmiotu z listy'); return 0; }
	if ($("#wystaw #kat1").val()=='') { alert('Wybierz kategorię główn± z listy'); return 0; }
	if ($("#wystaw #adres").val()=='true') 
	{
		if ($("#wystaw #imie").val()=='') { alert('Podaj swoje imię'); return 0; }
		if ($("#wystaw #nazwisko").val()=='') { alert('Podaj swoje nazwisko'); return 0; }
		if ($("#wystaw #ulica").val()=='') { alert('Podaj swoją ulicę'); return 0; }
		if ($("#wystaw #kod").val()=='') { alert('Podaj swój kod pocztowy'); return 0; }
		if ($("#wystaw #miasto").val()=='') { alert('Podaj swoje miasto'); return 0; }
		if ($("#wystaw #wojewodztwo").val()=='') { alert('Wybierz swoje województwo'); return 0; }
		if ($("#wystaw #kraj").val()=='') { alert('Podaj swój kraj'); return 0; }
	}
            var options={
				url:'add.temp.foto.php',
				type:'post',
				dataType:'json',
//				complete:function(a, response) { alert(print_r(a, true)); }, 
				success:function(response){
					$('#frmrecenzja').attr('action',$('#frmrecenzja').attr('actionb'));
					if (response.type=='zdjecia'){
			      // Dodawanie linkow do zdjeć na stronę
						var rl=response.zdjecia.length;
						for(var i=0;i<rl;i++)
						{
							$('#misio'+(i+1)).css('display','block');
							$('#misio'+(i+1)).css('margin-right','20px');
							$('#misio'+(i+1)).css('float','left');
							$('.foto-miniaturki').css('text-align','center');
							$('.foto-miniaturki').css('display','block');							
							$('#misio'+(i+1)).attr('src',response.zdjecia[i]);
						}
				   // Ustawianie reszty pól na stronie
					   $("#wystaw-podglad #name").html($("#wystaw #nazwa").val());
                            	if ($("#wystaw #kat1").val()!='')
                            	{
                            		KatName = $("#wystaw #kat1").children("[@selected]").text();
                            		KatName = KatName.replace(/- /, "");
                            		KatName = KatName.replace(/-/, "");
                            		KatName = KatName.replace(/-/, "");
                            		KatName = KatName.replace(/-/, "");
                            		$("#wystaw-podglad #kategoria #KatLink1").html(ucfirst(KatName));
                            		$("#wystaw-podglad #kategoria #KatLink1").attr('href', 'k'+$("#wystaw #kat1").val()+'.php');
                            		$("#wystaw-podglad #kategoria #ikona").attr('src', 'foto/kategorie/ikona-kategoria-'+$("#wystaw #kat1").val()+'.gif');
                            	}
                            	if ($("#wystaw #kat2").val()!='')
                            	{
                            		KatName = $("#wystaw #kat2").children("[@selected]").text();
                            		KatName = KatName.replace(/- /, "");
                            		KatName = KatName.replace(/-/, "");
                            		KatName = KatName.replace(/-/, "");
                            		KatName = KatName.replace(/-/, "");
                            		$("#wystaw-podglad #kategoria #KatLink2").html(ucfirst(KatName));
                            		$("#wystaw-podglad #kategoria #KatLink2").attr('href', 'k'+$("#wystaw #kat2").val()+'.php');
                            	}

                            	$("#wystaw-podglad #description").html($("#wystaw #opis").val());
                            	$("#wystaw-podglad #wartosc #punkty").attr('src', 'img/'+$("#wystaw input[@id='wartosc']:checked").val()+'pkt.gif');
                            	$("#wystaw-podglad #tagi").html('<b>Słowa:</b> '+$("#wystaw #tagi").val());
								tmp_przeznaczenie = '';
								if ($("#wystaw #dla_chlopca").fieldValue()=="T") tmp_przeznaczenie = tmp_przeznaczenie + 'dla chłopca, ';
								if ($("#wystaw #dla_dziewczynki").fieldValue()=="T") tmp_przeznaczenie = tmp_przeznaczenie + 'dla dziewczynki, ';
                            	$("#wystaw-podglad #przeznaczenie").html('<b>Przeznaczenie:</b> '+tmp_przeznaczenie.substring(0, (tmp_przeznaczenie.length-2)));
								


                            	$("#wystaw-podglad #producent").html('<b>Producent:</b> '+$("#wystaw #producent").val());
                            	if ($("#wystaw #rozmiar").val()!='') $("#wystaw-podglad #rozmiar").html('<b>Rozmiar odzieży:</b> '+$("#wystaw #rozmiar").children("[@selected]").text());
									else $("#wystaw-podglad #rozmiar").html('<b>Rozmiar:</b> brak');
                            	if ($("#wystaw #rozmiar-obuwia").val()!='') $("#wystaw-podglad #rozmiar-obuwia").html('<b>Rozmiar obuwia:</b> '+$("#wystaw #rozmiar-obuwia").children("[@selected]").text());
									else $("#wystaw-podglad #rozmiar-obuwia").html('<b>Rozmiar obuwia:</b> brak');
                            	if ($("#wystaw #stan").val()!='') $("#wystaw-podglad #stan").html('<b>Stan:</b> '+$("#wystaw #stan").children("[@selected]").text());
									else $("#wystaw-podglad #stan").html('<b>Stan:</b> brak');
                            	//window.scrollTo( 100, 258);
                            	//$("#wystaw").slideUp('slow', function() { $("#wystaw-podglad").slideDown('slow', function() {}); });
					}
					if(response.type=='error'){
				// Ubsługa niepoprawnie dodanego zdjęcia
//						CzyscPodglad();
						for (var i in response[response.type])
							$("#info").jGrowl(response[response.type][i][0],{header: response[response.type][i][1], speed: 'slow', life: 10000, theme: response[response.type][i][2]});
					}
					else{
//						$('div.recenzja-podglad').show();
					}
				}
			};
			$('#frmdodaj').ajaxSubmit(options);	
			$('#frmdodaj').submit();

}


function DodajPrzywroc()
{
	window.scrollTo( 100, 258); 
	$("#wystaw-podglad").slideUp('slow', function() { $("#wystaw").slideDown('slow', function() {}); });	
}
