
/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

function clearTextInput(inputToClear,stringToClear){
	if(inputToClear.value==stringToClear)
		inputToClear.value='';
	inputToClear.style.color='#55636A';
}

function showlayer(elemToHighlight){
	//alert(elemToHighlight);
	//elemToHighlight.style.background-color='red';
}
function hidelayer(elemToHighlight){
	//elemToHighlight.style.background-color='white';
}

function setInputText(spanId,key){
	var textArray = new Array()
	textArray[0]='';
	textArray[1]='Site name:';
	textArray[2]='Search engine name:';
	textArray[3]='Tip de publicitate(pliante, bannere etc):';
	textArray[4]='Detalii:';
	document.getElementById(spanId).innerHTML = textArray[key];
	if(key>0)	
		document.getElementById('user_referrerText').style.display='block';
	else{
		document.getElementById('user_referrerText').style.display='none';
	}
	document.getElementById('user_referrerText').value='';
	
}

function makeCalendar(className,startArray, endArray){
	 for(j=0;j<startArray.length;j++){
		var stDay = startArray[j];
		var calendStDay = document.getElementById('day_'+stDay.getDate()+'_'+(stDay.getMonth()+1)+'_'+stDay.getFullYear());
		if(calendStDay!=null) {
			if( calendStDay.className=='reservedCalendDayStop' || calendStDay.className=='weekendreservedCalendDayStop' || calendStDay.className=='freeCalendDayStop' || calendStDay.className=='weekendfreeCalendDayStop')
			{
				if(calendStDay.className=='freeCalendDayStop') calendStDay.className = 'reservedCalendDayEndStart';
				if(calendStDay.className=='weekendfreeCalendDayStop') calendStDay.className = 'weekendreservedCalendDayEndStart';

				if(calendStDay.className=='reservedCalendDayStop') calendStDay.className = 'freeCalendDayEndStart';
				if(calendStDay.className=='weekendreservedCalendDayStop') calendStDay.className = 'weekendfreeCalendDayEndStart';
			}
			else
			{
				if(stDay.getDay()==0 || stDay.getDay()==6)
					calendStDay.className = 'weekend'+className;
				else
					calendStDay.className = className;
				calendStDay.className +='Start';
			}
		}

		if(endArray.length>0 && endArray[j]!=null){
			var endDay = endArray[j];
			var calendEndDay = document.getElementById('day_'+endDay.getDate()+'_'+(endDay.getMonth()+1)+'_'+endDay.getFullYear());
			if(calendEndDay!=null) {
				if( calendEndDay.className=='reservedCalendDayStart' || calendEndDay.className=='weekendreservedCalendDayStart' || calendEndDay.className=='freeCalendDayStart' || calendEndDay.className=='weekendfreeCalendDayStart')
				{
					if(calendEndDay.className=='reservedCalendDayStart') calendEndDay.className = 'reservedCalendDayEndStart';
					if(calendEndDay.className=='weekendreservedCalendDayStart') calendEndDay.className = 'weekendreservedCalendDayEndStart';

					if(calendEndDay.className=='freeCalendDayStart') calendEndDay.className = 'freeCalendDayEndStart';
					if(calendEndDay.className=='weekendfreeCalendDayStart') calendEndDay.className = 'weekendfreeCalendDayEndStart';
				}
				else
				{
					if(endDay.getDay()==0 || endDay.getDay()==6)
						calendEndDay.className = 'weekend'+className;
					else
						calendEndDay.className = className;
					calendEndDay.className += 'Stop';
				}
			}
						
			var diff = endDay - stDay;
			if(diff<0) {
				var temp = Date();
				temp = startArray[j];
				startArray[j] = endArray[j];
				endArray[j] = temp;
				
				stDay = startArray[j]
				endDay = endArray[j]
				diff = stDay - endDay;
			}
			
			var day_diff = Math.ceil(diff/(1000*60*60*24));
  			var locDay = new Date(stDay.getFullYear(),stDay.getMonth(),stDay.getDate());
			locDay.setTime(Date.UTC(stDay.getFullYear(),stDay.getMonth(),stDay.getDate()));
			for (d=1;d<day_diff;d++){
				locDay.setDate(locDay.getDate() + 1); 
				//locDay.setTime(Date.UTC(locDay.getFullYear(),locDay.getMonth(),locDay.getDate()+1));
				var calendBetweenDay = document.getElementById('day_'+locDay.getDate()+'_'+(locDay.getMonth()+1)+'_'+locDay.getFullYear());
				if(calendBetweenDay!=null) {
					if(locDay.getDay()==0 || locDay.getDay()==6){
						calendBetweenDay.className = 'weekend'+className;
					}
					else{
						calendBetweenDay.className = className;
					}
				}
			}
		}
	}
}
function test(){
	alert('test');
}
function clearCalendar(startYear,startMonth,startDay,days){
	 for(j=0;j<startDates.length;j++){
		var stDay = startDates[j];
		var calendStDay = document.getElementById('day_'+stDay.getDate()+'_'+(stDay.getMonth()+1)+'_'+stDay.getFullYear());
		if(calendStDay!=null){
			if(stDay.getDay()==0 || stDay.getDay()==6)
				calendStDay.className = 'weekendunselCalendDay';
			else
				calendStDay.className = 'unselCalendDay';
		}

		if(endDates.length>0 && endDates[j]!=null){
			var endDay = endDates[j];
			var calendEndDay = document.getElementById('day_'+endDay.getDate()+'_'+(endDay.getMonth()+1)+'_'+endDay.getFullYear());
			if(calendEndDay!=null) {
				if(endDay.getDay()==0 || endDay.getDay()==6)
					calendEndDay.className = 'weekendunselCalendDay';
				else
					calendEndDay.className = 'unselCalendDay';
			}
						
			var diff = endDay - stDay;
			if(diff<0) {
				var temp = Date();
				temp = startDates[j];
				startDates[j] = endDates[j];
				endDates[j] = temp;
				
				stDay = startDates[j]
				endDay = endDates[j]
				diff = stDay - endDay;
				drawCalendar();
			}
			
			var day_diff = Math.ceil(diff/(1000*60*60*24));
  			var locDay = new Date(stDay.getFullYear(),stDay.getMonth(),stDay.getDate());
			locDay.setTime(Date.UTC(stDay.getFullYear(),stDay.getMonth(),stDay.getDate()));
			for (d=1;d<day_diff;d++){
				//locDay = stDay;
				locDay.setDate(locDay.getDate() + 1); 
				var calendBetweenDay = document.getElementById('day_'+locDay.getDate()+'_'+(locDay.getMonth()+1)+'_'+locDay.getFullYear());
				if(calendBetweenDay!=null) {
					if(locDay.getDay()==0 || locDay.getDay()==6)
						calendBetweenDay.className = 'weekendunselCalendDay';
					else
						calendBetweenDay.className = 'unselCalendDay';
				}
			}
		}
	}
	makeCalendar('reservedCalendDay',originalBookedStartDates, originalBookedEndDates);
	makeCalendar('freeCalendDay',originalFreeStartDates, originalFreeEndDates);
	startDates=new Array();
	endDates=new Array();
}

