//// By CO Jul 2004
//// Copyright (c) 2001-2004 Saranjan, Inc.
//// Status: Experimental

//// Generic flags
var gbDebug=false;     // by default, can be changed by param
var gbCookiesOK=true;  // by default, will be tested later
//var gbNoNestingAllowed = true; //


//// Browser sniffing

var gbIsIE = false;
var gbIsIE5 = false;
var gbIsIE6 = false;
var gbIsNS = false;
var bgIsMoz = false;
var bgIsFireFox = false;

if (parseInt(navigator.appVersion) >= 4) {
	if (navigator.userAgent.indexOf("MSIE") > 0) {
		gbIsIE = true;
		if (navigator.userAgent.indexOf("MSIE 5")) {
			gbIsIE5 = true;
		}
		if (navigator.userAgent.indexOf("MSIE 6")) {
			gbIsIE6 = true;
			gbIsIE5 = true;
		}
	} else if (navigator.appName == "Netscape") {
		gbIsNS = true;
		if (navigator.userAgent.indexOf("Mozilla")) {
			bgIsMoz = true;
		}
		if (navigator.userAgent.indexOf("Firefox")) {
			bgIsFireFox = true;
		}
	}
}

//// Generic flag updates based on sniffing

if ((gbCookiesOK) && (navigator.cookieEnabled) && (navigator.cookieEnabled == false))
{
	gbCookiesOK = false;
	//alert ("Cookies disabled");
}

//// Generic functions


function trim(str)
{
	if (str == null) return "";
	return str.replace(/^\s*(\b.*\b|)\s*$/, "$1");
}

function compareStr(sA,sB)
{
	if (sA > sB) return 1;
	if (sA < sB) return -1;
	return 0;
}

//// Generic cookie functions

var gCookieExpDate = new Date ();

// Mac date bug fix
function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}

function SetCookie (name,value,expires,path,domain,secure) {
// first 2 params are required, others optional
	//if (!(domain)) { domain = "Saranjan"; }
	if (!(expires)) { expires = gCookieExpDate ;}
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
	//alert('cookie set to expire ' + expires + ' : ' + GetCookie(name))
}

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";
  }
}

function GetCookie(nam) {
// Parses document's cookie for a named value
// Weird coding supports both IE6 and Mozilla
	var a = document.cookie.split(";");
	var aCk = null;
	for (i=0;i<a.length;i++)
	{
		if (a[i].indexOf("=") < 0)
		{
			continue;
		}
		aCk = a[i].split("=");
		if (trim(aCk[0]) == nam)
		{
			if (aCk.length > 0)
			{
				return unescape(aCk[1]);
			}
			else
			{
				break;
			}
		}
	}
	return "";
}

function GetCookieList()
{
	// Returns an array of cookie names
	// IE uses the form 'name;' for empty cookies,
	// while moz uses the form 'name=;'
	var a = document.cookie.split(";");
	var aNams = new Array();
	for (i=0;i<a.length;i++)
	{
		if (a[i].indexOf("=") > -1)
		{
			aNams[aNams.length] = trim((a[i].split("="))[0]);
		}
		else
		{
			aNams[aNams.length] = trim(a[i]);
		}
	}
	return aNams.sort(compareStr);
}

