function confirmSubmit(infotext)
{
  var agree=confirm(infotext);
  if (agree){
    return true ;
  } else {
    return false ;
  }
}

// general submit form function
function submitForm(_formName, _actionName, _actionValue)
{ 	
  	var actionName = document.getElementById(_actionName) ;
  	
  	if(actionName == null)
  	{
  		alert("Error: you have to define hidden action variable") ;
  		return ;
	}
  	actionName.value = _actionValue ;
  	document.forms[_formName].submit();

}

function submitenter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)
	{
	   myfield.form.submit();
	   return false;
	}
	else
	   return true;
}

function showhide(id) 
{
	if(document.getElementById(id).style.display=='none')
	{
		document.getElementById(id).style.display='block';
	}
	else
		document.getElementById(id).style.display='none';
}

function openpopup(url)
{
	window.open(url,'popUpWindow','height=1000,width=1200,left=0,top=0,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=no')
}

function openpopupform(url)
{
	window.open(url,'popUpWindow','height=1000,width=780,left=0,top=0,resizable=yes,scrollbars=yes,toolbar=no,menubar=yes,location=no,directories=no,status=no')
}

function addtofavorite(adres,opis)
{
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(opis, adres,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( adres, opis); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
}

function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}

function textCounter(field, countfield, maxlimit) 
{
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
	else 
		countfield.value = maxlimit - field.value.length;
}


var personCount = 0;

function delPerson() 
{
	if(personCount > 0)
	{
		jQuery("#person_"+personCount).remove();
		personCount -= 1;
	}
}

function addPerson($add) 
{
	if($add)
	{
		jQuery.get("addPerson.php?count="+personCount+"&add=true",
	        function(data){
	            jQuery('#person').append(data);
	            personCount += 1;
					
				jQuery('input').focus(function () {
				  jQuery(this).parent().parent().find('.redCornerInput').show();
			    });
				
				jQuery('input').blur(function () {
				  jQuery(this).parent().parent().find('.redCornerInput').hide();
			    });

	        }
	    );
	} else {
		jQuery.get("addPerson.php?count="+personCount+"&add=false",
	        function(data){
	            jQuery('#person').append(data);
	            
	            jQuery('input').focus(function () {
				  jQuery(this).parent().parent().find('.redCornerInput').show();
			    });
				
				jQuery('input').blur(function () {
				  jQuery(this).parent().parent().find('.redCornerInput').hide();
			    });
	        }
	    );
	}
}

function updatePersonCount($count) 
{
	personCount = $count;
	addPerson(false);
}

function download1($file)
{
	setTimeout("window.open('files/download/"+$file+"','Download')",1000);   
}

function ChangeImage(id, img_name) 
{
	document.getElementById(id).src = img_name;
	//document[img_name].src=img_nazwa;
}

function AllowNewsletter() 
{
	var n = jQuery(".NewsVal:checked").length;
	if(n == 2)
	{
		jQuery("#SendNewsletter").show();
		jQuery("#SendNewsletterBlank").hide();
	} else {
		jQuery("#SendNewsletter").hide();
		jQuery("#SendNewsletterBlank").show();
	}
}

