var defaultDetik=3;
var intervals;
var setUrlNext;
var ajaxObj;
var ajaxWaitObj;
var ajaxWaitObjChange;
var xLoad=false;  

var detikLogin;

function execJS(node) {
	var bSaf = (navigator.userAgent.indexOf('Safari') != -1);
	var bOpera = (navigator.userAgent.indexOf('Opera') != -1);
	var bMoz = (navigator.appName == 'Netscape');

	var st = node.getElementsByTagName('SCRIPT');

	var strExec;

	for(var i=0;i<st.length; i++) {
		if (bSaf) {
			strExec = st[i].innerHTML;
		} else if (bOpera) {
			strExec = st[i].text;
		} else if (bMoz) {
			strExec = st[i].textContent;
		} else {
			strExec = st[i].text;
		}

		try {
			eval(strExec);
		} catch(e) {
			alert(e);
		}
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  
  if(!d) d=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n]; 
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); 
  return x;
}

function searchAjax(host,imgloc,page,mod){
	if ($('searchText')){
		var textSearch = $('searchText').value;
	}
	else{
		var textSearch = MM_findObj('searchText').value;
	}
	var opt	= {
		method: 'get',
		parameters: 't=ajaxlist&id='+page+'&jenis='+mod+'&r='+textSearch, 
		onLoading: function(t) {
			$('divajax').innerHTML = '<table border="0" width="100%" height="100"><tr valign="middle" align="center"><td align="center"><img src="'+imgloc+'" border="0"><br>Loading Page ...</td></tr></table>';
			$('bodyWindows').innerHTML = '<table border="0" width="100%" height="100"><tr valign="middle" align="center"><td align="center"><img src="'+imgloc+'" border="0"><br>Loading Page ...</td></tr></table>';
		},
		onComplete: function(t) {
			$('divajax').innerHTML = t.responseText;
			execJS($('divajax'));
		},
		onFailure: function(t) {
			$('divajax').innerHTML = t.status;
		}
	};
	new Ajax.Request(host,opt);
}

function searchAjaxNext(host,imgloc){
	$('divajax').innerHTML = '<table border="0" width="100%" height="100"><tr valign="middle" align="center"><td align="center"><img src="'+imgloc+'" border="0"><br>Panggil Halaman ...</td></tr></table>';
	$('bodyWindows').innerHTML = '<table border="0" width="100%" height="100"><tr valign="middle" align="center"><td align="center"><img src="'+imgloc+'" border="0"><br>Loading Page ...</td></tr></table>';
	var opt	= {
		method: 'get',
		onComplete: function(t) {
			$('divajax').innerHTML = t.responseText;
			execJS($('divajax'));
		},
		onFailure: function(t) {
			$('divajax').innerHTML = t.status;
		}
	};
	new Ajax.Request(host,opt);
}

function listsekolahover(selObj){
	selObj.style.backgroundColor='#FFCC00';
	selObj.style.color='#FFFFFF';
	selObj.style.cursor='pointer';
}

function listsekolahout(selObj){
	selObj.style.backgroundColor='';
	selObj.style.color='';
	selObj.style.cursor='default';
}

function listlink(varLink,imgloc,objNext){
	if(objNext){
		$('xLoad').value = 'true';
	}
	$('bodyWindows').innerHTML = '<table border="0" width="100%" height="150"><tr valign="middle" align="center"><td align="center"><img src="'+imgloc+'" border="0"><br><br>Loading Page ...</td></tr></table>';
	var opt	= {
		method: 'get',
		onComplete: function(t) {
			$('bodyWindows').innerHTML = t.responseText;
			execJS($('bodyWindows'));
		},
		onFailure: function(t) {
			$('bodyWindows').innerHTML = t.status;
		}
	};
	new Ajax.Request(varLink,opt);
}

function liststatistikover(selObj){
	selObj.style.backgroundColor='#4F89C7';
	selObj.style.color='#000000';
	selObj.style.cursor='hand';
}

