function move(fbox,tbox) {
var i = 0;
if(fbox.value != "") {
var no = new Option();
no.value = fbox.value;
no.text = fbox.value;
tbox.options[tbox.options.length] = no;
fbox.value = "";
   }
}

function checkForCharacters(text){
   
    filteredValues = "1234567890";     // Characters stripped out
    var i;
    var returnString = "";
    for (i = 0; i < text.length; i++) {  // Search through string and append to unfiltered values to returnString.
        var c = text.charAt(i);
        if (filteredValues.indexOf(c) == -1) 
            returnString += c;
    }
    
    if(returnString.length > 0)
        return true;
    else
        return false;
}


function addPhone(tbox, phonearea, phoneprefix, phonenumber, type ) {
    var i = 0;
    var typeText = "";
    var phoneTypeText = " (" + type.options[type.selectedIndex].label + ")";
    var phoneTypeValue = type.options[type.selectedIndex].value;


    if(checkForCharacters(phonearea.value) == true || 
       checkForCharacters(phoneprefix.value) == true || 
       checkForCharacters(phonenumber.value) == true ){
        alert("Only numeric values allowed in phone number");
        return;
    }

    if(phonearea.value == "" || phonearea.value.length != 3){
        alert("You must supply an area code");
        return;
    }
    if(phoneprefix.value == "" || phoneprefix.value.length != 3){
        alert("You must supply a phone prefix");
        return;
    }
    if(phonenumber.value == "" || phonenumber.value.length != 4){
        alert("You must supply a phone number");
        return;
    }

    var text = "(" + phonearea.value + ")" + phoneprefix.value + "-" + phonenumber.value;
    if(text != "") {
        var newOption = new Option();
        newOption.value = text + "," + phoneTypeValue;
        newOption.text = text + phoneTypeText ;
        tbox.options[tbox.options.length] = newOption;
        //now we need to blank out our fields
        phonenumber.value = "";
        phoneprefix.value = "";
        phonearea.value = "";
   }
 
    var i = 0;
    var len = tbox.options.length;
    for(i=0; i < len; i++){
        tbox.options[i].selected=1;
    }
   
}


function addEmail(tbox, email) {
    var i = 0;

    if(email.value == ""){
        alert("No email address entered.");
        return;
    }

    if(checkEmail(email) == false){
        alert("Invalid email address.");
        return;
    }
    
    var text = email.value;
    if(text != "") {
        var no = new Option();
        no.value = text;
        no.text = text;
        tbox.options[tbox.options.length] = no;
        //now we need to blank out our fields
        email.value = "";
   }
}

function checkEmail(email) {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value)){
        return (true)
    }
    
    return (false)
}


function remove(box) {
for(var i=0; i<box.options.length; i++) {
if(box.options[i].selected && box.options[i] != "") {
box.options[i].value = "";
box.options[i].text = "";
   }
}
BumpUp(box);
} 
function BumpUp(abox) {
for(var i = 0; i < abox.options.length; i++) {
if(abox.options[i].value == "")  {
for(var j = i; j < abox.options.length - 1; j++)  {
abox.options[j].value = abox.options[j + 1].value;
abox.options[j].text = abox.options[j + 1].text;
}
var ln = i;
break;
   }
}
if(ln < abox.options.length)  {
abox.options.length -= 1;
BumpUp(abox);
   }
}
function Moveup(dbox) {
for(var i = 0; i < dbox.options.length; i++) {
if (dbox.options[i].selected && dbox.options[i] != "" && dbox.options[i] != dbox.options[0]) {
var tmpval = dbox.options[i].value;
var tmpval2 = dbox.options[i].text;
dbox.options[i].value = dbox.options[i - 1].value;
dbox.options[i].text = dbox.options[i - 1].text
dbox.options[i-1].value = tmpval;
dbox.options[i-1].text = tmpval2;
      }
   }
}
function Movedown(ebox) {
for(var i = 0; i < ebox.options.length; i++) {
if (ebox.options[i].selected && ebox.options[i] != "" && ebox.options[i+1] != ebox.options[ebox.options.length]) {
var tmpval = ebox.options[i].value;
var tmpval2 = ebox.options[i].text;
ebox.options[i].value = ebox.options[i+1].value;
ebox.options[i].text = ebox.options[i+1].text
ebox.options[i+1].value = tmpval;
ebox.options[i+1].text = tmpval2;
      }
   }
}


