// JavaScript Document
//var portcounter=1;
var time = 1000;
var numofitems = 4;

//menu constructor
function menu(allitems,thisitem,startstate){ 
  callname= "gl"+thisitem;
  divname="subglobal"+thisitem;  
  this.numberofmenuitems = allitems;
  this.caller = document.getElementById(callname);
  this.thediv = document.getElementById(divname);
  this.thediv.style.visibility = startstate;
}

function konfirmasi(filenya,aksinya) {
	var konfirm = window.confirm('Apakah '+filenya+' ini akan dihapus ?');
	if(konfirm) { 
		location.href='?action=delFile&file='+filenya+'&aksi='+aksinya;
		return true; 
	} else { 
		return false; 
	}
}

//menu methods
function ehandler(event,theobj){
  for (var i=1; i<= theobj.numberofmenuitems; i++){
    var shutdiv =eval( "menuitem"+i+".thediv");
    shutdiv.style.visibility="hidden";
  }
  theobj.thediv.style.visibility="visible";
}
				
function closesubnav(event){
  if ((event.clientY <48)||(event.clientY > 107)){
    for (var i=1; i<= numofitems; i++){
      var shutdiv =eval('menuitem'+i+'.thediv');
      shutdiv.style.visibility='hidden';
    }
  }
}

// batas function menu

function movein_menu(which,html){
which.style.background='#EDECED';
//which.style.cursor='hand';
}

function movein_x(which,html){
which.style.background='#DAE9FE';
}

function moveout_x(which,html){
which.style.background='#f3f3f3';
//which.style.cursor=''
}

function moveout_menu(which){
which.style.background=''
}

// digunakan untuk pop-up
function openWindow(url, width, height) { 	
	popupWin = window.open(url, 'new_page', width, height)
} 

function rightClick(rButton) {
	var msg = "Copyright © 2008 - Tim Persiapan Indonesia National Single Window.\nAll rights reserveds.";
	if (navigator.appName == 'Netscape' && rButton.which == 3) {
		alert(msg);
		return false;
	}
	else if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
		alert(msg);
		return false;
	}
	return true;
}
document.onmousedown = rightClick;

function about(){
	var msg = "Copyright © 2008 PT EDI Indonesia.\nAll rights reserveds.";
	alert(msg);
}

var comoditycounter=1;
function addrow_country()
{
	var crows=document.getElementById('country').rows.length-1;
	var x=document.getElementById('country').insertRow(crows);
	var cell1=x.insertCell(0);	
	var cell2=x.insertCell(1);
	var cell3=x.insertCell(2);
	var cell4=x.insertCell(3);
	cell1.align = 'left';
	cell2.align = 'left';
	cell3.align = 'left';
	cell4.align = 'left';
	crox=crows;
	cell1.innerHTML='';
	cell2.innerHTML='Negara '+crox;	
	cell3.innerHTML=':';		
	cell4.innerHTML='<input type="text" name="country'+crows+'" maxlength="2" size="5"> <input onClick="javascript:window.open(\'FormSearch.php?task=negara&amp;frm=webform&amp;colm=country'+crows+';ur_country'+crows+'\',\'_blank\',\'width=700,height=500,top=150,left=150,toolbar=no,minimize=no,status=no,menubar=no,location=no,scrollbars=yes\',\'1\')" type="button" value="..."> ';
	cell4.innerHTML+=' <input name="Delete" type="button" id="Delete" style="color: #FFFFFF;background-color: #FF6600" value="Hapus" onClick="delrow_country('+crows+')"> <input type="text" name="ur_country'+crows+'" size="25" style="border:none">';
}

function delrow_country(rowIndex)
{if(confirm("Hapus negara "+rowIndex+" ini?"))
 {
  document.getElementById('country').deleteRow(rowIndex);
  //untuk menata ulang index
  var therow=document.getElementById('country').rows;
  var crows=document.getElementById('country').rows.length-1;  
  for(i=1;i<crows;i++)
  { thecol=therow[i].cells;
  	thecol[1].innerHTML='Negara '+i;
  }
 }
}

//insert
function addrow_country2()
{
	var crows=document.getElementById('country').rows.length-2;
	
	var x=document.getElementById('country').insertRow(document.getElementById('country').rows.length-1);
	var cell1=x.insertCell(0);	
	var cell2=x.insertCell(1);
	var cell3=x.insertCell(2);
	var cell4=x.insertCell(3);
	cell1.align = 'left';
	cell2.align = 'left';
	cell3.align = 'left';
	cell4.align = 'left';
	crox=crows+1;
	cell1.innerHTML='';
	cell2.innerHTML='Negara '+crox;	
	cell3.innerHTML=':';		
	cell4.innerHTML='<input type="text" name="country'+crows+'" maxlength="2" size="5"> <input onClick="javascript:window.open(\'FormSearch.php?task=negara&amp;frm=webform&amp;colm=country'+crows+';ur_country'+crows+'\',\'_blank\',\'width=700,height=500,top=150,left=150,toolbar=no,minimize=no,status=no,menubar=no,location=no,scrollbars=yes\',\'1\')" type="button" value="..."> ';
	cell4.innerHTML+=' <input name="Delete" type="button" id="Delete" style="color: #FFFFFF;background-color: #FF6600" value="Hapus" onClick="delrow_country2('+crows+')"> <input type="text" name="ur_country'+crows+'" size="25" style="border:none">';
}

