function checkMaxChecked(iMax, iFree, oCheckBox) {
	var iBooksChecked = GetNoOfCheckedBooks();
	if(oCheckBox.checked == true)
	{
		if(iBooksChecked > (iMax + iFree)) {
			if (iMax == 1) {
				alert('Du har valgt mer enn 1 bok');
			}
			else {
				alert('Du har valgt mer enn ' + iMax + ' bøker');
			}
			oCheckBox.checked = false;
		}
	}
}

function checkMaxCheckedFastReplyBooks(iMax, oCheckBox) {
	var iBooksChecked = GetNoOfCheckedFastReplyBooks();
	if(oCheckBox.checked == true)
	{
		if(iBooksChecked > (iMax)) {
			if (iMax == 1) {
				alert('Du har valgt mer enn 1 hurtigsvar bok');
			}
			else {
				alert('Du har valgt mer enn ' + iMax + ' hurtigsvar bøker');
			}
			oCheckBox.checked = false;
		}
	}
}

function GetNoOfCheckedBooks() {
	var iTmp = 0;
	var sTmp = "";
	for (var i=0; i < document.forms[0].length; i++){
		sTmp = document.forms[0][i].name.toLowerCase();
		if (sTmp.indexOf("orderno", 0) == 0) {
			if (document.forms[0][i].checked == true) {
				iTmp = iTmp + 1;
			}
		}
	}
	return iTmp; 
}

function GetNoOfCheckedFastReplyBooks() {
	var iTmp = 0;
	var sTmp = "";
	for (var i=0; i < document.forms[0].length; i++){
		sTmp = document.forms[0][i].name.toLowerCase();
		if (sTmp.indexOf("fastreply", 0) == 0) {
			if (document.forms[0][i].checked == true) {
				iTmp = iTmp + 1;
			}
		}
	}
	return iTmp; 
}

function CheckNoOfSelectedBooks(iNoOfMinSelectedBooks, iNoOfFreeBooks) {
	var iBooksChecked = GetNoOfCheckedBooks();
	if (iBooksChecked != (iNoOfMinSelectedBooks + iNoOfFreeBooks)) {	
		if (iNoOfMinSelectedBooks == 1) {
			alert('Du har ikke valgt 1 bok');
		}
		else {
			alert('Du har ikke valgt ' + iNoOfMinSelectedBooks + ' bøker');
		}
		return false;
	}
	return true;
}

function CheckNoOfSelectedBooks2(iNoOfMinSelectedBooks, iNoOfFreeBooks, iNoOfFastReplyBooks) {
    if (CheckNoOfSelectedBooks(iNoOfMinSelectedBooks, iNoOfFreeBooks))
    {
        //check Fast Reply books
	    var iNrOfCheckedFastReplyBooks = GetNoOfCheckedFastReplyBooks();
	    if (iNrOfCheckedFastReplyBooks != iNoOfFastReplyBooks) {	
		    if (iNoOfFastReplyBooks == 1) {
			    alert('Du har ikke valgt 1 hurtigsvar bok');
		    }
		    else {
			    alert('Du har ikke valgt ' + iNoOfFastReplyBooks + ' hurtigsvar bøker');
		    }
		    return false;
	    }
    }
    else
    {
        return false;
    }
    return true;
}

function Caida_Validate() {
	var sRC;
	if (document.frmCaida.MustValidate.value == "1") {
		for (var i=0; i < document.forms[0].length; i++){
			if (document.forms[0][i].name == "Validation") {
				if (eval(document.forms[0][i].value) == false) {
					return false;
				}
			}
		}
	}
}

function LTrim(instr){
	if (instr.charAt(0) == ' '){
		instr = LTrim(instr.substring(1));
	}
	return instr;
}
function RTrim(instr){
	p_instr = instr.toString();
	if (p_instr.charAt(p_instr.length - 1) == ' '){
		p_instr = RTrim(p_instr.substring(0, p_instr.length - 1));
	}
	return p_instr;
}
function Trim(instr){
	return LTrim(RTrim(instr));
}
function infoPopup(subject, text, width, height){
    var oInf = window.open("/_caida/Popup/information.asp?subject="+subject+"&text="+text,null,"height="+height+",width="+width+",status=no,toolbar=no,menubar=no,location=no,resizable=1,scrollable=yes");
}
