/* Copyright (c) 2008-2009 Developing Solutions, Inc.
 * All rights reserved.
 *
 * This product is distributed under licenses restricting its use,
 * copying, distribution, and decompilation. No part of this product may
 * be reproduced in any form by any means without prior written
 * authorization of Developing Solutions, Inc. and its licensors, if any.
 * 
 */

/*------------------- Scripts for form/document submission ------------------------*/

function validateSubmit(formId, value_) 
{ 
   var status = false;
   if (submitting == 0) 
   {
      if (anyfieldChanged == 0) { devsolAlert("No values have been changed!\n\nIf you have pasted to a field, please click outside the field to register the change."); }
      else if (validateForm())
      {
	 submitting=1; 
	 var obj = document.getElementById(formId); obj.submitted_by.value=value_;
         status = true;
      }
   }
   return status;
}

function failSubmit() 
{ 
	var status = false;
	devsolAlert("Form may not be submitted! You do not have permission.");
	return status;
}

function saveData(formId, value_) 
{ 
   if (submitting == 0) 
   {
      if (anyfieldChanged == 0) { devsolAlert("No values have been changed!\n\nIf you have pasted to a field, please click outside the field to register the change."); }
      else if (validateForm())
      {
         submitting=1; 
         var obj = document.getElementById(formId); obj.submitted_by.value=value_; obj.submit(); 
      }
   }
}

function submitDoc(value, formId)
{
	if (submitting == 0 && value != null) 
	{ 
		submitting=1; 
		var obj = document.getElementById(formId); obj.submitted_by.value="Submit_Document"; obj.DocState.value=value; obj.submit(); 
	}
}

function submitNow(formId, value_)
{
        if (submitting == 0 && value_ != null)
        {
                submitting=1;
                var obj = document.getElementById(formId); obj.submitted_by.value=value_; anyfieldChanged = 1; obj.submit();
        }
}

function saveDefaults(formId)
{
	if (submitting == 0)
	{
		submitting=1; 
		var obj = document.getElementById(formId); obj.submitted_by.value="Save_Defaults"; obj.submit();
	}
}

function displayChange(id)
{ 
	var object = document.getElementById(id); 
	if (object)
	{
		if (anyfieldChanged == 0) { setOpacity(object, 40); }
		else { setOpacity(object, 100); }
	}
	// else devsolAlert('age error, no object found!');
}

function fieldChanged(obj) {
    if (anyfieldChanged == 0) { 
        anyfieldChanged = 1; 
        displayChange('devsol_formbar_save'); 
        if (window.saveButtons !== undefined) {
           for (var index = 0; index < saveButtons.length; index++ )
           {
              enableRowView(saveButtons[index]);
           }
        }
    } };

function idleTimeout(remaining)
{
   idleTimerId = -1;
   if (remaining > 60)
        idleTimerId = setTimeout("idleTimeout(" + 60 + ")", (remaining - 60) * 1000);
   if (anyfieldChanged != 0) {
      alert("Your session will timeout out in " + remaining/60 + " minute(s, unless you interact with the server (e.g. save data, change pages, ...)");
   }
}

function setPageTimer(seconds, remaining) {
   idleTimerId = setTimeout("idleTimeout(" + remaining + ")", seconds * 1000);
}
function clearPage() {
        if (idleTimerId >= 0)
        {
           clearTimeout(idleTimerId);
           idleTimerId = -1;
        }
        return;
}
function unloadPage() {
        // if (/MSIE 6/i.test(navigator.userAgent)) { return; }
	if ((anyfieldChanged != 0) && (submitting == 0)) {
		return "You have changed values that have not been saved!\nTo save your changes, click the save button (diskette icon), after clicking cancel below.\nYour changes will be lost if you navigate to a different page by pressing OK."; } 
	return; 
} 
function changeTarget(obj) { var temp = obj.value; if (temp != "" && temp != null) window.location=temp; return true; }

var extendedKeyDown=0;
function devsolAlert(alertText)
{
   alert(alertText);
   extendedKeyDown=0;
}

var anyfieldChanged=0; var submitting=0;
window.onbeforeunload=unloadPage;
var idleTimerId = -1;
window.onunload=clearPage;

/*------------------- Scripts for form/document submission ------------------------*/

/*------------------- popup management ------------------------*/

