function addRow(id){
	
	$('#'+id+' tr:last').after('<tr><td><select><option>vali</option><option>facebook</option><option>rate</option><option>muu</option></select></td><td><div class="text-input"><input type="text" /></div></td><td><a href="javascript:void(0);" onclick="deleteRow(this);">-</a></td></tr>');
	
	$('#'+id+' tr:last select').selectbox();	
}

function addDate(id){
	
	$('#'+id+' tr:last').after('<tr><td><div class="date-input"><input type="text" class="date-pick dp-applied code" /></div></td><td><a href="javascript:void(0);" onclick="deleteDate(this);">kustuta</a></td></tr>');
	
	$('#'+id+' tr:last .date-pick').datePicker({startDate:'01.01.2009',endDate: '31.01.2010'});
}

function deleteDate(element){
	$(element).parent().parent().remove();
}

function deleteRow(element){
	$(element).parent().parent().remove();
}

function submitForm(id){
	$('#'+id).submit();
	return true;
}

function show(selector){
	$(selector).toggle();
	if(selector == "#ideed-comment"){
		$("#teostus-comment").hide();	
	} else {
		$("#ideed-comment").hide();
	}
}

function showIdee(){
	$("#idee-lisa").toggle();
}

function showTip(name){
	$(name).fadeIn();
	//$(name).show();
}

function hideTip(name){
	$(name).fadeOut();
	//$(name).hide();
}


tinyMCE.init({
		mode : "exact",
		elements : "sisu,sisu2",
		language : 'et',
		invalid_elements : "div",

		theme : "advanced",
		plugins : "safari,pagebreak,advimage,advlink,contextmenu,fullscreen,media,paste2",
		theme_advanced_buttons1 : "bold,italic,underline, strikethrough, |,bullist,numlist,|,outdent,indent, separator,justifyleft, justifycenter,justifyright,separator,pagebreak,media,image,link",
	
		theme_advanced_buttons2: "",
		theme_advanced_buttons3: "",
		theme_advanced_buttons4: "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true
	});

//onload init
$(function() {
	
	$("input[type=file]").filestyle({ 
		image: "img/vali-fail.png",
		imageheight : 22,
		imagewidth : 100,
		width : 250
	});
	
	$('select').selectbox();

	$('.date-pick').datePicker({startDate:'01.01.2009',endDate: '31.01.2010'});
	
    $('input:checkbox:not([safari])').checkbox();

	$("#tags").autocomplete("autocomplete.php", {
		width: 320,
		max: 4,
		highlight: false,
		multiple: true,
		multipleSeparator: ", ",
		scroll: true,
		scrollHeight: 300
	});
	
	$("td.ideed div.idee-list").each(
		function(){
			$(this).mouseover(function(){ $(this).not(".active").addClass("hover"); });
			$(this).mouseout(function(){ $(this).removeClass("hover"); });
			$(this).click(function(){ window.location.href = $(this).find("div.content a").attr("href"); });
		}
	);

});

function formHandler2(ansid,redirto){
var URL = ansid;
window.location.href = "/gallup.php?vastus="+URL+"&redirto="+redirto;
}

