//    printf("        var =trim(form..value);\n");
//    printf("        =str_null(, );\n");

var isIE=document.all?true:false;
var OS='';
if (navigator.userAgent.indexOf("Windows NT 6.0") > -1) { OS='vista'; }// Windows vista 
var now   = new Date();
var year  = now.getYear();
if (year < 2000) year = year + 1900;

var randoms=1; //set random for page editor

var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1);

var i=0;
var dec1 = Math.pow(10, 1);
var dec2 = Math.pow(10, 2);
var amount=0;
var temp=0;

var middle=50;
var side=25;
var ex=5;
var screenW = 640, screenH = 480;
 
var orderno='*';
var choice=99;
var pageLoaded=true;
var Arguments = '';

 if (parseInt(navigator.appVersion)>3) { screenW = screen.width; screenH = screen.height; }
 else if (navigator.appName == "Netscape" && parseInt(navigator.appVersion)==3 && navigator.javaEnabled()) 
 {
  var jToolkit = java.awt.Toolkit.getDefaultToolkit();
  var jScreenSize = jToolkit.getScreenSize();
  screenW = jScreenSize.width;
  screenH = jScreenSize.height;
 }

var top=50; var left=50; var screenW=800, screenH=600;
 if (parseInt(navigator.appVersion)>3) { screenW = screen.width; screenH = screen.height; }
 else if (navigator.appName == 'Netscape' 
     && parseInt(navigator.appVersion)==3
     && navigator.javaEnabled()
    ) 
 {
  var jToolkit = java.awt.Toolkit.getDefaultToolkit();
  var jScreenSize = jToolkit.getScreenSize();
  screenW = jScreenSize.width-100;
  screenH = jScreenSize.height-100;
 }
 if(screenW>800){ left=100; top=100; }

function ryear(){ document.write(year); }
function wind(ref,title){ window.open(ref,title,'width=700, height=450, copyhistory=no, status=no, resizable=yes, scrollbars=yes'); }

///////////////////////check popup first page must contain onLoad='checkPopUp();'
function checkPopUp()
{
}
function checkPopUps()
{
// var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
// var popUpsBlocked;
// if(mine){ popUpsBlocked = false; mine.close() }
// else{ popUpsBlocked = true; }
// if(popUpsBlocked) alert('POPUP BLOCKER ACTIVE\n\nWe have detected that you are using popup blocking software.\n\nThis website needs to open a window to show messages, along with help menus...\n\nPlease disable your popup blocker.');
}
///////end popup blocker checker

function Format(total,decimals)
{
   if ( decimals==undefined ) decimals = 2;

   decimals *= 1;

   var suffix = ""
   for ( var i=0; i<decimals; i++ ) suffix += "0";

   var num = "" + parseFloat(total);
   if ( num == "NaN" ) return num = "0" + ((decimals>0) ? "."+suffix : "");

   if ( num.indexOf(".") == -1 ) return num += (decimals>0) ? "."+suffix : "";

   num += suffix;
   var tp = num.indexOf(".")+decimals;
   var rnd = Math.round(num.substring(tp,tp+1)+"."+num.substring(tp+1));

   return num.substring(0,tp)+rnd;
}

function renew() { ///clears the variables when page is loaded
  if(document.parent && parent.HEAD)parent.HEAD.pageLoaded=true;
  if(document.parent && parent.BOT) parent.BOT.pageLoaded=true;
 }
 middle=(screenW-(side*2));

function moveto(L,T)
{
 if (screenW <640)screenW=640;
 L=(screenW/2)-(L/2);
 moveTo(L,T);
}


/////////////////////////////tax functions DO NOT EDIT
function checktax(yy,xx)
{
 for(var x=0;x<form.govtax[yy].length;x++)
 if(ffields[xx]==form.govtax[yy][x].value.substring(4,7))
 form.govtax[yy][x].selected=true;
}

function changeamount(ref)
{
 for(var x=0;x<form.qty.length;x++){ if(ref==form.qty[x]) break; }
 var qty =parseFloat(form.qty[x].value);
 var temp=qty*parseFloat(form.price[x].value); 
 if(form.amount[x].value=='')form.amount[x].value=addcents((temp*dec2)/dec2);
 changecost();
}

function changecost()
{
 var cost=0,qty=0,y=0,temp=0;
 for(var x=0;x<form.qty.length;x++)
 {
  qty =parseFloat(form.qty[x].value);
  temp=Math.round((qty*parseFloat(form.cost[x].value)*dec2)/dec2);
  if(!isNaN(temp)){ cost+=temp; }
 }
 form.totalcost.value=cost;
}

function changegovtax(ref)
{
 var taxrate=form.taxrate;
 var govtax =form.govtax;
 var tax    =form.tax;
 var amount =form.amount;
 for(var x=0;x<form.govtax.length;x++){ if(ref==form.govtax[x]) break; }
 var temp =parseFloat(govtax[x].value.substring(0, 4));
 var total=parseFloat(amount[x].value);
 taxrate[x].value=(Math.round(temp*dec1)/dec1).toString();
 if(taxrate[x].value=='NaN')form.taxrate[x].value='';
 form.tax[x].value=addcents(Math.round(((total/(100+temp))*temp)*dec2)/dec2);
}

function changerate(ref)
{
 if(parseFloat(ref.value)>=100){ alert('Tax cannot be that high.'); ref.value=''; return false; }
 for(var x=0;x < form.taxrate.length;x++)if(ref==form.taxrate[x]) break;
 amount=parseFloat(form.amount[x].value);
 temp=parseFloat(form.taxrate[x].value);
 form.tax[x].value=addcents(Math.round(((amount/(100+temp))*temp)*dec2)/dec2);
 temp=(Math.round(temp*dec1)/dec1).toString();
 changegov(x,temp);
 return true;
}

