/* Functions in this file
		PrintHead				46
		PrintMenu				72
		showMap					312
		bas						322				
		createQueryString		352
		goToList				358
*/

//PrintHead prints the header at the top of the page
function PrintHead(TitleStr)
{
	tablewidth=750;
	var header = window.location.search.substring(1);
	if(header.length < 1)
	{
		header = createQueryString();
	} 
	
	homeURL = 'http://www.ahparis.com/';
	
	document.write('<div align="center">');
	document.write('<table align="center" border="1" cellpadding="0" cellspacing="0" bordercolor="#0B2A8E">');
	document.write('<tr>');
	document.write('<td>');
	document.write('<table align="center" border="0" cellpadding="0" cellspacing="0">');
	document.write('	<tr>');
	document.write('		<td align="center"  rowspan="2" valign="bottom" width="' + tablewidth/3 + '">');
	document.write('			<a name="link_top">');
	document.write('    		<a href="' + homeURL + '">');
	document.write('      		<img border="0" src="images/logo_grey.gif">');
	document.write('      	</a>');
	document.write('      </a>');
	document.write('		</td>');
	document.write('		<td align="center" valign="bottom" width="' + tablewidth*2/3 + '">');
	document.write('		<font face="Geneva, Arial, Helvetica, sans-serif" size="4" color="#0E215E">');
	var lang=QueryString("lang");
	if(lang=="fr")
	{
	document.write('		Location saisonnière d\'appartements à prix abordables !');
	}else
	{
	document.write('		Short-term vacation apartment rentals at affordable rates!');
	}
	document.write('        </font>');	
	document.write('		</td>');
	document.write('	</tr>');
	document.write('	<tr>');
	document.write('		<td align="center">');
	document.write('			<b><font color="#0E215E" size="4">');
	document.write(TitleStr);
	document.write('			</font></b>');
	document.write('		</td>');
	document.write('	</tr>');
	document.write('</table>');
	document.write('		</td>');
	document.write('	</tr>');
	document.write('</table>');
	document.write('</div>');
}

//-------------------------------------------------------------------
function showMap(mypage) 
{
	win = window.open(mypage, "map", "toolbar=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,directories=yes,location=yes,left=0,top=0");
	win.window.focus();
}


/*-------------------------------------------------------------------------------------
Writes the webmaster's email address at the bottom of the page
---------------------------------------------------------------------------------------*/
function bas()
{
//document.write("<table width='600' align='center' background='images/bg_whole.gif'>");
document.write("<table width='600' align='center'>");
document.write("	<tr>");
document.write("		<td align='center'>");
document.write("			<font size='2' face='Arial'>");
document.write("				<a href='mailto:johnfay@ahparis.com' target='principal' class='norm'>webmaster</a>");
document.write("			</font>");
document.write("		</td>");
document.write("	</tr>");
document.write("	<tr>");
document.write("		<td align='center' valign='bottom' class='petit'>");
document.write("				Ah Paris apartmetns, vacation rentals, lodging and accommodations in Paris<br>");
document.write("			<font color='#FFFFFF'>Ah Paris apartment rentals offers affordable Paris vacation apartments. Accommodations in Paris include the Marais, the Latin Quarter (Quartier Latin), the Eiffel Tower, the Bastille and Montmartre.</font>");
document.write("		</td>");
document.write("	</tr>");
document.write("</table>");
//document.write("<table width='600' align='center' background='images/bg_bot.gif'>");
document.write("<table width='600' align='center'");
document.write("	<tr>");
document.write("	</tr>");
document.write("</table>");
}

/*--------------------------------------------------------
Creates a default QueryString
----------------------------------------------------------*/

function createQueryString()
{
	var QString = "lang=en&pageno=1";
	return QString;
}


