
var alphanumeric = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
function res(t,v){
	var w = "";
	for (i=0; i < t.value.length; i++) {
		x = t.value.charAt(i);
		if (v.indexOf(x,0) != -1)
			w += x;
	}
	t.value = w;
}

function getinput(e){
return window.self.document.getElementById(e).value;
}

function clearinput(e){
window.self.document.getElementById(e).value='';
}

function getselectedinput(e){
var elem = window.self.document.getElementById(e);
return elem.options[elem.selectedIndex].value;
}

function openeditor(AppPath, id){
var RichTextEditor=window.open('/WebWrite/Tools/RichText/RTEEditor.aspx?AppPath=' + AppPath + '&ID=' + id + '','RichTextEditor','width=700,height=700,left=100,top=100');RichTextEditor.focus();
}



function MoveItem(ctrlSource, ctrlTarget) {
	var Source = document.getElementById(ctrlSource);
	var Target = document.getElementById(ctrlTarget);

	if ((Source != null) && (Target != null)) {
		//while ( Source.options.selectedIndex >= 0 ) {
			var newOption = new Option(); // Create a new instance of ListItem
			newOption.text = Source.options[Source.options.selectedIndex].text;
			newOption.value = Source.options[Source.options.selectedIndex].value;

			var add = true;
			for (x = 0; x < Target.length; x++) {
				if (Target.options[x].value == newOption.value) {
					add = false;
					x = Target.length;
				}
			}
			if (add) 
				Target.options[Target.length] = newOption; //Append the item in Target
			
			//Source.remove(Source.options.selectedIndex);  //Remove the item from Source
		//}
	}
}

function ReMoveItem(ctrlSource) {
	var Source = document.getElementById(ctrlSource);

	if (Source != null) {
		while ( Source.options.selectedIndex >= 0 ) {
			Source.remove(Source.options.selectedIndex);  //Remove the item from Source
		}
	}
}

function SaveListToHidden(crtllist, ctrlhidden){
	var list = document.getElementById(crtllist);
	var hidden = document.getElementById(ctrlhidden);
	
	hidden.value = "";
	
	for (x = 0; x < list.length; x++) {
		hidden.value += list.options[x].value + ";";
	}
}



	/** this function Takes all items that are not of the FORM type
	 * attached to the BODY tag and Inserts them in the specified form Tag
	 * @param formName the id of the form */
	function fixStupidFormErrorThatTookLongTimeForJasonToFigureOut(formName) {
		var form = document.getElementById(formName);
		var body = document.body;
		var finished = false;
		var index = 0;
		for(counter=0; counter<1000; counter++){
			if (index == body.childNodes.length){
				break;
			}
			var child = body.childNodes[index];
			if(child == form){
				index++;
				continue;
			}
			else {
				var removed = body.removeChild(child);
				form.appendChild(removed);
			}
		}
		if (counter >= 1000){ alert("fixStupidFormErrorThatTookLongTimeForJasonToFigureOut() seemingly Failed it ran for " + counter + " Times!!"); }
	}
	
	
	
/*
  This contains a set of functions that help protect email addresses
  from spam-bots. Instead of using the email address directly, the 
  encoded value is stored in the html and decoded when required.

  Ralph Arvesen
  Vertigo Software
*/

// open the client email with the specified address
function sendEmail(encodedEmail)
{
  // do the mailto: link
  location.href = decodeEmail(encodedEmail);
}

// display the email address in the statusbar
function displayStatus(encodedEmail)
{
  window.status = decodeEmail(encodedEmail);
}

// clear the statusbar message
function clearStatus()
{
  window.status = "";
}

// return the decoded email address
function decodeEmail(encodedEmail)
{
  // The encodedEmail is a string that contains the email address.
  // Each character in the email address has been converted into 
  // a two digit number (hex / base16). This function converts the
  // series of numbers back into the real email address.

  // holds the decoded email address
  var email = "";

  // go through and decode the email address
  for (i=0; i < encodedEmail.length;)
  {
    // holds each letter (2 digits)
    var letter = "";
    letter = encodedEmail.charAt(i) + encodedEmail.charAt(i+1)

    // build the real email address
    email += String.fromCharCode(parseInt(letter,16));
    i += 2;
  }
  
  return email;
}








//###################################################################

/*
  - Give Credit Where Its Due -
  Please acknowledge this article and its author, at
  least in code comments, when using this code.

  Author: Justin Whitford
  Source: www.evolt.org

  Thank you.
*/

/*
  filtery(pattern, list)
  pattern: a string of zero or more characters by which to filter the list
  list: reference to a form object of type, select

  Example:
  <form name="yourForm">
    <input type="text" name="yourTextField" onchange="filtery(this.value,this.form.yourSelect)">
    <select name="yourSelect">
      <option></option>
      <option value="Australia">Australia</option>
       .......
*/
function filtery(pattern, list){
  /*
  if the dropdown list passed in hasn't
  already been backed up, we'll do that now
  */
  if (!list.bak){
    /*
    We're going to attach an array to the select object
    where we'll keep a backup of the original dropdown list
    */
    list.bak = new Array();
    for (n=0;n<list.length;n++){
      list.bak[list.bak.length] = new Array(list[n].value, list[n].text);
    }
  }

  /*
  We're going to iterate through the backed up dropdown
  list. If an item matches, it is added to the list of
  matches. If not, then it is added to the list of non matches.
  */
  match = new Array();
  nomatch = new Array();
  for (n=0;n<list.bak.length;n++){
    if(list.bak[n][1].toLowerCase().indexOf(pattern.toLowerCase())!=-1){
      match[match.length] = new Array(list.bak[n][0], list.bak[n][1]);
    }else{
      nomatch[nomatch.length] = new Array(list.bak[n][0], list.bak[n][1]);
    }
  }

  /*
  Now we completely rewrite the dropdown list.
  First we write in the matches, then we write
  in the non matches
  */
  for (n=0;n<match.length;n++){
    list[n].value = match[n][0];
    list[n].text = match[n][1];
  }
  for (n=0;n<nomatch.length;n++){
    list[n+match.length].value = nomatch[n][0];
    list[n+match.length].text = nomatch[n][1];
  }

  /*
  Finally, we make the 1st item selected - this
  makes sure that the matching options are
  immediately apparent
  */
  list.selectedIndex=0;
}