//TODO: once civicrm 2.0 updated for PP, use civicrm 2.0 validation instead of below validation
$(document).ready(function() {
  //only allow numeric for budget
  if ($.browser.msie){
    //use attachEvent for IE since setAttribute doesnot work for IE
    document.getElementById('custom_12').attachEvent('onkeypress', numericonly);
  }else{
    document.getElementById('custom_12').setAttribute('onkeypress', "return numericonly(event)");
  }
});

// Show org types based on country selected
$(function(){
  $("select#edit-org-country").change(function(){
      var country_id = $("select#edit-org-country").val();
      if (country_id > 0) {
        var j = org_types[country_id];
        var options = '';
        for (i in j) {
          options += '<option value="' + i + '">' + j[i] + '</option>';
        }
        $("select#edit-org-type").html(options);
      }
      $("select#country-3").removeAttr("selected");
      $("select#country-3").val(country_id);
  })
})

//cross browser numeric only checking
function numericonly(evt) {
    evt = (evt) ? evt : window.event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :  ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
    }
    return true;
}

function initialize_org_types(org_types_param) {
	org_types = org_types_param;
}
