
//add new hostel site
function add_site()
{
  var title = $("#title").val();
  var description = $("#description").val();
  var date = $("#date").val();
  var by_name = $("#by_name").val();
  var user_status = $("#user_status").val();
  var status = $("#status").val();
	if(title=='')
	{
		$('#title').focus();
	}else if(description==''){
		$('#description').focus();
	}else if(date==''){
		$('#date').focus();
	}else if(by_name==''){
		$('#by_name').focus();
	}
	else
	{

		$.post("php/add_site.php",{title:title,description:description,date:date,by_name:by_name,user_status:user_status,status:status},
		function(response,status)
		{
			//alert(response);
			$('#q').html(response);

		});
	}


}

//add hostel room
function add_room(){
	var campus =$("#campus").val();
	//var category =$("#category").val();
  var category = document.getElementById("category");
  var selectedValue = category.options[category.selectedIndex].value;
	var title = $("#title").val();
	var description = $("#description").val();
	var reserved = $("#reserved").val();
	var date_added = $("#date_added").val();
	var added_by = $("#added_by").val();
	var bedspace = $("#bedspace").val();
	var user_status = $("#user_status").val();
	var status = $("#status").val();
	if(title==''){
			$('#title').focus();
		}else if(description==''){
			$('#description').focus();
		}else if(reserved==''){
			$("#reserved").focus();
		}else if(date_added==''){
			$('#date_added').focus();
		}else if(added_by==''){
			$('#added_by').focus();
		}else if(bedspace==''){
			$("#bedspace").focus();
		}else	if(campus=='')
  		{
  			$('#campus').focus();
  		}else if(selectedValue==''){
  			$('#category').focus();
  		}
    else{
			$.post("php/add_room.php",{campus:campus,selectedValue:selectedValue,title:title,description:description,reserved:reserved,date_added:date_added,added_by:added_by,bedspace:bedspace,user_status:user_status,status:status},
			function(response,status)
			{
				alert(response);
				$('#q').html(response);
        location.reload();

			});
		}
}

//add new category
function add_category(){
	var campus =$("#campus").val();
	var title = $("#title").val();
	var description = $("#description").val();
	var reserved = $("#reserved").val();
	var date_added = $("#date_added").val();
	var added_by = $("#added_by").val();
	var gender = $("#gender").val();
	var bedspace = $("#bedspace").val();
	var amount = $("#amount").val();
	var user_status = $("#user_status").val();
	var status = $("#status").val();

	if(campus=='')
	{
		$('#campus').focus();
	}else if(title==''){
		$('#title').focus();
	}else if(description==''){
		$('#description').focus();
	}else if(date_added==''){
		$('#date_added').focus();
	}else if(added_by==''){
		$('#added_by').focus();
	}else if(bedspace==''){
		$("#bedspace").focus();
	}else if(amount==''){
		$("#amount").focus();
	}else{
		$.post("php/add_category.php",{campus:campus,amount:amount,title:title,description:description,reserved:reserved,date_added:date_added,added_by:added_by,bedspace:bedspace,user_status:user_status,status:status,gender:gender},
		function(response,status)
		{
			//alert(response);
			$('#q').html(response);

		});
	}
}

//edit hostel site
function edit_site(){
      var title =$("#title").val();
      var site_id =$("#site_id").val();
    	var description = $("#description").val();
    	var date_modified = $("#date_modified").val();
    	var modified_by = $("#modified_by").val();
    	var status = $("#status").val();
        if(title==''){
          $("#title").focus();
        }else if(description==''){
          $("#description").focus();
        }else if(date_modified==''){
          $("#date_modified").focus();
        }else if(modified_by==''){
          $("#modified_by").focus();
        }else{
          $.post("php/edit_site.php",{site_id:site_id,title:title,description:description,date_modified:date_modified,modified_by:modified_by,status:status},
          function(response,status)
          {
            //alert(response);
            $('#t').html(response);
            window.location.href="gateway.php?act=view_hostel_sites";

          });
        }

}


//edit hostel room
function edit_room(){
    	var campus =$("#campus").val();
      var room_id =$("#room_id").val();
    	var category =$("#category").val();
    	var title = $("#title").val();
    	var description = $("#description").val();
    	var reserved = $("#reserved").val();
    	var date_modified = $("#date_modified").val();
    	var modified_by = $("#modified_by").val();
    	var bedspace = $("#bedspace").val();
    	var status = $("#status").val();
      		if(campus=='')
      		{
      			$('#campus').focus();
      		}else if(category==''){
      			$('#category').focus();
      		}else if(title==''){
      			$('#title').focus();
      		}else if(description==''){
      			$('#description').focus();
      		}else if(date_modified==''){
      			$("#date_modified").focus();
      		}else if(modified_by==''){
      			$('#modified_by').focus();
      		}else if(reserved==''){
      			$('#reserved').focus();
      		}else if(bedspace==''){
      			$("#bedspace").focus();
      		}else{
            $.post("php/edit_room.php",{room_id:room_id,campus:campus,category:category,title:title,description:description,reserved:reserved,date_modified:date_modified,modified_by:modified_by,bedspace:bedspace,status:status},
            function(response,status)
            {
              alert(response);
              $('#q').html(response);
              window.location.href="gateway.php?act=view_hostel_rooms";
            });
		}
}