function liststatistikout(selObj){
	selObj.style.backgroundColor='';
	selObj.style.color='#FFFFFF';
	selObj.style.cursor='default';
}

function jumpAjax(selObj){
  eval(selObj.options[selObj.selectedIndex].value+';');
}

function goJumpAjax(selName){
  var selObj = $(selName); if (selObj) jumpAjax(selObj);
}

function jumpPage(selObj){
  location.href = selObj.options[selObj.selectedIndex].value;
}

function goJumpPage(selName){
  var selObj = $(selName); if (selObj) jumpPage(selObj);
}

function changeBg(objName,colorNum){
	var selObj = objName;
	selObj.style.backgroundColor=colorNum;
	if (colorNum == '' ){
		selObj.style.cursor='default';
	}
	else{
		selObj.style.cursor='pointer';
	}
}

function linkPage(urlNext){
	window.location=urlNext;
}

function echoSiteMap(txtChange,objName){
	var selObj = $(objName);
	selObj.innerHTML = txtChange;
}

function redirectNext(){
	if (detikLogin > 1){
		detikLogin=detikLogin-1;
		ajaxObj.innerHTML = detikLogin;
	}
	else{
		window.location = setUrlNext;
		detikLogin = defaultDetik;
		clearInterval(intervals);
	}
}

function pageRedirect(urlNext,objName){
	var selObj = $(objName);
	detikLogin = defaultDetik;
	selObj.innerHTML = detikLogin;
	setUrlNext = urlNext;
	ajaxObj = selObj;	
	intervals = setInterval(redirectNext,1000);
}

function redirectDl(){
	if (detikLogin > 1){
		detikLogin=detikLogin-1;
		ajaxObj.innerHTML = detikLogin;
	}
	else{
		window.location = setUrlNext;
		detikLogin = defaultDetik;
		ajaxWaitObj.innerHTML = ajaxWaitObjChange;
		clearInterval(intervals);
	}
}

function dlWait(urlNext,divGlobal,spanTime,replaceObj){
	var selObj1 = $(divGlobal);
	var selObj2 = $(spanTime);
	detikLogin = defaultDetik;
	selObj2.innerHTML = detikLogin;
	setUrlNext = urlNext;
	ajaxObj = selObj2;	
	ajaxWaitObj = selObj1;
	ajaxWaitObjChange = replaceObj;
	intervals = setInterval(redirectDl,1000);
}

function quest(urlNext,txtQuest){
	if (confirm(txtQuest)) {
	    window.location=urlNext;
	}	
}

function openSubWin(url, nm, x, y, w, h, atts) {
	nm = nm || "subwindow";
	atts = atts || "menubar,resizable,scrollbars";
	w = w || 600; 
	h = h || 450;
	x = (typeof x=="number")? x: window.opera? 100: Math.round( (screen.availWidth - w)/2 );
	y = (typeof y=="number")? y: window.opera? 20: Math.round( (screen.availHeight - h)/2 );
	atts += ',width='+w+',height='+h+',left='+x+',top='+y;
	var win = window.open(url, nm, atts); 
	if (win) {
		if (!win.closed) { 
			win.resizeTo(w,h); 
			win.moveTo(x,y); 
			win.focus(); 
			return false; 
		}
	} 
	return true;
}

function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(cookieName) {
	var cookieValue = '';
	var posName = document.cookie.indexOf(escape(cookieName) + '=');
	if (posName != -1) {
		var posValue = posName + (escape(cookieName) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);
		if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
		else cookieValue = unescape(document.cookie.substring(posValue));
	}
	return (cookieValue);
};

function getPrint(){
	var pUrl = getCookie('printurl');
	openSubWin(pUrl, 'winprint', null, null, 800, 600, 'noresizable,scrollbars');
}

function listpenelusuranover(selObj){
	selObj.style.backgroundColor='#D9E3EE';
	selObj.style.color='#000000';
	selObj.style.cursor='crosshair';
}