var EFSHelpWindowObjectReference;
function OpenHelpPopup(strUrl)
{
  if (EFSHelpWindowObjectReference == null || EFSHelpWindowObjectReference.closed)
  {
     EFSHelpWindowObjectReference = window.open(strUrl,'EFSHelpWin','width=' + f_clientWidth() + ',height=' + f_clientHeight() + ',resizable=yes,toolbar=yes'); 
     EFSHelpWindowObjectReference.focus(); 
  }
  else if(EFSHelpWindowObjectReference.focus) { EFSHelpWindowObjectReference.focus(); };
};

/*------------------- popup management ------------------------*/

/*------------------- Scripts for table view management ------------------------*/

function enableRowView(id) { var row=document.getElementById(id); if (row) { try { row.style.display='table-row';} catch(e) { row.style.display = 'block'; }}}
function disableRowView(id) { var row=document.getElementById(id); if (row) { row.style.display = 'none'; }};
function enableColumnView(id) { var col=document.getElementById(id); if (col) { try { col.style.display='table';} catch(e) { col.style.display = 't'; } }}
function disableColumnView(id) { var col=document.getElementById(id); if (col) { col.style.display = 'none'; }}; 
function changeClass(id, newClass) { var obj=document.getElementById(id); if (obj) { obj.className = newClass; }}
function tableCheck(checked, count) { if (count > 0) { for(var i = 0; i < count; i++) { var row=document.getElementById('checkColumn_' + i); if (row) { row.checked = checked; } } } }
function anyChecked(count) { var checked = 0; if (count > 0) { for(var i = 0; i < count; i++) { var row=document.getElementById('checkColumn_' + i); if (row) { if (row.checked) checked++; } } } return checked; }
function groupForward(count, target, force) { var tempTarget = target;  var forward = 0; 
                                       for(var i = 0; i < count; i++) { var row=document.getElementById('checkColumn_' + i); 
                                                                        if (row) { if (row.checked) {  var item=document.getElementById('checkItem_' + i); 
                                                                                                       if (item) { tempTarget += ("&c=" + item.value ); forward=1; } } } }
                                       if (forward != 0 || force) { window.location= tempTarget; return true; } else devsolAlert("No Items selected"); }

/*------------------- Scripts for table view management ------------------------*/


/*------------------- Scripts for field management ------------------------*/

function changeForm(target) { window.location= currentPage + "&form=" + target; return true; }

function getMaxChars(name) { if (window.formNames !== undefined) {
        var tempid = formNames.indexOf(name); var tempLength = 0;
        if (tempid >= 0) tempLength = fieldMaxChars[tempid];
        return tempLength; } return 0; }

function getMaxWords(name) { if (window.formNames !== undefined) {
        var tempid = formNames.indexOf(name); var tempLength = 0;
        if (tempid >= 0) tempLength = fieldMaxWords[tempid];
        return tempLength; } return 0; }

function getParent(child) { if (window.formNames !== undefined) {
	var tempid = formNames.indexOf(child); var tempParent = null;
	if (tempid >= 0) tempParent = formParent[tempid];
        if (tempParent != null && tempParent != "") { var parent = document.getElementById(tempParent); 
        return parent; }} return null; }

