
var Id = "total";
function describe(string){
	if(document.layers){
		with (document[Id].document){
			open();
			write(string);
			close();
		}
	} else if (document.all){
		document.all[Id].innerHTML = string;
	} else if (document.getElementById){
		jxdocrange = document.createRange();
		jxdocrange.setStartBefore(document.getElementById(Id));
		while (document.getElementById(Id).hasChildNodes()){
			document.getElementById(Id).removeChild(document.getElementById(Id).lastChild);
		}
		document.getElementById(Id).appendChild(jxdocrange.createContextualFragment(string));
	}
}

function checkit(form)
{
	// Get value of the 'How' select box.
	check = 0;

    size = count;
	for (i=0;i<size;i++){
		check += parseInt(form.elements[i].options[form.elements[i].selectedIndex].value);
	}
	if (check<1)
	{
		alert('Du måste välja minst en bok!');
		//box.focus()
		return;
	}		

	// In textstring I gather the data that are finally written to the textarea.

	var textstring = '';
	
	// First of all, have all the text boxes been filled in?
	// This part is treated in the normal page.
	// I put all boxes and their values in textstring

	for (i=size;i<(size+7);i++)
	{
		box = form.elements[i];		
		if (!box.value && box.name.indexOf('email') == -1)
		{
			alert('Du har inte fyllt i ' + box.title + '!');
			box.focus()
			return;
		}
		textstring += box.name + ': ' + box.value + '\n';
	}
	
	emailOK = IsEmailValid('orderforms','email');	
	
	// Write textstring to the textarea.

	//document.form.output.value = textstring;
	//Calc();

		
	if(emailOK)	{
		//alert(textstring);
		//form.btnsend.disabled = true; 
		document.forms['orderforms'].elements['btnsend'].disabled = true; 
		form.submit();
	
	}
	else
		alert('Du har skrivit in en felaktig epostadress!');
}



function Calc(){
	var Price = 0;
	var Frakt = 0;
	var Amount = new Array();
	Amount[0]=0;
	var Sum = 0;

	//document.Order.frakt.value = Frakt;

	//get amount	
    for(i=1;i<100;i++){
        if("article"+i == article[i]){
            art = article[i];
        	var selected = document.getElementById(art).selectedIndex;
        	Amount[i] = document.getElementById(art).options[selected].value;   
            
        }
    }

	var textstring = '';	
	//ingen frakt --> Sum = (Amount * Price) + Frakt;
	//for (i=1;i<=4;i++){
    for (i in ids){
		Sum += (Amount[i] * prices[i]);
		textstring += Amount[i] + ': ' + prices[i] + '\n';
	}
	//document.form.total.value = Sum;
	describe(Sum.toString() + " SEK");
	//textstring += Sum;	
	//alert(textstring);
}

function IsEmailValid(FormName,ElemName){

// Copyright: (c) 1998 Shawn Dorman
// http://www.goodnet.com/~sdorman/web/IsEmailValid.html
// Source: Webmonkey Code Library
// (http://www.hotwired.com/webmonkey/javascript/code_library/)

	var EmailOk  = true
	var Temp     = document.forms[FormName].elements[ElemName]
	var AtSym    = Temp.value.indexOf('@')
	var Period   = Temp.value.lastIndexOf('.')
	var Space    = Temp.value.indexOf(' ')
	var Length   = Temp.value.length - 1 // Array is from 0 to length-1
	
	if(!Temp.value){
		return EmailOk;
	}
	// '@' cannot be in first position
	// Must be atleast one valid char btwn '@' and '.'
	// Must be atleast one valid char after '.'
	// No empty spaces permitted
	if ((AtSym < 1) || (Period <= AtSym+1) || (Period == Length ) || (Space  != -1)){
		EmailOk = false
		Temp.focus()
	}

	return EmailOk
}
