//********************************************************************************************
// utils.js
//  @author:kcowan@cytopia.cc
//  @version 1.0
//
//  &copy;2003 computer paradigm resolutions associates, inc.
//  
//  a set of utilities providing some java-styled objects for a web page.
//
//   --> <code> Request object </code>
//        loads in params from request.  obtainable via request.getParameter("myParam");
//
//   --> <code> StringBuffer </code>
//        allows for creations of a buffer for concatenating long strings, etc.
//         example usage:
//          buffer = new StringBuffer();
//          buffer.append("my string foo"+varBar);
//
//   --> <code> StringTokenizer </code>
//           similar to the Java Object. Takes an string and a delimeter for arguments, and returns an array of strings.
//
//           sample useage:
//               tokenizer = new StringTokenizer();
//               var str = "foo, bar, bee, bop";
//               var delimeter = ",";
//               my_tokens_array = tokenizer.tokenize(str, delimeter);
//
//    --> Array DOM extensions
//        adds 'pop' and 'push', and Iterator functionality to javascript Array object
//
//    --> <code> Iterator object </code>
//         similar to the Java Iterator object. 
//         used in lieu of 'for' statement to iterate through
//         an array using:
//  
//              itr = myArray.iterator();

//              while(itr.hasNext()){
//                   itr.next();
//              }
//     
//
//
//*********************************************************************************************
//*************************************************************************************
//  CODE SAMPLE
//*************************************************************************************
/*

    *Note: this method provides usage demonstrations for the Array, 
	StringBuffer, Request and Iterator DOM Extensions.


 function testDOMUtils(){

		testOne = new Array(); // create New array

		// add objects using the 'push(myObj)' method
		testOne.push("one");
		testOne.push("two");
		testOne.push("three");
		testOne.push("four");

		buf = new StringBuffer(); // instantiate new StringBuffer

		// gather up elements for output
		resEle = document.getElementById("results");
		reqEle = document.getElementById("requestLayer");
		paramEle = document.getElementById("paramLayer");
		
     try{

		itr = testOne.iterator(); // get Array Iterator instance
		buf.append("<UL>");
		while(itr.hasNext()){ // use the Iterator 'hasNext()' method.  returns false when complete

		   buf.append("<li>"+itr.next()+"</li>");// append to the buffer the next item in the array using iteraor 'next()' method
		}

	    buf.append("</ul>");

		   resEle.innerHTML = buf.toString();
		   buf.reset();

          itreq = request.getParameters().iterator(); // get parameters from Request object using Iterator object
		  buf.append("<ul> Request Parameters");

		  while(itreq.hasNext()){
		     var reqName = itreq.next().name;
			 var reqValue = itreq.next().value;

		     buf.append("<li>"+reqName+" is "+reqValue+"</li>");
			 }
			 buf.append("</ul>");
			 reqEle.innerHTML = buf.toString();

			 buf.reset();
			 buf.append("<ul>");
			 buf.append("GET PARAM FROM REQUEST TEST: <BR>");
			 buf.append("<li> param: "+request.getParameter('me')+" .</li>"); // get single param from Request object
			 buf.append("</ul>");

			 paramEle.innerHTML = buf.toString();

		   }catch(anErr){
				alert("an error occured: "+anErr.message);
		   }

		   
 }
*/
//*************************************************************************************
//  LICENSE AGREEMENT
//*************************************************************************************
/*
     These extensions are free software; you can redistribute it and/or modify it 
     under the terms of the GNU General Public License as published by the 
     Free Software Foundation; either version 2 of the License, or (at your 
     option) any later version, as long as this header remains in tact.

     This program is distributed in the hope that it will be useful, but WITHOUT 
     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
     FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
*/
//  
//*************************************************************************************


//****************************************************************************
//  TEMP PROTOTYPE OBJECT and Methods
//****************************************************************************

function Temp(){}

function _iniTemp(){

	this.popWinParams = "";
	this.displayManager = null;
	this.storageIsActive = false;
	this.currentEvent = null;
}


function setPopWinParams(heit, wide){

//height=375,width=610,scrollbars=yes,resizable=yes,location=yes

	try{
	if(wide){
		var width = wide;//Math.round(getWindowWidth()*wide);
	} else {
		var width = Math.round(getWindowWidth()*.8);
	}

	if(heit){
		var height = heit;//Math.round(getWindowHeight()*heit);
	}else {
		var height = Math.round(getWindowHeight()*.6);
	}

	tmp.popWinParams = "height="+height+",width="+width+",scrollbars=yes,resizable=yes";
	}catch(anErr){
	tmp.popWinParams = "height=375,width=610,scrollbars=yes,resizable=yes,location=yes";
	}

	


}

