﻿var xmlHttp;
function createXMLHttpRequest() {
try {
		xmlHttp = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				xmlHttp = false;
			}
		}
	}

	if (!xmlHttp) {
		alert("Error initializing XMLHttpRequest!");
	}else{
//		alert("Initializing XMLHttpRequest!");
	}
}

function callAJAX(strurl, varA, obj){
	createXMLHttpRequest();
	var url = strurl + escape(varA)
//	alert (url);
	xmlHttp.open ("GET", url, true);
	if (obj == "divExamDate"){
		xmlHttp.onreadystatechange = GetDate;
	}else if (obj == "divExamTime"){
		xmlHttp.onreadystatechange = GetTime;
	}else if (obj == "txtSectionId")
	{
		if (document.getElementById(obj).value.length == 7)
		{
			xmlHttp.onreadystatechange = GetSectionId;
		}
	}
	xmlHttp.send(null);
}

function GetDate(){
//	alert(obj);
	if (xmlHttp.readyState == 4) {
//		alert("readyState is " + xmlHttp.readyState);
		var strResponse = xmlHttp.responseText;

		switch (xmlHttp.status)
		{
		case 404:
			alert("File Not Found.");
		case 500:
				handleErrFullPage(strResponse);
				break;
		}

		if (xmlHttp.status == 200){
			document.getElementById("divExamDate").style.display = "";
			document.getElementById("divExamDate").innerHTML = xmlHttp.responseText;
		}else{
//			alert("status is " + xmlHttp.status);
		}
	}else{
//		alert("Data Dose Not Arrival In This DIV Object");
//		alert("status is " + xmlHttp.readyState);
		document.getElementById("divExamDate").style.display = "none";
	}
}

function GetTime(){
//	alert(obj);
	if (xmlHttp.readyState == 4) {
//		alert("readyState is " + xmlHttp.readyState);
		var strResponse = xmlHttp.responseText;

		switch (xmlHttp.status)
		{
		case 404:
			alert("File Not Found.");
		case 500:
				handleErrFullPage(strResponse);
				break;
		}

		if (xmlHttp.status == 200){
			document.getElementById("divExamTime").style.display = "";
			document.getElementById("divExamTime").innerHTML = xmlHttp.responseText;
		}else{
//			alert("status is " + xmlHttp.status);
		}
	}else{
//		alert("Data Dose Not Arrival In This DIV Object");
//		alert("status is " + xmlHttp.readyState);
		document.getElementById("divExamTime").style.display = "none";
	}
}

function GetSectionId(){
//	alert(obj);
	if (xmlHttp.readyState == 4) {
//		alert("readyState is " + xmlHttp.readyState);
		var strResponse = xmlHttp.responseText;

		switch (xmlHttp.status)
		{
		case 404:
			alert("File Not Found.");
		case 500:
				handleErrFullPage(strResponse);
				break;
		}
		if (xmlHttp.status == 200){
			document.getElementById("txtSectionId").value = xmlHttp.responseText;
		}else{
//			alert("status is " + xmlHttp.status);
		}
	}else{
//		alert("Data Dose Not Arrival In This DIV Object");
//		alert("status is " + xmlHttp.readyState);
//		document.getElementById("txtSectionId").style.display = "none";
	}
}

function handleErrFullPage(strIn) {

        var errorWin;

        // Create new window and display error
        try {
                errorWin = window.open('', 'errorWin');
                errorWin.document.body.innerHTML = strIn;
        }
        // If pop-up gets blocked, inform user
        catch(e) {
                alert('An error occurred, but the error message cannot be' +
                        ' displayed because of your browser\'s pop-up blocker.\n' +
                        'Please allow pop-ups from this Web site.');
        }
}