function selectCategory(Typeselect,Islandselect) {
	var category = Typeselect.options[Typeselect.selectedIndex].value
	var location  = Islandselect.options[Islandselect.selectedIndex].value
	setCookie("MyStr",printDataPage(category,location,0))
}

function selectIsland(Island,Category,StartID){
	setCookie("MyStr",printDataPage(Category,Island,StartID))
}


function selectDetail(ID, Category, Island) {
	setCookie("MyStr",printDetailPage(ID, Category, Island))
}

function printDataPage(categoryID,QNumber,StartID) {
//	var query = "(AccomTypeID == '" + categoryID + "')"
//	DB.AccomodationType.FindFirst(query)	
//	var category = DB.AccomodationType.AccomTypeDesc	//ok got category description

	var s = ""
//	s += "<h2>Category: " + category + ", " + IName +"</h2>\n"
	DB.Accomodation.Sort('Accom_Name','ascend') //sort the database
	if (QNumber == '0') {var query = "((AccomTypeID == "  + categoryID + "))"}
	else if(categoryID == '0') {var query = "((IslandCode == " + QNumber + "))"}
	else {var query = "((AccomTypeID == "  + categoryID + ") && (IslandCode == " + QNumber + "))"}
	DB.Accomodation.FindFirst(query)

	if (DB.Accomodation.RsetProperties.NoMatch) {s += "No records found \n"}
	else {
		if (StartID != '0'){
			DB.Accomodation.Seek(StartID)
			DB.Accomodation.FindNext(query)
		}
		
		s += "<table border=\"0\" width=\"350\">\n"
		
		var x = 0
		while (!DB.Accomodation.RsetProperties.NoMatch && x <= 15) {
			s += "<tr><td><a href=\"javascript:selectDetail(" 
			s += DB.Accomodation.AccomID +"," + categoryID + "," 
			s += QNumber +");history.go(0)\">"
			s += "<font face=\"Verdana\" size=\"2\" >"
			s += DB.Accomodation.Accom_Name
			s += "</font></a>"
			s += "</td></tr>\n" 

			DB.Accomodation.FindNext(query)
			x++
		}

		if (x >= 15 && !DB.Accomodation.RsetProperties.NoMatch){
			s += "<tr><td colspan =2><br><a href=\"javascript:selectIsland("
			s += QNumber +"," + categoryID +"," +  DB.Accomodation.AccomID +");history.go(0)\">"
			s += "<font face=\"Verdana\" size=\"2\" >"
			s += "More ..."
			s += "</font></a></td></tr>"
		}
		s += "</table><br>\n"}
	return s
}

