//alert(parseInt('09'));

function intVal(value)
{
    value = value.toString();
    if( value.charAt(0) == '0' )
        value = value.substr(1);
    value = parseInt(value);
    return value;
}

function reloadCalendar(date_from,date_to)
{
    var year = listGetSelectedValue( getEbyID('selCalendarYear') );
    var month = listGetSelectedValue( getEbyID('selCalendarMonth') );

    var axID = "axCalendar";
    Ajax.call(axID,"index.php?area=ax:calendar",null,Ajax.OP_SETHTML,{nodeId: "bkCalendar", post: {"year":year,"month":month,"date_from":date_from,"date_to":date_to}});
}

function setEventFilter(key,value)
{
    var form = document.forms['frmEventFilter'];
    var mode = form.mode.value;

    if( mode == "quick" || mode == "archive" )
    {
        switch( key )
        {
            case 'id_performer' :   if( value == "" )   {alert("Válasszon előadót!");return false;}; break;
            case 'id_location'  :   if( value == "" )   {alert("Válasszon helyszínt!");return false;}; break;
            case 'id_pass'      :   if( value == "" )   {alert("Válasszon bérletet / sorozatot!");return false;}; break;
            case 'fulltext'     :   if( value.length < 3 )   {alert("Adjon meg legalább 3 karakter!");return false;}; break;
            case 'date'         :   form.date.value = value; break;
        }

        if( form.id_performer )
            if( key != "id_performer" ) listSelectByValue(form.id_performer,"");
        if( form.id_performer )
            if( key != "id_location" ) listSelectByValue(form.id_location,"");
        if( form.id_pass )
            if( key != "id_pass" ) listSelectByValue(form.id_pass,"");
        if( form.fulltext )
            if( key != "fulltext" ) form.fulltext.value = "";
        if( form.date )
            if( key != "date" ) form.date.value = "";

        form.submit();
    }

    if( mode == "detail" )
    {
        if( form.fulltext.value == "keresett kifejezés(ek) (vesszővel elválasztva)")  form.fulltext.value = "";
        if( key == "submit" )
            form.submit();
    }
}

function flipInfTable(postfix)
{
    var nodeLink = getEbyID('linkFlipArrow_' + postfix);
    var nodeContent = getEbyID('bkFlipContent_' + postfix);

    if( isVisible(nodeContent) )
    {
        showBlock(nodeContent,false);
        nodeLink.innerHTML = "&gt;&gt;";
    }
    else
    {
        showBlock(nodeContent,true);
        nodeLink.innerHTML = "&lt;&lt;";
    }
}

function refreshMonths(monthSelID,yearSelID,date_from,date_to,selMonthValue)
{
    var selMonth = getEbyID(monthSelID);
    var selYear = getEbyID(yearSelID);
    if( (selMonth) && (selYear) )
    {
        var year = listGetSelectedValue(selYear);
        date_from = date_from.substring(0,7);
        date_to = date_to.substring(0,7);

        listDelOption(selMonth,false);
        for(var i=0; i < listMonthName.length;i++)
        {
            var date = year + '-' + listMonthName[i][0];

            switch( true )
            {
                case ((date_from != "") && (date_to != "")) :   if( (date >= date_from) && (date <= date_to) )
                                                                    listAddOption(selMonth,listMonthName[i][0],listMonthName[i][1]);
                                                                break;
                case (date_from != "")                      :   if( date >= date_from )
                                                                    listAddOption(selMonth,listMonthName[i][0],listMonthName[i][1]);
                                                                break;
                case (date_to != "")                        :   if( date <= date_to )
                                                                    listAddOption(selMonth,listMonthName[i][0],listMonthName[i][1]);
                                                                break;
            }
        }

        if( selMonthValue != undefined )
            listSelectByValue(selMonth,selMonthValue);
    }
}

function goPrevCalendarMonth(monthSelID,yearSelID,date_from,date_to,autoshow)
{
    if( autoshow == undefined )
        autoshow = true;
    var selYear = getEbyID(yearSelID);
    var selMonth = getEbyID(monthSelID);
    if( (selMonth) && (selYear) )
    {
        var year = intVal(selYear.options[selYear.selectedIndex].value);
        var month = intVal(selMonth.options[selMonth.selectedIndex].value);
        month -= 1;
        if( month == 0 )
        {
            month = 12;
            year -= 1;
        }
        if( month < 10 )
            month = '0' + month;
            
        if( listInList(selYear,false,year) )
        {
            listSelectByValue(selYear,year);
            refreshMonths(monthSelID,yearSelID,date_from,date_to);
            if( listInList(selMonth,false,month) )
                listSelectByValue(selMonth,month);
            reloadCalendar(date_from,date_to);
            if( autoshow )
                showMonthFirstDay(monthSelID,yearSelID);
        }
    }
}

