var iwpath='',tsvpath='',re_iw_content=/\/content\/[A-Z0-9_\/]+\.jsp$/;
function setIWpath(path){
  iwpath=path;
}
/**************************************************************************
  showzone support following format of calls:
  
   - showzone(dcr_path, face_text, start_date, end_date);
     This is used for display scheduled dates with customized face text, 
     underline link is path to DCR after templatedata/content.
      
   - showzone(dcr_path/iw-web_file_path, face_text);
     This is used for display customized face text, underline link is 
     path to DCR after templatedata/content or any other non-iw generated 
     files underneath iw-web directory.

   - showzone(iw_web_content_file_path);
     This is used for backward compatibility. parameter should be existing 
     iw generated file in iw-web/content directory (exclusive).
      
   - showzone();
     used for close 'showzone' div tag.
    
**************************************************************************/
var SHOWZONE_START_HTML = '<div class="showzone">';
var SHOWZONE_END_HTML = '</div>';
function showzone(){
  if(iwpath != ''){
    var out = [];
    var al=arguments.length,a=arguments;
    
    if(al==2 && typeof a[0] != 'undefined' && typeof a[1] != 'undefined'){
      var ref = iwpath+a[0],faceTxt=a[1];
			out.push(SHOWZONE_START_HTML);
      out.push('<a target="_blank" href="');
      out.push(ref);
      out.push('">Edit ');
      out.push(faceTxt);
      out.push('</a>');
			out.push(SHOWZONE_END_HTML);
      
    /* Note: this code is used only for 'showzone' feature coupled with date compare. */
    } else if(al==4 && typeof a[0] != 'undefined' &&
                       typeof a[1] != 'undefined' &&
                       typeof a[2] != 'undefined' &&
                       typeof a[3] != 'undefined') {
      
      var ref = iwpath+a[0], faceTxt=a[1];
			out.push(SHOWZONE_START_HTML);
      out.push('<a target="_blank" href="');
      out.push(ref);
      out.push('">Edit ');
      out.push(faceTxt);
      out.push('</a>');
      if(a[2] != '') out.push('<span class="date">start: '+a[2]+'</span>');
      if(a[3] != '') out.push('<span class="date">end: '+a[3]+'</span>');
			out.push(SHOWZONE_END_HTML);
      
    /* Note: this code is used only for 'showzone' feature backward compactivity. */
    } else if(al==1 && typeof a[0] != 'undefined'){
      var tsvpath = iwpath.replace(/templatedata/, "iw-web");
      var re_content = /^\/.+?\/(\w+)\.jsp$/;
			out.push(SHOWZONE_START_HTML);
      out.push('<a target="_blank" href="');
      out.push(tsvpath+a[0]);
      out.push('">Edit ');
      out.push(a[0].replace(re_content,'$1'));
      out.push('</a>');
			out.push(SHOWZONE_END_HTML);
    }
    document.write(out.join(''));
  }
}