function listpenelusuranout(selObj){
	selObj.style.backgroundColor='';
	selObj.style.color='#FFFFFF';
	selObj.style.cursor='default';
}

function listpenelusuranclick(checkObjName){
	var selObj = $(checkObjName);
//	selObj.checked = !selObj.checked;	
}

function callAjax(urls,pars,objLoad1,objLoad2,MsgLoad){
	$(objLoad2).innerHTML = MsgLoad;
	$(objLoad1).innerHTML = MsgLoad;
	var opt	= {
		method: 'get',
		parameters: pars, 
		onComplete: function(t) {
			$(objLoad1).innerHTML = t.responseText;
			execJS($(objLoad1));
		},
		onFailure: function(t) {
			$(objLoad1).innerHTML = t.status;
		}
	};
	new Ajax.Request(urls,opt);
}

function callStatistik(urls,page,mod,tabel,kode,wil,tahun,imgloc){
	var pars = 't=ajaxval&id='+page+'&jenis='+mod+'&kode='+kode+'&wil='+wil+'&tahun='+tahun+'&tabel='+tabel;
	var opt	= {
		method: 'get',
		parameters: pars, 
		onLoading: function(t) {
			$('bodyWindows').innerHTML = '<table border="0" width="100%" height="150"><tr valign="middle" align="center"><td align="center"><img src="'+imgloc+'" border="0"><br><br>Loading Page ...</td></tr></table>';
		},
		onSuccess: function(t) {
			$('bodyWindows').innerHTML = t.responseText;
			execJS($('bodyWindows'));
		},
		onFailure: function(t) {
			$('bodyWindows').innerHTML = t.status;
		}
	};
	new Ajax.Request(urls,opt);
}


function searchDataNext(host,imgloc){
	var opt	= {
		method: 'get',
		onLoading: function (t) {
			$('toolBarIcon').innerHTML = '';
			$('dataPage').innerHTML = '';
			$('griddiv').innerHTML = '<table border="0" width="100%" height="100"><tr valign="middle" align="center"><td align="center"><img src="'+imgloc+'" border="0"><br>Loading Page ...</td></tr></table>';
		},
		onSuccess: function(t) {
			$('griddiv').innerHTML = t.responseText;
			execJS($('griddiv'));
		},
		onFailure: function(t) {
			$('griddiv').innerHTML = t.status;
		}
	};
	new Ajax.Request(host,opt);
}

function blocking(nr,st){
	if (st == 'on'){
		current = 'block';
	}
	else{
		current = 'none';
	}
	if (document.layers)
	{
//		current = (document.layers[nr].display == 'none') ? 'block' : 'none';
		document.layers[nr].display = current;
	}
	else if (document.all)
	{
//		current = (document.all[nr].style.display == 'none') ? 'block' : 'none';
		document.all[nr].style.display = current;
	}
	else if (document.getElementById)
	{
//		current = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
		document.getElementById(nr).style.display = current;
	}
}
function getDl(urlGet) {
	window.location=urlGet;
	clearInterval(intervals);
}
function submitAddUser(host,docGet){
	var username = MM_findObj('username', docGet.document).value;
	var admstatus = MM_findObj('access', docGet.document).value;
	var opt	= {
		method: 'post',
		parameters: 'username='+username+'&status='+admstatus, 
		onLoading: function(t) {
			$('Submit').value = 'Loading';
			$('Submit').enable = false;
		},
		onComplete: function(t) {
			window.close();
		},
		onFailure: function(t) {
			$('divajax').innerHTML = t.status;
		}
	};
	new Ajax.Request(host+'usermanage.php',opt);
}
function ajaxRequestGet(urls,objSel,msgWait,errMsg){
	msgWait = msgWait || 'Wait.....';
	errMsg = errMsg || 'Error Request';
	var opt	= {
		method: 'get',
		onLoading: function(t) {
			$(objSel).innerHTML = msgWait;
		},
		onComplete: function(t) {
			$(objSel).innerHTML = t.responseText;
			execJS($(objSel));
		},
		onFailure: function(t) {
			$(objSel).innerHTML = t.status;
		}
	};
	new Ajax.Request(urls,opt);
}