function goNextCalendarMonth(monthSelID,yearSelID,date_from,date_to,autoshow)
{
    if( autoshow == undefined )
        autoshow = true;
    var selYear = getEbyID(yearSelID);
    var selMonth = getEbyID(monthSelID);
    if( (selMonth) && (selYear) )
    {
        var year = intVal(selYear.options[selYear.selectedIndex].value);
        var month = intVal(selMonth.options[selMonth.selectedIndex].value);
        month += 1;
        if( month == 13 )
        {
            month = 1;
            year += 1;
        }
        if( month < 10 )
            month = '0' + month;
            
        if( listInList(selYear,false,year) )
        {
            listSelectByValue(selYear,year);
            refreshMonths(monthSelID,yearSelID,date_from,date_to);
            if( listInList(selMonth,false,month) )
                listSelectByValue(selMonth,month);
            reloadCalendar(date_from,date_to);
            if( autoshow )
                showMonthFirstDay(monthSelID,yearSelID);
        }
    }
}

function showMonthFirstDay(monthSelID,yearSelID)
{
//
    var selYear = getEbyID(yearSelID);
    var selMonth = getEbyID(monthSelID);
    if( (selMonth) && (selYear) )
    {
        var year = listGetSelectedValue( selYear );
        var month = listGetSelectedValue( selMonth );
        var date = year + "-" + month + "-01";
        setEventFilter('date',date);    
    }
    
}


function postRegOrgan()
{
    var form = document.forms['frmRegOrgan'];

    if( checkInput(form.company,CHK_LENGTH,"A cégnév megadása kötelező!",3) )
        if( checkInput(form.tel,CHK_TEXT,"A telefonszám megadása kötelező!") )
        {
            if( form.fax.value == "" && form.email.value == "" )
            {
                alert("Fax vagy e-mail cím megadása kötelező!");
                return false;
            }

            if( form.fax.value != "" )
                if(! checkInput(form.fax,CHK_TEXT,"A faxszám megadása kötelező!") )
                    return false;

            if( form.email.value != "" )
                if(! checkInput(form.email,CHK_EMAIL,"Az e-mail cím megadása kötelező!") )
                    return false;

            if( checkInput(form.username,CHK_LENGTH,"A bejelentkezési név megadása kötelező!",3) )
                if( checkInput(form.password,CHK_LENGTH,"A jelszó megadása kötelező!",3) )
                    if( checkPassword(form.password,form.passwordchk,"") )
                        return true;
        }

    return false;
}

function writeRightMenu(postfix)
{
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="95" height="638" id="menu" align="middle">');
    document.write('<param name="allowScriptAccess" value="sameDomain" />');
    document.write('<param name="movie" value="flash/menu.swf?menuprovider=xmls/menuitems_'+postfix+'.xml&amp;textsize=10" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="flash/menu.swf?menuprovider=xmls/menuitems_'+postfix+'.xml&textsize=10" quality="high" bgcolor="#ffffff" width="95" height="638" name="menu" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</object>');
}

function writeSplash()
{
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100%" height="100%" id="splash" align="middle">');
    document.write('<param name="allowScriptAccess" value="sameDomain" />');
    document.write('<param name="movie" value="flash/splash.swf?splashprovider=xmls/splash.xml" /><param name="quality" value="high" /><param name="scale" value="noscale" /><param name="bgcolor" value="#ffffff" /><embed src="flash/splash.swf?splashprovider=xmls/splash.xml" quality="high" scale="noscale" bgcolor="#ffffff" width="100%" height="100%" name="splash" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</object>');
}

function postSearchIssue()
{
    var form = document.forms['frmSearchIssue'];
    
    if( checkSelect(form.year,"Kérem válassza ki az évet!","") )
        return true;
    
    return false;    
}

function postSearchLetter()
{
    var form = document.forms['frmSearchLetter'];
    
    if( checkSelect(form.author) || checkSelect(form.title) || checkSelect(form.subject) )
        form.submit();
}

function postSearchFT()
{
    var form = document.forms['frmSearchFullText'];
    
    if( checkInput(form.fulltextsearch,CHK_LENGTH,"Kérem adjon meg legalább 3 karaktert!","3") )
        return true;
    
    return false;    
}

function filterSearchResultBySource(source)
{
    window.location = 'index.php?area=searchres&source=' + source;
}

function updateSearchFTStates(chk)
{
    var form = document.forms['frmSearchFullText'];
    
    if( chk.name == "all" )
    {
        if( form.all.checked )
        {
            form.title.checked = false;
            form.author.checked = false;
            form.article.checked = false;
            form.reper.checked = false;
        }
    }
    else
    {    
        if( form.title.checked || form.author.checked || form.article.checked || form.reper.checked )
            form.all.checked = false;
    }
}

function posImprintBox()
{
    var nodeImprint = getEbyID('nodeImprint');
    var nodeImprintPosH = getEbyID('nodeImprintPosH');
    nodeImprint.style.top = (getScrollHeight() - getOffsetHeight(nodeImprint)) + "px";
}
