/* Script for holidays.htm page only.
   Copyright (C)1996 Web Integration Systems, Inc. DBA Websys, Inc.
   All Rights Reserved.
   This applet can be re-used or modified, if credit is given in the source code.
   We will not be held responsible for any unwanted effects due to the usage of this applet or any derivative.
   No warrantees for usability for any specific application are given or implied.
   Chris Skinner, January 30th, 1996.
   Hacked for CNNfn by RD, Jan. 31, 1996
   I just changed the message: lcp, Feb 2, 1996
   I made it resize with the window, and made it work with XHTML1.0 Strict: JPD, 2002-2003.
*/

function scrollit_r2l(seed)
{
  var msg="Holidays in Paradise ... Greece ... Canaries ... Caribbean ... Spain ... Portugal ... Seychelles ... Mauritius ... Maldives ... France ... Switzerland ... Thailand ... Mexico ...";
  var out = " ";
  var c   = 1;

  if (seed > 100) {
    seed = (seed-1);
    var cmd="scrollit_r2l(" + seed + ")";
    timerTwo=window.setTimeout(cmd,100);
  }
  else if ((seed <= 100) && (seed > 0)) {
    for (c=0 ; c < seed ; c++) {
      out+=" ";
    }
    out+=msg;
    seed = (seed-1);
    var cmd="scrollit_r2l(" + seed + ")";
    document.getElementById("foo").bar.value=out;
    timertwo=window.setTimeout(cmd,100);
  }
  else if (seed <= 0) {
    if (-seed < msg.length) {
      out += msg.substring((-seed),msg.length);
      seed = (seed-1);
      var cmd="scrollit_r2l(" + seed + ")";
      document.getElementById("foo").bar.value=out;
      timertwo=window.setTimeout(cmd,100);
    }
    else {
      document.getElementById("foo").bar.value=" ";
      timertwo=window.setTimeout("scrollit_r2l(100)",75);
    }
  }
}

/***********************************************
* Contractible Headers script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use. Last updated Oct 21st, 2003.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
// John Davies 2004.  Called from holidays.htm

var enablepersist="on" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="yes" //Collapse previously open content when opening present? (yes/no)

function getElementbyClass(classname){
  ccollect=new Array()
  var inc=0
  var alltags=document.all? document.all : document.getElementsByTagName("*")
  for (i=0; i<alltags.length; i++){
    if (alltags[i].className==classname)
      ccollect[inc++]=alltags[i]
  }
}

function contractcontent(omit){
  var inc=0
  while (ccollect[inc]){
    if (ccollect[inc].id!=omit)
      ccollect[inc].style.display="none"
    inc++
  }
}

function expandcontent(cid){
  if (typeof ccollect!="undefined"){
    if (collapseprevious=="yes")
    contractcontent(cid)
  document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
  }
}

function revivecontent(){
  contractcontent("omitnothing")
  selectedItem=getselectedItem()
  selectedComponents=selectedItem.split("|")
  for (i=0; i<selectedComponents.length-1; i++)
    document.getElementById(selectedComponents[i]).style.display="block"
}

function get_cookie(Name) { 
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { 
      offset += search.length
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
        returnvalue=unescape(document.cookie.substring(offset, end))
    }
  }
  return returnvalue;
}

function getselectedItem(){
  if (get_cookie(window.location.pathname) != ""){
    selectedItem=get_cookie(window.location.pathname)
    return selectedItem
  }
  else
    return ""
}

function saveswitchstate(){
  var inc=0, selectedItem=""
  while (ccollect[inc]){
    if (ccollect[inc].style.display=="block")
      selectedItem+=ccollect[inc].id+"|"
    inc++
  }
  document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload(){
  getElementbyClass("switchcontent")
  if (enablepersist=="on" && typeof ccollect!="undefined")
    revivecontent()
}


if (window.addEventListener)
  window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
  window.attachEvent("onload", do_onload)
else if (document.getElementById)
  window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
  window.onunload=saveswitchstate


/********************************************************************/
// Copyright 2001 Roman Koch
// See http://www.romankoch.ch/capslock/tablesort.htm for more information.
//  Added to by John Davies 2004
/********************************************************************/
// John Davies 2004.  Called from holidays.htm
var currentCol = 0
var previousCol = -1

