function atidaryk(psl)
{		
	var X = screen.width / 2 - 180;
	var Y = screen.height / 2 - 135;
	  myWin= open("", "displayWindow", 
				"width=360,height=270,status=no,toolbar=no,menubar=no,resizable=no,left="+X+",top="+Y+"");  
	  myWin.document.open();  
	  myWin.document.write("<html><head><title>Activity</title>");
	  myWin.document.write("</head><body topmargin=0 leftmargin=0>");
	  myWin.document.write("<a href='javascript:close()'><center><img src="+psl+" border=0></center></a>");  	  
	  myWin.document.write("</body></html>"); 
	  myWin.document.close();  
}
function openWin (fileName, windowName)
{
	var X = screen.width / 2 - 265;
	var Y = screen.height / 2 - 210;
	window.open(fileName,'Contacts','width=530,height=420,left='+X+',top='+Y+',screenX='+X+',screenY='+Y+',directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no');
} 
function openMovie (fileName)
{
	var X = screen.width / 2 - 140;
	var Y = screen.height / 2 - 135;
	window.open(fileName,'Intro','width=280,height=270,left='+X+',top='+Y+',screenX='+X+',screenY='+Y+',directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no');
}

function openImage (fileName, windowName)
{
	var X = screen.width / 2 - 400;
	var Y = screen.height / 2 - 400;
	window.open(fileName,'Contacts','width=400,height=400,left='+X+',top='+Y+',screenX='+X+',screenY='+Y+',directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no');
}


var oldPrice = 0;
var oldAccomodation = 0;
var accomodationPrice = 0;
var oldTransport = 0;

var svaroDalinimas = 1.448;

var firstChange = false;

function agree()
{
    var submitButton = document.getElementById('submit');
    var agreeButton  = document.getElementById('sutinku');

    if ( agreeButton.checked == false )
    {
        submitButton.disabled = true;
    } else {
        submitButton.disabled = false;
    }
}

function increaseInt ( objectId )
{
	var	myObject = document.getElementById( objectId );
	myObject.value = parseInt( myObject.value ) + 1;
}

function decreaseInt ( objectId )
{
	var	myObject = document.getElementById( objectId );
    if (myObject.value > 1)
        myObject.value = parseInt( myObject.value ) - 1;
}

function showBox( objectId )
{
    var myObject = document.getElementById( objectId );
	if (myObject)
	{	
		myObject.style.display = 'block';
	}
}

function hideBox( objectId )
{
    var myObject = document.getElementById( objectId );
    if (myObject)
    {
		myObject.style.display = 'none';
	}
}

function changeDepartDate()
{
     var nightsCount = document.getElementById('nights').value;
     var arrivalDate = document.getElementById('arrrivalDate').value;
     var dateExtracted = arrivalDate.split("-");

     var year = dateExtracted[0];
     var month = dateExtracted[1];
     var day  = dateExtracted[2];

     arrivalDate = new Date( year, month, day );

     departDate = new Date(arrivalDate.getTime() + nightsCount*24*60*60*1000);

     var departInput = document.getElementById('departureDate');

     year = departDate.getFullYear();
     month = departDate.getMonth();
     day  = departDate.getDate();

     if (year < 1970) year += 100;

     year = new String( year );
     month = new String( month );
     day = new String( day );

     if ( month.length == 1 ) month = "0" + month;
     if ( day.length == 1) day = "0" + day;

     showDate = year + '-' + month + '-' + day;
     departInput.value = showDate;
}

function changePrice( item, id )
{
    var actualPrice = document.getElementById('price');
    var actualPrice2 = document.getElementById('price2');
    var accomodation = document.getElementById('nRequired1');    
    
    if ( accomodation.checked == true )
    {
        realPrice = parseInt( prices[ id ][ 2 ] );
    } else {
        realPrice = parseInt( prices[ id ][ 1 ] );
    }

    if ( item.checked == true )
    {
        actualPrice.value = parseInt( actualPrice.value ) + realPrice ;
    } else {
        actualPrice.value = parseInt( actualPrice.value ) - realPrice;
    }

    actualPrice2.value = Math.round( parseInt( actualPrice.value ) * svaroDalinimas );
}

function addPrice( price )
{
    var actualPrice = document.getElementById('price');
    var actualPrice2 = document.getElementById('price2');
    actualPrice.value = parseInt( actualPrice.value ) + price - oldPrice;
    actualPrice2.value = Math.round( parseInt( actualPrice.value ) * svaroDalinimas );
    oldPrice = price;
}

