
function debugToDiv ( oToDebug, sDivId, iIndent ) {
        document.getElementById( sDivId ).innerHTML += '<pre>' ; 
        for ( mProperty in oToDebug ) {
                var oMember = oToDebug[ mProperty ];
                var j = 0;
        
                for( j=0; j<iIndent; j++ ) {
                        document.getElementById( sDivId ).innerHTML += '        ';
                }
                if( typeof( oMember ) == 'object' ) {
                        document.getElementById( sDivId ).innerHTML += mProperty + ' (Object) <br />';
                        debugToDiv( oMember, sDivId, iIndent + 1 );
                } else {
                        //document.getElementById( sDivId ).innerHTML += oMember ;
                        //
                        document.getElementById( sDivId ).innerHTML +=( mProperty + ' => ' + oMember + '<br />' );
                }
        }
        document.getElementById( sDivId ).innerHTML += '</pre>' ; 
}



function sailingsearch()
{	
	var locationString = 'rejsy,strona-1.html?'; 
	
	if( document.getElementById('sailingregion').value != '' )
		locationString = locationString + 'region='+document.getElementById('sailingregion').value+'&' ; 
		
	if( document.getElementById('sailindate').value != '' )
		locationString = locationString +'date='+document.getElementById('sailindate').value  ;
				
	
	document.location = locationString; 	
}



function addToMyOffers(code)
{
		
	var exdate = new Date();
	expiredays = 366 ;
	 
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie="offer["+code+"]"+ "=" +escape(code)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString() +"; path=/");
	
	alert("Oferta dodana do schowka.");
}


function removeFromMyOffers(code)
{
	var exdate = new Date();
	expiredays = 366 ;
	 
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie="offer["+code+"]"+ "=0"+((expiredays==null) ? "" : ";expires="+exdate.toGMTString() +"; path=/");
	document.mForm.action="schowek.html";
	document.mForm.submit();		
	

}


function mailto(title, body , link)
{
	
	var subject = title ;
	var body_message = body + link; 


	var mailto_link = 'mailto:?subject='+subject+'&body='+body_message;

	win = window.open(mailto_link,'emailWindow');
	if (win && win.open &&!win.closed) win.close();

}

function pay()
{			
	document.mForm.action = "https://ssl.dotpay.pl";
	document.mForm.method = "POST";
	document.mForm.target = "_blank";
	
	document.mForm.submit();		
}	

function BusSearch()
{
	var oldMethod = document.mForm.method;
	var oldTarget = document.mForm.target;
	var oldAction = document.mForm.action;
	
		
	document.mForm.action = "http://sale.euroticket.pl/start.php?profile=radtur_comeon.pl_krosno_html&cnt=cts";
	document.mForm.method = "POST";
	document.mForm.target = "_blank";
	
	document.mForm.submit();
		
}	



var tabReviewBox = new Object();


function showReviewBox()
{
	if(document.getElementById('reviewBox').style.display=='none')
	{
		document.getElementById('reviewBox').style.display='inline';
		document.getElementById('reviewBoxImg').src='http://comeon.pl/xslt/comeon/graphics/gfx/gototop.gif';
	}
	else
	{	
		document.getElementById('reviewBoxImg').src='http://comeon.pl/xslt/comeon/graphics/gfx/gotobottom.gif';
		document.getElementById('reviewBox').style.display='none';
	}
}		


function ShowCalendarField(maxPerson)
{
	personCount = document.getElementById('personlist').options[document.getElementById('personlist').selectedIndex ].text ; 

	for (var t = 1 ; t <= maxPerson ; t++)
		document.getElementById('datepickerdiv'+t).style.display='none';
		
	for (var t = 1 ; t <= personCount ; t++)
		document.getElementById('datepickerdiv'+t).style.display='inline';
	
	document.getElementById('booking_personcount').value = document.getElementById('personlist').options[document.getElementById('personlist').selectedIndex ].text ;
	
	SelectOnlyAvailRooms();
	
	//SelectAvailRoom() ; 
	
}


function SelectOnlyAvailRooms()
{
	$(".roomtypebookingdatatmp").attr("disabled",true) ;
	$(".cl"+personCount).attr("disabled",false) ;
				
	for( var t = 0 ; t < $(".roomtypebookingdatatmp").length ; t++) {

		var roomCode = $(".roomtypebookingdatatmp")[t].id.substring(9,$(".roomtypebookingdatatmp")[t].id.length) ; 
		if( $("#roomtypeprice_"+roomCode).text() == '' )
		{
			$("#roomtype_"+roomCode).attr("disabled",true) ;
		}
	}
}


