function newWindow(oElm, iWidth, iHeight)
{
	var sOption = "width=" + iWidth + ", height=" + iHeight + ", left=10, top=10, resizable=yes, scrollbars=yes";
	if (window.open(oElm.href, oElm.target, sOption))
	{
		return true;
	}
	return false;
}

function createEmail(sName)
{
	var sDomain = "elektrohadrava.cz";
	var sLink = sName + "@" + sDomain;
	document.write("<a hre" + "f=ma" + "ilto:" + sName + "@" + sDomain + ">" + sLink + "</a>"); 
}

function checkPass()
{
	if(document.getElementById('Email').value=="")
	{
		window.alert("Před odesláním formuláře musíte vyplnit email!");
		document.getElementById('Email').style.backgroundColor = "#ffb0b0";
		document.getElementById('Email').focus();
		return false;
	}
	else
	{
		return true;
	}
}

function checkOrder()
{
	var bOrder = true;
	
	if(document.getElementById('Payment').value=="0")
	{
		window.alert("Před odesláním formuláře musíte vybrat způsob platby!");
		document.getElementById('Payment').style.backgroundColor = "#ffb0b0";
		document.getElementById('Payment').focus();
		bOrder = false;
	}
	else if(document.getElementById('Delivery').value=="0")
	{
		window.alert("Před odesláním formuláře musíte vybrat způsob dodání!");
		document.getElementById('Delivery').style.backgroundColor = "#ffb0b0";
		document.getElementById('Delivery').focus();
		document.getElementById('Payment').style.backgroundColor = "#ffffff";
		bOrder = false;
	}
	else if(document.getElementById('needRegister') && document.getElementById('needRegister').value=="true")
	{
		bOrder = checkRegistration();
	}

	return bOrder;

}

function checkRegistration()
{
	document.getElementById('Subject').style.backgroundColor = "#ffffff";
	document.getElementById('Name1').style.backgroundColor = "#ffffff";
	document.getElementById('Address1').style.backgroundColor = "#ffffff";
	document.getElementById('City1').style.backgroundColor = "#ffffff";
	document.getElementById('Zip1').style.backgroundColor = "#ffffff";
	document.getElementById('Phone').style.backgroundColor = "#ffffff";
	document.getElementById('Email').style.backgroundColor = "#ffffff";
	document.getElementById('Bussines1').style.backgroundColor = "#ffffff";
	document.getElementById('Bussines2').style.backgroundColor = "#ffffff";

	if(document.getElementById('Subject').value=="0")
	{
		window.alert("Před odesláním formuláře musíte vybrat subjekt!");
		document.getElementById('Subject').style.backgroundColor = "#ffb0b0";
		document.getElementById('Subject').focus();
		return false;
	}
	else if(document.getElementById('Name1').value=="")
	{
		window.alert("Před odesláním formuláře musíte vyplnit název společnosti!");
		document.getElementById('Name1').style.backgroundColor = "#ffb0b0";
		document.getElementById('Name1').focus();
		return false;
	}
	else if(document.getElementById('Address1').value=="")
	{
		window.alert("Před odesláním formuláře musíte vyplnit adresu!");
		document.getElementById('Address1').style.backgroundColor = "#ffb0b0";
		document.getElementById('Address1').focus();
		return false;
	}
	else if(document.getElementById('City1').value=="")
	{
		window.alert("Před odesláním formuláře musíte vyplnit město!");
		document.getElementById('City1').style.backgroundColor = "#ffb0b0";
		document.getElementById('City1').focus();
		return false;
	}
	else if(document.getElementById('Zip1').value=="")
	{
		window.alert("Před odesláním formuláře musíte vyplnit PSČ!");
		document.getElementById('Zip1').style.backgroundColor = "#ffb0b0";
		document.getElementById('Zip1').focus();
		return false;
	}
	else if(document.getElementById('Phone').value=="")
	{
		window.alert("Před odesláním formuláře musíte vyplnit telefon!");
		document.getElementById('Phone').style.backgroundColor = "#ffb0b0";
		document.getElementById('Phone').focus();
		return false;
	}
	else if(!checkEmail(document.getElementById('Email').value))
	{
		window.alert("Před odesláním formuláře musíte vyplnit email!");
		document.getElementById('Email').style.backgroundColor = "#ffb0b0";
		document.getElementById('Email').focus();
		return false;
	}
	else if(document.getElementById('Subject').value=="Firma" && document.getElementById('Bussines1').value=="")
	{
		window.alert("Před odesláním formuláře musíte vyplnit IČO!");
		document.getElementById('Bussines1').style.backgroundColor = "#ffb0b0";
		document.getElementById('Bussines1').focus();
		return false;
	}
	else if(document.getElementById('Subject').value=="Firma" && document.getElementById('Bussines2').value=="")
	{
		window.alert("Před odesláním formuláře musíte vyplnit DIČ!");
		document.getElementById('Bussines2').style.backgroundColor = "#ffb0b0";
		document.getElementById('Bussines2').focus();
		return false;
	}
	else if(!document.getElementById('Agree').checked)
	{
		window.alert("Před odesláním formuláře musíte souhlasit s obchodními podmínkami!");
		return false;
	}
	else
	{
		return true;
	}
}