function delrow_country2(rowIndex)
{
var norow = rowIndex+1;
if(confirm("Hapus negara "+norow+" ini?"))
 {
  document.getElementById('country').deleteRow(norow);
  //untuk menata ulang index
  var therow=document.getElementById('country').rows;
  var crows=document.getElementById('country').rows.length-2;  
  for(i=0;i<crows;i++)
  { thecol=therow[i].cells;
  	thecol[1].innerHTML='Negara '+i;
  }
 }
}


function addrow_port2(portname, porttype)
{
	var crows=document.getElementById('port').rows.length-3;
	
	var x=document.getElementById('port').insertRow(crows+1);
	
	var cell1=x.insertCell(0);	
	var cell2=x.insertCell(1);
	var cell3=x.insertCell(2);
	var cell4=x.insertCell(3);	
	cell1.align = 'right';
	cell2.align = 'left';
	cell3.align = 'left';
	cell4.align = 'left';
	crows2=(crows+2)/2;
	portcounter=crows2;
//	portcounter++;
	cell1.innerHTML=portcounter+'.';
	cell2.innerHTML='Jenis ';	
	cell3.innerHTML=':';		
	cell4.innerHTML='<select name="porttype'+crows+'"><option value=""></option><option value="1">Muat</option><option value="2">Bongkar</option><option value="3">Transit</option></select>';

	x=document.getElementById('port').insertRow(crows+2);
	
	cell1=x.insertCell(0);	
	cell2=x.insertCell(1);
	cell3=x.insertCell(2);
	cell4=x.insertCell(3);	
	cell2.align = 'left';
	cell3.align = 'left';
	cell4.align = 'left';
	crox=crows;
	crows_1=crows-1;
	cell1.innerHTML='';
	cell2.innerHTML='Nama ';	
	cell3.innerHTML=':';		
	cell4.innerHTML='<input type=text name="portname'+crows+'" maxlength="5" size="5" > <input onClick="javascript:window.open(\'FormSearch.php?task=pelabuhan&amp;frm=webform&amp;colm=portname'+crows+';ur_portname'+crows+'\',\'_blank\',\'width=700,height=500,top=150,left=150,toolbar=no,minimize=no,status=no,menubar=no,location=no,scrollbars=yes\',\'1\')" type="button" value="..."> ';	
	
	cell4.innerHTML+=' <input name="Delete" type="button" id="Delete" style="color: #FFFFFF;background-color: #FF6600" value="Hapus" onClick="delrow_port2('+crows+')"> <input type=text name="ur_portname'+crows+'" size="25" style="border:none">';
}

function delrow_port2(rowIndex)
{
	var norow = rowIndex+1;
	if(confirm("Hapus kelompok data ini?"))
 {
  document.getElementById('port').deleteRow(norow);
  document.getElementById('port').deleteRow(norow);  
  //untuk menata ulang index
  var number=1;
  var therow=document.getElementById('port').rows;
  var crows=document.getElementById('port').rows.length-3;  
  
  for(i=1;i<crows;i+=2)
  { 
  	
  	thecol=therow[i].cells;
  	thecol[0].align='right';
  	thecol[0].innerHTML=''+number+'.';
	number++;
  }
 }
}

//