function AddLink(index,text,className)
{
	var PageList = new Object() ;
	
	PageList['IH'] = 'internethou'+'se.pl';
	PageList['PIT'] = 'pit.org'+'.pl/ind'+'ex.ph'+'p?co'+'m=catalog&id=726';
	PageList['facebook'] = 'facebook.com/comeonpl';
	PageList['blip'] = 'comeon.blip.pl';
	PageList['twitter'] = 'twitter.com/comeonpl';
	PageList['youtube'] = 'www.youtube.com/user/WwwComeOnPL';

//
	document.write("<"+"a hr" );
	document.write("e"+"f='ht" );
	document.write("t"+"p://" );
	document.write( PageList[ index ] );
		
	if( className != '' )
		document.write("' cla"+"ss='"+className+"' " );
	else
		document.write("' " );	
	

		
	document.write(' onclick="c'+'likcReporting(\'link\',\''+PageList[ index ]+'\', \'\');" ');	
		
	document.write(' re'+'l="n'+'ofol'+'low" ');
	document.write("><span>"+ text+ "</span><" );
	document.write("/a"+ ">" );
}

function SelectAvailRoom()
{
	personCount = document.getElementById('personlist').options[document.getElementById('personlist').selectedIndex ].text ; 
		
	SelectOnlyAvailRooms() ; 

	for( var t = 0 ; t < $(".roomtypebookingdatatmp").length ; t++) 
	{
		if( $(".roomtypebookingdatatmp")[t].disabled == false )
		{
			$(".roomtypebookingdatatmp")[t].checked = true; 
			
			var roomCode = $(".roomtypebookingdatatmp")[t].id.substring(9,$(".roomtypebookingdatatmp")[t].id.length) ; 
					
			$("#booking_roomtype").val(roomCode); 

			$.fn.selectAvailable();
					
			return ; 
		} 
	}
	
	
	alert('nie ma mozliwosci');
	
/*
	for( var t = 0 ; t < $(".roomtypebookingdatatmp").length ; t++) {
alert(t);
		if( $(".roomtypebookingdatatmp")[t].checked == true && $(".roomtypebookingdatatmp")[t].disabled == true )
		{
		
			for( var r = 0 ; r < $(".roomtypebookingdatatmp").length ; r++) 
			{
			
				if( $(".roomtypebookingdatatmp")[r].disabled == false )
				{
					$(".roomtypebookingdatatmp")[r].checked = true; 
					
					var roomCode = $(".roomtypebookingdatatmp")[r].id.substring(9,$(".roomtypebookingdatatmp")[r].id.length) ; 
										
					$("#booking_roomtype").val(roomCode); 

					$.fn.selectAvailable();
					
					return ; 
				}
			}
		}
	}
	*/
	
}



function submitForm(file,page)
{

	//if( document.getElementById('keyword') )
	//	document.getElementById('keyword').value = '' ;
 	
 	document.getElementById('calledpage').value = page ;
 	document.mForm.action=file;
 	
 	document.mForm.submit();
}


function submitSailingForm()
{	
 	document.mForm.submit();
}


function checkEnter(event,file,page )
{    	
	var keyword = urlencode( $("#keyword").val() ); 
	keyword = keyword.replace(/\+/gi, "-") ;

	$("#tmp_search_keyword").val(keyword); 
	
	if (event.keyCode==13){		
		searchKeyword(file,page);
	}
}


function searchKeyword(file,page)
{
	var keyword = $("#keyword").val(); 

	clikcReporting('link','keyword',keyword) ;
	
	keyword = urlencode(keyword) ; 
	keyword = keyword.replace(/\+/gi, "-") ;
	
	//alert(keyword +' - ' + page +' - '+ file ) ;
	
	$("#tmp_search_keyword").val(keyword); 

	if( keyword.length < 3 )
	{
		alert("Podana fraza powinna zawierać minimum 3 znaki") ;
		return ; 
	}
	else
	{		
		document.getElementById('calledpage').value = page ;
		document.mForm.action=file;
		document.mForm.submit();
	}
	
}



