var ppimgNW;

function popupImage(src, note, title, css, border) {
  if (border==null) border = 0;
  if (note==null) note = '';
  if (ppimgNW != null) ppimgNW.close();

  ppimgNW = window.open('','POPUPIMAGE','width=1,height=1');
  var doc = ppimgNW.document;
  doc.write('<html>');
  doc.write('<head>');

  if (title!=null) doc.write('<title>'+ title +'</title>');
  doc.write('<style> body {'+css+'} #ppImgText{'+ css +'} #ppImg{cursor:hand}</style></head>');
  doc.write('<body leftmargin="0" topmargin="' + border + '">');
  doc.write('<div align="center">');
  doc.write('<img src="' + src + '" id="ppImg" onclick="self.close();" title="Close">');
  doc.write('</div>');
  doc.write('<div style="height:1; width:' + border + '; font-size:4pt;">');
  doc.write('</div>');
  doc.write('<div id="ppImgText" align="center">');
  doc.write(note);
  doc.write('</div>');
  doc.write('</body>');
  doc.write('</html>');

  doc.write('<' + 'script>');
  doc.write('var resized = false;');
  doc.write('function doResize() {');
  doc.write('  var imgW = ppImg.width, imgH = ppImg.height;');     
  doc.write('  window.resizeTo(imgW + 8 +' + border*2 +', imgH + ppImgText.offsetHeight + 26 + '+ border*2 +');');
  doc.write('  setTimeout("doResize()",1000);');

  doc.write('}');
  doc.write('doResize(); ');
  doc.write('</' + 'script>');
}



// Restrict input alphabetic letters only ////////////////
// USAGE: onKeyPress="checkAlphabetic();"
function checkAlphabetic() {
  if ((event.keyCode >= 65 && event.keyCode <= 90) || (event.keyCode >= 65+32 && event.keyCode <= 90+32))
    return; 
  else
    event.returnValue = null;
}

// Restrict input numeric letters only /////////////////
// USAGE: onKeyPress="checkNumeric();"
function checkNumeric() {
  if ((event.keyCode >= 48 && event.keyCode <= 57))
    return; 
  else
    event.returnValue = null;
}

function hasChars(str, charStr) {
  var i;
  for (i=0; i<charStr.length; i++) {
    if (str.indexOf(charStr.charAt(i)) >= 0)
      return true;
  }
  return false;
}

function isEmail(str) {
  iAt = str.indexOf('@');
  iDot = str.lastIndexOf('.');
  return (iAt>=0 && iDot>=0 && iAt<iDot);
}

function isUsername(str) {
  return (!hasChars(str, ' ~!@#$%^&*()+|=\\{}[]:";\'<>?,./')) && str.length > 3;
}

function isPassword(str) {
  return (!hasChars(str, ' ~!@#$%^&*()+|=\\{}[]:";\'<>?,./'))  && str.length > 3;
}

function csv2Array(str, seperator) {
  var csv = new Array();
  var i=0, ci=0, ch;
  var realLength = str.length, start = 0;

  seperator = seperator==null ? ',' : seperator;

  while (str.charAt(start) == seperator) start++;
  while (str.charAt(realLength-1) == seperator) realLength--;
  
  csv[ci] = '';
  for (i=start; i<realLength; i++) { 
    if (str.charAt(i) != seperator) {
      csv[ci] += str.charAt(i);
    } else {
      csv[++ci] = '';
    }    
  }
  return csv;
}

function writeItem(aArgs,sSelect) {
  for (i=0; i<aArgs.length; i+=2)
    if (sSelect == aArgs[i+1]) {
      document.write(aArgs[i]);
      return;
    }
}

function writeSelect(sName, aArgs, sSelect, sAttr) {
  document.write('<select name="' + sName + '" ' + (sAttr==null ? '' : sAttr) + '>');
  for (i=0; i<aArgs.length; i+=2) {
    if (sSelect == aArgs[i+1])
      document.write('<option' + (aArgs[i+1]!=null ? ' value="' + aArgs[i+1] + '"' : '') + ' selected>' + aArgs[i] + '</option>\r\n');
    else
      document.write('<option' + (aArgs[i+1]!=null ? ' value="' + aArgs[i+1] + '"' : '') + '>' + aArgs[i] + '</option>\r\n');
  }
  document.write('</select>');
}