//edit hostel category
function edit_category(){
	var campus =$("#campus").val();
	var title = $("#title").val();
	var description = $("#description").val();
	var reserved = $("#reserved").val();
	var date_modified = $("#date_modified").val();
	var modified_by = $("#modified_by").val();
	var gender = $("#gender").val();
	var bedspace = $("#bedspace").val();
	var amount = $("#amount").val();
	var cat_id = $("#cat_id").val();


	if(campus=='')
	{
		$('#campus').focus();
	}else if(title==''){
		$('#title').focus();
	}else if(description==''){
		$('#description').focus();
	}else if(date_modified==''){
		$('#date_modified').focus();
	}else if(modified_by==''){
		$('#modified_by').focus();
	}else if(bedspace==''){
		$("#bedspace").focus();
	}else if(amount==''){
		$("#amount").focus();
	}else{
		$.post("php/edit_category.php",{cat_id:cat_id,campus:campus,amount:amount,title:title,description:description,reserved:reserved,date_modified:date_modified,modified_by:modified_by,bedspace:bedspace,gender:gender},
		function(response,status)
		{
		//	alert(response);
			$('#tt').html(response);
      window.location.href="gateway.php?act=view_hostel_categories";
		});
	}
}

//select campus to allocate
function category_select(){
  var site =  $("#site").val();
  var gender =  $("#gender").val();
  var student_id =  $("#student_id").val();
    if(site==''){
      $('#site').focus();
    }else {
      $.post("php/category_selection.php",{site:site,gender:gender,student_id:student_id},
  		function(response,status)
  		{
  			//alert(response);

  			$('#q').html(response);
        //window.location.href="gateway.php?act=view_hostel_categories";
  		});
    }
}


//select block to allocate
function room_select(){
  var site =  $("#site").val();
  var block =  $("#block").val();
  var student_id =  $("#student_id").val();
    if(block==''){
      $('#block').focus();
    }else {
      $.post("php/room_selection.php",{site:site,block:block,student_id:student_id},
  		function(response,status)
  		{
  			//alert(response);
  			$('#qq').html(response);
      //  window.location.href="gateway.php?act=view_hostel_categories";
  		});
    }
}


//allocate room to Students

function allocate()
{
    var site =  $("#site").val();
    var block =  $("#block").val();
    var room =  $("#room").val();
    var student_id =  $("#student_id").val();
    if(room=='')
    {
      $("#room").focus();
    }else {
      $.post("php/allocate.php",{site:site,block:block,room:room,student_id:student_id},
      function(response,status)
      {
        //alert(response);
        $('#qqq').html(response);
      //  window.location.href="gateway.php?act=view_hostel_categories";
      });
    }

}

//select campus
      function changeFunc() {
        var gender =  $("#gender").val();
          var student_id =  $("#student_id").val();
       var selectBox = document.getElementById("selectBox");
       var selectedValue = selectBox.options[selectBox.selectedIndex].value;
       if(selectedValue=='')
       {
         $("#selectBox").focus();
       }else {
         $.post("php/cat_select.php",{selectedValue:selectedValue,gender:gender,student_id:student_id},
         function(response,status)
         {
           //alert(response);
           $('#cat').html(response);
         //  window.location.href="gateway.php?act=view_hostel_categories";
         });
       }
      }


      //select Category
            function changeCat() {
              var site_id =  $("#site_id").val();
                var student_id =  $("#student_id").val();
             var selectCategory = document.getElementById("selectCategory");
             var selectedValue = selectCategory.options[selectCategory.selectedIndex].value;
             if(selectedValue=='')
             {
               $("#selectCategory").focus();
             }else {
               $.post("php/rm_select.php",{site_id:site_id,student_id:student_id,selectedValue:selectedValue},
               function(response,status)
               {
                 //alert(response);
                 $('#room').html(response);
               //  window.location.href="gateway.php?act=view_hostel_categories";
               });
             }
            }


            //select Category
                  function changeRoom() {
                    var site_id =  $("#site_id").val();
                    var student_id =  $("#student_id").val();
                    var cat_id =  $("#cat_id").val();
                   var room_id = document.getElementById("room_id");
                   var selectedValue = room_id.options[room_id.selectedIndex].value;
                   if(selectedValue=='')
                   {
                     $("#room_id").focus();
                   }else {
                     $.post("php/editAllocation.php",{site_id:site_id,student_id:student_id,selectedValue:selectedValue,cat_id:cat_id},
                     function(response,status)
                     {
                       //alert(response);
                       $('#action').html(response);
                     //  window.location.href="gateway.php?act=view_hostel_categories";
                     });
                   }
                  }


                  function editAllocation()
                  {
                    var site_id =  $("#site_id").val();
                    var student_id =  $("#student_id").val();
                    var cat_id =  $("#cat_id").val();
                    var room_id =  $("#room_id").val();
                    if (room_id=='') {
                      $("#room_id").focus();
                    }else {
                      $.post("php/editingAllocation.php",{site_id:site_id, student_id:student_id, cat_id:cat_id, room_id:room_id},
                      function(response,status)
                      {
                        //alert(response);
                        $('#msg').html(response);
                      //  window.location.href="gateway.php?act=view_hostel_categories";
                      });
                    }

                  }

                  function ggg() {
                   var gender =  $("#gender").val();
                   var campus = document.getElementById("campus");
                   var selectedValue = campus.options[campus.selectedIndex].value;
                   if(selectedValue=='')
                   {
                     $("#campus").focus();
                   }else {
                     $.post("php/selection.php",{selectedValue:selectedValue, gender:gender},
                     function(response,status)
                     {
                       //alert(response);
                       $('#q').html(response);

                     });

                   }

                  }
