/* Fuction to check terms and conditions is ticked (monthly donations gateway) */
function validateTerms () {
	var valid = true;
	var el = document.getElementById('termck');
	if ( el.checked == false ) {
		alert ( "Please check the Terms and Conditions box." );
		valid = false;
	}
	return valid;
}

/* Fuction to check terms and conditions & Gift aid are ticked on donations pages */
function validateGiftAid() {
    var theForm = document.donationform;
    var valid = true;
    var rad = theForm.os0;
    if (rad[0].checked == false && rad[1].checked == false) {
        alert("Please complete the gift aid option.");
        valid = false;
    }
    return valid;
}

/* On load... disable the free text input and enable the fixed list for the donation amount inputs */
function setupOptionalInputs() {
    var freeIn = document.getElementById('freeinput');
    var fixedIn = document.getElementById('fixedinput');
    freeIn.disabled = true;
    fixedIn.disabled = false;
}

/* Toggles the enabled/disabled property of the donation amount inputs */
function toggleFreeInput() {
    var freeIn = document.getElementById('freeinput');
    var fixedIn = document.getElementById('fixedinput');
    var toggle = document.getElementById('toggle_amount');
    freeIn.disabled = !toggle.checked;
    fixedIn.disabled = toggle.checked;
}

/* Function to make sure quantity is a valid number (whole & > 0) */
function validateQuantity() {
    var theForm = document.productform;
    var val = theForm.quantity.value;

    if(val==null || val == 0 || val.length == 0 || val == ''){
        alert("Please enter a quantity.");
        return false;
    }
    for (var i = 0; i < val.length; i++) {
        var ch = val.charAt(i);
        if (ch < "0" || ch > "9") {
            alert("Please enter a quantity.");
            return false;
        }
    }
    return true;
}

function openpopup(popurl){
    window.open(popurl,"","width=480,height=550,status=no,menubar=no,scrollbars=no");
    return false;
}
function openpopuplarge(popurl) {
    window.open(popurl,"","width=800,height=600,status=yes,menubar=yes,scrollbars=yes");
    return false;
}