function writeDayMonthYear(name, d, m, y, h, mn) {
  var dt = new Date();
  d = d==null ? dt.getDate() : d;
  m = m==null ? dt.getMonth()+1 : m;
  y = y==null ? dt.getYear() : y;

  document.write('<input type="hidden" id=xxzz name="'+ name +'" value="'+m+'/'+d+'/'+y+'">');
  document.write('<input type="hidden" name="'+ name +'_vn" value="'+d+'/'+m+'/'+y+'">');
  writeSelect(name + '_fpt_wdmy_d', new Array('1','1','2','2','3','3','4','4','5','5','6','6','7','7','8','8','9','9','10','10','11','11','12','12','13','13','14','14','15','15','16','16','17','17','18','18','19','19','20','20','21','21','22','22','23','23','24','24','25','25','26','26','27','27','28','28','29','29','30','30','31','31','--',''), d, 
              'onchange="document.all(\''+ name +'\').value = document.all(\'' + name + '_fpt_wdmy_m\').value + \'/\' + document.all(\'' + name + '_fpt_wdmy_d\').value + \'/\' + document.all(\'' + name + '_fpt_wdmy_y\').value + \' \' + '+ name +'_fpt_wdmy_th.value + \':\' + '+ name +'_fpt_wdmy_tm.value;"' +
              'xonchange="document.all(\''+ name +'_vn\').value = document.all(\'' + name + '_fpt_wdmy_d\').value + \'/\' + document.all(\'' + name + '_fpt_wdmy_m\').value + \'/\' + document.all(\'' + name + '_fpt_wdmy_y\').value;"');
  document.write('&nbsp');
  writeSelect(name + '_fpt_wdmy_m', new Array('Jan.','1','Feb.','2','Mar.','3','Apr.','4','May','5','Jun.','6','Jul.','7','Aug.','8','Sep.','9','Oct.','10','Nov.','11','Dec.','12','--',''), m, 
              'onchange="document.all(\''+ name +'\').value = document.all(\'' + name + '_fpt_wdmy_m\').value + \'/\' + document.all(\'' + name + '_fpt_wdmy_d\').value + \'/\' + document.all(\'' + name + '_fpt_wdmy_y\').value + \' \' + '+ name +'_fpt_wdmy_th.value + \':\' + '+ name +'_fpt_wdmy_tm.value;"' +
              'xonchange="document.all(\''+ name +'_vn\').value = document.all(\'' + name + '_fpt_wdmy_d\').value + \'/\' + document.all(\'' + name + '_fpt_wdmy_m\').value + \'/\' + document.all(\'' + name + '_fpt_wdmy_y\').value;"');
  document.write('&nbsp');
  writeSelect(name + '_fpt_wdmy_y', new Array(1960,1960,1961,1961,1962,1962,1963,1963,1964,1964,1965,1965,1966,1966,1967,1967,1968,1968,1969,1969,1970,1970,1971,1971,1972,1972,1973,1973,1974,1974,1975,1975,1976,1976,1977,1977,1978,1978,1979,1979,1980,1980,1981,1981,1982,1982,1983,1983,1984,1984,1985,1985,1986,1986,1987,1987,1988,1988,1989,1989,1990,1990,1990,1990,1991,1991,1992,1992,1993,1993,1994,1994,1995,1995,1996,1996,1997,1997,1998,1998,1999,1999,2000,2000,2001,2001,2002,2002,2003,2003,2004,2004,2005,2005,2006,2006,2007,2007,2008,2008,'----',''), y, 
              'onchange="document.all(\''+ name +'\').value = document.all(\'' + name + '_fpt_wdmy_m\').value + \'/\' + document.all(\'' + name + '_fpt_wdmy_d\').value + \'/\' + document.all(\'' + name + '_fpt_wdmy_y\').value + \' \' + '+ name +'_fpt_wdmy_th.value + \':\' + '+ name +'_fpt_wdmy_tm.value;"' +
              'xonchange="document.all(\''+ name +'_vn\').value = document.all(\'' + name + '_fpt_wdmy_d\').value + \'/\' + document.all(\'' + name + '_fpt_wdmy_m\').value + \'/\' + document.all(\'' + name + '_fpt_wdmy_y\').value;"');
  if (h!=null)
    document.write(' <input maxlength=2 onKeyPress=checkNumeric(); size=2 type=text id='+ name +'_fpt_wdmy_th value='+ h +
                   ' onchange="document.all(\''+ name +'\').value = document.all(\'' + name + '_fpt_wdmy_m\').value + \'/\' + document.all(\'' + name + '_fpt_wdmy_d\').value + \'/\' + document.all(\'' + name + '_fpt_wdmy_y\').value + \' \' + '+ name +'_fpt_wdmy_th.value + \':\' + '+ name +'_fpt_wdmy_tm.value;"' +
                   '>');
  else
    document.write(' <input size=2 type=hidden id='+ name +'_fpt_wdmy_th value='+ dt.getHours() +'>');

  if (mn!=null)
    document.write('h<input maxlength=2 onKeyPress=checkNumeric(); size=2 type=text id='+ name +'_fpt_wdmy_tm value='+ mn +
                   ' onchange="document.all(\''+ name +'\').value = document.all(\'' + name + '_fpt_wdmy_m\').value + \'/\' + document.all(\'' + name + '_fpt_wdmy_d\').value + \'/\' + document.all(\'' + name + '_fpt_wdmy_y\').value + \' \' + '+ name +'_fpt_wdmy_th.value + \':\' + '+ name +'_fpt_wdmy_tm.value;"' +
                   '>');
  else
    document.write('<input size=2 type=hidden id='+ name +'_fpt_wdmy_tm value='+ dt.getMinutes() +'>');

  //document.write('<scr' + 'ipt>function updateDMY(name) { document.all(\''+ name +'\').value = document.all(\'' + name + '_fpt_wdmy_m\').value + \'/\' + document.all(\'' + name + '_fpt_wdmy_d\').value + \'/\' + document.all(\'' + name + '_fpt_wdmy_y\').value + \' \' + '+ name +'_fpt_wdmy_th.value + \':\' + '+ name +'_fpt_wdmy_tm.value; } </scr' + 'ipt>');

}