function setPopWinParamsDebug(heit, wide){

	if(!heit){
		heit = 500;
	}
	if(!wide){
		wide = 800;
	}

	var width = Math.round(wide);
	var height = Math.round(heit);

	 tmp.popWinParams = "height="+height+",width="+width+",scrollbars=yes,resizable=yes,location=yes,status=yes";

}


function getPopWinParams(){

	return tmp.popWinParams.toString();
}

function styleCursorHand(ele){

	document.body.style.cursor = "hand";

}

function styleCursorDefault(ele){

	document.body.style.cursor = "default";
}

function styleCursorWait(){
	document.body.style.cursor = "wait";
}

function setDisplayManager(dispMgr){
	tmp.displayManager = dispMgr;
	tmp.storageIsActive = true;
}

function getDisplayManager(){
	return tmp.displayManager;
}

function toggleButtonEnabled(ele){
   ele.disabled = false;
   /*
   ele.style.color = "#ffffff";
   ele.style.backgroundColor = "#006699";
   */
   ele.className = "button";
   return;
}


/*
.buttonoff {
background-color: #silver;
font: 10px tahoma, sans-serif;
cursor: hand;
color: gray;
border: outset 2px;
}
*/
function toggleButtonDisabled(ele){
	ele.disabled = true;
	ele.className = "buttonoff";
	return;
}

//****************************************************************************
// UUID OBJECT
//****************************************************************************

function UUID(){
  this.alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
}

function _genUUID(prefix){
    var id   = "";
	var id1  = "";
	var id2  = "";
	var txt1 = "";
	var txt2 = "";
	var txt3 = "";

	if(!prefix){
		prefix = "";
	}
	 id1 = prefix+Math.round(9999999999*Math.random());
	 id2 = prefix+Math.round(9999999999*Math.random());
	 txt1 =  this.getRandomLetters(4);
	 txt2 =  this.getRandomLetters(5);
	 txt3 =  this.getRandomLetters(4);
	 id = txt3 + id1 + txt2 + id2 + txt1;
	 id = this.scramble(id);
     id = prefix+id;

	//alert("new Id "+id);
	return id;
}

   function _getRandomLetters(strLen){
	 
	 tempStr = "";

	 for(grli=0; grli<strLen; grli++){
		randInt = Math.round(this.alphabet.length*Math.random());
        tempStr += this.alphabet.charAt(randInt);
	 }
	 return tempStr;
   }

   function _scramble(id){
	   tid = "";
      for(scri=0; scri<id.length; scri++){
		  int1 = Math.round(id.length*Math.random());
		  
          tid += id.charAt(int1);

	  }
	  return tid;
   }

   function _genUUIDOfLength(len){
      var uid = this.genIntUID();
      var newuid = uid.substring(0, new Number(len));
	  return newuid;
   }

   function _genIntUID(){
    var id   = 0;
	var id1  = 0;
	var id2  = 0;

	 id1 = Math.round(9999999999*Math.random());
	 id2 = Math.round(99999999999*Math.random());

	 id = new String(id1 + id2);
	 id = this.scramble(id);

	//alert("new [int] Id "+id);
	return id;
   }

UUID.prototype.getRandomLetters = _getRandomLetters;
UUID.prototype.genUUIDOfLength = _genUUIDOfLength;
UUID.prototype.genUUID = _genUUID;
UUID.prototype.genIntUID = _genIntUID;
UUID.prototype.scramble = _scramble;

uuidGenerator = new UUID(); // default 


//****************************************************************************
//  ITERATOR PROTOTYPE OBJECT
//****************************************************************************

function Iterator(){
	this.count = 0;
	this.max   = 0;
	this.firstRun = true;
}

function _iteratorHasNext(){

	if(!this.firstRun){
	    this.count++;
	} else {
		this.firstRun = false;
	}

	if(this.count < this.max){
		return true;
	}else {
		this.count = 0;
		this.firstRun = true;
		return false;
	}

}

function _getArrayItemFromIterator(){

	return this.array[this.count];
}

function _getIteratorIndex(){
	return this.count;
}

function _getIteratorSize(){
	return this.max;
}


//****************************************************************************
//  REQUEST PROTOTYPE OBJECT
//****************************************************************************

function Request(locale){

    this.url = unescape(locale);
	this.params = new Array();
}

function RequestParameter(name, value){
	this.name = name;
	this.value = value;

}

function _getParameters(){
	return this.params;
}

function _setParameter(name, value){

	parameter = new RequestParameter(name, value);
	this.params.push(parameter);
}