function changetax(ref)
{
 for(var x=0;x<form.tax.length;x++)if(ref==form.tax[x]) break;
 amount=parseFloat(form.amount[x].value);
 if(parseFloat(ref.value)>=amount){ alert('Tax cannot be that high.'); form.tax[x].value=''; return false; }
 form.tax[x].value=addcents(parseFloat(form.tax[x].value));
 if(parseFloat(form.tax[x].value)>=parseFloat(form.amount[x].value)){ alert('Tax cannot be greater than amount.'); form.tax[x].value=''; return false; }
 temp=(100/(form.amount[x].value-form.tax[x].value))*form.tax[x].value;
 temp=(Math.round(temp*dec1)/dec1).toString();
 changegov(x,temp);
 return true;
}

function changegov(x,temp)
{
 for(var y=0;y<form.govtax[x].length;y++)
 {
  temp=str_null(temp,4)+form.govtax[x].value.substring(4, 7);
  if(form.govtax[x][y].selected)
  {
   if(form.govtax[x][y].value!=temp)
   {
    form.govtax[x].options[form.govtax[x].length]=new Option(form.govtax[x].value.substring(4, 7),temp);
    form.govtax[x][form.govtax[x].length-1].selected=true;
    form.govtax[x][form.govtax[x].length-1].style.color='red';
    form.taxrate[x].value=parseFloat(form.govtax[x][form.govtax[x].length-1].value.substring(0, 4));
   }
   break;
  }
 }
}

/////////////////////////////end tax functions

function resize() {
  if (navigator.appName == 'Netscape') i=40;
  if (document.images[0]) window.resizeTo(document.images[0].width +30, document.images[0].height+60-i);
  self.focus();
}

function process(refresh)
{
 form.submitbut.value='Processing';
 form.submitbut.style.border=0;
 form.submitbut.disabled=true;
 if(refresh)setTimeout('window.location.reload();',3000);
 return false;
}

function side_entry()
{
 document.write("&nbsp;<a href='http://www.eziaccounts.com.au/index.html' target='new' title='Home page'>Home</a><br>\n");
 document.write("&nbsp;<a href='http://www.eziaccounts.com.au/bbs.html' target='new' title='Post your bulletin'>Bulletin Board</a><br>\n");
 document.write("&nbsp;<a href=\"JavaScript:popup('http://www.eziaccounts.com.au/chat.html',540,130,'no','no','no');\" title='Chat with others'>Chat</a><br>\n");
 document.write("&nbsp;<a href='http://www.eziaccounts.com.au/guestbook.html' target='new' title='Sign our guest book'>Guest Book</a><br>\n");
}

function addcents(num)//function to return dollars and cents
{
 if(isNaN(num)) num=0.00;
 num = num.toString().replace(/\$|\,/g,'');
 var n , x ;
 for (n=0 ; n<=num.length; n++)
 {
  if (num.charAt(n-1)=='.')//found
  {
   for(x=n; x<n+2; x++) if (num.charAt(x)=='') num+='0';
   break;
  }
  else if (n==num.length && num.charAt(n-1)!='.') num+='.'; //add decimal point
 }
 return(num);
}

function click() {
 var gdCurDate = new Date();
 var giYear = gdCurDate.getFullYear();
 var message="Copyright "+giYear+" EZIaccounts© by Lloyd Etheridge";
//  if ((event.button==3 || event.button==2) && popCal.style.visibility=='visible') popCal.style.visibility='hidden';
   if (document.all && event.button==2) alert(message);
} document.onmousedown=click;

//function goto()
//{
// if (document.all && event.keyCode == 13 && document.form){ form.submit(); return false; }
//} document.onkeydown=goto;

function onpressed(act){ choice=act; }

function housecode(code)
{
// if (window.dialogArguments) { opener = window.dialogArguments; }
 window.opener.document.form.prod.value=code; window.close(); 
}
function glasspanel(code)
{
// if (window.dialogArguments) { opener = window.dialogArguments; }
 window.opener.document.form.panelglass.value=code; window.close(); 
}
function modelcode(code)
{
// if (window.dialogArguments) { opener = window.dialogArguments; }
 window.opener.document.form.prod.value='';
 window.opener.document.form.product.value=code;
 window.close();
}

function page_load()
{
 if(pageLoaded==true){  pageLoaded=false; return(true); }
 else { alert('Page is still loading......Please wait.'); return(false); }
}

function editor_html(objname,page) { showModalDialog(page, window, "resizable: yes; help: no; status: no; scroll: yes;"); }
function editor_html_modeless(objname,page) { showModelessDialog(page, window, "resizable: yes; help: no; status: no; scroll: yes;"); }

 var new1;
 var new2;
 var new3;
 var new4;
 var new5;
 var new6;
 var new7;
 var new8;
 var new9;
 var new10;
 var new11;
 var new12;
 var new13;
 var new14;
 var new15;
 var window1;
 var window2;
 var price;
 var changea;
 var changeb;
 var changec;
 var magic;
 var new_window;
 var openHelpWindow;

