function loadAjax()
{
	var loadAjax;
	try { loadAjax = new XMLHttpRequest(); return loadAjax;}			// For Mozilla browsers
	catch (e){ try { loadAjax = new ActiveXObject("Msxml2.XMLHTTP");  return loadAjax;}		// For the users with IE browser
	catch (e){ try { loadAjax = new ActiveXObject("Microsoft.XMLHTTP");  return loadAjax;}	// For the users with IE browser
	catch (e){ alert("Your browser broke!"); return false;}	} }
}
function selectCountry(values)
{	
	var loadAjaxVar = loadAjax();	
	if(loadAjaxVar)
	{		
		var selectvalue = values.value;
		if(selectvalue != "")
		{
			var url = "selectCountry.php?selectvalue="+selectvalue;
			loadAjaxVar.onreadystatechange = function()
			{		
				if(loadAjaxVar.readyState == 4)
				{
					if(selectvalue == "international" && document.getElementById('centre_code'))
					{
						//document.getElementById('centre_code').options[0]  = new Option("N/A","N/A");
						document.getElementById('centre_code').value = "N/A";
					}
					var y = loadAjaxVar.responseText;	
					//alert("Y is "+y);
					document.getElementById("city").options.length = 0;
					document.getElementById("state").options.length = 0;
					document.getElementById("city").options[0] = new Option("Select","");					
					document.getElementById("state").options[0] = new Option("Select","");
					
					x = y.split("#");
					fillupState(x);
				}
				else
				{
					//alert(loadAjaxVar.readyState);
					document.getElementById("state").options[0] = new Option("Loading...","");
				}
			}      
			url = url+"&sid="+Math.random();
			loadAjaxVar.open("GET", url, true);
			loadAjaxVar.send('');	
		}
	}
	else
	{
		alert("Your Browser doesn't support ajax....");
	}
}
function fillupState(z)
{
	var combobox = document.getElementById("state");
	combobox.options.length = 0;
	for (var i=0; i < z.length-1; i++)
	{
		var k = z[i+1];
		var splitted = k.split("@");
		combobox.options[i] = new Option(splitted[1],splitted[0]);
	}
}

function selectCity(values)
{	
	var loadAjaxVar = loadAjax();	
	if(loadAjaxVar)
	{		
		var selectvalue = values.value;
		if(selectvalue != "")
		{
			var centre = document.studid.centre_loc;
			document.getElementById('centre_code').value = "";
			//alert(centre);
			/*
			if(centre.value == "international")
			{
				//alert(document.studid.state.value);
				var x = "CADD Centre@CADD Centre";				
				var splitted = x.split("@");				
				document.getElementById('city').options[0] = new Option(splitted[1],splitted[0]);
				//document.getElementById('centre_code').options[0] = new Option("N/A","N/A");				
			}
			else
			{
			*/
				var url = "selectCity.php?selectvalue="+selectvalue;
				loadAjaxVar.onreadystatechange = function()
				{		
					if(loadAjaxVar.readyState == 4)
					{				
						var y = loadAjaxVar.responseText;	
						//alert("Y is "+y);	
						//document.getElementById('state').innerHTML = y;
						x = y.split("#");
						fillupCity(x);
					}
					else
					{
						//alert(loadAjaxVar.readyState);
						document.getElementById("city").options[0] = new Option("Loading...","");
					}
				}      
				url = url+"&sid="+Math.random();
				loadAjaxVar.open("GET", url, true);
				loadAjaxVar.send('');	
			//}
		}
	}
	else
	{
		alert("Your Browser doesn't support ajax....");
	}
}
function fillupCity(z)
{
	var combobox = document.getElementById("city");
	combobox.options.length = 0;
	for (var i=0; i < z.length-1; i++)
	{
		var k = z[i+1];
		var splitted = k.split("@");
		combobox.options[i] = new Option(splitted[1],splitted[0]);
	}
}
function fillupCentre(z)
{
	var combobox = document.getElementById("centre_code");
	if(combobox)
	{
		combobox.value = z;
		/*
		combobox.options.length = 0;		
		for (var i=0; i < z.length-1; i++)
		{
			var k = z[i+1];
			var splitted = k.split("@");
			combobox.options[i] = new Option(splitted[1],splitted[0]);
		}
		*/
	}
}
function selectCode(city)
{
	var loadAjaxVar = loadAjax();	
	if(loadAjaxVar)
	{		
		var selectvalue = city.value;
		if(selectvalue != "")
		{
			var url = "selectCentre.php?cityvalue="+selectvalue;
			loadAjaxVar.onreadystatechange = function()
			{		
				if(loadAjaxVar.readyState == 4)
				{				
					var y = loadAjaxVar.responseText;	
					//alert("Y is "+y);	
					//document.getElementById('state').innerHTML = y;
					if(y != "")
					{
						x = y.split("#");
						fillupCentre(x);
					}
					else
					{
						fillupCentre("N/A");
					}
				}
				else
				{
					//alert(loadAjaxVar.readyState);
					fillupCentre("Loading...");
				}
			}     
			url = url+"&sid="+Math.random();
			loadAjaxVar.open("GET", url, true);
			loadAjaxVar.send('');	
		}
	}
	else
	{
		alert("Your Browser doesn't support ajax....");
	}
}
function createsidno(datevalue)
{
	var loadAjaxVar = loadAjax();	
	if(loadAjaxVar)
	{		
		datevalue = datevalue.replace("/","-");
		datevalue = datevalue.replace("/","-");
		//alert(datevalue);
		var url = "stuidprocess.php?datevalue="+datevalue;
		loadAjaxVar.onreadystatechange = function()
		{		
			if(loadAjaxVar.readyState == 4)
			{				
				var y = loadAjaxVar.responseText;	
				//alert("Y is "+y);	
				document.getElementById('studidno').value = y;
			}
			else
			{
				//alert(loadAjaxVar.readyState);
			}
		}      
		url = url+"&sid="+Math.random();
		loadAjaxVar.open("GET", url, true);
		loadAjaxVar.send('');		
	}
	else
	{
		alert("Ajax not working in your browser");
	}
}

