//education

function show_div(div)
{
//	alert(div);
	document.getElementById(div).style.display = "block";
}
function hide_div(div)
{
	document.getElementById(div).style.display = "none";
}

function toggle_div(div) {
	
	if(document.getElementById(div).style.display == "block"){
		document.getElementById(div).style.display = "none";
	} else {
		document.getElementById(div).style.display = "block";
	}
}

// Sirimon: Study School
function validation(str1,str2){
//	alert(str1 + str2);
	if(document.getElementById(str1).value== ''){
		alert("Please select school for creating new sign up form link.");
		document.getElementById(str1).focus();
		return false;
	}
	
	if(document.getElementById(str2).value == ''){
		alert("Please insert your link of school's study.");
		document.getElementById(str2).focus();
		return false;
	}
	return true;
}

var xmlHttp
function manageStudySchoolLink(str,id,sclink){
	var action = str;


	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}

	
		if(action == 'add'){
			if(school == ''){
				alert("Please select school for creating new sign up form link.");
				document.getElementById('school').focus();
				return false;
			}
			
			if(path == ''){
				alert("Please insert your link of school's study.");
				document.getElementById('sslink').focus();
				return false;
			}
			
				var school = document.getElementById('school').value;
				var study = document.getElementById('study').value;
				var path = document.getElementById('sslink').value;
				
		}else if(action == 'edit'){
			document.getElementById('editbtn['+id+']').style.display = "none";
			document.getElementById('updatebtn['+id+']').style.display = "block";
			document.getElementById('sclink['+id+']').innerHTML = "<input type='text' id='schoollink' value='"+sclink+"' size='70' />";
			return false;
		}else if(action == 'update'){
			var school = document.getElementById('school['+id+']').value;
			var study = document.getElementById('study['+id+']').value;
			var path = document.getElementById('schoollink').value;
			
		}
	
		xmlHttp.onreadystatechange= StudySchoolChanged 
		xmlHttp.open("POST","../actions/adminStudySchool.php",true)
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 	
		xmlHttp.send("school="+encodeURIComponent(school)+"&study="+encodeURIComponent(study)
		+"&path="+encodeURIComponent(path)+"&action="+action+"&school_study_id="+id);
/*	if (confirm("Confirm to "+action+" your list.") == true){
	}*/
	
}

function StudySchoolChanged(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById("studyschool").innerHTML=xmlHttp.responseText 
	} 
}

function manageDegreeProgram(str,id,degreename){
var action = str;

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}

		if(action == 'add'){
			if(school == ''){
				alert("Please select school for creating new sign up form link.");
				document.getElementById('school').focus();
				return false;
			}
			
			if(path == ''){
				alert("Please insert your link of school's study.");
				document.getElementById('sslink').focus();
				return false;
			}
			
				var school = document.getElementById('school').value;
				var study = document.getElementById('studydegree').value;
				var path = document.getElementById('sslink').value;
				
		}else if(action == 'edit'){
			document.getElementById('editbtnd['+id+']').style.display = "none";
			document.getElementById('updatebtnd['+id+']').style.display = "block";
			document.getElementById('degree['+id+']').innerHTML = "<img src=\"../images/arrow_132.gif\"/> <input type='text' id='deegreename' value='"+degreename+"' size='70' />";
			document.getElementById('degree['+id+']').focus();
			return false;
		}else if(action == 'update'){
			var degree = id; // degree_program id
			var study = document.getElementById('studydegree['+id+']').value; // study id
			var newname = document.getElementById('deegreename').value; // new name for degree_program
			
			xmlHttp.onreadystatechange=function()
			{
				if(xmlHttp.readyState==4)
				  {document.getElementById('deegreeprogram['+study+']').innerHTML=xmlHttp.responseText}
			}
			////////////////
			xmlHttp.open("POST","../actions/adminStudyDegree.php",true)
			xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 	
			xmlHttp.send("degree="+encodeURIComponent(degree)+"&study="+encodeURIComponent(study)
			+"&newname="+encodeURIComponent(newname)+"&action="+encodeURIComponent(action));
			
			document.getElementById('editbtnd['+id+']').style.display = "block";
			document.getElementById('updatebtnd['+id+']').style.display = "none";
		}else if(action == 'delete'){
			var study = document.getElementById('studydegree['+id+']').value; // study id
			
			if(confirm("Do you want to delete this degree program : '"+degreename+"' ?")){

				xmlHttp.onreadystatechange=function()
				{
					if(xmlHttp.readyState==4)
					  {document.getElementById('deegreeprogram['+study+']').innerHTML=xmlHttp.responseText}
				}
				////////////////
				xmlHttp.open("POST","../actions/adminStudyDegree.php",true)
				xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 	
				xmlHttp.send("degree="+encodeURIComponent(id)+"&study="+encodeURIComponent(study)
				+"&action="+encodeURIComponent(action));
				
			}else{
				return false;
			}
		}
}

function deleteProgramSchool(id,school,degree){
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}

//	var study = document.getElementById('studydegree['+id+']').value; // study id
	
	if(confirm("Do you want to delete this school program?")){
	
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			  {document.getElementById('showprogram['+school+']').innerHTML=xmlHttp.responseText}
		}
		////////////////
		xmlHttp.open("POST","../actions/adminSchoolProgram.php",true)
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 	
		xmlHttp.send("action="+encodeURIComponent('delete')+"&id="+encodeURIComponent(id)
		+"&degree="+encodeURIComponent(degree)+"&school="+encodeURIComponent(school));
		
	}else{
		return false;
	}
}

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;
}