function data(h,w,doc){
  data = window.open(doc, 'data', 'left=50, top=100, width='+w+', height='+h+' resizable=yes, scrollbars=yes');
}
function help(h,w,doc){
  new_window = window.open(doc, 'magic_window', 'left=50, top=100, width='+w+', height='+h+', resizable=0, scrollbars=no');
}
function helpwindow(doc){
 ModalWindow(320,280,100,100,'/scripts/ezi/htmlhelp.exe?%20*%20'+doc+'%20*');
}
function openMagicWindow1(doc1){
  new1 = window.open( doc1, 'new1','width=750, height=300, copyhistory=no, resizable=yes, scrollbars=yes');//'fullscreen=1, resizable=no, copyhistory=no, scrollbars=no');
 if (window.focus)new1.focus();
}
function openMagicWindow2(doc1){
  new2 = window.open( doc1, 'new2', 'width=750, height=300, copyhistory=no, resizable=no, scrollbars=no');
 if (window.focus)new2.focus();
}
function openMagicWindow3(doc1){
  new3 = window.open( doc1, 'new3', 'width=750, height=300, copyhistory=no, resizable=no, scrollbars=no');
 if (window.focus)new3.focus();
}
function openMagicWindow4(doc1){
  new4 = window.open( doc1, 'new4', 'width=750, height=300, copyhistory=no, resizable=no, scrollbars=no');
 if (window.focus)new4.focus();
}
function openMagicWindow5(doc1){
  new5 = window.open( doc1, 'new5', 'width=750, height=300, copyhistory=no, resizable=no, scrollbars=no');
 if (window.focus)new5.focus();
}
function openMagicWindow6(doc1){
  new6 = window.open( doc1, 'new6', 'width=750, height=300, copyhistory=no, resizable=no, scrollbars=no');
 if (window.focus)new6.focus();
}
function openMagicWindow7(doc1){
  new7 = window.open( doc1, 'new7', 'width=750, height=310, copyhistory=no, resizable=no, scrollbars=no');
 if (window.focus)new7.focus();
}
function openMagicWindow8(doc1){
  new8 = window.open( doc1, 'new8', 'width=750, height=300, copyhistory=no, resizable=no, scrollbars=no');
 if (window.focus)new8.focus();
}
function openMagicWindow9(doc1){
  new9 = window.open( doc1, 'new9', 'width=750, height=300, copyhistory=no, resizable=no, scrollbars=no');
 if (window.focus)new9.focus();
}
function openMagicWindow10(doc1){
  new10 = window.open( doc1, 'new10', 'width=750, height=300, copyhistory=no, resizable=no, scrollbars=no');
 if (window.focus)new10.focus();
}
function openMagicWindow11(doc1){
  new11 = window.open( doc1, 'new11', 'width=750, height=300, copyhistory=no, resizable=no, scrollbars=no');
 if (window.focus)new11.focus();
}
function openMagicWindow12(doc1){
  new12 = window.open( doc1, 'new12', 'width=750, height=300, copyhistory=no, resizable=no, scrollbars=no');
 if (window.focus)new12.focus();
}
function openMagicWindow13(doc1){
  new13 = window.open( doc1, 'new13', 'width=750, height=300, copyhistory=no, resizable=yes, scrollbars=yes');
 if (window.focus)new13.focus();
}
function openMagicWindow14(doc1){
  new14 = window.open( doc1, 'new14', 'width=750, height=300, copyhistory=no, resizable=yes, scrollbars=yes');
 if (window.focus)new14.focus();
}
function openMagicWindow15(doc1){
  new15 = window.open( doc1, 'new15', 'width=750, height=300, copyhistory=no, resizable=yes, scrollbars=yes');
 if (window.focus)new15.focus();
}
function ccWindow(doc){
  window1 = window.open( doc, 'window1', 'left=100, top=100, width=240, height=208, copyhistory=no, resizable=no, scrollbars=no');
 if (window.focus)window1.focus();
}
function change(h, doc){
  changea = window.open( doc, 'changea', 'left=15, top=100, screenX=15, screenY=200, width=800, height='+h+', scrollbars=yes, resizable=yes');
 if (window.focus)changea.focus();
} 
function change_D(h, doc){
  changeb = window.open( doc, 'changeb', 'left=15, top=100, screenX=15, screenY=200, width=780, height='+h+', scrollbars=yes, resizable=yes');
 if (window.focus)changeb.focus();
} 
function change_C(h, doc){
  changec = window.open( doc, 'changec', 'left=15, top=100, screenX=15, screenY=200, width=780, height='+h+', scrollbars=yes, resizable=yes');
 if (window.focus)changec.focus();
} 
function openMagicWindowL(doc){
  magic = window.open( doc, "magic", 'left=50, top=100, width=450, height=300, copyhistory=no, resizable=no, menu=yes, scrollbars=yes');
 if (window.focus)magic.focus();
}

function closeall()
{
 if (new1) new1.close();
 if (new2) new2.close();
 if (new3) new3.close();
 if (new4) new4.close();
 if (new5) new5.close();
 if (new6) new6.close();
 if (new7) new7.close();
 if (new8) new8.close();
 if (new9) new9.close();
 if (new10) new10.close();
 if (new11) new11.close();
 if (new12) new12.close();
 if (new13) new13.close();
 if (new14) new14.close();
 if (new15) new15.close();
 if (window1) window1.close();
 if (window2) window2.close();
 if (price) price.close();
 if (changea) changea.close();
 if (changeb) changeb.close();
 if (changec) changec.close();
 if (magic) magic.close();
 if (new_window) new_window.close();
 if (openHelpWindow) openHelpWindow.close();
}

