/**
 * Check if a current school is the same as logged school
 *
 * Uses AJAX
 * @param integer current_school_id
 * @param string logged_out_mes Message to show during log out
 * @param string switch_mes Message to show during account switch
 */
function check_logged_school(current_school_id, logged_out_mes, switch_mes) {
    xhro = createXmlHttpRequestObject();
    if (xhro==null) return false;
    xhro.onreadystatechange=function () {
        if (xhro.readyState==4 || xhro.readyState=="complete") {
            //alert(xhro.responseText); //for testing purposes
            var resp = eval('(' + xhro.responseText + ')');
            if (resp.result.not_logged == 1) {
            	alert(logged_out_mes);
            	clearInterval(current_school_check_id);
            	window.location.reload(true);
            }
            else if (resp.result.other_school == '1') {
            	var confirm_mes = switch_mes.replace('{current_school_name}', resp.result.current_school);
            	confirm_mes = confirm_mes.replace('{school_name}', resp.result.school);
            	if (confirm(confirm_mes)) {
            	
            		window.location.href = '/schools/frontend/actions/s_account_switch.php?uncache=' + (new Date()).getTime() + '&id=' + current_school_id;
            	}
            	else {
            		window.location.href = '/';
            	}
            	clearInterval(current_school_check_id);
            }
        }
    };
    data = "current_school_id=" + current_school_id;
    xhro.open("post","/schools/frontend/actions/s_current_school_check.php",true); //true - asynchronous flag
    xhro.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhro.setRequestHeader("Content-length", data.length);
    xhro.setRequestHeader("Connection", "close");
    xhro.send(data);
}