function _setParameters(){
	
	try{

	     url = this.url;
	     var index = Math.ceil(url.indexOf("?")+1);
		 var end = url.length;
		 params = url.substr(index, end);
		 paramsArray = params.split("&");

		if(index){
			//alert("request params "+paramsArray.length);
			iter = paramsArray.iterator();
			while(iter.hasNext()){
				
			 request_param = paramsArray[iter.index()].split("=");
			
			 parameter = new RequestParameter(request_param[0], unescape(request_param[1]));

			   if(parameter.name != "?"){
			        this.params.push(parameter);
			        //alert(parameter.name+" has a value of "+parameter.value);
			    }//fi
			
		    }//rof
		 }//fi

	}catch(anErr){
	
			alert("error parsing request: \n "+anErr.message);

			window.status = "Error: "+anErr.message;
	}

}

function _getParameter(name){
	try{
    iter = this.params.iterator();
		while(iter.hasNext()){
			reqParams = iter.next();

			if(reqParams.name == name){
				return reqParams.value;
	        }
	  }
	}catch(anErr){
		alert("error getting parameter: "+anErr.message);
	}
 return false;
}
function _setPage(){

	var pageIndex = this.url.lastIndexOf("//");
	var paramIndex = this.url.indexOf("?");
	this.page = this.url.substr(pageIndex, paramIndex);

}
function _getPage(){
	return this.page;
}

//****************************************************************************
//  STRING BUFFER PROTOTYPE OBJECT
//****************************************************************************

function StringBuffer(){
	this.string = new String();
} // string buffer object


function _appendToBuffer(string){

	this.string += new String(string);
}
function _bufferToString(){
	return this.string;
}

function _resetBuffer(){
	this.string = new String();
}


//****************************************************************************
//  STRING TOKENIZER PROTOTYPE OBJECT
//****************************************************************************

function StringTokenizer(){

	this.string = "";
	this.delimeter = ","; // set to comma by default
}

function _tokensToString(){
   return this.string;
}

function _tokenize(string, delimeter){
	//alert("tokenize: "+string);
     this.string = string;
	 this.delimeter = delimeter;

     tempString = new String();
	 token_array = new Array();

	 for(sta=0; sta<string.length; sta++){
          if(string.charAt(sta) == delimeter){
			  token_array.push(tempString);
			//  alert("push token: "+tempString);
			  tempString = new String();
		  } else {
			  tempString += string.charAt(sta);
		  }
			  

	 }
	 token_array.push(tempString);
    // alert("returning: "+token_array.length+" with tokens: "+token_array.toString());
	 return token_array;

}
StringTokenizer.prototype.tokenize = _tokenize;
StringTokenizer.prototype.asString = _tokensToString;



//****************************************************************************
// FILE INFO OBJECT AND MANAGER
//****************************************************************************

function FileInfoManager(){
  this.files = new Array();
}

function _findFile(fileId){
	//alert("total files: "+this.files.length);
   for(i=0; i<this.files.length; i++){
	  //alert("checking file: "+this.files[i].name+" compare id: "+this.files[i].id+" with target id: "+fileId);
     if(this.files[i].id == fileId){
		//alert("found a file: "+this.files[i].name);
		 return this.files[i];
	 }
   }
   return false;
}

function _addFile(fileInfo){
	this.files.push(fileInfo);
}

FileInfoManager.prototype.findFile = _findFile;
FileInfoManager.prototype.addFile  = _addFile;

function FileInfo(name, id, date, oldfile, size, storeInMaster, returnTarget, pageKey, type){
   this.name = name;
   this.id = id;
   this.date = date;
   this.oldfile = oldfile;
   this.size = size;
   this.storeInMaster = storeInMaster;
   this.returnTarget = returnTarget;
   this.pageKey = pageKey;
   this.type = type;
}


//****************************************************************************
//  CPR RESOURCE ENTRY OBJECT
//****************************************************************************

function CPRResourceEntry(id, label, type){
    this.id = id;
	this.label = label;
	this.type = type;
}


//****************************************************************************
//  CPR COMMON RESOURCE ENTRY OBJECT 
//  
//****************************************************************************

function CommonResource(id, label, type, uid, slid){
    this.id = id;
	this.label = label;
	this.type = type;
	this.uid = uid;
	this.slid = slid;
}

function _getCommonResourceDisplayStr(){
   return this.id+" | "+this.label;
}

CommonResource.prototype.getDisplayStr = _getCommonResourceDisplayStr;
//****************************************************************************
//  CPR RESOURCE MAPPING 
//  
//****************************************************************************

