/*
================================================
AJAX RisTIE
Kumpulan fungsi-fungsi untuk ajax di web RisTIE
serta berbagai fungsi javascript lainnya.
================================================
*/

var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function halaman(url, containerid)
{
	document.getElementById(containerid).style.cursor="wait"
	preload(containerid,2000)
	//document.getElementById(containerid).style.cursor="default"
	
	var page_request = false
	if(window.XMLHttpRequest) // jika Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject)
	{ // jika IE
		try
		{
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch(e)
		{
			try
			{
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e)
			{
			}
		}
	}
	else
		return false
	page_request.onreadystatechange=function()
	{
		//preload(containerid)
		loadpage(page_request, containerid)
	}
	page_request.open('GET', url, true)
	page_request.send(null)
	document.getElementById(containerid).style.cursor="default"
}

function loadpage(page_request, containerid)
{
	if(page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
		document.getElementById(containerid).innerHTML=page_request.responseText
}

//Fungsi untuk menampilkan image proses loading halaman
function preload(containerid,lama_delay_ms)
{
	var date = new Date()
	var curDate = null
	
	do
	{
		document.getElementById(containerid).style.cursor="wait"
		curDate = new Date()
	}
	while(curDate-date < lama_delay_ms)
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}// JavaScript Document

function jam()
{
var skg=new Date()
var taon=skg.getFullYear()-2000
var bln=skg.getMonth()+1
var hr=skg.getDay()
var tgl=skg.getDate()
var jm =skg.getHours()
var mnt =skg.getMinutes()
var det =skg.getSeconds()

var hari = new Array(7)
 hari[0]="Minggu"
 hari[1]="Senin"
 hari[2]="Selasa"
 hari[3]="Rabu"
 hari[4]="Kamis"
 hari[5]="Jum'at"
 hari[6]="Sabtu"
//ini buat ngasi angka nol di depan angka yg krg dr 10
bln=cek(bln)
mnt=cek(mnt)
det=cek(det)
taon=cek(taon)
document.getElementById('kal').innerHTML=hari[hr]+", "+tgl+"/"+bln+"/"+taon+" "+jm+":"+mnt+":"+det

t=setTimeout('jam()',500)
}

function cek(z)
{
if (z<10) 
  {z="0" + z}
  return z
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Untuk operasi GET dan POST dengan PHP

function createAjaxObj(){
var httprequest=false
if (window.XMLHttpRequest){ // jika Mozilla, Safari etc
httprequest=new XMLHttpRequest()
if (httprequest.overrideMimeType)
httprequest.overrideMimeType('text/xml')
}
else if (window.ActiveXObject){ // jika IE
try {
httprequest=new ActiveXObject("Msxml2.XMLHTTP");
} 
catch (e){
try{
httprequest=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
return httprequest
}

var ajaxpack=new Object()
ajaxpack.basedomain="http://"+window.location.hostname
ajaxpack.ajaxobj=createAjaxObj()
ajaxpack.filetype=""
ajaxpack.addrandomnumber=0 //Set to 1 or 0. Lihat dokumentasi

ajaxpack.getAjaxRequest=function(url, parameters, callbackfunc, filetype){
ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object menghindari cache di IE
if (ajaxpack.addrandomnumber==1) //Lebih jauh mengatasi caching di IE?
var parameters=parameters+"&ajaxcachebust="+new Date().getTime()
if (this.ajaxobj){
this.filetype=filetype
this.ajaxobj.onreadystatechange=callbackfunc
this.ajaxobj.open('GET', url+"?"+parameters, true)
this.ajaxobj.send(null)
}
}

ajaxpack.postAjaxRequest=function(url, parameters, callbackfunc, filetype){
ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object menghindari cache di IE
if (this.ajaxobj){
this.filetype=filetype
this.ajaxobj.onreadystatechange = callbackfunc;
this.ajaxobj.open('POST', url, true);
this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
this.ajaxobj.setRequestHeader("Content-length", parameters.length);
this.ajaxobj.setRequestHeader("Connection", "close");
this.ajaxobj.send(parameters);
}
}

function processGetPost()
{
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4){ //jika telah sukses
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //jika permintaan sukses atau script dieksekusi lokal
if (myfiletype!="")
{
	if(myfiletype=="form_komentar")
	{
		document.getElementById('form_komentar').innerHTML=myajax.responseText
	}
	else
		document.getElementById('cntn').innerHTML=myajax.responseText
	//halaman('myajax.responseText', 'cntn')
}
else
	alert(myajax.responseXML)
}
}
}

/*
+++++++++++++++++++++++++++++++++++++++++
Fungsi-fungsi untuk menampilkan link dg
Ajax
+++++++++++++++++++++++++++++++++++++++++
*/
//Menampilkan berita
function panggil_berita_ristie_headline()
{
	ajaxpack.getAjaxRequest("isi/lnews.php", "page=berita_ristie&index=1", processGetPost, "berita_ristie")
}
function panggil_berita_it_headline()
{
	ajaxpack.getAjaxRequest("isi/news.php", "page=berita_it&index=1", processGetPost, "berita_it")
}
function panggil_berita(berita)
{
	ajaxpack.getAjaxRequest("isi/show_news.php", berita, processGetPost, "berita")
}

//Menampilkan artikel
function panggil_artikel(artikel)
{
	ajaxpack.getAjaxRequest("isi/artikel/artikel.php", artikel, processGetPost, "artikel")
}

//Menampilkan tutorial
function panggil_tutorial_net_headline()
{
	ajaxpack.getAjaxRequest("isi/tutor/tutornet.php", "page=tutor_net&index=1", processGetPost, "tutorial_net")
}
function panggil_tutorial_db_headline()
{
	ajaxpack.getAjaxRequest("isi/tutor/tutordb.php", "page=tutor_db&index=1", processGetPost, "tutorial_db")
}
function panggil_tutorial_web_headline()
{
	ajaxpack.getAjaxRequest("isi/tutor/tutorweb.php", "page=tutor_web&index=1", processGetPost, "tutorial_web")
}
function panggil_tutorial(tutorial)
{
	ajaxpack.getAjaxRequest("isi/tutor/tutor.php", tutorial, processGetPost, "tutorial")
}
function form_komentar_tutorial(var_tutorial)
{
	if(document.getElementById('form_komentar').innerHTML!='')
	{
		document.getElementById('form_komentar').innerHTML='';
		document.getElementById('form_komentar').height=0;
		document.getElementById('form_komentar').display='none';
	}
	else
	{
		ajaxpack.getAjaxRequest("isi/tutor/form_komentar.php", var_tutorial, processGetPost, "form_komentar")
		//ajaxpack.getAjaxRequest("inc/blank.php", var_tutorial, processGetPost, "form_komentar")
	}
}
function komentar_tutorial()
{
	var komentar=document.getElementById('komentar');
	var username=document.getElementById('username');
	var password=document.getElementById('password');
	var id_tutor=document.getElementById('id_tutor');
	var var_komentar='komentar='+komentar.value+'&username='+username.value+'&password='+password.value+'&id_tutorial='+id_tutor.value;
	ajaxpack.getAjaxRequest("isi/tutor/olah_komentar.php", var_komentar, processGetPost, "form_komentar")
}

//Menampilkan bukutamu
function paging_bukutamu(var_halaman)
{
	ajaxpack.getAjaxRequest("bukutamuku/index.php", var_halaman, processGetPost, "bukutamu")
}

//Pagination halaman content
function paging_content(var_content,var_halaman)
{
	ajaxpack.getAjaxRequest(var_content, var_halaman, processGetPost, "halaman_content")
}

//Fasilitas search
function tampilkan_hasil_pencarian()
{
	var kata_kunci=document.getElementById('kata_kunci');
	var kata_kuncinya='kata_kunci='+kata_kunci.value;
	ajaxpack.getAjaxRequest("search.php", kata_kuncinya, processGetPost, "search")
}
function tampilkan_sub_pencarian(parameter_sub)
{
	ajaxpack.getAjaxRequest("search.php", parameter_sub, processGetPost, "search")
}
