function getTermsByDate(dateel, termel) {
	var date=document.getElementById(dateel).value;
	var ident=$('#frm\\[term_ident\\]').val();
	
	if (ident!=null && ident!='') date=ident;
	WGuiFillSelect('/admin/tshop.php?job=getTermsRes&date='+encodeURIComponent(date), termel);
}

//nastavenie sablony ceny v kalkulacke

function setCalcFormByTemplate(selid, frm) {
	eval('var dataobj='+selid.value);
	WGuiJSONToForm(dataobj, frm);
}

function toggleTypZajazdu(tz) {
	switch ($(tz).val()) {
		case '1':
			$('#frm\\[tours_accommodation_id\\]').attr('disabled','disabled');
			$('#frm\\[tours_destination_id\\]').attr('disabled','disabled');
		//	$('#frm\\[odjazd\\]').attr('disabled','disabled');
		break;

		case '2':
		case '3':
			$('#frm\\[tours_accommodation_id\\]').removeAttr('disabled');
			$('#frm\\[tours_destination_id\\]').removeAttr('disabled');
		//	$('#frm\\[odjazd\\]').removeAttr('disabled');
		break;
	}
}

function fillSupplier(elid, nameid, frm) {	//element s id a s nazvom!!!!!!!!!!!!!!!!!!!
	elid=$(document.getElementById(elid));
	nameid=$(document.getElementById(nameid));
	var supname=nameid.val();
	if (supname=='') elid.val('');
	var supid=elid.val();
	
	if (supid!='') supname=supid;
	
	if (supname=='') {
		WGuiOpenDialog({url:'/admin/dialogs/sellers.php?retids[]='+nameid.attr('id')+'&retids[]='+elid.attr('id')+'&retcols[]=name&retcols[]=id'});
	} else {
		$.getJSON('/admin/tours.php', {job:'getSupplierData', id:supname}, function (data) {
			if (data.find==false) {
				WGuiOpenDialog({url:'/admin/dialogs/sellers.php?retids[]='+nameid.attr('id')+'&retids[]='+elid.attr('id')+'&retcols[]=name&retcols[]=id&filter[name]='+supname});
			} else WGuiJSONToForm(data, frm);
		});
	}
}

function fillFakSupplier(el, frm) {
	var supname=$('#'+frm+'\\[odberatel_meno\\]').val();
	if (supname=='') $('#'+frm+'\\[tours_supplier_id\\]').val('');
	var supid=$('#'+frm+'\\[tours_supplier_id\\]').val();
	
	if (supid!='') supname=supid;
	
	if (supname=='') {
		WGuiOpenDialog({url:'/admin/dialogs/sellers.php?retids[]=frm[odberatel_meno]&retids[]=frm[tours_supplier_id]&retcols[]=name&retcols[]=id&trigger=fillFakSupplier(this,"frm")'});
	} else {
		$.getJSON('/admin/tours_faktury.php', {job:'getSupplierData', id:supname}, function (data) {
			if (data.find==false) {
				WGuiOpenDialog({url:'/admin/dialogs/sellers.php?retids[]=frm[odberatel_meno]&retids[]=frm[tours_supplier_id]&retcols[]=name&retcols[]=id&filter[name]='+supname+'&trigger=fillFakSupplier(this,"frm")'});
			} else WGuiJSONToForm(data, frm);
		});
	}
}

