<!--
//<![CDATA[	

var addressBookWindowPointer = null;

function sEnter(inp, str){
    q = inp;
    if(q && q.value == str) {
        q.value = '';
        q.style.color = '#000000';
    }
}
function sExit(inp, str){
    q = inp;
    if(q && q.value == '') {
        q.value = str;
        q.style.color = '#999999';
    }
}
function noEnter(e,form,addParam){
	if (document.all){
	    if (addParam == 1 && window.event && window.event.keyCode == 13) {
	        addRecepient(form);
	    }
	    return !(window.event && window.event.keyCode == 13);
	} else {
		if (addParam == 1 && e.keyCode == 13) {
	        addRecepient(form);
	    }
	    return !(e.keyCode == 13);
	}
}
function addRecepient(form) {
    var emailAddress = trim(form.add_address.value);
    if (emailAddress.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]{2,}$/) == -1) {
        alert ("Email address should look like username@provider.com");
        return;
    }

    var emailFound = 0;
    emailFound = findRecByValue(emailAddress);
    if (!emailFound) {
        addEmailText(emailAddress,emailAddress);
        form.add_address.value="";
        form.add_address.focus();
    }
}

function addRecepientFromAddressBook(emails) {
    var emailAddressArray = emails.split(",");
    for(var i=0; i<emailAddressArray.length; i++){
        if (emailAddressArray[i].search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]{2,}$/) == -1) {
            alert ("Email address should look like username@provider.com");
            return;
        }
    
        var emailFound = 0;
        emailFound = findRecByValue(emailAddressArray[i]);
        if (!emailFound) {
            addEmailText(emailAddressArray[i],emailAddressArray[i]);
        }
    }
}

function findRecByValue(value) {
    var tbl   = document.getElementById("tblCombo");
    var inputs = tbl.getElementsByTagName("input");

    if (inputs == null) {
        return;
    }
    for (var i=0; i<inputs.length;i++) {
        if (inputs[i].name == "recipients_list_fake" && inputs[i].value == value) {
            return 1;
        }
    }
    return 0;
}
function addEmailText(text,value) {
    var tbl   = document.getElementById("tblCombo").getElementsByTagName("tbody")[0];
    var count = document.getElementById("tblCombo").rows.length;

    var row = document.createElement("tr");
    var cell = document.createElement("td");

    cell.setAttribute("nowrap","1");
    cell.innerHTML = '<input type="checkbox" name="recipients_list_fake" value="'+ value +'" checked>';
    row.appendChild(cell);

    var cell = document.createElement("td");
    cell.setAttribute("nowrap","");
    cell.setAttribute("width","100%");
    cell.innerHTML = text;

    row.appendChild(cell);
    tbl.appendChild(row);
}

function removeRecepient(form) {
    removeEmailItem();
}
function removeEmailItem() {
    var row;
    var victimFound = 1;
    var checkbox;
    var tbl = document.getElementById("tblCombo");

    while (victimFound) {
        victimFound = 0;
        var count = tbl.rows.length;
        for (var i=0; i<count; i++) {
            row   = tbl.getElementsByTagName("tr")[i];
            checkbox = row.getElementsByTagName("input")[0];
            if (checkbox.checked){
                tbl.deleteRow(i);
                victimFound = 1;
                break;
            }
        }
    }
}


function getEmailsFromTable(){
    var friendsEmail = new String();
    var tbl = document.getElementById("tblCombo");
    var count = tbl.rows.length;
    var form = document.formToSendData;

    for (var i=0; i<count; i++) {
        row   = tbl.getElementsByTagName("tr")[i];
        checkbox = row.getElementsByTagName("input")[0];
        if (checkbox.checked){
            if (friendsEmail != "") {
                friendsEmail += ",";
            }
            friendsEmail += checkbox.value;
        }
    }

    form.friendsEmail.value = friendsEmail;
}
function trim(strText) {
    // this will get rid of leading spaces
    while (strText.substring(0,1) == ' ')
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

    return strText;
}
function formValidateEmail(email_str, whom) {
    if (email_str.length == 0) {
        alert ("Valid Email is required.");
        return false;
    } else {
        var pos = -1;
        if ((pos = email_str.indexOf("@")) > 0) {
            if (email_str.indexOf(".", pos) < 0) {
                alert (whom + " Email address should look like username@provider.com.");
                return false;
            }
        } else {
            alert (whom + " Email address should look like username@provider.com.");
            return false;
        }
    }
    return true;
}
function addGroup(form) {
    var val = "";
    var text = "";
    //group_list
    for (var i=0;i<form.group_list.options.length;i++){
        if (form.group_list.options[i].selected) {
            val = form.group_list.options[i].value;
            text = form.group_list.options[i].text;
            break;
        }
    }

    var groupFound = findRecByValue(val);
    if (!groupFound && val != -1) {
        addEmailText("<b>"+text+"</b>",val);
    }
}

function openAddressBook(){
    var windowProp = "copyhistory=false,directories=false,location=false,menubar=false,resizable=false,status=false,toolbar=false,scrollbars, width=559, height=400";
    addressBookWindowPointer = window.open("email-address-book.html", "Address_book", windowProp);
    //window.onunload = closeAddressBook;
}

function closeAddressBook(){
    addressBookWindowPointer.close();
}

//]]>
-->