function urlencode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // %          note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
                             
    var histogram = {}, unicodeStr='', hexEscStr='';
    var ret = (str+'').toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urldecode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    histogram['\u00DC'] = '%DC';
    histogram['\u00FC'] = '%FC';
    histogram['\u00C4'] = '%D4';
    histogram['\u00E4'] = '%E4';
    histogram['\u00D6'] = '%D6';
    histogram['\u00F6'] = '%F6';
    histogram['\u00DF'] = '%DF';
    histogram['\u20AC'] = '%80';
    histogram['\u0081'] = '%81';
    histogram['\u201A'] = '%82';
    histogram['\u0192'] = '%83';
    histogram['\u201E'] = '%84';
    histogram['\u2026'] = '%85';
    histogram['\u2020'] = '%86';
    histogram['\u2021'] = '%87';
    histogram['\u02C6'] = '%88';
    histogram['\u2030'] = '%89';
    histogram['\u0160'] = '%8A';
    histogram['\u2039'] = '%8B';
    histogram['\u0152'] = '%8C';
    histogram['\u008D'] = '%8D';
    histogram['\u017D'] = '%8E';
    histogram['\u008F'] = '%8F';
    histogram['\u0090'] = '%90';
    histogram['\u2018'] = '%91';
    histogram['\u2019'] = '%92';
    histogram['\u201C'] = '%93';
    histogram['\u201D'] = '%94';
    histogram['\u2022'] = '%95';
    histogram['\u2013'] = '%96';
    histogram['\u2014'] = '%97';
    histogram['\u02DC'] = '%98';
    histogram['\u2122'] = '%99';
    histogram['\u0161'] = '%9A';
    histogram['\u203A'] = '%9B';
    histogram['\u0153'] = '%9C';
    histogram['\u009D'] = '%9D';
    histogram['\u017E'] = '%9E';
    histogram['\u0178'] = '%9F';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
 
    for (unicodeStr in histogram) {
        hexEscStr = histogram[unicodeStr];
        ret = replacer(unicodeStr, hexEscStr, ret); // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
}
function ShowRevieBox(boxId)
{
	//boxId
	
	var trTab = document.getElementsByTagName("tr");
    
    for (var i=0; i<trTab.length; i++)
    {
    	if (trTab[i].id.indexOf("reviewBox_"+boxId) == 0) 
      	{
      		if(trTab[i].style.display == 'none')
      			trTab[i].style.display = "";
      		else
      			trTab[i].style.display = "none";		
		}
	
	}
}


function ValidEmail(str) {

		var at="@" ; 
		var dot="." ; 
		var lat=str.indexOf(at) ; 
		var lstr=str.length ; 
		var ldot=str.indexOf(dot) ; 
		
		if ((str==null)||(str=="")){
		   alert( document.getElementById('invalidemailalert').value ) ;
		   return false
		}
			
		
		if (str.indexOf(at)==-1){
		   alert( document.getElementById('invalidemailalert').value ) ;
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert( document.getElementById('invalidemailalert').value )
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert( document.getElementById('invalidemailalert').value )
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert( document.getElementById('invalidemailalert').value )
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert( document.getElementById('invalidemailalert').value )
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert( document.getElementById('invalidemailalert').value )
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert( document.getElementById('invalidemailalert').value )
		    return false
		 }
		 
		 

 		 return true					
	}


function AddOrRemoveEmail(newsletermailid,action)
{
	newsletteraddress = document.getElementById(newsletermailid).value ; 
	
	if (ValidEmail(newsletteraddress))
	{
		var params 			= new Object();

		params['email']		= newsletteraddress ; 
			
		var ajax = new AjaxClient();
									
		ajax.onSuccess 	= function cbSuccess(response) {
			 
		if(response.result == 'emailexist')
			alert(document.getElementById('emailexistalert').value);
		else if(response.result == 'emaildontexist')
		{
			alert(document.getElementById('emaildontexistalert').value);
		}
		else
		{
			if(action == 'add')
			{
				alert(document.getElementById('emailaddedalert').value);
				document.getElementById(newsletermailid).value = '' ; 
			}
			else 
			{
			 	alert(document.getElementById('emailremovedalert').value);
			 	document.getElementById(newsletermailid).value = '' ; 
			}
		}
		
		};
		ajax.onLoading 	= function cbLoading() {};
		ajax.onError 	= function cbError( msg ) { alert(msg); };
			
		if(action == 'add')	
			ajax.call( document.getElementById('ajaxlib').value, 'GET', 'AjaxNewsletterService', 'addNewsletter', params );
			
		if(action == 'remove')
			ajax.call( document.getElementById('ajaxlib').value, 'GET', 'AjaxNewsletterService', 'deleteNewsletter', params );
	}	
}



function CheckOrder(action)
{
	document.mForm.action = action;
	//document.getElementById('new_user_check').value = 'yes' ;
	document.mForm.submit();
}


function ChangeTotalPrice()
{
	var totalPriceField = document.getElementById('totalPriceField').value ;

	var deliveryType = document.getElementById('order_deliverytype') ; 
	var deliveryId = deliveryType[deliveryType.selectedIndex].value ; 
	
	var tmpPrice = "deliveryPrices_"+deliveryId ; 
	var tmpName = "deliveryName_"+deliveryId ; 
	
	var deliveryPriceField = document.getElementById(tmpPrice).value ; 
	var deliveryNameField = document.getElementById(tmpName).value ; 
		 
	document.getElementById('deliveryTypeField').innerHTML = deliveryNameField ; 
	document.getElementById('deliveryPriceField').innerHTML = deliveryPriceField ;  
	
	document.getElementById('allPriceField').innerHTML = 1*totalPriceField + 1*deliveryPriceField ; 
}

