function VyplnFormAction(skript)
{					  
	var FormElement = document.getElementById("PosliEmailForm");

	var NahodneCislo = Math.round((Math.random() * 20000)) * 8513; 
	
	if (FormElement != undefined){
		FormElement.action = baseUrl + 'tools/'+skript+'?AuthKey=' + NahodneCislo; 	
	}
	
}

 //-----------------------------------------------------------------------------------
 
function initializeInputItem( defaultText, elementId ) {
	var value = document.getElementById(elementId).value;
	if (value == defaultText)
		document.getElementById(elementId).value = "";
	else if (value == "")
	    document.getElementById(elementId).value = defaultText;
	return false;    
}  

//-----------------------------------------------------------------------------------
 
function otevriPanel( divId )
{
	div = document.getElementById(divId);
	
	if (div.style.display=='block') {
		$('#'+divId).hide('slow');
	} else {
		$('#'+divId).show('fast');
	}
} 

//-----------------------------------------------------------------------------------

function vyplnFormControl(id) {
	var FormElement = document.getElementById(id);

	var NahodneCislo = Math.round((Math.random() * 20000)) * 8513;

	if (FormElement != undefined){
		FormElement.value = NahodneCislo;
	}
}

/**
 * Znepristpneni formulare a zobrazeni loaderu
 * Moc si nerozumi validator a $("form").submit(function...)
 * Ukazka zakomponovani do validatoru
$("#formular").validate({
	errorElement: "em",
	errorPlacement: function(error, element) {
		error.appendTo( element.parent("div") );
	},
	rules: {
		...
	},
	messages: {
		...
	},
	submitHandler: function(form) {
		disable_form(form);
		form.submit();
	}
	});
 * @author Lukas Pohl
 */
function disable_form($form) {
	$(":submit", $form).parent().append("<img class='ajax-loader' src='"+BASE__URL+"img/ajax-loader.gif' alt='loading' />");
	$(":submit", $form).attr('disabled', 'disabled');
	$("input", $form).attr('readonly', 'true');
	$("textarea", $form).attr('readonly', 'true');
}

//function enable_form() {
//	$(prvekForm + ' img.ajax-loader').remove();
//	$(prvekForm + " :submit").attr('disabled', '');
//	$(prvekForm + " input").attr('readonly', '');
//	$(prvekForm + " textarea").attr('readonly', '');
//}

function in_array(arr, val) { 
	for (i = 0; i < arr.length; i++) {
		if (val == arr[i]) return true; 
	}
	return false; 
}

function orderProduct(id) {
	
	var pieces = $('#pieces-'+id).val();
	
	if (!pieces.toString().search(/^[0-9]+$/) == 0 || pieces < 1 || pieces == '') {
		alert("Zadejte, prosím, počet kusů.");
		return false;
	}
	
	$('#product_id').val(id);
	$('#product_pieces').val($('#pieces-'+id).val());
	$('#pieces').val($('#pieces-'+id).val());
	$('#prod').val($('#name-'+id).val());
	
	otevriPanel('formular');
	
}

function order() {
	
	$('.disable-input').each(
		function() {
			$(this).attr('readonly', 'true');
		}
	)
	
//	$('.disable-checkbox').each(
//		function() {
//			$(this).attr('disabled', 'disabled');
//		}
//	)
		
	otevriPanel('order-info');
	document.location.href="#formular";
}

function checkCheckbox(id, i) {
	
	var pieces = $('#pieces-'+id).val();
	
	if (!pieces.toString().search(/^[0-9]+$/) == 0 || pieces < 1 || pieces == '') {
		
		alert("Zadejte, prosím, počet kusů.");
		$('#pieces-'+id).val('0');
		$('#uniform-name-'+i+' span').removeClass('checked');
		$('#name-'+id).attr('checked', false);
		return false;
		
	} else {
		
		$('#uniform-name-'+i+' span').addClass('checked');
		$('#name-'+id).attr('checked', true);
	}	
	
}
