function trim(str) {
    str = this != window? this : str;
    return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function check_mail(str) {
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (filter.test(str))
        return true
    else
        return false;
}

function check_radio(radio_button) {
    radio_choice = false;
    for (counter = 0; counter < radio_button.length; counter++) {
        if (radio_button[counter].checked)
            radio_choice = true; 
    }
    return radio_choice;
}

function check_form(f) {

    if( !check_radio(f.ind) ) {
        alert("Please select your card.");
        return (false);
    }
    if( trim(f.to.value) == "" ) {
        alert("Please enter recipient's email.");
        f.to.focus();
        return (false);
    }
    if( !check_mail(trim(f.to.value)) ) {
        alert("Please enter valid recipient's email address.");
        f.to.focus();
        return (false);
    }
    if( trim(f.name.value) == "" ) {
        alert("Please enter your name.");
        f.name.focus();
        return (false);
    }
    if( trim(f.from.value) == "" ) {
        alert("Please enter your email.");
        f.from.focus();
        return (false);
    }
    if( !check_mail(trim(f.from.value)) ) {
        alert("Please enter valid your email address.");
        f.from.focus();
        return (false);
    }
    return true;
}

function openNewWindow(url, name, width, height) {
    newWindow = window.open(url,name,"toolbar=0,directories=0,resizable=0,status=0,scrollbars=0,menubar=0,width="+width+",height="+height+",top=150,left=150");
    newWindow.focus();
}