function ResourceMapping(){
   this.table = [""];
   this.resources = new Array();
   this.RESOURCE_SUBSCRIBER_TYPE           = 0;
   this.RESOURCE_SUBSCRIBER_GROUP_TYPE     = 1;
   this.RESOURCE_MEDIAAPP_TYPE             = 2;
   this.RESOURCE_LINE_TYPE                 = 3;
   this.RESOURCE_LINE_GROUP_TYPE           = 4;
   this.RESOURCE_GLOBAL_TYPE               = 5;
}

function _addResourceMapping(id, label, type, uid, slid){
	//uid = trimWhiteSpace(uid);
   this.table[new String(uid)] = new CommonResource(id, unescape(label), type, uid, slid);
   this.resources.push(new CommonResource(id, unescape(label), type, uid, slid));

}

function _findResource(uid){
	//uid = trimWhiteSpace(uid);
	if(uid == ""){
		alert("Empty uuid: "+uid);
		return false;
	}
   resc = this.table[new String(uid)];
   if(resc){
	   return resc;
   } else {
	  idArray = parseIDStringAsArray(uid);
	   //alert("looking for "+uid+" in resources...");
       //buf = new StringBuffer();
     for(rs=0; rs<this.resources.length; rs++){
		 //buf.append(" compare: "+this.resources[rs].uid+" to target: "+uid+" \n");
         if(this.resources[rs].uid == uid){
             return this.resources[rs];
		 }
		 // parse id string and check attributes
         if(idArray.length > 0 ){
           if(this.resources[rs].id == idArray[1] && this.resources[rs].slid == idArray[0]){
               return this.resources[rs];
		   }
		 }
	 }
   }

   return false;
}

function _findResourceSet(type){
	  typeSet = new Array();
      for(key in this.table ){
           if(this.table[key].type == type){
			   typeSet.push(this.table[key]);
		   }
	  }

	  return typeSet;
}

ResourceMapping.prototype.addResource  =    _addResourceMapping;
ResourceMapping.prototype.findResource =    _findResource;
ResourceMapping.prototype.findSet      =    _findResourceSet;


function parseIDStringAsArray(str){
        if(str.indexOf("|") > -1){
           str = str.substring(0, str.indexOf("|")-1);
        }
           if(str.indexOf(".") == -1){ 
              idtokens = new Array(str);
            } else {
             idtokenizer = new StringTokenizer();
             idtokens = idtokenizer.tokenize(str, ".");
             }
             return idtokens;
        }


//****************************************************************************
//  ARRAY DOM EXTENSIONS
//****************************************************************************

// ARRAY DOM EXTENTIONS
//  extends the Array object in the dom
//

// removes item from array. returns a fresh array
//
// useage:  myArray = myArray.pop(anObject);
//
//------------------------------------------------
function _pop(anObject){

	tempArray = new Array();
	itr = this.iterator();

	while(itr.hasNext()){
		if(itr.next() != anObject){
			tempArray.push(itr.next());
		}
	}

	return tempArray;
}
// adds an obeject to array
function _push(anObject){

	var count = this.length++;
	this[count] = anObject;

	return this;
}

function _getIteratorForArray(){

	iter = new Iterator();
	iter.max = this.length;
	iter.array = this;

	return iter;
}

//****************************************************************************
//  STRING DOM EXTENSIONS
//****************************************************************************

function _strToArray(str){
	if(str){
	strArr = new Array();

	for(st=0; st<str.length; st++){
      strArr[st] = str.charAt(i);
	}
	return strArr;
	} else {
		return new Array();
	}
}


//****************************************************************************
//  DATE DOM EXTENSIONS
//****************************************************************************

function date_getInstancesForDay(dayInt){ // returns an array of dates for this day in this month of the date obj
    tempArray = new Array();

   for(di=1; di<this.getDaysInMonth(); di++){
		tdate = new Date();
		tdate.setMonth(this.getMonth());
		tdate.setFullYear(this.getFullYear());
		tdate.setDate(di);

		if(tdate.getDay() == dayInt){
			tempArray.push(di);
		}
   }

   return tempArray;

}


function date_yearIsLeapYear(){
  if ((this.getFullYear() % 4) == 0) {
		if ((this.getFullYear() % 100) == 0 && (this.getFullYear() % 400) != 0){
			return false;
		}
		return true;
	} else {
		return false;
	}
}

function date_getDaysInMonth(){
	dayArray = new Array();
	nmonth = this.getMonth();
	nyear = this.getFullYear();

	if(this.isLeapYear()){
		dayArray = this.lDOMonth;
	} else {
		dayArray = this.DOMonth;
	}
	return dayArray[nmonth];
}

//****************************************************************************
//  DOCUMENT EXTENSIONS and CROSS-BROWSER DOM ACCESS UTILS
//****************************************************************************

