/* 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>');
}

//'-------------------------------------------------------------------------
//'PrintMenu prints the menu on the left hand side of the page
//'--------------------------------------------------------------------------
function PrintMenu()
{
	enStr = new Array();
	frStr = new Array();
	siteURL = new Array();
	enTitleStr = new Array();
	frTitleStr = new Array();
	
	var tablewidth=150;
	var numLinks = 8;
	var numLinks_renter = 4;
	var numLinks_owner = 3;
	var numInfoLinks = 1;
	var noheaderFlag = 0;
	
	
	//Set the language
	var header = window.location.search.substring(1);
//alert('header = ' + header);
	//Check to see if there's a header (QueryString)
	if(header.length < 1)
	{
	//If there's no header, create a default header and set the noheader flag
		noheaderFlag = 1;
		header = createQueryString();
		lang = 'en';
	} else
	{
	lang = QueryString("lang");	
	}
	
	//Get the entire URL String (must add quotes to make it a string)
	var URLStr = '"' + window.location + '"';
	//Get rid of the quotes
	var URLStrLen = URLStr.length;
	URLStr = URLStr.substr(1, URLStrLen - 2);
	//If there was no header, add the header
	if (noheaderFlag == 1)
	{
		URLStr = URLStr + '?' + header;
	} 
	
	//Create a new header for changing languages
	var QueryStrLen = header.length;
	//Get just the address
	var pos = URLStr.indexOf('?');
	var headerLft = URLStr.substr(0, pos);
	if(lang=="en")
	{
		newHeader = modQueryString('lang', 'fr');
		langTxt = 'Français';
	} else
	{
		newHeader = modQueryString('lang', 'en');
		langTxt = 'English';
	}
	var newURL = headerLft + '?' + newHeader;
//-----------------------------------------------
//Contact Us
	enStr[1] = 'Contact Us';
	frStr[1] = 'Nous contacter';
	siteURL[1] = 'mailto:johnfay@ahparis.com" target="principal';

//Renter Strings
	enTitleStr[1] = 'Looking for an apartment?';
	frTitleStr[1] = 'Vous cherchez un appartement';
	enStr[0] = 'Home';
	frStr[0] = 'Page d&acute;accueil';
	siteURL[0] = 'index.asp?' + header;
	enStr[2] = 'View our Apartments';
	frStr[2] = 'Voir nos appartements';
	siteURL[2] = 'apt_list.asp?' + header;
	enStr[3] = 'How to rent';
	frStr[3] = 'Comment louer';
	siteURL[3] = 'works_renter.asp?' + header;
	enStr[4] = 'Transportation';
	frStr[4] = 'Transport';
	siteURL[4] = 'transport.asp?' + header;
	enStr[5] = 'Weather';
	frStr[5] = 'Météo';
	siteURL[5] = 'http://content.oeb.co.uk/clients/timeout/parisweather.html';

//Owner Strings
	
//'------------------------------------------------	
	enTitleStr[2] = 'You have an apartment to list';
	frTitleStr[2] = 'Vous voulez louer votre appartement';
	enStr[6] = 'List your Apartment';
	frStr[6] = 'Passer une annonce';
	siteURL[6] = 'http://www.ahparis.com/owner.asp?' + header;
	enStr[7] = 'How to list your apartment';
	frStr[7] = 'Comment passer une annonce';
	siteURL[7] = 'works_owner.asp?' + header;
//'------------------------------------------------	
	enTitleStr[3] = 'Useful Information';
	frTitleStr[3] = 'Informations utiles';

	document.write('<div align="left">');
	document.write('<table width="' + tablewidth + '" border="0" bordercolor="#2C3666" cellspacing="0" cellpadding="0">');

	//Language
	document.write('<tr>');
	document.write('<td align="center" valign="middle" height="24" background="images/lang_bg.gif">')
	document.write('<b><a href="' + newURL + '" class="menu">' + langTxt + '</a></b>');
	document.write('</td>');
	document.write('</tr>');

//Space
	document.write('<tr>');
	document.write('<td>');
	document.write('<br>');
	document.write('</td>');
	document.write('</tr>');

//Client information
	document.write('<tr>');
	document.write('<td valign="bottom"><img src="images/menu2_top.gif" width="' + tablewidth + '">');
	document.write('</td>');
	document.write('</tr>');
	document.write('<tr>');
	document.write('<td align="center"  bgcolor="#205188">');
	document.write('<strong><font size="2" color="#80FFFF" face="Arial, Helvetica, sans-serif">');
	if(lang == "fr")
	{
		document.write('<b>' + frTitleStr[1] + '</b>');
	} else
	{
		document.write('<b>' + enTitleStr[1] + '</b>');
	}		
	document.write('</strong></font>');	
	document.write('</td>');
	document.write('</tr>');
 
	//Write the renter menu
	for(i = 2; i <= numLinks_renter; i++)
	{
		document.write('<tr>');
		document.write('<td align="center" height="24" width="' + tablewidth + '" bgcolor="#205188">');
		document.write('<a href="' + siteURL[i] + '" class="menu">');
		if(lang == "fr")
		{
			document.write('<b>' + frStr[i] + '</b>');
		} else
		{
			document.write('<b>' + enStr[i] + '</b>');
		}		
		document.write('</a>');
		document.write('</td>');
		document.write('</tr>'); 
	}
	
	//Weather
	document.write('<tr>');
	document.write('<td align="center" height="24" width="' + tablewidth + '" bgcolor="#205188">');
	document.write('<a href="JavaScript:onclick=showMap(%27' + siteURL[5] + '%27)" class="menu">');
	if(lang == "fr")
	{
		document.write('<b>' + frStr[5] + '</b>');
	} else
	{
		document.write('<b>' + enStr[5] + '</b>');
	}		
	document.write('</a>');
	document.write('</td>');
	document.write('</tr>'); 
	
	document.write('<tr>');
	document.write('<td align="center" height="24" width="' + tablewidth + '" bgcolor="#205188">');
	document.write('<a href="' + siteURL[1] + '" class="menu">');
	if(lang == "fr")
	{
		document.write('<b>' + frStr[1] + '</b>');
	} else
	{
		document.write('<b>' + enStr[1] + '</b>');
	}		
	document.write('</a>');
	document.write('</td>');
	document.write('</tr>'); 
	document.write('<tr>');
	document.write('<td valign="top"><img src="images/menu2_bot.gif" width="' + tablewidth + '" height="11"></td>');
	document.write('</tr>');

//Space
	document.write('<tr>');
	document.write('<td>');
	document.write('<br>');
	document.write('</td>');
	document.write('</tr>');
	
	//Owner menu
	document.write('<tr>');
	document.write('<td valign="bottom"><img src="images/menu_top.gif" width="' + tablewidth + '">');
	document.write('</td>');
	document.write('</tr>');
	document.write('<tr>');
	document.write('<td align="center" height="24"" width="' + tablewidth + '" bgcolor="#2C3666">');
	document.write('<strong><font size="2" color="#80FFFF" face="Arial, Helvetica, sans-serif">');
	if(lang == 'fr')
	{
		document.write(frTitleStr[2]);
	} else
	{
		document.write(enTitleStr[2]);
	}
	document.write('</strong></font>');
	document.write('</td>');
	document.write('</tr>');

	//How it Works - Links	
	for( i = numLinks_renter + 2; i <= numLinks_renter + numLinks_owner; i++)
	{
		document.write('<tr>');
		document.write('<td align="center" height="24" width="' + tablewidth + '" bgcolor="#2C3666">');
		document.write('<a href="' + siteURL[i] + '" class="menu">');
		if(lang == 'fr')
		{
			document.write('<b>' + frStr[i] + '</b>');
		} else
		{
			document.write('<b>' + enStr[i] + '</b>');
		}		
		document.write('</a>');
		document.write('</td>');
		document.write('</tr>'); 
	}
	document.write('<tr>');
	document.write('<td align="center" height="24" width="' + tablewidth + '" bgcolor="#2C3666">');
	document.write('<a href="' + siteURL[1] + '" class="menu">');
	if(lang == "fr")
	{
		document.write('<b>' + frStr[1] + '</b>');
	} else
	{
		document.write('<b>' + enStr[1] + '</b>');
	}		
	document.write('</a>');
	document.write('</td>');
	document.write('</tr>'); 
	document.write('<tr>');
	document.write('<td valign="top"><img src="images/menu_bot.gif" width="' + tablewidth + '" height="11"></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;
}

function goToList()
{
	var QStr = window.location.search.substring(1);
	var newURL = "checkout_list.asp?" + QStr;
	document.location = newURL;
}


//----------------------------------------------------------------------------------
//'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; 
}

