var postLocation="pgbar.php";

/* 
 * add any extension that you do no want to upload to the list 
 * below they should be placed with in the /^ and / characters
 * separate each extension by a pipe symbol |
 */
 
var re = /^(\.php)|(\.sh)/;  // disallow shell scripts and php


/**
 * dofilter = true; to enable filtering
 */
var dofilter=false;

/**
 * this method will match each of the filenames with a
 * given list of banned extension. If any one of the
 * extensions match, an alert will be popped up and the
 * upload will not continue;
 */

function wnd(what,w,h)
{
	v = "width="+(w+32)+",height="+(h+32)+",scrollbars=1";
	okno = window.open(what,"",v);
}

 
function check_types() {
	if(dofilter==false)
		return true;
	with(document.frm)
	{
		/*
		 * with who uses with?
		 * i do, i am an ancient. ok?
		 */
		
		for(i=0 ; i < elements.length ; i++)
		{
			if(elements[i].value.match(re))
			{
				alert('Sorry ' + elements[i].value + ' is not allowed');
				return false;
			}
		}
	}
	return true;
}

function popUP(mypage, myname, w, h, scroll, titlebar)
{

	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=0,status=no,location=no'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

function postIt()
{

	if(check_types() == false)
	{
		return false;
	}
	baseUrl = postLocation;
	sid = document.frm.sessionid.value;
	iTotal = escape("-1");
	baseUrl += "?iTotal=" + iTotal;
	baseUrl += "&iRead=0";
	baseUrl += "&iStatus=1";
	baseUrl += "&oid=" + document.frm.fPWOrderID.value;

	// toto musi byt na konci stringu
	baseUrl += "&sessionid=" + sid;
	
	
	popUP(baseUrl,"Uploader",460,262,false,false);
	document.frm.submit();
}

function preklop(co,kde)
{
	kam = co.item(co.selectedIndex).value;
	location.replace(kde+kam);
}

function hideAttachments()
{
	document.all.fAttachmentsArea.style.display = 'none';
}
function showAttachments()
{
	document.all.fAttachmentsArea.style.display = 'block';
}
function hideCourier()
{
	document.all.courier.style.display = 'none';
}
function showCourier()
{
	document.all.courier.style.display = 'block';

}
function hideBindingInfo()
{
	document.all.bindingInfo.style.display = 'none';

}
function showBindingInfo()
{
	document.all.bindingInfo.style.display = 'block';

}
function changePaperTypes()
{
	if (document.all.paperType.value == 'matný')
	{
		document.all.fGlossy.style.display = 'none';
		document.all.fOther.style.display = 'none';
		document.all.fOpaque.style.display = 'block';
	}
	if (document.all.paperType.value == 'lesklý')
	{
		document.all.fGlossy.style.display = 'block';
		document.all.fOther.style.display = 'none';
		document.all.fOpaque.style.display = 'none';
	}
	if (document.all.paperType.value == 'iný')
	{
		document.all.fGlossy.style.display = 'none';
		document.all.fOther.style.display = 'block';
		document.all.fOpaque.style.display = 'none';
	}
}
function changePaperTypes2()
{
	if (document.all.paperType2.value == 'matný')
	{
		document.all.fGlossy2.style.display = 'none';
		document.all.fOther2.style.display = 'none';
		document.all.fOpaque2.style.display = 'block';
	}
	if (document.all.paperType2.value == 'lesklý')
	{
		document.all.fGlossy2.style.display = 'block';
		document.all.fOther2.style.display = 'none';
		document.all.fOpaque2.style.display = 'none';
	}
	if (document.all.paperType2.value == 'iný')
	{
		document.all.fGlossy2.style.display = 'none';
		document.all.fOther2.style.display = 'block';
		document.all.fOpaque2.style.display = 'none';
	}
}
function checkFlyerOrder()
{
	var checked = false;
	var isOK = true;
	var msg = "";
	var attchMode;
	
	//return true;
	if (typeof(document.all.fAttachmentMode) != "undefined")
	{
		for (var i=0; i < document.all.fAttachmentMode.length; i++)
		{
			if (document.all.fAttachmentMode[i].checked)
			{
				document.all.fAttachmentHiddenMode.value = document.all.fAttachmentMode[i].value;
				checked = true;
				attchMode = document.all.fAttachmentMode[i].value;;
				break;
			}
		}
	}
	if (!checked)
	{
		isOK = false;
		msg += "Vyberte prosím, spôsob dodania podkladov pre tlač.";
	}
	//alert(document.all.fAttachmentHiddenMode.value);
	if (attchMode == 2)
	{
		if (document.all.fNumOfAttachments.value == 0)
		{
			isOK = false;
			msg = "\Nie sú priložené žiadne súbory ako príloha.";
		}
	}
	
	if (document.all.fOsoba.value == "" || document.all.fUserPhone.value == "" || document.all.fUserEmail.value == "")
	{
		isOK = false;
		msg += "\nNie sú vyplnené všetky povinné údaje.";
	}
	if (document.all.fAcceptVOP.checked != true)
	{
		isOK = false;
		msg += "\nJe potrebné súhlasiť so všeobecnými obchodnými podmienkami.";
	}
	if (msg != "")
		alert(msg);

	return isOK;
}

function flyerSubmit()
{
	var isOK = true;
	var msg = "";
	
	for (var i=0; i < document.all.fPWDimensions.length; i++)
	{
		if (document.all.fPWDimensions[i].checked)
		{
			if (document.all.fPWDimensions[i].value == "other")
			{
				sirka = document.getElementById("fLeafletWidth").value;
				vyska = document.getElementById("fLeafletHeight").value;
				sirka.replace(/,/g,".");
				vyska.replace(/,/g,".");
				sirka.replace(/ /g,"");
				vyska.replace(/ /g,"");
				sirka *= 1;
				vyska *= 1;
				if (sirka > 0 && vyska > 0)
					isOK = true;
				else
				{
					//alert("Zadajte prosím správne číslené hodnoty.");
					msg = "Zadajte prosím správne číslené hodnoty pre rozmer.";
					isOK = false;
				}
			}
			else
				isOK = true;
		}
	}

	if (typeof(document.all.fPWPostpress) != "undefined")
	{
		for (var i=0; i < document.all.fPWPostpress.length; i++)
		{
			if (document.all.fPWPostpress[i].checked)
			{
				hodnota = document.all.fPWPostpressCount.value;
				hodnota.replace(/,/g,".");
				hodnota.replace(/ /g,"");
				hodnota *= 1;
				if (hodnota > 0)
					isOK = true;
				else
				{
					isOK = false; 	
					msg += "\nZadajte správnu číselnú hodnotu pre počet operácií knihárskeho spracovania.";
				}
			}
		}
	}
	if (msg != "")
		alert(msg);
	return isOK;
}

