var xmlHttp
//-- untuk menampilkan file field untuk mengupload file pada saat manajemen materi
//-- referer : templates/dosen/komunitas_materi.htm
function showAllMultiMediaContent(komunitas_id,materi_id,mfcount)
{			
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}        
	var url="includes/request.php?cmd=amc&q=" + komunitas_id + "&r=" + materi_id + "&sid=" + Math.random()
	xmlHttp.onreadystatechange=stateChangedAMC
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	document.getElementById("ifMateri").height=mfcount * 365
}
//-- untuk menampilkan file field untuk mengupload file pada saat manajemen materi
//-- referer : templates/dosen/komunitas_materi.htm
function showFileForm(frm,jml)
{	
	var jmlp1 = parseInt(jml) + 1
	var buf="<table width='100%' cellpadding='0' cellspacing='0' border='0'>"
	    buf += "<tr><td>File " + jml + " : <input name='mmcontent" + jml +"' type='file' size='40'></td></tr></table>"
		buf += "<span id='spFileForm" + jmlp1 + "'></span>"
		document.getElementById("spFileForm" + jml).innerHTML += buf
		document.getElementById("jumlah").value=jmlp1
		document.getElementById("btnKurangFile").disabled = false
	return false
}

function toggleInsertMateri(id){
	if(document.getElementById(id).style.display == 'block'){
		document.getElementById(id).style.display = 'none'
	}
	else{
		document.getElementById(id).style.display = 'block'
	}
}
function removeFileForm(frm,jml)
{	
	var jmlm1 = parseInt(jml) - 1
	document.getElementById("spFileForm" + jmlm1).innerHTML = ""
	document.getElementById("jumlah").value = jmlm1
	if(jmlm1==2) document.getElementById("btnKurangFile").disabled = true
	return false
}

//-- untuk menampilkan prodi/jurusan pada combo box sesuai fakultas yang dipilih
//-- referer : templates/dosen/komunitas.htm
function showProdiJurusan(fak,mode)
{
	if (fak.length==0)
	{ 
		document.getElementById("ProdiJurusan").innerHTML=""
		return
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}        
	var url="includes/request.php?cmd=pj&mode=" + mode + "&q=" + fak + "&sid=" + Math.random()	
	xmlHttp.onreadystatechange=stateChangedPJ 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

//-- untuk mengecek apakah sebuah user id sudah dipakai ato belum
//-- referer : templates/home/reg.htm
function checkUserId(frm)
{
	if (frm.user_id.value=='')
	{ 
		document.getElementById("spUserId").innerHTML=""
		return
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	document.getElementById("spUserId").innerHTML = "<img src='images/loading.gif'>"
	var url="includes/request.php?cmd=cui&&q=" + frm.user_id.value + "&sid=" + Math.random()
	xmlHttp.onreadystatechange=stateChangedCUI 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

//-- untuk mengecek apakah sebuah nama komunitas sudah dipakai ato belum
//-- referer : templates/dosen/komunitas.htm
function checkNamaKomunitas(frm)
{
	if (frm.nama.value=='')
	{ 
		document.getElementById("spNamaKomunitas").innerHTML=""
		return
	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	var url="includes/request.php?cmd=cnk&&q=" + frm.nama.value + "&sid=" + Math.random()
	document.getElementById("spNamaKomunitas").innerHTML = "<img src='images/loading.gif'>"
	xmlHttp.onreadystatechange=stateChangedCNK 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}


//===========================================================================================
function stateChangedMMF() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("multimediaForm").innerHTML = xmlHttp.responseText 
	} 
} 

function stateChangedPJ() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("spProdiJurusan").innerHTML = xmlHttp.responseText
	} 
}

function stateChangedAMC() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("spMultiMediaContent").innerHTML=xmlHttp.responseText
	} 
}

function stateChangedCUI() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		if(xmlHttp.responseText==0){
			document.getElementById("spUserId").innerHTML="&nbsp;<font color=green>ID Belum dipakai</font>"
			document.getElementById("btnSimpan").disabled=false
		}
		else{
			document.getElementById("spUserId").innerHTML="&nbsp;<font color=red>ID Sudah dipakai</font>"
			document.getElementById("btnSimpan").disabled=true
		}
	} 
}

function stateChangedCNK() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		if(xmlHttp.responseText==0){
			document.getElementById("spNamaKomunitas").innerHTML="&nbsp;<font color=green>ID Belum dipakai</font>"
			document.getElementById("btnSimpan").disabled=false
		}
		else{
			document.getElementById("spNamaKomunitas").innerHTML="&nbsp;<font color=red>ID Sudah dipakai</font>"
			document.getElementById("btnSimpan").disabled=true
		}		
	} 
}

function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
  	{
  		objXMLHttp=new XMLHttpRequest()
  	}
	else if (window.ActiveXObject)
  	{
  		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  	}
	return objXMLHttp
} 