/*******************************************************************************
 * Copyright (c) 2014 Eclipse Foundation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://eclipse.org/legal/epl-v10.html
 *
 * Edouard Poitras (Eclipse Foundation) - Some modifications
 *******************************************************************************/
var ajaxObject = AjaxObject();

function AjaxObject () {
	if (window.XMLHttpRequest)
		return new XMLHttpRequest();
	else if (window.ActiveXObject)
		return new ActiveXObject('Microsoft.XMLHTTP');
	else
		alert ("Error Creating AjaxObject");
		return false;
}

function whatsThisToggle(i) {
	var e = document.getElementById(i);
	var t = e.className;
	if (t.match('invisible')) { t = t.replace(/invisible/gi, 'visible'); }
	else { t = t.replace(/visible/gi, 'invisible'); }
	e.className = t;
}

function amountCheck() {
	var a = document.getElementById("amount");
	var b = document.getElementById("bugzilla");
	if (a.value >= 35) {
		b.disabled=false;
		b.className = "enabled";
	} else {
		b.disabled=true;
		b.className = "disabled";
	}
}
function validateForm() {
	var retVal = true;
	var fn = document.getElementById("first_name");
	var ln = document.getElementById("last_name");
	var a = document.getElementById("amount");
	var b = document.getElementById("bugzilla");
	var v = document.getElementById("verify");
	var anon = document.getElementById("os1private");

	if (parseInt(a.value) >= 35) {
			if (b.value.length != 0)	{
				if (v.innerHTML.length == 0) {
					alert("Please verify your Eclipse.org login to continue");
					return false;
				}
				if (v.innerHTML != "Verified!") {
					alert ("Your Eclipse.org ID could not be verified. If you have recently created an account, please ensure you have verified your email address." + '\n' + "For donations of $35 dollars or more we require you to provide a valid ID.  If you do not wish to provide your Eclipse.org ID please list your name Anonymously.");
					return false;
				}
			}
	}
	return retVal;
}


function isNumeric(input) {
	var numbers = "01234567890.-";
	var singleChar;
	var retVal = true;
	if (input.length > 0) {
		for (i = 0; i < input.length && retVal == true; i++) {
			singleChar = input.charAt(i);
			if (numbers.indexOf(singleChar) == -1) {
				retVal = false;
			}
		}
	}
	return retVal;
}

function verifyBugzillaLogin() {
	var v = document.getElementById('verify');
	var a = document.getElementById('amount');
	var bugzillaLogin = document.getElementById('bugzilla');
	if (bugzillaLogin.value.length == 0 || parseInt(a.value) < 35) {
		v.innerHTML = "";
		v.removeAttribute("class");
		bugzillaLogin.value = "";
		bugzillaLogin.removeAttribute("style");
	}

	var url = "ajaxBugzilla.php?bugzillaLogin=" + bugzillaLogin.value.replace('+', '%2B');
	ajaxObject.open("GET", url, true);
	ajaxObject.onreadystatechange = updatePage;
	ajaxObject.send(null);

}

function updatePage() {
	var v = document.getElementById('verify');
	var b = document.getElementById('bugzilla');
	var anon = document.getElementById('os1private');
    if (ajaxObject.readyState == 4){
    	response = ajaxObject.responseText;
    	if (response.indexOf("Verified!") > -1 || b.value.length == 0 || anon.checked) {
    		if (response.indexOf("Verified!") > -1) {
				v.innerHTML = "Verified!";
				v.setAttribute("class", "green");
				b.setAttribute("style","border:2px solid green;");
            }
    		if (validateForm()) {
    			document.donateForm.submit();
            } else {
                return false;
            }
	    }
    	else { // Anonymous
            v.innerHTML = "Invalid Login";
    		v.setAttribute("class", "red");
    		b.setAttribute("style","border:2px solid #FF0000;");
    		validateForm();
    	}
    }
}
