var isopen=0;
var xmlhttp=null;
var oStdAlone=null; // 'STANDALONE' field
var iNoLogout=false;
var gridID=new Array();
var gridID2=new Array();
var field_data=null;
var all_data=null;
var gmouse={x:0, y:0};
var oPopup=null;
var _popT1;
var _dsb=null;
var saved_awcols=false;
var SavePageColsUrl=null;
var NewFormMethod='POST';
var CSRFToken = null;

/* trim polyfill */
if (!String.prototype.trim) {
   (function() {
     // Make sure we trim BOM and NBSP
     var rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
     String.prototype.trim = function() {
       return this.replace(rtrim, '');
     };
   })();
 }

SetSaveColUrl();

function SetSaveColUrl()
{
   var ar1=location.href.split('/');
   if (ar1.length<=0)
      return;

   ar1.pop();
   ar1.push('ishop_visual.php');
   SavePageColsUrl=ar1.join('/');
}

try {
   $(function(){ $(document).foundation(); });
}
catch (e) {}

try {
   $(function(){
      try {
         document.body.onbeforeunload=bodyUnloading;
         document.body.onunload=bodyUnloading;
      }
      catch (e) {}

      if ($.datepicker) {
         $.datepicker.setDefaults({dateFormat: 'dd-mm-yy', changeMonth: true, changeYear: true});
         $('.date').attr('readonly', 'readonly').datepicker();
      }

      $('.xNORMAL, .xHILINE').on('mouseenter', function(){
            $(this).addClass('xNORMAL2Over');
         } ).on('mouseleave', function(){
            $(this).removeClass('xNORMAL2Over');
      } );

   });
}
catch (e) {}

function fillzero2(s1)
{
   while (s1.toString().length<2) {
      s1 = '0' + s1.toString();
   }
   return s1;
}