function trim(string) {
var n; 
  var check="";
  if(!string)return("");
  for(n=1; n<=string.length; n++){
   if(string.substring(n-1, n)=='+'
      || string.substring(n-1, n)=='#'
      || string.substring(n-1, n)=='!'
      || string.substring(n-1, n)=='\\'
      || string.substring(n-1, n)=='"'
      || string.substring(n-1, n)=='?'
      || string.substring(n-1, n)=='%'
      || string.substring(n-1, n)==':'
      || string.substring(n-1, n)=='|'
      || string.substring(n-1, n)==';'
      || string.substring(n-1, n)=='=')
   {
    alert('The Invalid character " '+string.charAt(n-1)+' "  has been replaced with "_".');
    check+="_";
   }
   else if(string.substring(n-1, n)=='\'') check+="`";
   else check+=string.substring(n-1, n);
  }
  string=check;

  var spos=0; var epos=0;
  while(string.charAt(spos)==' ' && spos<string.length) spos++;
  if(spos==string.length) string='';
  else {
   string=string.substring(spos, string.length);
   epos=(string.length)-1;
   while(string.charAt(epos)==' ') epos--;
   string=string.substring(0, epos+1);
  }
  return(string);
}

function checkword(entry){
   var check='';
    for (var n=0 ; n<entry.length ; n++)
    {
     if (entry.substring(n, n+1)=='+') check+='^';
     else check+=entry.substring(n, n+1);
    }
 return(check);
}

function str_null(string, len) {
 var re=/ /g;
 if (string=='') string='_';
 string=string.replace(re, '_');
 for(i=string.length; i<len; i++) string+='_';
 string=string.substring(0, len);
 return(string);
}

 var message="The browser window that opened this popup window has been closed.\n\nThis directory window will not function properly so I will close it.\n\nTo re-enable it, you must go back go to your Start Menu.";

function goThere(YN, location) {
 if(YN==0) self.close();
 if(window.opener){ Load(1); window.opener.parent.TOP.location.href = location; }
 else { parent.TOP.location.href = location; }
}

function isDigit(num) {
    if (num.length>1){return false;}
    var string="1234567890";
    if (string.indexOf(num)!=-1) return true;
    return false;
}

function isNumeric(val){ return(parseFloat(val,10)==(val*1)); }
//////reformatting date
function checkdate(date)
{
 var tdate =new Date();
 var tday  =tdate.getDay();
 var tmonth=tdate.getMonth();
 var tyear =tdate.getFullYear();
 var days, year, month, day;

 var dd= new Array(); dd=date.split('.');

 if(!dd[0])dd[0]=tday;
 if(!dd[1])dd[1]=tmonth;
 if(!dd[2])dd[2]=tyear;

 if(dd[0].length<2)dd[0]='0'+dd[0];
 if(dd[1].length<2)dd[1]='0'+dd[1];
 if(dd[2].length<2)dd[2]='200'+dd[2];
 if(dd[2].length<3)dd[2]='20'+dd[2];
 if(dd[2].length<4)dd[2]=tyear; //current year

 day  =parseFloat(dd[0]);
 month=parseFloat(dd[1]);
 year =parseFloat(dd[2]);

 if (day<1 || day>31) dd[0]=tday;
 if (month<1 || month>12) dd[1]=tmonth;

 if (dd[1]=='02'){ if (isLeapYear(year)) days=29; else days=28; }
 else if (dd[1]==4 || dd[1]==6 || dd[1]==9 || dd[1]==11) days=30;
 else days=31;

 if (day>days) dd[0]=days;

//alert(dd[2]+'.'+dd[1]+'.'+dd[0]);
 date=dd[2]+dd[1]+dd[0];
 return(date);
}

/////creating date if input field
function createdate(ref)
{
 var date=ref.value;
 var tdate =new Date();
 var tday  =tdate.getDay();
 var tmonth=tdate.getMonth();
 var tyear =tdate.getFullYear();
 var days, year, month, day;

 var dd= new Array(); dd=date.split('.');

 if(!dd[0])dd[0]=tday;
 if(!dd[1])dd[1]=tmonth;
 if(!dd[2])dd[2]=tyear;

 if(dd[0].length<2)dd[0]='0'+dd[0];
 if(dd[1].length<2)dd[1]='0'+dd[1];
 if(dd[2].length<2)dd[2]='200'+dd[2];
 if(dd[2].length<3)dd[2]='20'+dd[2];
 if(dd[2].length<4)dd[2]=tyear; //current year

 day  =parseFloat(dd[0]);
 month=parseFloat(dd[1]);
 year =parseFloat(dd[2]);

 if (day<1 || day>31) dd[0]=tday;
 if (month<1 || month>12) dd[1]=tmonth;

 if (dd[1]=='02'){ if (isLeapYear(year)) days=29; else days=28; }
 else if (dd[1]==4 || dd[1]==6 || dd[1]==9 || dd[1]==11) days=30;
 else days=31;

 if (day>days) dd[0]=days;

//alert(dd[0]+'.'+dd[1]+'.'+dd[2]);
 ref.value=dd[0]+'.'+dd[1]+'.'+dd[2];
}

function isLeapYear (Year) {
 if ((Year % 4)==0 && (Year % 100)!=0 || (Year % 400)==0) return (true);else return (false);
}

//special function to take change the "+" sign in equations
// to stop the string being changed at the "+" sign
 function wordcheck(entry){
    var checkplus = "";
    for (var n=1 ; n<=entry.length ; n++) 
    {
     if (entry.substring(n-1, n) == "+") checkplus+="^";
     else checkplus+=entry.substring(n-1, n); 
    }
   return checkplus;
 }

function toUpper(word)
{
 var check;
 check=word.toUpperCase();
 return(check);
}