function addrow_port(portname, porttype)
{
	var crows=document.getElementById('port').rows.length-2;
	var x=document.getElementById('port').insertRow(crows);
	var cell1=x.insertCell(0);	
	var cell2=x.insertCell(1);
	var cell3=x.insertCell(2);
	var cell4=x.insertCell(3);	
	cell1.align = 'right';
	cell2.align = 'left';
	cell3.align = 'left';
	cell4.align = 'left';
	crows2=(crows+1)/2;
	portcounter=crows2;
//	portcounter++;
	cell1.innerHTML=portcounter+'.';
	cell2.innerHTML='Jenis ';	
	cell3.innerHTML=':';		
	cell4.innerHTML='<select name="porttype'+crows+'"><option value=""></option><option value="1">Muat</option><option value="2">Bongkar</option><option value="3">Transit</option></select>';

	x=document.getElementById('port').insertRow(crows+1);
	cell1=x.insertCell(0);	
	cell2=x.insertCell(1);
	cell3=x.insertCell(2);
	cell4=x.insertCell(3);	
	cell2.align = 'left';
	cell3.align = 'left';
	cell4.align = 'left';
	crox=crows;
	crows_1=crows-1;
	cell1.innerHTML='';
	cell2.innerHTML='Nama ';	
	cell3.innerHTML=':';		
	cell4.innerHTML='<input type=text name="portname'+crows+'" maxlength="5" size="5"> <input onClick="javascript:window.open(\'FormSearch.php?task=pelabuhan&amp;frm=webform&amp;colm=portname'+crows+';ur_portname'+crows+'\',\'_blank\',\'width=700,height=500,top=150,left=150,toolbar=no,minimize=no,status=no,menubar=no,location=no,scrollbars=yes\',\'1\')" type="button" value="..."> ';	
	
	cell4.innerHTML+=' <input name="Delete" type="button" id="Delete" style="color: #FFFFFF;background-color: #FF6600" value="Hapus" onClick="delrow_port('+crows+')"> <input type=text name="ur_portname'+crows+'" size="25" style="border:none">';
}

function delrow_port(rowIndex)
{if(confirm("Hapus kelompok data ini?"))
 {
  document.getElementById('port').deleteRow(rowIndex);
  document.getElementById('port').deleteRow(rowIndex);  
  //untuk menata ulang index
  var number=1;
  var therow=document.getElementById('port').rows;
  var crows=document.getElementById('port').rows.length-2;  
  for(i=1;i<crows;i+=2)
  { 
  	
  	thecol=therow[i].cells;
  	thecol[0].align='right';
  	thecol[0].innerHTML=''+number+'.';
	number++;
  }
 }
}

function addrow_comodity(nohs,produk,stocktype,amount,unit,productnote)
{
	var crows=document.getElementById('comodity').rows.length-3;
	var x=document.getElementById('comodity').insertRow(crows);
	var cell1=x.insertCell(0);	
	var cell2=x.insertCell(1);
	var cell3=x.insertCell(2);
	var cell4=x.insertCell(3);	
	crox=crows;	
	cell1.align = 'right';
	cell2.align = 'left';
	cell3.align = 'left';
	cell4.align = 'left';
	comoditycounter++;
	cell1.innerHTML=comoditycounter+'.';
	cell2.innerHTML='Nomor HS ';	
	cell3.innerHTML=':';		
	cell4.innerHTML='<input type=text name="nohs'+crox+'" maxlength="12" size="12"> <input onClick="javascript:window.open(\'FormSearch.php?task=noHS&amp;frm=webform&amp;colm=nohs'+crox+';produk'+crox+'\',\'_blank\',\'width=700,height=500,top=150,left=150,toolbar=no,minimize=no,status=no,menubar=no,location=no,scrollbars=yes\',\'1\')" type="button" name="Submit22" value="..." />';

	x=document.getElementById('comodity').insertRow(++crox);
	cell1=x.insertCell(0);	
	cell2=x.insertCell(1);
	cell3=x.insertCell(2);
	cell4=x.insertCell(3);
	crox11=crox-1;
	cell2.align = 'left';
	cell3.align = 'left';
	cell4.align = 'left';
	cell1.innerHTML='';
	cell2.innerHTML='Produk ';	
	cell3.innerHTML=':';		
	cell4.innerHTML='<textarea name="produk'+crox11+'" cols="50" rows="2"></textarea>';
	
	x=document.getElementById('comodity').insertRow(++crox);
	cell1=x.insertCell(0);	
	cell2=x.insertCell(1);
	cell3=x.insertCell(2);
	cell4=x.insertCell(3);
	crox2=crox-2;
	cell2.align = 'left';
	cell3.align = 'left';
	cell4.align = 'left';
	cell1.innerHTML='';
	cell2.innerHTML='Sediaan ';	
	cell3.innerHTML=':';		
	cell4.innerHTML='<input type=text name="stocktype'+crox2+'"  maxlength="25">';
		
	x=document.getElementById('comodity').insertRow(++crox);
	cell1=x.insertCell(0);	
	cell2=x.insertCell(1);
	cell3=x.insertCell(2);
	cell4=x.insertCell(3);	
	crox3=crox-3;
	cell2.align = 'left';
	cell3.align = 'left';
	cell4.align = 'left';
	cell1.innerHTML='';
	cell2.innerHTML='Jumlah ';	
	cell3.innerHTML=':';		
	cell4.innerHTML='<input type=text name="amount'+crox3+'" maxlength="10" size="10"><i>* gunakan tanda titik (.) untuk decimal</i>';
		
	x=document.getElementById('comodity').insertRow(++crox);
	cell1=x.insertCell(0);	
	cell2=x.insertCell(1);
	cell3=x.insertCell(2);
	cell4=x.insertCell(3);	
	crox4=crox-4;
	cell2.align = 'left';
	cell3.align = 'left';
	cell4.align = 'left';
	cell1.innerHTML='';
	cell2.innerHTML='Satuan ';	
	cell3.innerHTML=':';		
	cell4.innerHTML='<input type=text name="unit'+crox4+'" id="unit'+crox4+'" maxlength="3" size="5" onkeyup="showHint(this.value, this.id, 1);"> <input onClick="javascript:window.open(\'FormSearch.php?task=satuan&amp;frm=webform&amp;colm=unit'+crox4+';ur_unit'+crox4+'\',\'_blank\',\'width=700,height=500,top=150,left=150,toolbar=no,minimize=no,status=no,menubar=no,location=no,scrollbars=yes\',\'1\')" type="button" name="Submit22" value="..." /> <input type=text name="ur_unit'+crox4+'" id="ur_unit'+crox4+'" size="25" style="border:none">';
	
	x=document.getElementById('comodity').insertRow(++crox);
	cell1=x.insertCell(0);	
	cell2=x.insertCell(1);
	cell3=x.insertCell(2);
	cell4=x.insertCell(3);	
	crox5=crox-5;
	cell2.align = 'left';
	cell3.align = 'left';
	cell4.align = 'left';
	cell1.innerHTML='';
	cell2.innerHTML='';	
	cell3.innerHTML='';		
	cell4.innerHTML='<span id="returnunit'+crox4+'" style="font-size:10px"></span>';
	
	x=document.getElementById('comodity').insertRow(++crox);
	cell1=x.insertCell(0);	
	cell2=x.insertCell(1);
	cell3=x.insertCell(2);
	cell4=x.insertCell(3);	
	crox6=crox-6;
	cell2.align = 'left';
	cell3.align = 'left';
	cell4.align = 'left';
	cell1.innerHTML='';
	cell2.innerHTML='Catatan ';	
	cell3.innerHTML=':';		
	cell4.innerHTML='<textarea name="productnote'+crox5+'" cols="50" rows="2"></textarea>';
		
	cell4.innerHTML+=' <input name="Delete" type="button" id="Delete" style="color: #FFFFFF;background-color: #FF6600" value="Hapus" onClick="delrow_comodity('+crows+')">';
}