function ChangeEndDate(date,endDateId)
{
	selectedDate = new Date() ; 
	selectedDate.setDate(date.substring(8,10)) ; 
	selectedDate.setMonth(date.substring(5,7)-1) ; 
	selectedDate.setYear(date.substring(0,4)) ;
		
	var newDateTmp = selectedDate.getTime()*1 + 14*60*60*24*1000 ; 
		
		
	var newDate = new Date(newDateTmp);
	

	tmpYear = newDate.getYear() ; 
		
	if(1*tmpYear<2000)
	{
		tmpYear = newDate.getYear()-100 ;
		if(1*tmpYear<10)
			tmpYear = "200"+tmpYear;
		else
			tmpYear = "20"+tmpYear;
	}
	else
		tmpYear = newDate.getYear() ;
	
	tmpMonth = 1*newDate.getMonth()+1 ; 
	
	if(tmpMonth<10)
		tmpMonth = "0"+tmpMonth;
	
	tmpDay = newDate.getDate() ;  ; 
		
	if(tmpDay<10)
		tmpDay = "0"+tmpDay;
			
	document.getElementById(endDateId).value = tmpYear+'-'+tmpMonth+'-'+tmpDay; 			
}





function findElementPosition(obj) {

	var curleft = curtop = 0;
	if (obj.offsetParent) {
	  curleft = obj.offsetLeft
	  curtop = obj.offsetTop
	  while (obj = obj.offsetParent) {
	   curleft += obj.offsetLeft
	   curtop += obj.offsetTop
	  }
	}
	
	var param = new Object ();
	
	param['curleft']  = curleft ; 
	param['curtop']  = curtop ; 
	
	return param;
}

function ReloadCart(action)
{
        document.mForm.action = action;
        document.mForm.submit();
}


function displayContacBox()
{
	pos = findElementPosition(document.getElementById('contactTable'));
	
	document.getElementById('divcontactbox').style.left = pos['curleft'] + 30;
	document.getElementById('divcontactbox').style.top 	= pos['curtop']  + 30;
	
	document.getElementById('divcontactbox').style.visibility='visible';
}


function currencyRecalculate()
{


	var quant 		= 1*document.getElementById('quant').value.replace(',','.') ; 
	var currFrom 	= 1*document.getElementById('currFrom').value.replace(',','.') ; 
	var currTo 		= 1*document.getElementById('currTo').value.replace(',','.') ; 

	var oCurrFrom	= document.getElementById('currFrom') ; 
	var oCurrTo		= document.getElementById('currTo') ; 	



	if(!IsNumeric(quant) || isNaN(quant) )
	{
		quant = 100 ; 	
		document.getElementById('quant').value  = 100 ; 
	}
		
	if(!IsNumeric(currFrom)) 
		currFrom = 1 ;
		
	if(!IsNumeric(currTo)) 
		currTo = 1 ;
	
	result = (quant*currFrom)/currTo ;
	result = Math.ceil(10000*result)/10000 ;  
	
	document.getElementById('currencyresult').innerHTML = quant + ' ' + oCurrFrom.options[oCurrFrom.selectedIndex].text.substring(0,3)+ ' = ' + result + ' '+ oCurrTo.options[oCurrTo.selectedIndex].text.substring(0,3); 
	document.getElementById('currencydiv').style.display = 'inline' ;
	
	
	//alert(result);

}



function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }




function SearchAdvancedSetTransport(starttype)
{
	document.getElementById('sa_tripoffersearchbox').style.display = 'none' ;
	document.getElementById('sa_busoffersearchbox').style.display = 'none' ;
	document.getElementById('sa_hoteloffersearchbox').style.display = 'none' ;

	if( document.getElementById('sa_transport_flight').checked==true )
	{
		document.getElementById('sa_tripoffersearchbox').style.display = 'inline' ;
	}
	
	if(document.getElementById('sa_transport_bus').checked==true )
	{
		document.getElementById('sa_busoffersearchbox').style.display = 'inline' ;
	}
	
	if(document.getElementById('sa_transport_own').checked==true )
	{
		document.getElementById('sa_hoteloffersearchbox').style.display = 'inline' ;
	}
	
	
	document.getElementById('sa_searchType').value=starttype; 
		
}


function PassValue(rating,id)
{
	updateReviewBox(id);
  	document.getElementById('add_review_'+id).value = rating; 
}


function RecalculationImageSize(imgId,maxWidth,maxHeight)
{
       imgObj 	= document.getElementById("mainimage");

       imageWidth   = document.getElementById('imageWidth['+imgId+']').value ;
       imageHeight 	= document.getElementById('imageHeight['+imgId+']').value ;

       var scaleValue	= 100 ;
       var newWidth     = 0 ;
       var newHeight	= 0 ;

       if(imageWidth < maxWidth && imageHeight < maxHeight) // mniejszy niz ramka
       {
            newWidth                = imageWidth  ;
        	newHeight               = imageHeight ;
       }
       else    // ktorys z rozmiarow iekszy
       {
               if( (imageWidth/imageHeight) < (maxWidth/maxHeight))
               {
                       if(imageWidth > imageHeight)
                               scale = Math.floor(maxHeight*scaleValue/imageHeight)/scaleValue ;
                       else
                               scale = Math.floor(maxHeight*scaleValue/imageHeight)/scaleValue ;
               }
               else
               {
                       if(imageWidth > imageHeight)
                               scale = Math.floor(maxWidth*scaleValue/imageWidth)/scaleValue ;
                       else
                               scale = Math.floor(maxHeight*scaleValue/imageHeight)/scaleValue ;
               }
               newWidth        = Math.ceil(imageWidth  * scale );
               newHeight       = Math.ceil(imageHeight * scale );
       }

      	//alert( imageWidth  +' x '+ imageHeight +' --  ' +      newWidth + ' x ' + newHeight );
       
       imgObj.style.width 	=  newWidth+'px';
       imgObj.style.height 	=  newHeight+'px';

}