function changeCondition(object) { if (window.conditionFields !== undefined) {
     var fieldId = object.id; var x = fieldId.indexOf('_');  fieldId = fieldId.substring(x + 1);
     x = fieldId.indexOf('_');  fieldId = fieldId.substring(0, x);
     for(var i=0; i< conditionIds.length; i++){ 
     if(conditionFields[i] == -1) { 
        var match = -1;
        if(conditionIds[i]== object.id) { var condValue = conditionalValue[i];
           if (condValue == null) {
              if (object.value == "") match = 0;
              else if (object.value == "No") match = 0;
              else if (object.value == -1) match = 0;
              else match = 1;
            } if (object.type == 'select-multiple') {
                 match = 0;
                 var count = object.options.length;
                 for (var x = 0; x < count; x++) {
                    if (object.options[x].selected) {
                       if (condValue == object.options[x].value) {
                          enableRowView('conditional' + i);
                          match = 1; break; } } }
            } else if (object.type == 'radio') {
                  if (condValue == getRadioValue(object)) match = 1; else match = 0;
            } else if (condValue == object.value) { match = 1; 
            } else match = 0;
         } 
         if (match == 0) disableRowView('conditional' + i); 
         else if (match == 1) enableRowView('conditional' + i); 
       } else if (fieldId == conditionFields[i]) { 
           var match = 0;
           var condValue = conditionalValue[i];
           if (condValue == null) {
              if ((object.value != "") && (object.value != "No") && (object.value != -1))
                 match = 1;
            } else {
              if (object.type == 'select-multiple') {
                 var count = object.options.length; 
                 for (var x = 0; x < count; x++) {
                    if (object.options[x].selected) {
                       if (condValue == object.options[x].value) {
                          enableRowView('conditional' + i); 
                          match = 1; break; } } }
               } else if (object.type == 'radio') {
                  if (condValue == getRadioValue(object)) { match = 1; } 
               } else if (condValue == object.value) { match = 1; } }
           if (match != 1) {
             for(var y=0; y< formNames.length; y++){ 
             var otherId = formNames[y]; var x = otherId.indexOf('_');  otherId = otherId.substring(x + 1);
             x = otherId.indexOf('_');  otherId = otherId.substring(0, x);
             if (fieldId == otherId) { var otherObject=document.getElementById(formNames[y]); 
                if (otherObject) if (condValue == null) {
                   if ((otherObject.value != "") && (otherObject.value != "No") && (otherObject.value == -1)) match = 1;
                } else {
                  if (otherObject.type == 'select-multiple') { var count = otherObject.options.length;
                     for (var x = 0; x < count; x++) {
                        if (otherObject.options[x].selected) {
                           if (condValue == otherObject.options[x].value) {
                              enableRowView('conditional' + i);
                              match = 1; break; } } }
                  } else if (otherObject.type == 'radio') {
                      if (condValue == getRadioValue(otherObject)) { match = 1; }
                  } else if (condValue == otherObject.value) { match = 1; } } }
           } }
         if (match == 0) disableRowView('conditional' + i); 
         else enableRowView('conditional' + i); 
       } 
       }}}

function getRadioValue(radioObj) {
	if(!radioObj) return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined) if(radioObj.checked) return radioObj.value; else return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function clearInputValue(id) { var input=document.getElementById(id); if (input) { input.value = ""; } }
function clearSelectValue(id) { var select=document.getElementById(id); if (select) { select.value = -1; }}
function checkReport(object, target) { var targetIn=document.getElementById(target); if (targetIn) { if (object.checked) targetIn.value = "Yes"; 
       else targetIn.value = "No"; changeCondition(targetIn); fieldChanged(targetIn); } }

function selectValidate(type, object) { var status=false; var parent = getParent(object.id);
	if (parent != null) { if ((parent.value == "") || (parent.value == "-1"))
	   { tempid = formNames.indexOf(parent.id);  devsolAlert(fieldNames[tempid] + " must not be blank"); return false; }}
	if (type == "none") { status = true; } else if (type == "required") { var currentValue = object.value;
	if (currentValue == null || currentValue == "") { devsolAlert("At least one selection required!"); object.value = object.options[0].value; } else status=true; }
    if (status == true) { changeCondition(object); fieldChanged(object); } return status; 
}

function enableField(id) { var obj=document.getElementById(id); if (obj) { obj.disabled = false; }}
function disableField(id) { var obj=document.getElementById(id); if (obj) { obj.disabled = true; }}


if(!Array.indexOf) { Array.prototype.indexOf = function(obj){ for(var i=0; i < this.length; i++){ if(this[i]==obj){ return i;  } } return -1; } }

function fieldKeyUp(type, object, e)  
{
	var keycode;
	if (window.event) keycode = window.event.keyCode; else if (e) keycode = e.which;  else return true; 
	if ((keycode == 16) || (keycode == 17) || (keycode == 18) || (keycode == 20)) { extendedKeyDown = false; }
        return true;
}