function writeIntoRequest(){
	var result = '';
	for(i=0;i<startDates.length;i++){
		if(startDates[i]!=null && endDates[i]!=null)
			result += '<input type="hidden" name="selDates[]" value="'+startDates[i].getDate()+'|'+startDates[i].getMonth()+'|'+startDates[i].getFullYear()+'+'+endDates[i].getDate()+'|'+endDates[i].getMonth()+'|'+endDates[i].getFullYear()+'" />';
	}
	document.getElementById('request').innerHTML = result;
	return true;
}


startDates=new Array();
endDates=new Array();
startDate = new Date(0000,00,00);
endDate = new Date(0000,00,00);
i=0;
function setDate(day,month,year){
	
	if(i==0){
		startDate = new Date(year,month-1,day);
		startDate.setTime(Date.UTC(year,month-1,day));
		startDates.push(startDate);
		startDate = new Date(0000,00,00);
		i=1;
		//
	}
	else{
		endDate = new Date(year,month-1,day);
		endDate.setTime(Date.UTC(year,month-1,day));
		endDates.push(endDate);
		endDate = new Date(0000,00,00);
		i=0;
	}
	drawCalendar();
}
function drawCalendar(){
	 for(j=0;j<startDates.length;j++){
		var stDay = startDates[j];
		var calendStDay = document.getElementById('day_'+stDay.getDate()+'_'+(stDay.getMonth()+1)+'_'+stDay.getFullYear());
		if(calendStDay!=null) {
			if(stDay.getDay()==0 || stDay.getDay()==6)
				calendStDay.className = 'weekendfirstCalendDay';
			else
				calendStDay.className = 'firstCalendDay';
			//calendStDay.className = 'firstCalendDay';
		}

		if(endDates.length>0 && endDates[j]!=null){
			var endDay = endDates[j];
			var calendEndDay = document.getElementById('day_'+endDay.getDate()+'_'+(endDay.getMonth()+1)+'_'+endDay.getFullYear());
			if(calendEndDay!=null) {
				if(endDay.getDay()==0 || endDay.getDay()==6)
					calendEndDay.className = 'weekendlastCalendDay';
				else
					calendEndDay.className = 'lastCalendDay';
			}
			
			
			var diff = endDay - stDay;
			if(diff<0) {
				var temp = Date();
				temp = startDates[j];
				startDates[j] = endDates[j];
				endDates[j] = temp;
				
				stDay = startDates[j]
				endDay = endDates[j]
				diff = stDay - endDay;
				drawCalendar();
			}
			
			var day_diff = Math.ceil(diff/(1000*60*60*24));
  			var locDay = new Date(stDay.getFullYear(),stDay.getMonth(),stDay.getDate());
			locDay.setTime(Date.UTC(stDay.getFullYear(),stDay.getMonth(),stDay.getDate()));
			for (d=1;d<day_diff;d++){
				//locDay = stDay;
				locDay.setDate(locDay.getDate() + 1); 
				var calendBetweenDay = document.getElementById('day_'+locDay.getDate()+'_'+(locDay.getMonth()+1)+'_'+locDay.getFullYear());
				if(calendBetweenDay!=null) {
					calendBetweenDay.className = 'betweenCalendDay';
				}
			}
		}
	} 
}

