///////////////////////////////////////////////////////////////////////////////
//
// the main JS File
// Juan M. Casillas <juanm.casillas@jmcresearch.com
//
///////////////////////////////////////////////////////////////////////////////

function light_cell(cellname) {
    if  (document.getElementById) {
        cell = document.getElementById(cellname);
        cell.style.prevbackgroundColor = cell.style.backgroundColor;
        cell.style.backgroundColor = 'f5EEC3';
        cell.style.cursor = 'default';
    }
}

function dark_cell(cellname) {
    if  (document.getElementById) {
        cell = document.getElementById(cellname);
        cell.style.backgroundColor = cell.style.prevbackgroundColor;
    }
}

function navigate(url) {
    document.location = url;
    return(true);
}

function validate_poll(form_name) {
 if  (document.getElementById) {
    form = document.getElementById(form_name);

    active=false;
    for (i=0; i<form.poll.length; i++) {
        if (form.poll[i].checked == true) {
            active = true;
            break;
        }
    }
    if (active) {
        form.submit();
    }
    else {
        alert("You must select one option if you want to vote");
    }
 }
}

function validate_search(form_name) {
 if  (document.getElementById) {
    form = document.getElementById(form_name);
    if (form['query'].value != null && form['query'].value != "" ) {
        form.submit();
    }
    else {
        alert("Please type your query");
    }
 }
}

function validate_login(form_name) {
 if  (document.getElementById) {
    form = document.getElementById(form_name);
    if (form['nick'].value != null && form['passwd'].value != "" ) {
        form.submit();
    }
    else {
        alert("Please insert your login and password");
    }
 }
}

function validate_create_account(form_name) {
 if  (document.getElementById) {
    form = document.getElementById(form_name);
    if (form['nick'].value != null && form['email'].value != "" &&
        form['passwd'].value != null && form['passwd2'].value != "" ) {
        form.submit();
    }
    else {
        alert("Please fill all the required fields");
    }
 }
}

function validate_create_comment(form_name) {
 if  (document.getElementById) {
    form = document.getElementById(form_name);
    if (form['title'].value != null && form['body'].value != "") {
        form.submit();
    }
    else {
        alert("Please fill all the required fields");
    }
 }
}

function validate_create_email(form_name) {
 if  (document.getElementById) {
    form = document.getElementById(form_name);
    if (form['from'].value != null && form['subject'].value != "" &&
	form['body'].value != "") {
        form.submit();
    }
    else {
        alert("Please fill all the required fields");
    }
 }
}


function validate_create_history(form_name) {
 if  (document.getElementById) {
    form = document.getElementById(form_name);
    if (form['title'].value != null && form['subtitle'].value != "" &&
	form['body'].value != "") {
        form.submit();
    }
    else {
        alert("Please fill all the required fields");
    }
 }
}

