/*
 *	Project	:	Informatics Online Library
 *	File	:	scripts/core_process.php
 */

function checkAvailability(divId, url, email){

	xmlHttp = Ajax();

	xmlHttp.onreadystatechange = function(){

		if(xmlHttp.readyState == 3){

			document.getElementById(divId).innerHTML = 'loading..';

		}

		else if(xmlHttp.readyState == 4){

			document.getElementById(divId).innerHTML = xmlHttp.responseText;

		}

	}

	xmlHttp.open("GET", url + "?email=" + email, true);

	xmlHttp.send(null);

}

function searchResult(divId, url){

	xmlHttp = Ajax();

	xmlHttp.onreadystatechange = function(){

		if(xmlHttp.readyState == 3){

			document.getElementById(divId).innerHTML = 'loading..';

		}

		else if(xmlHttp.readyState == 4){

			document.getElementById(divId).innerHTML = xmlHttp.responseText;

		}

	}

	xmlHttp.open("GET", url + "/key/" + getElementById("key").value, true);

	xmlHttp.send(null);

	return false;

}

function ForgotPassword(url, username){

	xmlHttp = Ajax();

	xmlHttp.onreadystatechange = function(){

		if(xmlHttp.readyState == 3){

			document.getElementById("msg").innerHTML = 'loading..';

		}

		else if(xmlHttp.readyState == 4){

			document.getElementById("msg").innerHTML = xmlHttp.responseText;

		}

	}

	xmlHttp.open("GET", url + "/functions/forgot-password.php?email=" + username, true);

	xmlHttp.send(null);

}

function DeleteCartItem(url, id){

	confirm("Are you sure you want to delete the item from cart?");

	xmlHttp = Ajax();

	xmlHttp.onreadystatechange = function(){

		if(xmlHttp.readyState == 3){

			document.getElementById("refresh-cart-item").innerHTML = 'loading..';

		}

		else if(xmlHttp.readyState == 4){

			document.getElementById("refresh-cart-item").innerHTML = xmlHttp.responseText;

		}

	}

	xmlHttp.open("GET", url + "/delete-cart-item/" + id, true);

	xmlHttp.send(null);

}

function ToggleDisplay(id, status){

	xmlHttp = Ajax();

	xmlHttp.onreadystatechange = function(){

		if(xmlHttp.readyState == 3){

			document.getElementById("refresh-cart-item").innerHTML = 'loading..';

		}

		else if(xmlHttp.readyState == 4){

			document.getElementById("refresh-cart-item").innerHTML = xmlHttp.responseText;

		}

	}

	xmlHttp.open("GET", url + "/delete-cart-item/" + id, true);

	xmlHttp.send(null);

}

