var Cart = {
	
	show: function( ){
		alert(credit);
	},
	
	calculateCredit: function( ){
		
		var bank = $('order_banka');
		var months = $('order_meseci');
		var month = months.value;
		
		var MonthlyRate = 0;
		var UcesceFin = 0;
		var cena = cartValue;
		var ucesce = 0;
		var kamata = 0;
		
		var bankId = bank.selectedIndex;
		
		ucesce = eval(creditSettings.banks[bankId].ucesce);
		kamata = eval(creditSettings.banks[bankId].kamata);

		UcesceFin = cena*(ucesce/100);
		cena = cena*((100-ucesce)/100);
		MonthlyRate = (cena*(1+(kamata/100))/month);
			
		$('fin_uc').innerHTML = UcesceFin.toFixed(2);
		$('fin_cena').innerHTML = MonthlyRate.toFixed(2);
	
	},
	
	populateFields: function( ){
	
		var bankContainer = $('order_banka');
		var monthContainer = $('order_meseci');
		var bankHTML = "";
		var monthHTML = "";
		
		for (i=0; i < creditSettings.banks.length; i++){
			if (creditSettings.banks[i].enabled == 'true')
				bankHTML += '<option style="font-weight: bold;" value="'+ creditSettings.banks[i].bank +'">'+ creditSettings.banks[i].bank +'</option>\n';
		}
		bankContainer.innerHTML = bankHTML;
		
		for (i=0; i < creditSettings.months.length; i++){
			if (creditSettings.months[i].enabled == 'true')
				monthHTML += '<option style="font-weight: bold;" value="'+ creditSettings.months[i].month +'">'+ creditSettings.months[i].month +'</option>\n';
		}
		monthContainer.innerHTML = monthHTML;
		
		if (cartValue < creditSettings.settings.min_price)
			$('pay_credit').disabled = true;

		this.calculateCredit();
		
	},

	payOptions: function( ){
			
		var cash = $('pay_cash').checked;
		var credit = $('pay_credit').checked;
		
		if (cash)
			$('credits').hide();
		else if(credit)
			$('credits').show();
		else
			$('credits').hide();
	},
	
	showOrderForm: function( ){
	
		var orderForm = $('orderform');

		orderForm.show();
		this.populateFields();
		orderForm.scrollTo();
	},
	
	validateForm: function( ){
		var form = $('userInfoForm');
		var fields = form.getElementsByTagName('input');
		
		for(i = 0; i < fields.length; i++) {
	        attr = fields[i].getAttribute("required");			
	        if(attr == 'true') {
				if (fields[i].value == ''){
					alert('Morate ispuniti sva polja markirana sa (*)!');
					return false;
				}
	        }
	    }		
		
		if ($('pay_credit').checked) {
			var submitForm = confirm('Sigurno želite naruchiti izabrane artikle na odloženo plaćanje?')
		} else  {
			var submitForm = confirm('Sigurno želite naruchiti izabrane artikle u iznosu od ' + cartValue + ' DIN?')
		}

		return submitForm;
		return true;
		
	}
	
}


function rowover(num){
	
	var korpa_row = new getObj('korpa['+num+']');
	
	if(korpa_row.style.backgroundColor != 'gold'){
		korpa_row.style.backgroundColor = '#FFFFFF';
	}
}

function rowout(num){

	var korpa_row = new getObj('korpa['+num+']');
	
	if(korpa_row.style.backgroundColor != 'gold'){
	
		if (num % 2 != 0) {
			korpa_row.style.backgroundColor = '#E0E7F3'; //paratlan
		} else {
			korpa_row.style.backgroundColor = '#F1F4FA'; //paros
		}
	}
}

function AskToRemove(what,which,url) {
	var korpa_row = new getObj('korpa['+which+']');
	var kcolor = korpa_row.style.backgroundColor;
	
	korpa_row.style.backgroundColor = 'gold';
	
	var Remove = confirm('Sigurno hocete izbrisati stavku: ' + what + '?');
	if (Remove){
		window.location = url;
	} else {
		if (which % 2 != 0) {
			korpa_row.style.backgroundColor = '#E0E7F3'; //paratlan
		} else {
			korpa_row.style.backgroundColor = '#F1F4FA'; //paros
		}
	}
}

function AskToEmtyCart(url) {
	var Remove = confirm("Sigurno odustajete od kupovine?")
	if (Remove){
		window.location = url;
	}
}