function fieldValidate(type, object, e)  
{
  // called by onKeyDown  (onKeyPress does not detect backspace/delete)
  //   onKeyDown has issues with key being held down in FF, as not called for every auto-repeat
  //
	var status=false; var keycode;
	if (window.event) keycode = window.event.keyCode; else if (e) keycode = e.which;  else return true; 
        //
      //var keycode2 = "";
      //if (window.event) keycode2 = window.event.keyCode;
      //var keycode3 = e.which;
      //var charcode3= e.charCode;
      //devsolAlert ("key pressed: " + keycode + " 2: " + keycode2 + " 3: " + keycode3  + " c: " + charcode3);
        // control keys 
        if ((keycode == null) || (keycode == 0)) return true;
        else if ((keycode == 9) || (keycode == 13)) return true;   // tab & return
        else if ((keycode == 8) || (keycode == 46)) 
        {  // backspace & delete
	   if (type == "email") { if (emailAddressToValidate.indexOf(object.id) < 0) 
                                  { var newIndex = emailAddressToValidate.length; emailAddressToValidate[newIndex] = object.id; } }
           fieldChanged(object); return true; 
        }
	
	// extended keys (shift, cntrl, alt, caplocks)
	else if ((keycode == 16) || (keycode == 17) || (keycode == 18) || (keycode == 20)) { extendedKeyDown = true; return true; }
	else if ((keycode == 27)) return false;

        var parent = getParent(object.id);
	if (parent != null) { if ((parent.value == null) || (parent.value == "") || (parent.value == "-1"))
	   { tempid = formNames.indexOf(parent.id);  devsolAlert(fieldNames[tempid] + " must not be blank"); return false; }}

	var key = String.fromCharCode(keycode);
        if (keycode >= 96 && keycode <= 105) { key = '0' + keycode - 96; }
        if (keycode == 190 || keycode == 110) { key = '.'; }
	var currentValue = object.value;
	if (type == "int") { if (!extendedKeyDown && (("0123456789").indexOf(key) > -1))
	  { status = true; } else { devsolAlert("Only numeric characters allowed!" + key); } }
	else if (type == "float") { if (!extendedKeyDown && (("0123456789.").indexOf(key) > -1)) {
	     { status=true; } } else { devsolAlert("Float format is ###.###!"); } } 
	else if (type == "phone") {
	  if (!extendedKeyDown && (key == '-')) {
	  if ((currentValue.length == 3) || (currentValue.length == 7)) { object.value = currentValue + key; }
	  else { devsolAlert("Only numeric characters allowed!"); } }
	  else if (!extendedKeyDown && (("0123456789").indexOf(key) > -1)) {
	  if (currentValue.length < 2) { object.value = currentValue + key; }
	  else if (currentValue.length == 2) { object.value = currentValue + key + '-'; }
	  else if (currentValue.length < 6) { object.value = currentValue + key; }
	  else if (currentValue.length == 6) { object.value = currentValue + key + '-'; }
	  else if (currentValue.length <= 11) { object.value = currentValue + key; } }
	  else { devsolAlert("Phone Numbers format is as follows: ###-###-####"); } }
	else if (type == "ssn") {
	  if (!extendedKeyDown && (key == '-')) {
	  if ((currentValue.length == 3) || (currentValue.length == 6)) { object.value = currentValue + key; }
	  else { devsolAlert("Only numeric characters allowed!"); }  }
	  else if (!extendedKeyDown && (("0123456789").indexOf(key) > -1)) {
	  if (currentValue.length < 2) { object.value = currentValue + key; }
	  else if (currentValue.length == 2) { object.value = currentValue + key + '-'; }
	  else if (currentValue.length < 5) { object.value = currentValue + key; }
	  else if (currentValue.length == 5) { object.value = currentValue + key + '-'; }
	  else if (currentValue.length <= 10) { object.value = currentValue + key; } }
	  else { devsolAlert("Social Security Number format is as follows: ###-##-####"); } }
	else if (type == "date") {
	  var firstDash  = currentValue.indexOf("/");  var secondDash  = currentValue.indexOf("/", firstDash + 1);
	  if (!extendedKeyDown && (key == '/')) {   if (firstDash == -1) { if (currentValue.length == 1) {
	  var newValue = '0' + currentValue; object.value = newValue+ key; }
	  else if (currentValue.length == 2) { object.value = currentValue + key; } }
	  else if (secondDash == -1) { if (currentValue.length == 4) {
	  var newValue = currentValue.substring(0,3) + '0' + currentValue.substring(3); object.value = newValue + key; }
	  else if (currentValue.length == 5) { object.value = currentValue + key; } }
	  else { devsolAlert("Date format is as follows: MM/DD/YYYY"); } }
	  else if (!extendedKeyDown && (("0123456789").indexOf(key) > -1)) {
	  if (currentValue.length == 0) {  object.value = currentValue + key; }
	  else if (currentValue.length == 1) { var newValue = currentValue.substring(0,2) + key;
	  if (newValue >= 1 && newValue <= 12) object.value = currentValue + key + '/';
	  else devsolAlert("Date format is as follows: MM/DD/YYYY"); }
	  else if (currentValue.length == 3) {  object.value = currentValue + key; }
	  else if (currentValue.length == 4) { var newValue = currentValue.substring(firstDash + 1,5) + key;
	  if (newValue >= 1 && newValue <= 31) object.value = currentValue + key + '/'; else devsolAlert("Date format is as follows: MM/DD/YYYY"); }
	  else if (currentValue.length == 6) { if (secondDash != -1 && (key == '1' || key == '2')) { object.value = currentValue + key; }
	  else devsolAlert("Date format is as follows: MM/DD/YYYY"); }
	  else if (currentValue.length == 7) { var newValue = currentValue.substring(secondDash + 1) + key;
	  if (newValue >= 19 && newValue <= 20) object.value = currentValue + key;
	  else devsolAlert("Date format is as follows: MM/DD/YYYY"); }
	  else if (currentValue.length == 8) { var newValue = currentValue.substring(secondDash + 1) + key;
	  if (newValue >= 196 && newValue <= 201) object.value = currentValue + key;
	  else devsolAlert("Date format is as follows: MM/DD/YYYY"); }
	  else if (currentValue.length == 9) { var newValue = currentValue.substring(secondDash + 1) + key;
	  if (newValue >= 1960 && newValue <= 2020) object.value = currentValue + key;
	  else devsolAlert("Date format is as follows: MM/DD/YYYY"); }
	  } else { devsolAlert("Date format is as follows: MM/DD/YYYY"); } }
	else if (type == "alpha") { var tempkey = key.toLowerCase(); if ((("abcdefghijklmnopqrstuvwxyz").indexOf(tempkey) > -1))
	 { status=true; } else { devsolAlert("Only alpha characters allowed!"); } }
	else if (type == "other") { if (parent != null) { if (parent.value == "Other")
	 { status=true; } else { devsolAlert("Other must be selected before entering data"); }}}
	else if (type == "email") { status=true; if (emailAddressToValidate.indexOf(object.id) < 0) { var newIndex = emailAddressToValidate.length; emailAddressToValidate[newIndex] = object.id; } }
	else if (type == "none") { status=true; }

        if (status == true) { var maxChars = getMaxChars(object.id);
           if (maxChars > 0) { if (currentValue.length >= maxChars) { status = false; devsolAlert("Character limit of " + maxChars + " exceeded"); } } }

        if (status == true) { var maxWords = getMaxWords(object.id); 
           if (maxWords > 0) { if (currentValue.length >= maxWords/2) { var words = 0; var tempVal = currentValue.replace("/\s/g",' '); tempVal=tempVal.split(' ');
                               for (var z=0; z < tempVal.length; z++) { if (tempVal[z].length > 0) words++;} if (words > maxWords) { status = false; devsolAlert("Word limit of " + maxWords + " exceeded"); } } } }

	if ((status == true) || (object.value != currentValue)) { fieldChanged(object); }
	return status; 
}

