function deleteSelected(){ var deleteList = document.getElementsByClassName("deleteBox"); var resource = "/api/delete?" var counter = 0; for(var i =0; i < deleteList.length; ++i){ var checkbox = deleteList[i]; if(checkbox.checked != false){ if(counter > 0) resource+="&"; resource +=('id='+checkbox.id); counter++; } } if(counter >0 ){ var xhttp = new XMLHttpRequest(); xhttp.open('DELETE', resource,true); xhttp.send(); xhttp.onreadystatechange = function() { if(this.readyState == 4){ list(); } }; } } function addMonitor(){ var new_name = document.getElementById("new_name"); var new_url = document.getElementById("new_url"); if(!validURL(new_url.value)) alert("invalid URL"); else{ var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if(this.readyState == 4){ if(200 <= this.status && this.status< 300){ list(); } else{ alert("Error, URL invalid. Status: "+this.status); } } }; xhttp.open("POST", "/api/newMonitor",true); xhttp.send(JSON.stringify({"name": new_name.value, "url": new_url.value})); } } function logout(){ document.cookie="ssid=0"; window.location.href = '/index.html'; } function login(){ var email = document.getElementById("email").value; var password = document.getElementById("password").value; var obj = {"command":"login","method":"POST","email":email,"password":password}; if(validEmail(email) && password !== ""){ var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4) { if(200 <= this.status && this.status < 300){ window.location.href = '/account.html' } else{ alert("Error. Status: "+this.status); } } }; xhttp.open(obj.method, "/api/"+obj.command, true); //xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhttp.send(JSON.stringify(obj)); } else{ alert("Invalid username or password"); } } function register(){ var email = document.getElementById("email").value; var password = document.getElementById("password").value; var password_confirm = document.getElementById("confirm_password").value; //Client side input checks if(password != password_confirm){ alert("passwords do not match"); } else if(!validEmail(email)){ alert("Invalid email address"); } else if(!validPassword(password)){ alert("Invalid password: Must be 8 characters"); } else{ var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 ) { if(200 <= this.status && this.status < 300){ alert("Success"); window.location.href = '/index.html'; } else{ alert("Error. Status: "+this.status); } } } xhttp.open("POST", "/api/register", true); xhttp.send(JSON.stringify({"email":email,"password":password})); } } function list(){ var table = document.getElementById("table_list_body"); //table.innerHTML="