function ShowNext()
{
	var imageCount 		= document.getElementById('imageCount').value ; 
	var imageCurrently 	= document.getElementById('imageCurrently').value ; 
	
	if( 1*imageCurrently+1 > imageCount ) 
		imageCurrently = 1 ; 
	else
		imageCurrently = 1*imageCurrently+1 ; 
		
	document.getElementById('imageCurrently').value	= imageCurrently ;
	
	ChangeImage(imageCurrently) ; 
}



function ShowPrevious()
{
	var imageCount 		= document.getElementById('imageCount').value ; 
	var imageCurrently 	= document.getElementById('imageCurrently').value ; 
	
	if( 1*imageCurrently-1 < 1 ) 
		imageCurrently = imageCount ; 
	else
		imageCurrently = 1*imageCurrently-1 ; 
		
	document.getElementById('imageCurrently').value	= imageCurrently ;
	
	ChangeImage(imageCurrently) ; 
}



function ShowFirstImage()
{
	document.getElementById('imageCurrently').value	= 1 ;
	ChangeImage(1) ;
}



function ShowLastImage()
{
	var imageCount = document.getElementById('imageCount').value ; 
	document.getElementById('imageCurrently').value	= imageCount ;
	ChangeImage(imageCount) ;
}



function CallSlideShow()
{
	if(document.getElementById('slideFlag').value == 0)
	{
		document.getElementById('slideFlag').value = 1 ;
		SlideShow() ;
	}
	else
	{
		document.getElementById('slideFlag').value = 0 ;
	}
}



function ShowImage(id)
{
	document.getElementById('imageCurrently').value	= id ;
    ChangeImage(id) ; 
}


function ChangeImage(id)
{
  RecalculationImageSize(id,250,185) ; 
  document.getElementById('mainimage').src = document.getElementById('imageList['+id+']').value ;
}

function SlideShow() 
{
	if(document.getElementById('slideFlag').value == 0)
		return ;

	var delay = 1; 
	
	ShowNext();
	
	setTimeout("SlideShow()",delay*2000);
}



var MonthName = new Array(12);
MonthName[0]	= "Styczen";
MonthName[1]	= "Luty";
MonthName[2]	= "Marzec";
MonthName[3]	= "Kwiecien";
MonthName[4]	= "Maj";
MonthName[5]	= "Czerwiec";
MonthName[6]	= "Lipiec";
MonthName[7]	= "Sierpien";
MonthName[8]	= "Wrzesien";
MonthName[9]	= "Pazdziernik";
MonthName[10]	= "Listopad";
MonthName[11]	= "Grudzien";

