


/*
 * InPlaceEditor extension that adds a 'click to edit' text when the field is 
 * empty.
 * /
Ajax.InPlaceEditor.prototype.__initialize = Ajax.InPlaceEditor.prototype.initialize;
Ajax.InPlaceEditor.prototype.__getText = Ajax.InPlaceEditor.prototype.getText;
Ajax.InPlaceEditor.prototype.__onComplete = Ajax.InPlaceEditor.prototype.onComplete;
Ajax.InPlaceEditor.prototype = Object.extend(Ajax.InPlaceEditor.prototype, {

    initialize: function(element, url, options){
        this.__initialize(element,url,options)
        this.setOptions(options);
        this._checkEmpty();
    },

    setOptions: function(options){
        this.options = Object.extend(Object.extend(this.options,{
            emptyText: 'nic',
            emptyClassName: 'inplaceeditor-empty'
        }),options||{});
    },

    _checkEmpty: function(){
        if( this.element.innerHTML.length == 0 ){
            this.element.appendChild(
                Builder.node('span',{className:this.options.emptyClassName},this.options.emptyText));
        }
    },

    getText: function(){
        document.getElementsByClassName(this.options.emptyClassName,this.element).each(function(child){
            this.element.removeChild(child);
        }.bind(this));
        return this.__getText();
    },

    onComplete: function(transport){
        this._checkEmpty();
        this.__onComplete(transport);
    }
});






/* nove okno */
	var browserName = window.navigator.appName;
	var platform = navigator.platform;

	
	if (browserName.indexOf("Explorer") >= 0){
		var nn = false;
		var ie = true;
	}
	else if(browserName.indexOf("Netscape") >= 0 || browserName.indexOf("Konqueror") >= 0){
		var nn = true;
		var ie = false;
	}

	// nove okno s parametrami --------------------------------------------------------------------------------------------------
	function customWindow(link, winName, winWidth, winHeight, winParam){

		// Microsoft Internet Explorer
		if (ie){
			window.open(link, winName,"width=" + winWidth + ",height=" + winHeight + "," + winParam);
		}
		
		// ak je to mac a netscape
		else if (nn && navigator.platform == 'MacPPC') {
			window.open(link, winName, "screenX=0,screenY=0,outerWidth=" + width + ",outerHeight=" + height + "," + winParam);
		}		
		
		// Netscape Navigator alebo nieco ine
		if (nn){
			window.open(link, winName, "screenX=0,screenY=0,Width=" + winWidth + ", Height=" + winHeight + "," + winParam);
		}

	}



function okno(c,w,h) {
	if(!w)
		w = 550;
	if(!h)
		h = 550;
	//alert(c);
	window.open(c,"_blank","menubar=1,resizable=1,scrollbars=1,width="+w+",height="+h);
}

/*nove  okno - koniec */

function viewuser(id) {
		customWindow("http://novypocitac.sk/userinfo/&op=window&uid="+id,"viewuser","600","400","scrollbars=yes,resizable=yes");
}

function help(i) {
		customWindow("http://novypocitac.sk/okno/help/&i="+i,"help","300","250","scrollbars=yes,resizable=yes");
}

function nahlad(i) {
	windowObject = customWindow("http://novypocitac.sk/okno/vimg/"+i+"/","nahlad","250","300","scrollbars=auto,resizable=yes");
	//parent.windowObject.focus();
}

function quatro_prepocet(f) {

	Element.update("spl_vysled","čakajte prosím, počítam");
	new Ajax.Updater("spl_vysled","/nakup-na-splatky/prepocet/?ajax=1&suma="+f.suma.value+"&ak="+f.ak.value+"&spl="+f.spl.value);
	return false;
}
/* komentare */
function comment(formular)
{
	
	if (formular.name.value=="")
    {
        alert("Tvoje meno (prezývku) musíš vyplniť!");
        formular.name.focus();
        return false;
    }
	if (formular.predmet.value=="")
    {
        alert("Predmet správy musíš vyplniť!");
        formular.predmet.focus();
        return false;
    }
	else if (formular.text.value=="")
    {
        alert("Text správy musíš vyplniť!");
        formular.text.focus();
        return false;
    }
    else
	      return true;
}

function zmena(i) {
	
	if(i==1) {
		document.obj.cena.value=hotovo;
		document.obj.cenas.value=hotovos;
	} else {
		document.obj.cena.value=zakl;
		document.obj.cenas.value=zakls;
	}
}

var MAX_DLZKAkom = 750;

function kontrolakom() 
{
  pointer = document.insertform.textkom;
  dlzka = pointer.value.length;
  if (dlzka>MAX_DLZKAkom) {
  	pointer.value = pointer.value.substring(0,MAX_DLZKAkom);
  	//alert("Maximálny počet znakov v správe je "+ MAX_DLZKAkom +"!");
  }
   document.insertform.pocetkom.value = MAX_DLZKAkom-pointer.value.length;
  return true;
}

function novyprihlasform() {
		Element.update('prihlasovaci_form','meno: <input name="uidnp" class="input" /> heslo: <input type="password" class="input" name="upwdnp"> <input type="submit" value="prihlásiť" id="menu_uzivatel_submit" />');	
		return false;
}


