/**
 *    jmenne prostory
 */
var lib = {};
var page = {};

/**
 *    funckce selectCountry(String, Array(Array), Array(Arrays)) - modul OrderForm
 *    funkce sestavi option v selectech #resort a #transport na zaklade id (vyberu v selectu #country)
 *    pouzit plugin do jQuery
 */
lib.selectCountry = function (id, countryResorts, countryTransports) {

    $("select#resort").removeOption(/./);
    $("select#transport").removeOption(/./);
    
    id = id+'';
    
    if(id != '') {
        var i;
        if(countryResorts[id].length > 0) {
            for(i = 0; i<countryResorts[id].length; i++) {
                $("select#resortCopy").selectOptions(countryResorts[id][i]+"");
                $("select#resortCopy").copyOptions("select#resort");
            }
        }
        if(countryTransports[id].length > 0) {
            for(i = 0; i<countryTransports[id].length; i++) {
                $("select#transportCopy").selectOptions(countryTransports[id][i]+"");
                $("select#transportCopy").copyOptions("select#transport");
            }
        }
    } else {
        $("select#resortCopy").copyOptions("select#resort", "all");
        $("select#transportCopy").copyOptions("select#transport", "all");
    }

    $("select#resort").selectOptions("");
    $("select#transport").selectOptions("");
}

lib.selectCountrySelects = function (idCountry, idResort, countryResorts) {
    var c = (idCountry == '2');
    var r = (inArray(countryResorts[2], idResort));
    if(c || r) {
        $('div.accommodation, div.board').show();
    } else {
        $('div.accommodation, div.board').hide();
    }
}

//function lib.optionResortSelects(id, countryResorts) {
//    if(id != '') {
//        if() {
//            $('div.accommodation, div.board').show();
//        } else {
//            $('div.accommodation, div.board').hide();
//        }
//    } else {
//        $('div.accommodation, div.board').hide();
//    }
//}


lib.createCookie = function (name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

lib.readCookie = function (name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

lib.eraseCookie = function (name) {
    createCookie(name,"",-1);
}