function findFormElement(eleName){
    // This will find ANY element in the browser, but is generally focused on 
	// finding elements in the form with the 'name' attr, but not an 'id' attr
	// which causes the getElementById to fail in Mozilla based browsers.
	// For sanity and IE
	// make an initial effort to return the element via DOM call.
	__ele = document.getElementById(eleName);
	if(__ele){
		return __ele;
	}

    // if no element is found, go through the forms and look for a match
	for(f1=0; f1<document.forms.length; f1++){
		currForm = document.forms[f1];

        // go through each element and focus on the name or id
		for(fe=0; fe<currForm.elements.length; fe++){
			if(currForm.elements[fe].name == eleName || currForm.elements[fe].id == eleName){
				return currForm.elements[fe];
			}
		}
	}

	return false;
}

function setRadioButtonSelected(radioId, radioValue){
	for(f1=0; f1<document.forms.length; f1++){
		currForm = document.forms[f1];
		for(fe=0; fe<currForm.elements.length; fe++){
			if(currForm.elements[fe].name == radioId || currForm.elements[fe].id == radioId){
				var isDisabled = false;
				if(currForm.elements[fe].disabled){
					currForm.elements[fe].disabled = false;
					isDisabled = true;
				}
				if(currForm.elements[fe].value == radioValue){
                   currForm.elements[fe].checked = true;

				    if(isDisabled){
					  currForm.elements[fe].disabled = true;
				    }

				   //return true;
				}

				if(isDisabled){
					currForm.elements[fe].disabled = true;
				}
			}
		}
	}

	//return false;
}

function setRadioButtonGroupDisabledState(radioId, state){
	try{
     for(f1=0; f1<document.forms.length; f1++){
		currForm = document.forms[f1];
		for(fe=0; fe<currForm.elements.length; fe++){
			if(currForm.elements[fe].name == radioId || currForm.elements[fe].id == radioId){
				currForm.elements[fe].disabled = state;
			}
		}
	}
	}catch(anErr){ alert("Error: "+anErr.message); }


	return;
}

// returns an array of radio buttons base on id
function getRadioButtonGroup(radioId){
	radios = new Array();
     for(f1=0; f1<document.forms.length; f1++){
		currForm = document.forms[f1];
		for(fe=0; fe<currForm.elements.length; fe++){
			if(currForm.elements[fe].name == radioId || currForm.elements[fe].id == radioId){
				radios.push(currForm.elements[fe]);
			}
		}
	}
	return radios;
}


// returns a radio button element by value
function getRadioButtonElementByValue(radioId, val){
     for(f1a=0; f1a<document.forms.length; f1a++){
		currForm = document.forms[f1a];
		for(feq=0; feq<currForm.elements.length; feq++){
			if(currForm.elements[feq].name == radioId || currForm.elements[feq].id == radioId ){
				if(currForm.elements[feq].value == val){
				   return currForm.elements[feq];
				}
			}
		}
	}
	return false;
}

// returns the selected value of a radio group
function getRadioButtonGroupValue(radioId){
   //buf = new StringBuffer();
   //var oneVal = true;
   //var prePend = "";
    radios = getRadioButtonGroup(radioId);
	  for(grv=0; grv<radios.length; grv++){
		  radEle = radios[grv];
		if(radEle.checked){
			/*  		  
		   if(!oneVal){
			  prePend = "|";
		   }
		   buf.append(prePend+radEle.value);
		   oneVal = false;
		   */
		   return radEle.value;

		} // end fi

	  }// end for

   return "";
}

function addSelectValueSelected(elementId, value, label){
   newOpt = document.createElement("OPTION");
   newOpt.value = value;
   newOpt.text = label;
   newOpt.selected = true;
   
   targetEle = findFormElement(elementId);
   targetEle.appendChild(newOpt);
  //  setSelectMenuSelected(elementId, value);
	return;
}

function removeAllOptions(elementId){

   targetEle = findFormElement(elementId);
   for(i=0; i<targetEle.options.length; i++){
       targetEle.removeChild(targetEle.options[i]);
   }
}

function setNewSelectMenuValueAndLabel(selectId, index, newValue, newLabel){
	try{
	selEle = findFormElement(selectId);
	if(selEle){
		
      selEle.options[index].selected = true;
	  selEle.options[index].text = newLabel;
	  selEle.options[index].value = newValue;

	}
	}catch(anErr){
		alert("Unable to set select value for: "+selectId+" at index: "+index+" because: "+anErr.message);
	}
}

function setSelectMenuLabel(selectId, valueKey, newLabel){
	try{
	selEle = findFormElement(selectId);
	if(selEle){
     for(se=0; se<selEle.options.length; se++){
		 if(selEle.options[se].value == valueKey){
              selEle.options[se].selected = true;
	          selEle.options[se].text = newLabel;
		 }
	 }

	}
	}catch(anErr){
		alert("Unable to set select value for: "+selectId+" at index: "+index+" because: "+anErr.message);
	}
}