var emailAddressToValidate = new Array();

function emailCheck(object_id)
{
        var object = document.getElementById(object_id);
        if (object == null)
	{
		alert("Failed to find object: " + object_id);
		return false;
	}
        var currentValue = object.value;
	var at="@"
	var dot="."
	var lat=currentValue.indexOf(at)
	var lstr=currentValue.length
	if (lstr == 0)  return true;  // blank OK
	if (lat == -1 || lat == 0 || lat == lstr) 
	{
	   alert("Invalid Email Address: " + currentValue)
	   return false
	}
	if (currentValue.indexOf(dot) == -1 || currentValue.indexOf(dot)==0 || currentValue.indexOf(dot)==lstr)
	{
	   alert("Invalid Email Address: " + currentValue)
	   return false
	}
	if (currentValue.indexOf(at,(lat+1))!=-1)
	{
	   alert("Invalid Email Address: " + currentValue)
	   return false
	}
	if (currentValue.substring(lat-1,lat)==dot || currentValue.substring(lat+1,lat+2)==dot)
	{
	   alert("Invalid Email Address: " + currentValue)
	   return false
	}
	if (currentValue.indexOf(dot,(lat+2))==-1)
	{
	   alert("Invalid Email Address: " + currentValue)
	   return false
	}
	if (currentValue.indexOf(" ")!=-1)
	{
	   alert("Invalid Email Address: " + currentValue)
	   return false
	}
	if (currentValue.substring(lstr-1,lstr)==dot)
	{
	   alert("Invalid Email Address: " + currentValue)
	   return false
	}
	return true					
}

