// JavaScript Document
function enterFocus(e, idAwal, kd) {
  var keynum;

  if(window.event) // IE
  {
    keynum = e.keyCode;
  }
  else if(e.which) // Netscape/Firefox/Opera
  {
    keynum = e.which;
    if(keynum==13)
    {
      kd++;
      if(kd<=5)
      {
        document.getElementById(idAwal+kd).focus();
      }
      else
      {
        //document.getElementById('nilaihuruf').focus();
        posting_var('op5/user/valcekberkas','1;;'+document.form_2.wil.value+';;'+document.form_2.bidangstudi.value+';;'+document.form_2.input1.value+';;'+document.form_2.input2.value+';;'+document.form_2.input3.value+';;'+document.form_2.input4.value+';;'+document.form_2.input5.value,'valcekberkas');
      }   
      //e.preventDefault();
    }
  }
}

function cekNilai(idAspek, idAwal) {
  var total_aspeka1=0;
  var total_aspeka2=0;
  var total_aspekb1=0;
  var total_aspekb2=0;
  var total_aspekc1=0;
  var total_aspekc2=0;
  var nilaia1_1 =0;
  var nilaia1_2 =0;
  var nilaia2_1 =0;
  var nilaia2_2 =0;
  var nilaib2_1 =0;
  var nilaib2_2 =0;
  
  var ii=0;
  var selisih_aspek;
  
  for(ii=1;ii<=3;ii++) {
    total_aspeka1+=parseInt(document.getElementById(idAwal+1+ii).value);
    total_aspeka2+=parseInt(document.getElementById(idAwal+2+ii).value);
  }
  for(ii=4;ii<=7;ii++) {
    total_aspekb1+=parseInt(document.getElementById(idAwal+1+ii).value);
    total_aspekb2+=parseInt(document.getElementById(idAwal+2+ii).value);
  }
  for(ii=8;ii<=10;ii++) {
    total_aspekc1+=parseInt(document.getElementById(idAwal+1+ii).value);
    total_aspekc2+=parseInt(document.getElementById(idAwal+2+ii).value);
  }
  var total1=total_aspeka1+total_aspekb1+total_aspekc1;
  var total2=total_aspeka2+total_aspekb2+total_aspekc2;
  
  nilaia1_1 =parseInt(document.getElementById(idAwal+1+1).value);
  nilaia1_2 =parseInt(document.getElementById(idAwal+2+1).value);
  nilaia2_1 =parseInt(document.getElementById(idAwal+1+2).value);
  nilaia2_2 =parseInt(document.getElementById(idAwal+2+2).value);
  nilaib2_1 =parseInt(document.getElementById(idAwal+1+5).value);
  nilaib2_2 =parseInt(document.getElementById(idAwal+2+5).value);
  
  //alert(nilaia1_1);
  if(idAspek==1) {
    selisih_aspek=Math.abs(total_aspeka1-total_aspeka2);
    //alert(selisih_aspek);
    if(selisih_aspek>15) {
      document.getElementById('totalAspek1').innerHTML="<td id=\"field\" colspan=\"8\" style=\"color:yellow;font-size:large\">Selisih Total = " + selisih_aspek + " > 15</td><td>" + total_aspeka1 + "</td><td>" + total_aspeka2 + "</td>";
    } else if (nilaia1_1 != nilaia1_2){
    document.getElementById('totalAspek1').innerHTML="<td id=\"field\" colspan=\"10\" style=\"color:yellow;font-size:large\">Nilai skor A1 asesor 1 tidak sama dengan nilai skor A1 asesor 1</td>";  
    } else if (nilaia2_1 != nilaia2_2){
    document.getElementById('totalAspek1').innerHTML="<td id=\"field\" colspan=\"10\" style=\"color:yellow;font-size:large\">Nilai skor A2 asesor 1 tidak sama dengan nilai skor A2 asesor 2</td>";  
    } else {
      document.getElementById('totalAspek1').innerHTML="";
    }
  } else if(idAspek==2) {
    selisih_aspek=Math.abs(total_aspekb1-total_aspekb2);
    if(selisih_aspek>35) {
      document.getElementById('totalAspek2').innerHTML="<td id=\"field\" colspan=\"8\" style=\"color:yellow;font-size:large\">Selisih Total = " + selisih_aspek + " > 35</td><td>" + total_aspekb1 + "</td><td>" + total_aspekb2 + "</td>";
    } else if (nilaib2_1 != nilaib2_2){
    document.getElementById('totalAspek2').innerHTML="<td id=\"field\" colspan=\"10\" style=\"color:yellow;font-size:large\">Nilai skor B2 asesor 1 tidak sama dengan nilai skor B2 asesor 2</td>";  
    } else {
      document.getElementById('totalAspek2').innerHTML="";
    }
  } else if(idAspek==3) {
    selisih_aspek=Math.abs(total_aspekc1-total_aspekc2);
    if(selisih_aspek>20) {
      document.getElementById('totalAspek3').innerHTML="<td id=\"field\" colspan=\"8\" style=\"color:yellow;font-size:large\">Selisih Total = " + selisih_aspek + " > 20</td><td>" + total_aspekc1 + "</td><td>" + total_aspekc2 + "</td>";
    } else {
      document.getElementById('totalAspek3').innerHTML="";
    }
  } else {
  }
  if(total1>=850 && total2<841) {
      document.getElementById('totalSemua').innerHTML="<td id=\"field\" colspan=\"8\" style=\"color:yellow;font-size:large\">Ada perbedaan <b>STATUS KELULUSAN</b> antara Asesor I dengan Asesor II</td><td>" + total1 + " (LULUS)</td><td>" + total2 + " (MPLPG)</td>";
  } else if(total1>=850 && total2<850) {
      document.getElementById('totalSemua').innerHTML="<td id=\"field\" colspan=\"8\" style=\"color:yellow;font-size:large\">Ada perbedaan <b>STATUS KELULUSAN</b> antara Asesor I dengan Asesor II</td><td>" + total1 + " (LULUS)</td><td>" + total2 + " (MS)</td>";
  } else if(total2>=850 && total1<841) {
      document.getElementById('totalSemua').innerHTML="<td id=\"field\" colspan=\"8\" style=\"color:yellow;font-size:large\">Ada perbedaan <b>STATUS KELULUSAN</b> antara Asesor I dengan Asesor II</td><td>" + total1 + " (MPLPG)</td><td>" + total2 + " (LULUS)</td>";
  } else if(total2>=850 && total1<850) {
      document.getElementById('totalSemua').innerHTML="<td id=\"field\" colspan=\"8\" style=\"color:yellow;font-size:large\">Ada perbedaan <b>STATUS KELULUSAN</b> antara Asesor I dengan Asesor II</td><td>" + total1 + " (MS)</td><td>" + total2 + " (LULUS)</td>";
  } else if(total1>=841 && total2<841) {
      document.getElementById('totalSemua').innerHTML="<td id=\"field\" colspan=\"8\" style=\"color:yellow;font-size:large\">Ada perbedaan <b>STATUS KELULUSAN</b> antara Asesor I dengan Asesor II</td><td>" + total1 + " (MS)</td><td>" + total2 + " (MPLPG)</td>";
  } else if(total2>=841 && total1<841) {
      document.getElementById('totalSemua').innerHTML="<td id=\"field\" colspan=\"8\" style=\"color:yellow;font-size:large\">Ada perbedaan <b>STATUS KELULUSAN</b> antara Asesor I dengan Asesor II</td><td>" + total1 + " (MPLPG)</td><td>" + total2 + " (MS)</td>";
  } else {
      document.getElementById('totalSemua').innerHTML="";
  }
}

