﻿var MessageType = { 'alert': 'alert',
    'error': 'error',
    'success': 'success',
    'notice': 'notice'
};

//stvara notification div na stranici
//inMessage je poruka
//inType je neki od clanova objekta MessageType
function NotifyUser(inMessage, inType) {

    if (inType == null) inType = MessageType.notice;

    var htmlMessage = '<div id="' + inType + '" class="message"><p>' +
    inMessage.replace('\n', '<br/>') +
    '</p><a onclick="return $(this).parent(\'div\').fadeOut(\'slow\');" title="Close" class="close" href="#">&nbsp;</a></div>';

    if ($('.paketinfo').length == 0)
        $('#menu').after(htmlMessage);
    else
        $('.paketinfo').after(htmlMessage);
    
    $('html, body').animate({scrollTop:0}, 'slow');
}

function isDate(text) {
    var reValidator = new RegExp(/^(\d{1,2})(\.)(\d{1,2})(\.)(\d{4})$/);
    var aMatch = text.match(reValidator);

    if (aMatch == null) return false;

    day = aMatch[1];
    month = aMatch[3];
    year = aMatch[5];

    if (month < 1 || month > 12) return false;
    if (day < 1 || day > 31) return false;
    if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) return false;
    if (month == 2) {
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day == 29 && !isleap)) return false;
    }

    return true;
}