function checkEmail(address)
{
	re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,3}$/;
	return address.search(re) == 0;
}

function changeBoost()
{
	var FinalPrice = parseInt(document.getElementById('PriceVatTemp').value);
	document.getElementById('boost').innerHTML = "";
	if (FinalPrice < 3000) document.getElementById('boost').innerHTML = "<span>Hodnota objednávky je nižší než <strong>3 000.00 Kč</strong>, bude započítáno dopravné. Pokud přidáte do košíku zboží za alespoň <strong>" + (3000 - FinalPrice) + ".00 Kč</strong>, ušetříte 144.00 Kč</span>";
}

function changePrice()
{
	var FinalPrice = document.getElementById('PriceVatTemp').value;

	var dot = FinalPrice.indexOf(".");
	var DecimalPlaces = '.00';
	
	if (dot > -1)
	{
		DecimalPlaces = FinalPrice.substring(dot, FinalPrice.length);	
	}

	FinalPrice = parseInt(FinalPrice);
	
	var PaymentMethod = document.getElementById('Payment').value;
	var DeliveryMethod = document.getElementById('Delivery').value;

	document.getElementById('paymentRow').style.display = "none";
	document.getElementById('paymentRowFree').style.display = "none";
	
	document.getElementById('deliveryRow').style.display = "none";	
	document.getElementById('deliveryRowCP').style.display = "none";
	document.getElementById('deliveryRowCPFree').style.display = "none";
	document.getElementById('deliveryRow50').style.display = "none";
	document.getElementById('deliveryRowFree').style.display = "none";
	document.getElementById('deliveryRowSK').style.display = "none";
	
	if (FinalPrice < 3000)
	{	
		if (PaymentMethod == 'Dobírkou – při převzetí zboží od přepravce (36,- Kč)')
		{
			FinalPrice = FinalPrice + 36;
			document.getElementById('paymentRow').style.display = "block";
		}
		
		if (DeliveryMethod == 'Dodání zboží ČR do 50 kg – přepravcem Geis (108,-Kč)')
		{
			FinalPrice = FinalPrice + 108;
			document.getElementById('deliveryRow').style.display = "block";
		}
		
		if (DeliveryMethod == 'Dodání zboží ČR do 30 kg – přepravcem Česká pošta (108,- Kč)')
		{
			FinalPrice = FinalPrice + 108;
			document.getElementById('deliveryRowCP').style.display = "block";
		}
	}
	else
	{
		if (PaymentMethod == 'Dobírkou – při převzetí zboží od přepravce (36,- Kč)')
		{
			document.getElementById('paymentRowFree').style.display = "block";
		}
		
		if (DeliveryMethod == 'Dodání zboží ČR do 50 kg – přepravcem Geis (108,-Kč)')
		{
			document.getElementById('deliveryRowFree').style.display = "block";
		}
		
		if (DeliveryMethod == 'Dodání zboží ČR do 30 kg – přepravcem Česká pošta (108,- Kč)')
		{
			document.getElementById('deliveryRowCPFree').style.display = "block";
		}
	}
	
	if (DeliveryMethod == "Dodání zboží ČR nad 50 kg – přepravcem Geis (660,-Kč)")
	{
			document.getElementById('deliveryRow50').style.display = "block";
			
			FinalPrice = FinalPrice + 660;
	}
	
	if (DeliveryMethod == "Dodání zboží SLOVENSKO do 10 kg – přepravcem Česká pošta (300,-Kč)")
	{
			document.getElementById('deliveryRowSK').style.display = "block";
			
			FinalPrice = FinalPrice + 300;
	}
	
	document.getElementById('PriceVat').value = parseFloat(FinalPrice + DecimalPlaces).toFixed(2);
}

function Image_Show(sImageID, sImageSrc)
{
	document.getElementById(sImageID).src = sImageSrc;
	document.getElementById(sImageID).alt = sImageID;
	document.getElementById(sImageID).style.display = "block";
}

function Image_Hide(sImageID)
{
	document.getElementById(sImageID).src = "";
	document.getElementById(sImageID).alt = "";
	document.getElementById(sImageID).style.display = "none";
}
