document.observe('dom:loaded', function() {

	if( $('mapa-cr') )
	{
		var flashvars = {};
		var params = {};
		params.quality = "best";
		params.wmode = "transparent";
		var attributes = {};
		swfobject.embedSWF("/swf/mapa-cr.swf", "mapa-cr", "220", "160", "9.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);

		$('county_id').observe('change', function(e){
			refreshServiceCenters();
		});
	}
	
	if( $('mapa-cr2') )
	{
		var flashvars = {};
		var params = {};
		params.quality = "best";
		params.wmode = "transparent";
		var attributes = {};
		swfobject.embedSWF("/swf/mapa-cr2.swf", "mapa-cr2", "320", "240", "9.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);
	}
});

function changepic(img_name, img_src)
{
	document[img_name].src = img_src;
}

function vyberKraj( cislo )
{
	$('county_id').setValue(cislo);
	refreshServiceCenters();
}

function vyberKraj2( cislo )
{
	new Ajax.Updater('countycontent2', '/ajax.php', {
	  parameters: { counties_id: cislo, module: 'loadcenters', content: 'true' }
	});
}

function refreshServiceCenters()
{
	new Ajax.Updater('countycontent', '/ajax.php', {
	  parameters: { counties_id: $('county_id').getValue(), module: 'loadcenters' }
	});
}

function checkInstallAvailability()
{
	new Ajax.Request('/ajax.php?module=countyinfo&zip=' + $('zip').getValue(), {
	  method: 'get',
	  onSuccess: function(transport) {
	    if( transport.responseText == 1 )
		{
			$('elem6_1_dl').show();
			$('elem7_4_wrap').show();
			$('install').update('Ve vaší lokalitě <strong>je</strong> dostupná služba instalace.');
		}
		else
		{
			$('elem6_1_dl').hide();
			$('elem7_4_wrap').hide();// = true;
			
			if( $('zip').getValue() != '' )
				$('install').update('Ve vaší lokalitě není dostupná služba instalace.');
		}
	  }
	});
}


	
function checkint(field)
{
		field = $(field);
      var check = true;
      var value = field.value; //get characters
      //check that all characters are digits, ., -, or ""
      for(var i=0;i < field.value.length; ++i)
      {
           var new_key = value.charAt(i); //cycle through characters
           if(((new_key < "0") || (new_key > "9")) &&
                !(new_key == ""))
           {
                check = false;
                break;
           }
      }
      //apply appropriate colour based on value
      if(!check)
      {
           alert('Do položky Ks zadávejte pouze čísla.');
           field.activate();
           return false;
		//	field.setStyle('background', 'red');
      }
      else
      {
      //field.setStyle('background', 'white');
           return true;
      }
 }
function checkintAll()
{
	$A($$('input.integer')).each(
			function( element ){
				if( !checkint(element) )
				    return false;
			}
		);
		
	return true;
}
