﻿// buttons: { Delete: true, Cancel: false },

//---  Sample code of Jquery Dialog box ---
$(function() {
    $("#dialog").dialog({
        bgiframe: true,
        height: 140,
        modal: true,
        autoOpen: false,
        resizable: false
    })
});

function setWaitMessage (formName) {
    var submitButton = $('#' + formName).find("input[type='submit']");
    $(submitButton)
                    .val("Παρακαλώ περιμένετε...")
                    .css("cursor", "default")
                    .attr("disabled", "true");
}

// generic error and success faceboxes
$.errorBox = function(title, text) {
    $.facebox('<h2 class="title icon_warning">' + title + '</h2>' + text);
    setTimeout(function() {
        jQuery(document).trigger('close.facebox');
    }, 2000);
}

$.successBox = function(title, text) {
    $.facebox('<h2 class="title icon_check">' + title + '</h2>' + text);
    setTimeout(function() {
        jQuery(document).trigger('close.facebox');
    }, 2000);
}


function limitChars(textid, limit, infodiv) {
    var text = $('#' + textid).val();
    var textlength = text.length;
    if (textlength > limit) {
        $('#' + infodiv).html('Δεν μπορείς να γράψεις πάνω απο ' + limit + ' χαρακτήρες!');
        $('#' + textid).val(text.substr(0, limit));
        return false;
    } else {
        $('#' + infodiv).html((limit - textlength) + ' χαρακτήρες απομένουν.');
        return true;
    }
}

function returnSafeBool(str) {
    if (str.toString().toLowerCase() == 'true') {
        return true;
    } else if (str.toString().toLowerCase() == 'false') {
        return false;
    }
}


function confirm(msg, callBackFunc) {
    $.prompt(msg, {
        callback: callBackFunc,
        buttons: { Yes: true, No: false }
    });
}

function confirm2(msg, title, callbackFunc) {
    Boxy.confirm(msg, callbackFunc, { title: title }
            );
}


function alert(msg) {
    var brown_theme_text = '<h3>Alert</h3>' +
                                  '<p>' + msg + '</p>';

    $.prompt(brown_theme_text, {
        buttons: { Ok: true, Cancel: false },
        prefix: 'brownJqi'
    });
}

function alert2(msg, title, callbackFunc) {
    Boxy.alert(msg, callbackFunc, { title: title }
            );
}

String.prototype.trim = function() {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}


$(document).ready(function() {
    var searchTxt = 'αναζήτηση προϊόντων';
    $('#search')
                .css("color", "gray")
                .attr('value', searchTxt)
                .focus(function() {
                    $(this).attr('value', '');
                })
                .keyup(function(e) {                    
                    if (e.keyCode == 13) {
                        var searchValue = $('#search').attr('value');
                        window.location = "http://www.antallakseto.gr/search?sv=" + searchValue.trim();
                    }                    
                });

    $('#searchImg')
                .css("cursor", "pointer")
                .click(function() {
                    var searchValue = $('#search').attr('value');
                    window.location = "http://www.antallakseto.gr/search?sv=" + searchValue.trim();

                    //                    $(location).attr('href', "search?sv=" + searchValue);
                    //                    $.ajax({
                    //                        type: "GET",
                    //                        url: "search",
                    //                        data: { sv: searchValue }
                    //                    });
                })
});