function validateForm()
{
   var status = true;
   for (var index = 0; (status == true) && (index < emailAddressToValidate.length); index++ )
   {
      status = emailCheck(emailAddressToValidate[index]);
   }
   return status;
}
/*------------------- Scripts for field management ------------------------*/

/*------------------- Scripts for filter criteria ------------------------*/

function formEditItemTypeChange2(object) 
{
   fieldSelectEnable = false; filterSelectEnable = false; 
   formSelectEnable = false; editControlEnable = false;
   countControlEnable = false; conditionalControlEnable = false;
   fieldStyleEnable = false; elementStyleEnable = false;
   flyOverEnable = false;

   if (object.value == "field") {
      fieldSelectEnable = true;
      editControlEnable = true;
      flyOverEnable = true;
      fieldStyleEnable = true;
      elementStyleEnable = true;
   } else if (object.value == "conditional field") {
      fieldSelectEnable = true;
      editControlEnable = true;
      conditionalControlEnable = true;
      flyOverEnable = true;
      fieldStyleEnable = true;
      elementStyleEnable = true;
   } else if (object.value == "value") {
      fieldSelectEnable = true;
      editControlEnable = false;
      flyOverEnable = true;
      elementStyleEnable = true;
   } else if (object.value == "filter score") {
      filterSelectEnable = true;
      editControlEnable = false;
      flyOverEnable = true;
      elementStyleEnable = true;
   } else if (object.value == "contributor") {
      formSelectEnable = true;
      editControlEnable = true;
      flyOverEnable = true;
      elementStyleEnable = true;
      conditionalControlEnable = true;
   } else if (object.value == "repeat end") {
      countControlEnable = true;
   } else if (object.value == "end columns") {
      countControlEnable = true;
   } else if (object.value == "title only") {
      flyOverEnable = true;
      fieldStyleEnable = true;
      elementStyleEnable = true;
   } else if (object.value == "multi-access field") {
      fieldSelectEnable = true;
      editControlEnable = true;
      flyOverEnable = true;
      fieldStyleEnable = true;
      elementStyleEnable = true;
   } else if (object.value == "save button") {
      flyOverEnable = true;
      fieldStyleEnable = true;
      elementStyleEnable = true;
   } else if (object.value == "document action") {
      editControlEnable = true;
      conditionalControlEnable = true;
      flyOverEnable = true;
      fieldStyleEnable = true;
      elementStyleEnable = true;
   } 

   formEditDisplayUpdate2();
   return selectValidate("none", object);
}

function formEditDisplayUpdate2() {
   if (filterSelectEnable == true) {
      enableRowView('filterSelectRow'); 
   } else {
      disableRowView('filterSelectRow');
   }
   if (fieldSelectEnable == true) {
      enableRowView('fieldSelectRow'); 
      if (currentFieldOptions.length > 0) { enableRowView('defaultSelectRow'); disableRowView('defaultTextRow'); }
      else { enableRowView('defaultTextRow'); disableRowView('defaultSelectRow'); };
   } else {
      disableRowView('fieldSelectRow'); disableRowView('defaultTextRow'); disableRowView('defaultSelectRow'); 
   }
   if (formSelectEnable == true) {
      enableRowView('formSelectRow'); 
   } else {
      disableRowView('formSelectRow');
   }
   if (editControlEnable) {
      enableRowView('editControlRow'); 
   } else {
      disableRowView('editControlRow');
   }
   if (countControlEnable) {
      enableRowView('countControlRow'); 
   } else {
      disableRowView('countControlRow');
   }
   if (conditionalControlEnable) {
      enableRowView('conditionalControlRow1'); 
      enableRowView('conditionalControlRow2'); 
   } else {
      disableRowView('conditionalControlRow1');
      disableRowView('conditionalControlRow2');
   }
   if (flyOverEnable) {
      enableRowView('flyOverRow'); 
   } else {
      disableRowView('flyOverRow');
   }
   if (fieldStyleEnable) {
      enableRowView('fieldStyleRow'); 
   } else {
      disableRowView('fieldStyleRow');
   }
   if (elementStyleEnable) {
      enableRowView('elementStyleRow'); 
   } else {
      disableRowView('elementStyleRow');
   }
}