function updatePrice(priceSpanId,selValueId,prices,disconts,price,pricePromo){
	//alert(priceSpanId+' '+selValueId+' '+prices+' '+values+' '+price+' '+pricePromo);
	//alert(prices[selValueId]);
	if(prices[selValueId]==null) {
		document.getElementById(priceSpanId).innerHTML=0;
		return true;
	}

	var pr=0;
	
	if(pricePromo>0)
		pr=prices[selValueId]*pricePromo;
	else
		pr=prices[selValueId]*price;
		
	if(disconts[selValueId]>0) pr = pr-(disconts[selValueId]*pr/100);

	document.getElementById(priceSpanId).innerHTML= pr;
}

function openWindow(url,width,height) {
	if(width==null) width = 900;
	if(height==null) height = 600;
  popupWin = window.open(url, 'remote',  'menubar=yes,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,dependent,width='+width+',height='+height+',left=50,top=50')
}

function updateRentalPrice(curency,curencyRate,periods,periodsW,periodsDD,periodsDW,currencyText){
	for (i=0;i<periods.length;i++){
		if((curencyRate[curency]*periodsW[periods[i]]).toFixed(0)>0)
			document.getElementById('periodsW_'+periods[i]).innerHTML = (curencyRate[curency]*periodsW[periods[i]]).toFixed(0) + ' '+currencyText[curency];
		else
			document.getElementById('periodsW_'+periods[i]).innerHTML ='-';
			
		if((curencyRate[curency]*periodsDD[periods[i]]).toFixed(0)>0)
			document.getElementById('periodsDD_'+periods[i]).innerHTML = (curencyRate[curency]*periodsDD[periods[i]]).toFixed(0)+ ' '+currencyText[curency];
		else
			document.getElementById('periodsDD_'+periods[i]).innerHTML ='-';
			
		if((curencyRate[curency]*periodsDW[periods[i]]).toFixed(0)>0)
			document.getElementById('periodsDW_'+periods[i]).innerHTML = (curencyRate[curency]*periodsDW[periods[i]]).toFixed(0)+ ' '+currencyText[curency];
		else
			document.getElementById('periodsDW_'+periods[i]).innerHTML='-';
	}
}

function showHideElem(action,divId){
	if(divId!=""){
		divElem = document.getElementById(divId);
		if(divElem!=null){
			if(action=="show") divElem.style.display='inline';
			if(action=="hide") divElem.style.display='none';
		}
	}
}
function showHideDiv(action,divId){
	if(divId!=""){
		divElem = document.getElementById(divId);
		if(divElem!=null){
			if(action=="show") divElem.style.display='block';
			if(action=="hide") divElem.style.display='none';
		}
	}
}

function plusAction(nrOfElements,curentIndex){
	for(i=1;i<=nrOfElements;i++){
		if(i!=curentIndex){
			showHideDiv('hide','menuContent'+i);
			showHideDiv('hide','minus_'+i);
			showHideDiv('show','plus_'+i);
		}else{
			showHideDiv('hide','plus_'+i);
		}
	}
	showHideDiv('show','minus_'+curentIndex);
	showHideDiv('show','menuContent'+curentIndex);
}

function minusAction(curentIndex){
	showHideDiv('hide','minus_'+curentIndex);
	showHideDiv('show','plus_'+curentIndex);
	showHideDiv('hide','menuContent'+curentIndex);
}

function showNewCity(id)
{
	if(id==-1)
		document.getElementById('NewCity').style.display = 'block';
	else
		document.getElementById('NewCity').style.display = 'none';
}
function showNewSubRegion(id)
{
	if(id==-1)
		document.getElementById('NewSubRegion').style.display = 'block';
	else
		document.getElementById('NewSubRegion').style.display = 'none';
}


