// JavaScript Document
//DON'T EDIT THE CODES BELOW IF YOU DONT UNDERSTAND WHAT CODES DO.
//Author: Djono Amidjojo, 16 August 2008
//Email: djonoamidjojo@hotmail.com
function movepic(img_name,img_src) {
	document[img_name].src=img_src;
}

function decimalCurrency(txt) {
	regExp = /^[0-9]+(\.[0-9]+)*$/;
	return regExp.test(txt.value);
}

function numeric(txt){
    var flag=true;
    for(i=0;txt.value.length>i;i++){
        code=txt.value.charCodeAt(i);
        if (( (code>=48) && (code<=57) ) || (code == 45) || (code == 43))
            flag=true
        else {
            flag=false;
            break;
        }
    }
    return flag;
}

function clearAll() {
	document.forms[0].reset('');
}

function printPage(page) {
	if (page.print) {
		page.print() ;
	} else {
    	var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		page.document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
		WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";
	}
}
function checkEmail(emailStr) {
        // checks if the e-mail address is valid
	var emailPat = /^(([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)*(\.[a-zA-Z]+))$/;
    if (emailPat.test(emailStr)) {
       	return true;
    } else {
		return false;
	}
}
function frmAddHide () {
		//document.getElementById("txtType").style.visibility="hidden";
		document.getElementById("layerForm").style.visibility="hidden";
		document.getElementById("layerFormLoc").style.visibility = "hidden";
		document.getElementById("tblCompStruct").focus();
}

function frmEditHide () {
		//document.getElementById("txtType").style.visibility="hidden";
	document.getElementById("layerEditForm").style.visibility="hidden";
	document.getElementById("layerFormLoc").style.visibility = "hidden";
}

function commaSplit(srcNumber,JumDigit) {
	var txtNumber = '' + srcNumber;
	if (isNaN(txtNumber)) {
		txtNumber=replaceString(",",".",txtNumber);
	}
	var arrNumber = txtNumber.split('.');
	if(isNaN(arrNumber[1])){
		txtNumber+='.000';	
		arrNumber = txtNumber.split('.');
	}
	if(arrNumber[1].length>0 && arrNumber[1].length<JumDigit){
		do {
			txtNumber += '0';
			arrNumber = txtNumber.split('.');
		} while (arrNumber[1].length<JumDigit);
	}
	if(arrNumber[1].length>JumDigit){ txtNumber=formatDecimal(txtNumber,JumDigit); }
	return txtNumber;
}

function replaceString(oldS,newS,fullS) {
   for (var i=0; i<fullS.length; i++) {
      if (fullS.substring(i,i+oldS.length) == oldS) {
         fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length)
      }
   }
   return fullS;
} 
function formatDecimal(number,X) {
	X = (!X ? 2 : X);
	return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function formatUang(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num);
}

function isNumber(elem) {
    var str = elem.value;
    var re = /^[-]?\d*\.?\d*$/;
    str = str.toString( );
    if (!str.match(re)) {
        alert("Hanya boleh angka.");
        return false;
    }
    return true;
}

function isEMailAddr(elem) {
    var str = elem.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        alert("Format email Salah. Coba ulangi lagi.");
		elem.value="";
		//elem.focus();
        return false;
    } else {
        return true;
    }
}

function HanyaAngka(evt) { //angka only
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
    if ((charCode >= 37 && charCode <=40) || (charCode >= 48 && charCode < 58) || charCode==190 || charCode==8 || charCode==9 || charCode==13) {//tanda panah,tab,backspace,del dan enter boleh
        return true;
    } else {
        return false;
    }
}

function Konfirmasi(pesan){
	if (confirm(pesan)){ return true; }
	else { return false; }
}

function Konfirmasi2(pesan,nilai){
	if(nilai==0){ alert("Maaf, tidak dapat diproses."); return false; }
	if (confirm(pesan+nilai+" ?")){ return true; }
	else { return false; }
}
function Konfirmasi2a(pesan,nilai){
	nilai++;
	if (confirm(pesan+nilai+" ?")){ return true; }
	else { return false; }
}
function Konfirmasi2b(pesan,nilai){
	if(nilai==0 || nilai==1){ alert("Maaf, tidak dapat diproses."); return false; }
	if (confirm(pesan+nilai+" ?")){ return true; }
	else { return false; }
}

function Konfirmasi3(pesan,Formapa){
	if (confirm(pesan)){ 
		CompleteBack(Formapa);
		return true; 
	}
	else { return false; }
}

function CekForm(Formapa){
	var tempobj;
	for (i=0;i<Formapa.length;i++) {
		tempobj=Formapa.elements[i];
		if ((tempobj.type=="text" ||tempobj.type=="textarea" || tempobj.type=="password") && tempobj.value=='' && tempobj.name !="txtsearch"){
			pass=false;
			break;
		} else { pass=true; }
	}
	if (!pass) {
		shortFieldName=tempobj.id.toUpperCase();
		alert("Maaf! '"+shortFieldName+"' belum terisi. Proses tidak dapat dilanjutkan.");
		return false;
	}
	else { return true; }
}
function CekForm2(Formapa){
	var tempobj;
	for (i=0;i<Formapa.length;i++) {
		tempobj=Formapa.elements[i];
		if ((tempobj.name=="text" ||tempobj.type=="textarea" || tempobj.type=="password") && tempobj.value=='' && tempobj.name !="txtsearch"){
			pass=false;
			break;
		} else { pass=true; }
	}
	if (!pass) {
		shortFieldName=tempobj.name.toUpperCase();
		alert("Maaf! Data "+shortFieldName+" belum terisi. Proses tidak dapat dilanjutkan.");
		return false;
	}
	else { return true; }
}
function CompleteBack(Formapa){
	var tempobj;
	for (i=0;i<Formapa.length;i++) {
		tempobj=Formapa.elements[i];
		if ((tempobj.type=="text" || tempobj.type=="textarea") && tempobj.value==''){
			tempobj.value='0'
		}
	}
}
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=0,width=640,height=480');");
}
function popUp2(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=640,height=480');");
}

function CariInvo(noinvo,url){
	if(!url){
		popUp('preview.php?inv='+noinvo);
	} else {
		popUp('../preview.php?inv='+noinvo);
	}
}

function NewWin (locs, name, winwidth, winheight, wintop, winleft, scrollskah, resizekah, titlekah, statuskah)
{	
	extra = '';
	extra = extra + 'width=' + winwidth;
	extra = extra + ', height=' + winheight;
	extra = extra + ', top=' + wintop;
	extra = extra + ', left=' + winleft;
	extra = extra + ', scrollbars=' + scrollskah;
	extra = extra + ', resizable=' + resizekah;
	extra = extra + ', titlebar=' + titlekah;	
	extra = extra + ', status=' + statuskah;	
	window.open (locs, name, extra);
}