function delrow_comodity(rowIndex)
{if(confirm("Hapus kelompok data ini?"))
 {
  comoditycounter--;
  document.getElementById('comodity').deleteRow(rowIndex);
  document.getElementById('comodity').deleteRow(rowIndex);  
  document.getElementById('comodity').deleteRow(rowIndex);
  document.getElementById('comodity').deleteRow(rowIndex);  
  document.getElementById('comodity').deleteRow(rowIndex);
  document.getElementById('comodity').deleteRow(rowIndex);  
  document.getElementById('comodity').deleteRow(rowIndex);  
  
  //untuk menata ulang index
  var number=1;
  var therow=document.getElementById('comodity').rows;
  var crows=document.getElementById('comodity').rows.length-7;  
  for(i=1;i<crows;i+=7)
  {   	
  	thecol=therow[i].cells;
  	thecol[0].align='right';
  	thecol[0].innerHTML=''+number+'.';
	number++;
  }
 }
}



function delrow_comodityEDIT(rowIndex,nohs,seri)
{if(confirm("Hapus kelompok data ini?"))
	 {
	  comoditycounter--;
	  document.getElementById('comodity').deleteRow(rowIndex);
	  document.getElementById('comodity').deleteRow(rowIndex);  
	  document.getElementById('comodity').deleteRow(rowIndex);
	  document.getElementById('comodity').deleteRow(rowIndex);  
	  document.getElementById('comodity').deleteRow(rowIndex);
	  document.getElementById('comodity').deleteRow(rowIndex);  
	  document.getElementById('comodity').deleteRow(rowIndex);  
	  
	  //untuk menata ulang index
	  var number=1;
	  var therow=document.getElementById('comodity').rows;
	  var crows=document.getElementById('comodity').rows.length-7;  
	  for(i=1;i<crows;i+=7)
	  {   	
		thecol=therow[i].cells;
		thecol[0].align='right';
		thecol[0].innerHTML=''+number+'.';
		number++;
	  }
	  /*op=input&act=edit
	  location.href='?op=input&act=edit&aksi=delKmdt&nohs='+nohs+'&seri='+seri;*/
	  $.post('PostUpdateChannel.php?nohs='+nohs+'&seri='+seri, 'data=', function(response){
		if(response=="success")
			$("#console").html('<div></div>').hide().fadeIn(1000);
		setTimeout(function(){
			$('#console').fadeOut(1000);
		}, 2000);
		});
	 }
}