function updateFormField2(object) { updateOptions(object.value);
 if (currentFieldOptions.length >= '1') {
    var tempOptions = document.getElementById("defaultSelectValue");
    while (tempOptions.options.length) { tempOptions.remove(0); }
    tempOptions.options[0] = new Option("Please make selection", "");
    tempOptions.value = -1; 
    for (var index = 0; index < currentFieldOptions.length; index++) {
       tempOptions.options[index + 1] = new Option(currentFieldOptions[index], currentFieldOptions[index]);
    } } formEditDisplayUpdate2(); return selectValidate("none", object); 
}

function formEditItemTypeChange(object) 
{
   if (object.value == "filter score") {
      filterSelectEnable = true;
   } else {
      filterSelectEnable = false;
   }
   formEditDisplayUpdate();

   return selectValidate("none", object);
}

function formEditDisplayUpdate() 
{
   if (filterSelectEnable == true) {
      disableRowView('fieldSelectRow'); disableRowView('defaultTextRow'); disableRowView('defaultSelectRow'); 
      enableRowView('filterSelectRow'); 
   } else {
      disableRowView('filterSelectRow'); enableRowView('fieldSelectRow'); 
      if (currentFieldOptions.length > 0) { enableRowView('defaultSelectRow'); disableRowView('defaultTextRow'); }
      else { enableRowView('defaultTextRow'); disableRowView('defaultSelectRow'); };
   }
}

function updateFormField(object) { updateOptions(object.value);
 if (currentFieldOptions.length >= '1') {
    var tempOptions = document.getElementById("defaultSelectValue");
    while (tempOptions.options.length) { tempOptions.remove(0); }
    tempOptions.options[0] = new Option("Please make selection", "");
    tempOptions.value = -1; 
    for (var index = 0; index < currentFieldOptions.length; index++) {
       tempOptions.options[index + 1] = new Option(currentFieldOptions[index], currentFieldOptions[index]);
    } } formEditDisplayUpdate(); return selectValidate("none", object); }


function updateOptions(value) { 
   if (value == 'Filter') filterSelectEnable = true; 
   else filterSelectEnable = false; 
   currentFieldOptions = new Array(); 
   var fieldIndex = fieldNames.indexOf(value);
   if (fieldTypes[fieldIndex] == '1') { optionIndex = 0;  
     for (index = 0; index < fieldOptions.length; index++) { 
        if (fieldOptionsId[index] == fieldIndex) {  currentFieldOptions[optionIndex] = fieldOptions[index];  optionIndex++;  }
     }
   }
 }

function updateFieldOptions(value) { updateOptions(value);
 if (currentFieldOptions.length >= '1') { 
    var tempOptions1 = document.getElementById("CriteriaSelect1"); 
    var tempOptions2 = document.getElementById("CriteriaSelect2"); 
    while (tempOptions1.options.length) { tempOptions1.remove(0); } 
    while (tempOptions2.options.length) { tempOptions2.remove(0); } 
    tempOptions1.options[0] = new Option("Please make selection", "");  
    tempOptions2.options[0] = new Option("Please make selection", ""); 
    tempOptions1.value = -1; tempOptions2.value = -1; 
    for (var index = 0; index < currentFieldOptions.length; index++) { 
       tempOptions1.options[index + 1] = new Option(currentFieldOptions[index], currentFieldOptions[index]);  
       tempOptions2.options[index + 1] = new Option(currentFieldOptions[index], currentFieldOptions[index]); 
    } } }

function fieldUpdated(value)
{ 
    updateFieldOptions(value); displayUpdate();
}

function displayUpdate(unused)
{ 
    criteriaDisplayUpdate();
    fieldChanged(null);
}

function criteriaDisplayRefresh()
{
    //var field=document.getElementById('CriteriaField');
    //updateFieldOptions(field.value);
    criteriaDisplayUpdate();
}