function setNewSelectMenuValue(selectId, index, newValue){
	try{
	selEle = findFormElement(selectId);
	if(selEle){
		
      selEle.options[index].selected = true;
	  selEle.options[index].value = newValue;

	}
	}catch(anErr){
		alert("Unable to set select value for: "+selectId+" at index: "+index+" because: "+anErr.message);
	}
}

function setNewSelectMenuLabel(selectId, index, newLabel){
	try{
	selEle = findFormElement(selectId);
	if(selEle){
		
      selEle.options[index].selected = true;
	  selEle.options[index].text = newLabel;

	}
	}catch(anErr){
		alert("Unable to set select value for: "+selectId+" at index: "+index+" because: "+anErr.message);
	}
}

// used for loading custom value/text into select menus
function CustomOption(text, value){
	this.text = text;
	this.value = value;
	return this;
}

// loads a select menu with options from the provided array
function loadSelectMenu(selectId, selectArray, selectedItem, usesCustomOption){
	try{
	selectEle = findFormElement(selectId);
    if(selectEle){
		
		selectEle.options.length = selectArray.length;
		
	for(si=0; si<selectArray.length; si++){

        // set label and value
		if(usesCustomOption){
          selectEle.options[si].text = selectArray[si].text;
		  selectEle.options[si].value = selectArray[si].value;
		} else {
          selectEle.options[si].text = selectArray[si];
		  selectEle.options[si].value = selectArray[si];
		}
        
		// set selected
		if(selectedItem == selectArray[si]){
          selectEle.options[si].selected = true;
		}
	}

	} else {
		alert(" Element: "+selectId+" not found!");
	}
	}catch(anErr){
		alert("Unable to load select menu: "+selectId+" because: "+anErr.message);
	}
}

function setElementValue(targetId, newValue, elementType){
	/*
		  element types:
		  0 = form element
	      1 = div element
		  
    */
	switch(elementType){
        
		case 0:
          ele = findFormElement(targetId);
		  ele.value = newValue;
		break;

		case 1:
           ele = document.getElementById(targetId);
		   ele.innerHTML = newValue;
	    break;

	}
}

// sychronizes to identical select menus
// returns 
// -1 if successful, 
//  0 if done with errors, 
//  1 if severe failure
//
function synchronizeSelectMenus(targetId, sourceEle, useSelected, useValue){
	var result = -1;
	try{
		if(!useSelected){
			useSelected = false;
		}
		if(!useValue){
			useValue = false;
		}
		// get the select menus
       targetEle = findFormElement(targetId);

	 if(targetEle && sourceEle){
       for(sm=0; sm<targetEle.options.length; sm++){
		   try{
			srcOption = sourceEle.options[sm];
			if(srcOption){
			  // update label
			  targetEle.options[sm].text  = srcOption.text;
              // update value
			  if(useValue){
                 targetEle.options[sm].value = srcOption.value;
			  }
			  // update selected
			  if(useSelected){
			    targetEle.options[sm].selected = srcOption.selected;
			  }

			}// end if srcOption

		   }catch(anErr0){
               alert("Unable to synchronize select menus "+anErr0.message);
		       result = 0;
		   }// end try/catch anErr0

	   }// end for

	 } else {
       //alert("Unable to synchronize select menus.  Both target and source elements must be valid.");
	   if(!targetEle){
           alert("Target Element: "+targetId+" not found!");
	   }
	   if(!sourceEle){
           alert("Source Element not found!");
	   }
	   result = 1;
     }// end if ele check

	}catch(anErr){
		alert("Unable to synchronize select menus "+anErr.message);
		result = 1;
	}// end try/catch anErr

	return result;
}

function setSelectMenuSelected(selectId, selectValue){
	try{
	selEle = findFormElement(selectId);
	if(selEle && selEle.options != null && selEle.options && selEle.options.length && selEle.options.length > 0){
	for(xe=0; xe<selEle.options.length; xe++){
		if(selEle.options[xe].value == selectValue){
          selEle.options[xe].selected = true;
		  if(selEle.selectedIndex){
		     selEle.selectedIndex = xe;
		  }
		  selEle.value = selectValue;
		}
	}

	}

	}catch(anErr){
		alert("Unable to set select value for: "+selectId+" because: "+anErr.message);
	}
}

