$(document).ready(function(){
	$(".toggle1").click(function(){
		$(".slider1").slideToggle();
	})
	
	$(".toggle2").click(function(){
		$(".slider2").slideToggle();
	})
	
	$(".toggle3").click(function(){
		$(".slider3").slideToggle();
	})
	
	$(".toggle4").click(function(){
		$(".slider4").slideToggle();
	})
})
	
function checkTable(ref)
{
	niPrazna = false;
	table = $(ref).parent().parent().parent();
	zadnja = table.find("tr:last")
	zadnja.find("input").each(function(i, elem){
		if($(elem).val() != "")
		{
			niPrazna = true;
		}
	})
	if(niPrazna)
	{
		table.append("<tr>"+zadnja.html()+"</tr>");
		//table = $(ref).parent().parent().parent();
		//trs = table.find("tr")
		//$(trs[trs.length-1]).find("td:first").html(parseInt($(trs[trs.length-1]).find("td:first").html())+1)
	}
		
}

function addRow(ref)
{
	trs = $(ref).parent().find("tr");
	
	$(ref).parent().find("table").append("<tr>"+$(trs[trs.length-1]).html()+"</tr>");
	//trs = $(ref).parent().find("tr");
	//$(trs[trs.length-1]).find("td:first").html(parseInt($(trs[trs.length-1]).find("td:first").html())+1)
}

function clearEmpty(ref)
{
	table = $(ref).parent().parent().parent();
	$(table).find("tr").not("tr:first").each(function(){
		thisLine = $(this);
		thisLine.find("input[type=text]").each(function(){
			if($(this).val() == "")
			{
				thisLine.remove();
				return false;
			}
		})
	})
}

function checkForm(ref)
{
	//console.log("akcija");
	thisForm = $(ref).parent().parent().parent().parent();
	//console.log(thisForm.html());
	ok = true;
	
	$(thisForm).find(".obvezen").each(function(){
		elem = $(this)
		if(elem.val() == "" || elem.val() == "Vaš e-mail/Telefon/GSM")
		{
			elem.css({'border-color': 'red'})
			ok = false;
		}
		else
		{
			elem.css({'border-color': '#FFF'})
		}
	})
	
	if (ok) {
		clearEmpty(ref);
		thisForm.submit();
	}
	else 
		$(".errors").text("Pomanjkljivo ste izpolnili polja ki so obrobljena rdeče.");
}

