// guiframework.js

var fwSubmitFlag = false;
var fwSubmitCount = 0;

function setAction(action) { 
	document.forms[0].fwAction.value = action; 
}
 
function submitAction(action) { 
	setAction(action); 
	submitForm(); 
} 
function hrefAction(action, params) { 
	location.href= document.forms[0].fwUrl.value + "?fwAction=" + action + "&fwMenu=" + document.forms[0].fwMenu.value + "&" +params; 
} 

function hrefLink(link) { 
	var url = "";
	if (document.forms[0].fwServerUrl) {
		url = document.forms[0].fwServerUrl.value;
	}
	url +=  document.forms[0].fwUrl.value + "?fwLink=" + link + "&fwMenu=" + document.forms[0].fwMenu.value; 
	location.href=url;
} 
function shrefLink(link) { 
	var url = "";
	if (document.forms[0].fwSslServerUrl) {
		url = document.forms[0].fwSslServerUrl.value;
	}
	url +=  document.forms[0].fwUrl.value + "?fwLink=" + link + "&fwMenu=" + document.forms[0].fwMenu.value; 
	location.href=url;
} 
function hrefMenu(link) { 
	var url = "";
	if (document.forms[0].fwServerUrl) {
		url = document.forms[0].fwServerUrl.value;
	}
	url +=  document.forms[0].fwUrl.value + "?fwLink=" + link + "&fwMenu=" + link; 
	top.location.href=url;
} 
function shrefMenu(link) { 
	var url = "";
	if (document.forms[0].fwSslServerUrl) {
		url = document.forms[0].fwSslServerUrl.value;
	}
	url +=  document.forms[0].fwUrl.value + "?fwLink=" + link + "&fwMenu=" + link; 
	location.href=url;
} 

function submitForm() { 
	if (fwSubmitFlag) 	{
	   if (fwSubmitCount < 5) 	   {
		   alert("The previous operation has not been completed yet.");
		   fwSubmitCount++;
		   return;
	   } 
	}
	document.forms[0].submit(); 
	fwSubmitFlag = true; 
}	



function addItem(source, target) { 
    if (source.options.selectedIndex < 0) {
         alert("No items to add");
         return false;
    }
    
    var value = source.options[source.options.selectedIndex].value; 
	if ("dummy" != value) {
	    for (i=0; i < target.options.length; i++) { 
	         if (target.options[i].value == value) { 
	              alert(value + " already exists in the list!"); 
	              return false;
	         } 
	    } 
	}
    var newOption = new Option(value, value, true); 
    target.options[target.options.length]=newOption; 
    target.options.selectedIndex = target.options.length - 1; 
    return true; 
}

function addItem1(value, target) { 
	if ("dummy" != value) {
	    for (i=0; i < target.options.length; i++) { 
    	     if (target.options[i].value == value) { 
        	      alert(value + " already exists in the list!"); 
        	      return false;
    	     } 
   	 	}
   	} 
    var newOption = new Option(value, value, true); 
    target.options[target.options.length]=newOption; 
    target.options.selectedIndex = target.options.length - 1; 
    return true; 
}


function removeCurrent(select) { 
//alert("in removeCurrent");

    if (select.options.selectedIndex < 0) {
         alert("No items to remove");
         return false;
    }
   	select.options.remove(select.options.selectedIndex); 
   	return true;
}

function selectItems(select) {
	for (i=0; i < select.options.length; i++)  {
		    select.options[i].selected = true;
	}
	return true;
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