function addOptionToSelectMenu(targetId, optText, optVal){
     targetEle = findFormElement(targetId);
	 var newindex = targetEle.options.length+1;
	 newopt = document.createElement("OPTION");
	 newopt.value = optVal;
	 newopt.text = optText;
	 targetEle.appendChild(newopt);
	 //targetEle.options[newindex].text = optText;
	 //targetele.options[newindex].value = optVal;
}

function setSelectMenuSelectedIndex(selectId, index){
	try{
      selEle = findFormElement(selectId);
      selEle.options[index].selected = true;
	}catch(anErr){}
}

function trimWhiteSpace(str){
	var newStr = new StringBuffer();
	for(tws=0; tws<str.length; tws++){
	 try{
      if(str.charAt(tws) != " "){
		newStr.append(str.charAt(tws));
	  }
	 }catch(anErr){
	    return str;
	 }
	}
	return newStr.toString();
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };


function toggleFormButton(eleId, state){
   var stateClass = "";
   _ELE = findFormElement(eleId);
    if(_ELE){
        if (state){
          stateClass="button";
		}else{
          stateClass="buttonOff";
		}

	  _ELE.className = stateClass;
      _ELE.disabled = (! state);
	} else {
       alert("ELE: "+eleId+" not found!");
	}
   return;
}

// EXPERIMENTAL.  
// SHOULD NOT BE DEPLOYED WIDELY. USE findFormElement instead.
function getDocumentElement(elemId){

      isNS = (document.all)?false:true;
	  var elem;

	  try{
		  if(isNS){
			  // first try the regular route
              elem = document.getElementById(elemId);
			  if(!elem){
				  // if we don't find an id attribute, check for match in name. this is for NS only.
				 // get DIV elements by tag name;
					  eleArray = document.getElementsByTagName("div");
					  for(elems=0; elems<eleArray.length; elems++){
						  if(eleArray[elems].name == elemId){
							  return eleArray[elems];
						  }
					  }// end for divArray loop

				  // get SPAN elements by tag name;
					  eleArray = document.getElementsByTagName("span");
					  for(elems=0; elems<eleArray.length; elems++){
						  if(eleArray[elems].name == elemId){
							  return eleArray[elems];
						  }
					  }// end for divArray loop

                 // look in forms array
				 for(frms=0; frms<document.forms.length; frms++){
					 if(document.forms[frms].name == elemId){
						 return document.forms[frms];
					 }
					 for(elems=0; elems<document.forms[frms].elements.length; elems++){
						if(document.forms[frms].elements[elems].name == elemId){
							return document.forms[frms].elements[elems];
						}
					 }	 
				 }
                  // look in images array
				  for(elems=0; elems<document.images.length; elems++){
						if(document.images[elems].name == elemId){
							return document.images[elems];
						}
				 }


			  }// end if elem
			  if(!elem){
				  return false;
			  }

		  } else {// for IE use

             elem = document.getElementById(elemId);
			 if(elem){ 
				 return elem;
			 } else {
				 return false;
			 }
		  }

	  }catch(dErr){
		  alert("unable to complete element retrival because: "+dErr.message);
		  return false;
	  }

	  return false;
}



//****************************************************************************
// FLASH UTILS
//****************************************************************************

function getFlashPlayer(id, fileName, flash_params, height, width){
	flashStr =  new StringBuffer();

	var port = "";

	if(location.port != ""){
		 port = ":"+location.port
	}

	var codebaseURL =  location.protocol+"://"+location.host+port+"/"+WEB_CONTEXT+"/common/swflash.cab#version=6,0,0,0";

     //alert(codebaseURL);
	flashStr.append("<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\""+codebaseURL+"\" WIDTH=\""+width+"\" HEIGHT=\""+height+"\" id=\""+id+"\" ALIGN=\"\">");
	flashStr.append(" <PARAM NAME=movie VALUE=\""+fileName+"\">");
	flashStr.append(" <PARAM NAME=quality VALUE=high>");
	flashStr.append(" <PARAM NAME=wmode VALUE=transparent>");
	//flashStr.append(" <PARAM NAME=bgcolor VALUE=#FFFFFF>");
	flashStr.append(" <PARAM NAME=FlashVars VALUE=\"" +flash_params+ "\">");
	flashStr.append(" <EMBED src=\""+fileName+"\" FlashVars=\"" +flash_params+ "\" quality=high wmode=transparent bgcolor=#FFFFFF  WIDTH=\""+width+"\" HEIGHT=\""+height+"\" NAME=\""+id+"\" swLiveConnect=true ALIGN=\"\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\"></EMBED>");
	flashStr.append("</OBJECT>");

	return flashStr;
}


//****************************************************************************
//  EMAIL VALIDATION
//****************************************************************************
function isValidEmail(str) {

	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filter.test(str)){
         return true;
	  } else{
         //alert("Please input a valid email address!")
         return false;
	  }
}