function ClearAllCookies(path, domain)
{
	var aNams = GetCookieList();
	for (i=0;i<aNams.length;i++)
	{
    document.cookie = aNams[i] + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

FixCookieDate (gCookieExpDate); // Correct for Mac date bug - call only once for given Date object!

// Arbitrary expiration date set to 1 year for this app.
gCookieExpDate.setTime (gCookieExpDate.getTime() + (365 * 24 * 60 * 60 * 1000)); // 1 * 24 hrs from now

function GetWeirdCookie(nam){
	var s1 = GetCookie(nam);
	var s = '';
	if (s1 != null) {
		for (i=0;i<s1.length;i++) {
			n = s1.charCodeAt(i) - 1;
			s += String.fromCharCode(n);
		}
	}
	return s;
}

function SetWeirdCookie(nam,val) {
	var s = '';
	if (val != null) {
		var s1 = val + '';
		for (i=0;i<s1.length;i++) {
			n = s1.charCodeAt(i) + 1;
			s += String.fromCharCode(n);
		}
	}
	SetCookie(nam,s);
}

function clearCookies(aNames)
{
	if (aNames)
	{
		for (i=0;i<aNams.length;i++)
		{
			DeleteCookie(aNames[i])
		}
	}
}

// End of generic cookie functions

// Parse any parameters passed on command line

var gaURLParams = new Array();

function URLParams2Array() {
	var nameVal   = "";                 // Holds array for a single name-value pair.
	var inString  = location.search;    // Strips query string from URL.
	var i = 0;
	var a = 0;
	var v = "";

	// If URL contains a query string, grabs it.
	if (inString.charAt(0) == "?") {
        // Removes "?" character from query string.
        inString = inString.substring(1, inString.length);
	}
	if (inString.length > 0) {
   	var aKeypairs = inString.split("&")
   	// Loops through name-value pairs.
   	for (i=0;i<aKeypairs.length;i++) {
		// Splits name-value into array (nameVal[0]=name, nameVal[1]=value).
			nameVal = aKeypairs[i].split("=");
			v = nameVal[1]
			while (v.indexOf('+') > -1) {
				//Got to do this the hard way because of IE
				//bug with 'g' in regular expression /+/g
				v = v.substring(0,v.indexOf('+')) + ' ' + v.substring(v.indexOf('+') + 1);
			}//while
			nameVal[1]= unescape(v);
			nameVal[0] = nameVal[0].toUpperCase();
			gaURLParams[gaURLParams.length] = nameVal;
		}
	}
}

URLParams2Array();

function GetURLParam(nam) {
	nam=nam.toUpperCase();
	for (i=0;i<gaURLParams.length;i++){
		if (gaURLParams[i][0]==nam){
			return gaURLParams[i][1]
		}
	}
	return ""
}

if (GetURLParam("DEBUG").toUpperCase().indexOf("Y") == 0) gbDebug == true;

// This stuff for debugging only
if (gbDebug) {
	var s = ""
	for (i=0;i<gaURLParams.length;i++) {
 	 s += '\nName=' + gaURLParams[i][0] + ' value=' + gaURLParams[i][1]
	}
	alert("Paramcount " + gaURLParams.length + s)
}

function MakeYouAreHereXHTML(url){
	// This function creates the "You are here" links by inspecting
	// the structure array created by snjstruct.js
	// It must be called only *after* snjstruct has been included
	// and executed.
	var aPath = null;
	var aPaths = new Array();
	var bFound = false;

	var sPath = 'You are here: ';

	if (!window.gaLinkTable) return "";
	if (gaLinkTable.length==0) return "";

	var sUrl = GetShortUrl(url);
	if (sUrl == "index.htm") return ""; // No you are here on home page

	sPath = '<div class="link2">You are here: <a class="link2" href="index.htm" alt="Home">Saranjan Tours</a>'

	// Find this page in the LinksTable. It may appear
	// more than once
	var titl = "";
	var idParent = "";

	for (i=0;i<gaLinkTable.length;i++){
		if (gaLinkTable[i].href == sUrl){
			// found one instance of this page
			idParent = gaLinkTable[i].idParent;
			aPath = new Array();
			aPath[0] = i;
			idLastParentFound = null;
			while ((idParent != "") && (idParent != "(none)")){
				idTest = idParent;
				idParent = "";
				for (j=0; j < gaLinkTable.length; j++){
					if (gaLinkTable[j].idPg == idTest){
						if (gaLinkTable[j].idPg != idLastParentFound) {
							idLastParentFound = gaLinkTable[j].idPg;
							aPath[aPath.length] = j;
						}
						idParent = gaLinkTable[j].idParent
					}
				}
			}
			aPaths[aPaths.length] = aPath;
		}
	}

	// Now we have 0, 1 or more paths.
	if (aPaths.length > 0) {
		// If more than one, we need the shortest one
		var iShort = 0;
		if (aPath.length > 1) {
			nShortCnt = 100;
			for (i=0;i<aPaths.length;i++){
				if (aPaths[i].length < nShortCnt){
					iShort = i;
					nShortCnt = aPaths[i].length;
				}
			}
		}
		aPath = aPaths[iShort];
		for (i = aPath.length-1; i > 0; i--){
			sPath += ' &gt; ';
			sPath += '<a class="link2" href="' + gaLinkTable[aPath[i]].href + '" ';
			sPath += 'alt="' + gaLinkTable[aPath[i]].title + '">';
			sPath += gaLinkTable[aPath[i]].title + '</a>'
		}
		sPath += ' &gt; ' + gaLinkTable[aPath[0]].title;
	}
	sPath += '</div>';
	// Special case - we might be in a frame
	if ((aPaths.length == 0) && (window.parent) && (window.parent != window)){
		sPath = MakeYouAreHereXHTML(window.parent.location.href)
	}
	return sPath
}


function MakeYouAreHereXHTML06(url){
	// This function creates the "You are here" links by inspecting
	// the structure array created by snjstruct.js
	// It must be called only *after* snjstruct has been included
	// and executed.
	var aPath = null;
	var aPaths = new Array();
	var bFound = false;

	var sPath = 'You are here: ';

	if (!window.gaLinkTable) return "";
	if (gaLinkTable.length==0) return "";

	var sUrl = GetShortUrl(url);
	if (sUrl == "index.htm") return ""; // No you are here on home page

	sPath = '<div class="link2">You are here: <a class="link2" href="index.htm" alt="Home">Saranjan Tours</a>'

	// Find this page in the LinksTable. It may appear
	// more than once
	var titl = "";
	var idParent = "";

	for (i=0;i<gaLinkTable.length;i++){
		if (gaLinkTable[i].href == sUrl){
			// found one instance of this page
			idParent = gaLinkTable[i].idParent;
			aPath = new Array();
			aPath[0] = i;
			idLastParentFound = null;
			while ((idParent != "") && (idParent != "(none)")){
				idTest = idParent;
				idParent = "";
				for (j=0; j < gaLinkTable.length; j++){
					if (gaLinkTable[j].idPg == idTest){
						if (gaLinkTable[j].idPg != idLastParentFound) {
							idLastParentFound = gaLinkTable[j].idPg;
							aPath[aPath.length] = j;
						}
						idParent = gaLinkTable[j].idParent
					}
				}
			}
			aPaths[aPaths.length] = aPath;
		}
	}

	// Now we have 0, 1 or more paths.
	if (aPaths.length > 0) {
		// If more than one, we need the shortest one
		var iShort = 0;
		if (aPath.length > 1) {
			nShortCnt = 100;
			for (i=0;i<aPaths.length;i++){
				if (aPaths[i].length < nShortCnt){
					iShort = i;
					nShortCnt = aPaths[i].length;
				}
			}
		}
		aPath = aPaths[iShort];
		for (i = aPath.length-1; i > 0; i--){
			sPath += ' &gt; ';
			sPath += '<a class="link2" href="' + gaLinkTable[aPath[i]].href + '" ';
			sPath += 'alt="' + gaLinkTable[aPath[i]].title + '">';
			sPath += gaLinkTable[aPath[i]].title + '</a>';
		}
		sPath += ' &gt; ' + gaLinkTable[aPath[0]].title;
	}
	sPath += '</div>';
	// Special case - we might be in a frame
	if ((aPaths.length == 0) && (window.parent) && (window.parent != window)){
		sPath = MakeYouAreHereXHTML(window.parent.location.href)
	}
	alert(sPath);
	return sPath
}



function GetShortUrl(url) {
	var s = url;
	if (s == null) s = window.location.href;
	p = (s.substr(7)).lastIndexOf('\/');
	if (p > -1) s = s.substr(8 + p);
	p = s.indexOf("#");
	if (p > 0) s = s.substr(0,p); //subtle
	p = s.indexOf("?");
	if (p > 0) s = s.substr(0,p); //subtle
	return s
}

function GetUrlPath(url) {
	// returns the path up to the last "/"
	var s = url;
	if (s == null) s = window.location.href;
	p = s.lastIndexOf('\/');
	if (p > -1) return s.substr(0,p+1);
	return url
}

function DeactivateLinksToThisPage (){
	var sShortUrl = GetShortUrl();
	var sUrl = window.location.href;
	if ((window.parent) && (window.parent != window)){
		sUrl = window.parent.location.href;
	}
	var p = sUrl.indexOf("#");
	if (p > 0) {
		sUrl = sUrl.substr(0,p-1)
	}
	var aLinks = document.getElementsByTagName("A");
	for (i=0;i<aLinks.length;i++){
		obj = aLinks[i];
		if ((obj.href == sUrl) || (obj.href == sShortUrl)) {
			//alert("found a link to myself: " + obj.href)
			//obj.href="#";
			obj.disabled = true;
			obj.style.cursor="default";
			if ((obj.className != null) && (obj.className != "")){
				switch (obj.className){
					case "link1":
						obj.className = "link1off";
						break;
					case "link2":
						obj.className = "link2off";
						break;
					default: // do nothing
				}
			}
		}
	}
}

function DoNothing(){
	// catcher function called by disabled hyperlinks
	return
}


function ShowBrowser() {
	if (parseInt(navigator.appVersion) >= 4) {
		if (navigator.userAgent.indexOf("MSIE") > 0) {
			gbIsIE = true;
			if (navigator.userAgent.indexOf("MSIE 5")) {
				gbIsIE5 = true;
			}
			if (navigator.userAgent.indexOf("MSIE 6")) {
				gbIsIE6 = true;
				gbIsIE5 = true;
			}
		} else if (navigator.appName == "Netscape") {
			gbIsNS = true;
		}
	}
	alert("navigator.userAgent=" + navigator.userAgent + '\nnavigator.appName=' + navigator.appName)
}

var zWndExternalLink = null;
var zExtLink = null;

function ExternalLink(url) {
    if (url == "travelinsurance") {
        url = "https://www.TravelInsured.com/Agent_Login/Agent_Template/46145_Template_One/46145.aspx"
    } else if (url == "travelinsaa") {
    	url = "http://www.accessamerica.com/integration_start.asp?accamnum=F027913&target=new&Start_Page=products&referrer=createlink";
    }

    if (url.indexOf("://") < 0) {
        url = "./" + url
    }
	zExtLink = url;
    if ((!zWndExternalLink) || (zWndExternalLink.closed)) {
        window.status = "Opening external link window"
        zWndExternalLink= window.open("about:blank");
        if (!zWndExternalLink.opener) zWndExternalLink.opener = self;
		var s = '<script language="JavaScript">function goUrl()'
		  + '\{window.location.href=window.opener.zExtLink\}<\/script> '
		  + '<p style="font-family: Arial, Helvetica, Sans-Serif;font-size: medium;font-weight: bold;">'
		  + '<br />One moment, please...</p>';
		zWndExternalLink.url="about:blank";
		zWndExternalLink.document.write(s);
	    zWndExternalLink.focus()
		zWndExternalLink.goUrl();
    } else {
		zWndExternalLink.location.href="about:blank";
	    zWndExternalLink.focus()
		zWndExternalLink.location.href = url;
	}
}

// Vars and functions used in displaying alternate rows
 var gnRow=2;
 var gsRow="";

 function rowtag() {
	document.write('<tr class="row'+gnRow+'">');
	(gnRow==1?gnRow=2:gnRow=1)
 }
 function resetRowTags() {
	gnRow=2;
 	gsRow="";
 }


//alert("OK still");


/////////////////////////////////////////////////////////
// Cookie optin/out for privacy management

if (GetCookie("NoCookies") == "true")
{
	gbCookiesOK = false;
}

function DisallowCookies(){
	// Ironically, must set a cookie to remember this option
	ClearAllCookies()
	SetCookie("NoCookies", "true");
	gbCookiesOK = false;
	//alert("Cookies allowed: " +  gbCookiesOK);
}

function AllowCookies(){
	// Ironically, must set a cookie to remember this option
	SetCookie("NoCookies", "false");
	gbCookiesOK = true;
	//alert("Cookies allowed: " +  gbCookiesOK);
}

function ConfirmCookiesOK(){
	//alert("confirming cookies: " + gbCookiesOK);
	var sCk = GetCookie("NoCookies");
	var bOK = false;
	if ((!gbCookiesOK) || (sCk == "true"))
	{
		bOK = false;
	}
	else if (sCk == "false")
	{
		bOK = true;
	}
	else if ((gbCookiesOK == true) || (sCk == ""))
	{
		var s = 'Is it OK to use a cookie to keep track of your preferences?';
		if ((true) || (confirm(s)))
		{
			SetCookie("NoCookies", "false");
			bOK = true;
		}
		else
		{
			ClearAllCookies()
			SetCookie("NoCookies", "true");
			bOK = false;
		}
	}
	//alert("cookies confirmed: " + bOK);
	gbCookiesOK = bOK;
	return bOK;
}

//// Used in managing radio button groups

function GetRadioButtonValue(frm, nam)
{
	var elems = frm.elements;
	var rbgrp = elems[nam];
	if (gbContactFormDebug)
	{
		var s = "Debug GetRadiobuttonValue for " + nam;
		for (i=0;i<rbgrp.length;i++)
		{
			if (rbgrp[i].name == nam)
			{
				s += "\n" + rbgrp[i].value + " = " + rbgrp[i].checked;
			}
		}
		alert(s);
  }
	for (i=0;i<rbgrp.length;i++)
	{
		if ((rbgrp[i].name == nam) && (rbgrp[i].checked)) return rbgrp[i].value;
	}
	return "(nothing selected)";
}

function GetRadioButtonSetting(rbgrp)
{
	for (i=0;i<rbgrp.length;i++)
	{
		if (rbgrp[i].checked) return i;
	}
	return -1;
}

function SetRadioButtonSetting(rbgrp, i)
{
	if (isNaN(i)) i = parseInt(i);
	if ((!isNaN(i)) && (i >= 0) && (i < rbgrp.length)) rbgrp[i].click();
}

function SetRadioButtonValue(rbgrp, v)
{
	for (i=0;i<rbgrp.length;i++)
	{
		rbgrp[i].checked = (rbgrp[i].value == v);
		if (rbgrp[i].value == v) if (rbgrp[i].click());
	}
}


//// Manage "tag" cookies for taggable topics

var gaTags = new Array();

function AddToCart(tag){

	if (!ConfirmCookiesOK()) return false; // works only if cookies enabled

	if (GetTagIndexInCart(tag) < 0) {
	//alert("adding tag: " + tag);
		var s = GetCookie("tags");
		var aTags = new Array();
		if (s != null){
			aTags = s.split(",");
		}
		aTags[aTags.length] = tag;
		SetCookie("tags", (aTags.toString()));
		//alert("tags cookie has been set=" + GetCookie("tags"))
		return true; // yes, did add
	}
	return false // did not add because already there
}

//alert("OK")

function RemoveFromCart(tag){

	if (!gbCookiesOK) return false; // works only if cookies enabled

	var i = GetTagIndexInCart(tag);
	if (i < 0) {
		return false // was not there in the first place
	}
	//alert("removing tag: " + tag);
	var s = GetCookie("tags")
	var aTags = s.split(",");
	aTags.splice(i,1);
	SetCookie("tags", aTags.toString());
	return true; // yes, if was there
}

function GetTagIndexInCart(tag){
	var s = GetCookie("tags");
	if ((s != null) && (s != "")){
		var aTags = s.split(",");
		for (i=0;i<aTags.length;i++){
			if (aTags[i] == tag){
				return i;
			}
		}
	}
	return -1;
}

function IsTagInCart(tag){
	if (!gbCookiesOK) return false; // works only if cookies enabled
	//alert("looking up tag: " + tag + '\n' + GetTagIndexInCart(tag))
	return (GetTagIndexInCart(tag) >= 0)
}

function UrlToTag(url){
	for (i=0;i<gaLinkTable.length;i++){
		if (gaLinkTable[i].href == url){
			return gaLinkTable[i].idPg
		}
	}
	return "";
}

function ClickTagCheckbox(sVal,bChecked,n)
{
	//alert("Clicking Tag checkbox " + obj.value + " " + obj.checked)
	window.status = ("Clicking Tag checkbox " + sVal + " " + bChecked)
	var a = sVal.split("~");
	tag = a[0];
	if (ConfirmCookiesOK())
	{
		if (bChecked)
		{
			AddToCart(tag)
			if (n == 1) // this was set on an individual page
			{
				SetCookie("PgTagged","1")
			}
		}
		else
		{
			RemoveFromCart(tag)
		}
	}
}

function MakeTagCheckbox() {
	// Called by pages when loading. If the page
  // id does not begin in SNJ then this is a tag
  // that can be remembered and used in the contact
  // form by prechecking the corresponding options
  // If page id begins with SNJ then this function
  // does nothing.

  if (!gbCookiesOK) return;

	var url = GetShortUrl(window.location.href);
	var tag = UrlToTag(url);

/*
	//alert("page tag = " + tag + "\n for url = " + url)
	if ((tag == "") || (tag.indexOf("SNJ") == 0)) return;
	var s = '<!--[if IE]><style> .tagbox {font-size: 0.6em; }</style><![endif]-->';

	s +=  '<form id="tagbox" name="tagbox">';
	s += '<table border="0" cellspacing="0" cellpadding="0" width="100%" summary="Layout around checkbox"><tr><td nowrap valign="top" class="tagbox">';
	s += '<input type="checkbox" name="TagForInterest" id="TagForInterest" size="50"';
	if (IsTagInCart(tag)){
		s += ' defaultchecked="true"';
	}
	s += ' onclick="javascript:ClickTagCheckbox(this.value,this.checked,1)"';
	s += ' value="' + tag + '">&nbsp;</td><td class="snjdark">';
	s += '<b>Mark this topic in the <a class="linkbg" href="contact.htm';
	//s += '#' + tag;
	s += '">contact form</a></b>';
  //s += ' <a class="linkbg" href="javascript:ExplainTagCheckbox()"><img src="img/helpbtntiny.gif" width="13" height="14" border="0" alt="Button to explain the tagging checkbox" /></a>'
  s += '<small><br clear="all"/>(<a class="linkbg" href="javascript:ExplainTagCheckbox()">What is this?</a>)'
	s += '</td></tr></table></form>'

*/
	//alert("page tag = " + tag + "\n for url = " + url)
	if ((tag == "") || (tag.indexOf("SNJ") == 0)) return;
	var s = ""; // '<!--[if IE]><style> .tagbox {font-size: 0.6em; }</style><![endif]-->';

	s +=  '<form id="tagbox" name="tagbox">';
	s += '<input type="checkbox" name="TagForInterest" id="TagForInterest" size="50"';
	if (IsTagInCart(tag)){
		s += ' defaultchecked="true"';
	}
	s += ' onclick="javascript:ClickTagCheckbox(this.value,this.checked,1)"';
	s += ' value="' + tag + '">&nbsp;';
	s += '<b>Check this box to mark this topic in the <a class="linkbg" href="contact.htm';
	//s += '#' + tag;
	s += '">contact form</a></b>';
  //s += ' <a class="linkbg" href="javascript:ExplainTagCheckbox()"><img src="img/helpbtntiny.gif" width="13" height="14" border="0" alt="Button to explain the tagging checkbox" /></a>'
  s += '<small><br />(<a class="linkbg" href="javascript:ExplainTagCheckbox()">What is this?</a>)</small>'
	s += '</form>'

	document.write(s);

	//alert(document.forms["tagbox"].elements["TagForInterest"])
	document.forms["tagbox"].elements["TagForInterest"].checked = (IsTagInCart(tag));
}
//alert("OK")

function ExplainTagCheckbox(){
	alert('If you check this box, a corresponding box will be checked in the information request form on the "Contact Us" page. That page can be reached by clicking the "Contact Us" link in the menu at the top of every page on this web site. You can also reach it by clicking the "Contact form" link next to the check box. \n\nAs you browse this web site, you can check or uncheck the things you are interested in. This checkbox is only available on pages that correspond to a topic on the information request form. If you need information on other topics, you can type in your request in another box on that form.\n\nNote: This works by setting a small first-party "cookie" on your computer. This is entirely safe. If you are concerned about this, or if you want to learn more about cookies, you can look up the topic "cookie" in the help for your browser, or visit the Privacy page on our web site.')
}

function ActivateExternalLinkFootnote()
{
  if( document.getElementById &&
      document.getElementsByTagName )
  {
  	var footnote = document.getElementById("ExternalLinkFootnote")
  	if (!footnote) return;

  	var bExt = false;
  	var classN="";
    links = document.getElementsByTagName( 'a' );
    for( var i=0; i < links.length; i++ )
    {
      classN = links[i].className;
      //if (classN) alert("classname = " + classN);
      if ((classN) && (classN.indexOf("external") != -1))
      {
      	if ((links[i].href).indexOf("links.htm") == -1)
      	{
      		//alert("External link: " + links[i].href);
      		bExt = true;
      	}
      }
    }
    //alert("bExt=" + bExt);
    if (bExt)
    {
    	footnote.style.display = "block";
    }
  }
}


// Generic character transformation function (not complete set)
function EscapeHTMLEntities(v) {

	// Caution! The function will try to check, but it
	// is safer do not use it if the string has already been escaped!
	var s = "";
	var c = "";
	for(i=0; i<v.length;i++){
		c = v.charAt(i);

		switch(c) {
			case "&":
				if ((v.substr(i)).indexOf("&amp;") != 0){
					// TBD need more tests here
					c = "&amp;"; break;
				}
				break;
			/*
			case "á":
				c = "&aacute;"; break;
			case "Á":
				c = "&Aacute;"; break;
			case "é":
				c = "&eacute;"; break;
			case "É":
				c = "&Eacute;"; break;
			case "è":
				c = "&ègrave;"; break;
			case "È":
				c = "&Ègrave;"; break;
			case "í":
				c = "&íacute;"; break;
			case "Í":
				c = "&Íacute;"; break;
			case "ó":
				c = "&óacute;"; break;
			case "Ó":
				c = "&Óacute;"; break;
			case "ú":
				c = "&úacute;"; break;
			case "Ú":
				c = "&Úacute;"; break;
			case "ñ":
				c = "&ntilde;"; break;
			case "Ñ":
				c = "&Ntilde;"; break;
			case "ç":
				c = "&ccedil;"; break;
			case "Ç":
				c = "&Ccedil;"; break;
			case "©":
				c = "&copy;"; break;
			case "®":
				c = "&reg;"; break;
		*/
			default:
				n = v.charCodeAt(0);
				if (n > 127){
					c = '&#'+ n + ';'
				}
		}//switch

		s += c;
	}
	return s

}

function init() {
	var myUrl = window.location.href;

	//
	//alert(myUrl)
	if ((myUrl.indexOf("http://www.showmespain.com") == 0)||
	    (myUrl.indexOf("http://showmespain.com") == 0)||
	    (myUrl.indexOf("http://www.showmesportugal.com") == 0)||
	    (myUrl.indexOf("http://showmeportugal.com") == 0))
	{
		//alert("Redirecting to Saranjan.com, the owner site of ShowMeSpain.com.")
		window.location.href = "http://www.saranjan.com/";
		return;
	}

  // If page has a script function to initialize page data, call it
	if (window.initPgData)
	{
		window.initPgData();
	}
	TrackReferParams()
	DeactivateLinksToThisPage()
	//ShowBrowser()
	InitAutoUpdate();
	ShowReferrer();
	ActivateExternalLinkFootnote();
}

function cleanOnBeforeUload(){
	// catcher function; noop
}

function TrackReferParams()
{
	var s = null;
	if (document.referrer) s = document.referrer;
	if (!gbCookiesOK) return;
	if ((s != null) && (s != ""))
	{
		// ignore if referrer is our own web site
		if (s.indexOf(GetUrlPath()) == 0) s = null;
	}
	// better than referrer, we may have a specific param
	if (GetURLParam("referredby") != "")
	{
		s = location.search;
	}
	else if (GetURLParam("src") != "")
	{
		s = location.search;
	}
	if ((s != null) && (s != ""))
	{
		var p = s.indexOf("?");
		var sV = s;
		if (p > -1 ) sV = s.substring(p+1, s.length-1);

		window.status = sV;

		if (p == 0) s = s.substr(1);
		SetCookie("refby",  s + "\n" + (new Date()).toUTCString())

		//alert("referparam = " + s)
	}
}

function ShowReferrer()
{
	var s = null;
	if (document.referrer) s = document.referrer;
	if ((s != null) && (s != ""))
	{
		var p = s.indexOf("?");
		if (p > -1 ) s = s.substring(p+1, s.length-1);
		window.status = s;
	}
}

if (!gbCookiesOK)
{
	window.status = "Cookies disabled -- See Privacy page"
}

// Workaround for lazy IE; force it to preload spacer image
gImage1 = new Image();
gImage1.src = "img/onepixel.gif";

//Nesting not allowed by default
var gbNoNestingAllowed = true; // To avoid error in some older scripts
// New script
if ( (!(window.gbNestingAllowed)) && (window.parent) && (window.parent!=window)) {
    window.parent.location.href=window.location.href
}

function ClosureDate()
{
	var s="";
  var sd1 = "20 Dec 2005 UTC";
  var sd2 = "8 Jan 2006 UTC";
  var now = new Date();
  var nowmil = now.getTime();
  var d1 = new Date(sd1);
  var d1mil = d1.getTime();
  var d2 = new Date(sd2);
  var d2mil = d2.getTime();

//var s1, s2
//if (d1mil < nowmil) s1 = "now is after " + sd1; else s1 = "now is before " + sd1;
//if (d2mil < nowmil) s2 = "now is after " + sd2; else s2 = "now is before " + sd2;
//alert(s1 + "\n" + s2);

  if ((d1mil < nowmil) && (d2mil > nowmil))
  {
    s = "<div align='center'><font color='#008000'><strong>"
    s += "The Saranjan offices will be closed from December&nbsp;26,&nbsp;2005 to January&nbsp;6,&nbsp;2006. They will reopen on January 9.<br />Season's greetings and best wishes for the new year!"
    s += "</strong></font></div>";
    document.write(s);
  }
}
//

function getStyleObject(objectId) {
  // checkW3C DOM, then MSIE 4, then NN 4.
  //
  if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
   }
   else if (document.all && document.all(objectId)) {
	return document.all(objectId).style;
   }
   else if (document.layers && document.layers[objectId]) {
	return document.layers[objectId];
   } else {
	return false;
   }
}

function GetPageScroll()
{
	var n = null;
	if ((window.pageYOffset) && (!isNaN(window.pageYOffset)))
	{
		n = window.pageYOffset; window.status="pageYOffset=" + n;
	}
	else if (true) // (document.body.scrollTop)
	{

		n = document.body.scrollTop; //window.status= (new Date()) + " scrollLeft=" + document.body.scrollLeft + " scrollTop=" + n;
	}
	else window.status="no scroll data"
	return n
}

function ShowTopPagePrompt()
{
	var obj = document.getElementById("pageTopPrompt");
	if (typeof(obj) == "undefined") return;
	var style_sheet = getStyleObject("pageTopPrompt");
  if (!style_sheet) return;

	//window.status = obj.style.display;
	var n = GetPageScroll();

	//window.status = document.body.scrollTop;
	var v = "";

	if ((!isNaN(n)) && (n > 12))
	{
		v = "block"
	}
	else
	{
		v = "none"
	}
	if (gbIsIE) // temporary until figure out IE bug
	{
		v = "block"
	}
	if (obj.style.display != v) obj.style.display = v;
}

function TimedUpdate()
{
	//d = new Date();
	//window.status = "   " + d;

	ShowTopPagePrompt();
}

document.onload = init;
document.onmousemove = ShowTopPagePrompt;

function InitAutoUpdate()
{
	//alert(navigator.appName);
	//window.status = "Starting timer";
	//setInterval("TimedUpdate()", 500);
	//window.status = "Timer started";
}

function PhotoRights(who)
{
	if (!who) who = "Claude Ostyn";
	alert('This image is copyrighted - (c) '
	 + who + ' - All rights reserved');
}

function InsertInDocUntil(s, sDate){
// Takes a string, and a date in format YYYYMMDD
// Writes out the string only if today is < than the specified date
	//alert("pull date:" + sDate +"\nstring:" + s);
	var d = new Date();
	var sd = d.getFullYear().toString();
	var n = d.getMonth()+1;
	(n < 10? sd += "0" + n.toString() : sd += n + "");
	n = d.getDate();
	(n < 10? sd += "0" + n.toString() : sd += n + "");
	//alert("pull:" + sDate + "\nnow:" + sd);
	if (sd <= sDate) document.write(s);
}