function loadCategory(cat)
{
	var loadAjaxVar = loadAjax();	
	if(loadAjaxVar)
	{		
		var selectvalue = cat.value;
		if(selectvalue != "")
		{
			var url = "selectCategory.php?catvalue="+selectvalue;
			loadAjaxVar.onreadystatechange = function()
			{		
				if(loadAjaxVar.readyState == 4)
				{				
					var y = loadAjaxVar.responseText;	
					//alert("Y is "+y);	
					//document.getElementById('state').innerHTML = y;
					x = y.split("#");
					fillupCategory(x);
				}
				else
				{
					//alert(loadAjaxVar.readyState);
					document.getElementById("category").options[0] = new Option("Loading...","");
				}
			}     
			url = url+"&sid="+Math.random();
			loadAjaxVar.open("GET", url, true);
			loadAjaxVar.send('');	
		}
	}
	else
	{
		alert("Your Browser doesn't support ajax....");
	}
}

function fillupCategory(z)
{
	var combobox = document.getElementById("category");
	combobox.options.length = 0;
	for (var i=0; i < z.length-1; i++)
	{
		var k = z[i+1];
		var splitted = k.split("@");
		combobox.options[i] = new Option(splitted[1],splitted[0]);
	}
}
function loadCourseCode(cat)
{
	var loadAjaxVar = loadAjax();	
	if(loadAjaxVar)
	{		
		var selectvalue = cat.value;
		//alert(selectvalue);
		if(selectvalue != "")
		{
			var url = "selectCourseCode.php?coursecodevalue="+selectvalue;
			loadAjaxVar.onreadystatechange = function()
			{		
				if(loadAjaxVar.readyState == 4)
				{				
					var y = loadAjaxVar.responseText;	
					//alert("Y is "+y);	
					//document.getElementById('state').innerHTML = y;
					x = y.split("#");
					fillupCourseCode(x);
				}
				else
				{
					//alert(loadAjaxVar.readyState);
					document.getElementById("course_code").options[0] = new Option("Loading...","");
				}
			}     
			url = url+"&sid="+Math.random();
			loadAjaxVar.open("GET", url, true);
			loadAjaxVar.send('');	
		}
	}
	else
	{
		alert("Your Browser doesn't support ajax....");
	}
}

