function VyplnFormAction(skript)
{					  
	var FormElement = document.getElementById("order-form");

	var NahodneCislo = Math.round((Math.random() * 20000)) * 8513; 
	
	test = testPovinnychPolozek();
	if (test){
		if (FormElement != undefined){
			FormElement.action = BASE__URL + 'tools/'+skript+'?AuthKey=' + NahodneCislo; 	
		}
		return true;
	} else {
		return false;
	}
}

 //-----------------------------------------------------------------------------------
 
 function testPovinnychPolozek(){
 	
 	error = document.getElementById('errorMess').value
 	
 	if (document.getElementById('boxClientObjednavajici').style.display != 'none'){
 	
		 	res = checkString(document.getElementById('test1'));
		 	if (res == false){
		 		alert(error);
		 		return false;
		 	}
		 	
		 	res = checkString(document.getElementById('test2'));
		 	if (res == false){
		 		alert(error);
		 		return false;
		 	}
		 	
		 	res = checkString(document.getElementById('test2'));
		 	if (res == false){
		 		alert(error);
		 		return false;
		 	}
		 	
		 	res = checkEmail(document.getElementById('test3'));
		 	if (res == false){
		 		alert(error);
		 		return false;
		 	}
		 	
		 	res = checkString(document.getElementById('test4'));
		 	if (res == false){
		 		alert(error);
		 		return false;
		 	}
		 	
		 	res = checkString(document.getElementById('test5'));
		 	if (res == false){
		 		alert(error);
		 		return false;
		 	}
 	}
 	
 	res = checkString(document.getElementById('test6'));
 	if (res == false){
 		alert(error);
 		return false;
 	}
 	
 	res = checkString(document.getElementById('test7'));
 	if (res == false){
 		alert(error);
 		return false;
 	}
 	
 	res = checkString(document.getElementById('test8'));
 	if (res == false){
 		alert(error);
 		return false;
 	}
 	
 	if (document.getElementById('addressRadio').checked == true){
		 	res = checkString(document.getElementById('test9'));
		 	if (res == false){
		 		alert(error);
		 		return false;
		 	}
    }
    if (document.getElementById('airportRadio').checked == true){
		  	res = checkString(document.getElementById('test10'));
		 	if (res == false){
		 		alert(error);
		 		return false;
		 	}
    }
  	res = checkString(document.getElementById('test11'));
 	if (res == false){
 		alert(error);
 		return false;
 	}
 	
 	
  	res = checkInt(document.getElementById('test12'));
 	if (res == false){
 		alert(error);
 		return false;
 	}
 	if (document.getElementById('backYopRadio').checked == true){
 		
 		if (document.getElementById('backAddressRadio').checked == true){
		  	res = checkString(document.getElementById('test13'));
		 	if (res == false){
		 		alert(error);
		 		return false;
		 	}
 		}
 		if (document.getElementById('backAirportRadio').checked == true){ 	
		  	res = checkString(document.getElementById('test14'));
		 	if (res == false){
		 		alert(error);
		 		return false;
		 	}
 		}	
 	}
 	return true;
 	
 }
 
 //-----------------------------------------------------------------------------------
 
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') {
		document.getElementById(divId).style.display='none';
	} else {
		document.getElementById(divId).style.display='block';
	}
}

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

