﻿    var field_length = 0;
    var txtGr_Fy = null;
    var txtGr_ProgCat = null;
    var txtGr_Seq_No = null;


    function TabNext(obj, event, len, next_field) {
        if (event == "down") {
	        field_length = obj.value.length;
        }
        else if (event == "up") {
	        if (obj.value.length != field_length) {
		        field_length = obj.value.length;
		        if (field_length == len) {
			        next_field.focus();
		        }
	        }
        }
    }

    function disableEnterKey() {
	    if (window.event.keyCode == 13)
		    window.event.keyCode = 0;
    }

    function clickFindGrantButton() {
	    if (window.event.keyCode == 13) {
		    window.event.keyCode = 0;
	        document.getElementById('ctl00$GEOForm$btnFindGrant').click();
        }
       }

       function selectCheckBox(field) {
       	var KeyCode = (window.event) ? event.keyCode : e.which;
       	var KeyChar = (window.event) ? String.fromCharCode(event.keyCode) : String.fromCharCode(e.which);

       	if (KeyCode == 13) {
       		var btnSubmit = FindControl(ButtonName, "input");

       		if (btnSubmit != null) {
       			alert("whoopie");
       			btnSubmit.click();
       		}

       		if (window.event) {
       			window.event.returnValue = false;
       		}
       		else {
       			e.preventDefault();
       		}
       	}
       }

    function clickAllCheckboxes(sender, field) {
    	//alert(sender.checked);
    	if (sender.checked)
    		checkAll(field);
    	else
    		uncheckAll(field);
    }

   function checkAll(field) {
   	    if (document.forms[0].elements[n].type=="checkbox")
            document.forms[0].elements[n].checked=Select; return false; 
   	    //for (i = 0; i < field.length; i++)
   		//    field[i].checked = true;
   }

   function uncheckAll(field) {
   	    for (i = 0; i < field.length; i++)
   		    field[i].checked = false;
   		  }

    function SelectAll(CheckBoxControl) {
  	    if (CheckBoxControl.checked == true) {
  		    var i;
  		    for (i = 0; i < document.forms[0].elements.length; i++) {
  		    	if ((document.forms[0].elements[i].type == 'checkbox') && (document.forms[0].elements[i].name.indexOf('cbDeleteActivity') > -1)) {
  				    document.forms[0].elements[i].checked = true;
  			    }
  		    }
  	    }
  	    else {
  		    var i;
  		    for (i = 0; i < document.forms[0].elements.length; i++) {
  		    	if ((document.forms[0].elements[i].type == 'checkbox') && (document.forms[0].elements[i].name.indexOf('cbDeleteActivity') > -1)) {
  				    document.forms[0].elements[i].checked = false;
  			    }
  		    }
  	   }
  	  }

  	  function PopulateReviewFields() {
  	  	var objActivityType = document.getElementById('ctl00_GEOForm_ddlActivityType');
  	  	var objState = document.getElementById('ctl00_GEOForm_ddlState');

  	  	document.getElementById('ctl00_GEOForm_lblActivityTitleReview').innerHTML = document.getElementById('ctl00_GEOForm_txtActivityTitle').value;
  	  	document.getElementById('ctl00_GEOForm_lblActivityTypeReview').innerHTML = objActivityType.options[objActivityType.selectedIndex].innerHTML;
  	  	document.getElementById('ctl00_GEOForm_lblActivityDatesReview').innerHTML = document.getElementById('ctl00_GEOForm_txtDateOfActivity').value;
  	  	document.getElementById('ctl00_GEOForm_lblActivityVenueReview').innerHTML = document.getElementById('ctl00_GEOForm_txtVenue').value;
  	  	document.getElementById('ctl00_GEOForm_lblActivityAddress1Review').innerHTML = document.getElementById('ctl00_GEOForm_txtAddress1').value;
  	  	document.getElementById('ctl00_GEOForm_lblActivityAddress2Review').innerHTML = document.getElementById('ctl00_GEOForm_txtAddress2').value;
  	  	document.getElementById('ctl00_GEOForm_lblActivityCityReview').innerHTML = document.getElementById('ctl00_GEOForm_txtCity').value;
  	  	document.getElementById('ctl00_GEOForm_lblActivityStateReview').innerHTML = objState.options[objState.selectedIndex].innerHTML;

  	  	var strZip = document.getElementById('ctl00_GEOForm_txtZipCode').value;
  	  	if (strZip.length == 9) {
  	  		document.getElementById('ctl00_GEOForm_lblActivityZipCodeReview').innerHTML = strZip.substring(0, 5) + "-" + strZip.substring(5)
  	  	}
  	  	else {
  	  		document.getElementById('ctl00_GEOForm_lblActivityZipCodeReview').innerHTML = document.getElementById('ctl00_GEOForm_txtZipCode').value;
  	  	}
  
  	  	
  	  	//document.getElementById('ctl00_GEOForm_lblActivityZipCodeReview').innerHTML = document.getElementById('ctl00_GEOForm_txtZipCode').value;
  	  	//document.getElementById('ctl00_GEOForm_lblActivityZipCodePlus4Review').innerHTML = document.getElementById('ctl00$GEOForm$txtZipPlus4').value;
  	  	//document.getElementById('ctl00_GEOForm_lblActivityDistrictReview').innerHTML = document.getElementById('ctl00_GEOForm_txtDistrict').value;
  	  }

  	  function SetEscapeCharacters(strVal) {
        var sTemp;

        sTemp = escape(strVal);
        sTemp = sTemp.replace("+", "%2B");
        sTemp = sTemp.replace("/", "%2F");
        
        return sTemp;
       }
       
       function ZIPLookupURI() {
           var strValue = "http://zip4.usps.com/zip4/zcl_0_results.jsp?";
           
           strAddress1 = document.getElementById('ctl00$GEOForm$txtAddress1').value;
           strAddress2 = document.getElementById('ctl00$GEOForm$txtAddress2').value;
           strCity = document.getElementById('ctl00$GEOForm$txtCity').value;
           strState = document.getElementById('ctl00$GEOForm$ddlState').value;

           strValue += "visited=1&pagenumber=0&firmname=";
           strValue += "&address2=" + SetEscapeCharacters(strAddress1).toUpperCase();
           strValue += "&address1=" + SetEscapeCharacters(strAddress2).toUpperCase();
           strValue += "&city=" + SetEscapeCharacters(strCity).toUpperCase();
           strValue += "&state=" + SetEscapeCharacters(strState).toUpperCase();
           strValue += "&urbanization=&zip5=";

           return strValue;
          }

          function ZipCodeLookup() {
          	var strURL = ZIPLookupURI();

          	window.open('' + strURL, 'zipwin','left=100,top=100,width=700,height=600,toolbar=0,resizable=1');

          }

          function ValidateActivityEntry() {
          	var bolValid = true;
          	var bolZipValid = true;
          	var strErrMsg = "";
          	var strZipErrorMsg = "<img src=\"Images/alert.gif\">  The Zip Code entered is invalid.  The Zip Code can only consist of numberic values and one dash (i.e. 55555-5555).";
          	var strRequiredFieldErrorMsg = "<img src=\"Images/alert.gif\">  The fields marked with an exclamation point are required.";
          	var strAreValuesCorrectMsg = "Is the activity information correct?";
          	var strClickCancelButtonMsg = "<br><br>Please click the \"Cancel\" button and fix the errors specified.";
          	
          	var strActivityTitle = document.getElementById('ctl00_GEOForm_lblActivityTitleReview').innerHTML;
          	var strActivityType = document.getElementById('ctl00_GEOForm_lblActivityTypeReview').innerHTML;
          	var strVenue = document.getElementById('ctl00_GEOForm_lblActivityVenueReview').innerHTML;
          	var strAddressLine1 = document.getElementById('ctl00_GEOForm_lblActivityAddress1Review').innerHTML;
          	var strCity = document.getElementById('ctl00_GEOForm_lblActivityCityReview').innerHTML;
          	var strState = document.getElementById('ctl00_GEOForm_lblActivityStateReview').innerHTML;
          	var strZipCode = document.getElementById('ctl00_GEOForm_lblActivityZipCodeReview').innerHTML;

          	if (strActivityTitle != null && strActivityTitle != "") {
          		document.getElementById('ctl00_GEOForm_imgActivityTitleAlert').style.visibility = "hidden";
          	}
          	else {
          		document.getElementById('ctl00_GEOForm_imgActivityTitleAlert').style.visibility = "visible";
          		bolValid = false;
          	}

          	if (strActivityType != null && strActivityType != "") {
          		document.getElementById('ctl00_GEOForm_imgActivityTypeAlert').style.visibility = "hidden";
          	}
          	else {
          		document.getElementById('ctl00_GEOForm_imgActivityTypeAlert').style.visibility = "visible";
          		bolValid = false;
          	}

          	if (strVenue != null && strVenue != "") {
          		document.getElementById('ctl00_GEOForm_imgVenueAlert').style.visibility = "hidden";
          	}
          	else {
          		document.getElementById('ctl00_GEOForm_imgVenueAlert').style.visibility = "visible";
          		bolValid = false;
          	}

          	if (strAddressLine1 != null && strAddressLine1 != "") {
          		document.getElementById('ctl00_GEOForm_imgAddress1Alert').style.visibility = "hidden";
          	}
          	else {
          		document.getElementById('ctl00_GEOForm_imgAddress1Alert').style.visibility = "visible";
          		bolValid = false;
          	}

          	if (strCity != null && strCity != "") {
          		document.getElementById('ctl00_GEOForm_imgCityAlert').style.visibility = "hidden";
          	}
          	else {
          		document.getElementById('ctl00_GEOForm_imgCityAlert').style.visibility = "visible";
          		bolValid = false;
          	}

          	if (strState != null && strState != "") {
          		document.getElementById('ctl00_GEOForm_imgStateAlert').style.visibility = "hidden";
          	}
          	else {
          		document.getElementById('ctl00_GEOForm_imgStateAlert').style.visibility = "visible";
          		bolValid = false;
          	}

          	if (strZipCode != null && strZipCode != "") {
          		//document.getElementById('ctl00_GEOForm_imgZipAlert').style.visibility = "hidden";
          		if (isValidZipCode(strZipCode)) {
          			document.getElementById('ctl00_GEOForm_imgZipAlert').style.visibility = "hidden";
          			document.getElementById('ctl00_GEOForm_btnCommit').style.visibility = "visible";
          		}
          		else {
          			document.getElementById('ctl00_GEOForm_imgZipAlert').style.visibility = "visible";
          			//document.getElementById('ctl00_GEOForm_lblPopUpTitle').innerHTML = strZipErrorMsg;
          			strErrMsg = strZipErrorMsg;
          			bolZipValid = false;
          			document.getElementById('ctl00_GEOForm_btnCommit').style.visibility = "hidden";
          		}
          	}
          	else {
          		document.getElementById('ctl00_GEOForm_imgZipAlert').style.visibility = "visible";
          		bolValid = false;
          	}

          	//if (bolZipValid == true) {
          		if (bolValid == false) {
          			if (strErrMsg != "") {
          				strErrMsg += "<br><br>";
          			}
          			strErrMsg += strRequiredFieldErrorMsg;
          			//document.getElementById('ctl00_GEOForm_lblPopUpTitle').innerHTML = "The fields marked with an exclamation point <img src=\"Images/alert.gif\"> are required.";
          			document.getElementById('ctl00_GEOForm_btnCommit').style.visibility = "hidden";
          			//document.getElementById('ctl00_GEOForm_btnCommit').disabled = true;
          		}
          		else {
          			document.getElementById('ctl00_GEOForm_lblPopUpTitle').innerHTML = strAreValuesCorrectMsg;
          			if (bolZipValid == true) {
          				document.getElementById('ctl00_GEOForm_btnCommit').style.visibility = "visible";
          			}
          			//document.getElementById('ctl00_GEOForm_btnCommit').disabled = false;
          		}

          		if (strErrMsg != "") {
          			strErrMsg += strClickCancelButtonMsg;
          			document.getElementById('ctl00_GEOForm_lblPopUpTitle').innerHTML = strErrMsg;
          			
          		}
          	//}

          }


          function isValidZipCode(strZip) {
          	var myRegxp = /^(\d{5}-\d{4}|\d{5}|\d{9})$/;
          	return myRegxp.test(strZip);
          }
       