function fillupCourseCode(z)
{
	var combobox = document.getElementById("course_code");
	combobox.options.length = 0;
	for (var i=0; i < z.length-1; i++)
	{
		var k = z[i+1];
		var splitted = k.split("@");
		combobox.options[i] = new Option(splitted[1],splitted[0]);
	}
}
function fillupstudent(z)
{
	var combobox = document.getElementById("fullname");
	
	
	if(combobox)
	{
		combobox.value = z;
	}
}
function fillupjoincentre(z)
{
	var combobox = document.getElementById("centre");
	
	
	if(combobox)
	{
		combobox.value = z;
	}
}
function fillupemail(z)
{
	var combobox = document.getElementById("email");
	
	
	if(combobox)
	{
		combobox.value = z;
	}
}
function fillupphone(z)
{
	var combobox = document.getElementById("phone");
	
	
	if(combobox)
	{
		combobox.value = z;
	}
}
function selectstudentid(studid)
{
	var loadAjaxVar = loadAjax();	
	if(loadAjaxVar)
	{		
		var selectvalue = studid.value;
		//alert(selectvalue);
		if(selectvalue != "")
		{
			var url = "selectstudidno.php?studid="+selectvalue;
			loadAjaxVar.onreadystatechange = function()
			{		
				if(loadAjaxVar.readyState == 4)
				{				
					var y = loadAjaxVar.responseText;	
					//alert("Y is "+y);	
					//document.getElementById('state').innerHTML = y;
					if(y != "")
					{
						x = y.split("#");
						fillupstudent(x[0]);
						fillupjoincentre(x[1]);
						fillupemail(x[2]);
						fillupphone(x[3]);
						
						
						
					}
					else
					{
						alert("student id is wrong");
						document.getElementById("studentid").focus();
						document.getElementById("studentid").value="";
						document.getElementById("fullname").value="";
						document.getElementById("centre").value="";
						document.getElementById("email").value="";
						document.getElementById("phone").value="";
						
					}
				}
				else
				{
					//alert(loadAjaxVar.readyState);
					//document.getElementById("studentid").focus();
					//fillupstudent("Loading...");
					//alert("student id is wrong");
					//document.getElementById("studentid").value="";
				}
			}     
			url = url+"&sid="+Math.random();
			loadAjaxVar.open("GET", url, true);
			loadAjaxVar.send('');	
		}
	}
	else
	{
		alert("Your Browser doesn't support ajax....");
	}
}

// Course Eqnuire fom 
/*

function selectCity1(values)
{	
	var loadAjaxVar = loadAjax();	
	if(loadAjaxVar)
	{		
		var selectvalue = values.value;
		if(selectvalue != "")
		{
			var centre = document.couseenquire.centre_loc;
			//alert(centre);
			if(centre.value == "international")
			{
				//alert(document.studid.state.value);
				var x = "CADD Centre@CADD Centre";				
				var splitted = x.split("@");				
				document.getElementById('city').options[0] = new Option(splitted[1],splitted[0]);
			}
			else
			{
				var url = "selectCity.php?selectvalue="+selectvalue;
				loadAjaxVar.onreadystatechange = function()
				{		
					if(loadAjaxVar.readyState == 4)
					{				
						var y = loadAjaxVar.responseText;	
						//alert("Y is "+y);	
						//document.getElementById('state').innerHTML = y;
						x = y.split("#");
						fillupCity1(x);
					}
					else
					{
						//alert(loadAjaxVar.readyState);
					}
				}      
				url = url+"&sid="+Math.random();
				loadAjaxVar.open("GET", url, true);
				loadAjaxVar.send('');	
			}
		}
	}
	else
	{
		alert("Your Browser doesn't support ajax....");
	}
}
function fillupCity1(z)
{
	var combobox = document.getElementById("city");
	combobox.options.length = 0;
	for (var i=0; i < z.length-1; i++)
	{
		var k = z[i+1];
		var splitted = k.split("@");
		combobox.options[i] = new Option(splitted[1],splitted[0]);
	}
}
function loadCategory1(cat)
{
	var loadAjaxVar = loadAjax();	
	if(loadAjaxVar)
	{		
		var selectvalue = cat.value;
		if(selectvalue != "")
		{
			var url = "selectCategory.php?catvalue="+selectvalue;
			loadAjaxVar.onreadystatechange = function()
			{		
				if(loadAjaxVar.readyState == 4)
				{				
					var y = loadAjaxVar.responseText;	
					//alert("Y is "+y);	
					//document.getElementById('state').innerHTML = y;
					x = y.split("#");
					fillupCategory1(x);
				}
				else
				{
					//alert(loadAjaxVar.readyState);
				}
			}     
			url = url+"&sid="+Math.random();
			loadAjaxVar.open("GET", url, true);
			loadAjaxVar.send('');	
		}
	}
	else
	{
		alert("Your Browser doesn't support ajax....");
	}
}

function fillupCategory1(z)
{
	var combobox = document.getElementById("category");
	combobox.options.length = 0;
	for (var i=0; i < z.length-1; i++)
	{
		var k = z[i+1];
		var splitted = k.split("@");
		combobox.options[i] = new Option(splitted[1],splitted[0]);
	}
}
*/