function autoComplete (field, select, property, forcematch)
{
 var found = false;
 for (var i = 0; i < select.options.length; i++)
 {
  if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) == 0) { found=true; break; }
 }
 if (found) select.selectedIndex = i;
 else select.selectedIndex = -1;
 if (field.createTextRange)
 {
  if (forcematch && !found){ field.value=field.value.substring(0,field.value.length-1); return; }
  var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
  if (cursorKeys.indexOf(event.keyCode+";") == -1)
  {
   var r1 = field.createTextRange();
   var oldValue = r1.text;
   var newValue = found ? select.options[i][property] : oldValue;
   if (newValue != field.value)
   {
    field.value = newValue.substr(0,8);
    field.value = field.value.replace(',',' ');
    var rNew = field.createTextRange();
    rNew.moveStart('character', oldValue.length) ;
    rNew.select();
   }
  }
 }
}

function Loadss()
{
 if (window.opener)
 {
  var top=window.opener.parent.TOP.document.body.scrollTop+150;
  var width=(window.opener.parent.TOP.document.body.scrollWidth/2)-100;
 }
 else
 {
  var top=parent.TOP.document.body.scrollTop+150;
  var width=(document.body.scrollWidth/2)-100;
 }

 var message= '<DIV ID="load" STYLE="position:absolute; TOP:'+top+'px; LEFT:'+width+'px;">'
      +'<TABLE BORDER=1 bordercolor=orange CELLSPACING=0 CELLPADDING=0 bgcolor=#FFFFFF>'
      +'<tr><td width=100 height=25 align=center valign="center">'
//      +'<img src="../../ezi/images/progress.gif">'
      +'<marquee><font color=#000000>Please wait.... Please wait...</font></marquee>'
      +'</td></tr></TABLE>'
      +'</DIV>';

 if (window.opener) window.opener.parent.TOP.document.body.insertAdjacentHTML('BeforeEnd', message);
 else parent.TOP.document.body.insertAdjacentHTML('BeforeEnd', message);
}

///////////////////////////////object hide and show
function anyObj(divName)
{
 this.IE5=this.NN4=this.NN6=false
 if(document.all)this.IE5=true
 else if(document.layers)this.NN4=true
 else if(document.getElementById)this.NN6=true
	
 if(this.NN4)this.obj=eval("document."+divName)
 if(this.IE5)this.obj=eval("document.all."+divName)
 if(this.NN6)this.obj=eval("document.getElementById(\""+divName+"\")")

 this.show = showDiv
 this.hide = hideDiv
}

function showDiv()
{
  if(this.NN4) this.obj.visibility="visible";
  else this.obj.style.visibility="visible";
}

function hideDiv()
{
 if(this.NN4) this.obj.visibility="hidden";
 else this.obj.style.visibility="hidden";
}

function check_show()
{
 if (form.Resource.value && form.Resource.value == "Business Card" || form.Resource.value == "Leaflet")
 {
   myObj.show();
 }
 else myObj.hide();
}

function initialize() { myObj = new anyObj("tableDiv"); myObj.hide(); }
function hide_me(ref){ ref = new anyObj(ref); ref.hide(); }
function show_me(ref){ ref = new anyObj(ref); ref.show(); }

//////////////////////////////////////used with loader div
//var t_id = setInterval(animate,20); //use in loading ONLY
var pos=0;
var dir=2;
var len=0;

function animate()
{
	var elem = document.getElementById('progress');
	if(elem != null) {
		if (pos==0) len += dir;
		if (len>32 || pos>79) pos += dir;
		if (pos>79) len -= dir;
		if (pos>79 && len==0) pos=0;
		elem.style.left = pos;
		elem.style.width = len;
	}
}
function remove_loading() {
	this.clearInterval(t_id);
	var targelem = document.getElementById('loader_container');
	targelem.style.display='none';
	targelem.style.visibility='hidden';
}

////////////////UnkeyUp
function whichButton()
{
 //alert("got a key = " + event.keyCode);
 if (event.keyCode == 13) { var followingInput = document.getElementById("E"); followingInput.focus(); }
}

/////////////////chart of accounts focus
var DHTML = (document.getElementById || document.all || document.layers);

function getObj(name)
{
 if (!DHTML) return;
 if (document.getElementById)
 {
  this.obj = document.getElementById(name);
  this.style = document.getElementById(name).style;
 }
 else if (document.all)
 {
  this.obj = document.all[name];
  this.style = document.all[name].style;
 }
 else if (document.layers)
 {
  this.obj = document.layers[name];
  this.style = document.layers[name];
 }
}

function fillchart(me,chart)
{
 newObj=me;
 oldchart=chart;
 if(me.value!='9-9999')invi(0,me);
}

function finme(chart)
{
 newObj.value=chart;
 invi(1);
}

function invi(flag,id)
{
 var xx=125;var yy=150;
 if(event && id)
 {
  xx = event.clientX + document.body.scrollLeft+40; /* get the mouse left position */
  yy = event.clientY + document.body.scrollTop;     /* get the mouse top position  */
  if(event.clientY>350)yy-=15;
  if(event.clientX>700)xx-=130;
 }
 if (!DHTML) return;
 var x = new getObj('tchart');
 x.style.left=xx-120; x.style.top=yy-28;
 x.style.visibility = (flag) ? 'hidden' : 'visible';
}

function move(amount)
{
 var texttop = 300;
 if (!DHTML) return;
 var x = new getObj('tchart');
 texttop += amount;
 x.style.top = texttop;
}

function changeCol(col)
{
 if (!DHTML) return;
 var x = new getObj('tchart');
 x.style.color = col;
}

function etax(me,tax,code)
{
 for(var x=0;x < me.length;x++)if(me[x] && me[x].value==tax+code)me[x].selected=true;
}

/* cookies use to set working folder */

var expire = new Date ().getTime();

