function toggleCheck(thisField) {
   checkSet = eval("document.forms[0]." + thisField)
   checkSet.checked = !(checkSet.checked)
}

function toggleRadio(thisField,thisValue) {
   radioSet = eval("document.forms[0]."+thisField)
   for (i=0;i < radioSet.length;i++) {
      if (radioSet[i].value == thisValue)
         radioSet[i].checked = true
   }
}

function highlight_errors(field){
	document.getElementById(field).style.backgroundColor = 'yellow';
	}

function highlight_listbox_errors(field){
	obj  = document.getElementById(field);
	obj.style.backgroundColor = 'yellow';
	}
	
function verify(){
		iGotPic = false;
  		if (document.forms[0].photo1.value != '') iGotPic=true;
  		if (document.forms[0].photo2.value != '') iGotPic=true;
  		if (document.forms[0].photo3.value != '') iGotPic=true;
  		if (document.forms[0].photo4.value != '') iGotPic=true;
  		if (document.forms[0].photo5.value != '') iGotPic=true;
  		if (document.forms[0].photo6.value != '') iGotPic=true;
				
		if (iGotPic==false){
			document.forms[0].flag_pics.value = '0';
			var answer = confirm ("Continue without submitting picture?");
			if (answer){
				return true;
			}else{
        		return false;
			}
		}
	}
	
/* AJAX functions */
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function sndReq() {
    lname = document.forms[0].lastname.value;
    fname = document.forms[0].firstname.value;
	http.open('get', 'check_name.php?lname='+lname+'&fname='+fname);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
		lname = document.forms[0].lastname.value;
		fname = document.forms[0].firstname.value;
        var response = http.responseText;
		var str = "We already have an application from "+fname.toUpperCase()+" "+lname.toUpperCase()+". You may have submitted your application already, or if you are a different person with the same name, please continue.";
		if (response > 0){alert (str);}
    }
}
