// JavaScript Document
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}
function number_only(e) {
    var keynum, keychar, numcheck;
    if(window.event) {
        keynum=e.keyCode;
    } else if(e.which) {
        keynum=e.which;
    }
    keychar = String.fromCharCode(keynum);
    numcheck = /\d/;
    if(numcheck.test(keychar) || keynum==8 || keynum==undefined) return true;
    else return false;
}
function cek_all_checkbox(form) {
    var cek;
    if(form.check_all.checked) {
        cek=true;
    } else {
    cek=false;
    }
    if(form.c_box!=null) {
        if(form.c_box.length==undefined) {
            form.c_box.checked=cek;
        } else {
            for(var i=0; i < form.c_box.length; i++) {
                form.c_box[i].checked=cek;
            }
        }
    }
}
function goto_ref(modul) {
    window.location='?modul='+modul;
}
function create_view(show_element) {
    document.getElementById('menu_content').style.display='none';
    document.getElementById('main_content').style.display='none';
    document.getElementById(show_element).style.display='';
}
function mycback(text) {
    alert(text);
}
function cback(element,text) {
    document.getElementById(element).innerHTML = text;
}
function cback_engine(text) {
    document.getElementById('main_content').innerHTML = text;
    create_view('main_content');
}
function cback_w_msg(msg,text) {
    document.getElementById('main_content').innerHTML = text;
    create_view('main_content');
    alert(msg);
}
function cback_select_engine(sel_input,sel_output,tag_id,tag_desc,preselect_false,preselect_true,text) {
    var res = text.getElementsByTagName('hasil')[0].childNodes[0].nodeValue;
    var arr = new Array();
    var option_len = document.getElementById(sel_output).length;
    var temp_id, temp_desc, result_id, result_desc, preselect;
    if(navigator.appName == "Microsoft Internet Explorer") {
        for(a=option_len; a>=0; a--) {
            document.getElementById(sel_output).options.remove(a);
        }
        preselect = document.createElement('OPTION');
        document.getElementById(sel_output).options.add(preselect);
        preselect.value = 'false';
        if(document.getElementById(sel_input).value == 'false') {
            preselect.innerHTML = preselect_false;
        } else {
            preselect.innerHTML = preselect_true;
        }
        if (res=='true') {
            temp_id = text.getElementsByTagName(tag_id)[0].childNodes[0].nodeValue;
            temp_desc = text.getElementsByTagName(tag_desc)[0].childNodes[0].nodeValue;
            result_id = temp_id.split('~');
            result_desc = temp_desc.split('~');
            for(a=0; a<result_id.length; a++) {
                arr[a]= document.createElement('OPTION');
                document.getElementById(sel_output).options.add(arr[a]);
                arr[a].innerHTML = result_desc[a];
                arr[a].value = result_id[a];
            }
        }
    } else {
        for(a=option_len; a>=0; a--) {
            document.getElementById(sel_output).remove(a);
        }
        preselect = document.createElement('OPTION');
        document.getElementById(sel_output).add(preselect, null);
        preselect.value = 'false';
        if(document.getElementById(sel_input).value == 'false') {
            preselect.innerHTML = preselect_false;
        } else {
            preselect.innerHTML = preselect_true;
        }
        if (res=='true') {
            temp_id = text.getElementsByTagName(tag_id)[0].childNodes[0].nodeValue;
            temp_desc = text.getElementsByTagName(tag_desc)[0].childNodes[0].nodeValue;
            result_id = temp_id.split('~');
            result_desc = temp_desc.split('~');
            for(a=0; a<result_id.length; a++) {
                arr[a]= document.createElement('OPTION');
                document.getElementById(sel_output).add(arr[a], null);
                arr[a].innerHTML = result_desc[a];
                arr[a].value = result_id[a];
            }
        }
    }
}
function checked_view(element,form) {
    var r;
    if(form.checked) {
        r = document.getElementById('qty_temp').value;
        for(a=0; a<r; a++) {
            document.getElementById('brand_id_'+a).disabled = true;
            document.getElementById('bom_id_'+a).disabled = true;
            document.getElementById('part_qty_'+a).disabled = true;
            document.getElementById('part_qty_'+a).value = 1;
        }
        document.getElementById(element).style.display='';
    } else {
        r=document.getElementById('qty_temp').value;
        for(a=0; a<r; a++) {
            document.getElementById('brand_id_'+a).disabled = false;
            document.getElementById('bom_id_'+a).disabled = false;
            document.getElementById('part_qty_'+a).disabled = false;
            document.getElementById('part_qty_'+a).value = '';
        }
        document.getElementById(element).style.display='none';
    }
}
function upd_checked_view(element, form, jobissue_no, bom_id, part_no, p_qty, j_no) {
    var answer;
    var nor_issue=document.getElementById('normal_issue');
    if(nor_issue.value=='Y') {
	if(form.checked) {
            document.getElementById(element).style.display='';
	} else {
            document.getElementById(element).style.display='none';
	}
    } else {
	answer=confirm('Hapus semua part dari handset?');
	if(answer) {
            del_jobissue(jobissue_no, bom_id, part_no, p_qty, j_no, 'Y');
            document.getElementById(element).style.display='none';
	} else {
            form.checked=true;
	}
    }
}		
function cback_select_engine2(sel_input,sel_output,tag_id,tag_desc,preselect_false,preselect_true,text) {
    var res = text.getElementsByTagName('hasil')[0].childNodes[0].nodeValue;
    var arr = new Array();
    var option_len = document.getElementById(sel_output).length;
    var temp_id, temp_desc, result_id, result_desc, preselect;
    if(navigator.appName == "Microsoft Internet Explorer") {
        for(a=option_len; a>=0; a--) {
            document.getElementById(sel_output).options.remove(a);
        }
        preselect = document.createElement('OPTION');
        document.getElementById(sel_output).options.add(preselect);
        preselect.value = 'false';
        if(document.getElementById(sel_input).value == 'false') {
            preselect.innerHTML = preselect_false;
        } else {
            preselect.innerHTML = preselect_true;
	}
	if (res=='true') {
            temp_id = text.getElementsByTagName(tag_id)[0].childNodes[0].nodeValue;
            temp_desc = text.getElementsByTagName(tag_desc)[0].childNodes[0].nodeValue;
            result_id = temp_id.split('~');
            result_desc = temp_desc.split('~');
            for(a=0; a<result_id.length; a++) {
                arr[a]= document.createElement('OPTION');
                document.getElementById(sel_output).options.add(arr[a]);
                arr[a].innerHTML = result_desc[a]+' ['+result_id[a]+']';
                arr[a].value = result_id[a];
            }
        }
    } else {
        for(a=option_len; a>=0; a--) {
            document.getElementById(sel_output).remove(a);
        }
        preselect = document.createElement('OPTION');
        document.getElementById(sel_output).add(preselect, null);
        preselect.value = 'false';
        if(document.getElementById(sel_input).value == 'false') {
            preselect.innerHTML = preselect_false;
        } else {
            preselect.innerHTML = preselect_true;
        }
        if (res=='true') {
            temp_id = text.getElementsByTagName(tag_id)[0].childNodes[0].nodeValue;
            temp_desc = text.getElementsByTagName(tag_desc)[0].childNodes[0].nodeValue;
            result_id = temp_id.split('~');
            result_desc = temp_desc.split('~');
            for(a=0; a<result_id.length; a++) {
                arr[a]= document.createElement('OPTION');
                document.getElementById(sel_output).add(arr[a], null);
                arr[a].innerHTML = result_desc[a]+' ['+result_id[a]+']';
                arr[a].value = result_id[a];
            }
        }
    }
}
function reset_jobissue_part(number) {
    var preselect;
    var option_len = document.getElementById('part_no_'+number).length;
    if(navigator.appName == "Microsoft Internet Explorer") {
        for(a=option_len; a>=0; a--) {
            document.getElementById('part_no_'+number).options.remove(a);
        }
        preselect = document.createElement('OPTION');
        document.getElementById('part_no_'+number).options.add(preselect);
        preselect.value = 'false';
        preselect.innerHTML = '::Select Model First::';
    } else {
        for(a=option_len; a>=0; a--) {
            document.getElementById('part_no_'+number).remove(a);
        }
        preselect = document.createElement('OPTION');
        document.getElementById('part_no_'+number).add(preselect, null);
        preselect.value = 'false';
        preselect.innerHTML = '::Select Model First::';
    }
}
function cback_update(alert_msg,ref,text) {
    if(text=='') {
        alert(alert_msg);
        goto_ref(ref);
    } else {
        alert(text);
    }
}
//CS
function cback_imei(text) {
    var res = text.getElementsByTagName('hasil')[0].childNodes[0].nodeValue;
    var symp, TAT, history;
    if(res>0) {
        TAT = text.getElementsByTagName('TAT_1')[0].childNodes[0].nodeValue;
        if(TAT<=90) {
            symp = text.getElementsByTagName('symp_code_1')[0].childNodes[0].nodeValue;
        } else {
            symp='';
        }
        history = text.getElementsByTagName('view_history')[0].childNodes[0].nodeValue;
        document.getElementById('repeated').value = symp;
        document.getElementById('hsl_imei').innerHTML = "&nbsp;&nbsp;&nbsp;<strong><font color='red'><a title='Click to View Job History' id='view_job' name='view_job' style='cursor:hand' onclick=\"open_view('hsl_job');\">IMEI</a></font> sudah pernah diinput sebanyak: "+res+" kali</strong>";
        document.getElementById('hsl_job').innerHTML = history;
    } else {
        document.getElementById('repeated').value = '';
        document.getElementById('hsl_imei').innerHTML = '';
        document.getElementById('hsl_job').innerHTML = '';
        close_view('hsl_job');
    }
}
function cback_jobform(text) {
    document.getElementById('main_content').innerHTML = text;
    var cal1 = new Epoch('epoch_popup','popup',document.getElementById('entry_date'));
    var cal2 = new Epoch('epoch_popup','popup',document.getElementById('purchase_date'));
    var cal3 = new Epoch('epoch_popup','popup',document.getElementById('factory_date'));
    create_view('main_content');
}
function cek_warranty() {
    var month_arr = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
    var myarr;
    var tgl_entry = document.getElementById('entry_date');
    var tgl_purchase = document.getElementById('purchase_date');
    if(tgl_entry==null || tgl_purchase==null) return false;
    if(tgl_entry.value != '' && tgl_purchase.value != '') {
        myarr = document.getElementById('entry_date').value.split('-');
        for(a=0; a<12; a++) {
            if(month_arr[a] == myarr[1]) {myarr[1]=a;}
        }
        var entry = new Date(myarr[2], myarr[1], myarr[0]);
        myarr = document.getElementById('purchase_date').value.split('-');
        for(a=0; a<12; a++) {
            if(month_arr[a] == myarr[1]) {myarr[1]=a;}
        }
        var p_date = new Date(myarr[2], myarr[1], myarr[0]);
        var selisih = (entry-p_date)/1000/86400;
        if(selisih<=365) {
            document.getElementById('status_warranty').innerHTML='IN Warranty';
        } else {
            document.getElementById('status_warranty').innerHTML='OUT Warranty';
	}
    } else {
        document.getElementById('status_warranty').innerHTML='';
    }
    return true;
}
function reset_jobform() {
    var option_len = document.getElementById('bom_id').length;
    var preselect;
    document.getElementById('brand').selectedIndex=0;
    document.getElementById('status_warranty').innerHTML='';
    document.getElementById('hsl_imei').innerHTML = '';
    if(navigator.appName == "Microsoft Internet Explorer") {
        for(a=option_len; a>=0; a--) {
            document.getElementById('bom_id').options.remove(a);
        }
        preselect = document.createElement('OPTION');
        document.getElementById('bom_id').options.add(preselect);
        preselect.value = 'false';
        if(document.getElementById('brand').value == 'false') {
            preselect.innerHTML = '::Select Brand First::';
        } else {
            preselect.innerHTML = '::Select Models::';
        }
    } else {
        for(a=option_len; a>=0; a--) {
            document.getElementById('bom_id').remove(a);
        }
        preselect = document.createElement('OPTION');
        document.getElementById('bom_id').add(preselect, null);
        preselect.value = 'false';
        if(document.getElementById('brand').value == 'false') {
            preselect.innerHTML = '::Select Brand First::';
        } else {
            preselect.innerHTML = '::Select Models::';
        }
    }
}
function enter_eval(e,form,cbackfile,param) {
    var keynum;//var keychar;
    if(window.event) {
        keynum=e.keyCode;
    } else if(e.which) {
        keynum=e.which;
    }
    //keychar = String.fromCharCode(keynum);
    if(keynum==13) {
        goto_page(form,cbackfile,param);
        return true;
    } else {
        return true;
    }
}
function goto_page(form, cbackfile, param) {
    var postparam = param+"&page_num="+form.sel_page.value+"&find_name="+escape(encodeURIComponent(form.src_input.value))+'&path_js='+escape(encodeURIComponent('../.'));
    doAjax(cbackfile,postparam,'cback_engine()','post','0',['ajax_loader','busy_view'],['sel_page','btn_src','src_input']);
}
function goto_page2(form, cbackfile, param) {
    var postparam = param+"&page_num="+form.sel_page.value+"&find_name="+escape(encodeURIComponent(form.src_input.value));
    doAjax(cbackfile,postparam,'cback(/edit_cust/)','post','0',['ajax_loader','busy_view'],['sel_page','btn_src','src_input']);
}
function enter_eval2(e,form,cbackfile,param) {
    var keynum;//var keychar;
    if(window.event) {
        keynum=e.keyCode;
    } else if(e.which) {
        keynum=e.which;
    }
    //keychar = String.fromCharCode(keynum);
    if(keynum==13) {
        goto_page2(form,cbackfile,param);
        return true;
    } else {
        return true;
    }
}
function cekform_walkin(form, param, tipe) {
    var postparam;
    if(form.nama.value=="") {
        alert("Nama Customer belum diisi...");
        form.nama.select();
        return false;
    }
    if(form.alamat.value=="") {
        alert("Alamat Customer belum diisi...");
        form.alamat.select();
        return false;
    }
    if(form.kota.value=="") {
        alert("Kota Customer belum diisi...");
        form.kota.select();
        return false;
    }
    if(form.telp.value=="" && form.mobile.value=="") {
        alert("You must fill atleast one customer phone or mobile.");
        form.telp.select();
        return false;
    }
    postparam=param+"&nama="+escape(encodeURIComponent(form.nama.value))+"&id_card="+escape(encodeURIComponent(form.id_card.value))+"&id_cardno="+escape(encodeURIComponent(form.id_cardno.value))+"&company="+escape(encodeURIComponent(form.company.value))+"&alamat="+escape(encodeURIComponent(form.alamat.value))+"&kota="+escape(encodeURIComponent(form.kota.value))+"&kodepos="+escape(encodeURIComponent(form.kodepos.value))+"&telp="+escape(encodeURIComponent(form.telp.value))+"&mobile="+escape(encodeURIComponent(form.mobile.value));
    if(tipe=='save') {
        if(param!='') {
            doAjax('./module/admin/engine/update_job_cust.php',postparam,'cback_special(/'+param+'/)','post','0',['ajax_loader','busy_view'],['nama','id_card','id_cardno','alamat','kota','kodepos','telp','mobile','save_data']);
        } else {
            doAjax('./module/cs/engine/save_walkin.php',postparam,'cback_engine()','post','0',['ajax_loader', 'busy_view'],['nama','id_card','id_cardno','alamat','kota','kodepos','telp','mobile','save_data','reset_data']);
        }
    } else {
        if(param!='') {
            doAjax('./module/cs/engine/update_walkin.php',postparam,'cback_special(/'+param+'/)','post','0',['ajax_loader', 'busy_view'],['nama','id_card','id_cardno','alamat','kota','kodepos','telp','mobile','edit_data']);
        } else {
            doAjax('./module/cs/engine/update_walkin.php',postparam+'&cust_id='+escape(encodeURIComponent(form.cust_id.value)),'cback_engine()','post','0',['ajax_loader', 'busy_view'],['nama','id_card','id_cardno','alamat','kota','kodepos','telp','mobile','edit_data']);
        }
    }
    return true;
}
function cekform_collect(form, tipe) {
    var postparam;
    if(form.company.value=="") {
        alert("Collect Point Name belum diisi...");
        form.company.select();
        return false;
    }
    if(form.alamat.value=="") {
        alert("Alamat belum diisi...");
        form.alamat.select();
        return false;
    }
    if(form.kota.value=="") {
        alert("Kota belum diisi...");
        form.kota.select();
        return false;
    }
    if(form.telp.value=="" && form.fax.value=="") {
        alert("You must fill atleast one collect point phone or fax");
        form.telp.select();
        return false;
    }
    postparam="&company="+escape(encodeURIComponent(form.company.value))+"&contact_name="+escape(encodeURIComponent(form.contact_name.value))+"&alamat="+escape(encodeURIComponent(form.alamat.value))+"&kota="+escape(encodeURIComponent(form.kota.value))+"&kodepos="+escape(encodeURIComponent(form.kodepos.value))+"&telp="+escape(encodeURIComponent(form.telp.value))+"&fax="+escape(encodeURIComponent(form.fax.value));
    if(tipe=='save') {
        doAjax('./module/cs/engine/save_collect.php',postparam,'cback_engine()','post','0',['ajax_loader', 'busy_view'],['company','contact_name','alamat','kota','kodepos','telp','fax','save_data','reset_data']);    
    } else {
        doAjax('./module/cs/engine/update_collect.php',postparam+'&collect_point_id='+escape(encodeURIComponent(form.collect_point_id.value)),'cback_engine()','post','0',['ajax_loader', 'busy_view'],['company','contact_name','alamat','kota','kodepos','telp','fax','edit_data']);
    }
    return true;
}
function cekform_collect_user(form, param, tipe) {
    var postparam;
    if(form.contact_name.value=="") {
        alert("Contact Name belum diisi...");
        form.contact_name.select();
        return false;
    }
    if(form.alamat.value=="") {
        alert("Alamat belum diisi...");
        form.alamat.select();
        return false;
    }
    if(form.kota.value=="") {
        alert("Kota belum diisi...");
        form.kota.select();
        return false;
    }
    if(form.telp.value=="" && form.mobile.value=="") {
        alert("You must fill atleast one contact phone or mobile");
        form.telp.select();
        return false;
    }
    postparam=param+"&contact_name="+escape(encodeURIComponent(form.contact_name.value))+"&alamat="+escape(encodeURIComponent(form.alamat.value))+"&kota="+escape(encodeURIComponent(form.kota.value))+"&kodepos="+escape(encodeURIComponent(form.kodepos.value))+"&telp="+escape(encodeURIComponent(form.telp.value))+"&mobile="+escape(encodeURIComponent(form.mobile.value));
    if(tipe=='save') {
        doAjax('./module/cs/engine/save_collect_user.php',postparam,'cback_engine()','post','0',['ajax_loader', 'busy_view'],['contact_name','alamat','kota','kodepos','telp','mobile','save_data','reset_data','back_to_collect_user']);
    } else if(tipe=='save2') {
        doAjax('./module/admin/engine/update_job_cust.php',postparam,'cback_special(/'+param+'/)','post','0',['ajax_loader','busy_view'],['contact_name','alamat','kota','kodepos','telp','mobile','save_data']);
    } else {
        if(param!='') {
            doAjax('./module/cs/engine/update_collect_user.php',postparam+'&collect_id='+escape(encodeURIComponent(form.collect_id.value)),'cback_special(/'+param+'/)','post','0',['ajax_loader', 'busy_view'],['contact_name','alamat','kota','kodepos','telp','mobile','edit_data','back_to_collect_usr']);
        } else {
            doAjax('./module/cs/engine/update_collect_user.php',postparam+'&cust_id='+escape(encodeURIComponent(form.cust_id.value))+'&collect_id='+escape(encodeURIComponent(form.collect_id.value)),'cback_engine()','post','0',['ajax_loader', 'busy_view'],['contact_name','alamat','kota','kodepos','telp','mobile','edit_data','back_to_collect_usr']);
        }
    }
    return true;
}
function checkform_job_form(form, param, tipe, print_file) {
    var postparam;
    var warstatus = document.getElementById('status_warranty').innerHTML;
    var month_arr = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
    var myarr;
    var factory_date='0000-00-00';
    if(form.AWB.value=='') {
        if(form.type_user.value=='Collect') {
            alert('AWB No. belum diisi...');
            return false;
        } else {
            if(form.type_scc.value=='1') {
                alert('AWB No. belum diisi...');
                return false;
            }
        }
    }        
    if(document.getElementById('factory_date').value != '') {
        myarr=document.getElementById('factory_date').value.split('-');
        for(a=0; a<12; a++) {
            if(month_arr[a] == myarr[1]) {myarr[1]=a+1;}
        }
        factory_date = myarr[2]+'-'+myarr[1]+'-'+myarr[0];
    }
    if(document.getElementById('entry_date').value != '' && document.getElementById('purchase_date').value != '') {
        myarr = document.getElementById('entry_date').value.split('-');
        for(a=0; a<12; a++) {
            if(month_arr[a] == myarr[1]) {myarr[1]=a+1;}
        }
        var entry = myarr[2]+'-'+myarr[1]+'-'+myarr[0];
        myarr = document.getElementById('purchase_date').value.split('-');
        for(a=0; a<12; a++) {
            if(month_arr[a] == myarr[1]) {myarr[1]=a+1;}
        }
        var p_date = myarr[2]+'-'+myarr[1]+'-'+myarr[0];
    }
    if(form.imei.value=="") {
        alert("Nomor IMEI belum diisi..");
        form.imei.select();
        return false;
    }
    if(form.serial_no.value=="") {
        alert("Serial Number belum diisi...");
        form.serial_no.select();
        return false;
    }
    if(form.brand.value=="false") {
        alert("Brand harus dipilih...");
        return false;
    }
    if(form.bom_id.value=="false") {
        alert("Anda harus memilih Model...");
        return false;
    }
    if(form.entry_date.value=="") {
        alert("Masukkan tanggal Entry");
        return false;
    }
    if(form.purchase_date.value=="") {
        alert("Masukkan tanggal Purchase");
        return false;
    }
    if(form.symptom_code.value=="false") {
        alert("Pilih Symptom Code untuk melanjutkan");
        return false;
    }
    if(form.complain_notes.value=="") {
        alert("Complain Notes harus diisi...");
        form.complain_notes.select();
        return false;
    }
    postparam=param+"&imei="+escape(encodeURIComponent(form.imei.value))+"&serial_no="+escape(encodeURIComponent(form.serial_no.value))+"&sw_ver="+escape(encodeURIComponent(form.swver.value))+"&brand="+escape(encodeURIComponent(form.brand.value))+"&bom_id="+escape(encodeURIComponent(form.bom_id.value))+"&AWB="+escape(encodeURIComponent(form.AWB.value))+"&job_type="+escape(encodeURIComponent(form.job_type.value))+"&entry_date="+escape(encodeURIComponent(entry))+"&purchase_date="+escape(encodeURIComponent(p_date))+"&factory_date="+escape(encodeURIComponent(factory_date))+"&status_warranty="+escape(encodeURIComponent(warstatus))+"&battery_type="+escape(encodeURIComponent(form.battery_type.value))+"&others="+escape(encodeURIComponent(form.others.value))+"&symptom_code="+escape(encodeURIComponent(form.symptom_code.value))+"&complain_notes="+escape(encodeURIComponent(form.complain_notes.value))+"&repeated="+escape(encodeURIComponent(form.repeated.value));
    if(tipe=='save') {
        doAjax('./module/cs/engine/save_job_form.php',postparam,'cback_engine_print(/'+print_file+'/,/?total_checked=1/)','post','0',['ajax_loader', 'busy_view'],['imei','serial_no','brand','bom_id','AWB','job_type','entry_date','purchase_date','factory_date','swver','battery_type','others','symptom_code','complain_notes','back_to_listing','reset_data','confirm_next']);
    } else {
        doAjax('./module/admin/engine/update_job_form.php',postparam,'cback_engine_print(/'+print_file+'/,/?total_checked=1/)','post','0',['ajax_loader', 'busy_view'],['imei','serial_no','brand','bom_id','AWB','job_type','entry_date','purchase_date','factory_date','swver','battery_type','others','symptom_code','complain_notes','back_to_listing','reset_data','confirm_next']);
    }
    return true;
}
function back_to_list(jenis) {
    if(jenis=='Walkin') {
        doAjax('./module/cs/engine/get_walkin.php','','cback_engine()','post','0',['ajax_loader','busy_view'],['back_to_listing','reset_data','confirm_next','imei','serial_no','job_type','brand','entry_date','bom_id','purchase_date','AWB','battery_type','others','symptom_code','complain_notes']);
    } else {
        doAjax('./module/cs/engine/get_collect.php','','cback_engine()','post','0',['ajax_loader','busy_view'],['back_to_listing','reset_data','confirm_next','imei','serial_no','job_type','brand','entry_date','bom_id','purchase_date','AWB','battery_type','others','symptom_code','complain_notes']);
    }
}
function get_checkbox(form,cbackfile) {
    var c_value = '';
    var answer;
    if(form.c_box!=null) {
        if(form.c_box.length==undefined) {
            if(form.c_box.checked) {
                c_value = "'" + form.c_box.value + "'";
            }
        } else {
            for(var i=0; i < form.c_box.length; i++) {
                if(form.c_box[i].checked) {
                    c_value = c_value + "'" + form.c_box[i].value + "',";
                }
            }
            c_value = c_value.substring(0,c_value.length-1);
        }
        if((c_value.length)>0) {
            answer=confirm('Send selected Job?');
            if(answer) {
                doAjax(cbackfile,'&checked_box='+escape(encodeURIComponent(c_value)),'cback_engine()','post','0',['ajax_loader','busy_view'],['back_to_prev','sel_page','src_input','btn_src','btn_submit']);
                form.reset();
            }
        }
    }
}
function get_checkbox2(form) {
    var c_value = '';
    var answer, param;
    if(form.c_box!=null) {
        if(form.tech.value=='false') {
            alert('You must choose assigned tech to confirm');
            return false;
        }
        if(form.c_box.length==undefined) {
            if(form.c_box.checked) {
                c_value = "'" + form.c_box.value + "'";
            }
        } else {
            for(var i=0; i < form.c_box.length; i++) {
                if(form.c_box[i].checked) {
                    c_value = c_value + "'" + form.c_box[i].value + "',";
                }
            }
            c_value = c_value.substring(0,c_value.length-1);
        }
        if((c_value.length)>0) {
            answer=confirm('Send selected Job to Technician?');
            if(answer) {
                param='&checked_box='+escape(encodeURIComponent(c_value))+'&technician='+escape(encodeURIComponent(form.tech.value));
                doAjax('./module/admin/engine/admin_to_tech.php',param,'cback_engine()','post','0',['ajax_loader','busy_view'],['back_to_prev','sel_page','src_input','btn_src','btn_submit','tech']);
                form.reset();
            }
        }
        return true;
    } else {
        return false;
    }
}
//INVENTORY
function checked_broken(form) {
    if(form.others.checked) {
        form.subcon.selectedIndex = 0;
        form.subcon.disabled = true;
    } else {
        form.subcon.disabled = false;
    }
}
function cek_save_stock(form,cbackfile) {
    var postparam, temp, to_subcon, print_file;
    var brand_id_param='';
    var bom_id_param='';
    var part_no_param='';
    var part_qty_param='';
    var subcon=form.subcon;
    var qty_temp_chk=form.qty_temp;
    var s_ref_no=form.s_ref_no;
    var ref_no='false';
    if(s_ref_no!=null) {
        if(s_ref_no.value=='false') {
            alert('Pilih Ref No yang akan diedit..');
            return false;
        } else {
            ref_no=s_ref_no.value;
            if(ref_no.substr(2,2)=='IN') {
                print_file='.~module~inventory~engine~stockin_pdf.php';
            } else if(ref_no.substr(2,2)=='OU') {
                print_file='.~module~inventory~engine~stockout_pdf.php';
            }
        }
    }
    if(subcon!=null) {
        if(subcon.value=='false') {
            if(!form.others.checked) {
                alert('Subcon belum dipilih');
                return false;
            } else {
                to_subcon='OTHERS';
            }
        } else {
            to_subcon=subcon.value;
        }
    }
    if(qty_temp_chk==null) {
        alert('Silahkan isi Qty Input..');
        form.qty_input.select();
        return false;
    }
    if(form.qty_temp.value=='0' && ref_no=='false') {
        alert('Silahkan isi Qty Input..');
        form.qty_input.select();
        return false;
    }
    if(form.stock_notes.value=='') {
        alert('Notes masih kosong...');
        form.stock_notes.select();
        return false;
    }
    for(a=0;a<form.qty_temp.value;a++) {
        temp=eval('form.brand_id_'+a+'.value');
        brand_id_param=brand_id_param+'&brand_id_'+a+'='+escape(encodeURIComponent(temp));
        if(temp=='false') {
            alert('Brand untuk no. '+(a+1)+' belum dipilih');
            return false;
        }
        temp=eval('form.bom_id_'+a+'.value');
        bom_id_param=bom_id_param+'&bom_id_'+a+'='+escape(encodeURIComponent(temp));
        if(temp=='false') {
            alert('Model untuk no. '+(a+1)+' belum dipilih');
            return false;
        }
        temp=eval('form.part_no_'+a+'.value');
        part_no_param=part_no_param+'&part_no_'+a+'='+escape(encodeURIComponent(temp));
        if(temp=='false') {
            alert('Part untuk no. '+(a+1)+' belum dipilih');
            return false;
        }
        temp=parseInt(eval('form.part_qty_'+a+'.value'));
        part_qty_param=part_qty_param+'&part_qty_'+a+'='+temp;
        if(isNaN(temp) || temp==0) {
            alert('Qty untuk no. '+(a+1)+' belum diisi');
            return false;
        }
    }
    postparam='&ref_no='+escape(encodeURIComponent(ref_no))+'&subcon='+to_subcon+'&qty_input='+form.qty_temp.value+'&stock_notes='+escape(encodeURIComponent(form.stock_notes.value))+brand_id_param+bom_id_param+part_no_param+part_qty_param;
    if(ref_no=='false') {
        doAjax(cbackfile,postparam,'cback_w_msg(/Save successful.../)','post','0',['ajax_loader','busy_view'],[]);
    } else {
        doAjax(cbackfile,postparam,'cback_engine_print(/'+print_file+'/,/'+'?ref_no='+escape(encodeURIComponent(ref_no))+'/)','post','0',['ajax_loader','busy_view'],[]);
    }
    return true;
}
function goto_page_listpart(form, cbackfile, param) {
    var postparam = param+"&page_num="+form.sel_page.value+"&find_name="+escape(encodeURIComponent(form.src_input.value));
    doAjax(cbackfile,postparam,'cback(/list_part/)','post','0',['ajax_loader','busy_view'],['sel_page','btn_src','src_input']);
}
function cek_save_part(form, action) {
    var postparam, preselect;
    if(form.brand.value=='false') {
        alert('Pilih brand untuk part..');
        return false;
    }
    if(form.bom_id.value=='false') {
        alert('Pilih BOM Model...');
        return false;
    }
    if(form.part_no.value=='') {
        alert('Part No harus diisi...');
        form.part_no.select();
        return false;
    }
    if(form.description.value=='') {
        alert('Isikan deskripsi untuk part..');
        form.description.select();
        return false;
    }
    postparam="&brand_id="+escape(encodeURIComponent(form.brand.value))+"&bom_id="+escape(encodeURIComponent(form.bom_id.value))+"&part_no="+escape(encodeURIComponent(form.part_no.value))+"&description="+escape(encodeURIComponent(form.description.value))+"&cat_code="+escape(encodeURIComponent(form.cat_code.value))+"&part_type_id="+escape(encodeURIComponent(form.part_type_id.value))+"&curr="+escape(encodeURIComponent(form.currency.value))+"&cost_price="+escape(encodeURIComponent(form.cost_price.value))+"&sell_price="+escape(encodeURIComponent(form.sell_price.value))+"&dist_price="+escape(encodeURIComponent(form.dist_price.value))+"&visel_price="+escape(encodeURIComponent(form.visel_price.value))+"&com_price="+escape(encodeURIComponent(form.com_price.value))+"&min_order="+escape(encodeURIComponent(form.min_order.value))+"&max_order="+escape(encodeURIComponent(form.max_order.value));
    if(action=='update') {
        var answer=confirm('Update data for Part No='+form.part_no.value+'?');
        if(answer) {
            doAjax('./module/inventory/engine/update_part.php',postparam+'&discontinued='+form.discontinued.value+'&bom_id_bef='+form.bom_id_bef.value,'cback_update(/Data part updated../,/add_part/)','post','0',['ajax_loader', 'busy_view'],['brand','bom_id','part_no','description','cat_code','part_type_id','currency','cost_price','sell_price','dist_price','visel_price','com_price','min_order','max_order','back_to_prev','btn_save','back_to_add','discontinued']);
            return true;
        } else {
            return false;
        }
    } else {
        doAjax('./module/inventory/engine/save_part.php',postparam,'cback(/list_part/)','post','0',['ajax_loader', 'busy_view'],['brand','bom_id','part_no','description','cat_code','part_type_id','currency','cost_price','sell_price','dist_price','visel_price','com_price','min_order','max_order','back_to_prev','btn_save']);
    }
    //reset
    form.reset();
    var option_len = document.getElementById('bom_id').length;
    document.getElementById('brand').selectedIndex=0;
    if(navigator.appName == "Microsoft Internet Explorer") {
        for(a=option_len; a>=0; a--) {
            document.getElementById('bom_id').options.remove(a);
        }
        preselect = document.createElement('OPTION');
        document.getElementById('bom_id').options.add(preselect);
        preselect.value = 'false';
        if(document.getElementById('brand').value == 'false') {
            preselect.innerHTML = '::Select Brand First::';
        } else {
            preselect.innerHTML = '::Select Models::';
        }
    } else {
        for(a=option_len; a>=0; a--) {
            document.getElementById('bom_id').remove(a);
        }
        preselect = document.createElement('OPTION');
        document.getElementById('bom_id').add(preselect, null);
        preselect.value = 'false';
        if(document.getElementById('brand').value == 'false') {
            preselect.innerHTML = '::Select Brand First::';
        } else {
            preselect.innerHTML = '::Select Models::';
        }
    }
    return true;
}
function cek_save_bom(form, action) {
    var postparam;
    if(form.brand.value=='false') {
        alert('Pilih brand untuk BOM Model..');
        return false;
    }
    if(form.bom_model.value=='') {
        alert('BOM Model harus diisi...');
        form.bom_model.select();
        return false;
    }
    if(form.description.value=='') {
        alert('Isikan deskripsi untuk BOM Model..');
        form.description.select();
        return false;
    }
    if(form.imei_char.value=='') {
        alert('Jumlah character IMEI harus diisi...');
        form.imei_char.select();
        return false;
    }
    postparam="&brand_id="+escape(encodeURIComponent(form.brand.value))+"&bom_model="+escape(encodeURIComponent(form.bom_model.value))+"&description="+escape(encodeURIComponent(form.description.value))+"&imei_char="+escape(encodeURIComponent(form.imei_char.value));
    if(action=='update') {
        var answer=confirm('Update BOM Model data?');
        if(answer) {
            if(form.discontinued.value=='Y') {
                answer=confirm("Set Discontinued to 'Yes'?, EVERY PARTS related to this BOM Model will be discontinued too!");
                if(answer) {
                    doAjax('./module/inventory/engine/update_bom.php',postparam+'&bom_id='+form.bom_id.value+'&discontinued='+form.discontinued.value,'cback_update(/Data model updated../,/add_bom_models/)','post','0',['ajax_loader', 'busy_view'],['brand','bom_model','description','imei_char','back_to_prev','btn_save','back_to_add','discontinued']);
                    return true;
                } else {
                    return false;
                }
            } else {
                doAjax('./module/inventory/engine/update_bom.php',postparam+'&bom_id='+form.bom_id.value+'&discontinued='+form.discontinued.value,'cback_update(/Data model updated../,/add_bom_models/)','post','0',['ajax_loader', 'busy_view'],['brand','bom_model','description','imei_char','back_to_prev','btn_save','back_to_add','discontinued']);
                return true;
            }
        } else {
            return false;
        }
    } else {
        doAjax('./module/inventory/engine/save_bom.php',postparam,'cback(/list_part/)','post','0',['ajax_loader', 'busy_view'],['brand','bom_model','description','imei_char','back_to_prev','btn_save']);
    }
    form.reset();
    return true;
}
function cek_save_brand(form, action) {
    var postparam;
    if(form.brand_name.value=='false') {
        alert('Input nama Brand...');
        form.brand_name.select();
        return false;
    }
    postparam="&brand_name="+escape(encodeURIComponent(form.brand_name.value))+'&status_brand='+escape(encodeURIComponent(form.status_brand.value));
    if(action=='update') {
        var answer=confirm('Update Brand data?');
        if(answer) {
            if(form.discontinued.value=='Y') {
                answer=confirm("Set Discontinued to 'Yes'?, EVERY BOM Models related to this Brand will be discontinued too!");
                if(answer) {
                    doAjax('./module/inventory/engine/update_brand.php',postparam+'&brand_id='+form.brand_id.value+'&discontinued='+form.discontinued.value+'&status_brand='+form.status_brand.value,'cback_update(/Data brand updated../,/add_brand/)','post','0',['ajax_loader', 'busy_view'],['brand_name','back_to_prev','btn_save','back_to_add','discontinued']);
                    return true;
                } else {
                    return false;
                }
            } else {
                doAjax('./module/inventory/engine/update_brand.php',postparam+'&brand_id='+form.brand_id.value+'&discontinued='+form.discontinued.value+'&status_brand='+form.status_brand.value,'cback_update(/Data brand updated../,/add_brand/)','post','0',['ajax_loader', 'busy_view'],['brand_name','back_to_prev','btn_save','back_to_add','discontinued']);
                return true;
            }
        } else {
            return false;
        }
    } else {
        doAjax('./module/inventory/engine/save_brand.php',postparam,'cback(/list_part/)','post','0',['ajax_loader', 'busy_view'],['brand_name','back_to_prev','btn_save']);
    }
    form.reset();
    return true;
}
//TECHNICIAN
function cback_technician(text) {
    var tech_from_admin = text.getElementsByTagName('tech_from_admin')[0].childNodes[0].nodeValue;
    var tech_start_repair = text.getElementsByTagName('tech_start_repair')[0].childNodes[0].nodeValue;
    var tech_request_part = text.getElementsByTagName('tech_request_part')[0].childNodes[0].nodeValue;
    var reject_by_tech = text.getElementsByTagName('reject_by_tech')[0].childNodes[0].nodeValue;
    var status_jobissue = text.getElementsByTagName('status_jobissue')[0].childNodes[0].nodeValue;
    var tech_to_qc = text.getElementsByTagName('tech_to_qc')[0].childNodes[0].nodeValue;
    var res = text.getElementsByTagName('main_content')[0].childNodes[0].nodeValue;
    if(res!='false') {
        document.getElementById('main_content').innerHTML = res;
    } else {
        document.getElementById('received_from_admin').disabled = true;
        document.getElementById('start_repair').disabled = true;
        document.getElementById('request_part').disabled = true;
        
        document.getElementById('rep_desc_1').disabled = true;
        document.getElementById('rep_desc_2').disabled = true;
        document.getElementById('rep_desc_3').disabled = true;
	
        document.getElementById('tech_repair_notes').disabled = true;
        document.getElementById('send_to_qc').disabled = true;
        document.getElementById('reject_notes').disabled = true;
        document.getElementById('reject_tech').disabled = true;
	
        document.getElementById('step_1').bgColor = '';
        document.getElementById('step_2').bgColor = '';
        document.getElementById('step_3').bgColor = '';
        document.getElementById('step_4').bgColor = '';
        document.getElementById('reject').bgColor = '';
    }
    if(reject_by_tech=='N' && tech_to_qc=='N') {
        if(tech_from_admin=='Y') {
            if(tech_start_repair=='Y') {
                if(tech_request_part=='Y') {
                    document.getElementById('rep_desc_1').disabled = false;
                    document.getElementById('rep_desc_2').disabled = false;
                    document.getElementById('rep_desc_3').disabled = false;
                    document.getElementById('finish_date').disabled = false;
                    document.getElementById('tech_repair_notes').disabled = false;
                    document.getElementById('send_to_qc').disabled = false;
                    document.getElementById('reject_notes').disabled = false;
                    document.getElementById('reject_tech').disabled = false;
                    document.getElementById('step_4').bgColor = '#FFFF00';
                    document.getElementById('reject').bgColor = '#FFFF00';
                    document.getElementById('rep_desc_1').focus();
                } else {
                    document.getElementById('rep_desc_1').disabled = false;
                    document.getElementById('rep_desc_2').disabled = false;
                    document.getElementById('rep_desc_3').disabled = false;
                    document.getElementById('finish_date').disabled = false;
                    document.getElementById('tech_repair_notes').disabled = false;
                    document.getElementById('send_to_qc').disabled = false;
                    document.getElementById('reject_notes').disabled = false;
                    document.getElementById('reject_tech').disabled = false;
                    document.getElementById('step_4').bgColor = '#FFFF00';
                    document.getElementById('reject').bgColor = '#FFFF00';
                    document.getElementById('request_part').disabled = false;
                    document.getElementById('step_3').bgColor = '#FFFF00';
                    document.getElementById('request_part').focus();
                }
            } else {
                document.getElementById('start_repair').disabled = false;
                document.getElementById('step_2').bgColor = '#FFFF00';
                document.getElementById('start_repair').focus();
            }
        } else {
            document.getElementById('received_from_admin').disabled = false;
            document.getElementById('step_1').bgColor = '#FFFF00';
            document.getElementById('received_from_admin').focus();
        }
    }
    if(status_jobissue=='N' && tech_request_part=='Y' && reject_by_tech=='N') {
        alert("Job Issue belum dibuat.\r\nSilahkan hubungi admin...");
    }
    if(reject_by_tech=='Y' || tech_to_qc=='Y') {
        goto_ref('create_service_job');
    }
    var cal1  = new Epoch('epoch_popup','popup',document.getElementById('finish_date'));
}
//use xml
function get_serv_job_no(cbackfile, param) {
    doAjax(cbackfile,param,'cback_technician()','post','1',['ajax_loader','busy_view'],[]);
}
function proses_job(form, action, job_no) {
    var answer, param, myarr;
    var cbackfile='./module/tech/engine/proses_repair.php';
    var month_arr = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
    if(action=='received_from_admin') {
        answer=confirm('Received from admin?');
        param='&received_from_admin=Y&job_no='+job_no;
    } else if(action=='start_repair') {
        answer=confirm('Start repair for Job No: '+job_no+'?');
        param='&start_repair=Y&job_no='+job_no;
    } else if(action=='request_part') {
        answer=confirm('Request Part?');
        param='&request_part=Y&job_no='+job_no;
    } else if(action=='send_to_qc') {
        //cek jobissue status
        if(document.getElementById('finish_date').value != '') {
            myarr = document.getElementById('finish_date').value.split('-');
            for(a=0; a<12; a++) {
                if(month_arr[a] == myarr[1]) {myarr[1]=a+1;}
            }
            var finish = myarr[2]+'-'+myarr[1]+'-'+myarr[0];
            var f_date = new Date(myarr[2], myarr[1]-1, myarr[0]);
            myarr = document.getElementById('date_in').value.split('-');
            var e_date = new Date(myarr[0], myarr[1]-1, myarr[2]);
            var selisih = (f_date-e_date)/1000/86400;
            if(selisih<0) {
                alert('Finish Date harus setelah atau minimal sama dengan tanggal masuk...');
                return false;
            }
        }
        if(form.rep_desc_1.value=='false') {
            alert("Repair Description 1 harus dipilih...");
            return false;
        }
        if(form.tech_repair_notes.value=='') {
            alert("Technician repair notes harus diisi...");
            form.tech_repair_notes.select();
            return false;
        }
        answer=confirm('Finish repair and send to QC?');
        param='&send_to_qc=Y&job_no='+job_no+'&finish_date='+escape(encodeURIComponent(finish))+'&rep_desc_1='+escape(encodeURIComponent(form.rep_desc_1.value))+'&rep_desc_2='+escape(encodeURIComponent(form.rep_desc_2.value))+'&rep_desc_3='+escape(encodeURIComponent(form.rep_desc_3.value))+'&tech_repair_notes='+escape(encodeURIComponent(form.tech_repair_notes.value));
    } else if(action=='reject_tech') {
        if(form.reject_notes.value=='') {
            alert("Reject notes harus diisi...");
            form.reject_notes.select();
            return false;
        }
        answer=confirm('Reject repair for Job No: '+job_no+'?');
        param='&reject_tech=Y&job_no='+job_no+'&reject_notes='+escape(encodeURIComponent(form.reject_notes.value));
    }
    if(answer) {
        doAjax(cbackfile, param, 'cback_technician()','post','1',['ajax_loader','busy_view'],[action]);
        return true;
    } else {
        return false;
    }
}
//JOB ISSUE
function cek_save_job_issue(form,cbackfile,param,job_no) {
    var postparam, temp;
    var bom_id_param='';
    var part_no_param='';
    var part_qty_param='';
    var stock_type_param='';
    var print_file='.~module~admin~engine~jobissue_pdf.php';
    var post_job_no="'"+job_no+"'";
    var hs_no='false';
    var param2='?total_checked=1&checked_box='+escape(encodeURIComponent(post_job_no));
    if(form.from_hs.checked) {
        if(form.hs_part_no.value=='false') {
            alert('Silahkan pilih jenis handset yang diambil partnya...');
            return false;
        } else {
            hs_no=form.hs_part_no.value;
        }
    }
    if(form.qty_temp.value=='0') {
        alert('Silahkan isi Qty Input..');
        form.qty_input.select();
        return false;
    }
    if(form.notes.value=='') {
        alert('Notes masih kosong...');
        form.notes.select();
        return false;
    }
    if(form.fault_code.value=='false') {
        alert('Pilih Fault Code...');
        return false;
    }
    for(a=0;a<form.qty_temp.value;a++) {
        temp=eval('form.brand_id_'+a+'.value');
        if(temp=='false') {
            alert('Brand untuk no. '+(a+1)+' belum dipilih');
            return false;
        }
        temp=eval('form.bom_id_'+a+'.value');
        bom_id_param=bom_id_param+'&bom_id_'+a+'='+escape(encodeURIComponent(temp));
        if(temp=='false') {
            alert('Model untuk no. '+(a+1)+' belum dipilih');
            return false;
        }
        temp=eval('form.part_no_'+a+'.value');
        part_no_param=part_no_param+'&part_no_'+a+'='+escape(encodeURIComponent(temp));
        if(temp=='false') {
            alert('Part untuk no. '+(a+1)+' belum dipilih');
            return false;
        }
        temp=eval('form.stock_type_'+a+'.value');
        stock_type_param=stock_type_param+'&stock_type_'+a+'='+temp;
        if(temp=='false') {
            alert('Stock Type untuk no. '+(a+1)+' belum dipilih');
            return false;
        }
        temp=parseInt(eval('form.part_qty_'+a+'.value'));
        part_qty_param=part_qty_param+'&part_qty_'+a+'='+temp;
        if(isNaN(temp) || temp==0) {
            alert('Qty untuk no. '+(a+1)+' belum diisi');
            return false;
        }
    }
    postparam=param+'&hs_no='+escape(encodeURIComponent(hs_no))+'&swap_imei='+escape(encodeURIComponent(form.swap_imei.value))+'&swap_sn='+escape(encodeURIComponent(form.swap_sn.value))+'&fault_code='+form.fault_code.value+'&qty_input='+form.qty_temp.value+'&notes='+escape(encodeURIComponent(form.notes.value))+bom_id_param+part_no_param+part_qty_param+stock_type_param;
    doAjax(cbackfile,postparam,'cback_engine_print(/'+print_file+'/,/'+param2+'/)','post','0',['ajax_loader','busy_view'],[]);
    return true;
}
function cek_edit_job_issue(form,cbackfile,param) {
    var postparam, temp;
    var bom_id_param='';
    var part_no_param='';
    var part_qty_param='';
    var stock_type_param='';
    var temp_qty=document.getElementById('qty_temp');
    var input_qty=0;
    var hs_no='false';
    var param2='?total_checked=1';
    var print_file='.~module~admin~engine~jobissue_pdf.php';
    if(form.from_hs.checked) {
        if(form.hs_part_no.value=='false') {
            alert('Silahkan pilih jenis handset yang diambil partnya...');
            return false;
        } else {
            hs_no=form.hs_part_no.value;
        }
    }
    if(form.notes.value=='') {
        alert('Notes masih kosong...');
        form.notes.select();
        return false;
    }
    if(form.fault_code.value=='false') {
        alert('Pilih Fault Code...');
        return false;
    }
    if(temp_qty!=null) {
        input_qty=temp_qty.value;
    }
    for(a=0;a<input_qty;a++) {
        temp=eval('form.brand_id_'+a+'.value');
        if(temp=='false') {
            alert('Brand untuk no. '+(a+1)+' belum dipilih');
            return false;
        }
        temp=eval('form.bom_id_'+a+'.value');
        bom_id_param=bom_id_param+'&bom_id_'+a+'='+escape(encodeURIComponent(temp));
        if(temp=='false') {
            alert('Model untuk no. '+(a+1)+' belum dipilih');
            return false;
        }
        temp=eval('form.part_no_'+a+'.value');
        part_no_param=part_no_param+'&part_no_'+a+'='+escape(encodeURIComponent(temp));
        if(temp=='false') {
            alert('Part untuk no. '+(a+1)+' belum dipilih');
            return false;
        }
        temp=eval('form.stock_type_'+a+'.value');
        stock_type_param=stock_type_param+'&stock_type_'+a+'='+temp;
        if(temp=='false') {
            alert('Stock Type untuk no. '+(a+1)+' belum dipilih');
            return false;
        }
        temp=parseInt(eval('form.part_qty_'+a+'.value'));
        part_qty_param=part_qty_param+'&part_qty_'+a+'='+temp;
        if(isNaN(temp) || temp==0) {
            alert('Qty untuk no. '+(a+1)+' belum diisi');
            return false;
        }
    }
    postparam=param+'&alter='+escape(encodeURIComponent(form.alter.value))+'&hs_no='+escape(encodeURIComponent(hs_no))+'&swap_imei='+escape(encodeURIComponent(form.swap_imei.value))+'&swap_sn='+escape(encodeURIComponent(form.swap_sn.value))+'&fault_code='+form.fault_code.value+'&qty_input='+input_qty+'&notes='+escape(encodeURIComponent(form.notes.value))+bom_id_param+part_no_param+part_qty_param+stock_type_param;
    doAjax(cbackfile,postparam,'cback_engine_print(/'+print_file+'/,/'+param2+'/)','post','0',['ajax_loader','busy_view'],[]);
    return true;
}
function cback_upd_jobissue(msg, jn) {
    alert(msg);
    doAjax('./module/admin/engine/proses_edit_job_issue.php','&job_no='+jn,'cback_engine()','post','0',['ajax_loader','busy_view'],[]);
}
function del_jobissue(jobissue_no, bom_id, part_no, p_qty, j_no, is_handset) {
    if(is_handset=='Y') {
        doAjax('./module/admin/engine/del_jobissue_detail.php','&jobissue_no='+escape(encodeURIComponent(jobissue_no))+'&bom_id='+escape(encodeURIComponent(bom_id))+'&part_no='+escape(encodeURIComponent(part_no))+'&part_qty='+p_qty+'&is_handset='+escape(encodeURIComponent(is_handset)),'cback_upd_jobissue(/Part deleted.../,/'+j_no+'/)','post','0',['ajax_loader','busy_view'],[]);
        return true;
    } else {
        var answer=confirm('Are you sure want to delete this part?\r\n# '+part_no+' #');
        if(answer) {
            doAjax('./module/admin/engine/del_jobissue_detail.php','&jobissue_no='+escape(encodeURIComponent(jobissue_no))+'&bom_id='+escape(encodeURIComponent(bom_id))+'&part_no='+escape(encodeURIComponent(part_no))+'&part_qty='+p_qty+'&is_handset='+escape(encodeURIComponent(is_handset)),'cback_upd_jobissue(/Part deleted.../,/'+j_no+'/)','post','0',['ajax_loader','busy_view'],[]);
            return true;
        } else {
            return false;
        }
    }
}
//Quotation
function checkbox_void_invoice(form) {
    var input_part_cost=document.getElementById('part_cost');
    var input_service_cost=document.getElementById('service_cost');
    var quotation_status=document.getElementById('quo_status');
    if(form.void_invoice.checked) {
        input_part_cost.value='0';
        input_service_cost.value='0';
        quotation_status.selectedIndex=0;
        input_part_cost.disabled = true;
        input_service_cost.disabled = true;
        quotation_status.disabled = true;
    } else {
        input_part_cost.disabled = false;
        input_service_cost.disabled = false;
        quotation_status.disabled = false;
    }
}
function cback_quotation(text) {
    alert(text);
    goto_ref('create_quotation');
}
function cback_upd_quotation(text) {
    alert(text);
    goto_ref('edit_quotation');
}
function cek_save_quotation(form, param) {
    var postparam;
    var void_invoice_value='N';
    if(!form.void_invoice.checked) {
        if(form.part_cost.value=='' && form.service_cost.value=='') {
            alert("Total Part Cost & Service Cost belum diisi..\r\nMinimal salah satu harus diisi..");
            return false;
        }
    } else {
        void_invoice_value='Y';
    }
    postparam=param+'&part_cost='+form.part_cost.value+'&service_cost='+form.service_cost.value+'&void_invoice='+void_invoice_value+'&quo_status='+form.quo_status.value+'&notes='+escape(encodeURIComponent(form.notes.value));
    doAjax('./module/admin/engine/save_quotation.php',postparam,'cback_quotation()','post','0',['ajax_loader','busy_view'],['save_btn','back_to_prev']);
    return true;
}
function cek_update_quotation(form, param) {
    var postparam;
    var void_invoice_value='N';
    if(!form.void_invoice.checked) {
        if(form.part_cost.value=='' && form.service_cost.value=='') {
            alert("Total Part Cost & Service Cost belum diisi..\r\nMinimal salah satu harus diisi..");
            return false;
        }
    } else {
        void_invoice_value='Y';
    }
    postparam=param+'&part_cost='+form.part_cost.value+'&service_cost='+form.service_cost.value+'&void_invoice='+void_invoice_value+'&quo_status='+form.quo_status.value+'&notes='+escape(encodeURIComponent(form.notes.value));
    doAjax('./module/admin/engine/update_quotation.php',postparam,'cback_upd_quotation()','post','0',['ajax_loader','busy_view'],['save_btn','back_to_prev']);
    return true;
}
//QUALITY CONTROL
function get_checkbox3(form) {
    var c_value = '';
    var answer, param, type;
    if(form.c_box!=null) {
        if(form.submit_type_0.checked)type=form.submit_type_0.value;
        else if(form.submit_type_1.checked)type=form.submit_type_1.value;
        else {
            alert('You must choose submit type..');
            return false;
        }
        if(form.c_box.length==undefined) {
            if(form.c_box.checked) {
                c_value = "'" + form.c_box.value + "'";
            }
        } else {
            for(var i=0; i < form.c_box.length; i++) {
                if(form.c_box[i].checked) {
                    c_value = c_value + "'" + form.c_box[i].value + "',";
                }
            }
            c_value = c_value.substring(0,c_value.length-1);
        }
        if((c_value.length)>0) {
            answer=confirm('Update selected job?');
            if(answer) {
                param='&checked_box='+escape(encodeURIComponent(c_value))+'&submit_type='+type;
                doAjax('./module/tech/engine/get_check_qc.php',param,'cback_engine()','post','0',['ajax_loader','busy_view'],['back_to_prev','sel_page','src_input','btn_src','btn_submit']);
                form.reset();
            }
        }
        return true;
    } else {
        return false;
    }
}
//INVOICE
function confirm_invoice(form, param) {
    var postparam, temp;
    var n=form.tot_list.value;
    var n_param='&n_param='+form.tot_list.value;
    var price_param='';
    var part_no_param='';
    var bom_id_param='';
    for(a=1; a<=n; a++) {
        temp=parseInt(document.getElementById('part_'+a).value);
        price_param=price_param+'&part_'+a+'='+temp;
        if(isNaN(temp)) {
            alert('Unit Price untuk part no '+a+' belum diisi..');
            return false;
        }
        temp=escape(encodeURIComponent(document.getElementById('part_no_'+a).innerHTML));
        part_no_param=part_no_param+'&part_no_'+a+'='+temp;
        temp=escape(encodeURIComponent(document.getElementById('bom_id_'+a).value));
        bom_id_param=bom_id_param+'&bom_id_'+a+'='+temp;
    }
    if(form.notes.value=='') {
        alert('Notes masih kosong..');
        form.notes.select();
        return false;
    }
    postparam=param+price_param+part_no_param+bom_id_param+n_param+'&labour_cost='+escape(encodeURIComponent(form.labour_cost.value))+'&part_cost='+escape(encodeURIComponent(form.part_cost.value))+'&currency='+escape(encodeURIComponent(form.currency.value))+'&discount='+escape(encodeURIComponent(form.discount.value))+'&tax='+escape(encodeURIComponent(form.tax.value))+'&delivery_charge='+escape(encodeURIComponent(form.delivery_charge.value))+'&payment_type='+escape(encodeURIComponent(form.payment_type.value))+'&notes='+escape(encodeURIComponent(form.notes.value));
    doAjax('./module/admin/engine/confirm_invoice.php',postparam,'cback_engine()','post','0',['ajax_loader','busy_view'],['back_to_prev','currency','payment_type','btn_confirm']);
    return true;
}
function save_invoice(postparam, job_no, type) {
    var print_file='.~module~admin~engine~invoice_pdf.php';
    var post_job_no="'"+job_no+"'";
    var param='?total_checked=1&checked_box='+escape(encodeURIComponent(post_job_no));
    if(type=='save') {
        doAjax('./module/admin/engine/save_invoice.php',postparam,'cback_engine_print(/'+print_file+'/,/'+param+'/)','post','0',['ajax_loader','busy_view'],['back_to_prev','btn_save']);
    }
    else {
        var parameter, temp;
        var n=postparam.tot_list.value;
        var n_param='&n_param='+postparam.tot_list.value;
        var price_param='';
        var part_no_param='';
        var bom_id_param='';
        for(a=1; a<=n; a++) {
            temp=parseInt(document.getElementById('part_'+a).value);
            price_param=price_param+'&part_'+a+'='+temp;
            if(isNaN(temp)) {
                alert('Unit Price untuk part no '+a+' belum diisi..');
                return false;
            }
            temp=escape(encodeURIComponent(document.getElementById('part_no_'+a).innerHTML));
            part_no_param=part_no_param+'&part_no_'+a+'='+temp;
            temp=escape(encodeURIComponent(document.getElementById('bom_id_'+a).value));
            bom_id_param=bom_id_param+'&bom_id_'+a+'='+temp;
        }
        if(postparam.notes.value=='') {
            alert('Notes masih kosong..');
            postparam.notes.select();
            return false;
        }
        parameter='&job_no='+job_no+price_param+part_no_param+bom_id_param+n_param+'&labour_cost='+escape(encodeURIComponent(postparam.labour_cost.value))+'&part_cost='+escape(encodeURIComponent(postparam.part_cost.value))+'&currency='+escape(encodeURIComponent(postparam.currency.value))+'&discount='+escape(encodeURIComponent(postparam.discount.value))+'&tax='+escape(encodeURIComponent(postparam.tax.value))+'&delivery_charge='+escape(encodeURIComponent(postparam.delivery_charge.value))+'&payment_type='+escape(encodeURIComponent(postparam.payment_type.value))+'&inv_no='+escape(encodeURIComponent(postparam.inv_no.value))+'&notes='+escape(encodeURIComponent(postparam.notes.value));
        doAjax('./module/admin/engine/update_invoice.php',parameter,'cback_engine_print(/'+print_file+'/,/'+param+'/)','post','0',['ajax_loader','busy_view'],['back_to_prev','btn_save']);
    }
    return true;
}
//REPRINT
function get_checkbox_reprint(form,cbackfile,print_file) {
    var c_value = '';
    var answer, param;
    var total_checked=0;
    if(form.c_box!=null) {
        if(form.c_box.length==undefined) {
            if(form.c_box.checked) {
                c_value = "'" + form.c_box.value + "'";
                total_checked++;
            }
        } else {
            for(var i=0; i < form.c_box.length; i++) {
                if(form.c_box[i].checked) {
                    c_value = c_value + "'" + form.c_box[i].value + "',";
                    total_checked++;
                }
            }
            c_value = c_value.substring(0,c_value.length-1);
        }
        if((c_value.length)>0) {
            answer=confirm('Print selected Job?');
            if(answer) {
                param='?total_checked='+total_checked+'&checked_box='+escape(encodeURIComponent(c_value));
                doAjax(cbackfile,'','cback_engine_print(/'+print_file+'/,/'+param+'/)','post','0',['ajax_loader','busy_view'],['back_to_prev','sel_page','src_input','btn_src','btn_submit']);
                form.reset();
            }
        }
    }
}
function cback_engine_print(print_file,param,text) {
    var temp_str=print_file.replace(/~/g,'/');
    var randomer='&id='+Math.random();
    var ref_id_param='';
    var ref_id_temp;
    document.getElementById('main_content').innerHTML = text;
    var ref_id=document.getElementById('ref_id');
    if(ref_id!=null) {
        ref_id_temp="'"+ref_id.value+"'";
        ref_id_param='&checked_box='+escape(encodeURIComponent(ref_id_temp));
    }
    temp_str=temp_str+param+ref_id_param+randomer;
    document.getElementById('print_frame').src = temp_str;
    create_view('main_content');
}
function print_inventory(form) {
    var print_file='.~module~inventory~engine~stock_inventory_pdf.php';
    var param_scc=form.p_scc;
    if(param_scc==null) return false;
    if(param_scc.value=='false') return false;
    var param='?scc='+escape(encodeURIComponent(form.p_scc.value))+'&brand_id='+escape(encodeURIComponent(form.p_brand_id.value))+'&bom_id='+escape(encodeURIComponent(form.p_bom_id.value));
    doAjax('./module/inventory/engine/print_stock_inventory.php','','cback_engine_print(/'+print_file+'/,/'+param+'/)','post','0',['ajax_loader','busy_view'],[]);
    return true;
}
//SELLING
function cek_save_sell(form,cbackfile,print_file,param_id) {
    var postparam, temp;
    var brand_id_param='';
    var bom_id_param='';
    var part_no_param='';
    var part_qty_param='';
    var part_price_param='';
    var part_disc_param='';
    var subcon=form.subcon;
    var to_subcon='';
    var qty_temp_chk=form.qty_temp;
    var qty_value=0;
    var collect=form.collect_point_id;
    var to_collect='';
    var param='?total_checked=1';
    if(form.nama.value=='') {
        alert('Contact Name belum diisi..');
        form.nama.select();
        return false;
    }
    if(form.telp.value=='') {
        alert('Phone belum diisi..');
        form.telp.select();
        return false;
    }
    if(subcon!=null) {
        if(subcon.value=='false') {
            alert('Subcon belum dipilih');
            return false;
        } else {
            to_subcon=escape(encodeURIComponent(subcon.value));
        }
    }
    if(collect!=null) {
        if(collect.value=='false') {
            alert('Collect Point belum dipilih');
            return false;
        } else {
            to_collect=escape(encodeURIComponent(collect.value));
        }
    }
    if(qty_temp_chk!=null) {
        qty_value=form.qty_temp.value;
    }
    if(form.notes.value=='') {
        alert('Notes masih kosong...');
        form.notes.select();
        return false;
    }
    for(a=0;a<qty_value;a++) {
        temp=eval('form.brand_id_'+a+'.value');
        brand_id_param=brand_id_param+'&brand_id_'+a+'='+escape(encodeURIComponent(temp));
        if(temp=='false') {
            alert('Brand untuk no. '+(a+1)+' belum dipilih');
            return false;
        }
        temp=eval('form.bom_id_'+a+'.value');
        bom_id_param=bom_id_param+'&bom_id_'+a+'='+escape(encodeURIComponent(temp));
        if(temp=='false') {
            alert('Model untuk no. '+(a+1)+' belum dipilih');
            return false;
        }
        temp=eval('form.part_no_'+a+'.value');
        part_no_param=part_no_param+'&part_no_'+a+'='+escape(encodeURIComponent(temp));
        if(temp=='false') {
            alert('Part untuk no. '+(a+1)+' belum dipilih');
            return false;
        }
        temp=parseInt(eval('form.part_qty_'+a+'.value'));
        part_qty_param=part_qty_param+'&part_qty_'+a+'='+temp;
        if(isNaN(temp) || temp==0) {
            alert('Qty untuk no. '+(a+1)+' belum diisi');
            return false;
        }
        temp=parseInt(eval('form.part_price_'+a+'.value'));
        part_price_param=part_price_param+'&part_price_'+a+'='+temp;
        if(isNaN(temp)) {
            alert('Price untuk no. '+(a+1)+' belum diisi');
            return false;
        }
        temp=parseInt(eval('form.part_disc_'+a+'.value'));
        part_disc_param=part_disc_param+'&part_disc_'+a+'='+temp;
        if(isNaN(temp)) {
            alert('Discount untuk no. '+(a+1)+' belum diisi');
            return false;
        }
    }
    postparam='&nama='+escape(encodeURIComponent(form.nama.value))+'&telp='+escape(encodeURIComponent(form.telp.value))+'&subcon='+to_subcon+'&collect_point_id='+to_collect+'&payment_type='+form.payment_type.value+'&qty_input='+qty_value+'&notes='+escape(encodeURIComponent(form.notes.value))+brand_id_param+bom_id_param+part_no_param+part_qty_param+part_price_param+part_disc_param+param_id;
    doAjax(cbackfile,postparam,'cback_engine_print(/'+print_file+'/,/'+param+'/)','post','0',['ajax_loader','busy_view'],[]);
    return true;
}
function del_sell_detail(sell_id, part_no, p_qty, cbackfile) {
    var answer=confirm('Are you sure want to delete this part?\r\n# '+part_no+' #');
    if(answer) {
        doAjax('./module/admin/engine/del_sell_detail.php','&inv_no='+escape(encodeURIComponent(sell_id))+'&part_no='+escape(encodeURIComponent(part_no))+'&part_qty='+p_qty,'cback_upd_sell(/'+cbackfile+'/,/Part deleted.../,/'+sell_id+'/)','post','0',['ajax_loader','busy_view'],[]);
        return true;
    } else {
        return false;
    }
}
function cback_upd_sell(cbackfile, msg, jn) {
    var temp_str=cbackfile.replace(/~/g,'/');
    alert(msg);
    doAjax(temp_str,'&inv_no='+jn,'cback_engine()','post','0',['ajax_loader','busy_view'],[]);
}
function print_stock_summary(form, print_file, tipe) {
    var param_ref_no=form.p_ref_no;
    var param_brand_id=form.p_brand_id;
    if(param_ref_no==null && param_brand_id==null) return false;
    if(param_ref_no.value=='false' || param_brand_id.value=='false') return false;
    var param='?ref_no='+escape(encodeURIComponent(form.p_ref_no.value))+'&brand_id='+escape(encodeURIComponent(form.p_brand_id.value))+'&bom_id='+escape(encodeURIComponent(form.p_bom_id.value))+'&part_no='+escape(encodeURIComponent(form.p_part_no.value))+'&date1='+escape(encodeURIComponent(form.p_date1.value))+'&date2='+escape(encodeURIComponent(form.p_date2.value));
    doAjax('./module/inventory/engine/print_'+tipe+'.php','','cback_engine_print(/'+print_file+'/,/'+param+'/)','post','0',['ajax_loader','busy_view'],[]);
    return true;
}
function get_collect_list(form) {
    if(form.type_selector.value=='collect') {
        document.getElementById('collect_content').style.display='';
    } else {
        document.getElementById('collect_content').style.display='none';
        document.getElementById('collect_point_id').selectedIndex=0;
    }
}
function save_shipment(form,cbackfile,print_file,checked_job,param_id) {
    var postparam='&checked_jobno='+checked_job+'&notes='+escape(encodeURIComponent(form.notes.value))+param_id;
    var param='?total_checked=1';
    doAjax(cbackfile,postparam,'cback_engine_print(/'+print_file+'/,/'+param+'/)','post','0',['ajax_loader','busy_view'],[]);
    return true;
}
function cback_xml(field_output, tag_res, text) {
    var res = text.getElementsByTagName('hasil')[0].childNodes[0].nodeValue;
    if (res=='true') {
        var temp_res = text.getElementsByTagName(tag_res)[0].childNodes[0].nodeValue;
        document.getElementById(field_output).value=temp_res;
    }
}
function cback_select_engine3(sel_input,sel_output_1,sel_output_2,tag_id_1,tag_desc_1,tag_id_2,tag_desc_2,preselect_text_1,preselect_text_2,text) {
    var res = text.getElementsByTagName('hasil')[0].childNodes[0].nodeValue;
    var res2 = text.getElementsByTagName('hasil_2')[0].childNodes[0].nodeValue;
    var arr = new Array();
    var option_len_1 = document.getElementById(sel_output_1).length;
    var option_len_2 = document.getElementById(sel_output_2).length;
    var preselect_1, preselect_2, temp_id_1, temp_desc_1, result_id_1, result_desc_1, temp_id_2, temp_desc_2, result_id_2, result_desc_2;
    if(navigator.appName == "Microsoft Internet Explorer") {
        for(a=option_len_1; a>=0; a--) {
            document.getElementById(sel_output_1).options.remove(a);
        }
        for(a=option_len_2; a>=0; a--) {
            document.getElementById(sel_output_2).options.remove(a);
	}
        preselect_1 = document.createElement('OPTION');
        preselect_2 = document.createElement('OPTION');
        document.getElementById(sel_output_1).options.add(preselect_1);
        document.getElementById(sel_output_2).options.add(preselect_2);
        preselect_1.value = 'false';
        preselect_2.value = 'false';
        preselect_1.innerHTML = preselect_text_1;
        preselect_2.innerHTML = preselect_text_2;
        if (res=='true') {
            temp_id_1 = text.getElementsByTagName(tag_id_1)[0].childNodes[0].nodeValue;
            temp_desc_1 = text.getElementsByTagName(tag_desc_1)[0].childNodes[0].nodeValue;
            result_id_1 = temp_id_1.split('~');
            result_desc_1 = temp_desc_1.split('~');
            for(a=0; a<result_id_1.length; a++) {
                arr[a]= document.createElement('OPTION');
                document.getElementById(sel_output_1).options.add(arr[a]);
                arr[a].innerHTML = result_desc_1[a];
                arr[a].value = result_id_1[a];
            }
        }
        if (res2=='true') {
            temp_id_2 = text.getElementsByTagName(tag_id_2)[0].childNodes[0].nodeValue;
            temp_desc_2 = text.getElementsByTagName(tag_desc_2)[0].childNodes[0].nodeValue;
            result_id_2 = temp_id_2.split('~');
            result_desc_2 = temp_desc_2.split('~');
            for(a=0; a<result_id_2.length; a++) {
                arr[a]= document.createElement('OPTION');
                document.getElementById(sel_output_2).options.add(arr[a]);
                arr[a].innerHTML = result_desc_2[a];
                arr[a].value = result_id_2[a];
            }
        }
    } else {
        for(a=option_len_1; a>=0; a--) {
            document.getElementById(sel_output_1).remove(a);
        }
        for(a=option_len_2; a>=0; a--) {
            document.getElementById(sel_output_2).remove(a);
        }
        preselect_1 = document.createElement('OPTION');
        preselect_2 = document.createElement('OPTION');
        document.getElementById(sel_output_1).add(preselect_1, null);
        document.getElementById(sel_output_2).add(preselect_2, null);
        preselect_1.value = 'false';
        preselect_2.value = 'false';
        preselect_1.innerHTML = preselect_text_1;
        preselect_2.innerHTML = preselect_text_2;
        if (res=='true') {
            temp_id_1 = text.getElementsByTagName(tag_id_1)[0].childNodes[0].nodeValue;
            temp_desc_1 = text.getElementsByTagName(tag_desc_1)[0].childNodes[0].nodeValue;
            result_id_1 = temp_id_1.split('~');
            result_desc_1 = temp_desc_1.split('~');
            for(a=0; a<result_id_1.length; a++) {
                arr[a]= document.createElement('OPTION');
                document.getElementById(sel_output_1).add(arr[a], null);
                arr[a].innerHTML = result_desc_1[a];
                arr[a].value = result_id_1[a];
            }
        }
        if (res2=='true') {
            temp_id_2 = text.getElementsByTagName(tag_id_2)[0].childNodes[0].nodeValue;
            temp_desc_2 = text.getElementsByTagName(tag_desc_2)[0].childNodes[0].nodeValue;
            result_id_2 = temp_id_2.split('~');
            result_desc_2 = temp_desc_2.split('~');
            for(a=0; a<result_id_2.length; a++) {
                arr[a]= document.createElement('OPTION');
                document.getElementById(sel_output_2).add(arr[a], null);
                arr[a].innerHTML = result_desc_2[a];
                arr[a].value = result_id_2[a];
            }
        }
    }
}
function del_stock_det(ref_no, from_scc, to_scc, bom_id, part_no, p_qty) {
    var answer=confirm('Are you sure want to delete this part?\r\n# '+part_no+' #');
    if(answer) {
        doAjax('./module/inventory/engine/del_stock_detail.php','&ref_no='+escape(encodeURIComponent(ref_no))+'&from_scc='+escape(encodeURIComponent(from_scc))+'&to_scc='+escape(encodeURIComponent(to_scc))+'&bom_id='+escape(encodeURIComponent(bom_id))+'&part_no='+escape(encodeURIComponent(part_no))+'&part_qty='+p_qty,'cback_upd_stock(/Part deleted.../,/'+ref_no+'/)','post','0',['ajax_loader','busy_view'],[]);
        return true;
    } else {
        return false;
    }
}
function cback_upd_stock(msg, jn) {
    alert(msg);
    if(jn.substr(2,2)=='IN') {
        doAjax('./module/inventory/engine/get_edit_stockin.php','&ref_no='+jn,'cback(/edit_form/)','post','0',['ajax_loader','busy_view'],[]);
    } else if(jn.substr(2,2)=='OU') {
        doAjax('./module/inventory/engine/get_edit_stockout.php','&ref_no='+jn,'cback(/edit_form/)','post','0',['ajax_loader','busy_view'],[]);
    }
}
function calc_total() {
    var temp_tot=0;
    var n=document.getElementById('tot_list').value;
    var p;
    var q;
    for(a=1; a<=n; a++) {
        p=parseInt(document.getElementById('part_'+a).value);
        if(isNaN(p))p=0;
        q=parseInt(document.getElementById('qty_'+a).innerHTML);
        if(isNaN(q))q=0;
        temp_tot=temp_tot+(p*q);
    }
    document.getElementById('part_cost').value=temp_tot;
}
function cek_curr_imei(curr_imei, curr_state) {
    var edited_imei=document.getElementById('imei').value;
    edited_imei=edited_imei.trim();
    edited_imei=edited_imei.toUpperCase();
    curr_imei=curr_imei.toUpperCase();
    if(curr_imei==edited_imei) {
        document.getElementById('hsl_imei').innerHTML = '';
        document.getElementById('hsl_job').innerHTML = '';
        close_view('hsl_job');
        document.getElementById('repeated').value = curr_state;
        return false;
    } else {
        doAjax('./module/cs/engine/cek_imei.php','&imei='+escape(encodeURIComponent(edited_imei)),'cback_imei()','post','1',['ajax_loader'],[]);
        return true;
    }
}
function close_view(element) {
    document.getElementById(element).style.display='none';
}
function open_view(element) {
    document.getElementById(element).style.display='';
}
function view_haier(element, selector) {
    if(selector=='BRD-004') {
        document.getElementById(element).style.display='';
    } else {
        document.getElementById(element).style.display='none';
    }
}
function edit_current(cust_type, cust_id, j_no) {
    if(cust_type=='Walkin') {
        doAjax('./module/cs/engine/edit_walkin.php','&cust_id='+escape(encodeURIComponent(cust_id))+'&job_no='+escape(encodeURIComponent(j_no))+'&view_setting=inline','cback(/edit_cust/)','post','0',['ajax_loader'],[]);
    } else {
        doAjax('./module/cs/engine/edit_collect_user.php','&cust_id='+escape(encodeURIComponent(cust_id))+'&job_no='+escape(encodeURIComponent(j_no))+'&view_setting=inline','cback(/edit_cust/)','post','0',['ajax_loader'],[]);
    }
}
function cback_special(param) {
    doAjax('./module/admin/engine/proses_edit_job_form.php',param,'cback_jobform()','post','0',['ajax_loader','busy_view'],[]);
}
function reset_select(select_element, select_text) {
    var preselect;
    var option_len = document.getElementById(select_element).length;
    if(navigator.appName == "Microsoft Internet Explorer") {
        for(a=option_len; a>=0; a--) {
            document.getElementById(select_element).options.remove(a);
        }
	preselect = document.createElement('OPTION');
	document.getElementById(select_element).options.add(preselect);
	preselect.value = 'false';
	preselect.innerHTML = select_text;
    } else {
        for(a=option_len; a>=0; a--) {
            document.getElementById(select_element).remove(a);
        }
        preselect = document.createElement('OPTION');
        document.getElementById(select_element).add(preselect, null);
        preselect.value = 'false';
        preselect.innerHTML = select_text;
    }
}
function cback_w_ref(ref, text) {
    alert(text);
    goto_ref(ref);
}
function cekform_user(form, param, tipe) {
    var postparam;
    if(form.username.value=="") {
        alert("Username belum diisi...");
        form.username.select();
        return false;
    }
    if(form.pass1.value=="") {
        alert("Password belum diisi...");
        form.pass1.select();
        return false;
    }
    if(form.pass2.value=="") {
        alert("Confirm Password belum diisi...");
        form.pass2.select();
        return false;
    }
    if(form.pass1.value!=form.pass2.value) {
        alert('Password yang anda ketik tidak sama..');
        form.pass1.select();
        return false;
    }
    if(form.nama.value=="") {
        alert("Nama lengkap belum diisi..");
        form.nama.select();
        return false;
    }
    postparam=param+"&username="+escape(encodeURIComponent(form.username.value))+"&password="+escape(encodeURIComponent(form.pass1.value))+"&scc="+escape(encodeURIComponent(form.scc.value))+"&rule_id="+escape(encodeURIComponent(form.rule_id.value))+"&email="+escape(encodeURIComponent(form.email.value))+"&nama_lengkap="+escape(encodeURIComponent(form.nama.value));
    if(tipe=='save') {
            doAjax('./module/sysconfig/engine/save_user.php',postparam,'cback_w_ref(/add_user/)','post','0',['ajax_loader', 'busy_view'],['username', 'pass1', 'pass2', 'scc', 'rule_id', 'email', 'nama']);
    } else {
            doAjax('./module/sysconfig/engine/update_user.php',postparam+'&cust_id='+escape(encodeURIComponent(form.cust_id.value)),'cback_w_ref(/edit_user/)','post','0',['ajax_loader', 'busy_view'],['username', 'pass1', 'pass2', 'scc', 'rule_id', 'email', 'nama']);
    }
    return true;
}