﻿function AddEmail() {
    document.getElementById("nlErrorDiv").style.display = "none";
    vName = document.getElementById("nlName").value;
    vEmail = document.getElementById("nlEmail").value;
    if (!HasText(vName) || vName == "your name") {
        document.getElementById("nlErrorDiv").style.display = "";
        document.getElementById("nlErrorDiv").innerHTML = "Παρακαλούμε γράψτε το όνομά σας";
        document.getElementById("nlName").focus();
        return;
    }
    if (!HasText(vEmail) || vEmail == "your email") {
        document.getElementById("nlErrorDiv").style.display = "";
        document.getElementById("nlErrorDiv").innerHTML = "Παρακαλούμε γράψτε το email σας";
        document.getElementById("nlEmail").focus();
        return;
    }
    if (!IsValidEmail(vEmail)) {
        document.getElementById("nlErrorDiv").style.display = "";
        document.getElementById("nlErrorDiv").innerHTML = "Το email δεν είναι έγκυρο";
        document.getElementById("nlEmail").focus();
        return;
    }

    BeginAjaxProcess("", "nlAjaxProcess", "nlAjax");
    Vlemma.controls.newsletter_form.writeEmail(vName, vEmail, function(ajax) {
        if (!ajax.error) {
            document.getElementById("nlErrorDiv").style.display = "";
            if (ajax.value.indexOf("err_") > -1) {
                document.getElementById("nlErrorDiv").innerHTML = "Υπήρξε σφάλμα";
                EndAjaxProcess("nlAjaxProcess", "nlAjax");
            }
            else {
                document.getElementById("nlErrorDiv").innerHTML = "Ευχαριστούμε για την εγγραφή σας";
                document.getElementById("nlName").value = "";
                document.getElementById("nlEmail").value = "";
                EndAjaxProcess("nlAjaxProcess", "nlAjax");
            }
        }
        else {
            alert(ajax.error);
        }
    });
}

function BeginAjaxProcess(text,processDiv,htmlDiv) {
    document.getElementById(processDiv).style.display = "";
    document.getElementById(htmlDiv).style.display = "none";
}
function EndAjaxProcess(processDiv, htmlDiv) {
    document.getElementById(processDiv).style.display = "none";
    document.getElementById(htmlDiv).style.display = "";
}

function search() {
    keyword = document.getElementById("keyword").value;

    if (!HasText(keyword)) {
        alert("Πρέπει να πληκτρολογείσετε τουλάχιστον 2 χαρακτήρες");
        document.getElementById("keyword").focus();
        return;
    }

    document.forms[0].action = "searchresults.aspx"
    document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
}
function handleEnter(field, event) {
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 13) {
        keyword = document.getElementById("keyword").value;

        if (!HasText(keyword)) {
            alert("Πρέπει να πληκτρολογείσετε τουλάχιστον 2 χαρακτήρες");
            document.getElementById("keyword").focus();
            return false;
        }

        search();
    }
    else
        return true;
}
