﻿// JScript source code
function fillDays(ddlYear, ddlMonth, ddlDay, selectedDay) {
    var xmlHttp;
    //
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	//
	xmlHttp.onreadystatechange = function() { 
		removeLoading(ddlDay);
		if (xmlHttp.readyState == 4) {
		    var arr = xmlHttp.responseText.split(",");
		    if (xmlHttp.responseText.indexOf(",") == -1) {
		        var opt = document.createElement("option");
	                opt.text = xmlHttp.responseText;
	                opt.value = xmlHttp.responseText;
	                try {
		                document.getElementById(ddlDay).add(opt, null);
	                } catch (e) {
		                document.getElementById(ddlDay).add(opt);
	                }
		    } else {
		        for (i=0; i<arr.length; i++) {
		            var opt = document.createElement("option");
	                opt.text = arr[i];
	                opt.value = arr[i];
	                try {
		                document.getElementById(ddlDay).add(opt, null);
	                } catch (e) {
		                document.getElementById(ddlDay).add(opt);
	                }
		        }
		        //
		        if (selectedDay == "" || selectedDay == null) {
		            //
		        } else {
		            document.getElementById(ddlDay).value = selectedDay;
		        }
		    }
		}
	}
	//
	addLoading(ddlDay);
	xmlHttp.open("GET","functions.aspx?cat=getDays&year="+document.getElementById(ddlYear).value+"&month="+document.getElementById(ddlMonth).value+"&ran="+Math.random(),true);
	xmlHttp.send(null);
}

function addLoading(ddl) {
    document.getElementById(ddl).length = 0;
    var optLoading = document.createElement("option");
    optLoading.text = "Loading ...";
    optLoading.value = "0";
    try {
        document.getElementById(ddl).add(optLoading, null);
    } catch (e) {
        document.getElementById(ddl).add(optLoading);
    }
	document.getElementById(ddl).disabled = true;   
}

function removeLoading(ddl) {
    document.getElementById(ddl).length = 0;
	document.getElementById(ddl).disabled = false;
}

function checkmem(memno)
{
    var xmlHttp;
    //
	try 
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} 
	catch (e) 
	{
		// Internet Explorer
		try 
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) 
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	//
	
	xmlHttp.onreadystatechange = function() 
	{ 
		if (xmlHttp.readyState == 4) 
		{
		    var str = xmlHttp.responseText;
		    return str;
		    //		    
		}
	}
		
	xmlHttp.open("GET","functions.aspx?cat=checkmem&memno=" + memno,false);
	xmlHttp.send(null);	
}

function addBookings(no,Loc,Half,Day,Time)
{
    var xmlHttp;
    //
	try 
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} 
	catch (e) 
	{
		// Internet Explorer
		try 
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) 
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	//
	
	xmlHttp.onreadystatechange = function() 
	{ 
		if (xmlHttp.readyState == 4) 
		{
		    var str = xmlHttp.responseText;
		    return str;
		    //		    
		}
	}
		
	xmlHttp.open("GET","functions.aspx?cat=addBooking&num=" + no + "&loc=" + Loc + "&half=" + Half + "&day=" + Day + "&time=" + Time,false);
	xmlHttp.send(null);	
}

function CheckValidHalf(Loc,Half,Valid)
{
    var xmlHttp;
    //
	try 
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} 
	catch (e) 
	{
		// Internet Explorer
		try 
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) 
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	//
	
	xmlHttp.onreadystatechange = function() 
	{ 
		if (xmlHttp.readyState == 4) 
		{
		    var str = xmlHttp.responseText;
		    Valid.value = str;
		    return str;
		    //		    
		}
	}
		
	xmlHttp.open("GET","functions.aspx?cat=checkfld&loc=" + Loc + "&half=" + Half,false);
	xmlHttp.send(null);	
}

function CheckValidTime(Loc,Day,Time,Valid)
{
    var xmlHttp;
    //
	try 
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} 
	catch (e) 
	{
		// Internet Explorer
		try 
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) 
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	//
	
	xmlHttp.onreadystatechange = function() 
	{ 
		if (xmlHttp.readyState == 4) 
		{
		    var str = xmlHttp.responseText;
		    Valid.value = str;
		    return str;
		    //		    
		}
	}
		
	xmlHttp.open("GET","functions.aspx?cat=checktime&loc=" + Loc + "&day=" + Day + "&time=" + Time,false);
	xmlHttp.send(null);	
}

function addIns(no,Amt,dt_ins)
{
    var xmlHttp;
    //
	try 
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} 
	catch (e) 
	{
		// Internet Explorer
		try 
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) 
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	//
	
	xmlHttp.onreadystatechange = function() 
	{ 
		if (xmlHttp.readyState == 4) 
		{
		    var str = xmlHttp.responseText;
		    return str;
		    //		    
		}
	}
		
	xmlHttp.open("GET","functions.aspx?cat=addnewins&num=" + no + "&amt=" + Amt + "&dt=" + dt_ins,false);
	xmlHttp.send(null);	
}