function changeTransport( action )
{
    var actualPrice = document.getElementById('price');
    switch( action )
    {
        case('add'): actualPrice.value = parseInt( actualPrice.value ) + oldTransport; break;
        case('rem'): actualPrice.value = parseInt( actualPrice.value ) - oldTransport; break;
    }
    actualPrice2.value = Math.round( parseInt( actualPrice.value ) * svaroDalinimas );

}

function addTransport( price )
{
    addPrice( price );
    oldTransport = price;
}

function addAccomodation( price )
{
    var actualPrice = document.getElementById('price');
    var actualPrice2 = document.getElementById('price2');
    var dayCount = document.getElementById('nights');
    actualPrice.value = parseInt( actualPrice.value ) + (parseInt( dayCount.value ) * price) - oldAccomodation;
    actualPrice2.value = Math.round( parseInt( actualPrice.value ) * svaroDalinimas );
    oldAccomodation = parseInt( dayCount.value ) * price;
    accomodationPrice = price;
    updatePrices();
}


function changeNights()
{
    changeDepartDate();
    var actualPrice  = document.getElementById('price');
    var actualPrice2 = document.getElementById('price2');
    var dayCount     = document.getElementById('nights');
    
    actualPrice.value = parseInt( actualPrice.value ) + (parseInt( dayCount.value ) * accomodationPrice) - oldAccomodation;
    actualPrice2.value = Math.round( parseInt( actualPrice.value ) * svaroDalinimas );
    oldAccomodation = parseInt( dayCount.value ) * accomodationPrice;
}
    //
//function increaseNights()
//{
    //increaseInt( 'nights' );
//    
//    
//}

//function decreaseNights()
//{
//    decreaseInt( 'nights' );
//    changeDepartDate();
//    var actualPrice = document.getElementById('price');
//    var actualPrice2 = document.getElementById('price2');
//    var dayCount = document.getElementById('nights');
//    actualPrice.value = parseInt( actualPrice.value ) + (parseInt( dayCount.value ) * accomodationPrice) - oldAccomodation;
//    actualPrice2.value = Math.round( parseInt( actualPrice.value ) * svaroDalinimas );
//    oldAccomodation = parseInt( dayCount.value ) * accomodationPrice;
//}

function checkForm()
{
    var requiredName = document.getElementById('name');
    var requiredMail = document.getElementById('email');
    var requiredMobile = document.getElementById('mobile');
    var arriveTime = document.getElementById('arrivalTime');
    var departTime = document.getElementById('departureTime');

    if ( requiredName.value == '')
    {
        alert('Please enter Your name');
        requiredName.focus();
        return false;
    }

    if ( requiredMail.value == '')
    {
        alert('Please enter Your e-mail');
        requiredMail.focus();
        return false;
    }

    if ( requiredMobile.value == '')
    {
        alert('Please enter Your mobile phone');
        requiredMobile.focus();
        return false;
    }

    /*if ( document.getElementById('sutinku').checked == false )
    {
        alert('You must agree with terms and conditions');
        document.getElementById('sutinku').focus();
        return false;
    }*/

    return true;
}

function updatePrices(f)
{
    var priceField = document.getElementById('price');
    var actualPrice2 = document.getElementById('price2');
    var endPrice = parseInt( priceField.value );
    var noAccomodation = document.getElementById('nRequired1');

    var itemNames = new Array('nightTime[]', 'dayTime[]', 'Dining[]');

    if ( noAccomodation.checked == true ) firstChange = false;

    if ( firstChange == false )
    {
        for( a = 0; a < itemNames.length; a++)
        {
            var items = document.getElementsByName( itemNames[a] );
            var itemsCount = items.length;

            for (i=0; i < itemsCount; i++)
            {
                if ( items.item(i).checked == true )
                {
                    var id = items.item(i).value;
                    var priceItem = prices [ id ];

                    if ( noAccomodation.checked == true)
                    {
                        oldPrice = parseInt( priceItem[ 1 ] );
                        newPrice = parseInt( priceItem[ 2 ] );
                        firstChange = false;
                    } else {
                        oldPrice = parseInt( priceItem[ 2 ] );
                        newPrice = parseInt( priceItem[ 1 ] );
                        firstChange = true;
                    }
    //                alert('endPrice:' + endPrice + ' oldPrice:' + oldPrice + ' newPrice:' + newPrice );
                     endPrice = endPrice - oldPrice + newPrice;
                }
            }
        }
        priceField.value = endPrice;
        actualPrice2.value = Math.round( parseInt( priceField.value ) * svaroDalinimas );
    }
}
