//-----
function open_window(s_url, s_name, s_prop) {
  if (!(s_prop)) s_prop = 'status=yes,scrollbars=yes,resizable=yes,width=400,height=500'
  window.open(s_url, s_name, s_prop)
}
//-----
function copy_to_parent(s_elm, s_val) {
  eval('window.opener.frm.' + s_elm + ".value = '" + s_val + "'");
}
//-----
function confirm_action(vs_dialog, vs_href) {
  if (confirm(vs_dialog)) {
    document.location.href = vs_href;
  }
}
// return if is blank
function is_not_blank(o_ctl, s_msg) {
	if ("" == trim_str(o_ctl.value)) {
    return show_err(s_msg, o_ctl, true, true);
  }
  return true;
}
//-----
function is_valid_date(o_ctl, s_msg) {
  var b_temp =
    is_num(o_ctl[0], s_msg + ". Please enter numeric value between 1 and 31", 1, 31) &&
    is_selected(o_ctl[1], s_msg + ". Please select month") &&
    is_not_blank(o_ctl[2], s_msg + ". Please enter the year");
  if (!b_temp) return false;
  return true;
}

// return if is selected
function is_selected(o_ctl, s_msg) {
	if (o_ctl.selectedIndex == 0) {
    return show_err(s_msg, o_ctl, true, false);
  }
  return true;
}

// return if is numeric
function is_num(o_ctl, s_msg, n_low, n_high)
{
	if ("" != trim_str(o_ctl.value)) {
    if (!(is_int_in_range(o_ctl.value, n_low, n_high))) {
      return show_err(s_msg, o_ctl, true, true);
    }
  } else {
    return show_err(s_msg, o_ctl, true, true);
  }
  return true;
}

// trim string
function trim_str(s)
{
	var slen = ("" + s).length;
	for (var i = 0; i < slen && s.charAt(i) == " "; i++);
	for (var n = slen - 1; n > i && s.charAt(n) == " "; n--);
	return s.substring(i, n+1);
}

// string length
function is_str_in_range(s, lowBound, hiBound)
{
	var slen = ("" + s).length;
	return ((1 * slen >= 1* lowbound) && (1 * slen <= 1 * hiBound));
}

// integer in range
function is_int_in_range(u_var, n_lbound, n_hbound)
{
	var u_temp = "" + u_var, u_varInt = parseInt(u_var, 10);
	return (!isNaN(u_varInt) && ("" + u_varInt == u_temp) &&
    (1 * u_varInt >= 1 * n_lbound) && (1 * u_varInt <= 1 * n_hbound));
}
/*function is_int_in_range(chk, lowBound, hiBound)
{
	var chkStr = "" + chk, chkInt = parseInt(chk, 10);
	return (!isNaN(chkInt) && ("" + chkInt == chkStr) && 
    (1 * chkInt >= 1 * lowBound) && (1 * chkInt <= 1 * hiBound));
}*/

// floating in range
function is_float_in_range(chk, lowBound)
{
	var chkStr = "" + chk
	return (!isNaN(parseFloat(chk)) && ("" + parseFloat(chk) == chkStr) && (1 * parseFloat(chk) >= 1 * lowBound));
}

// cek banyak email dibatasi ';'
function is_valid_email(field) {
  var b_valid = true;
  chunk = field.split(";");
  for (var j=0; j<chunk.length; j++) {
    chunk[j] = trim_str(chunk[j]);
    b_valid = b_valid && valid_email(chunk[j]);
  }
  return b_valid;
}

// valid email
function valid_email(strchkEmail)
{
	var nullChar = 0
  var normChar = 1
  var dotChar = 2
  var atChar = 3
  var dashChar = 4
  var aChar
  var currentCharType = nullChar
  var atExist = false
  var dotExist = false
  var sLen = strchkEmail.length;

	if (sLen < 7) return false;

	strchkEmail = strchkEmail.toLowerCase();

	for (var i = 0; i < sLen; i++) {
		aChar = strchkEmail.charAt(i);
		if (aChar == "@") {
			if (atExist || (i < 1) || (i > sLen - 6) || (currentCharType == dotChar)) return false;
			atExist = true;
			currentCharType = atChar;
		}
		else if (aChar == ".") {
			if ((i > sLen - 3) || (currentCharType != normChar)) return false;
			dotExist = true;
			currentCharType = dotChar;
		}
		else if ((aChar == "_") || (aChar == "-")) {
			if (i > sLen - 5 || currentCharType != normChar) return false;
			currentCharType = dashChar;
		}
		else {
			if (("abcdefghijklmnopqrstuvwxyz01234567890").indexOf(aChar) == -1) return false;
			currentCharType = normChar;
		}
	}
	return (dotExist && atExist);
}