function CompareAlpha(a, b) {
	if (a[currentCol] < b[currentCol]) { return -1; }
	if (a[currentCol] > b[currentCol]) { return 1; }
	return 0;
}

function CompareAlphaIgnore(a, b) {
	strA = a[currentCol].toLowerCase();
	strB = b[currentCol].toLowerCase();
	if (strA < strB) { return -1; }
	else {
		if (strA > strB) { return 1; }
		else { return 0; }
	}
}

function CompareDate(a, b) {
	// this one works with date formats conforming to Javascript specifications, e.g. m/d/yyyy
	datA = new Date(a[currentCol]);
	datB = new Date(b[currentCol]);
	if (datA < datB) { return -1; }
	else {
		if (datA > datB) { return 1; }
		else { return 0; }
	}
}

function CompareDateEuro(a, b) {
	// this one works with european date formats, e.g. d.m.yyyy
	strA = a[currentCol].split(".");
	strB = b[currentCol].split(".")
	datA = new Date(strA[2], strA[1], strA[0]);
	datB = new Date(strB[2], strB[1], strB[0]);
	if (datA < datB) { return -1; }
	else {
		if (datA > datB) { return 1; }
		else { return 0; }
	}
}

function CompareNumeric(a, b) {
	//window.alert ("CompareNumeric");
	numA = a[currentCol]
	numB = b[currentCol]
	if (isNaN(numA)) { return 0;}
	else {
		if (isNaN(numB)) { return 0; }
		else { return numA - numB; }
	}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

var colandhead= '<colgroup>'
colandhead +=   '  <col class="col0" />'
colandhead +=   '  <col class="col1" />'
colandhead +=   '  <col class="col2" />'
colandhead +=   '  <col class="col3" />'
colandhead +=   '  <col class="col4" />'
colandhead +=   '  <col class="col5" />'
colandhead +=   '  <col class="col6" />'
colandhead +=   '</colgroup>           '
colandhead +=   '<thead>'
colandhead +=   '  <tr> '
colandhead +=   '    <th class="col0">Year:</th>'
colandhead +=   '    <th class="col1">Country:</th>'
colandhead +=   '    <th class="col2" style="text-align: left;">Destination:</th>'
colandhead +=   '    <th class="col3" title="Beach holidays">B</th>'
colandhead +=   '    <th class="col4" title="Diving holidays">D</th>'
colandhead +=   '    <th class="col5" title="Walking holidays">W</th>'
colandhead +=   '    <th class="col6" title="Sightseeing holidays">SS</th>'
colandhead +=   '    <th class="col7" title="Sailing holidays">S</th>'
colandhead +=   '  </tr>'
colandhead +=   '</thead>'


function getObj(name)
 {
  if (document.getElementById)
    {
      this.obj = document.getElementById(name); 
      this.style = document.getElementById(name).style; 
    }
  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];
   }
 };




//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function TableSort(myTable, myCol, myType) {
	// Create a two-dimensional array and fill it with the table's content
  var mySource = new getObj(myTable);
	var myRows = mySource.obj.rows.length;
	var myCols = mySource.obj.rows[0].cells.length;
	currentCol = myCol
	myArray = new Array(myRows)
	for (i=0; i < myRows; i++) {
		myArray[i] = new Array(myCols)
		for (j=0; j < myCols; j++) {
			myArray[i][j] = mySource.obj.rows[i].cells[j].innerHTML  // breaks in Mozilla - cos innerHTML not officially in DOM?
		}
	}

	if (myCol == previousCol) {
		myArray.reverse(); // clicked the same column as previously - reverse the sort
	}
	else { // clicked on a new column - sort as indicated
		switch (myType) {
			case "a":
				myArray.sort(CompareAlpha);
				break;
			case "ai":
				myArray.sort(CompareAlphaIgnore);
				break;
			case "d":
				myArray.sort(CompareDate);
				break;
			case "de":
				myArray.sort(CompareDateEuro);
				break;
			case "n":
				myArray.sort(CompareNumeric);
				break;
			default:
				myArray.sort()
		}
	}