function aktivujClientRadio()
{
	radio = document.getElementById( 'clientRadio' );
	if (radio.checked == true){
		
		showclose( 'boxClientObjednavajici', null );
	}
}
function aktivujMySelfRadio()
{
	radio = document.getElementById( 'myselfRadio' );
	if (radio.checked == true){
		showclose( null, 'boxClientObjednavajici' );
	}
}
//-----------------------------------------------------------------------------------
function aktivujAdresaRadio()
{
	radio = document.getElementById( 'addressRadio' );
	if (radio.checked == true){
		
		showclose( 'BoxAdresa', 'BoxLetiste' );
	}
}
function aktivujLetisteRadio()
{
	radio = document.getElementById( 'airportRadio' );
	if (radio.checked == true){
		showclose( 'BoxLetiste', 'BoxAdresa' );
	}
}
//-----------------------------------------------------------------------------------
function aktivujZpatecniAnoRadio()
{
	radio = document.getElementById( 'backYopRadio' );
	if (radio.checked == true){
		
		showclose( 'BackForm', null );
	}
}
function aktivujZpatecniNeRadio()
{
	radio = document.getElementById( 'backNoupRadio' );
	if (radio.checked == true){
		showclose( null, 'BackForm' );
	}
}

//-----------------------------------------------------------------------------------
function aktivujBackAdresaRadio()
{
	radio = document.getElementById( 'backAddressRadio' );
	if (radio.checked == true){
		showclose( 'back2AirportRadioPanel', null );
		showclose( 'BackBoxAdresa', 'BackBoxLetiste' );
	}
}
function aktivujBackLetisteRadio()
{
	radio = document.getElementById( 'backAirportRadio' );
	if (radio.checked == true){
		showclose( 'BackBoxLetiste', 'BackBoxAdresa' );
		showclose( null, 'back2AirportRadioPanel' );
	}
}

//-----------------------------------------------------------------------------------
function aktivujBack2AdresaRadio()
{
	radio = document.getElementById( 'back2AddressRadio' );
	if (radio.checked == true){
		
		showclose( 'Back2BoxAdresaPanel', null );
		showclose( 'backAirportRadioPanel', null );
	}
}
function aktivujBack2LetisteRadio()
{
	radio = document.getElementById( 'back2AirportRadio' );
	if (radio.checked == true){
		showclose( null, 'Back2BoxAdresaPanel' );
		showclose( null, 'backAirportRadioPanel' );
	}
}


//-----------------------------------------------------------------------------------
function showclose( showId, hideId )
{
	if (hideId != null){
		document.getElementById(hideId).style.display='none';
	}
	if (showId != null){	
		document.getElementById(showId).style.display='block';
	}	
}

//-----------------------------------------------------------------------------------
function checkString(id)
{
	
	val = id.value;
	if (val == ''){
		id.style.border = "1px solid red";
		return false;
	} else {
		id.style.border = "1px solid #DDDDDD";
		return true;
	}
}

function checkInt(id)
{
	
	val = parseInt(id.value);
	if (val > 0){
		id.style.border = "1px solid #DDDDDD";
		return true;
	} else {
		id.style.border = "1px solid red";
		return false;
	}
}

function checkEmail(id)
{
	str = id.value;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)){
		id.style.border = "1px solid #DDDDDD";
		return true;
	} else {
		id.style.border = "1px solid red";
		return false;
	}
}


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

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

	var NahodneCislo = Math.round((Math.random() * 20000)) * 8513; 
	
	jmeno = document.getElementById("jmeno").value;
	email = document.getElementById("email").value;
	mess = document.getElementById("mess").value;
	
	jmenoErr = document.getElementById("ErrJmeno").value;
	emailErr = document.getElementById("ErrEmail").value;
	messErr = document.getElementById("ErrVzkaz").value;
	
	
	if (!jmeno) {
		return ohlaschybu( jmenoErr );
	}
	if (!mess) {
		return ohlaschybu( messErr );
	}
	if (!email) {
		return ohlaschybu( emailErr );
	}
	
	if (FormElement != undefined){
		FormElement.action = BASE__URL + 'tools/'+skript+'?AuthKey=' + NahodneCislo; 	
	}
	
}
//-----------------------------------------------------------------------------------
function ohlaschybu(str){
   Ext.MessageBox.show({
	   title: 'Informace',
	   msg: str,
	   buttons: Ext.MessageBox.OK,
	   icon: Ext.MessageBox.INFO
	});		
	return false;
}