function criteriaDisplayUpdate()
{
    var type=document.getElementById('CriteriaType');
    var temp = type.value; var display = 1; var scaled = 0;
    if (temp == 'scaled') { display=2; scaled = 1; }
    var crit=document.getElementById('CriteriaCriteria'); temp = crit.value;
    var field=document.getElementById('CriteriaField');
    if (field.value == "") { display = 3; }

    if (display >= 2) { disableRowView('criteriaRow'); }
    else { enableRowView('criteriaRow'); }

    if (display == 1) { if (temp == 'NOT NULL') display=0; else if (temp == 'BETWEEN') display=2; }
    if (display >= 1) {
       if (scaled == 0 && currentFieldOptions.length >= '1') {
          disableRowView('criteriaTextRow1'); clearInputValue('CriteriaText1'); enableRowView('criteriaSelectRow1');
       } else {
          enableRowView('criteriaTextRow1'); disableRowView('criteriaSelectRow1'); clearSelectValue('CriteriaSelect1');
       }
    } else {
       disableRowView('criteriaTextRow1'); clearInputValue('CriteriaText1'); disableRowView('criteriaSelectRow1'); clearSelectValue('CriteriaSelect1');
    }
    if (display == 2) {
       if (scaled == 0 && currentFieldOptions.length >= '1') {
          disableRowView('criteriaTextRow2'); clearInputValue('CriteriaText2'); enableRowView('criteriaSelectRow2');
       } else {
          enableRowView('criteriaTextRow2'); disableRowView('criteriaSelectRow2'); clearSelectValue('CriteriaSelect2');
       }
    } else {
       disableRowView('criteriaTextRow2'); clearInputValue('CriteriaText2'); disableRowView('criteriaSelectRow2'); clearSelectValue('CriteriaSelect2');
    }
    if (filterSelectEnable == true) enableRowView('filterSelectRow'); else disableRowView('filterSelectRow');
}



/*------------------- Scripts for filter criteria ------------------------*/

/*------------------- Scripts for screen criteria ------------------------*/

function screenFieldUpdated(value) {
   var type=document.getElementById(value);
   var temp = type.value; var fieldId = -1;
   for (var index = 0; index < fieldNames.length; index++) {
      if (fieldNames[index] == temp) { fieldId = index; break; }}
   if (fieldId != -1) { display = fieldTypes[fieldId];
      if (display == 0) { changeClass(value + '_sc', 'invisible_column');
         changeClass(value + '_tc', 'visible_column');
      } else { changeClass(value + '_tc', 'invisible_column');
         updateScreenOptions(fieldId, value + '_s'); changeClass(value + '_sc', 'visible_column'); }
      changeClass(value + '_sb', 'visible_column'); }
   return true; 
}
	 
function updateScreenOptions(field, id) {
   var sel = document.getElementById(id);
   while (sel.options.length) { sel.remove(0); }
   sel.options[0] = new Option("Please make selection", "");
   sel.value = -1; optionIndex = 1;
   for (index = 0; index < fieldOptions.length; index++) {
      if (fieldOptionsId[index] == field) {
         sel.options[optionIndex++] = new Option(fieldOptions[index], fieldOptions[index]); }
   }
}

/*------------------- Scripts for screen criteria ------------------------*/

/*---------------- Scripts for email editing criteria ------------------------*/
function emailTriggerTypeChange(object)
{
   if ((object.value == "Manual")) {
      disableRowView('formSelectRow');
      disableRowView('formStateRow');
      enableRowView('toFirstRow');
      enableRowView('toLastRow');
      enableRowView('toEmailRow');
   } else if (object.value == "Contributor Notify") {
      enableRowView('formSelectRow2');
      disableRowView('formSelectRow');
      enableRowView('formStateRow');
      disableRowView('toFirstRow');
      disableRowView('toLastRow');
      disableRowView('toEmailRow');
   } else if (object.value == "Document Change") {
      enableRowView('formSelectRow');
      disableRowView('formSelectRow2');
      enableRowView('formStateRow');
      enableRowView('toFirstRow');
      enableRowView('toLastRow');
      enableRowView('toEmailRow');
   }

   return selectValidate("none", object);
}

/*--------------- Scripts for email editing criteria ------------------------*/

/*--------------- Scripts for getting window size from: ------------------------------*/
/*--- http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html-----*/
function f_clientWidth()
{ var myWidth = 770;
  if( typeof( window.innerWidth ) == 'number' ) { //Non-IE
    myWidth = window.innerWidth;
   } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
     //IE 6+ in 'standards compliant mode'
     myWidth = document.documentElement.clientWidth;
   } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible
     myWidth = document.body.clientWidth;
   }
   return myWidth;
}
function f_clientHeight()
{ var myHeight = 500;
  if( typeof( window.innerWidth ) == 'number' ) { //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}
/*--------------- Scripts for getting window size ------------------------*/

function setOpacity(obj, opacity) 
{
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}
