/* Functions in this file
		PrintLogo						20
		PrintHead						46
		PrintMenu						119
		newWindow						366
		showMap							373
		getObj							385
		colorText						409
		fourNumbers					422
		isNumber						433
		errorMessage				457
		bas									482				
		QueryString					514
		modQueryString			548
		createQueryString		601
*/

//PrintLogo prints the header at the top of the page
function PrintLogo()
{
	tablewidth=750;
	var header = window.location.search.substring(1);
	if(header.length < 1)
	{
		header = createQueryString();
	} 
	
	homeURL = 'http://www.ahparis.com/apt_list.asp?' + header;
	
	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" valign="middle" 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="center" 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 d\'appartements saisonnière au prix abordables !');
	}
	else
	{
	document.write('		Short-term vacation apartment rentals at affordable rates!');
	}
	document.write('        </font>');	
	document.write('		</td>');
	document.write('	</tr>');
	document.write('</table>');
	document.write('		</td>');
	document.write('	</tr>');
	document.write('</table>');
	document.write('</div>');
}

//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/apt_list.asp?' + header;
	
	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 d\'appartements saisonnière au 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);
	//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();
		var lang = 'en';
	} else
	{
	var 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")
	{
		var newHeader = modQueryString('lang', 'fr');
		var langTxt = 'Français';
	} else
	{
		var newHeader = modQueryString('lang', 'en');
		var 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] = 'https://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 newWindow(mypage) 
{
  win = window.open(mypage,"photo","status=yes,toolbar=no,directories=no,scrollbars=yes,width=800,height=800,resizable=yes,left=0,top=0");
  win.window.focus();
}

//-------------------------------------------------------------------
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();
}

/*--------------------------------------------------------------------- 
  getObj() returns the requested object
-----------------------------------------------------------------------*/

var DHTML = (document.getElementById || document.all || document.layers);

function getObj(name)
{
//alert('name = ' + name);
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
		this.value = document.getElementById(name).value;
  }
  else if (document.all)
  {
		this.obj = document.all[name];
		this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

/*------------------------------------------------------------
 colorText() changes the indicated text to the selected color
--------------------------------------------------------------*/
function colorText(txt, txtcolor)
{
		if (!DHTML) return;
//alert('txt = ' + txt);
		var x = new getObj(txt);
		x.style.color = txtcolor;
}
//--------------------------------------------

/*---------------------------------------------------------------
 fourNumbers() Limits the number of characters in field1 to 4
  then skips to field2
-----------------------------------------------------------------*/
function fourNumbers(field1, field2)
{
		var x = new getObj(field1);
		var letters=x.value.length + 1;
if(letters>4)
	{document.getElementById(field2).focus();}
}

/*---------------------------------------------------------
 isNumber() Verifies that the data in the field is numeric
-----------------------------------------------------------*/
function isNumber(fld)
{
  var parsed = true;
  var validchars = "0123456789";
    
  for (var i=0; i <fld.length; i++) 
  {
    var letter = fld.charAt(i);
    if (validchars.indexOf(letter) != -1)
    {
      continue;
    }
    else
    {
    	parsed = false;
    	break;
    }
  }
  return parsed;
}

/*---------------------------------------------------------------
  errorMessage opens a window and writes the error messages
-----------------------------------------------------------------*/
function errorMessage(errorField, errorFlag, Error_Msg1, Error_Msg2)
{
		var errorWin=window.open("errorpage.htm",'error_win', 'height=300, width=300, toolbar=yes, menubar=no, location=no scrollbar=yes');
    errorWin.document.write("<html>");
    errorWin.document.write("<b>" + "<font color = 'red'>");
		errorWin.document.write(Error_Msg1);
		errorWin.document.write("<br>");
    errorWin.document.write("</b>" + "</font>");
		for(i = 1; i <= errorFlag; i++)
		{
    	errorWin.document.write("<b>" + "<font color = 'red'>" + "&nbsp;&nbsp;&nbsp;");
			errorWin.document.write(errorField[i]);
    	errorWin.document.write("</font>" + "</b>" + "<br>");
		}
		errorWin.document.write("<br>");
		errorWin.document.write("<A href='javascript://' onclick='javascript:self.close()'>");
		errorWin.document.write(Error_Msg2 + "</A>");
    errorWin.document.write("</html>");
		errorWin.moveTo(0,0);
		errorWin.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! provides short term apartment flat rentals for vacation or business travel to Paris");
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("		<td align='center' height='2' valign='bottom'>");
document.write("			<br>");
document.write("		</td>");
document.write("	</tr>");
document.write("</table>");

}


/*--------------------------------------------------------------------------------
 QueryString returns the value associated with the key
----------------------------------------------------------------------------------*/

function QueryString(key)
{
	QueryString.keys = new Array();
	QueryString.values = new Array();
	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	var value = null;
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;
		}
	}

	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		}
	}
	return value;
}