function setDateOnForm(unixTime,daySelectId,MonthSelectId,oldDate)
{
	//alert(unixTime + ' '+ daySelectId+ ' '+MonthSelectId+ ' '+oldDate  ) ; 
	
	if( document.getElementById(daySelectId) || document.getElementById(MonthSelectId) )
	{
		
		
	var lastDay = document.getElementById(daySelectId).value ; 
	
	if(oldDate != undefined && oldDate !='')
	{
		selectedDate = new Date() ; 

		selectedDate.setDate(oldDate.substring(8,10)) ; 
		selectedDate.setMonth(oldDate.substring(5,7)-1) ; 
		selectedDate.setYear(oldDate.substring(0,4)) ;
	}
	else
	{

		if(unixTime==0)
			selectedDate 	= new Date();
		else 
			selectedDate 	= new Date(1*unixTime);
	}
	
	today			= new Date();
	
	startYear		= today.getYear()
	startMonth 		= today.getMonth();
	
	if(today.getMonth()+"_"+today.getYear() == selectedDate.getMonth()+"_"+selectedDate.getYear())
	{

		startDay 		= today.getDate();
		endDay 			= GetDayCountForMonth(today.getMonth(),today.getYear());
	}
	else
	{

		startDay 		= 1 ;
		endDay 			= GetDayCountForMonth(selectedDate.getMonth(),selectedDate.getYear());	
	}
	
	var dayselect = document.getElementById(daySelectId);	
				
	for(r = 0 ; r <= dayselect.options.length; r++)
		dayselect.options[r] = null ; 

	dayselect.options.length = 0 ;
	
	var monthselect = document.getElementById(MonthSelectId);	
				
	for(r = 0 ; r <= monthselect.options.length; r++)
		monthselect.options[r] = null ; 

	monthselect.options.length = 0 ;
	
	var i = 0 ; 
	
	for(var t = startMonth ; t <= startMonth + 10 ; t++)
	{
		tmpDate = new Date() ;
		
		if(startYear<2000)
		{
			tmpYear = (startYear+Math.floor(t/12))-100 ;
			
			if(1*tmpYear<10)
				tmpYear = "200"+tmpYear;
			else
				tmpYear = "20"+tmpYear;
		}
		else
				tmpYear = (startYear+Math.floor(t/12)) ;

		tmpDate.setDate(1);
		tmpDate.setMonth(t%12);
		tmpDate.setYear(tmpYear);
		
		monthselect.options[i]	= new Option(MonthName[t%12]+ ' ' + tmpYear , tmpDate.getTime() );	
	
		if( selectedDate.getMonth() == t%12 && selectedDate.getYear() == (startYear+Math.floor(t/12)) )
			monthselect.options[i].selected = true ; 

		i++;
	}
	

	var i = 0 ; 
	
	for(var t = startDay ; t <= endDay; t++)
	{
		dayselect.options[i]	= new Option(t,t);	
		
		if( selectedDate.getDate() == t  || (t ==  1*lastDay && selectedDate.getDate() == 1 ))
		{
			//alert(selectedDate.getDate() +' '+ t  +' '+ 1*lastDay);
			dayselect.options[i].selected = true ;
		}
		i++;
	}	
	
	}
	
	
	if( daySelectId=='tripofferdayselect' || MonthSelectId=='tripoffermonthselect' ||  daySelectId=='__tripofferenddayselect' || MonthSelectId=='__tripofferendmonthselect' ) 
	{	
		
		if( oldDate )
		{
			selectedDate = new Date() ; 
			selectedDate.setDate(oldDate.substring(8,10)) ; 
			selectedDate.setMonth(oldDate.substring(5,7)-1) ; 
			selectedDate.setYear(oldDate.substring(0,4)) ;
			
			unixTime = selectedDate.getTime() ; 
		}
		
		setDateOnForm(unixTime + 60*60*24*7*1000,'tripofferenddayselect','tripofferendmonthselect','');
	}
	
	if( daySelectId=='busofferdayselect' || MonthSelectId=='busoffermonthselect' ||  daySelectId=='__busofferenddayselect' || MonthSelectId=='__busofferendmonthselect' ) 
	{	
		
		if( oldDate )
		{
			selectedDate = new Date() ; 
			selectedDate.setDate(oldDate.substring(8,10)) ; 
			selectedDate.setMonth(oldDate.substring(5,7)-1) ; 
			selectedDate.setYear(oldDate.substring(0,4)) ;
			
			unixTime = selectedDate.getTime() ; 
		}
		
		setDateOnForm(unixTime + 60*60*24*7*1000,'busofferenddayselect','busofferendmonthselect','');
	}
	
	if( daySelectId=='hotelofferdayselect' || MonthSelectId=='hoteloffermonthselect' ||  daySelectId=='__hotelofferenddayselect' || MonthSelectId=='__hotelofferendmonthselect' ) 
	{	
		
		if( oldDate )
		{
			selectedDate = new Date() ; 
			selectedDate.setDate(oldDate.substring(8,10)) ; 
			selectedDate.setMonth(oldDate.substring(5,7)-1) ; 
			selectedDate.setYear(oldDate.substring(0,4)) ;
			
			unixTime = selectedDate.getTime() ; 
		}
		
		setDateOnForm(unixTime + 60*60*24*7*1000,'hotelofferenddayselect','hotelofferendmonthselect','');
	}
	
	if( daySelectId=='allofferdayselect' || MonthSelectId=='alloffermonthselect' ||  daySelectId=='__allofferenddayselect' || MonthSelectId=='__allofferendmonthselect' ) 
	{	
		
		if( oldDate )
		{
			selectedDate = new Date() ; 
			selectedDate.setDate(oldDate.substring(8,10)) ; 
			selectedDate.setMonth(oldDate.substring(5,7)-1) ; 
			selectedDate.setYear(oldDate.substring(0,4)) ;
			
			unixTime = selectedDate.getTime() ; 
		}
		
		setDateOnForm(unixTime + 60*60*24*7*1000,'allofferenddayselect','allofferendmonthselect','');
	}
}


