function changeMessage(){
    var msgSelector = document.getElementById('messagesel');
    var msgBox = document.getElementById('message');
    if(msgSelector.value == 'kid'){
        msgBox.value = 'Hi! You have to check out this cool online world - CentsCity!  When you sign-up, you get to learn all about money by traveling to virtual places like the Eiffel Tower, Area 51, and the Amazon Rainforest.  If your parents or teachers sign up, you can earn a fun Passport with stamps and stickers.  Best of all, you can buy rewards in the real world with the points you earn.\n\nCheck out the website at www.centscity.com to sign-up for free.'; 
    } else {
        msgBox.value = 'Hi!  I am writing to invite you to try out CentsCity.  CentsCity is an online world where kids learn financial skills and earn rewards in the real-world as they become financially savvy.  When you sign up, your kids receive a Passport Stamp & Sticker book that helps them track their progress in a cool and fun way.  They earn duckets by going on quests to places like the Eiffel Tower where gurus teach them financial secrets. \n\nVisit the website at www.centscity.com to learn more and to register for free.';
    }
}

function ValidateInviteOthersForm(frm)
{
    if(isStringEmpty(frm.name.value))
    {
        Popup.showAlertPopup('Please enter your name');
        return false;
    }
    else if(!isValidEmail(frm.fielde.value))
    {
        Popup.showAlertPopup('Please enter a valid email address');
        return false;
    }
    else if(isStringEmpty(frm.mailto.value))
    {
        Popup.showAlertPopup("<div style=\"height:24px;\">Please enter your friends' email address(es), separated by commas</div>");
        return false;
    }
    else if(!validateMultipleEmail(frm.mailto.value))//validate multiple ids
    {
        Popup.showAlertPopup("<div style=\"height:24px;\">Please enter valid email address(es), separated by commas</div>");
        return false;
    }
    else if(isStringEmpty(frm.message.value))//check in case the user has deleted the text in message field and clicked on send
    {
        Popup.showAlertPopup("Please enter a message");
        return false;    
    }
    return true;
}
//Validate email
function isValidEmail(email){
    var ck_email = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; //Standard email address 
    
    return ck_email.test(email);
}

//empty string
function isStringEmpty(str){

    var regex = /\s/g;
    var strNew = str.replace(regex, '');//replace whitespaces with empty string
    return strNew == '' ? true : false;
}

//function to validate multiple emails seperated by comma
//returns true if all the email ids are valid, else returns false
function validateMultipleEmail(strMultiEmail)
{
    if(strMultiEmail.indexOf(',') >= 0)//has multiple email ids
    {
        var arrEmails = strMultiEmail.split(',');
        for(var nCtr = 0; nCtr < arrEmails.length; nCtr++)
        {
            var strEmail = trim(arrEmails[nCtr]);
            if(strEmail != "")
            {
                if(!isValidEmail(strEmail))
                {
                    return false;
                }
            }
        }
        return true;
    }
    else//has single email id
    {
        return isValidEmail(trim(strMultiEmail));
    }
}

// Removes leading and trailing whitespaces
function trim(str) {
	return str.replace(/^\s+/, '').replace(/\s+$/, '');
}