
function getFirstPayment()
{
	document.forwardForm.fyrstagr.value = Math.round((document.forwardForm.heildarupphaed.value / 12));
}

function fncCheckReikna()
{
	if(document.forwardForm.tegund_korts.value == "")
	{
		alert("Þú verður að velja tegund korts!");
		document.forwardForm.tegund_korts.focus()
		return false;
	}
	
	if(document.forwardForm.heildarupphaed.value == "")
	{
		alert("Þú verður að fylla út heildarupphæð greiðsludreifingar!");
		document.forwardForm.heildarupphaed.focus();
		return false;
	}
	else
	{
		if( isNaN(document.forwardForm.heildarupphaed.value) )
		{
			alert("Heildarupphæð greiðsludreifingar má aðeins innihalda tölustafi!");
			document.forwardForm.heildarupphaed.focus();
			return false;
		}
	}
	
	if(document.forwardForm.fyrstagr.value != "")
	{
		if(isNaN(document.forwardForm.fyrstagr.value))
		{
			alert("Fyrsta greiðsla má aðeins innihalda tölustafi!");
			document.forwardForm.fyrstagr.focus();
			return false;
		}
		
		nFyrstaGreidsla = Math.round(document.forwardForm.heildarupphaed.value / 12);
	
		if(document.forwardForm.fyrstagr.value < nFyrstaGreidsla)
		{
			alert("Fyrsta greiðsla er of lág, verður að vera amk. 1/12 af heildarupphæð!");
			document.forwardForm.fyrstagr.focus();
			return false;
		}
	}
	
	if(document.forwardForm.fjoldi_man.value == "")
	{
		alert("Þú verður að velja fjölda mánaða!");
		document.forwardForm.fjoldi_man.focus();
		return false;
	}
	
	return true;
}

function fncReikna(strType)
{
	if(fncCheckReikna())
	{
		// Birtum svæðið.
		document.getElementById("lblReikna").style.visibility = "visible";
		
		try
		{
			xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
			document.getElementById('lblReikna').innerHTML = "Villa: Ekki náðist samband við netþjóninn, reyndu aftur!";
			return false;
		}
		
		xmlhttp.onreadystatechange = function() {
			if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
			{
				sResults = xmlhttp.responseText.split(",");
			
				//alert(xmlhttp.responseText);
			
				document.getElementById('lblReikna').innerHTML = "<img src=\"/s24/upload/files/code/reiknivelar/greidsludreifing/ajax_load.gif\" width=\"16\" height=\"16\" alt=\"page_loading\">Reikna...";
				document.getElementById("lblReikna").innerHTML = xmlhttp.responseText;
			}
		}
	
		xmlhttp.open("GET", "/s24/upload/files/code/beidnir/reikna/greidsludreifing.asp?upph=" + document.getElementById('heildarupphaed').value + "&fyrstagr="+ document.forwardForm.fyrstagr.value +"&fjoldi=" + document.getElementById('fjoldi_man').value + "&kort=" + document.getElementById('tegund_korts').value + "&teg=" + strType, true);
		xmlhttp.send(null);
	}
}
