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 = "temp_selectCity.php?selectvalue="+selectvalue;
				//alert(url)
				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]);
	}
}


//select centre place

function selectCentrePlace(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 = "temp_selectCentrePlace.php?selectvalue="+selectvalue;
				//alert(url)
				loadAjaxVar.onreadystatechange = function()
				{		
					if(loadAjaxVar.readyState == 4)
					{				
						var y = loadAjaxVar.responseText;	
						//alert("Y is "+y);	
						//document.getElementById('state').innerHTML = y;
						x = y.split("#");
						fillupCentrePlace(x);
					}
					else
					{
						//alert(loadAjaxVar.readyState);
						document.getElementById("centre_place").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 fillupCentrePlace(z)
{
	var combobox = document.getElementById("centre_place");
	//alert(document.getElementById("centre_place"));
	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]);
	}
}


//end centre place



//select stream

function fillupStream(z)
{
	var combobox = document.getElementById("course_join");
	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 loadStream()
{
	var loadAjaxVar = loadAjax();	
	if(loadAjaxVar)
	{		
		var selectvalue = 1;
		if(selectvalue != "")
		{
			var url = "temp_selectStream.php?Stream="+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("#");
						fillupStream(x);
					}
					else
					{
						fillupStream("N/A");
					}
				}
				else
				{
					//alert(loadAjaxVar.readyState);
                     document.getElementById("course_join").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....");
	}
}

//end stream






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 = "temp_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, centrecode)
{
	
	var loadAjaxVar = loadAjax();	
	if(loadAjaxVar)
	{		
		var selectvalue = cat.value;
		//var centreC = centrecode.value;
		//alert(selectvalue);
		if(selectvalue != "")
		{
			
			//var selectvalue1=document.getElementById('course_join').value;
			var url = "temp_selectCategory.php?catvalue="+selectvalue+"&centre="+centrecode.value;
			//alert(url);
			
			loadAjaxVar.onreadystatechange = function()
			{		
				if(loadAjaxVar.readyState == 4)
				{				
					var y = loadAjaxVar.responseText;	
						
					//document.getElementById('state').innerHTML = y;
					x = y.split("#");
//					alert("Y is "+y);
					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 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 loadCourseCode(cat)
{
	//alert(stream);
	var loadAjaxVar = loadAjax();	
	if(loadAjaxVar)
	{		
		var selectvalue = cat.value;
		//alert(selectvalue);
		if(selectvalue != "")
		{
			
			var selectvalue1=document.getElementById('course_join').value;
			var centre_code001=document.getElementById('centre_place').value;
			//alert(centre_code);
			var url = "temp_selectCourseCode.php?coursecodevalue="+selectvalue+"&value="+selectvalue1+"&centre_code002="+centre_code001;
			//alert(url);
			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(); //alert(url);
			loadAjaxVar.open("GET", url, true);
			loadAjaxVar.send('');	
		}
	}
	else
	{
		alert("Your Browser doesn't support ajax....");
	}
}



function checkListBoxSize(obj){
//alert(obj.multiple);
if(obj.multiple)
{
var count=0; var finalst='';
for(var i=0;i<obj.options.length;i++)
{
if(obj.options[i].selected)
{
	finalst = finalst + obj.options[i].value + "*";
	count++;
}
}
if(count>=2)
{
//	alert(finalst);
	document.getElementById('course_code_nsorso').value=finalst;
	return true;
}
else
{
	alert('select minimum two');
	for(var i=0;i<obj.options.length;i++) obj.options[i].selected = false;
	return false;
}
}
else
{
	return true;
}
/*oSelect=document.getElementById("course_code");
var count=0;
for(var i=0;i<oSelect.options.length;i++){
if(oSelect.options[i].selected)
count++;
if(count>maxNum){
alert("Can't select more than 3");
return false;
}
}
if(count<1){
alert("Must select at least one item");
return false;
}
return true;*/
}



/*
function loadCourseCode_software(cat)
{
	var loadAjaxVar = loadAjax();	
	if(loadAjaxVar)
	{		
		var selectvalue = cat.value;
		//alert(selectvalue);
		if(selectvalue != "")
		{
			var url = "temp_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_software").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....");
	}

}
*/


/*Neew code for Group Software*/

/*var xmlHttp;
//////set batch code in training.php checked
function loadCourseCode_software(val)
{
var x=document.getElementById("course_code").selectedIndex;	
alert(val + 'x is ' + x);
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){ alert ("Browser does not support HTTP Request"); return; }
document.getElementById("groupsoftwraediv").innerHTML='';
if(x!=0)
{
var url="temp_selectCourseCode_software.php";
url=url+"?coursecodevalue="+val; //alert(url);
document.getElementById("groupsoftwraediv").innerHTML='';
xmlHttp.onreadystatechange=stateChangedcoursecode;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
else document.getElementById("groupsoftwraediv").innerHTML='';

}


//////set Group software in temp_studid.php checked

function stateChangedcoursecode(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("groupsoftwraediv").innerHTML=xmlHttp.responseText; }
else document.getElementById("groupsoftwraediv").innerHTML="Loading...";}

function GetXmlHttpObject(){
var xmlHttp=null;
try{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest(); }
catch (e){
//Internet Explorer
try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e){ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } }
return xmlHttp;
}
*/

/*End of group software*/


function fillupCourseCode1(z,uniqueid)
{
	var combobox = document.getElementById("course_code");
	if(uniqueid==1)
	{
		document.getElementById("course_code").multiple=true;	
	}
	else
	{
		document.getElementById("course_code").multiple=false;
	}
	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....");
	}
}




//get combo list

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


function loadCourseCode_combo(cat)
{
	//alert(stream);
	var loadAjaxVar = loadAjax();	
	if(loadAjaxVar)
	{		
		var selectvalue = cat.value;
		//alert(selectvalue);
		if(selectvalue != "")
		{
			//var selectvalue1=document.getElementById('course_join').value;
			//alert(selectvalue1);
			var url = "temp_select_combo.php?value="+selectvalue;
			//alert(url);
			loadAjaxVar.onreadystatechange = function()
			{		
				if(loadAjaxVar.readyState == 4)
				{				
					var y = loadAjaxVar.responseText;	
					//alert("Y is "+y);	
					//document.getElementById('state').innerHTML = y;
					x = y.split("#");
					//fillupCourseCode__combo(x);
					document.getElementById("course_combo").innerHTML = x;
					//document.getElementById("course_combo").innerHTML=xmlHttp.responseText;
					//document.getElementById("course_combo")= x ;
				}
				else
				{
					//alert(loadAjaxVar.readyState);
					document.getElementById("course_combo").innerHTML = ("Loading...");
				}
			}     
			url = url+"&sid="+Math.random(); //alert(url);
			loadAjaxVar.open("GET", url, true);
			loadAjaxVar.send('');	
		}
	}
	else
	{
		alert("Your Browser doesn't support ajax....");
	}
}
