		function swap(e1, e2)
            {
              ttext = e1.text;
              tvalue = e1.value;
              e1.text = e2.text;
              e1.value = e2.value;
              e2.text = ttext;
              e2.value = tvalue;
            }
		function deleteBlankRowIfNotEmpty(list)
		{
		   var idx = -1;
		   var val = "";
		// find a blank row in table
		   for (i = 0; i < list.length; i++){
				val = list.options[i].value;
				if (val == "") {
				   idx = i;
				   break;
				}
		   }
		   if (idx >= 0 && (list.length > 1))
			  list.options[idx] = null;
		}
		 function moveElementUp(list)
				 {    // go through the list and get all selected items
					  for ( i = 0; i <= list.length-1; i++)
					  { // if the item is selected then swap it
						if (list.options[i].selected)
						{   // check if it is not the first item
							if (i != 0)
							{
								swap(list.options[i], list.options[i - 1]);
								list.options[i - 1].selected = true;
								list.options[i].selected = false;
							}
						}
					  }
				  newOrder(list, eval("document." + list.form.name + "." + list.name.substr(0, list.name.lastIndexOf("select"))));
				 }
		 function moveElementDown(list)
				 {    // go through the list and get all selected items
					  for ( i = list.length-1; i >= 0; i--)
					  { // if the item is selected then swap it
						if (list.options[i].selected)
						{   // check if it is not the first item
							if (i != list.length-1)
							{
								swap(list.options[i], list.options[i + 1]);
								list.options[i + 1].selected = true;
								list.options[i].selected = false;
							}
						}
					  }
				  newOrder(list, eval("document." + list.form.name + "." + list.name.substr(0, list.name.lastIndexOf("select"))));
				 }
		 function moveElementTop(list)
				 {    // get the first item selected which needs to move to top
					  iSelected = list.selectedIndex;
					  if (iSelected == 0)
						 return;
					  //now run the moveup loop
					  for ( iMoveTop = 1; iMoveTop <= iSelected; iMoveTop++) {
						 moveElementUp(list);
					  }
				 }
		 function moveElementBottom(list)
				 {    // get the last item selected which needs to move to bottom
					  for ( i = 0; i <= list.length-1; i++)
					  { // if the item is selected then swap it
						if (list.options[i].selected)
							iSelected = i;
					  }
					  if (iSelected == list.length-1)
						 return;
					  iSelected = list.length - 1 - iSelected;
					  // now run the movedown loop
					  for ( iMoveDown = 1; iMoveDown <= iSelected; iMoveDown++)
						 moveElementDown(list);
				 }
		function selectAll(list)
		{
		  for ( i = 0; i <= list.length-1; i++ )
			list.options[i].selected = true;
		  return true;
		}
		function unSelectAll(list)
		{
		  for ( i = 0; i <= list.length-1; i++ )
			list.options[i].selected = false;
		  return true;
		}
		function clearList(list)
		{
		  list.length = 0;
		}
		function copyToList(fromList, toList, direction,obj) {
		  for ( i = 0; i <= fromList.length-1;) {
			if (fromList.options[i].selected) {
				txt = fromList.options[i].text;
				val = fromList.options[i].value;
				if ( val != "" ) {
				   // check if value is a spacer or special element
				   if ( (val == "spacer") ) {
						if ( direction == "left" ) {
							 // remove from right and do not add on left
							 fromList.options[i]= null;
						}
						else {
							// add to right but do not remove from left
							fromList.options[i].selected = false;
							toList.options[toList.length] = new Option( txt, val, false, true );
							toList.options[toList.selectedIndex].selected = false;
						}
				   }
				   else {  //only increment when not moving and deleting
					 // create a new row
					 toList.options[toList.length] = new Option( txt, val, false, true );
					 // added these lines
					 // removes from fromList and unselects item in toList
					 fromList.options[i]= null;
					 toList.options[toList.selectedIndex].selected = false;
				   }  //only increment when not moving and deleting
				} else {
					i++; // increment when selected element is empty
				}
			}
			else i++;  //only increment when not moving and deleting
		  }
		  deleteBlankRowIfNotEmpty(fromList);
		  deleteBlankRowIfNotEmpty(toList);
		  //Set the order
		  //newOrder(toList, eval("document." + toList.form.name + "." + toList.name.substr(0, toList.name.lastIndexOf("select"))));
		  //newOrder(fromList, eval("document." + fromList.form.name + "." + fromList.name.substr(0, fromList.name.lastIndexOf("select"))));
		   if(direction=="right"){
				newOrder(toList,obj);
			}else{
				 newOrder(fromList,obj);
			}
		}
		function copyAll(fromList, toList, direction,obj) {
			 indexofspacer = -1;
			 indexofitem = toList.length;
			 for ( i = 0; i <= fromList.length-1; i++ ) {
				 txt = fromList.options[i].text;
				 val = fromList.options[i].value;
				 if (fromList.options[i].selected) {
						fromList.options[i].selected = false;
				 }
				 if ( val != "" ) {
					 // check if we need to copy the spacer too
					 if ( (val == "spacer") ) {
							indexofspacer = i;
					 }
					 else { // Not a spacer
						  toList.options[indexofitem] = new Option( txt, val, false, true );
						  toList.options[indexofitem].selected = false;
						  indexofitem++;
					 }
				 }
			 }
				if (indexofspacer != -1 && direction == "right" ) // let the spacer be on the from list
					fromList.length = indexofspacer + 1;
				else
			 clearList(fromList);
			 deleteBlankRowIfNotEmpty(toList);
			 unSelectAll(toList);

			 // Set the order
			 //newOrder(toList, eval("document." + toList.form.name + "." + toList.name.substr(0, toList.name.lastIndexOf("select"))));
			 //newOrder(fromList, eval("document." + fromList.form.name + "." + fromList.name.substr(0, fromList.name.lastIndexOf("select"))));
			 if(direction=="right"){					
				newOrder(toList,obj);
			 }else{
				 newOrder(fromList,obj);
			 }
		}

		 function toggleMoveButtons(prefix, checked)
		 {
		   if ( document.getElementById )
		   {
			 document.getElementById(prefix + "movecell").style.display = checked ? "none" : "";
		   }
		 }
				
		function swap(e1, e2)
		{
		  ttext = e1.text;
		  tvalue = e1.value;
		  e1.text = e2.text;
		  e1.value = e2.value;
		  e2.text = ttext;
		  e2.value = tvalue;
		}
		function deleteBlankRowIfNotEmpty(list)
		{
		   var idx = -1;
		   var val = "";
		// find a blank row in table
		   for (i = 0; i < list.length; i++){
				val = list.options[i].value;
				if (val == "") {
				   idx = i;
				   break;
				}
		   }
		   if (idx >= 0 && (list.length > 1))
			  list.options[idx] = null;
		}
		function newOrder(list, csv) {
			csv.value = "";
			for (var i = 0; i <= list.length - 1; i++){
				if (list.options[i].value != "") {
				   csv.value += list.options[i].value;
				   if (i < list.length - 1 && list.options[i+1].value != "")
					  csv.value += ",";
				}
			}
		 }
		 function fckNullTest(str){
				//var strMain = str;
				var index1 = str.indexOf("<body>");
				var index2 = str.indexOf("</body>");
				var strMain = str.substring(index1 + 6 ,index2);

				var strTemp;

				var strTemp2 = strMain; 
				while(strTemp2.indexOf("<p>") != -1){
				  strTemp2 = strTemp2.replace("<p>","&nbsp;");
				}
				while(strTemp2.indexOf("<\/p>") != -1){
				  strTemp2 = strTemp2.replace("<\/p>","&nbsp;");
				}

				var temp1 = strTemp2.indexOf("&nbsp;"); 
				//alert(strMain);
				if(temp1 == -1) return strMain;

				while(temp1 != -1){     
				  strTemp = strTemp2.substr(0,temp1);       
				  if(strTemp != "" && trim(strTemp).length > 0){
					return strMain;             
				  }
				  else{
					strTemp2 = strTemp2.substr(temp1+6,strTemp2.length);                                
					temp1 = strTemp2.indexOf("&nbsp;");
				  }
				}   
				if(strTemp2 == "") return ""; else return strMain;  
			  }	
			  
		function goToLink(ObjectName){
			var obj = document.getElementById(ObjectName);
			var link = obj.innerHTML;
			while(link.indexOf("&amp;")!=-1)
			{
				link = link.replace("&amp;","&");
			}
			window.open(link,"","toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes");
    	}
