var isSent=0;
var fwShowCursor=1; //1:show, 0:not show
var fwCursor;
function collectInputs(obj) {
  if (submitit()) {
    cursorInit();
    var sf_params = "";
    for ( i=0; i<document.forms.length; i++ ) {
      var form = document.forms[i];
      var pagePrefix = "";
      for ( j=0; j<form.elements.length; j++ ) {
        var t=form.elements[j].type, n=form.elements[j].name, v=form.elements[j].value;
        if (v==null||v=="") {continue;}
        if (n=="PAGE_PREFIX" ) {pagePrefix=v;continue;} 
        else if (n=="FW_PARAMS") {continue;}
        if (t=="submit"||t=="button"||t=="reset"||t=="file") {continue;}
        if (t.indexOf("select")!= -1) {v= getSelectValue(form.elements[j]);}
        if ((t=="checkbox"||t=="radio") && !form.elements[j].checked ) {continue;}
        if (t=="text") {v=v.replace('&quot;','"')}
        if (sf_params!="") {sf_params += "&";}
        sf_params+=pagePrefix+"."+n+"="+escape(v);
      }
    }
    
    obj.FW_PARAMS.value=sf_params;
    return true;
  } else { return false; }
}

function getSelectValue(sel) {
  var r = "", opts = sel.options, cnt = 0;
  for ( var i=0; i<opts.length; i++ ) {
    var o=opts[i]; if ( o.selected ) { if ( cnt > 0 ) {r += ",";} r+=o.value; cnt++; }
  }
  return r;
}

function submitCommand(u) {
  var f;
  if (arguments[1]){f=arguments[1];}
  else {
    if (u.href){f=u.getAttribute("fwForm");}
    if (f==null){f=fwGetForm();}
    else {
      if (f=="") {return true;} //just a link when fwForm attribute is blank. ex : <A HREF="PageServlet?pg=xxx&tg=yyy" fwForm="">...</A>
      f = eval("document."+f);
    }
  }  
  if (collectInputs(f)) {
    if(u.href){f.action=u.href;if(u.target==""||u.target==null){f.target="_self";}else{f.target=u.target;}}else{f.action=u;}
    f.submit();
  }
  return false;
}

//<FORM action="/PageServlet?pg=home_welcome&pfx=home_welcome.fw_submitform&tg=fw_submitform&null" NAME="fw_submitform" METHOD="post">
//<input type="hidden" name="PAGE_PREFIX" value="home_welcome.fw_submitform">
//<input type="hidden" name="FW_PARAMS" value="">
//</FORM>
function fwGetForm() {
  var f=document.fw_submitform;
  if (f==null) {
    f = document.createElement("FORM");
    f.method="post"; f.style.visibility="hidden"; f.name="fw_submitform";
    document.body.appendChild(f);
    var loc = window.location.href;
    var idx1 = loc.indexOf("pg="), idx2 = loc.indexOf("&", idx1);
    if (idx2==-1){pg=loc.substring(idx1+3);}
    else {pg=loc.substring(idx1+3, idx2);}
    f.action = "/PageServlet?pg=" + pg + "&pfx=" + pg + ".fw_submitform&tg=fw_submitform";
    f.innerHTML = "<input type='hidden' name='PAGE_PREFIX' value='" + pg + ".fw_submitform'><input type='hidden' name='FW_PARAMS'>";
  }
  return f;
}

function cursorInit(){fwGetForm();}
function submitit() {if(isSent==0) {isSent=1;setTimeout("resetCounter()", 5000); return true;} else {return false;}}
function resetCounter() {isSent=0;}

function ccBeforeUnload() {  
  resetCounter();
  if(typeof(ccBeforeUnloadFWS)=="function") {if(!ccBeforeUnloadFWS()) {return false;}}
  if(typeof(ccBeforeUnloadLocal)=="function") {if(!ccBeforeUnloadLocal()) {return false;}}
  if(typeof(ccDoUsageTracking) == "function") { ccDoUsageTracking(); }
}

window.onbeforeunload=ccBeforeUnload;


if(typeof(ccNoResetCounter)=='undefined') {
  try {if(opener && opener.ccResetTimeOut) {opener.ccResetTimeOut();}}catch(e){}
}

function setCmd(val) {
  var len = arguments.length;
  if (len==1) {
    var g = 0;
    for (var j=0; j<document.forms.length; j++) {if(document.forms[j].cmd) { document.forms[j].cmd.value=val; g++; } }
    if(!g) {alert("Please use our feedback form to report this error."); return false;} else { return true; }
  } else if (len==2) {
    var f=arguments[1];
    if (f.cmd) {f.cmd.value=val;} else {f.action=f.action+"&cmd="+val;}
    return true;
  }
}