function showdiscount(oneweek,twoweek,threeweek,onemonth,threemonts,sixmonths,ninemonths,oneyears,baseprice,monthlyprice,nightly,monthly,cityname)
{
document.getElementById('citynamed').innerHTML='<strong>'+cityname+'</strong>';
if(nightly==1 && monthly==1)
{
document.getElementById('monthlyrow1').style.display='block';
document.getElementById('monthlyrow2').style.display='block';
document.getElementById('nightlyrow1').style.display='block';
document.getElementById('nightlyrow2').style.display='block';
document.getElementById('onemonthed').style.display='none';
document.getElementById('basepriced').innerHTML=baseprice+' EUR';
document.getElementById('monthlypriced').innerHTML=monthlyprice+' EUR';
document.getElementById('oneweekdiscount').innerHTML=oneweek+' %';
document.getElementById('twoweekdiscount').innerHTML=twoweek+' %';
document.getElementById('threeweekdiscount').innerHTML=threeweek+' %';
document.getElementById('onemonthdiscount').innerHTML=onemonth+' %';
document.getElementById('threemonthdiscount').innerHTML=threemonts+' %';
document.getElementById('sixmonthdiscount').innerHTML=sixmonths+' %';
document.getElementById('ninemonthdiscount').innerHTML=ninemonths+' %';
document.getElementById('oneyeardiscount').innerHTML=oneyears+' %';
}
else if(nightly==1)
{
document.getElementById('monthlyrow1').style.display='none';
document.getElementById('monthlyrow2').style.display='none';
document.getElementById('nightlyrow1').style.display='block';
document.getElementById('nightlyrow2').style.display='block';
document.getElementById('basepriced').innerHTML=baseprice+' EUR';
document.getElementById('oneweekdiscount').innerHTML=oneweek+' %';
document.getElementById('twoweekdiscount').innerHTML=twoweek+' %';
document.getElementById('threeweekdiscount').innerHTML=threeweek+' %';
document.getElementById('onemonthdiscount').innerHTML=onemonth+' %';
}
else if(monthly==1)
{
document.getElementById('monthlyrow1').style.display='block';
document.getElementById('monthlyrow2').style.display='block';
document.getElementById('nightlyrow1').style.display='none';
document.getElementById('nightlyrow2').style.display='none';
document.getElementById('monthlypriced').innerHTML=monthlyprice+' EUR';
document.getElementById('threemonthdiscount').innerHTML=threemonts+' %';
document.getElementById('sixmonthdiscount').innerHTML=sixmonths+' %';
document.getElementById('ninemonthdiscount').innerHTML=ninemonths+' %';
document.getElementById('oneyeardiscount').innerHTML=oneyears+' %';
}
setVisible2('email12');
}

x = 20;
y = 70;
function setVisible2(obj)
{
	obj = document.getElementById(obj);
	obj.style.display = (obj.style.display == 'block') ? 'none' : 'block';
}
function placeIt32(obj)
{
	obj = document.getElementById(obj);
	if (document.documentElement)
	{
		theLeft = document.documentElement.scrollLeft;
		theTop = document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		theLeft = document.body.scrollLeft;
		theTop = document.body.scrollTop;
	}
	theLeft += x;
	theTop += y;	



	document.getElementById('email12').style.left = theLeft + 'px' ;
	document.getElementById('email12').style.top = theTop + 'px' ;
	
	
	setTimeout("placeIt32('email12')",500);
}