function printDetailPage(Accom_ID, Cat_ID, Isle_ID)
{
	
	var s = ""

	var query = "(AccomID == "  + Accom_ID + ")"
	DB.Accomodation.FindFirst(query)

	s += "<font face=\"Verdana\" size=\"1\">"

	if (DB.Accomodation.RsetProperties.NoMatch) {
		s += "No records found \n"}
	else {
		s += "<table border=\"0\" width=\"300>\" \n"
		s += "<tr><td colspan=\"3\"><font face=\"Verdana\" size=\"2\">"

		if( DB.Accomodation.WebSite.length != 0) {
		s += "<a href=\"http://"+ DB.Accomodation.WebSite +" \" class = \"c1\">"
		s += "<b>" + DB.Accomodation.Accom_Name + "</b></a></td></tr>"}
		else {s += "<b>" + DB.Accomodation.Accom_Name + "</b></td></tr>"}
		
	 	s += "<tr><td colspan = \"3\">"
		
		if( DB.Accomodation.Img_01.length != 0) {
			s += "<img src = \"images/" + DB.Accomodation.Img_01 + "\" >"}
		s += "</td></tr>"

		s += "<tr><td colspan=\"3\"><font face=\"Verdana\" size=\"1\">"
		s += DB.Accomodation.Accom_Description + "</font><br><br></td></tr>"
		s += "<tr><td><img src= \"images/spacer.gif\" width = \"80\" height = \"1\"></td>"
		s += "<td> <img src = \"images/spacer.gif\" width = \"220\" height = \"1\"></td></tr>"
		s += "<tr>"
		if( DB.Accomodation.WebSite.ConName1 != 0 && DB.Accomodation.ConSurname1 != 0) {
			s += "<td width=\"80\" valign=\"top\" align = \"right\"><font face=\"Verdana\" size=\"1\">Contact - </font></td>"
			s += "<td valign=\"top\"><font face=\"Verdana\" size=\"1\">"
			s += DB.Accomodation.ConName1 + " " + DB.Accomodation.ConSurname1 + "<br>\n"}
	
		else {	s += "<td width=\"80\"></td>"
			s += "<td valign=\"top\"><font face=\"Verdana\" size=\"1\">"}
		s += DB.Accomodation.Accom_Street
		if (DB.Accomodation.Accom_Street.length != 0 && DB.Accomodation.Accom_City.length != 0) { s += ", " }
		s += DB.Accomodation.Accom_City
		if ((DB.Accomodation.Accom_City.length != 0 && DB.Accomodation.Accom_District.length != 0) || (DB.Accomodation.Accom_Street.length != 0 && DB.Accomodation.Accom_District.length != 0))
			{ s += ", " }
		s += DB.Accomodation.Accom_District
		s += "</td></tr>"

		if (DB.Accomodation.Telephone.length != 0) {
			s += "<tr>"
			s += "<td width=\"80\" valign=\"top\" align = \"right\"><font face=\"Verdana\" size=\"1\">"
			s += "Tel - </font></td>"
			s += "<td  valign=\"top\"><font face=\"Verdana\" size=\"1\">473 " + DB.Accomodation.Telephone + "</td></tr>"}

		if (DB.Accomodation.Fax.length != 0) {
			s += "<tr>"
			s += "<td width=\"80\" valign=\"top\" align = \"right\"><font face=\"Verdana\" size=\"1\">"
			s += "Fax - </font></td>"
			s += "<td  valign=\"top\"><font face=\"Verdana\" size=\"1\">473 " + DB.Accomodation.Fax + "</td></tr>"}

		if( DB.Accomodation.Email.length != 0) {
			s += "<tr>"
			s += "<td width=\"80\" valign=\"top\" align = \"right\"><font face=\"Verdana\" size=\"1\">"
			s += "Email - </font></td>"
			s += "<td valign=\"top\"><font face=\"Verdana\" size=\"1\"><a href=\"mailto:" + DB.Accomodation.Email + " \">"
			s += DB.Accomodation.Email + "</a></font></td></tr>"}

		if( DB.Accomodation.WebSite.length != 0) {
			s += "<tr><td></td>"
			s += "<td  valign=\"top\"><font face=\"Verdana\" size=\"1\"><a href=\"http://"+ DB.Accomodation.WebSite +" \">"
			s += DB.Accomodation.WebSite + "</a></font></td></tr>"}
			s += "</table><br>\n"
		}
		s += "</font>\n"

// Prev and Next fields
	if (Isle_ID == '0')
		 {var q1 = "((AccomTypeID == "  + Cat_ID + "))"}
	else if (Cat_ID == '0')
		{var q1 = "((IslandCode == " + Isle_ID + "))"}
	else 
		{var q1 = "((AccomTypeID == "  + Cat_ID + ") && (IslandCode == " + Isle_ID + "))"}
	DB.Accomodation.Sort('Accom_Name','ascend')
	DB.Accomodation.FindFirst(q1)
	DB.Accomodation.Seek(Accom_ID)

	DB.Accomodation.FindPrevious(q1)
	if (!DB.Accomodation.RsetProperties.NoMatch) {
		var prev = DB.Accomodation.AccomID
		DB.Accomodation.FindNext(q1)}
	else { var prev = ""}

		DB.Accomodation.FindNext(q1)

	if (!DB.Accomodation.RsetProperties.NoMatch) {
		var next = DB.Accomodation.AccomID}
	else {var next = ""}
		s += "<table><tr><td width =\"100\" >"
		if (prev != ""){
			s += "<a href=\"javascript:selectDetail(" + prev 
			s += "," + Cat_ID + "," + Isle_ID		
			s += ");history.go(0)\">"
			s += "<font face=\"Verdana\" size=\"1\" > << Previous"
			s += "</font></a>"
		}
		s += "</td>\n" 	

		s += "<td  width =\"100\">"
		if (next != ""){
			s += "<a href=\"javascript:selectDetail(" + next
			s += "," + Cat_ID + "," + Isle_ID		
			s += ");history.go(0)\">"
			s += "<font face=\"Verdana\" size=\"1\" >Next>>"
			s += "</font></a>"
		}
		s += "</td></tr>\n" 	
		s += "</table>"
		return s		
}


function initialise() {
	//generate catagory page
	isIE = (typeof(document.all)!="undefined")?true:false
	
	var defaultCategory = "Sport"
	printQuestionsPage(defaultCategory)
}

function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +

((expires) ? "; expires=" + expires.toGMTString() : "") +

((path) ? "; path=" + path : "") +

((domain) ? "; domain=" + domain : "") +

((secure) ? "; secure" : "");

document.cookie = curCookie;
}

// name - name of the desired cookie

// * return string containing value of specified cookie or null if cookie does not exist

function getCookie(name) {

var dc = document.cookie;

var prefix = name + "=";

var begin = dc.indexOf("; " + prefix);

if (begin == -1) {

begin = dc.indexOf(prefix);

if (begin != 0) return null;

} else 
begin += 2;
var end = document.cookie.indexOf(";", begin);
if (end == -1)
end = dc.length;

return unescape(dc.substring(begin + prefix.length, end));

}

// name - name of the cookie

// [path] - path of the cookie (must be same as path used to create cookie)

// [domain] - domain of the cookie (must be same as domain used to create cookie)

// * path and domain default if assigned null or omitted if no explicit argument proceeds

function deleteCookie(name, path, domain) {

if (getCookie(name)) {

document.cookie = name + "=" + 

((path) ? "; path=" + path : "") +

((domain) ? "; domain=" + domain : "") +

"; expires=Thu, 01-Jan-70 00:00:01 GMT";

}

}