//****************************************************************************
//  STRING VALIDATION
//****************************************************************************

function checkValueRequired(elm){

		var elmValue = trim(elm.value);
		if( !elm || elmValue == "" || elm.value == null || elm.value.length == 0 ){
			return false;
		}else {
			return true;
			
		}

		return false;
}



//****************************************************************************
//  DEVELOPMENT METHODS
//**************************************************************************** 

function captureFormElement(){

     buffer = new StringBuffer();
      buffer.append("<html><head><title>result</title></head><body><form><textarea rows=35 cols=50 >");
     // if no element is found, go through the forms and look for a match
	for(f1=0; f1<document.forms.length; f1++){
		currForm = document.forms[f1];
         buffer.append("&gt;FORM  action= "+currForm.action);
        // go through each element and focus on the name or id
		for(fe=0; fe<currForm.elements.length; fe++){
			 ele = currForm.elements[fe];
			 buffer.append("&gt; &nbsp; &gt;INPUT  action= "+currForm.action);
		}
	}

    buffer.append("</textarea></form></body></html>");
	// now open a window with the result

	resultsWin = window.open("", "resultsWin", "height=375,width=610,scrollbars=yes,resizable=yes");
	resultsWin.document.open();
	resultsWin.document.writeln(buffer.toString());
	resultsWin.document.close();

    
}


// Evaluates a remote method call.
// Should be used for testing purposes only.
function fireRemoteCommand(evalStr){
   //alert("fire remote command");
   try{
   eval(evalStr+";");
   }catch(anErr){
	   alert("Unable to fire remote command: "+anErr.message);
   }
}

//****************************************************************************
//  OBJECT DOM EXTENSIONS
//****************************************************************************

// return a DOM element from an id 
// cross browser friendly
var isDOM = (document.getElementById ? true : false); 
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
var isIE  = (document.all)?true:false;

function getWindowHeight(){
	   if(isIE){
		 return document.body.offsetHeight;
	  } else {
         return window.innerHeight;
	  }
}

function getWindowWidth(){
	if(isIE){
		 return document.body.offsetWidth;
	  } else {
         return window.innerWidth;
	  }
}

function getRef(id)
{
 if (isDOM) return document.getElementById(id);
 if (isIE4) return document.all[id];
 if (isNS4) return document.layers[id];
}




/* extends()
// return void
// allows objects to inherit, similar to java's extend keyword

  USAGE 
function ClassA () { 
} 

function ClassB() { 
       this.extends(new ClassA()); 
}

Object.prototype.extends = function (oSuper) { 
       for (sProperty in oSuper) { 
               this[sProperty] = oSuper[sProperty]; 
       } 
}


// adds a get/set function for a property to an object
Object.prototype.addProperty = function (sName, vValue) { 
        
       this[sName] = vValue; 
        
       var sFuncName = sName.charAt(0).toUpperCase() + sName.substring(1, sName.length); 
        
       this["get" + sFuncName] = function () { return this[sName] }; 
       this["set" + sFuncName] = function (vNewValue) { 
                       this[sName] = vNewValue; 
       }; 
}


*/

// PROTOTYYPE DEFINITIONS
//---------------------------------------------------------------
Array.prototype.pop              = _pop;
Array.prototype.push             = _push;
Array.prototype.iterator         = _getIteratorForArray;

Date.prototype.getInstancesForDay = date_getInstancesForDay;
Date.prototype.getDaysInMonth     = date_getDaysInMonth;
Date.prototype.isLeapYear         = date_yearIsLeapYear;

String.prototype.toArray          = _strToArray;

  // Non-Leap year Month days..
  Date.prototype.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; 

  // Leap year Month days.. 
  Date.prototype.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];


StringBuffer.prototype.append    = _appendToBuffer;
StringBuffer.prototype.toString  = _bufferToString;
StringBuffer.prototype.reset     = _resetBuffer;

Iterator.prototype.hasNext       = _iteratorHasNext;
Iterator.prototype.next          = _getArrayItemFromIterator;
Iterator.prototype.index         = _getIteratorIndex;
Iterator.prototype.size          = _getIteratorSize;


Request.prototype.getParameters  = _getParameters;
Request.prototype.setParameters  = _setParameters;
Request.prototype.setParameter   = _setParameter;
Request.prototype.getParameter   = _getParameter;
Request.prototype.getPage		 = _getPage;


RequestParameter.prototype.name  = "";
RequestParameter.prototype.value = "";


Temp.prototype.ini               = _iniTemp;


// ini default object
//-----------------------------------------

tmp = new Temp();
tmp.ini();

request = new Request(escape(window.location));
request.setParameters();
