
function saveTask(){

	var Task=document.getElementById('Task').value;
	var Details=document.getElementById('Details').value;

	if(Task!=""){
    if (window.localStorage){
	localStorage.setItem(Task,Details);
	alert("Task Sucessfully Saved!");
	window.location.reload();
    }
  }
  else{
      
      alert('Please Enter A Name For Task.');
  }
}

function viewTask(){
	
	if(localStorage.length==0){
		document.getElementById('Tasks').innerHTML=("No Tasks Assigned Yet..");
		
	}
	else{
      
      var Clear=document.getElementById('btn-clear');
      $(Clear).append("<button onclick='Clear()' class='btn btn-clear pull-right'>Clear All Tasks</button>");

      for(i=0;i<=localStorage.length-1;i++){
			var Task=localStorage.key(i);
			var Detail=localStorage.getItem(Task);

			var count=i;

			var h4TaskTitle=$("<h4 id='h4'/>").text(Task);
			$("#Num");
			var pTaskDetails=$("<p/>").text(Detail).append("<a onclick='askRemove("+count+")'><span class='glyphicon glyphicon-trash pull-right'></span><a><br><hr class='no-margin'>");
            $("#Tasks").append(h4TaskTitle);
            $("#Tasks").append(pTaskDetails);
            


			
		}
		
	}
}
    function askRemove(value){

    var response=confirm("This Task is About to be Deleted...");
    if (response==true) {
        var Val=value;
        var Key=localStorage.key(Val);
        localStorage.removeItem(Key);
        window.location.reload();
	    alert("Task Has Been Deleted.");
	   
	    
}

}
function Clear(){

	var response=confirm("You are About To Delete All Your Assigned Tasks...")

	if(response==true){
		localStorage.clear();
		window.location.reload();
		alert("All Tasks Have Been Deleted");
	}
}

function Search(){

	var content=document.getElementById("Search").value;
	if(content!=""){

		for(i=0;i<=localStorage.length-1;i++){

			var Task=localStorage.key(i);
			var task=Task;
			var Detail=localStorage.getItem(Task);
			var detail=Detail;

			var count=i;
            
			if(content.match(task)){
			document.getElementById('Tasks').innerHTML=('');
            var h4TaskTitle=$("<h4 id='h4'/>").text(task);
            var pTaskDetails=$("<p/>").text(detail).append("<a onclick='askRemove("+count+")'><span class='glyphicon glyphicon-trash pull-right'></span><a><br><hr class='no-margin'>");
            $("#Tasks").append(h4TaskTitle);
            $("#Tasks").append(pTaskDetails);


            }
           
        
    }

}

}