function checkLoginAjax(host,formserialze,imgloc){
	var username = '';
	var password = '';
	var nextid = '';
	var nextjenis = '';
	var nextstinput = '';
	if ($('usernamefield')){ username = '&usernamefield='+$('usernamefield').value; }
	if ($('passwordfield')){ password = '&passwordfield='+$('passwordfield').value; }
	if ($('nextid')){ nextid = '&nextid='+$('nextid').value; }
	if ($('nextjenis')){ nextjenis = '&nextjenis='+$('nextjenis').value; }
	if ($('nextstinput')){ nextstinput = '&nextstinput='+$('nextstinput').value; }
	var opt	= {
		method: 'get',
		parameters: 't=script&id=login&'+username+password+nextid+nextjenis+nextstinput, 
		onComplete: function(t) {
			$('login').innerHTML = t.responseText;
			execJS($('login'));
		},
		onFailure: function(t) {
			$('login').innerHTML = t.status;
		}
	};
	new Ajax.Request(host,opt);
}

function questLogout(urlNext,txtQuest){
	if (confirm(txtQuest)) {
		var opt	= {
			method: 'get',
			onComplete: function(t) {
				$('login').innerHTML = t.responseText;
				execJS($('login'));
			},
			onFailure: function(t) {
				$('login').innerHTML = t.status;
			}
		};
		new Ajax.Request(urlNext,opt);
	}	
}

function showPageX(ids, urls)
{	$(ids).innerHTML = '<table><tr><td><img src="/images/loading.gif"></td><td>Tunggu..</td></tr></table>';
	var opt	= 
		{	method: 'get',
			onComplete: function(t) 
			{	$(ids).innerHTML = t.responseText;
				execJS($(ids));
			},
			onFailure: function(t) 
			{	$(ids).innerHTML = t.status;
			}
		};
	new Ajax.Request(urls, opt);
}

function execRoadShow(aId, aDesc)
{	
	if (aDesc == null)
	{	
		$('idApp').innerHTML = '<table><tr><td><img src="/images/loading.gif"></td><td>Tunggu..</td></tr></table>';
		var opt	= 
		{	
			method: 'get',
			onComplete: function(t) 
			{	
				$('idApp').innerHTML = t.responseText;
				appX.url = 'http://' + document.location.host + '/scripts/padati.dll/download?id=slide/roadshow/data/' + aId + '.ini';
				appX.ExecApp;
			},
			onFailure: function(t) 
			{	
				$('idApp').innerHTML = t.status;
			}
		};
		new Ajax.Request( 'http://' + document.location.host + '?t=page&id=roadshow.script&header=off', opt);
	}
}