function prihlasenieresp(uspesne) {
	if(uspesne) {
		Element.update('prihlasovaci_form','Úspešne prihlásený! Počkajte, alebo kliknite <a href="./">sem</a>');
		var sURL = unescape(window.location.pathname);
		window.location.href = sURL;
	} else {
		Element.update('prihlasovaci_form','Nesprávne meno alebo heslo! <a href=\'#\' onclick=\'javascript:novyprihlasform()\'>(ešte raz)</a>');
		new Effect.Pulsate('prihlasovaci_form',{duration:2,from:0.4});
	}
}
function prihlasit(thisf) {

	meno = thisf.uidnp.value;
	heslo = thisf.upwdnp.value;
	Element.update('prihlasovaci_form','Prosím čakajte..');
	var opt = {
		// Use POST
		method: 'post',
		postBody: 'ajax=1&uidnp='+meno+'&upwdnp='+heslo,

		onSuccess: function(t) {
			//alert(t.responseText);
			if(t.responseText==1) {
				prihlasenieresp(true);
			} else {
				prihlasenieresp(false);
			}
		},
		// Handle 404
		on404: function(t) {
			alert('Error 404: location "' + t.statusText + '" was not found.\n\nNie je mozne sa prihlasit, prosim kontaktujte nas');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText+'\n\nNie je mozne sa prihlasit, prosim kontaktujte nas');
		}
	}
	
	new Ajax.Request('/uzivatel/login/', opt);
	return false;
}

function formatsuma(num) { 
	num = num.toString().replace(/\$|\,/g,''); 
	if(isNaN(num)) 
		num = "0"; 
	num = Math.floor(num).toString(); 
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) 
	num = num.substring(0,num.length-(4*i+3))+' '+ 
	num.substring(num.length-(4*i+3)); 
	
	return (num+',- Sk'); 
}


function change_product(id_pro,string) {
	pocet = string.value;
			if (isNaN(pocet-0) || (pocet-0) <= 0 || pocet == '') {
				string.value = '0';
				pocet = 0;
			}
		produkty[id_pro]['pocet'] = (pocet * 1);
		var novacena = produkty[id_pro]['jedncena']*produkty[id_pro]['pocet'];
		if(novacena==0) {
			Effect.Fade('trprodukt'+id_pro, { from:1,to:0.3 })
			produkty[id_pro]['fade'] = 1;
		} else if(produkty[id_pro]['fade']==1) {
			Effect.Fade('trprodukt'+id_pro, { from:0.3,to:1 })
			produkty[id_pro]['fade'] = 0;
		}
		
			var opt = {
		// Use POST
		method: 'post',
		postBody: 'ajax=1&kompks='+pocet,

		onSuccess: function(t) {
			//alert("nahrane");
			return true;
		},
		// Handle 404
		on404: function(t) {
			alert('Error 404: location "' + t.statusText + '" was not found.\n\nNie je mozne sa prihlasit, prosim kontaktujte nas');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText+'\n\nNie je mozne sa prihlasit, prosim kontaktujte nas');
		}
	}
	
	new Ajax.Request('/kosik/pridat/'+id_pro, opt);
		Element.update('cenaprodukt'+id_pro,formatsuma(novacena));
		change_complete();
		change_payment(false);
		
}

function change_payment(string) {
	//alert("zmena payment");
	if(!string.value) {
		var platba = payment;
	} else {
		var platba = string.value;
			var opt = {
				// Use POST
				method: 'post',
				postBody: 'ajax=1',
		
				onSuccess: function(t) {
					//alert("nahrane");
					//alert(t.responseText);
					return true;
				},
				// Handle 404
				on404: function(t) {
					alert('Error 404: location "' + t.statusText + '" was not found.\n\nNie je mozne sa prihlasit, prosim kontaktujte nas');
				},
				// Handle other errors
				onFailure: function(t) {
					alert('Error ' + t.status + ' -- ' + t.statusText+'\n\nNie je mozne sa prihlasit, prosim kontaktujte nas');
				}
			}
			
			new Ajax.Request('/kosik/setplatba/'+platba, opt);
	}
	
		//alert("zmena payment");
		
	
		if(platba=='f') {
			payment = 'f';
			priplatky = 0*1;
			
		} else if(platba=='h') {
			payment = 'h';
			priplatky = 0*1;
			
		} else if(platba=='d') {
			payment = 'd';
			priplatky = platbahotov * 1;
			
		} else if(platba=='s') {
			payment = 's';
			priplatky = 0*1;
			
		} else {
			priplatky = 0*1;	
		}
		if(objednavka<dodanie_min) priplatky += dodanie;

		Element.update('priplatky',formatsuma(priplatky));
		change_absolute();
		//change_complete();
}

function change_complete() {
		//alert("change_complete");
		var celkovacena = 0*1;
		for (var pr in produkty) {
			if(pr!=0) {
				//alert("dalsi produk "+pr+' cena'+produkty[pr]['jedncena']+' pocet'+produkty[pr]['pocet'])
				polozcena = (produkty[pr]['jedncena']*produkty[pr]['pocet']);
				//alert("dalsi produk "+pr+' cena'+polozcena);
				celkovacena += (polozcena);
			}
		}
		objednavka = celkovacena * 1;
		//alert('celkovo'+objednavka);
		
		//Element.update('celkovacena',formatsuma(objednavka));
		Element.update('celkovacena2',formatsuma(objednavka));
}

function change_absolute() {
		var absolute = 0*1;
		//alert("absolute"+objednavka);
		absolute += objednavka;
		//alert("absolute"+priplatky);
		absolute += priplatky;
		//alert(absolute);
		Element.update('absolutne',formatsuma(absolute*1.19));
}

function returnById( id )
{
    if (document.getElementById)
        var returnVar = document.getElementById(id);
    else if (document.all)
        var returnVar = document.all[id];
    else if (document.layers)
        var returnVar = document.layers[id];
    return returnVar;
}
function novakategoria_produkty() {
  parent = returnById("kategoria_list");
  alert(parent.value); 
}

function go(dest)
{
	if (dest) location.href = dest;
}


