//fungsi handle xml
function createRequestObject() {
    var ro;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         ro = new XMLHttpRequest();
         if (ro.overrideMimeType) {
            ro.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            ro = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               ro = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
    return ro;
}

//inisial http
var http = createRequestObject();

//fungsi form get
function kirim(action,kode) {
    isi=kode;
    http.open('get', action);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

//fungsi hande respon
function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
            document.getElementById(isi).innerHTML = response;
    } else {
      document.getElementById(isi).innerHTML = 'Loading...';
    }
}
//fungsi form post
function kirim_post(url,form_kirim,bagi) {
      isi=bagi;
      parameters = siap_kirim(form_kirim);
      http.onreadystatechange = handleResponse;
      http.open('POST', url, true);
      http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http.setRequestHeader("Content-length", parameters.length);
      http.setRequestHeader("Connection", "close");
      http.send(parameters);
}

//fungsi membuat siap post
function siap_kirim(id_form) {
    var txt='';
    for (var i = 0; i < document.getElementById(id_form).elements.length; i++) {
    txt +=document.getElementById(id_form).elements[i].name+'='+encodeURI(document.getElementById(id_form).elements[i].value)+'&';
    }
  return txt;
}

//fungsi form cek all
checked = false;
function centang(isinya) {
  if (checked == false){checked = true}else{checked = false}
    for (var i = 0; i < document.getElementById(isinya).elements.length; i++) {
    document.getElementById(isinya).elements[i].checked = checked;   
    }
}
/*
function cek() {
var target='admin_form';
  bag=Array('nama','');
  psn=Array('judul','pengirim');
  for (i=0;i<bag.length;i++) {
    var cek=eval('document.'+target+'.'+bag[i]);
      if (cek.value=='') {
      alert(psn[i]+' harus diisi');
      cek.focus();
      return false;
      }
  }
}
*/
function IsNumeric(sText,cek){
   		var ValidChars = "0123456789.";
   		var IsNumber=true;
   		var Char;
   		for (i = 0; i < sText.length && IsNumber == true; i++){
      		Char = sText.charAt(i);
     		 if (ValidChars.indexOf(Char) == -1){
            cek.value='';
        		IsNumber = false;
			}
      	}
  		return IsNumber;
	}

function email_cek (emailStr) {
var emailPat=/^(.+)@(.+)\.(.+)$/;
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
alert("Alamat Email Salah.(check @ and .'s)");
return false;
}
return true;
}

function hapus() {
return confirm('Anda yakin ingin menghapus data ini?');
}


function mouse_over(id, bg){
	row = eval('document.getElementById("row'+id+'")');
	
	row.bgColor = bg;
}

function mouse_out(id){
	var f = document.admin_form;
	cb = eval('f.cb' + id);
	row = eval('document.getElementById("row'+id+'")');
	
	if( cb.checked == true ){
		row.bgColor = '#cbf9f7';
	} else {
		row.bgColor = '#ffffff';
	}
}

function mouse_cek(id) {
	var f = document.admin_form;
	cb = eval('f.cb' + id);
		if( cb.checked == true )  cb.checked=false; else cb.checked=true;
}

function mouse_cek2(ii) {
mouse_cek(ii);
}