function changePass(stGet,urlroot,urlnext){
	if (!stGet) stGet='open';
	nm = "addUser";
	atts = "noresizable,scrollbars";
	w = 400; 
	h = 250;
	x = (typeof x=="number")? x: window.opera? 100: Math.round( (screen.availWidth - w)/2 );
	y = (typeof y=="number")? y: window.opera? 20: Math.round( (screen.availHeight - h)/2 );
	atts += ',width='+w+',height='+h+',left='+x+',top='+y;
	var win = window.open('', nm, atts); 
	if (stGet == 'closed'){
		if (win) {
			if (!win.closed) { 
				win.focus();
				win.close();
				alert('Password Anda Telah Di ganti');
			}
		}
	}
	else{
		if (win) {
			if (!win.closed) { 
				if (win.document.getElementById('ErrMsg')){
					win.close();
					changePass();
				}
				win.resizeTo(w,h); 
				win.moveTo(x,y);
				win.focus();
				win.document.write('<html><head><title>GantiPassword</title><style type="text/css"><!-- body { font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #EFEFEF; color:#333333; } table { font-family: Arial, Helvetica, sans-serif; font-size: 12px; color:#333333; } --></style></head><body><form id="passChange" name="passChange" method="GET" onSubmit="javascript: test(); return false;"><div id="ErrMsg" style="color: #FF0000;"></div><table width="100%"  border="0" cellspacing="0" cellpadding="0"><tr><td width="150">Password Lama </td><td width="20" align="center">:</td><td><input name="oldpass" type="password" id="oldpass" size="25"></td></tr><tr><td width="150">&nbsp;</td><td width="20" align="center">&nbsp;</td><td>&nbsp;</td></tr><tr><td width="150">Password Baru </td><td width="20" align="center">:</td><td><input name="newpass" type="password" id="newpass" size="25"></td></tr><tr><td width="150">&nbsp;</td><td width="20" align="center">&nbsp;</td><td>&nbsp;</td></tr><tr><td width="150">Ulang Password Baru </td><td width="20" align="center">:</td><td><input name="newpass1" type="password" id="newpass1" size="25"></td></tr><tr><td width="150">&nbsp;</td><td width="20" align="center">&nbsp;</td><td>&nbsp;</td></tr><tr><td width="150">&nbsp;</td><td width="20" align="center">&nbsp;</td><td><input type="submit" id="Submit" name="Submit" value="Submit"></td></tr></table></form><script>document.getElementById(\'oldpass\').focus();  function test(){ var objX = document.getElementById(\'ErrMsg\'); var x1 = document.forms[0].oldpass.value; var x2 = document.forms[0].newpass.value; var x3 = document.forms[0].newpass1.value; if (x1 == \'\'){ objX.innerHTML = \'Password Lama Masih Kosong\'; document.forms[0].oldpass.focus(); } else if (x2 == \'\'){ objX.innerHTML = \'Password Baru Masih Kosong\'; document.forms[0].newpass.focus(); } else if (x3 == \'\'){ objX.innerHTML = \'Ulang Password Baru Masih Kosong\'; document.forms[0].newpass1.focus(); } else{ if (x2 != x3){ objX.innerHTML = \'Password Ulang Password Baru Tidak Sama \'+x2+\' \'+x3; document.forms[0].newpass.focus(); } else{ requestServer(); } } }  function requestServer(){ document.getElementById(\'Submit\').value = \'Loading ...\';  try { req = new XMLHttpRequest(); /* e.g. Firefox */  }  catch(e) {  try {  req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */  }  catch (e) {  try {  req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */  }  catch (E) {  req = false;  }   }   }  req.onreadystatechange = function() {  responseAHAH(\'Password Lama Salah\');  };  req.open("GET",\''+urlroot+'?t=script&id=changepass&oldpass=\'+document.forms[0].oldpass.value+\'&newpass=\'+document.forms[0].newpass.value,true);  req.send(null);  } function responseAHAH(errorMessage) {  var output = \'\';  var objX = document.getElementById(\'ErrMsg\');  if(req.readyState == 4) {  if(req.status == 200) {  output = req.responseText;  if (output == \'ok\'){  opener.changePass(\'closed\'); opener.location.href="'+urlnext+'";  }  else {  objX.innerHTML = errorMessage; document.getElementById(\'Submit\').value = \'Submit\';  }  }  else {  objX.innerHTML = \'Error Request\';  document.getElementById(\'Submit\').value = \'Submit\';  }  }  } <\/script></body></html>');
				win.document.writeln();
				return true;
			}
		} 
	}
}

function formRequest(urlReq,paramsGet,methodGet,valueTrue){
	var opt	= {
		method: methodGet, 
		parameters: paramsGet, 
		onComplete: function(t) {
			if (t.responseText == valueTrue){
				document.location.reload();
			}
		}
	};
	new Ajax.Request(urlReq,opt);
}