function ubahSelKabupaten(idProp) {
	var kab=document.getElementsByName('selKabupaten');
	if(idProp.value=='00') {
		for(ii=1;ii<=kab[0].options.length;ii++) {
			document.getElementById(kab[0].options[ii].id).style.display=document.getElementById('0000').style.display;
		}
	} else {
		for(ii=1;ii<=kab[0].options.length;ii++) {
			//alert(kab[0].options[ii].id.substring(0,2));
			if(kab[0].options[ii].id.substring(0,2)==idProp.value) {
				//alert(idProp.value);
				document.getElementById(kab[0].options[ii].id).style.display=document.getElementById('0000').style.display;
				//document.getElementById(kab[0].options[ii].id).style.visibility="visible";
				//document.getElementById(kab[0].options[ii].id).disabled="false";
			} else {
				document.getElementById(kab[0].options[ii].id).style.display="none";
				//document.getElementById(kab[0].options[ii].id).style.visibility="collapse";
				//document.getElementById(kab[0].options[ii].id).disabled="true";
			}
		}
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function setKabupaten(kab) {
  //alert(kab.value);
  if(readCookie('nowKab')!=kab.value) {
    //alert('Belum Set Cookie');
    createCookie('nowKab', kab.value, 1);
  }
}
function setMenteri(menteri) {
  //alert(menteri.value);
  if(readCookie('nowMen')!=menteri.value) {
    //alert('Belum Set Cookie');
    createCookie('nowMen', menteri.value, 1);
  }
}

function setBidangStudi(bidstud) {
  //alert(kab.value);
  if(readCookie('nowBidStud')!=bidstud.value) {
    //alert('Belum Set Cookie');
    createCookie('nowBidStud', bidstud.value, 1);
  }
}

function cekKabupaten(url_lanjut, theData, kodeKabMen, lokasi) {
	//alert(theData.substring(5,9));4;;10026502710685;;02651
  if(kodeKabMen.substring(0,4)!=theData.substring(5,9)) {
		alert(theData.substring(5,9)+':'+kodeKabMen.substring(0,4)+':Portofolio tidak sesuai dengan wilayah');
	} else if (kodeKabMen.substring(5,4)!=theData.substring(13,12)) {
		alert(theData.substring(13,12)+':'+kodeKabMen.substring(5,4)+':Portofolio tidak sesuai dengan Kementeriannya');
	} else{
		posting_var(url_lanjut,theData,lokasi);
  }
}

function ubahCalonC8(calonC8) {
	if(calonC8!='') {
		var nowMen=readCookie('nowMen');
		var nowKab=readCookie('nowKab');
		var nowBidStud=readCookie('nowBidStud');
		var arr=calonC8.split(";;");
		var buf='';
		for(var ii=0;ii<arr.length;ii++) {
			buf+=arr[ii];
			buf+='<br />';
		}
		document.getElementById('daftarCalonC8').innerHTML=buf+'<input type="button" value="Cetak C8+" onclick="posting_var(\'op3/user/valcekberkas\',\'1;;'+nowMen+';;'+nowKab+';;'+nowBidStud+';;'+calonC8+'\',\'validasiberkas\')" class="button" />';
	} else {
		document.getElementById('daftarCalonC8').innerHTML='';
	}
}

function ubahIndentC8(data, place) {
  if(xmlHttp.readyState == 1) {
    setTimeout(ubahIndentC8(data, place), 1000);
  } else {
    setTimeout(posting_var(data,';;',place), 5000);
  }
}

function periodePLPGberubah(periodeId) {
	var kelasPLPG=document.getElementById('kodeKelasPLPG');
	if(periodeId.value=='0000') {
		kelasPLPG.disabled=true;
	} else {
		kelasPLPG.disabled=false;
		kelasPLPG.options[0].selected=true;
		for(ii=1;ii<kelasPLPG.options.length;ii++) {
			//alert(kelasPLPG.options[ii].id.substring(0,2));
			if(kelasPLPG.options[ii].id.substring(0,4)==periodeId.value) {
				document.getElementById(kelasPLPG.options[ii].id).style.display=document.getElementById('akar_kelas').style.display;
			} else {
				document.getElementById(kelasPLPG.options[ii].id).style.display="none";
			}
		}
	}
	document.getElementById('formKelasPLPG').disabled=true;
	document.getElementById('cariKelasPLPGBtn').disabled=true;
}

function kelasPLPGberubah(kelasId) {
	if(kelasId.value=='00000000') {
		document.getElementById('formKelasPLPG').disabled=true;
		document.getElementById('cariKelasPLPGBtn').disabled=true;
	} else {
		document.getElementById('formKelasPLPG').disabled=false;
		document.getElementById('cariKelasPLPGBtn').disabled=false;
	}
}