/*  Don't want to re-write table.....
	// Re-write the table contents
	for (i=0; i < myRows; i++) {
		for (j=0; j < myCols; j++) {
			mySource.rows(i).cells(j).innerHTML = myArray[i][j]
		}
	}
*/

	previousCol = myCol; // remember the current sort column for the next pass
// Display Countries:
	var currentcountry = "";
	var slcountry="<p>Click on a country name below to see our holidays there:</p>"
	for (i=0; i < myRows; i++) {
	  if (myArray [i][1] == "Country:") {}
	  else
           {
	    if (myArray [i][1] != currentcountry) {
      	if (currentcountry != "") {slcountry+= '</table>'}
	      slcountry+= '<p class="cn" onClick="expandcontent('
	      slcountry+= "'" + myArray [i][1] + "'"
	      slcountry+= ')"> + ' + myArray [i][1] + '</p>'
	      slcountry+= '<table id="' + myArray [i][1] + '" class="switchcontent" width="100%" cellpadding="5" cellspacing="3" >' + colandhead
	      currentcountry = myArray [i][1];
	      }
	      else {}
	    }
	  slcountry+='<tr>';
	    if (myArray [i][1] != "Country:") {
		for (j=0; j < myCols; j++) {slcountry+= '<td class="col' + j + '" >' + myArray[i][j] + '</td>'};
	    }
	  slcountry+= '</tr>'
	}
	slcountry+= '</table>';
  document.getElementById("div2").innerHTML = slcountry;
	return 0;
} //end function TableSort



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function showtype(myTable) {
// John Davies 2004.  Called from holidays.htm

	// Create a two-dimensional array and fill it with the table's content
  var mySource = new getObj(myTable);
	var myRows = mySource.obj.rows.length;
	var myCols = mySource.obj.rows[0].cells.length;
	myArray = new Array(myRows)
	for (i=0; i < myRows; i++) {
		myArray[i] = new Array(myCols)
		for (j=0; j < myCols; j++) {
			myArray[i][j] = mySource.obj.rows[i].cells[j].innerHTML
		}
	}
//write out array by holtype:
	var typestartcol=3;
	var typeendcol=7;
	var holtypes=new Array(typeendcol+1)
	holtypes[typestartcol]   ="Beach"
	holtypes[typestartcol+1] ="Diving"
	holtypes[typestartcol+2] ="Walking"
	holtypes[typestartcol+3] ="Sight-seeing"
	holtypes[typestartcol+4] ="Sailing"
  var sltype = "<p>Click on a holiday type below to see our holidays of that type:</p>"

  for (k=typestartcol; k<typeendcol+1; k++) {
  	sltype+= '<p class="cn" onClick="expandcontent('
  	sltype+= "'" + holtypes[k] + "'"
  	sltype+= ')"> + ' + holtypes[k] + '</p>'
   	sltype+= '<table id="' + holtypes[k] + '" class="switchcontent" width="100%" cellpadding="5" cellspacing="3" >' + colandhead
	  for (i=0; i < myRows; i++) {
	    if (myArray [i][k] == "x") {
	      sltype+= '<tr>'
	        for (j=0; j < myCols; j++) {sltype+= '<td class="col' + j + '">' + myArray[i][j] + '</td>'};
	      sltype+= '</tr>'
	    }  //end if
	  }  //end for i
	  sltype+= '</table>'
    }  // end for k
  document.getElementById("div3").innerHTML = sltype;
	return 0;
} //end function showtype

/******************************************************************/
// John Davies 2004.  Called from holidays.htm
function showandhide (a,b,c) {
 document.getElementById("div" + a).style.display="block";
 document.getElementById("div" + b).style.display="none";
 document.getElementById("div" + c).style.display="none";
}  //end function showandhide

