function zip_addr (zip)
{
	var zipValue = zip.value;
	http.open("GET", "/ajax.php?do=zipcode&zipcode=" + escape(zipValue), true);
	
	http.onreadystatechange = zip_addr_set;
	http.send(null);
}

function zip_addr_set ()
{
	document.getElementById('or_zipcode_place').innerHTML = http.responseText;
}

function zip_addr2 (zip)
{
	var zipValue = zip.value;
	http.open("GET", "/ajax.php?do=zipcode&zipcode=" + escape(zipValue), true);
	
	http.onreadystatechange = zip_addr_set2;
	http.send(null);
}

function zip_addr_set2 ()
{
	document.getElementById('or_zipcode_place2').innerHTML = http.responseText;
}

function pr_baddr_toggle ()
{
	toggler = document.getElementById('o_bill_diff');
	toogleform = document.getElementById('br_baddress_table');
	
	if (toggler.checked)
	{
		toogleform.style.display = "block";
	} else
	{
		toogleform.style.display = "none";
	}
	
	
}

function ordersummary ()
{
	numprods = prodids.length;
	
	price_mnd = 0;
	price_inst = 0;
	
	for (i=0;i<numprods;i++)
	{
		prodid = prodids[i];
		if (document.getElementById('check_' + prodid).checked)
		{
			document.getElementById('orderline_' + prodid).setAttribute('class', 'orderline_active');
			document.getElementById('orderline_' + prodid).setAttribute('className', 'orderline_active');
			
			
			if (prodtypes[prodid] == 'subscription')
			{
				price_mnd += prices[prodid];
			} else
			{
				price_inst += prices[prodid];
			}
			
		} else
		{
			document.getElementById('orderline_' + prodid).setAttribute('class', 'orderline');
			document.getElementById('orderline_' + prodid).setAttribute('className', 'orderline');
		}
		
	}
	
	//document.getElementById('price_mnd').innerHTML = price_mnd.toFixed(0)+",-";
	//document.getElementById('price_inst').innerHTML = price_inst.toFixed(0)+",-";
	
}

function checkOrderForm (theForm)
{
	var reason = "";
	
	reason += validateEmpty(theForm.o_firstname,"fornavn");
	reason += validateEmpty(theForm.o_lastname,"lastname");
	reason += validateEmpty(theForm.o_tlf,"telefon");
	reason += validateEmpty(theForm.o_address_street,"gatenavn");
	reason += validateEmpty(theForm.o_address_zipcode,"postnummer");
	reason += validateEmpty(theForm.o_address_number,"husnr");
	reason += validateEmpty(theForm.o_address_apartment,"leilighetsnummer");
	reason += validateEmpty(theForm.o_email,"e-post");
	
	if (theForm.accept.checked == false)
	{
		reason += "* Du må godta vilkårene.";
	}
	
	if (reason != "") {
		alert("Noen feil oppstod:\n" + reason);
		return false;
	}

	return true;
}

function validateEmpty(fld,navn) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#ff9c9c'; 
        error = "* Vennligst fyll inn " + navn + ".\n"
    } else {
        fld.style.background = '#ffffff';
    }
    return error;
}


