/*if($) {
  alert("PoPo");
} else {
  alert("Sorry");
}*/

function checkbox_disabled(tocheck, todisable1, todisable2, todisable3) {
  var x = document.getElementById(tocheck);
  if(x.checked) {
    document.getElementById(todisable1).disabled=false;
    document.getElementById(todisable2).disabled=false;
    document.getElementById(todisable3).disabled=false;
  } else {
    document.getElementById(todisable1).disabled=true;
    document.getElementById(todisable2).disabled=true;
    document.getElementById(todisable3).disabled=true;
  }
}

function checkbox_disabled1(tocheck, todisable, to) {
  var x = document.getElementById(tocheck);
  if(x.checked) {
    document.getElementById(todisable).disabled=false;
  } else {
    document.getElementById(todisable).value = 0;
    document.getElementById(todisable).disabled=true;
    document.getElementById('Community_Id').value = 0;
    document.getElementById('Event_Location').value = '';
    document.getElementById('Event_Address').value = '';
    document.getElementById('Event_Phone').value = '';
    document.getElementById('Event_Latitude').value = '';
    document.getElementById('Event_Longitude').value = '';
    document.getElementById('Event_URL').value = '';
    document.getElementById('Event_Details').value = '';
  }
}

function restaurant_info(rid) {
  //alert('?cmd=restaurant_info_ajax&id='+rid);
  $.getJSON('?cmd=restaurant_info_ajax&id='+rid, function(d) {
    //alert(html_entity_decode(d.Restaurant_Name));
    $("#Community_Id").val(d.Community_Id);
    $("input#Event_Location").val(d.Restaurant_Name);
    $("input#Event_Address").val(d.Restaurant_Address);
    $("input#Event_Latitude").val(d.Restaurant_Latitude);
    $("input#Event_Longitude").val(d.Restaurant_Longitude);
    $("input#Event_Phone").val(d.Restaurant_Phone);
    if(d.Restaurant_URL == '')
      $("input#Event_URL").val("http://");
    else
      $("input#Event_URL").val(d.Restaurant_URL);
    $("#Event_Details").val(d.Restaurant_Description);
  });
}

function community_info(cid) {
  //alert('?cmd=community_info_ajax&id='+cid);
  $.getJSON('?cmd=community_info_ajax&id='+cid, function(d) {
    //alert(d.Community_Latitude);
    $("input#Event_Latitude").val(d.Community_Latitude);
    $("input#Event_Longitude").val(d.Community_Longitude);
    $("input#Event_Phone").val(d.Community_Phone);
    if(d.Community_URL == '')
      $("input#Event_URL").val("http://");
    else
      $("input#Event_URL").val(d.Community_URL);
  });
}

function openGoogleMap() {
  var lat = document.getElementById('Event_Latitude').value;
  var lng = document.getElementById('Event_Longitude').value;
  var url = "common/GoogleMap.php";

  if ((lat=="") && (lng =="")) {
    url += "?lat=30.283529&long=-86.030502";
  } else {
    url += "?lat=" + lat + "&long=" + lng;
  }
  window.open(url,"googleMap","status=0,toolbar=0,location=0,menubar=0,resizable=0,height=460,width=320,scrollbars=0");
}

$(document).ready(function() {

  $("#No_Repeat").click(function() {
    $(".norepeat_clear").val("");
    $(".norepeat_uncheck").attr("checked", false);
    $("#Repeat_details").hide();
    $("#Repeat_details").parent().hide();
    $("#Darren_bReoccur").removeAttr("checked");
  });
  $("#Daily").click(function() {
    $("#Repeat_details").show();
    $("#Repeat_details").parent().show();
    $(".daily_clear").val("");
    $(".daily_uncheck").attr("checked", false);
    $(".for_weekly").hide();
    $(".for_monthly").hide();
    $("#interval_type").html("days");
    $("#Darren_bReoccur").attr("checked", true);
  });
  $("#Weekly").click(function() {
    $("#Repeat_details").show();
    $("#Repeat_details").parent().show();
    $(".weekly_clear").val("");
    $(".weekly_uncheck").attr("checked", false);
    $(".for_monthly").hide();
    $(".for_weekly").show();
    $("#interval_type").html("weeks");
    $("#Darren_bReoccur").attr("checked", true);
  });
  $("#Monthly").click(function() {
    $("#Repeat_details").show();
    $("#Repeat_details").parent().show();
    $(".monthly_clear").val("");
    $(".monthly_uncheck").attr("checked", false);
    $(".for_yearly").hide();
    $(".for_monthly").show();
    $("#interval_type").html("months");
    $("#Darren_bReoccur").attr("checked", true);
  });
  $("#Yearly").click(function() {
    $("#Repeat_details").show();
    $("#Repeat_details").parent().show();
    $("#interval_type").html("years");
    $("#Darren_bReoccur").attr("checked", true);
  });

  $("#Repeat_Count").click(function() {
    $("input[name='Repeat_Count']").attr("disabled", false);
    $("input[name='Repeat_Until']").val("");
    $("input[name='Repeat_Until']").attr("disabled", true);
  });
  $("#Repeat_Until").click(function() {
    $("input[name='Repeat_Until']").attr("disabled", false);
    $("input[name='Repeat_Count']").val("");
    $("input[name='Repeat_Count']").attr("disabled", true);
  });
  $("#Darren_bReoccur").click(function() {
    if($(this).attr("checked")) {
      $("#Daily").click();
      $("#No_Repeat").parent().parent().parent().show();
    } else {
      $("#No_Repeat").click();
      $("#No_Repeat").parent().parent().parent().hide();
    }
  });

  $("#_ByDay input").click(function() {
    $("#Repeat_ByMonthDay").val("");
  });
  $("#_ByMonthDay input").click(function() {
    $(".to_clean_when__ByMonthDay label input").removeAttr("checked");
  });

	$("#all_day_event").click(function() {
    if($(this).attr("checked")) {
			$("#StartTimeHrs").attr("disabled", true);
			$("#StartTimeMins").attr("disabled", true);
			$("#StartTimeAMPM").attr("disabled", true);
			$("#EndTimePresent").attr("checked", false);
			$("#EndTimePresent").attr("disabled", true);
			$("#EndTimeHrs").attr("disabled", true);
			$("#EndTimeMins").attr("disabled", true);
			$("#EndTimeAMPM").attr("disabled", true);
    } else {
			$("#StartTimeHrs").attr("disabled", false);
			$("#StartTimeMins").attr("disabled", false);
			$("#StartTimeAMPM").attr("disabled", false);
			$("#EndTimePresent").attr("disabled", false);
    }
	});
	$("#start_date").change(function(){
		alert($(this).val());
	});

});