function GetCookie( cookieName )
{
 var cookieJar = document.cookie.split( "; " );
 for( var x = 0; x < cookieJar.length; x++ )
 {
  var oneCookie = cookieJar[x].split( "=" );
  if( oneCookie[0] == escape( cookieName ) ) { return unescape( oneCookie[1] ); }
 }
 return null;
}

function SetCookie( cookieName, cookieValue, lifeTime, path, domain, isSecure )
{
 if( !cookieName ) { return false; }
 if( lifeTime == "delete" ) { lifeTime = -10; } //this is in the past. Expires immediately.

 document.cookie = escape( cookieName ) + "=" + escape( cookieValue ) +
 ( lifeTime ? ";expires=" + new Date(expire + (24 * 60 * 60 * 1000 * lifeTime)).toGMTString() : "" ) +
 ( path ? ";path=" + path : "") + 
 ( domain ? ";domain=" + domain : "") + 
 ( isSecure ? ";secure" : "");

 //check if the cookie has been set/deleted as required
 if( lifeTime < 0 ) { if( typeof( GetCookie( cookieName ) ) == "string" ) { return false; } return true; }
 if( typeof( GetCookie( cookieName ) ) == "string" ) { return true; } return false;
}

///////////play sounds function
var ver=parseInt(navigator.appVersion)
var ie4=(ver>3  && navigator.appName!="Netscape")?1:0
var ns4=(ver>3  && navigator.appName=="Netscape")?1:0
var ns3=(ver==3 && navigator.appName=="Netscape")?1:0

function playSound(ref) {
 if (ie4) document.all['BGSOUND_ID'].src=ref;
 if ((ns4||ns3)
  && navigator.javaEnabled()
  && navigator.mimeTypes['audio/x-wav']
  && self.document.Bach.IsReady()
 ){ self.document.Bach.play() }
}

function stopSound(ref) {
 if (ie4) document.all['BGSOUND_ID'].src=ref;
 if ((ns4||ns3)
  && navigator.javaEnabled()
  && navigator.mimeTypes['audio/x-wav']
 ){ self.document.Bach.stop() }
}

//////////////////////////////hide layers
 function HideLayer(id,b)
 { 
  if (document.all)
  { 
   document.all[id].style.visibility = 'hidden';
   document.all[id].style.position   = 'absolute';
   if(b)document.all[id].style.display   = 'none';
  } 
  else if(document.layers)
  { 
   document.layers[id].visibility = 'hide';
   document.layers[id].position   = 'absolute';
   if(b)document.layers[id].display   = 'none';
  } 
  else if(document.getElementById)
  {
   document.getElementById(id).style.visibility ='hidden';
   document.getElementById(id).style.position   ='absolute';
   if(b)document.getElementById(id).style.display   = 'none';
  } 
 }
 
 function ShowLayer(id,t,b)
 {
  if (document.all && document.all[id])
  {
   if(t && document.all[id].style.visibility == 'visible'){ HideLayer(id,b); return; }
   document.all[id].style.visibility   = 'visible';
   document.all[id].style.position     = 'relative';
   if(b)document.all[id].style.display = 'block';
  } 
  else if(document.layers && document.layers[id])
  {
   if(t && document.layers[id].visibility == 'visible'){ HideLayer(id,b); return; }
   document.layers[id].visibility   = 'show' ;
   document.layers[id].position     = 'relative';
   if(b)document.layers[id].display = 'block';
  } 
  else if(document.getElementById && document.getElementById(id))
  {
   if(t && document.getElementById(id).style.visibility == 'visible'){ HideLayer(id,b); return; }
   document.getElementById(id).style.visibility   = 'visible';
   document.getElementById(id).style.position     = 'relative';
   if(b)document.getElementById(id).style.display = 'block';
  } 
 } 

//////menu
  var bgclr = new Array(); //used for menu background changing
  function mon(ref,x)
  {
   if(document.getElementById && document.getElementById('t'+ref)){ document.getElementById('t'+ref).className='td3'; }
   else if(document.all && document.all('t'+ref)){ document.all('t'+ref).className='td3'; }
   else{}
  }

  function moff(ref,x)
  {
   if(document.getElementById && document.getElementById('t'+ref)){ document.getElementById('t'+ref).className=bgclr[x]; }
   else if(document.all && document.all('t'+ref)){ document.all('t'+ref).className=bgclr[x]; }
   else{}
  }

  function ShowLay(ref,layrs)
  {
   var hide=1;
   for(var x=1;x<layrs+1;x++)
   {
    HideLayer('d'+x);
    bgclr[x]='td1';
    if(document.getElementById && document.getElementById('t'+x))
    {
     document.getElementById('t'+x).className='td1';
    }
    else if(document.all && document.all('t'+ref)){ document.all('t'+x).className='td1';  }
    else{}
   }
   ShowLayer('d'+ref);
   document.getElementById('t'+ref).className='td2';
   bgclr[ref]='td2';
   bgclr[layrs+1]='td1'; moff(layrs+1,layrs+1); //used for ALL
  }

  function ShowAll(layrs)
  {
   var n=0;
   ShowLay(1,layrs);
   for(var x=2;x<layrs+1;x++)
   {
    n++;
    bgclr[x]='td2';
    HideLayer('n'+n);
    ShowLayer('d'+x);
    document.getElementById('t'+x).className='td2';
   }
   bgclr[layrs+1]='td3'; moff(layrs+1,layrs+1); //used for ALL
  }
//end menu