function setDateOnField(fieldId,daySelectId,MonthSelectId)
{
	tmpdate	= new Date(1*document.getElementById(MonthSelectId).value);
	
	tmpYear = tmpdate.getYear() ; 
		
	if(1*tmpYear<2000)
	{
		tmpYear = tmpdate.getYear()-100 ;
		if(1*tmpYear<10)
			tmpYear = "200"+tmpYear;
		else
			tmpYear = "20"+tmpYear;
	}
	else
		tmpYear = tmpdate.getYear() ;
	
	tmpMonth = 1*tmpdate.getMonth()+1 ; 
	
	if(tmpMonth<10)
		tmpMonth = "0"+tmpMonth;
	
	tmpDay = document.getElementById(daySelectId).value ; 
		
	if(tmpDay<10)
		tmpDay = "0"+tmpDay;
			
	document.getElementById(fieldId).value = tmpYear+'-'+tmpMonth+'-'+tmpDay ; 
	
	if( daySelectId=='tripofferdayselect' ) 
		setDateOnForm('','__tripofferenddayselect','__tripofferendmonthselect',tmpYear+'-'+tmpMonth+'-'+tmpDay);

	if( daySelectId=='busofferdayselect' ) 
		setDateOnForm('','__busofferenddayselect','__busofferendmonthselect',tmpYear+'-'+tmpMonth+'-'+tmpDay);

	if( daySelectId=='hotelofferdayselect' ) 
		setDateOnForm('','__hotelofferenddayselect','__hotelofferendmonthselect',tmpYear+'-'+tmpMonth+'-'+tmpDay);

	if( daySelectId=='allofferdayselect' ) 
		setDateOnForm('','__allofferenddayselect','__allofferendmonthselect',tmpYear+'-'+tmpMonth+'-'+tmpDay);
	
}




function GetDayCountForMonth(month,year)
{	
	tmpdate	= new Date();	
	
	tmpdate.setDate(1) ; 
	tmpdate.setMonth(month) ; 
	tmpdate.setYear(year) ; 			
	
	CurUnixDate =  Math.ceil(tmpdate.getTime()/1000) ;
	
	var dayCount = 0 ; 
	
	for(var r = 27 ; r < 31 ; r ++)
	{
		unixTime = (CurUnixDate + r * 60*60*24)*1000 ; 
		
		day = new Date(unixTime) ;		
		
		if( month != day.getMonth())
			break ; 
		else
			dayCount = day.getDate() ; 
	}		
	
	return dayCount ;	
}
	









function ShowBirthdayField(id)
{
	//alert(selectedIndex);
	if( document.getElementById('bookingOnline').value == 1 )
		return ; 
	 
	
	if(document.getElementById('booking_person['+id+'][type]').value=="C")
	{
		document.getElementById('childbirthdayfield['+id+']').style.visibility = 'visible' ; 
		document.getElementById('childbirthmonthfield['+id+']').style.visibility = 'visible' ; 
		document.getElementById('childbirthyearfield['+id+']').style.visibility = 'visible' ; 
	}
	else
	{

		document.getElementById('childbirthdayfield['+id+']').style.visibility = 'hidden' ; 
		document.getElementById('childbirthmonthfield['+id+']').style.visibility = 'hidden' ; 
		document.getElementById('childbirthyearfield['+id+']').style.visibility = 'hidden' ; 
	}
}	

function ChoseDifferentRoom(link)
{
	document.mForm.action = link;
}

function ShowSeearchBox(boxId)
{
	if(boxId == '') return ; 
	
	document.getElementById('tripoffersearchbox').style.display='none' ; 
	document.getElementById('hoteloffersearchbox').style.display='none' ;
	
	document.getElementById('tripoffersearchboxbackground').className	=	'noActiveMenu';
	document.getElementById('hoteloffersearchboxbackground').className	=	'noActiveMenu';
	
	
	document.getElementById(boxId).style.display='inline' ; 
	document.getElementById(boxId+'background').className	=	'activeMenu';
	
}


function ShowTripMoreSearchDetail()
{
	if(document.getElementById('tripmoresearchdetail').style.display=='inline')
		document.getElementById('tripmoresearchdetail').style.display='none';
	else
		document.getElementById('tripmoresearchdetail').style.display='inline';
}


function ShowCalendarWindow(path,fieldName,type,daySelectId,monthSelectId)
{
	window.open(path+'controlers/ModuleCalendar/calendar.inc.php?fieldName='+fieldName+'&type='+type+'&daySelectId='+daySelectId+'&monthSelectId='+monthSelectId+'', 'Calendar', 'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,fullscreen=no,channelmode=no,width=180,height=150,top=450,left=730') ;
}

function ShowConditionWindow(path)
{
	window.open(path+'controlers/ModuleCondition/condition.inc.php', 'Calendar', 'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,fullscreen=no,channelmode=no,width=700,height=700,top=250,left=250') ;
}

function ShowChildData(obj)
{
	if(obj.selectedIndex == 0)
	{
		document.getElementById('childdata[1]').style.display = 'none';
		document.getElementById('childdata[2]').style.display = 'none';
	}
	
	if(obj.selectedIndex == 1)
	{
		document.getElementById('childdata[1]').style.display = 'inline';
		document.getElementById('childdata[2]').style.display = 'none';
	}
	
	if(obj.selectedIndex == 2)
	{
		document.getElementById('childdata[1]').style.display = 'inline';
		document.getElementById('childdata[2]').style.display = 'inline';
	}
}

