
function fOpenFooterWindowTest(winId) {

    var win = $('#' + winId);    
    win.toggle();

}

function fOpenFooterWindow(winId) {

    var wins = $('div.win-frame');
    wins.each(function(index) { if (this.id != winId && $(this).css("display") == "block") $(this).css("display", "none") });
    var win = $('#' + winId);
    //$('.customer-content  select').css("display", win.css('display'));
    //win.css("display", "none");
    win.toggle();
      
}

function fCloseFooterWindow(winId) {

    var win = $('#' + winId);
    win.toggle();
    //$('.customer-content select').css("display", "block");
}


function fSubmitWDForm() {
    var form = document.getElementById('WDForm');
    var value = "";
    var note = form["_note"].value;
    $("input[type=checkbox][name=wrongItem]:checked").each(function(index) { if (value == "") value = value + this.value; else value = value + "," + this.value; });
    if (value == "") {
        alert("נא לסמן את אחת מהאופציות");
        return;
    }
    var url = form.action + "&custId=" + vCustId + "&headingCode=" + vHeadingCode + "&wrongItem=" + value + "&note=" + form["_note"].value;

    $.ajax({
        type: "GET",
        url: url,
        success: function(output) {
            if (output == 1) {
                frameSuccess(form);
            }
            else {
                frameFailed(form);
            }
            setTimeout(function() { fFrameDelayedClose(form); }, 1000);
        }
    });
    
}
function fSubmitSTFForm() {

    var form = document.getElementById('STFForm');
    var toMail = form["_sentToMail"].value;
    if (!fIsValidMail(toMail)) {
        alert("מייל לא תקין");
        form["_sentToMail"].focus();
        return;
    }
    var url = form.action + "&custId=" + vCustId + "&headingCode=" + vHeadingCode + "&sentToMail=" + toMail + "&senderName=" + form["_senderName"].value + "&note=" + form["_note"].value;

    $.ajax({
        type: "GET",
        url: url,
        success: function(output) {
            if (output == 1) {
                frameSuccess(form);
            }
            else {
                frameFailed(form);
            }
            setTimeout(function() { fFrameDelayedClose(form); }, 1000);

        }

    });
}

function frameSuccess(parent) {
   var elems = $(parent).children(".form-table");
   elems.each(function(index) {
       if(!($(this).hasClass("failed")))
        $(this).toggle();
   }
   );
}

function frameFailed(parent) {
    var elems = $(parent).children(".form-table");
    elems.each(function(index) {
        if (!($(this).hasClass("success")))
            $(this).toggle();
    }
   );
}

function fFrameDelayedClose(parent) {
    var elems = $(parent).children(".form-table");
    parent.reset();
    elems.each(function(index) {
        if (index == 0) 
            this.style.display = "block";
        else
            this.style.display = "none";
    });
    $(parent).parents(".win-frame").css("display", "none");
}

function fIsValidMail(EmailAdress) {
    if (fIsEmpty(EmailAdress)) return false;   
    if ((EmailAdress.match(/^[\w\.\-\d]+@[\w\-\d]+\.\w+/) == null || EmailAdress.match(/\.\./) != null || EmailAdress.match(/\W$/) != null || EmailAdress.match(/[^\w\.\-\d@]/) != null || EmailAdress.match(/^\./) != null))
        return false;
    return true;
}
function fIsEmpty(str) {

    return !str.match(/\S/);
}





 