document.writeln("<SCRIPT src='../"+m_cThemePath+"/formTitle.js'></SCRIPT>");

//***********************************************************************
//                   Configuration variables:
var qp_bBorder=false;
var FormName='queryPage';
//***********************************************************************
function WriteBody_Begin(doc,events,height,addTitle,addToolbar){
  if (addTitle==null) addTitle=true;
  //Se la pagina e' nel frame menu bisogna cambiarne le impostazioni(Titolo e backkground)
  doc.writeln("<BODY "+events+" onresize='DoOnResize()' style='margin:0;padding:0;overflow:hidden'>");
  PrepareJsCalendar();
  doc.writeln("<TABLE border='0' width='100%' height='100%' cellpadding='0' cellspacing='0'>");
  if(window.name=='main'){
    if(addTitle){
      doc.writeln("<TR>");
      doc.writeln("<TD id='titleTD' valign='top' style='width:0;height:0'>");
      Title(doc);
      doc.writeln("</TD>");
      doc.writeln("</TR>");
    }
  }
  doc.writeln("<TR>");
  doc.writeln("<TD id='mainTD' valign='top' style='width:100%;height:100%'>");
  doc.writeln("<DIV id='bodyDiv' style='overflow:auto;width:0;height:0'>");
}
function DoOnResize() {
  adjustWidthAndHeight();
  if(typeof(AdjustOnResize)!='undefined')
    AdjustOnResize();
}
function adjustWidthAndHeight(){
  var titH,mainHeight;
  titH=Ctrl("titleTD")==null ? 0 : Ctrl("titleTD").offsetHeight;
  Ctrl("bodyDiv").style.width=document.body.clientWidth>0 ? document.body.clientWidth : document.body.offsetWidth;
  Ctrl("bodyDiv").style.height=0;
  var mainHeight=(document.body.clientHeight>0 ? document.body.clientHeight : document.body.offsetHeight)-titH;
  Ctrl("bodyDiv").style.height=mainHeight;
  if(Ctrl("scrollDiv")!=null){
    var updH=Ctrl("TblUpdateBtn")!=null?Ctrl("TblUpdateBtn").clientHeight:0;
    var headerH=Ctrl("header")!=null?parseInt(Ctrl("header").style.height):0;
    var footerH=Ctrl("pageFooter")!=null?parseInt(Ctrl("pageFooter").style.height):0;
    Ctrl("scrollDiv").style.width = Ctrl("bodyDiv").style.width;
    Ctrl("scrollDiv").style.height = Max(1,mainHeight)-footerH-headerH-titH-updH;
    Ctrl("bodyBegin").style.width=parseInt(Ctrl("scrollDiv").style.width)-18;
  }
}
function WriteBody_EndHtml(doc,addToolbar){
  doc.writeln("</DIV>");
  doc.writeln("</TD>");
  doc.writeln("</TR>");
  doc.writeln("</TABLE>");
}
function WriteBody_End(doc){
  doc.writeln("<NOSCRIPT>JavaScript required to see this page</NOSCRIPT>");
  doc.writeln("<SPAN id='dpi_controller' style='position:absolute;top:0;left:0;font-family:verdana;font-size:8pt;visibility:hidden'>0</SPAN>");
  doc.writeln("</BODY>");
  var dpi_controller=Ctrl("dpi_controller");
  try{
    if(dpi_controller.clientHeight>13) AdjustFontSize(dpi_controller.clientHeight/13);
  }catch(e){}
  DoOnResize();
}
function Header_BeginHtml(height){
  document.writeln("<DIV id='header' style='position:relative;height:"+height+"'>");
}
function Header_EndHtml(){
  document.writeln("</DIV>");
}
function Body_BeginHtml(h,bordercolor,borderwidth,positioning,tableRules){
  qp_bBorder=(borderwidth>0);
  if(positioning!='T'){
    if(window.name!='menu' && !qp_bBorder && typeof(sv_PageBeginDetailHtml)!='undefined'){
      document.writeln(sv_PageBeginDetailHtml);
    }
    document.writeln("<DIV style='position:relative'>");
    if(qp_bBorder)
      document.writeln("<DIV id=bodyBegin style='position:relative;border:"+bordercolor+" solid "+borderwidth+"px;' width='100%'>");
    else
      document.writeln("<DIV id=bodyBegin width='100%'>");
  }
  else{
    if(qp_bBorder){
      if(tableRules=='plain')
        document.writeln("<TABLE id=bodyBegin class='QueryPageTable' width='80%' align='center' cellspacing='"+borderwidth+"' cellpadding='2' style='background-color:"+bordercolor+"'>");
      else
        document.writeln("<TABLE id=bodyBegin class='QueryPageTable' width='80%' align='center' cellspacing='0' cellpadding='2' rules='"+tableRules+"' style='border-color:"+bordercolor+";border-width:"+borderwidth+"'>");
    }
    else
      document.writeln("<TABLE id=bodyBegin class='QueryPageTable' width='80%' align='center' cellspacing='0' cellpadding='2'>");
  }
}
function Body_EndHtml(positioning){
  //Se la pagina e' nel frame menu bisogna cambiarne le impostazioni(Linee che separano Header/Body/Footer)
  if(positioning!='T'){
    document.writeln("</DIV>");
    if(window.name!='menu' && !qp_bBorder && typeof(sv_PageEndDetailHtml)!='undefined'){
      document.writeln(sv_PageEndDetailHtml);
    }
    document.writeln("</DIV>");
  }
  else{
    document.writeln("</TABLE>");
  }
}
function AddColGroups(nCols) {
  for(i=0;i<nCols;i++) {
    document.writeln("<COLGROUP>");
  }
}
function Row_BeginHtml(document,rowcnt,id,positioning,rowcolor,w){
  if(rowcolor==null) rowcolor=true;
  if(w==null) w=-1;

  if(positioning!='T'){
    var s='position:relative;width:';
    if(w==-1)
      s=s+'100%;';
    else
      s=s+w+';float:left;';
    if(rowcolor && window.name!='menu'){
      document.writeln("<DIV class='"+((rowcnt%2)==0 ? "EvenRow" : "OddRow")+"' id="+id+" style='"+s+"'>");
    }
    else{
      document.writeln("<DIV id="+id+" style='"+s+"'>");
    }
  }
  else{
    if(rowcolor && window.name!='menu'){
      document.writeln("<TBODY class='"+((rowcnt%2)==0 ? "EvenRow" : "OddRow")+"'>");
    }
    else{
      document.writeln("<TBODY class='PageBg'>");
    }
  }
}
function Row_EndHtml(document,rowcnt,id,positioning){
  if (positioning!='T') {
    document.writeln("</DIV>");
  }
  else {
    document.writeln("</TBODY>");
  }
}
/* actually unused*/
function AddRow_BeginHtml(rowcnt){
  document.writeln("<TR>");
}
/* actually unused*/
function AddRow_EndHtml(rowcnt){
  document.writeln("</TR>");
}
function GroupColor(deep){
  var colorClass;
  switch(deep%4){
    case 1:
      colorClass='Group1';
      break;
    case 2:
      colorClass='Group2';
      break;
    case 3:
      colorClass='Group3';
      break;
    case 0:
      colorClass='Group4';
      break;
  }
  return colorClass;
}
function GroupHeader_BeginHtml(document,deep,id,positioning,groupcolor,columned_detail){
  if(groupcolor==null) groupcolor=true;
  if(columned_detail==null) columned_detail=false;

  if(positioning!='T'){
    var s="position:relative";
    if(columned_detail){
      s+=";float:left;clear:both;width:100%";
    }
    if(groupcolor)
      document.writeln("<DIV class='"+GroupColor(deep)+"' id="+id+" style='"+s+"'>");
    else
      document.writeln("<DIV id="+id+" style='"+s+"'>");
  }
  else{
    if(groupcolor)
      document.writeln("<TBODY class='"+GroupColor(deep)+"'>");
    else
      document.writeln("<TBODY>");
  }
}
function GroupHeader_EndHtml(document,deep,id,positioning){
  if(positioning!='T'){
    document.writeln("</DIV>");
  }
  else{
    document.writeln("</TBODY>");
  }
}
function GroupFooter_BeginHtml(document,deep,id,positioning,groupcolor,columned_detail) {
  if(groupcolor==null) groupcolor=true;
  if(columned_detail==null) columned_detail=false;

  if(positioning!='T'){
    var s="position:relative";
    if(columned_detail){
      s+=";float:left;clear:both;width:100%";
    }
    if (groupcolor)
      document.writeln("<DIV class='"+GroupColor(deep)+"' id="+id+" style='"+s+"'>");
    else
      document.writeln("<DIV id="+id+" style='"+s+"'>");
  }
  else{
    if(groupcolor)
      document.writeln("<TBODY class='"+GroupColor(deep)+"'>");
    else
      document.writeln("<TBODY>");
  }
}
function GroupFooter_EndHtml(document,deep,id,positioning){
  if(positioning!='T'){
    document.writeln("</DIV>");
  }
  else {
    document.writeln("</TBODY>");
  }
}
/* actually unused*/
function AddGroupRow_BeginHtml(deep){
  document.writeln("<TR>");
}
/* actually unused*/
function AddGroupRow_EndHtml(){
  document.writeln("</TR>");
}
function Body_Buttons(prev,next,positioning){
  if (!prev && !next) return;

  if(positioning=='T')
    document.writeln("<TR><TD>");

  document.writeln("<TABLE cellspacing='0' cellpadding='0' border='0'>");
  document.writeln("<TR><TD>");
  if (prev) {
    document.writeln("<BUTTON type='button' style='background-color:Transparent;margin:0;border-width:0;padding:0' onclick='DoPrevious()'>");
    document.writeln("<IMG border=0 src='../"+m_cThemePath+"/page/page_back.gif' alt='Previous page'></button>");
  }
  document.writeln("</TD><TD>");
  if (next) {
    document.writeln("<BUTTON type='button' style='background-color:Transparent;margin:0;border-width:0;padding:0' onclick='DoNext()'>");
    document.writeln("<IMG border=0 src='../"+m_cThemePath+"/page/page_forward.gif' alt='Next page'></button>");
  }
  document.writeln("</TD></TR>");
  document.writeln("</TABLE>");

  if(positioning=='T')
    document.writeln("</TD></TR>");
}
function Update_Button(name,caption,image,align,title,style,disabled,positioning){
  if (m_cDecoration=='none') return
  var htmlAlign = 'LEFT';
  switch (align) {
    case 'C':
      htmlAlign = 'CENTER';
      break;
    case 'R':
      htmlAlign = 'RIGHT';
      break;
  }
  if (positioning!='T')
    document.writeln("<TABLE id=TblUpdateBtn width='100%'>");
  document.writeln("<TR>");
  document.writeln("<TD align='"+htmlAlign+"' colspan='100'>");
  AddUpdateButton(name,caption,image,title,style,disabled);
  document.writeln("</TD>");
  document.writeln("</TR>");
  if (positioning!='T')
    document.writeln("</TABLE>");
}
function UpdateRow_Button(name,caption,image,align,title,style,disabled,rownum,positioning){
  if (m_cDecoration=='none') return
  var htmlAlign='LEFT';
  switch(align){
    case 'C':
      htmlAlign='CENTER';
      break;
    case 'R':
      htmlAlign='RIGHT';
      break;
  }
  if(positioning!='T')
    document.writeln("<TABLE width='100%' cellspacing='0' cellpadding='0'>");
  AddRow_BeginHtml(rownum);
  document.writeln("<TD align='"+htmlAlign+"' colspan='100'>");
  AddUpdateButton(name,caption,image,title,style,disabled,rownum);
  document.writeln("</TD>");
  AddRow_EndHtml(rownum);
  if (positioning!='T')
    document.writeln("</TABLE>");
}
function AddUpdateButton(name,caption,image,title,style,disabled,rownum){
  var focus='';
  if (image!=''){
    if(rownum!=null){
      focus="ChangeRow("+rownum+");";
    }
    document.writeln("<A href='javascript:"+focus+"Update()'><IMG "+style+" id='"+name+"' src='"+image+"' border='0' title="+ToHTMLValue(title)+"></IMG></A>");
  }
  else{
    if(rownum!=null){
      focus=" onfocus=ChangeRow("+rownum+") ";
    }
    document.writeln("<INPUT "+style+" name='"+name+disabled+"' type='button' value="+ToHTMLValue(caption)+" onclick='Update()' title="+ToHTMLValue(title)+" "+focus+">");
  }
}
function Footer_BeginHtml(height){
  document.writeln("<DIV id='pageFooter' style='position:relative;height:"+height+"'>");
}
function Footer_EndHtml(){
  document.writeln("</DIV>");
}
function ColumnedDetailEnd_BeginHtml(){
  document.writeln("<DIV style='float:left;clear:both'>");
}
function ColumnedDetailEnd_EndHtml(){
  document.writeln("</DIV>");
}