Date.prototype.toGrk2String=function() {
   var daysSort=['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
   var x = this.getDay(); // 0=sunday
   var s1 = daysSort[x] + ' ' + this.getDate() +'/' + (this.getMonth()+1) + '/' + this.getFullYear() + ' '
      + fillzero2(this.getHours()) + ':' + fillzero2(this.getMinutes()) + ':' + fillzero2(this.getSeconds());
   return s1;
};

$(document).mousedown(function(evt){
   gmouse.x=evt.pageX;
   gmouse.y=evt.pageY;
} );

function GetGoForm()
{
   g=document.goForm;
	if (g==null) {
      g=document.createElement('FORM');
      g.name='goForm';
      g.method=NewFormMethod;
      g.action=location.pathname;
      document.body.appendChild(g);
   }
   else if (g.constructor === HTMLCollection) {
      g = g[0];
   }
   return g;
}

function cPAGESIZE() { // object definition
   this.resetNavButtons=resetNavButtons;
   this.resetSize=doResetPgSize;
   this.movePage=goMovePageEx;
   this.fu=0;
   this.pg=1;
   this.epage=0;
}

/*
cPAGESIZE.prototype.resetSize=doResetPgSize;
cPAGESIZE.prototype.movePage=goMovePageEx;
cPAGESIZE.prototype.fu=0;
cPAGESIZE.prototype.pg=1;
cPAGESIZE.prototype.epage=0;
*/

var cPageSize=new cPAGESIZE();

function cDYNPAGER(_ogrid, _pgsz, _pg) { // object definition
   this.ogrid = _ogrid;
   this.pgsz = _pgsz;
   this.pg = _pg;

   cPAGESIZE.prototype.resetSize=dynResetPageSize;
   cPAGESIZE.prototype.movePage=dynMovePage;
}

var cDynPager=null;

function dynResetPageSize(fx)
{
   let newsz=parseInt($('#pgsize').val());
   if (isNaN(newsz))
      return;

   let d1 = new Date();
   d1.setYear( d1.getFullYear()+1 ); // increase by 1 year
   document.cookie='ADOPAGESIZE='+newsz+';expires='+d1.toGMTString()+';';

   pgsz=newsz;
   cDynPager.ogrid.clearAll(); // need call this because we may gona have less records
   cDynPager.reloadPage();
}

function dynMovePage(fx,pg2)
{
   cDynPager.pg=pg2;
   cDynPager.ogrid.clearAll(); // need call this because we may gona have less records
   cDynPager.reloadPage();
}

function mouseTrack(evt)
{
   if (document.all) { // IE
      gmouse.x = event.clientX;
      gmouse.y = event.clientY;
   }
   else { // not IE
      gmouse.x = evt.pageX;
      gmouse.y = evt.pageY;
   }
}

function goBottom()
{ // requires jquery
   try {
      window.scrollTo(0, $(document).height());
   }
   catch (e) {
      alert(e);
   }
}

function endofPage() {
  ; // discontinued
}
function pathnameEx()
{
	let val=location.pathname;
	// Correct HTA bug
   if (val.substring(0,1)!='/')
   	val = '/'+val;

   return val;
}

function iadmin_str()
{
   var ss=document.cookie.split(';');

   for (i=0;i<ss.length;i++) {
      while (ss[i].substr(0,1)==' ')
         ss[i]=ss[i].substr(1);

      ss2=ss[i].split('=');
      if (ss2.length==2 && ss2[0]=='iAdmin') {
         return '&'+ss[i];
      }
   }

   // Return empty string
   return '';
}

function win_openEx()
{
   var nargs = arguments.length;

   switch (nargs)
   {
   case 0:
      // do nothing
      break;
   case 1:
      window.open(arguments[0]);
      break;
   case 2:
      window.open(arguments[0], arguments[1]);
      break;
   default:
      window.open(arguments[0], arguments[1], arguments[2]);
      break;
   }
}

function queryNewWin()
{
   var f1=document.goForm;

   var opw=document.getElementById('openewin')
   if (opw==null || !opw.checked) {
      f1.target='';
      return;
   }

   if (f1.iAdmin==null) {
      o2=document.createElement('INPUT');
      o2.type='HIDDEN';
      o2.name='iAdmin';
      ar1=iadmin_str().split('=');
      if (ar1.length==2) {
         o2.value=ar1[1];
         f1.appendChild(o2);
      }
   }

   // oStdAlone is a global variable
   if (oStdAlone==null)
      oStdAlone=f1.STANDALONE;
   if (oStdAlone==null) { // still null
      oStdAlone=document.createElement('INPUT');
      oStdAlone.type='HIDDEN';
      oStdAlone.name='STANDALONE';
      f1.appendChild(oStdAlone);
   }
   oStdAlone.value="1";

   f1.target='_blank';
}
function resetOldWin()
{
   var f1=document.goForm;
   f1.action=window.location.pathname;
   f1.target='';
   if (oStdAlone!=null)
      oStdAlone.value='';
}
function iescape(login)
{
   var ret='';
   var l=login.length;
   for (i=0;i<l;i++) {
      c=login.charAt(i);
      if ((c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z')) {
         ret+=c;
         continue;
      }
      x=login.charCodeAt(i);
      if (x>127) {
         ret+=c;
         continue;
      }
      ret+=encodeURIComponent(c);
   }
   return ret;
}
function copy_fdata()
{
	if (field_data==null)
		return;

   hide_popup();

   if ($('#field_data_div').length>0) {
      $('#field_data_div').show();
   }
   else {
	  $(document.body).append('<div id=field_data_div style="position:absolute;top:0px;left:0px;padding:20px;">'+
         '<INPUT id=field_data_text TYPE=TEXT><button type=button onclick="$(\'#field_data_div\').hide()">Close</button>'+
         '</div>');
   }
	$('#field_data_text').val(field_data).focus();
}
function copy_alldata()
{
	if (all_data==null)
		return;

	let o1=document.createElement('<INPUT TYPE=TEXT style="position:absolute;top:0px;left:0px;">');
	o1.value=all_data.join('\t');
	document.body.appendChild(o1);
	o1.select();
	document.execCommand('Copy');
	document.body.removeChild(o1);
}
function formGoTo(g, go) { // go: generic object
   var _fx=0, _target=null;

   if (typeof go === 'object') {
      if (go.fx) {
         _fx = go.fx;
      }

      if (go.target) {
         _target = go.target;
      }
   }
   else { // not an object, it directly defines fx
      _fx = go;
   }

   var o2=g.FUNCTION;
   if (o2==undefined) {
      o2=document.createElement('INPUT');
      o2.type='hidden';
      o2.name='FUNCTION';
      g.appendChild(o2);
   }
   o2.value = _fx;

   if (CSRFToken !== null)
   {
      o2=g.CSRFToken;
      if (o2==undefined) {
         o2=document.createElement('INPUT');
         o2.type='hidden';
         o2.name='CSRFToken';
         g.appendChild(o2);
      }
      o2.value = CSRFToken;
   }

   if (_target!=null) {
      g.target = _target;
   }

  	g.submit();
}
function goTo(fx) {
	var g=GetGoForm();
   formGoTo(g,fx);
  /*
   var url = location.pathname + '?FUNCTION=' + fx;
   if (CSRFToken !== null)
   {
      url += '&CSRFToken=' + encodeURIComponent(CSRFToken);
   }
   location.href = url;
   */
}
function postTo(url, obj)
{
   if (url==null) {
      url = location.pathname;
   }
   let html = '<form action="' + url + '" method=POST>';
   for (p in obj) {
      html += '<input type=hidden name="' + p + '" id="dyn' + p + '">';
   }
   html += '</form>';
   let myform = $(html).appendTo('body'); // submit();
   let ids;
   for (p in obj) {
      ids = '#dyn' + p;
      $(ids).val(obj[p]);
   }
   myform.submit();
}
function followMe(obj) // deprecated
{
   var query_str = new Array();
   for (var k in obj)
   {
      query_str.push( k +'=' + encodeURIComponent(obj[k]) );
   }
   if (CSRFToken !== null)
   {
      query_str.push( 'CSRFToken=' + CSRFToken );
   }
   location.href = location.pathname + '?' + query_str.join('&');
}
function goDeleteFX(action, fx) {
   if (!window.confirm('Really delete record(s)?'))
		return;

	goFX(action,fx);
}
function goFX(a,fx) {
	let g=GetGoForm();
	g.action=a;
  	formGoTo(g,fx);
}
function goSecure(f) {
   let myRef='http://'+window.location.hostname+'/x/ishopm1.cgi';
   document.goForm.action=myRef;
   document.goForm.FUNCTION.value=f;
   document.goForm.submit();
}
function goBase(f) {
   let url='http://'+window.location.hostname+'/x/ishopm1.cgi';
   goFX(url,f);
}
function myHelp(lang,id) {
   let helpUrl='/ishop/help.htm';
   if (id!=undefined)
      helpUrl+='#'+id;

   let helpWin=window.open(helpUrl,'preview','scrollbars=yes,resizable=yes,menubar=yes,height=450,width=600');
   if (helpWin!=undefined) {
      helpWin.focus();
   }
   return ;
}
function onAction(myForm,myValue) {
  myForm.todo.value=myValue;
  myForm.submit();
}
function onAction2(myForm,myValue) {
  myForm.FUNCTION.value="12";
  myForm.todo.value=myValue;
  myForm.submit();
}
function clearIt(myfield) {
  myfield.value="";
  return ;
}
function example1(myfield) {
  myfield.value="+101;1;Cofee maker;2;70;60\n+405;1;Cofee cup set (2 pieces);2;140;105";
  return ;
}
function example2(myfield) {
  myfield.value="+1;Cofee mach.;Cofee machinery and other equipment\n+2;Refrigators;Cool gas refrigirators";
  return ;
}
function viewIt(myOrder) {
  document.goForm.ORDERID.value=myOrder;
  document.goForm.submit();
}
function checkPass(f) {
  if (f.PASS1.value.length<4) {
	window.alert('Minimum 4 chars. required!');
	return false;
  }
  if (f.PASS1.value!=f.PASS2.value) {
	window.alert('Verification error! Please re-type.');
	f.reset();
	return false;
  }
}
function gotoCart(merch) {
  let dest='/x/ishop.cgi?'+escape('me='+merch+'+fu=4');
  window.open(dest,'ishop');
}

var oPGNdiv=null;
var oRPSdiv=null;

function resetNavButtons() { // cPAGESIZE.resetNavButtons
   var dis='disabled';

   var btn=$('#movePageFirst');
   if (this.pg>1) {
      btn.removeAttr(dis).unbind('click').click(function(){ $('#pgNav').children().attr(dis,dis); onMovePageEx('F'); });
   }
   else {
      btn.attr(dis,dis).unbind('click');
   }

   var btn=$('#movePagePrev');
   if (this.pg>1) {
      btn.removeAttr(dis).unbind('click').click(function(){ $('#pgNav').children().attr(dis,dis); onMovePageEx('P'); });
   }
   else {
      btn.attr(dis,dis).unbind('click');
   }

   var btn=$('#movePageNext');
   if (this.pg<this.epage) {
      btn.removeAttr(dis).unbind('click').click(function(){ $('#pgNav').children().attr(dis,dis); onMovePageEx('N'); });
   }
   else {
      btn.attr(dis,dis).unbind('click');
   }

   var btn=$('#movePageLast');
   if (this.pg<this.epage) {
      btn.removeAttr(dis).unbind('click').click(function(){ $('#pgNav').children().attr(dis,dis); onMovePageEx('L'); });
   }
   else {
      btn.attr(dis,dis).unbind('click');
   }

   if (this.epage>1) {
      $('#movePager').html( '<a href="javascript:xtdPage(' + this.pg + ',' + this.epage + ')">'
         + this.pgLabel + ' ' + this.pg + '/' + this.epage + '</a>' );
   }
   else {
      $('#movePager').html( this.pgLabel + ' ' + this.pg + '/' + this.epage );
   }
}

function onResetPgSize(fx) {
   cPageSize.resetSize(fx);
   $(oRPSdiv).hide();
}

function doResetPgSize(fx)
{
   var newsz=parseInt($('#pgsize').val());
   if (isNaN(newsz))
      return;

   var f=GetGoForm(); // get existing or create new

   if (fx>0) {
      var o2=f.FUNCTION;
      if (o2==null) {
         o2=document.createElement('INPUT');
         o2.type='HIDDEN';
         o2.name='FUNCTION';
         f.appendChild(o2);
      }
      o2.value=fx;
   }

   var o2=f.ADOPAGESIZE;
   if (o2==null) {
      o2=document.createElement('INPUT');
      o2.type='HIDDEN';
      o2.name='ADOPAGESIZE';
      f.appendChild(o2);
   }
   o2.value=newsz;

   if (CSRFToken !== null)
   {
      o2=f.CSRFToken;
      if (o2==undefined) {
         o2=document.createElement('INPUT');
         o2.type='hidden';
         o2.name='CSRFToken';
         f.appendChild(o2);
      }
      o2.value = CSRFToken;
   }

   f.submit();
}
function goResetPgSize(fx,oldsz) {
   if (oRPSdiv==null) {
		oRPSdiv=document.createElement('DIV');
		oRPSdiv.className='POPMENU';
		document.body.appendChild(oRPSdiv);
      $(oRPSdiv).html('<table cellspacing=0>' +
		   '<tr><td colspan=2 class=bgHeader>Reset page size</td></tr>' +
			'<tr><td class=bgLabel>New value (minimum 10)</td>' +
         '<td class=bgInput><input type=TEXT id=pgsize value="'+oldsz+'" size=5></td></tr>' +
			'<tr><td></td>' +
         '<td><button type=button onclick="onResetPgSize(' + fx + ')">OK</button></td></tr>' +
			'</table>');
	}
   show_popup(oRPSdiv);
	$('#pgsize').focus();
   $('#pgsize').select();
}
function rsPage(f,pg) {
	if (!f.RSPAGE) {
      $(f).append('<input type=hidden name=RSPAGE>');
	}
	f.RSPAGE.value=pg;

   if (CSRFToken !== null)
   {
      o2=f.CSRFToken;
      if (o2==undefined) {
         o2=document.createElement('INPUT');
         o2.type='hidden';
         o2.name='CSRFToken';
         f.appendChild(o2);
      }
      o2.value = CSRFToken;
   }

   f.submit();
}

function onMovePageEx(act) {
   var fx=cPageSize.fu;

   switch (act)
   {
   case 'F':
      var pg=1;
      break;
   case 'P':
      var pg=cPageSize.pg-1;
      break;
   case 'N':
      var pg=cPageSize.pg+1;
      break;
   case 'L':
      var pg=cPageSize.epage;
      break;
   default: // goto specific page
      var pg=(typeof act=='number')?act:1;
      break;
   }

   cPageSize.movePage(fx, pg);
}

function goMovePageEx(fx,pg) { // ops.movePage
  	var f=GetGoForm();
  	if (fx>0) {
   	if (f.FUNCTION)
      	f.FUNCTION.value=fx;
      else if (f.FU)
      	f.FU.value=fx;
      else {
         o2=document.createElement('INPUT');
         o2.type='HIDDEN';
         o2.name='FUNCTION';
         f.appendChild(o2);
         o2.value=fx;
      }
   }
  	rsPage(f,pg);
}
function goMovePage(pg) {
   var f=GetGoForm();
   rsPage(f,pg);
}
function goRecord() {
   var nargs=arguments.length;
   if (nargs<1)
      return;

	var f=GetGoForm();

   var o2=f.FUNCTION;
   if (o2==null) {
      o2=document.createElement('INPUT');
      o2.type='HIDDEN';
      o2.name='FUNCTION';
      f.appendChild(o2);
   }
   o2.value = arguments[0];

  	var o2=f.RECORDID;
   if (o2==null) {
      o2=document.createElement('INPUT');
      o2.type='HIDDEN';
      o2.name='RECORDID';
      f.appendChild(o2);
   }
   o2.value = nargs>=2?arguments[1]:'';

  	for (var i=2;i<nargs;i++) {
  	   var fex='RECORDID'+i;
  	   var o2=f[fex];
  	   if (o2==null) {
         o2=document.createElement('INPUT');
         o2.type='HIDDEN';
         o2.name = fex;
         f.appendChild(o2);
      }
      o2.value = arguments[i];
   }

   if (CSRFToken !== null)
   {
      o2=f.CSRFToken;
      if (o2==null) {
         o2=document.createElement('INPUT');
         o2.type='hidden';
         o2.name='CSRFToken';
         f.appendChild(o2);
      }
      o2.value = CSRFToken;
   }

  	f.submit();
}
function goRecDelete() {
   if (!window.confirm('Really delete record(s)?'))
		return;

   switch (arguments.length)
   {
   case 2:
      goRecord(arguments[0], arguments[1] );
      break;
   case 3:
      goRecord(arguments[0], arguments[1], arguments[2] );
      break;
   case 4:
      goRecord(arguments[0], arguments[1], arguments[2], arguments[3] );
      break;
   }
}
function goRecordEx(act,fx,rid) {
	var f=document.goForm;
	f.action=act;

	var o2=f.FUNCTION;
   if (o2==null) {
      o2=document.createElement('INPUT');
      o2.type='HIDDEN';
      o2.name='FUNCTION';
      f.appendChild(o2);
   }
   o2.value = fx;

   var o2=f.RECORDID;
   if (o2==null) {
      o2=document.createElement('INPUT');
      o2.type='HIDDEN';
      o2.name='FUNCTION';
      f.appendChild(o2);
   }
   o2.value = rid;

  	f.submit();
}
function goRecDeleteEx(act,fx,rid) {
   if (!window.confirm('Really delete record(s)?'))
		return;

   goRecordEx(act,fx,rid);
}
function goExDelete(fx) {
   if (!window.confirm('Really delete record(s)?'))
		return;

	goTo(fx);
}
function goCategory(pg) {
   var g=GetGoForm();

   var fx=g.FUNCTION;
   if (!fx) {
      fx=$(g).append('<input type=hidden name=FUNCTION>').get(0).FUNCTION;
   }
   fx.value='142';

   var pgno=g.PAGENO;
   if (!pgno) {
      pgno=$(g).append('<input type=hidden name=PAGENO>').get(0).PAGENO;
   }
   pgno.value=pg;

   g.submit();
}
function on_dlvrec(x) {
   var f=document.goForm;
  	f.FUNCTION.value='162';
  	f.DLVID.value=x;
  	f.submit();
}
function on_deldlv(x) {
	if (!window.confirm('Really delete record?'))
		return;

   var f=document.goForm;
  	f.FUNCTION.value='165';
  	f.DLVID.value=x;
  	f.submit();
}
function on_stockacc(x) {
   var f=document.goForm;
	f.action='/ishop/ishop_item.php';
  	f.FUNCTION.value='158';
  	f.RECORDID.value=x;
  	f.submit();
}
function on_addstock(x,w) {
	var f=document.goForm;
	f.action='/ishop/ishop_stock.php';
	f.FUNCTION.value='2';
  	f.RECORDID.value=x;
  	f.WAREHOUSE.value=w;
  	f.submit();
}
function on_subitem(x) {
	var f=document.goForm;
	f.action='/ishop/ishop_subcod.php';
	f.FUNCTION.value='10';
  	f.RECORDID.value=x;
  	f.submit();
}
function goUsagePro(fx,d1) {
   var f=document.goForm;
   f.FUNCTION.value=fx;
   f.TRDATE.value=d1;
   f.submit();
}
function CopyTitle() {
   var f=document.goForm;
   f.TITLE.value=f.ABBREV.value;
}
function toUpperCase() {
   var f=document.goForm;
   f.TITLE.value=f.TITLE.value.toUpperCase();
}
function CopyPageNo() {
   var f=document.goForm;
   f.WMPAGE.value=f.PAGENO.value;
}
function onDelUps(f,id) {
	if (!window.confirm( 'You are about to delete id #' + id ))
   	return;

	f.FUNCTION.value=2;
	f.UPSID.value=id;
   f.submit();
}
function onMoreUps(f,id) {
	f.FUNCTION.value=4;
	f.UPSID.value=id;
   f.submit();
}
function onRenameUps(f,id,a) {
	f.FUNCTION.value=1;
	f.UPSID.value=id;
	f.UPSNAME.value=f.elements[a].value;
   f.submit();
}
function onDelDest(f) {
	if (!window.confirm('You are about to delete [' + f.DESTNAME.value + ']'))
   	return;

	f.FUNCTION.value=6;
   f.submit();
}
function onS80Day(x) {
   var f=document.goForm;
   f.FUNCTION.value=2;
   f.S80DAY.value=x;
   f.submit();
}
function onG11Rec(x) {
   var f=document.goForm;
   f.FUNCTION.value=3;
   f.G11ROW.value=x;
   f.submit();
}
function on_notes(x)
{
   var f=document.goForm;
   f.action="/ishop/ishop_note.php";
   f.RECORDID.value=x;
   f.FUNCTION.value='1';
   f.submit();
}
function onItemWinRet(x,icode)
{
   switch (x)
   {
   case 1:
	   queryNewWin();
		goRecordEx('/ishop/ishop_item.php',162,icode);
		break;
	case 2:
	   queryNewWin();
		goRecordEx('/ishop/ishop_item.php',152,icode);
		break;
	case 3:
	   queryNewWin();
		goRecDeleteEx('/ishop/ishop_item.php',155,icode);
		break;
	case 4:
	   queryNewWin();
		on_stockacc(icode);
		break;
	case 5:
	   queryNewWin();
		on_addstock(icode,0);
		break;
	case 6:
		queryNewWin();
		goRecordEx('/ishop/ishop_subcod.php',10,icode);
		break;
	case 7:
	   queryNewWin();
		goRecordEx('/ishop/ishop_item.php',160,icode);
		break;
	case 8:
	   queryNewWin();
		goRecordEx('/ishop/ishop_item.php',120,icode);
		break;
	case 9:
	   goRecordEx('/ishop/ishop_item.php',70,icode);
	   break;
	case 10:
      goRecordEx('/ishop/ishop_xtra.php',171,icode);
      break;
	case 54: // big photo
      goRecordEx('/ishop/ishop_item.php',4,icode);
      break;
	case 100:
		copy_fdata();
		hide_popup();
		break;
	}
}
function LogAgent(lpath,passwd)
// Discontinued
{
 	var f=document.goForm;
 	f.FUNCTION.value='1';
 	f.LPATH.value=lpath;
 	f.PASSWD.value=passwd;
 	f.submit();
}
function showHideN(obj,f)
{
   if (obj==null)
      return;
   else if (typeof obj=='string')
      obj=document.getElementById(obj);

 	if (!f) { // Hide
 		obj.style.display='none';
	}
	else { // Show
		obj.style.display='inline';
	}
}
function showHide(obj,f)
{
   if (obj==null)
      return;
   else if (typeof obj=='string')
      obj=document.getElementById(obj);

 	if (!f) { // Hide
 		obj.style.display='none';
	}
	else { // Show
		obj.style.display='inline';
	}
}
function showHideArea(ids)
{
   var jo = $('#'+ids);
   if (jo.length==0)
      return;

   if (jo.css('display')==='none') {
      jo.show();
      var o2=window.event;
      if (o2!=null && o2.srcElement.tagName=='A')
         $(o2.srcElement).text('[-]');
   }
   else {
      jo.hide();
      var o2=window.event;
      if (o2!=null && o2.srcElement.tagName=='A')
         $(o2.srcElement).text('[+]');
   }
}
function showHideAreaN(oref,ids)
{
   if ($('#'+ids).css('display')=='none') {
      $('#'+ids).show();
      $(oref).text('[-]');
   }
   else {
      $('#'+ids).hide();
      $(oref).text('[+]');
   }
}
function appendSession()
{
   var urlx='';
   var ss=document.cookie.split(';');
	n=ss.length;
	for (i=0;i<n;i++) {
	   ssi=ss[i].split('=');
	   if (ssi.length<2)
	     continue;

	   while (ssi[0].charAt(0)==' ')
	      ssi[0]=ssi[0].substr(1);

	   if (ssi[0]=='SESSIONID' || ssi[0]=='DELTA')
	      urlx += '&'+ssi[0]+'='+ssi[1];
	}
	if (urlx.length>0)
   	return urlx;

   var ss=location.search.split('&');
   n=ss.length;
   for (i=0;i<n;i++) {
      ssi=ss[i].split('=');
      while (ssi[0].charAt(0)=='?')
	      ssi[0]=ssi[0].substr(1);

	   if (ssi[0]=='SESSIONID' || ssi[0]=='DELTA')
	      urlx += '&'+ssi[0]+'='+ssi[1];
   }
   return urlx;
}
function save_cpanel_pref(ids,vis)
{
   if (xmlhttp==null) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlhttp=null;
			return null;
		}
	}

	try {
      url='/ishop/ishop_jsonfu.php?FUNCTION=4&ID='+ids+'&VIS='+vis;
      // Send async
      xmlhttp.open("GET", url, true);
      xmlhttp.send(null);
      return true;
   }
   catch (e) {
      return null;
   }
}
function get_record(qry,param)
{
   if (xmlhttp==null) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlhttp=null;
			return null;
		}
	}

	try {
      url="/ishop/ishop_json2.php?QUERY="+encodeURIComponent(qry);
      if (param!=null) {
         var n=param.length;
         for (i=0;i<n;i++) {
            url += '&PARAM[]='+encodeURIComponent(param[i]);
         }
      }
      // Synchronus call
      xmlhttp.open("GET", url, false);
      xmlhttp.send(null);
   }
   catch (e) {
      return null;
   }

  	if (xmlhttp.status==200) {
	   var local=new Function("return "+xmlhttp.responseText)();
      if (local.length==0)
         return null;

      q1=local[0];
      if (q1.error.length) {
         window.alert(q1.error);
         return null;
      }
      if (q1.data.length==0) {
         window.alert('No record read!');
         return null;
      }
      return q1.data[0];
   }
}
// New find code (end)
function zoom_omainNT(oid) // ...NT stands for New Technology
{
   let url='/ishop/ishop_infox.php?FUNCTION=1&ORDERID='+oid;
   url += iadmin_str();
	window.showModalDialog(url,'','dialogHeight:480px;dialogWidth:620px;help:no');
}
function zoom_opropNT(oid) // ...NT stands for New Technology
{
   let url='/ishop/ishop_infox.php?FUNCTION=2&ORDERID='+oid;
   url += iadmin_str();
	window.showModalDialog(url,'','dialogHeight:480px;dialogWidth:620px;help:no');
}
/* AW Grid */
function gridExpand(obj)
{
   // Alternate row function
   let alternate = function() {
      return this.getRowProperty("order") % 2 ? "#C9E9E9" : "#ffffff";
   }

   let row = new Active.Templates.Row;
	// Row hilight
   row.setEvent("onmouseover", "mouseover(this, 'active-row-highlight')");
   row.setEvent("onmouseout", "mouseout(this, 'active-row-highlight')");
   // Alternate row
   row.setStyle("background", alternate);
   obj.setTemplate("row", row);
}
function newWinPDA()
{
   var url='/pda/pda_emu.htm';
   var targetwin='ipda';
   var features='resizable=no,scrollbars=yes,status=yes,titlebar=yes,top=0,left=0,height=640,width=380';
   var owin=window.open(url, targetwin, features);
   try {
      owin.focus();
   }
   catch (e) {}
}
function isBrowserOk()
{
   return true;

	var ieStr='Microsoft Internet Explorer';
	if (navigator.appName!=ieStr) {
      window.alert('This application needs ' + ieStr + ' version 6.0 at least, in order to run!\r\n' +
			'Instead, you are using ' + navigator.appName + '.');
	   return false;
	}

	version='0.0';
	do {
		parts=navigator.appVersion.split('(');
		if (parts.length<2)
			break;

		parts=parts[1].split(';');
		n=parts.length;
		for (i=0;i<n;i++) {
			suparts=parts[i].split(' ');
			n2=suparts.length;
			for (i2=0;i2<n2-1;i2++) {
				if (suparts[i2]=="MSIE") {
					version=suparts[i+1];
					break;
				}
			}
		}
	} while(false);

	if (parseInt(version)<6) {
		window.alert('This application needs ' + ieStr + ' version 6.0 at least, in order to run!\r\n' +
			'Instead, you are using ' + navigator.appName + ' version ' + version + '.');
		return false;
	}
	else {
      return true;
   }
}
function checkUncheckAll2(ogrid)
{
   try {
      var chch = document.getElementById(ogrid._iid+'_CH').checked;
      var nc=ogrid.getRowsNum();
      for (var i=0;i<nc;i++) {
         grid1.cellByIndex(i,0).setChecked(chch);
      }
   }
   catch (e) {}
}
function checkUncheckAll(obj)
{
   selectAll(obj.checked, obj.id);
}
function selectAll(x, fieldName)
{
   if (!fieldName) { // may be undef.
      var fieldName='';
   }
   var key='javascript:selectAll(';
   var klen=key.length;
   if (document.all) // IE
      var co1=document.all;
   else
      var co1=document.getElementsByTagName('*');

   var n=co1.length;
   for (var i=0;i<n;i++) {
      var e1=co1[i];
      if (e1.tagName=='INPUT') {
         if (e1.type=='checkbox' && (fieldName=='' || e1.name.indexOf(fieldName)==0) ) {
            if ((x && !e1.checked) || (!x && e1.checked)) {
               e1.click();
            }
         }
      }
      else if (e1.tagName=='A') {
         // We did reach the function call link: stop here
         if (e1.href.substr(0,klen)==key)
            break;
      }
   }
}
function goAsciiDay(fx)
{
   goAsciiExport(fx,71);
}
function goAsciiDay2(fx)
{
   goAsciiExport(fx,181);
}
function goAsciiExport(fx,fu)
{
   // fx=0/1: export ascii/print
   let f1=document.goForm;
   j=f1.DELIMITER.selectedIndex;
   if (j<0) j=0;
   delimX=f1.DELIMITER.options[j].value;

   if (fx==1) delimX=4; // print->tabular format

   let url=location.protocol+'//'+location.host+'/ishop/ishop_export.php?FUNCTION=' + fu +
      '&DELIMITER=' + delimX;

   let ff=['FROMDATE', 'TODATE', 'TOTALS', 'HOW', 'OFFERID' ];
   let n=ff.length;
   for (i=0;i<n;i++) {
      if (f1[ff[i]])
         url += '&'+ff[i]+'='+f1[ff[i]].value;
   }
   if (fx==1)
      url += '&XPRINT=1';

   // Append session
   url += iadmin_str();

   window.open(url,'ascii','resizable=yes,scrollbars=yes,menubar=yes,status=yes');
}
function goAsciiZ(fx)
{
   // fx=0/1: export ascii/print
   let f1=document.goForm;
   j=f1.DELIMITER.selectedIndex;
   if (j<0) j=0;
   delimX=f1.DELIMITER.options[j].value;

   if (fx==1) delimX=4; // print->tabular format

   let url=location.protocol+'//'+location.host+'/ishop/ishop_export.php?FUNCTION=' + f1.FUNCTION.value +
      '&DELIMITER=' + delimX + '&TOTALS=' + f1.TOTALS.value +
      '&ZTYPE=' + f1.ZTYPE.value + '&FROMZ=' +  f1.FROMZ.value + '&TOZ=' + f1.TOZ.value +
      '&HOW=' + f1.HOW.value + '&FILTER=' + f1.FILTER.value;
   if (f1.RECORDID!=null)
      url += '&RECORDID=' + f1.RECORDID.value;
   if (fx==1)
      url += '&XPRINT=1';

   // Append session
   url += iadmin_str();

   win_openEx(url,'ascii','resizable=yes,scrollbars=yes,menubar=yes,status=yes');
}
function doPgSel(osel)
{
   var i=osel.selectedIndex;
   if (i<0) { i=0; }
   onMovePageEx(i+1);
}
function xtdPage(x,ex)
{
   if (oPGNdiv==null) {
		oPGNdiv=document.createElement('DIV');
		oPGNdiv.className='POPMENU';
		document.body.appendChild(oPGNdiv);
      $(oPGNdiv).html('<table cellspacing=0>' +
		   '<tr><td class=bgHeader>Goto page</td>' +
			'<td><input type=TEXT id=pgnoInp value="' + x + '" size=5></td>' +
         '<td><button type=button onclick="onGoPgno(' + ex + ')">OK</button></td></tr>' +
			'</table>');
	}
   show_popup(oPGNdiv);
	$('#pgnoInp').focus();
   $('#pgnoInp').select();
}
function onGoPgno(ex)
{
   let i=parseInt($('#pgnoInp').val(), 10);
   if (isNaN(i) || i<0) { i=0; }
   if (i>ex) { i=ex; }
   onMovePageEx(i);
}
function bodyUnloading()
{
   if (_dsb==null) {
      var html='<div id=loading style="padding:20px; background-color:rgb(200, 200, 200); ' +
         'filter:alpha(opacity=50); opacity:0.5; position:absolute; left:0; top:0; width:' + $(window).width() + 'px; ' +
         'height:' + $(window).height() + 'px; color: #008000; font-size:20pt; text-align:center;">' +
         '<div style="position:relative; top:' + ($(window).height()/2-50) + 'px;">Loading...</div></div>';
      $(document.body).append(html);
      _dsb=$('#loading').get(0);
   }
   else {
      $(_dsb).show();
   }
   window.setTimeout( "$('#loading').hide()", 500 );
   $(_dsb).keydown(function(event){
   if (event.keyCode==27)
      $(_dsb).hide();
   });
   $(_dsb).focus();
}
var fgrT=null;
function afterGResize(i)
{
   fgrT=null;
   var ogrid=gridID2[i];
   ogrid.setSizes();
}
function forGResize()
{
   let n=gridID2.length;
   let ogrid;

   for (var i=0;i<n;i++) {
      ogrid=gridID2[i];

      var odiv=$('#'+ogrid._iid+'_div').get(0);
      if (odiv==null)
         continue;

      if (fgrT!=null) {
         window.clearTimeout(fgrT);
      }

      // Set width
      var pobj=$(odiv).parent(':not(form)').get(0);
      if (!pobj || (pobj.tagName && pobj.tagName=='BODY')) {
         $(odiv).width( $(window).width() - 4 );
      }
      else {
         $(odiv).width( $(pobj).innerWidth() - 4 );
      }

      // Set height
      var wh=$(window).height();

      if (document.getElementById('tbar2')) {
         var delta = $(odiv).outerHeight() - $(odiv).height();
         var h1 = wh - $(odiv).offset().top - $('#tbar2').outerHeight() - delta - 1;
      }
      else {
         var bmargin = ogrid._ibottom_margin+5;
	      var h1 = wh - $(odiv).offset().top - bmargin;
      }

      if (h1<200) { h1=200; }
      $(odiv).height( h1 );

      // force grid redraw
      fgrT=window.setTimeout( 'afterGResize('+i+')', 100);
   }
}
function gridSetSize(ogrid) // 'grid2_div'
{
   let odiv=$('#'+ogrid._iid+'_div').get(0);

   // Set width
   let pobj=$(odiv).parent(':not(form)').get(0);
   if (!pobj || (pobj.tagName && pobj.tagName=='BODY')) {
      $(odiv).width( $(window).width() - 4 );
   }
   else {
      $(odiv).width( $(pobj).innerWidth() - 4 );
   }

   if (document.getElementById('tbar2')) {
      $('#tbar2').css('position', 'absolute').css('bottom', '0px').
         css('left', '0').css('right', '0');

      var y1=$(odiv).position().top;
      var y2=$('#tbar2').position().top;

      $(odiv).
         css('position','absolute'). //css('background-color', '#c0c0c0').
         css('top', y1+'px' ).
         css('bottom', $('#tbar2').height()+'px' ).
         height( y2-y1 );
   }
   else {
      $(odiv).css('position','absolute').
         css('top', ($(odiv).position().top)+'px' ).
         css('bottom', $(odiv)._ibottom_margin+'px' ).
         css('left', '0').css('right', '0');
   }

   ogrid.setSizes();
}
function forGResize2(ogrid)
{                 firstSetSize(ogrid); return;
   var odiv=$('#'+ogrid._iid+'_div').get(0);
   $(odiv).css('height','');

   // Set width
   var pobj=$(odiv).parent(':not(form)').get(0);
   if (!pobj || (pobj.tagName && pobj.tagName=='BODY')) {
      $(odiv).width( $(window).width() - 4 );
   }
   else {
      $(odiv).width( $(pobj).innerWidth() - 4 );
   }

   ogrid.setSizes();
}
function do_save_awcols2(idg)
{
   if (SavePageColsUrl==null)
      return;

   let n=idg.getColumnsNum();
   if (n==0)
    	return;

   let cw=new Array();
   for (i=0;i<n;i++) {
      cw.push(idg.getColWidth(i));
   }

   let val;
   let s1=pathnameEx().split('.');
   n=s1.length;
   if (n>=2) {
      s1.pop();
      val=s1.join('.');
   }
   else {
      val=pathnameEx();
   }
	let val2 = val+'.'+idg._iid+':'+cw.join(':');
   //console.log(val2);
   $.get(SavePageColsUrl, {'ADOPAGECOLS':val2} );
}
function advance_date(y,m,d)
{
	let o1=document.goForm.DATEFROM;
	let o2=document.goForm.DATETO;

	let ar1=o1.value.split('-');
	if (ar1.length!=3) {
		window.alert('Date format error!');
		return;
	}
	try {
		for (i=0;i<=2;i++) {
			if (ar1[i].length==2 && ar1[i].substr(0,1)=='0')
				ar1[i]=ar1[i].substr(1);

			ar1[i]=parseInt(ar1[i]);
		}
		let d2=new Date( ar1[2]+y, ar1[1]-1+m, ar1[0]+d );
		let s1=(d2.getDate()+100).toString();
		let s2=(d2.getMonth()+101).toString();
		o2.value=s1.substr(1,2)+'-'+s2.substr(1,2)+'-'+d2.getFullYear();
	}
	catch (e) {
		window.alert(e);
	}
}
function add_week()
{
	advance_date(0,0,7);
}
function add_month()
{
	advance_date(0,1,0);
}
function add_year()
{
	advance_date(1,0,0);
}
function f_reset(name,val)
{
   var f1=document.goForm;
   f1[name].value=val;
}
function f_reseti(id,val)
{
   $('#'+id).val( val );
}
function browse_d1(o1,title)
{
   var objShell=null;

   try {
	  objShell = new ActiveXObject("Shell.Application");
	}
	catch (e) {
	   alert('Error 1: '+e);
	   return;
	}

   var ssfDRIVES = 17;
   var ssfDESKTOP = 0x0;
   /*
   My Computer—virtual folder containing everything on the local computer:
   storage devices, printers, and Control Panel. This folder may also contain
   mapped network drives. (value = 17 = 0x11)
   */

   let BIF_RETURNONLYFSDIRS = 0x1;
   let BIF_EDITBOX = 0x10;

   let obj=null;
   try {
      obj=objShell.BrowseForFolder(0,
			title,
			BIF_RETURNONLYFSDIRS | BIF_EDITBOX,
			ssfDESKTOP );
   }
   catch (e) {
      alert('Error 2: '+e);
      return;
   }
   if (obj!=null) {
      oFolderItem = obj.Self;
      o1.type='text';
      o1.value=oFolderItem.Path;
   }
}
function show_popupFN(o1)
{
   if (_dsb)
      $(_dsb).hide();

   if (typeof o1=='undefined') // no parameter 'o1' passed
      o1 = document.getElementById('popmenu');
   else if (typeof o1=='string')
      o1 = document.getElementById(o1);

   if (oPopup!=null) { // global var
      $(oPopup).foundation('close');
   }

   oPopup = o1;

   //$(o1).foundation('open');
   try {
      $(o1).foundation('open');
   }
   catch (e) {}

   _popT1=new Date();

   $(o1).click(function(event){
      event.stopPropagation();
   });

   /*var inelem=true;
   $(o1).focus().mouseenter(
      function(){ inelem=true; }
   ).mouseleave(
      function(){ inelem=false; }
   );

   $('html').mousedown(function() {
      if (!inelem) {
         $(o1).unbind('mouseenter').unbind('mouseleave').hide();
         $('html').unbind('mousedown').unbind('keydown');
      }
   } ).keydown(function(e){
         var code = (e.keyCode ? e.keyCode : e.which);
         if (code==27) {
            $(o1).unbind('mouseenter').unbind('mouseleave').hide();
            $('html').unbind('mousedown').unbind('keydown');
         }
   } );*/
   $('html').keydown(function(e){
         var code = (e.keyCode ? e.keyCode : e.which);
         if (code==27) {
            $(o1).foundation('close');
            $('html').unbind('mousedown').unbind('keydown');
         }
   });
}
function show_popup(o1)
{
   if (_dsb)
      $(_dsb).hide();

   if (typeof o1=='undefined')
      o1 = document.getElementById('popmenu');
   else if (typeof o1=='string')
      o1 = document.getElementById(o1);

   // If 'nothing' so far, return
   if (o1==null)
      return;

   if (oPopup!=null) { // global var
      $(oPopup).hide();
   }

   oPopup=o1;

   // We need first apply display=inline, so that we can then measure dimensions.
	$(o1).show();

	let x=gmouse.x + document.body.scrollLeft - 16;
	let oWidth=o1.clientLeft * 2 + o1.clientWidth;
   if (x+oWidth > $(window).width() + $(window).scrollLeft()) {
		x=$(window).width() + $(window).scrollLeft() - oWidth;
		if (x<0) x=0;
	}
	o1.style.left=x+'px';

	let y=gmouse.y + document.body.scrollTop - 16;
	let oHeight=o1.clientTop * 2 + o1.clientHeight;
   if (y+oHeight > $(window).height() + $(window).scrollTop()) {
		y=$(window).height() + $(window).scrollTop() - oHeight;
		if (y<0) y=0;
	}
	o1.style.top=y+'px';

   _popT1=new Date();

   $(o1).click(function(event){
      event.stopPropagation();
   });

   var inelem=true;
   $(o1).focus().mouseenter(
      function(){ inelem=true; }
   ).mouseleave(
      function(){ inelem=false; }
   );

   $('html').mousedown(function() {
      if (!inelem) {
         $(o1).unbind('mouseenter').unbind('mouseleave').hide();
         $('html').unbind('mousedown').unbind('keydown');
      }
   } ).keydown(function(e){
         var code = (e.keyCode ? e.keyCode : e.which);
         if (code==27) {
            $(o1).unbind('mouseenter').unbind('mouseleave').hide();
            $('html').unbind('mousedown').unbind('keydown');
         }
   } );
}
function forPopClick(evt)
{
   doHidePopup(evt);
}
function hidePopupIE()
{
   doHidePopup(event);
}
function doHidePopup(evt)
{
   if (evt==null || oPopup==null)
      return;

   if (evt.type=='keydown' && evt.keyCode!=27) {
      return;
   }

   if (evt.type=='click') {
      let cx = evt.clientX + document.body.scrollLeft;
      let cy = evt.clientY + document.body.scrollTop;
      //$('#xmsg').text('cx='+cx+' cy='+cy);
      if (cx>=oPopup.offsetLeft && cx<=(oPopup.offsetLeft+oPopup.offsetWidth)
         && cy>=oPopup.offsetTop && cy<=(oPopup.offsetTop+oPopup.offsetHeight))
      {
         return;
      }
   }

   oPopup.style.display='none';
   if (window.removeEventListener) { // Mozilla, Netscape, Firefox
      document.removeEventListener("click", forPopClick, false);
      document.removeEventListener("keydown", forPopClick, false);
   }
   else if (document.detachEvent) { // IE
      document.detachEvent("onclick",hidePopupIE);
      document.detachEvent("onkeydown",hidePopupIE);
   }
}
function hide_popup()
{
   if (oPopup==null)
      return;

   $(oPopup).foundation('close');
   /*
   oPopup.style.display='none';
   if (window.removeEventListener) { // Mozilla, Netscape, Firefox
      document.removeEventListener("click", forPopClick, false);
   }
   else if (document.detachEvent) { // IE
      document.detachEvent("onclick",hidePopupIE);
   }
   */
}
function remove_tag(src)
{
	let ar1=src.split('<');
	let n=ar1.length;

	while (n>=0 && ar1[n-1].substr(0,1)=='/')
	  n--;

	if (n>0) {
      var ar2=ar1[n-1].split('>');
      if (ar2.length==2)
         return ar2[1];
   }
   return src;
}
function popwinonoff()
{
   if ((o1=document.getElementById('openewin'))==null)
      return;

   o1.checked=!o1.checked;
}
function clearVal(fldname)
{
	try {
		let f1=document.goForm;
		f1[fldname].value='';
	}
	catch (e) {}
}
function clearValEx(fldname)
{
	try {
		let f1=document.goForm;
		f1[fldname].value='';
		f1[fldname].style.backgroundColor='';
	}
	catch (e) {}
}
function openColorDlg(i) {
   let o1=(i==0?document.goForm.COLOR:document.goForm.BGCOLOR);

	let url='/ishop/ishop_color.php?COLOR='+o1.value;
	let args=o1.value;
	ret=window.showModalDialog(url,args,'help:no;dialogHeight:420px;dialogWidth:500px;');
	if (ret!=null) {
	  o1.value=ret;
	  o1.style.backgroundColor=ret;
	}
}
var colorField;
function color_mat(j)
{
   //var colorField = j==0 ? 'COLOR' : 'BGCOLOR';
   let url='/ishop/ishop_mat2.php?FUNCTION=6';
	let ret=window.showModalDialog(url,null,'help:no;dialogHeight:400px;dialogWidth:600px;');
	if (ret!=null) {
      if (set_colorname!=null)
         set_colorname(ret);
   }
}
function set_colorname(s1)
{
   try {
      document.goForm[colorField].value=s1;
      document.goForm[colorField].style.backgroundColor=s1;
   }
   catch (e) {}
}
function make_costr(k)
{
   if (external!=undefined  && external.adocostr!=undefined) {
      ado_call_external(k);
   }
   else
      ado_call_self(k);
}
function ado_call_external(k)
{
   // 'k' is an input field name on 'goForm' form of document
   try {
      let s1=document.goForm[k].value;
      external.configure_ado(s1);
      document.goForm[k].value=external.adocostr;
   }
   catch (e1) {
      window.alert('Script error: '+e1);
   }
}
function ado_call_self(k)
{
   // 'k' is an input field name on 'goForm' form of document
   try {
      var oshell = new ActiveXObject("WScript.Shell");
      var udl=oshell.SpecialFolders("MyDocuments") + "\\ishop.udl";
      var fso = new ActiveXObject("Scripting.FileSystemObject");

      var fi = fso.CreateTextFile(udl, true, true); // true(1):create or overwrite true(2):as unicode
      var s1=document.goForm[k].value;
      fi.WriteLine('[oledb]');
      fi.WriteLine('; Everything after this line is an OLE DB initstring');
      fi.WriteLine(s1);
      fi.Close();

      var cmd=oshell.RegRead('HKLM\\SOFTWARE\\Classes\\MSDASC\\shell\\open\\command\\');
      var re=/%1/;
      var cmdo=cmd.replace(re,udl);

      oshell.run(cmdo,1,true);

      var fi = fso.OpenTextFile(udl, 1, false, -1); // open for reading, as unicode
      var ok=false;
      while (!fi.AtEndOfStream) {
         s1=fi.ReadLine();
         if (s1.substr(0,1)==';') {
            ok=true;
         }
         else if (ok) {
            document.goForm[k].value=s1;
            break;
         }
      }
      fi.Close();

      fso=null;
      oshell=null;
   }
   catch (e1) {
      window.alert('Shell error: ' + e1);
   }
}
function get_selected_text()
{
   var t = '';
   if(window.getSelection){
      t = window.getSelection();
   } else if(document.getSelection) {
      t = document.getSelection();
   } else if(document.selection) {
      t = document.selection.createRange().text;
   }
   return t;
}
// Printing................................
var oprdiv=null;
var oimg1=document.createElement('img');
oimg1.src='../img/printer16x16.png';
var oimg2=document.createElement('img');
oimg2.src='../img/export.gif';
function show_prmenu(fx)
{
	if (oprdiv==null) {
		oprdiv=document.createElement('DIV');
		oprdiv.className='POPMENU';
		document.body.appendChild(oprdiv);
      $(oprdiv).html('<table cellspacing=0><tr class=xNORMAL onclick="printIt(0,' + fx + ')">' +
			'<td><img src="img/printer16x16.png"></td><td><nobr>Εκτ��πωση</nobr></td></tr>' +
			'<tr><td><img src="img/export.gif"></td><td>Εξαγωγή ascii:</td></tr>' +
			'<tr>' +
			'<td></td><td><select id=delimiter>' +
			'<option value="1">Comma (,) separated' +
			'<option value="2">Delimited (;)' +
			'<option value="5">Hash (#) separated' +
			'<option value="3">Tab (\\t) separated' +
			'<option value="4" SELECTED>Tabular format' +
			'<option value="6">Excel (tm) file' +
			'</select></td>' +
			'<td><button type=button class=NavButton onclick="printIt(1,'+fx+')"><img src="ishop/to_right.gif"></button></td>' +
			'</tr></table>');
	}
	show_popup(oprdiv);
}
function printIt(x,fx)
{
	if (x==0) // real print
		xprint=100;
	else { // export
		o1=document.getElementById('delimiter');
		j=o1.selectedIndex;
		if (j<0) j=0;
		xprint=o1.options[j].value;
	}
	var url=pathnameEx() + '?FUNCTION='+fx+'&XPRINT='+xprint+iadmin_str();
   window.open(url,'ascii','resizable=yes,scrollbars=yes,menubar=no,status=yes');
}
function send_grp_del(ogrd,jj)
{
   send_grp_action(32,ogrd,null,jj);
}
function send_grp_values(ogrd,ret,jj)
{ // DEPRECATED
   send_grp_action(31,ogrd,ret,jj);
}
function send_grp_action(fx,ogrd,ret,jj)
{
   var rows=ogrd.getRowsNum();

   var nc=0;
   for (var i=0;i<rows;i++) {
      var cbk='ii'+i;
      if (document.getElementById(cbk) && document.getElementById(cbk).checked) {
         nc++;
      }
   }

   if (nc==0)
      return;

	var og=document.createElement('FORM');
   og.method='POST';
   document.body.appendChild(og);

   var o2=document.createElement('INPUT');
   o2.type='HIDDEN';
   o2.name='FUNCTION';
   o2.value=fx;
   og.appendChild(o2);

	for(var key in ret) {
      var o2=document.createElement('INPUT');
      o2.type='HIDDEN';
      o2.name=key;
      o2.value=ret[key];

      og.appendChild(o2);
   }

   for (var i=0;i<rows;i++) {
      var cbk='ii'+i;
      if (document.getElementById(cbk) && document.getElementById(cbk).checked) {
         var o2=document.createElement('INPUT');
         o2.type='HIDDEN';
         o2.name='CBK[]';
         o2.value=ogrd.cells(i,jj).getValue();

         og.appendChild(o2);
      }
   }

   //document.body.disabled=true;
   og.submit();
}
function zoom_unzoom(o1)
{
   if (o1.height==100) {
      o2=document.createElement('img');
      o2.src=o1.src;
      o1.height=o2.height;
   }
   else {
      o1.height=100;
   }
}
function queryEmpty()
{
   var o1=window.event.srcElement;
   if (o1!=null) {
      o1.isempty=false;
      o1.style.color='';
   }
}
function leaveEmpty()
{
   var o1=window.event.srcElement;
   if (o1!=null && o1.value=='') {
      o1.value=o1.emptyStr;
      o1.style.color='#c0c0c0';
   }
}
function setEmpty(o1,str1)
{
   if (o1.value=='') {
      o1.isempty=true; // add new property
      o1.value=str1;
      o1.style.color='#c0c0c0';
   }
   else {
      o1.isempty=false; // add new property
   }
   o1.emptyStr=str1; // add new property
   o1.onblur=leaveEmpty;
   o1.onkeypress=queryEmpty;
}
function checkForEmpty(f1)
{
   var n=f1.elements.length;
   for (var i=0;i<n;i++) {
      if (f1.elements(i).isempty!=null && f1.elements(i).isempty) {
         f1.elements(i).value='';
      }
   }
}
function CBclick(ox) {
   $(ox).prev().click();
}
function onTips() {
	var url='/ishop/ishop_tips.php?DUMMY=1' + iadmin_str();
	var owin=window.open(url, 'tips');
	try {
		owin.focus();
	}
	catch (e) {}
}
function checkEafdss(f) {
   if (f.EAFDSS.value.length<11) {
      window.alert('Λείπουν χα��ακτή��ες');
      f.EAFDSS.focus();
      return false;
   }
   else {
      return true;
   }
}
function GrDateHour(d1s)
{
   var reg1 = /[T,Z]/g;
   d1s = d1s.replace(reg1, ' ');

   var ar1=d1s.split(' ');
   if (ar1.length!=2) {
      return d1s;
   }

   var ar2=ar1[0].split('-');
   if (ar2.length!=3) {
      return d1s;
   }

   var ar3=ar1[1].split(':');
   while (ar3.length<2) {
      ar3.push('00');
   }

   return [ ar2[2], ar2[1], ar2[0] ].join('-') + ' ' + ar3[0] + ':' + ar3[1];
}
function GrDateTime(d1s)
{
   var reg1 = /[T,Z]/g;
   d1s = d1s.replace(reg1, ' ');

   var ar1=d1s.split(' ');
   if (ar1.length!=2) {
      return d1s;
   }

   var ar2=ar1[0].split('-');
   if (ar2.length!=3) {
      return d1s;
   }

   return [ ar2[2], ar2[1], ar2[0] ].join('-') + ' ' + ar1[1];
}
//--- MAT (start) ----------------------
function _set_srcff(s)
{
   this.srcFF_name=s;
}
//--------------------------------------
var FindItem3Obj=null;
function FindItem3(xid)
{
   this.matx=3;

   this.t1=0;
   this.agentid=xid;
   this.icode=null;

   this.srcFF=null; // source form field
   this.srcFF_name=null;

   this.outEL=null; // output document.element
   this.outEL_id=null;

   // _apply_names() must be called late, that is only during event execution.
   this.apply_names=_item_apply_names;

   this.find=_item_find;
   this.blur=_item_blur;
   this.read=_item_read;

   this.onReadOk=null;

   this.set_srcFF=_set_srcff;
   this.set_outEL=_item_set_outel;
}
function _item_set_outel(s)
{
   this.outEL_id=s;
}
function _item_apply_names()
{
   if (this.srcFF==null && this.srcFF_name!=null) {
      this.srcFF=document.goForm[this.srcFF_name];
   }

   if (this.outEL==null && this.outEL_id!=null) {
      this.outEL=document.getElementById(this.outEL_id);
   }
}
function _item_find()
{
   this.apply_names();

	window.clearTimeout(this.t1);

   var icode='';
	if (this.srcFF!=null)
	  icode=this.srcFF.value;

	ret=window.showModalDialog('/ishop/ishop_mat3.php?FUNCTION='+this.matx, icode, 'dialogWidth:600px;dialogHeight:400px;help:no;');
	if (_dsb) {
	  $(_dsb).hide();
   }
	// Returns item code or null
	if (ret==null)
		return;

   this.icode=ret;
   if (this.srcFF!=null) {
   	this.srcFF.value=this.icode;
   }

	this.read(1);
}
function _item_blur()
{
   this.apply_names();
   FindItem3Obj=this;
	this.t1=window.setTimeout( this.read, 100);
}
function _item_read()
{
   if (arguments.length==1) {
      oo=this;
   }
   else {
      oo=FindItem3Obj;
   }

   oo.apply_names();

	var icode = oo.srcFF?oo.srcFF.value:oo.icode;

	var param=[ oo.agentid, icode ];
	var qry;
   if (oo.matx==3) {
      qry='SELECT NAME F1 FROM ishop_item WHERE AGENTID=? AND CODE=?';
   }
   else {
      qry='SELECT ABBREV F1 FROM ishop_ctg WHERE AGENTID=? AND PAGENO=?';
   }

   if (oo.outEL!=null)
      $(oo.outEL).text('Reading data...');

	var obj=get_record(qry,param);
	if (obj!=null) {
      if (oo.outEL!=null)
   		$(oo.outEL).text(obj.F1);
   	if (oo.onReadOk!=null)
   	  oo.onReadOk();
	}
	else {
      if (oo.outEL!=null)
   		$(oo.outEL).text('Error');
	}
}
//--------------------------------------
function FindCtg3(xid)
{
   this.matx=7;

   this.t1=0;
   this.agentid=xid;
   this.icode=null;

   this.srcFF=null; // source form field
   this.srcFF_name=null;

   this.outEL=null; // output document.element
   this.outEL_id=null;

   // _apply_names() must be called late, that is only during event execution.
   this.apply_names=_item_apply_names;

   this.find=_item_find;
   this.blur=_item_blur;
   this.read=_item_read;

   this.onReadOk=null;

   this.set_srcFF=_set_srcff;
   this.set_outEL=_item_set_outel;
}
//--------------------------------------
var FindMbr3Obj=null;
function FindMbr3(xid)
{
   this.matx=1;
   this.table='ishop_mbr';

   this.t1=0;
   this.agentid=xid;

   this.srcFF=null; // source form field
   this.srcFF_name=null;

   this.outELc=null; // output document.element
   this.outELc_id=null;

   this.outELn=null; // output document.element
   this.outELn_id=null;

   // _apply_names() must be called late, that is only during event execution.
   this.apply_names=_mbr_apply_names;

   this.find=_mbr_find;
   this.blur=_mbr_blur;
   this.read=_mbr_read;

   this.set_srcFF=_set_srcff;
   this.set_outEL=_mbr_set_outel;
}
function _mbr_set_outel()
{
   if (arguments.length>=1)
      this.outELc_id=arguments[0];

   if (arguments.length>=2)
      this.outELn_id=arguments[1];
}
function _mbr_apply_names()
{
   if (this.srcFF==null && this.srcFF_name!=null)
      this.srcFF=document.goForm[this.srcFF_name];

   if (this.outELc==null && this.outELc_id!=null)
      this.outELc=document.getElementById(this.outELc_id);

   if (this.outELn==null && this.outELn_id!=null)
      this.outELn=document.getElementById(this.outELn_id);
}
function _mbr_find()
{
   this.apply_names();

	window.clearTimeout(this.t1);
	if (this.srcFF==null)
	   return;

	var icode=this.srcFF.value;
	ret=window.showModalDialog('/ishop/ishop_mat3.php?FUNCTION='+this.matx, icode, 'dialogWidth:600px;dialogHeight:400px;help:no;');
	// Returns mbr code or null
	if (ret==null)
		return;

	this.srcFF.value=ret;
	this.read(1);
}
function _mbr_blur()
{
   this.apply_names();
   FindMbr3Obj=this;
	this.t1=window.setTimeout( _mbr_read, 100);
}
function _mbr_read()
{
   if (arguments.length==1)
      oo=this;
   else
      oo=FindMbr3Obj;

   oo.apply_names();
	var icode=oo.srcFF.value;

	param=[ oo.agentid, icode ];
	var qry='SELECT COMPANY, NAME FROM '+oo.table+' WHERE AGENTID=? AND LOGIN=?';

   if (oo.outELc!=null)
      $(oo.outELc).text('Reading data...');
   if (oo.outELn!=null)
  		$(oo.outELn).text('');

	var obj=get_record(qry,param);
	if (obj!=null) {
      if (oo.outELc!=null)
   		$(oo.outELc).text(obj.COMPANY);
   	if (oo.outELn!=null)
   		$(oo.outELn).text(obj.NAME);
	}
	else {
      if (oo.outELc!=null)
   		$(oo.outELc).text('Error');
	}
}
//--------------------------------------
function FindSup3(xid)
{
   this.matx=2;
   this.table='ishop_sup';

   this.t1=0;
   this.agentid=xid;

   this.srcFF=null; // source form field
   this.srcFF_name=null;

   this.outELc=null; // output document.element
   this.outELc_id=null;

   this.outELn=null; // output document.element
   this.outELn_id=null;

   // _apply_names() must be called late, that is only during event execution.
   this.apply_names=_mbr_apply_names;

   this.find=_mbr_find;
   this.blur=_mbr_blur;
   this.read=_mbr_read;

   this.set_srcFF=_set_srcff;
   this.set_outEL=_mbr_set_outel;
}
//--------------------------------------
function findSubitem3(codeField, subField)
{
	var ocode = typeof(codeField)=='string'?document.goForm[codeField]:codeField;
	var osubco = typeof(subField)=='string'?document.goForm[subField]:subField;
	var ar1=new Array(ocode.value, osubco.value);
	// Returns subitem code or null
	var ret=window.showModalDialog('/ishop/ishop_mat3.php?FUNCTION=4', ar1, 'dialogWidth:600px;dialogHeight:400px;help:no;');
	if (ret!=null) {
	  osubco.value=ret;
	}
}
//--- MAT (end) ------------------------
