function find(id) {
    return document.getElementById(id);
}

function appear(id) {
    document.getElementById(id).style.display = 'block';
}

function vanish(id) {
    document.getElementById(id).style.display = 'none';
}

function changeDisplay(id) {
    var el = document.getElementById(id);
    if (el.style.display != 'block') appear(id);
    else vanish(id);
}

function show(id) {
    document.getElementById(id).style.visibility = 'visible';
}

function hide(id) {
    document.getElementById(id).style.visibility = 'hidden';
}

function hideel(el) {
    el.style.display='none';
}

function pop (url) {
    pop(url, "");
}

function pop (url, caption) {
    w = window.open(url,caption, "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=800,height=600")
    w.moveTo(((screen.width-800)/2),((screen.height-600)/2));
    var ext = url.substr(url.length-3,3);
    if ((ext == "jpg") || (ext == "peg") || (ext == "gif") || (ext == "png")) { // is image
        w.document.write('<head><title>');
        w.document.write(caption);
        w.document.write('</title></head>');
        w.document.write('<body style="margin:0px;"><center><img id="img" src="' + url + '">');
        setTimeout("resizeOnLoad()",200);
    }
}

function poplinksize(url, width, height) {
    var wd = window.open(url, "pop", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=" + width + ",height=" + height);
    wd.moveTo((screen.width-width)/2, (screen.height-height)/2);
}


function poplink(url) {
    width=screen.width*0.8;
    height=screen.height*0.8;
    poplinksize(url, width, height); 
}

function popeditor(url, target) {
    /*
    find('beditor').target = target;
    find('beditor').contents = find("be_" + target).innerHTML;
    find('beditor').src = url;
    find('beditor').style.display='block';
    */
    wbeditor =  window.open(url, "BEditor", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=650,height=" + screen.height);
    //        find('beditor').target = target;
    //        find('beditor').contents = function() { return find("be_" + target).innerHTML; }
    wbeditor.target = find(target);
    wbeditor.be_target = find("be_" + target);
    wbeditor.contents = find("be_" + target).innerHTML;
    //find('beditor').src = url;
    //find('beditor').style.display='block';
    
}

// width, height, 0-100; pos: -1, 0, 1 (left, center, right)
function poprel(url, width, height, posx, posy) {
    var wd = window.open(url, "pop", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=" + (screen.width*width)/100 + ",height=" + (screen.height*height)/100);
    var posx=0;
    var posy=0;
    if (posx == 0) posx=(screen.width - (screen.width*width)/100)/2;
    if (posx > 0) posx = screen.width - (screen.width*width)/100;
    if (posy == 0) posy=(screen.height - (screen.height*height)/100)/2;
    if (posy > 0) posy = screen.height - (screen.height*height)/100;
    
    wd.moveTo(posx, posy);
}


function full(url) {
    width=screen.width;
    height=screen.height;
    var wd = window.open(url, "", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=" + width + ",height=" + height);
    wd.moveTo(0,0);
}

function link(url) {
    width=screen.width;
    height=screen.height;
    var wd = window.open(url, "", "width=" + width + ",height=" + height);
    wd.moveTo(0,0);
}

function resizeOnLoad()  {
    if (w.document.getElementById('img').complete == false) {
        setTimeout("resizeOnLoad()",200);
    } else {
    w.document.close();
    hors=w.document.getElementById('img').width +40;
    vers=w.document.getElementById('img').height+40;
    if (hors > screen.width) hors=screen.width;
    if (vers > screen.height) vers=screen.height;
    w.resizeTo(hors,vers);
    w.moveTo(((screen.width-hors)/2),((screen.height-vers)/2));
}
}





function dateSelected(fieldName, code) {
    document.getElementById(fieldName).value = code;
    document.getElementById(fieldName + "_year").value = code.substr(0,4);
    document.getElementById(fieldName + "_month").value = code.substr(4,2);
    document.getElementById(fieldName + "_date").value = code.substr(6,2);
    hideCalendarPanel(fieldName + "_panel");
}

function upDate(fieldName) {

    var year = document.getElementById(fieldName + "_year").value.substr(0,4);
    while (year.length < 4) year = "0" + year;
    var month = document.getElementById(fieldName + "_month").value.substr(0,2);
    while (month.length < 2) month = "0" + month;
    var date = document.getElementById(fieldName + "_date").value.substr(0,2);
    while (date.length < 2) date = "0" + date;
    
    document.getElementById(fieldName).value = year + month + date;
}

function showCalendarPanel(panelId) {
    show(panelId);
}

function hideCalendarPanel(panelId) {
    hide(panelId);
}

function fillCalendar(field) {
    var today = new Date();
    var tm = today.getMonth();
    var ty = today.getFullYear();
    fillCalendar2(field, tm, ty);
}

function fillCalendar2(field, month, year) {
    
    //var today = new Date();
    //var td = today.getDate();
    //var tm = today.getMonth();
    //var ty = today.getFullYear();
    
    var currentDay = new Date();
    currentDay.setMonth(month);
    currentDay.setYear(year);
    smonth = month + 1;
    if (smonth < 10) smonth = "0" + smonth;
    find(field + "_curr").innerHTML = smonth  + " / " + year; 
    find(field + "_curr").currentMonth = month; 
    find(field + "_curr").currentYear = year; 
    
    currentDay.setDate(1);
    while (currentDay.getDay() > 1) {
        currentDay.setDate(currentDay.getDate()-1);
    }
    
    for (week = 1; week <= 6; week ++) 
        for (day = 1; day <= 7; day ++) {
            var d = currentDay.getDate();
            if (d < 10) d = "0" + d;
            var m = currentDay.getMonth() + 1;
            if (m < 10) m = "0" + m;
            var y = currentDay.getFullYear();
            var code = "" + y + m + d;
            
            var el = find(field + "_" + week + "_" + day);
            el.innerHTML = currentDay.getDate();
            if (currentDay.getMonth() != month) {
                el.className="formCalendarDisabled";
            } else {
            el.className="formCalendarDate";
        }
        el.code = code;
        currentDay.setDate(currentDay.getDate() +1);
    }
}

function prevMonth(field) {
    var currentMonth = find(field + "_curr").currentMonth; 
    var currentYear = find(field + "_curr").currentYear; 
    var newMonth = new Date();
    newMonth.setYear(currentYear);
    newMonth.setMonth(currentMonth - 1);
    fillCalendar2(field, newMonth.getMonth(), newMonth.getFullYear());
}

function nextMonth(field) {
    var currentMonth = find(field + "_curr").currentMonth; 
    var currentYear = find(field + "_curr").currentYear; 
    var newMonth = new Date();
    newMonth.setYear(currentYear);
    newMonth.setMonth(currentMonth);
    newMonth.setMonth(newMonth.getMonth() + 1);
    fillCalendar2(field, newMonth.getMonth(), newMonth.getFullYear());
}

function dateSelected(fieldName, code) {
    find(fieldName).value = code;
    find(fieldName + "_year").value = code.substr(0,4);
    find(fieldName + "_month").value = code.substr(4,2);
    find(fieldName + "_date").value = code.substr(6,2);
    hideCalendarPanel(fieldName + "_panel");
}



function presentation() {
  
    find('header').style.top=-200;
    hide('body');
    
    hide('leftmenu');
    hide('logo');
    hide('dest');
    hide('l1');
    hide('l2');
    hide('l3');
    hide('l4');
    hide('l5');
    hide('l6');
    
    
//    find('leftmenu').style.opacity=0;
//    find('leftmenu').style.filter="alpha(opacity=0)";
//    find('logo').style.opacity=0;
//    find('logo').style.filter="alpha(opacity=0)";
//    find('dest').style.opacity=0;
//    find('dest').style.filter="alpha(opacity=0)";

    find('languages').style.opacity=0;
    find('languages').style.filter="alpha(opacity=0)";
    find('footer').style.opacity=0;
    find('footer').style.filter="alpha(opacity=0)";

//    find('l1').style.opacity=0;
//    find('l1').style.filter="alpha(opacity=0)";
//    find('l2').style.opacity=0;
//    find('l2').style.filter="alpha(opacity=0)";
//    find('l3').style.opacity=0;
//    find('l3').style.filter="alpha(opacity=0)";
//    find('l4').style.opacity=0;
//    find('l4').style.filter="alpha(opacity=0)";
//    find('l5').style.opacity=0;
//    find('l5').style.filter="alpha(opacity=0)";
//    find('l6').style.opacity=0;
//    find('l6').style.filter="alpha(opacity=0)";
    
    show('container');
    
    setTimeout("godown('header', -80)", 0);

//    setTimeout("fadein('leftmenu', 0)", 600);
//    setTimeout("fadein('logo', 0)", 1100);
    setTimeout("show('leftmenu')", 600);
    setTimeout("show('logo')", 900);

    setTimeout("show('l1')", 1000);
    setTimeout("show('l2')", 1100);
    setTimeout("show('l3')", 1200);
    setTimeout("show('l4')", 1300);
    setTimeout("show('l5')", 1400);
    setTimeout("show('l6')", 1500);
    setTimeout("fadein('footer', 0)", 1300);
    setTimeout("fadein('languages', 0)", 1500);
    setTimeout("show('dest')", 1500);
    setTimeout("show('body')", 1700);

    setTimeout("beginFotoSlideShow()", 2000);
}  

function fadein(id, amount) {
    find(id).style.opacity = amount;
    find(id).style.filter="alpha(opacity=" + (amount * 100) + ")";
    amount += 0.10;
    if (amount <= 1) setTimeout("fadein('" + id + "', " + amount + ")", 50);
}

function godown(id, amount) {
    find(id).style.top= amount;
    amount += 5;
    if (amount <= 0) setTimeout("godown('" + id + "', " + amount + ")", 50);
}



function beginFotoSlideShow() {

    images = document.getElementById("fotoslideshow").getElementsByTagName("img");
    amount = 90;
    fadeInImage(0, images.length, 0);
}

function fadeInImage(i, max, amount) {
    if (amount <= 100) {
        amount += 10;
        var ffamount = amount / 100;
        images[i].style.opacity = ffamount;
        images[i].style.filter="alpha(opacity=" + amount + ")";
        if (i > 0) {
            images[i-1].style.opacity = (1.0-ffamount);
            images[i-1].style.filter="alpha(opacity=" + (100 - amount) + ")";
        }
        timeout = setTimeout('fadeInImage(' + i + ', ' + max + ', ' + amount + ')', 75);
    } else {
        amount = 0;
        i += 1;
        if (i >= max) {
            i = 1;
            images[0].style.opacity = 1;
            images[0].style.filter="alpha(opacity=100)";
            for (j=1; j < max; j++) {
                images[j].style.opacity = 0;
                images[j].style.filter="alpha(opacity=0)";
            }
        }
        timeout = setTimeout('fadeInImage(' + i + ', ' + max + ', ' + amount + ')', 4000);
    }
}