//date writing
function pdate(page, name, date)
{
 var CurDate = new Date();
 var tYear   = CurDate.getFullYear();
 var tMonth  = CurDate.getMonth()+1;
 var tDay    = CurDate.getDate();
 var dmonth  = new Array('','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
 var i=1,d,m,y;
 if(!date)date=tYear+tMonth+tDay;
 d=parseFloat(date.charAt(6)+date.charAt(7));
 m=parseFloat(date.charAt(4)+date.charAt(5));
 y=parseFloat(date.charAt(0)+date.charAt(1)+date.charAt(2)+date.charAt(3));
 with(page)
 {
  write("<input type='hidden' name='"+name+"' value='d.m.y'>");
  write("<select class='input' name='"+name+"day' style=''>");//width:35px;
  for (i=1; i<10; i++){ if(i==d) write("<option value='0"+i+"' selected>"+i); else write("<option value='0"+i+"'>"+i); }
  for (i=i; i<32; i++) if(i==d)  write("<option value='"+i+"' selected>"+i); else write("<option value='"+i+"'>"+i);
  write("</select><select class='input' name='"+name+"month' style=''>");//width:35
  for (i=1; i<10; i++){ if(i==m) write("<option value='0"+i+"' selected>"+dmonth[i]); else write("<option value='0"+i+"'>"+dmonth[i]); };
  for (i=i; i<13; i++) if(i==m) write("<option value='"+i+"' selected>"+dmonth[i]); else write("<option value='"+i+"'>"+dmonth[i]);
  write("</select><select class='input' name='"+name+"year' style=''>");//width:47
  for (i=y-70; i<y+5; i++) if(i==y) write("<option value='"+i+"' selected>"+i); else write("<option value='"+i+"'>"+i);
  write("</select>");
 }
}

function CA(ref,process)
{
 var act=true;
 if(ref.checked!=true){ ref.checked=false; act=false; }
 for (i=0; i<form.elements.length; i++) if (form.elements[i].type == 'checkbox') form.elements[i].checked = act;
 if(process) process();
}

//////////////////Copy to Clipboard
//function CopyToClipboard(fromId)
//{
// var r = document.getElementById(fromId).createTextRange();
// r.select();
// r.execCommand('copy');
//}

//function ClipBoard() 
//{
//holdtext.innerText = copytext.innerText;
//Copied = holdtext.createTextRange();
//Copied.execCommand("Copy");
//}


///////////////////////morefields used for html journal entries
var counter   = 0;
var a; var b;
function moreFields()
{
 a=0; b=1; counter++;
 if (!document.getElementById  && !document.insertBefore){ alert('Please install a later browser.'); return; };
 var newFields = document.getElementById('readroot').cloneNode(true);
 newFields.id = 'clone'+counter;
 newFields.style.display = 'block';
 var newField = newFields.childNodes;
 for (var i=0;i<newField.length;i++)
 {
  var theName = newField[i].name;
  if (theName)newField[i].name = theName + counter;
  }
 var insertHere = document.getElementById('writeroot');
 insertHere.parentNode.insertBefore(newFields,insertHere);
}

function showhide(x)
{
 var chart1=form.chart1;
// var chart1=getElementById('chart1');
 var chart2=form.chart2;
 if(x==1)HideLayer('ch1'); 
 if(x==1)HideLayer('ch2');
 if(x>1) hidebof(form.bof[1]);
 if(chart1[x].value=='9-9999'){ hidebof(chart1[x]); }else{ showbof(chart1[x]); ShowLayer('ch1'); }
 if(chart2[x].value=='9-9999'){ hidebof(chart2[x]); }else{ showbof(chart2[x]); ShowLayer('ch2'); }
 if(form.Mchart1.value=='9-9999')  { hidebof(form.Mchart1);   }else{ showbof(form.Mchart1); form.type.value='C'; ShowLayer('ch2'); }
 if(form.Mchart2.value=='9-9999')  { hidebof(form.Mchart2);   }else{ showbof(form.Mchart2); form.type.value='D'; ShowLayer('ch1'); }
}

function hidebof(st){ st.style.visibility='hidden';  }
function showbof(st){ st.style.visibility='visible'; }

////////end morefields

///////Loading display
function Load(ref)
{
 var top=document.body.scrollTop+50; var width=(screenW/2)-100;
 if(ref==2){ }
 else if (window.opener)
 {
  var top=window.opener.parent.TOP.document.body.scrollTop+150;
  var width=(window.opener.parent.TOP.document.body.scrollWidth/2)-100;
 }
 else if(parent)
 {
  var top=parent.TOP.document.body.scrollTop+150;
  var width=(document.body.scrollWidth/2)-100;
 }

 var message= '<DIV ID="waitme" STYLE="position:absolute; TOP:'+top+'px; LEFT:'+width+'px; visibility:visible;">'
      +'<TABLE BORDER=1 bordercolor=orange CELLSPACING=0 CELLPADDING=0 bgcolor=#FFFFFF>'
      +'<tr><td width=100 height=25 align=center valign=center>'
      +'<img src="/ezi/images/progress.gif">'
      +'</td></tr></TABLE>'
      +'</div>';
// 
 pageLoaded=true;
 if(ref==2) document.write(message);
 else if (isIE && window.opener) window.opener.parent.TOP.document.body.insertAdjacentHTML('BeforeEnd', message);
 else if(isIE && parent) parent.TOP.document.body.insertAdjacentHTML('BeforeEnd', message);
 else if (window.opener) window.opener.parent.TOP.document.write(message);
 else if(parent)  parent.TOP.document.write(message);
}

function HideLoad(ref){ HideLayer('waitme'); }
/////end loading display



//######## chart of accounts
function chart(page, chart, name, YN, type, onclick, cwidth)
{
 var x=1;
 with(page)
 {
  write(" <select class='select' name='"+name+"' id='"+name+"' onClick='"+onclick+"' style='width:"+cwidth+"px;'> \n");
  if (type=='J')write(" <Option value='J' selected>Journal Entries Only\n");
  if (YN=='Y') x=0;
  while(x<achart.length)
  {
   write(" <option value='"+achart[x]+"'");
   if(chart==achart[x] && type!='J') write(" selected");
   write(">"+achart[x]+" "+descript[x]+"\n");
   x++;
  }
  write("</select>\n");
 }
}
//########

//######## display chart of account types in window
function dispchart(type)
{
 var x=1;
  write(" <select class='select' name='"+name+"' id='"+name+"' onClick='"+onclick+"' style='width:"+cwidth+"px;'> \n");
  if (type=='J')write(" <Option value='J' selected>Journal Entries Only\n");
  if (YN=='Y') x=0;
  while(x<achart.length)
  {
   write(" <option value='"+achart[x]+"'");
   if(chart==achart[x] && type!='J') write(" selected");
   write(">"+achart[x]+" "+descript[x]+"\n");
   x++;
  }
  write("</select>\n");

}
//########

//############### TIMER BAR
var i=0;
var tlen=0;
function Prog(len)
{
 tlen=len; //set the rate per process per item
 document.getElementById("d1").innerHTML="";
 document.getElementById("d2").style.width=0;
 timedProg();
}
function timedProg()
{
 if (i<=(500)){ if (i>20){document.getElementById("d1").innerHTML=parseInt(i/5)+"%" ; }
 document.getElementById("d2").style.width=i+"px";
 // simulates some lengthy processing
 var j=0; while (j<=100)j++; setTimeout("timedProg();", tlen); i++; }
}
function addscale(page)
{
 with(page)
 {
  write("<p id=timer style='position:relative;visibility:visible;' align=center>");
  write("<table bgcolor=#FFFFCC width=500 border=0 cellpadding=0 cellspacing=0>")
  write("<tr><td>");
  write("<div id='d2' style='position:relative;top:0px;left:0px;background-color:#660033;height:20px;width:0px;padding-top:5px;padding:0px;'>");
  write(" <div id='d1' style='position:relative;top:0px;left:0px;color:#FFFF33;height:20px;text-align:center;font:bold;padding:0px;padding-top:5px;'>");
  write(" </div>");
  write("</div>");
  write("</td></tr>");
  write("</table>");
  write("</p>\n");
 }
}

//################## END TIMERBAR
 /////form validation - storage and return onload/////
 function validatefields(ref)
 {
  var re=/'/g;
  for(var x=0;x<ref.length;x+=2)
  {
   var field= document.getElementById(ref[x]);
   if(field)
   {
    if(field.type=='textarea')field.value=field.value.replace(re,'`'); document.getElementById(ref[x]).value=field.value;
    if(field.value==''
       || (field.name.indexOf('Email')!=-1 && (field.value.indexOf('@')==-1 || field.value.indexOf('.')==-1)
      )
     )
    {
     if((field.name=='Phone' || field.name=='Mobile')
         && (document.getElementById('Phone').value!='' || document.getElementById('Mobile').value!='')){ document.getElementById(ref[x]).style.background='white'; continue; }
     if(field.name=='Email')alert('A valid email address is required.');
     else alert(ref[x+1]+' field required.');
     document.getElementById(ref[x]).style.background='pink';
     if(document.getElementById(ref[x]).type!='hidden')document.getElementById(ref[x]).focus();
     x=ref.length;
     return false;
    }
    document.getElementById(ref[x]).style.background='white';
   }
  }
  return true;
 }

 function storefields(no,ref,days)
 {
  for(var x=0;x<ref.length;x+=2)
  {
   var field= document.getElementById(ref[x]);
   if(field)
   {
    if(field.name=='code' || field.name=='PW')continue;
    else if(field && field.name && field.value)
    {
     if(field.value.indexOf('Email')!=-1 || field.value.indexOf('PassWord')!=-1 || field.value.indexOf('PW')!=-1)
     {
      SetCookie(no+field.name,field.value,days,'/');
     }
     else
     {
      if(field.value.indexOf('Email')!=-1)field.value=answer.toLowerCase()
      SetCookie(no+field.name,field.value,0,'/');
     }
    }
   }
  }
 }

 function returnfields(no,ref)
 {
  if(no)
  {
   for(var x=0;x<ref.length;x+=2)
   {
    var field= document.getElementById(ref[x]);
    if(field)
    {
     var val= GetCookie(no+field.name);
     if(val != null)
     {
      if(field.style!='radio' && field.name!='PassWord' && field.name!='APW')
       document.getElementById(ref[x]).value=trim(val);
     }
    }
   }
  }
 }
///////////////////////////////////////////////////////////////

function Hideall(ref){ for(var x=1;x<=ref;x++)HideLayer('L'+x); }

// returns true if the string only contains characters A-Z or a-z
function isaAlpha(str)
{
  var re = /[^a-zA-Z]/g
  if (re.test(str)) return false;
  return true;
}
// returns true if the string only contains characters 0-9
function isaNumeric(str)
{
  var re = /[\D]/g
  if (re.test(str)) return false;
  return true;
}

function ModalWindow(h,w,t,l,url)
{
 var Arguments = ''; new Object();
 var Elements="dialogTop:'+t+'px; dialogLeft:'+l+'px; dialogWidth:"+w+"px; dialogHeight:"+h+"px; center:yes; edge:raised; status:off;";
 window.showModalDialog(url, Arguments, Elements);
}