// minimal string length
function ValidLength(item, len) {
   return (item.length >= len);
} 

// show error
function error(s_err, o_elm, b_focus, b_select) {
   if (errfound) return;
   alert(s_err);
   if (b_focus) o_elm.focus();
	 if (b_select) o_elm.select();
   errfound = true;
}

// valid password
function valid_userpassword(s_string) {
  s_string = s_string.toLowerCase();
  var n_len = s_string.length;
  b_value = true;
  for (var n_loop=0; n_loop<n_len; n_loop++) {
    s_char = s_string.charAt(n_loop);
    if (("_abcdefghijklmnopqrstuvwxyz0123456789").indexOf(s_char) == -1) {
		b_value = false;
		break;
	}
  }
  return b_value;
}

function valid_code(s_string) {
  s_string = s_string.toLowerCase();
  var n_len = s_string.length;
  b_value = true;
  for (var n_loop=0; n_loop<n_len; n_loop++) {
    s_char = s_string.charAt(n_loop);
    if (("_abcdefghijklmnopqrstuvwxyz0123456789-").indexOf(s_char) == -1) {
		b_value = false;
		break;
	}
  }
  return b_value;
}

function setPointer(theRow, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor = (thePointerColor != '')
                     ? thePointerColor
                     : theDefaultColor;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

/*-- COnvert available in NetS 
function togl_disp_dom(vs_dom, vs_img) {
	var o_dom = document.getElementById(vs_dom);
	var o_img = document.getElementById(vs_img);
	if (o_dom.style.display == 'none') {
		o_dom.style.display = 'block';
		if (vs_img) {
			o_img.src = ICO_HIDE;
			o_img.alt = 'Hide';
		}
	} else {
		o_dom.style.display = 'none';
		if (vs_img) {
			o_img.src = ICO_SHOW;
			o_img.alt = 'Show';
		}
	}
}*/

/**
 * Expand DOM
 *
 * @updated 2004-09-28 15:17 <asep@konsep.net> :
 * - change imgnonevis.src path from /images/nav/ico_hide.gif to /webadmin/images/nav/ico_hide.gif
 * - change imgvis.src path from /images/nav/ico_show.gif to /webadmin/images/nav/ico_show.gif
 *
 * @created -
 * @updated -
 */
function expand_dom(vs_dom) {
  imgnonevis = new Image();
  imgnonevis.src = "/webadmin/images/nav/ico_hide.gif";
  imgvis = new Image();
  imgvis.src = "/webadmin/images/nav/ico_show.gif";
  if (vs_dom.style.display=="none") {
    vs_dom.style.display="";
    document["srchshow"].src = imgnonevis.src;
  } else {
    vs_dom.style.display="none";
    document["srchshow"].src = imgvis.src;
  }
}

function expand_elm(vs_elm) {
  if (vs_elm.style.display=="none") {
    vs_elm.style.display="";
  } else {
    vs_elm.style.display="none";
  }
}

/*****************************************************************************************
* Expand DOM
*
* @created	2002-09-05 21:53 <ivan@konsep.net>
*****************************************************************************************/
function togl_disp_dom(vs_dom, vs_img) {
	var o_dom = document.getElementById(vs_dom);
	var o_img = document.getElementById(vs_img);
	if (o_dom.style.display == 'none') {
		o_dom.style.display = 'block';
		if (vs_img) {
			o_img.src = ICO_HIDE;
			o_img.alt = 'Hide';
		}
	} else {
		o_dom.style.display = 'none';
		if (vs_img) {
			o_img.src = ICO_SHOW;
			o_img.alt = 'Show';
		}
	}
}
/*****************************************************************************************
* Expand Menu
*
* @created	2002-09-04 02:23 <ivan@konsep.net>
*****************************************************************************************/
function expand_menu(vn_menu) {
	var o_current=document.getElementById('menu'+vn_menu+'');
	if (o_current!=null) {
		//eval('var o_current=menu'+vn_menu+'');
		if (o_current.style.display=='none') {
			o_current.style.display='table';
		} else {
			o_current.style.display='none';
		}
		for (var i=1;i<=4;i++) {
			var o_mnu=document.getElementById('menu'+i+'');
			if (o_mnu!=null && i!=vn_menu) o_mnu.style.display='none';
		}
	}
}

function toggle_check_all(o_fm, s_chk, s_elm, s_tot) {
	var o_chk = document.frm[s_chk].checked;
	var o_elm = document.frm[s_elm + '[]'].length;
	//n_len = document.frm[s_elm].value;
	n_len = s_tot;
	
	if (n_len == 1)	{
		document.frm[s_elm + '[]'].checked = o_chk;
	} else {
		for (var n_loop=0; n_loop<o_elm; n_loop++) {
			document.frm[s_elm + '[]'][n_loop].checked = o_chk;
		}
	}
}

/* -- NEW -- */

/*****************************************************************************************
* Add GL item entry
*
* @created	2003-05-08 22:30 <ivan@konsep.net>
*****************************************************************************************/
/*function add_gli_row() {
	var o_tbl	= document.all.tbl_entry;
	var n_len	= o_tbl.rows.length - 1;
	var n_len2	= n_len - 1;
	var a_cell	= new Array(
		'<a href="javascript:del_gli_row(' + n_len2 + ')">' + ICO_DEL + '</a>',
		'' + n_len + '.<input type="hidden" name="gli_line" value="' + n_len + '" />', 
		html_inp_txt('coa_code', '', 8, 15, 'style="' + HTM_STY_WIDTH + '" onblur="rs_get_acc(' + n_len2 + ')"'), 
		html_inp_txt('coa_name', '', 20, 100, 'style="' + HTM_STY_WIDTH + '"  ' + HTM_DISABL + ''), 
		html_inp_txt('gli_name', '', 20, 100, 'style="' + HTM_STY_WIDTH + '"'), 
		html_inp_txt('gli_amntd', '', 12, 15, 'style="' + HTM_STY_WIDTH + '" onkeyup="calc_gli(' + n_len2 + ', 1)"'), 
		html_inp_txt('gli_amntc', '', 12, 15, 'style="' + HTM_STY_WIDTH + '" onkeyup="calc_gli(' + n_len2 + ', 1)"')
	);
	var n_loop1	= a_cell.length;
	var o_row	= o_tbl.insertRow(n_len);
	var s_bg	= (n_len % 2 != 0) ? '#FFFFFF' : '#EEEEEE';
	o_row.setAttribute('bgColor', s_bg)
	for (i = 0; i < n_loop1; i++) {
		o_row.insertCell().innerHTML = a_cell[i];
		if (i >= 4 || i == 1) {
			o_row.cells[i].setAttribute('align', "right")
		}
	}
}*/

function add_row() {
	var o_tbl	= document.all.tbl_entry;
	var n_len	= o_tbl.rows.length - 1;
	var n_len2	= n_len - 1;
	alert(o_tbl);
	/*var a_cell	= new Array(
		'<a href="javascript:del_gli_row(' + n_len2 + ')">' + ICO_DEL + '</a>',
		'' + n_len + '.<input type="hidden" name="gli_line" value="' + n_len + '" />', 
		html_inp_txt('coa_code', '', 8, 15, 'style="' + HTM_STY_WIDTH + '" onblur="rs_get_acc(' + n_len2 + ')"'), 
		html_inp_txt('coa_name', '', 20, 100, 'style="' + HTM_STY_WIDTH + '"  ' + HTM_DISABL + ''), 
		html_inp_txt('gli_name', '', 20, 100, 'style="' + HTM_STY_WIDTH + '"'), 
		html_inp_txt('gli_amntd', '', 12, 15, 'style="' + HTM_STY_WIDTH + '" onkeyup="calc_gli(' + n_len2 + ', 1)"'), 
		html_inp_txt('gli_amntc', '', 12, 15, 'style="' + HTM_STY_WIDTH + '" onkeyup="calc_gli(' + n_len2 + ', 1)"')
	);
	var n_loop1	= a_cell.length;
	var o_row	= o_tbl.insertRow(n_len);
	var s_bg	= (n_len % 2 != 0) ? '#FFFFFF' : '#EEEEEE';
	o_row.setAttribute('bgColor', s_bg)
	for (i = 0; i < n_loop1; i++) {
		o_row.insertCell().innerHTML = a_cell[i];
		if (i >= 4 || i == 1) {
			o_row.cells[i].setAttribute('align', "right")
		}
	}*/
}
/*****************************************************************************************
* Delete GL item entry
*
* @updated	2003-05-12 13:17 <ivan@konsep.net>
* @created	2003-05-12 11:24 <ivan@konsep.net>
*****************************************************************************************/
function del_gli_row(vn_idx) {
	var o_tbl	= document.all.tbl_entry;
	var o_fm	= document.all.frm;
	var n_loop1	= o_tbl.rows.length - 2;
	if (n_loop1 > 1) {								// maintain at least 1 row
		o_tbl.deleteRow(vn_idx + 1);
		for (i = vn_idx + 1; i < n_loop1; i++) {
			var n_idx = i - 1;
			o_tbl.rows[i].cells[0].innerHTML = '<a href="javascript:del_gli_row(' + n_idx + ')">' + ICO_DEL + '</a>';
			o_tbl.rows[i].cells[1].innerHTML = '' + i + '. <input type="hidden" name="gli_line" value="' + (i) + '" />';
			o_tbl.rows[i].cells[2].innerHTML = html_inp_txt('coa_code', o_fm.coa_code[n_idx].value, 8, 15, 'style="' + HTM_STY_WIDTH + '" onblur="rs_get_acc(' + n_idx + ')"');
		}
	} else {
		alert(STR_FGJE_LEFT_ONE);
	}
	calc_gli();
}

/*function del_row(vn_idx) {
	var o_tbl	= document.all.tbl_entry;
	var o_fm	= document.all.frm1;
	alert("pas");
	var n_loop1	= o_tbl.rows.length - 2;
	if (n_loop1 > 1) {								// maintain at least 1 row
		o_tbl.deleteRow(vn_idx + 1);
		for (i = vn_idx + 1; i < n_loop1; i++) {
			var n_idx = i - 1;
			o_tbl.rows[i].cells[0].innerHTML = '<a href="javascript:del_row(' + n_idx + ')">' + ICO_DEL + '</a>';
			o_tbl.rows[i].cells[1].innerHTML = '' + i + '. <input type="hidden" name="gli_line" value="' + (i) + '" />';
			o_tbl.rows[i].cells[2].innerHTML = html_inp_txt('coa_code', o_fm.coa_code[n_idx].value, 8, 15, 'style="' + HTM_STY_WIDTH + '" onblur="rs_get_acc(' + n_idx + ')"');
		}
	} else {
		alert(STR_FGJE_LEFT_ONE);
	}
	calc_gli();
}*/

/*****************************************************************************************
* Handle GL entry
*
* @created	2003-04-03 13:26 <ivan@konsep.net>
*****************************************************************************************/
function handle_gli_entry(vu_idx) {
	var o_fm	= document.all.frm;
	var n_idx	= o_fm.gli_line.length;
	if ((o_fm.gli_line[n_idx - 2].value != '') && (vu_idx == n_idx - 2)) {
		add_gli_row();
	}
}

/*****************************************************************************************
* Calc GL entry
*
* @created	2003-05-09 06:29 <ivan@konsep.net>
*****************************************************************************************/
function calc_gli(n_idx, opt) {
	var o_fm	= document.all.frm;
	var n_loop1	= o_fm.gli_line.length - 1;
	var n_amntd	= 0;
	var n_amntc	= 0;
	if (n_idx) {
		if (o_fm.gli_amntd[n_idx].value != '' && opt == 1) o_fm.gli_amntc[n_idx].value = '';
		if (o_fm.gli_amntc[n_idx].value != '' && opt == 2) o_fm.gli_amntd[n_idx].value = '';
	}
	for (i = 0; i < n_loop1; i++) {
		n_amntd	= n_amntd + (o_fm.gli_amntd[i].value == '' ? 0 : parseFloat(o_fm.gli_amntd[i].value));
		n_amntc	= n_amntc + (o_fm.gli_amntc[i].value == '' ? 0 : parseFloat(o_fm.gli_amntc[i].value));
	}
	o_fm.gli_amntd_tot.value	= n_amntd;
	o_fm.gli_amntc_tot.value	= n_amntc;
}


/*****************************************************************************************
* Remote script get account
*
* @created	2003-05-09 13:11 <ivan@konsep.net>
*****************************************************************************************/
function rs_get_acc(vn_idx) {
	var o_fm	= document.all.frm;
	var s_code	= o_fm.coa_code[vn_idx].value;
	if (s_code != '') {
		var s_ret = RSExecute(JS_RES_SVR, "get_acc_svr", s_code);
		if (s_ret.return_value != '') {
			o_fm.coa_name[vn_idx].value = s_ret.return_value;
			handle_gli_entry(vn_idx);
		} else {
			o_fm.coa_name[vn_idx].value = '';
			return show_err(STR_FGJE_ACC_ERR, o_fm.coa_code[vn_idx], true, true);
		}
	}
}

function toggle_check_all_prd(s_chk, s_elm) {
	var b_val=(document.frm[s_chk].checked);
	for (var n_loop=0; n_loop<document.frm.tot_item.value; n_loop++) {
		document.frm[s_elm + '[' + n_loop +']'].checked = b_val;
	}
}

function valid_hta(s_frm, s_type, s_name) {
	idContent = "HTA_DOC" + s_type;	
	idElement = document.getElementById(s_name);
	//idElement = document.getElementById('nw_con_' + s_tmp);

	if (HTA_DISP_MODE == 'HTML') { //03 Nov 2004, 03:18 <str> : displayMode as written in js_ace.js
		eval(idContent).document.body.innerHTML = eval(idContent).document.body.innerText;
	}
	idElement.value = eval(idContent).document.body.innerHTML;
	return true;
}
/** EOF NEW **/