//----------------------------------------------------------------------------------
//'CalcTotal calculates the total cost of the reservation
//' id_apt = Apartment ID
//' radate = Arrival Date
//' rddate = Departure Date
//'	it returns the variables Total, Comm and ToPay
//'----------------------------------------------------------------------------------//
function calcTotal(radate, rddate, Rent_Day,  Rent_Week, Rent_Month, DSpecial_Rate, WSpecial_Rate, MSpecial_Rate, Special_Begin, Special_End)
{
	var TDays, TWeeks, TMonths, CMonths, Mextra, CDays, CWeeks;
	var MgtFee;
	var min_Stay;
	var ANumStr;
	var PriceDiff, PriceDiffMax, PriceDiffTotal;
	var NbDaysInSpecial, NbDaysOutOfSpecial;
	var SpecialPrice, NormalPrice;
	var Total = 0;
	
//alert("radate = " & radate & "<br>")
//alert("rddate = " & rddate & "<br>")
//Get the Monthly and Daily rates
//alert("Special_Begin = " & Special_Begin & "<br>")
	if(Rent_Week == null){
		Rent_Week = 7 * Rent_Day;
	}
//Compute the total
	if(Rent_Month==null){
		Rent_Month = 21 * Rent_Day;
	}
//Get rid of #
//Strip off the "#"s

	TDays = DateDiff('d', radate, rddate);
	TWeeks = Math.floor(TDays/7);
	TMonths = Math.floor(TDays/30);
//alert("Rent_Week = " & Rent_Week & "<br>")
//alert("TDays = " & TDays & "<br>")
	MExtra = TDays % 30;
	Total = TDays * Rent_Day;
	if(TWeeks > 0){
		Total = Math.ceil(TDays * Rent_Week/7);
	}
//alert("Rent_Month = " & Rent_Month & "<br>")
	if(Total > Rent_Month){
		Total = Rent_Month;
	}
//alert("TMonths = " & TMonths & "<br>")
	if(TMonths > 0){
		Total = Math.ceil(TDays * Rent_Month/30);
	}
//Calculate any Specials
	NbDaysInSpecial = 0;
	NbDaysOutOfSpecial = TDays;
	PriceDiffTotal = 0;
	SpecialPrice = 0;
//alert("Special_Rate = " & Special_Rate & "<br>")
//alert("Special_Begin = " & Special_Begin & "<br>")
//alert("Special_End = " & Special_End & "<br>")
	if(DSpecial_Rate!='' && Special_Begin!='' && Special_End!=''){
//The arrival date and departure date are within the special period
		if(DateDiff('d', Special_Begin, radate) >= 0 && DateDiff('d', rddate, Special_End) >= 0){
			NbDaysInSpecial = DateDiff('d', radate, rddate);
			NbDaysOutOfSpecial = 0;
		}
//Arrival date before special period, Departure date within special period
		else if(DateDiff('d', radate, Special_Begin) >= 0 && DateDiff('d', Special_Begin, rddate) >= 0 && DateDiff('d', rddate, Special_End) >= 0){
			NbDaysInSpecial = DateDiff('d', Special_Begin, rddate);
			NbDaysOutOfSpecial = DateDiff('d', radate, Special_Begin);
		}
//The arrival date in special period and departure date after special period
		else if(DateDiff('d', Special_Begin, radate) == 0 && DateDiff('d', radate, Special_End) >= 0 && DateDiff('d', Special_End, rddate) >= 0){
			NbDaysInSpecial = DateDiff('d', radate, Special_End);
			NbDaysOutOfSpecial = DateDiff('d', Special_End, rddate);
		}
//alert("DateDiff(d, Special_Begin, radate) = " & DateDiff("d", Special_Begin, radate) & "<br>")
//alert("DateDiff(d, radate, Special_End) = " & DateDiff("d", radate, Special_End) & "<br>")
//The arrival date before special period and departure date after special period
		else if(DateDiff('d', radate, Special_Begin) >= 0 && DateDiff('d', Special_End, rddate) > 0){
			NbDaysInSpecial = DateDiff('d', Special_Begin, Special_End);
			NbDaysOutOfSpecial = DateDiff('d', radate, Special_Begin) + DateDiff('d', Special_End, rddate);
		}
		
//alert("NbDaysInSpecial = " + NbDaysInSpecial);
//alert("DSpecial_Rate = " + DSpecial_Rate);
		SpecialPrice = NbDaysInSpecial * DSpecial_Rate;
//alert("SpecialPrice = " + SpecialPrice);
//alert("NbDaysInSpecial = " & NbDaysInSpecial & "<br>")
//alert("NbDaysOutOfSpecial = " & NbDaysOutOfSpecial & "<br>")
//alert("DSpecial_Rate = " & DSpecial_Rate & "<br>")
//alert("WSpecial_Rate = " & WSpecial_Rate & "<br>")
//alert("MSpecial_Rate = " & MSpecial_Rate & "<br>")
		if(NbDaysInSpecial > 6){
			SpecialPrice = NbDaysInSpecial * (WSpecial_Rate/7);
		}
		if(NbDaysInSpecial > 29){
			SpecialPrice = NbDaysInSpecial * (MSpecial_Rate/30);
		}
		if(NbDaysInSpecial < 30 && SpecialPrice > MSpecial_Rate){
			SpecialPrice = MSpecial_Rate;
//alert("SpecialPrice = " & SpecialPrice & "<br>")
		}
		NormalPrice = NbDaysOutOfSpecial * Rent_Day;
		if(NbDaysOutOfSpecial > 6){
			NormalPrice = NbDaysOutOfSpecial * Rent_Week/7;
		}
		if(NbDaysOutOfSpecial > 29){
			NormalPrice = NbDaysOutOfSpecial * Rent_Month/30;
		}
		if(NbDaysOutOfSpecial < 30 && NormalPrice > Rent_Month){
			NormalPrice = Rent_Month;
		}

//alert("SpecialPrice = " & SpecialPrice & "<br>")
//alert("NormalPrice = " & NormalPrice & "<br>")
		Total = Math.ceil(NormalPrice + SpecialPrice);
//alert("Total = " & Total & "<br>")
//alert("radate = " & radate & "<br>")
//alert("rddate = " & rddate & "<br>")
//alert("DateDiff(d, Special_Begin, radate) = " & DateDiff("d", Special_Begin, radate) & "<br>")			
//alert("NbDaysInSpecial = " & NbDaysInSpecial & "<br>")			
//Don't go above 21 days of specials	
//alert("PriceDiff = " & PriceDiff & "<br>")			
			
	}
//alert("Total = " + Total);
	return Total; 
}


