// JavaScript Document
function first(key,county,city)
{
	
var text=key;
var text1=city;
//alert(text);
//alert(text1);
if(city.toLowerCase()=="comfort")
{

location="http://www.ramsgate-hotels.co.uk/comfortinn-hotels.html";
//location="../"+"comfortinn-hotels.html";

}
else if(city.toLowerCase()=="quality hotels")
{
location="http://www.ramsgate-hotels.co.uk/qualityinn-hotels.html";
}

else
{

text=this.replace(text," ","-");

if(text1.toLowerCase()=="st albans")
{
text1=this.replace(text1," ","-");
}
else
{
text1=this.replace(text1," ","");
}

county=this.replace(county," ","");
if(key.toLowerCase()=="hotels")
{
text2=text1+"-"+text;
}
else
{
text2=text+"-"+text1;
}

location="http://www.ramsgate-hotels.co.uk/"+county+"/"+text2.toLowerCase()+".html";
//location=county+"/"+text2.toLowerCase()+".html";
//location="../"+county+"/"+text2.toLowerCase()+".html";

}
}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function filloptions(city,key)
	{	
	//alert(chosen.options[chosen.selectedIndex].text);
	// ENTER CITY NAMES
	city.length=0;
	city.options[city.options.length]=new Option('Arundel', 'westsussex')
	city.options[city.options.length]=new Option('Ashbourne', 'derbyshire')
	city.options[city.options.length]=new Option('Ashford', 'kent')
	city.options[city.options.length]=new Option('Birminghamcity ', 'birmingham')
	city.options[city.options.length]=new Option('Blackpool', 'lancashire')
	city.options[city.options.length]=new Option('Bournemouth ', 'dorset')
	city.options[city.options.length]=new Option('Bracknell ', 'berkshire')
	city.options[city.options.length]=new Option('Broadstairs', 'kent')
	city.options[city.options.length]=new Option('Canterbury', 'kent')
	city.options[city.options.length]=new Option('Central London', 'london')
	city.options[city.options.length]=new Option('Chorley', 'lancashire')
	city.options[city.options.length]=new Option('Comfort', 'surrey')
	city.options[city.options.length]=new Option('Cranbrook', 'kent')
	city.options[city.options.length]=new Option('Croydon', 'surrey')
	city.options[city.options.length]=new Option('Deal', 'kent')
	city.options[city.options.length]=new Option('Dover', 'kent')
	city.options[city.options.length]=new Option('Epping', 'essex')
	city.options[city.options.length]=new Option('Folkestone', 'kent')
	city.options[city.options.length]=new Option('Great Yarmouth', 'norfolk')
	city.options[city.options.length]=new Option('Hastings', 'eastsussex')
	city.options[city.options.length]=new Option('Hinckley', 'leicestershire')
	city.options[city.options.length]=new Option('Hythe', 'kent')
	city.options[city.options.length]=new Option('Kensington and Chelsea', 'london')
	city.options[city.options.length]=new Option('Leeds', 'westyorkshire')
	city.options[city.options.length]=new Option('Londoncity', 'london')
	city.options[city.options.length]=new Option('Maidstone', 'kent')
	city.options[city.options.length]=new Option('Margate', 'kent')
	city.options[city.options.length]=new Option('Northampton', 'northamptonshire')
	city.options[city.options.length]=new Option('North London', 'london')
	city.options[city.options.length]=new Option('North West London', 'london')
	city.options[city.options.length]=new Option('Quality Hotels', 'surrey')
	city.options[city.options.length]=new Option('Ramsgate', 'kent')
	city.options[city.options.length]=new Option('Sandwich', 'kent')
	city.options[city.options.length]=new Option('Sittingbourne', 'kent')
	city.options[city.options.length]=new Option('St albans', 'hertfordshire')
	city.options[city.options.length]=new Option('Stevenage', 'hertfordshire')
	city.options[city.options.length]=new Option('South West London', 'london')
	city.options[city.options.length]=new Option('Westminster', 'london')
	city.options[city.options.length]=new Option('York', 'northyorkshire')
	
	// ENTER KEY WORDS FOR FILE NAMES
	
	key.length=0;
	key.options[key.options.length]=new Option('Hotels', 'key1')
	key.options[key.options.length]=new Option('Hotels in', 'key1')
	key.options[key.options.length]=new Option('Accommodation in', 'key1')
	key.options[key.options.length]=new Option('Bed and breakfast in', 'key1')
	key.options[key.options.length]=new Option('Cheap hotels in', 'key1')
	key.options[key.options.length]=new Option('Discount hotels in', 'key1')
	key.options[key.options.length]=new Option('Guest houses in', 'key1')
	key.options[key.options.length]=new Option('Reservations in', 'key1')
	key.options[key.options.length]=new Option('Family hotels in', 'key1')
	key.options[key.options.length]=new Option('Weekend breaks in', 'key1')
	
	
	//key.options[key.options.length]=new Option('Hotel accommodation ', 'key1')
	//key.options[key.options.length]=new Option('Online bookings', 'key1')

	var URL = unescape(location.href)	// get current URL in plain ASCII
var xstart = URL.lastIndexOf("/") + 1
	var xend = URL.length
	var hereName = URL.substring(xstart,xend)
	var herePath = URL.substring(0,xstart)
var fsplit=new Array();
var fsplit1=new Array();
//alert(hereName);
fsplit=hereName.split(".html");
fsplit1=fsplit[0].split("-");
var len=fsplit1.length;
var deli=1;
if(fsplit1[len-1].toLowerCase()=='albans' || fsplit1[len-1].toLowerCase()=='town')
{
deli=2;
var cityname=fsplit1[len-2]+fsplit1[len-1];
}
else
{
deli=1;
var cityname=fsplit1[len-deli];
}

//alert(cityname);
var keyname="";
for(var k=0;k<fsplit1.length-deli;k++)
{
//alert(fsplit1[k]);
keyname+=fsplit1[k]+" ";
}
//alert(keyname);

keyname=RTrim(keyname);
keyname=LTrim(keyname);

//alert(cityname);
//alert(keyname);
//alert(keyname.length);
//alert(ex.length);
//alert(fsplit.length-1);
//alert("split 0:"+ replace(fsplit[0],"-"," "));
//alert("split 1:"+replace(fsplit[1],".html",""));
for(var a=0;a<key.length;a++)
{
if(key.options[a].text.toLowerCase()==keyname)
{
key.selectedIndex=a;
}
}

for(var a=0;a<city.length;a++)
{
//alert("key:"+key.options[a].text.toLowerCase());
if(this.replace(city.options[a].text.toLowerCase()," ","")==cityname)
{
city.selectedIndex=a;
}
}

if(cityname=="hotels")
{
//alert(keyname);
//alert(keyname.length);

for(var a=0;a<city.length;a++)
{
////alert("key:"+key.options[a].text.toLowerCase());
if(this.replace(city.options[a].text.toLowerCase()," ","")==keyname)
{
city.selectedIndex=a;
}
}
}
	
	}
                 
	function setOptions(chosen)
	 {
	alert(chosen.options[chosen.selectedIndex].value); 
     }

// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}