function calendarSelectFunction(unixTime,fieldName,type,daySelectId,monthSelectId)
{
	var currentDate = new Date() ; 
	var newDate ; 
	
	currentDate.setTime(unixTime*1000)
	
	var day 	= currentDate.getDate() ; 
	var mounth 	= currentDate.getMonth()+1 ;
	var year 	= currentDate.getFullYear() ;
	
	if(day < 10)
		day = '0'+day;
	
	if(mounth < 10) 
		mounth = '0'+mounth;

	switch(type)
	{
		case 'unix':
			newDate = unixTime ;
		break ;
		case 'd.m.Y':
			newDate = day+'.'+mounth+'.'+year;
		break ;
		case 'd-m-Y':
			newDate = day+'-'+mounth+'-'+year;
		break ;
		case 'Y.m.d':
			newDate = year+'.'+mounth+'.'+day;
		break ;
		case 'Y-m-d':
			newDate = year+'-'+mounth+'-'+day;
		break ;
		default : 
			newDate = day+'.'+mounth+'.'+year;
		
	}
	
	switch(fieldName)
	{
		case 'tripoffer_search_startdate' :			
			setDateOnForm(unixTime*1000,daySelectId,monthSelectId);			
		break ; 
		case 'tripoffer_search_enddatebefore' :
			setDateOnForm(unixTime*1000,daySelectId,monthSelectId);
		break ; 
		case 'busoffer_search_startdate' :
			setDateOnForm(unixTime*1000,daySelectId,monthSelectId);
		break ;
		case 'busoffer_search_enddatebefore' :
			setDateOnForm(unixTime*1000,daySelectId,monthSelectId);
		break ; 
		case 'hoteloffer_search_startdate' :
			setDateOnForm(unixTime*1000,daySelectId,monthSelectId);
		break ; 
		case 'hoteloffer_search_enddatebefore' :
			setDateOnForm(unixTime*1000,daySelectId,monthSelectId);
		break ;
	
	}
	
	
	document.getElementById(fieldName).value = newDate ; 
	
	
	
}



function Search(action)
{
	document.mForm.action = window.location+action;
	document.mForm.submit();	
}


function SubmitAction(action)
{
	document.mForm.action = action;
	document.mForm.submit();
}



function ReloadPage(action)
{
	document.getElementById('myaction').value = action ;
	document.mForm.submit();	
}



function AjaxClient() {

	this.response = '';
	
	this.error = '';

	this.onSuccess = 	function () {
							alert( 'Please override onSuccess callback.' );
						};
	this.onLoading = 	function () {
							alert( 'Please override onLoading callback.' );
						};
	this.onError = 		function ( err) {
							alert( err );
						};
	this.call = 		function( uri, method, serverClass, serverMethod, params ) {
							uri += '?__serverClass=' + serverClass + '&__serverMethod=' + serverMethod;
							for ( property in params ) {
								uri += '&' + property + '=' + params[ property ];
							}
									var selfReference = this;
							this.http.open( method, uri );
							this.http.onreadystatechange = function(){AJAX_stateHandler(selfReference );}
							this.http.send( null );
							/* handling for POST method
							this.http.abort;
							this.http.open('post',  'back_end.php');
							this.http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
							this.http.send('arg1=val1&arg2=val2&arg3=val3');
							*/							
						};
	
	this.createRequestObject = 	function () {
									var request_o; //declare the variable to hold the object.
									var browser = navigator.appName; //find the browser name
									if( browser == "Microsoft Internet Explorer" ){
										/* Create the object using MSIE's method */
										request_o = new ActiveXObject( "Microsoft.XMLHTTP" );
									}else{
										/* Create the object using other browser's method */
										request_o = new XMLHttpRequest();
									}
									return request_o; //return the object
								};

	this.http = this.createRequestObject(); 						

}

function AJAX_stateHandler(client) {
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	//debugToDiv( client.http.responseText, 'divId', 0 );

	if( client.http.readyState == 4 ){ 
		var response = '';
		
		//debugToDiv(client.http.responseText,'print',0);
		if(client.http.responseText!= '')
			eval("response = " + client.http.responseText);
		else 
			return ; 
			
		if( client.http.status != 200 ) {
			client.onError( 'HTTP Error, received status ' + client.http.status + ' instead of expected 200' );
		} else if( response[ '__errorString' ] != null ) {
			client.onError( response[ '__errorString' ] );
		} else {
			client.onSuccess( response );
		}
	} else if( client.http.readyState == 1 ) {
		client.onLoading();
	}
}



function clikcReporting( type, value, description )
{

	var url = "http://"+document.domain+"/json.php?__serverClass=Statistic&__serverMethod=AddClickStatistic";	
	var params = new Object() ;

	params['type']		= type ; 
	params['objectId']	= value ; 
	params['description']	= description ; 
	
	$.getJSON(url,params,function(data){	
	}); 	
}