function createMarker(point, idapp, title, price, numofguests, numofbeds, roomsize, minstay, distancetocity, icon, checkin, checkout, guests, bedrooms ) {
		markerids[k++] = idapp;
		
		price = '<div style="width:auto;float:left;">'+price.replace(':',':</div><div style="width:55px;float:right;">')+'</div>';
		numofguests = '<div style="width:auto;float:left;">'+numofguests.replace(':',':</div><div style="width:55px;float:right;">')+'</div>';
		numofbeds = '<div style="width:auto;float:left;">'+numofbeds.replace(':',':</div><div style="width:55px;float:right;">')+'</div>';
		roomsize = '<div style="width:auto;float:left;">'+roomsize.replace(':',':</div><div style="width:55px;float:right;">')+'</div>';
		minstay = '<div style="width:auto;float:left;">'+minstay.replace(':',':</div><div style="width:55px;float:right;">')+'</div>';
		distancetocity = '<div style="width:auto;float:left;">'+distancetocity.replace(':',':</div><div style="width:55px;float:right;">')+'</div>';
		
		var marker = new GMarker(point, icon);
		var html = "<div class='map_popup_div_main'><a href='"+fullurl+"apartmentdetail/view/idapartment/"+idapp+"/checkin/"+checkin+"/checkout/"+checkout+"/guests/"+guests+"/bedrooms/"+bedrooms+"' style=\"color:#000000;font-weight:bold;text-decoration:none;\" target=\"_blank\"><span class='map_popup_title_span'>"+title+"</span></a>"+"<br/><div class='map_popup_img_div'><img src='"+fullurl+"picture/picture/idapartment/" + idapp + "' width='155'/></div><div class='map_popup_description'><div class='mapgridrow1'>"+price+"</div><div class='mapgridrow2'>"+numofguests+"</div><div class='mapgridrow2'>"+numofbeds+"</div><div class='mapgridrow2'>"+roomsize+"</div><div class='mapgridrow2'>"+minstay+"</div><div class='mapgridrow2'>"+distancetocity+"</div><div style=\"text-align:right;\"><a href='"+fullurl+"apartmentdetail/view/idapartment/"+idapp+"/checkin/"+checkin+"/checkout/"+checkout+"/guests/"+guests+"/bedrooms/"+bedrooms+"' style=\"color:#C82127;font-weight:bold;\" target=\"_blank\">View details</a> | <a onclick='addtolist("+idapp+")' style=\"cursor:pointer;color:#C82127;font-weight:bold;text-decoration:underline;\">Add to favorite</a><span id='mylistloader"+idapp+"'></span></div></div></div>";
		
		GEvent.addListener(marker, 'click', function() {
			for(var z = 0; z < gmarkers.length; z++){
				gmarkers[z].setImage("http://www.redappleapartments.com/images/marker.png");
			}
			marker.setImage("http://www.redappleapartments.com/images/pointer.png");
			marker.openInfoWindowHtml(html);
		});
		
		gmarkers[j] = marker;
		htmls[j] = html;
		idapp[j] = idapp; 
		j++;
		
		return marker;
    }
	
	// This function picks up the click and opens the corresponding info window
    function popup_app(idapp) {
		var index;
		
		for(var i = 0; i < gmarkers.length; i++)
		{
			gmarkers[i].setImage("http://www.redappleapartments.com/images/marker.png");
			
			if(idapp == markerids[i]){
				index = i;
			}
		}
		
		
		gmarkers[index].setImage("http://www.redappleapartments.com/images/pointer.png");
		gmarkers[index].openInfoWindowHtml(htmls[index]);
      }
	  
	function makeDisable(val){
		var x=document.getElementById("flexibledates")
		if(val){
			x.disabled=true
		}else{
			x.disabled=false
		}
	}
	

function closeloadingdiv()
{
	//alert('ok');
	document.getElementById('calenderloading').style.display = 'none';
	//alert('okok');
	
	if(navigator.appName == 'Microsoft Internet Explorer')
	{
		setTimeout("changeCalendarControlMonthPopup(1)",1100);
		setTimeout("changeCalendarControlMonthPopup(-1)",1200);
	}
	else
	{
		changeCalendarControlMonthPopup(1);
		changeCalendarControlMonthPopup(-1);
	}
}

function findPosition(object) {									// finds the position of a given object, used as reference point for our layer
	var positionLeft = positionTop = 0;							// declare variables to store co-ordinates
	if (object.offsetParent) {									// offsetParent returns the position from the nearest element in this case our link that was clicked
		do {
			positionLeft += object.offsetLeft;					// store the position
			positionTop += object.offsetTop;
		} while (object = object.offsetParent);
	}
	return [positionLeft,positionTop];							// return the co-ordinates of the link
}

function openLayer(object, myLayer)								// shows the layer and changes its position based on the given object
{
	var coords = findPosition(object);							// get our co-ordinates from the findPosition function
	var layer = document.getElementById(myLayer);
	layer.style.top = coords[1] + 'px'; 						// change the 100 to alter co-ordinates of popup
	//layer.style.left = 100 + coords[0] + \'px\';				// places it from the top left corner of our object, in this case the link clicked.
	document.getElementById(myLayer).style.display='inline';	// show the layer
}

function closeLayer(myLayer) {
	document.getElementById(myLayer).style.display='none';
}

function showavaildates(apid,object,isie)
{
	var calendarControlPopup = new CalendarControlPopup();
	
	var checkin = document.getElementById('checkin').value;
	var checkout = document.getElementById('checkout').value;
	var guests = document.getElementById('guests').value;
	var bedrooms = document.getElementById('bedrooms').value;
	var apartmentsort = document.getElementById('apartmentsort').value;
	var flexibledates = document.getElementById('flexibledates').value;
	
	var url = fullurl+'apartments/checkavailabledates/checkin/'+checkin+'/checkout/'+checkout+'/guests/'+guests+'/bedrooms/'+bedrooms+'/flexibledates/'+flexibledates+'/apid/'+apid;
	//alert(url);
	
	document.getElementById('availdatespop').innerHTML = '';
	if(isie == 1)
	{
		openLayer(object,'popupwindow');
	}
	else
	{
		document.getElementById('popupwindow').style.display = 'block';
	}
	
	var myAjax = new Ajax(url, {method: 'get',evalScripts: true,update: 'availdatespop',
		onComplete: function() {
			document.getElementById('calenderloading').style.display = 'block';
			//alert('hi');
			setTimeout("closeloadingdiv()",1000);
			
		}}).request();
}