/*-------------------------------------------------------------------------------
ModQueryString replaces the value in the "key" field with a new value
  if the key field doesn't exist, it creates a new field
---------------------------------------------------------------------------------*/

function modQueryString(key, modif)
{
	QueryString.keys = new Array();
	QueryString.values = new Array();
	var QString = "";
	//This gives you the query string
	var query = window.location.search.substring(1);
	//If there is no querystring, create a default query string
	if(query.length < 1)
	{
		query = createQueryString();
	}
	//This splits the query string on the symbol "&" creating an array of pairs "x=y" 
	var pairs = query.split("&");
	var value = null;
	for (var i=0;i<pairs.length;i++)
	{
		//Split the pairs into the key and it's value
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			//Create the array QueryString.keys
			QueryString.keys[QueryString.keys.length] = argname;
			//Create the corresponding key value array QueryString.values
			QueryString.values[QueryString.values.length] = value;
		}
	}
	
	//Set the newKey flag to true
	var newKey = true;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		//Find the index of the key
		if (QueryString.keys[i]==key)
		{
			//Replace the value with the modified value
			QueryString.values[i] = modif;
			newKey=false;
			break;
		}
	}
	//Recreate the query string
	QString = QueryString.keys[0] + "=" + QueryString.values[0];
	for (i = 1;i<QueryString.keys.length;i++)
	{
		QString = QString + "&" + QueryString.keys[i] + "=" + QueryString.values[i];
	}
	//if this is a new key, add it to the end of the QueryString
	if(newKey) 
	{
		QString = QString + "&" + key + "=" + modif;
	}
	return QString;
}

//Same function as modQueryString only the QString is sent in the 
//  parameters.  This lets you change a QueryString several times in  
//  succession.
function modQString(key, modif, query)
{
	QueryString.keys = new Array();
	QueryString.values = new Array();
	var QString = "";
	//If there is no querystring, create a default query string
	if(query.length < 1)
	{
		query = createQueryString();
	}
	//This splits the query string on the symbol "&" creating an array of pairs "x=y" 
	var pairs = query.split("&");
	var value = null;
	for (var i=0;i<pairs.length;i++)
	{
		//Split the pairs into the key and it's value
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			//Create the array QueryString.keys
			QueryString.keys[QueryString.keys.length] = argname;
			//Create the corresponding key value array QueryString.values
			QueryString.values[QueryString.values.length] = value;
		}
	}
	
	//Set the newKey flag to true
	var newKey = true;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		//Find the index of the key
		if (QueryString.keys[i]==key)
		{
			//Replace the value with the modified value
			QueryString.values[i] = modif;
			newKey=false;
			break;
		}
	}
	//Recreate the query string
	QString = QueryString.keys[0] + "=" + QueryString.values[0];
	for (i = 1;i<QueryString.keys.length;i++)
	{
		QString = QString + "&" + QueryString.keys[i] + "=" + QueryString.values[i];
	}
	//if this is a new key, add it to the end of the QueryString
	if(newKey) 
	{
		QString = QString + "&" + key + "=" + modif;
	}
	return QString;
}
/*--------------------------------------------------------
Creates a default QueryString
----------------------------------------------------------*/

function createQueryString()
{
	var QString = "lang=en&pageNo=1";
	return QString;
}


