var newWindow = null;

function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	
	closeWin();
	
	if (type == "fullScreen"){
		strWidth = screen.availWidth - 10;
		strHeight = screen.availHeight - 160;
	}
	
	var tools="";
	if (type == "standard" || type == "fullScreen") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}

function validateSendFriend()
{
	var emailFilter=/^.+@.+\..{2,3}$/;
	error = "";
	if (document.getElementById('ac-frm-email').value == '')
	{
		 error = "Vyplňte Vaši emailovou adresu.\n";
	}
	else if (!(emailFilter.test(document.getElementById('ac-frm-email').value))) { 
	      error = "Vyplňte správně Vaši emailovou adresu.\n";
	}	
	if (document.getElementById('ac-frm-email-r').value == '')
	{
		error += "Vyplňte email příjemce.\n";
	}
	else if (!(emailFilter.test(document.getElementById('ac-frm-email-r').value))) { 
	      error += "Vyplňte správný email příjemce.\n";
	}	
	if (error.length > 0)
	{
		alert(error);
		return false;
	}
}


function validationResult (result)
{
	if (result == "") {
		return true;
	} else {
		alert (result);
		return false;
	} 
}

function validateInput (element, regex, obligate, label)
{
	if (element.value == "") {
		if (obligate == 1) {
			return "Pole '" + label + "' nesmí být prázdné.\n";
		} else {
			return "";
		}
	} else {
		if (element.value.match(regex)) {
			return "";
		} else {
			return "Hodnota v poli '" + label + "' nemá povolený formát.\n";
		}
	}
}
