
/*
This is a simple javascript to deal with multiple clicks on a
button or a link.  When invoked, only the first click will be
processed.  Subsequent clicks within a pre-defined interval
after the first click will be ignored.  The time interval is
configurable by the "timeInterval" value (in milliseconds) below.

	for a form - use onSubmit event

		<form.......onSubmit="return checkFirst()">

	for a link - use onClick event

		<a........onClick="return checkFirst()">
*/
	// time interval to reset the lock....30 seconds for now
	var timeInterval = 30000;

	var iCount = 0;
	var clickTime = 0;
	var againTime = 0;
	var timeDiff = 0;

	function checkFirst() {

		if (iCount==0) {
			iCount++;
			var now = new Date();
			clickTime = now.getTime();
			return true;

		} else {

			iCount++;
			var now = new Date();
			againTime = now.getTime();

			if (clickTime != 0) {
				timeDiff = againTime - clickTime;
				if (timeDiff > timeInterval) {  // release the lock
					clickTime = againTime;
					return true;
				}
				else {
					return false;
				}
			}
			return false;
		}
	}

/* script to go to the dropdown url */
function changePage(newLoc)
 {
   nextPage = newLoc.options[newLoc.selectedIndex].value

   if (nextPage != "")
   {
      document.location.href = nextPage
   }
 }

/* open a new window */
function popWindow(windowName, fileName, winX, winY, menuY)
    {

			var params = "width=" + winX + ",height=" + winY + ",menubar=" + menuY + ",resize=no,scrollbars=yes";
			newWin = window.open(fileName, windowName, params);
			newWin.creator=self;
			newWin.focus();

      //eval(windowName +' = window.open("' + fileName + '", "'+ windowName +'", "width=' + winX + ',height=' + winY + ',menubar=' + menuY + ',resize=no,scrollbars=yes");');
      //eval(windowName + '.creator=self;');
    }

function MM_openBrWindow(theURL,winName,features) { //v2.0
        newWin = window.open(theURL,winName,features);
        newWin.focus();
      }

function ClosePop(sendTo) {
	  if(sendTo) { window.opener.location = sendTo; }
	  window.close(); }


function PopQuiz(popPage) {
if(!popPage) { popPage = "/harl/empty.htm"; }
var popName = "quiz"; // target=quiz in form
var popSize = "width=450,height=600,resizable,scrollbars";
popWindow = window.open(popPage,popName,popSize);
if(!popWindow.opener) { popWindow.opener = window; }
popWindow.focus();
if(document.quiz) { document.quiz.submit(); } }


function pollPopper() {
var popPage = "http://poll.eharlequin.com/blank.htm";
var popName = "popper";
var popSize = "width=450,height=500,resizable,scrollbars"
var pop = open(popPage,popName,popSize);
pop.focus(); }


/* --- Script for More than Words Begin ---*/
if(document.images)
{
 nav_about_a = new Image(); nav_about_a.src = "/images/charity/about_2.jpg";
 nav_about_i = new Image(); nav_about_i.src = "/images/charity/about_1.jpg";

 nav_submit_a = new Image(); nav_submit_a.src = "/images/charity/submit_2.jpg";
 nav_submit_i = new Image(); nav_submit_i.src = "/images/charity/submit_1.jpg";

 nav_story_a = new Image(); nav_story_a.src = "/images/charity/story_2.jpg";
 nav_story_i = new Image(); nav_story_i.src = "/images/charity/story_1.jpg";

 nav_contribute_a = new Image(); nav_contribute_a.src = "/images/charity/contribute_2.jpg";
 nav_contribute_i = new Image(); nav_contribute_i.src = "/images/charity/contribute_1.jpg";

 nav_getinv_a = new Image(); nav_getinv_a.src = "/images/charity/getinvolve_2.jpg";
 nav_getinv_i = new Image(); nav_getinv_i.src = "/images/charity/getinvolve_1.jpg";

 nav_faq_a = new Image(); nav_faq_a.src = "/images/charity/faq_2.jpg";
 nav_faq_i = new Image(); nav_faq_i.src = "/images/charity/faq_1.jpg";

}

function switchImages (ImageName2BChanged, objImage,   objInfoImage){
  if (document.images){
  	window.document[ImageName2BChanged].src=objImage.src;
  	}
}

function OpenWindow(s)
    {
		msgWindow=window.open(s, "contactWindow", "toolbar=no,width=375,height=500,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no");
		msgWindow.focus();
	}

/* --- Script for More than Words End ---*/
var popPage = "";

function PopWindow(popPage) {
var popName = "new";
popWindow = window.open(popPage,popName);
popWindow.focus(); }

function popQuizzes(popPage) {
if (popPage == "aomquiz.htm")
{
	popPage = "/harl/books/alcove/quiz/aomquiz.htm";
	var popName = "quiz"; // target=quiz in form
	var popSize = "width=450,height=600,resizable,scrollbars";
	popWindow = window.open(popPage,popName,popSize);
	if(!popWindow.opener) { popWindow.opener = window; }
		popWindow.focus();
	if(document.quiz) { document.quiz.submit(); }
}
else
{
	var popPage = "http://poll.eharlequin.com/cgi-bin/tallies.cgi?quiz=" + popPage + "&proceed=proceed";
	var popName = "quiz";
	var popSize = "width=450,height=550,resizable,scrollbars";
	popWindow = window.open(popPage,popName,popSize);
	if(!popWindow.opener) { popWindow.opener = window; }
		popWindow.focus();
}
}


function PopThesaurus() {
var popPage = "/harl/books/readingroom/thesaurus/20thes11.htm";
var popName = "thesaurus";
var popSize = "width=400,height=400,resizable,scrollbars";
popWindow = window.open(popPage,popName,popSize);
if(!popWindow.opener) { popWindow.opener = window; }
popWindow.focus();}

function PopCard(popPage) {
var popName = "card";
var popSize = "width=530,height=550,resizable,scrollbars";
popWindow = window.open(popPage,popName,popSize);
popWindow.focus(); }


function popvideo(desturl,winw,winh) {
var sWin;
  if (!((winw)&&(winh))) {
   winw = 640;
   winh = 480;
  }
  var scrw = 640;
  var scrh = 480;
  if ((document.layers)||(document.all)) {
    scrw = screen.width;
    scrh = screen.height;
  }
  winx = (scrw-winw)/2;
  winy = (scrh-winh)/2;
  if ((sWin) && (!sWin.closed)) { sWin.close(); }
  sWin = window.open(desturl,"_blank","toolbar=no,location=no,directories=no,resizable=no,scrollbars=no,status=yes,menubar=no,width="+winw+",height="+winh+",screenX="+winx+",screenY="+winy+",left="+winx+",top="+winy);
  return false;
}

function new_win(src) {

   window.open(src, "mywin", "width=550,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes");

}

function PopDaily(popPage)
{
		var popName = "card";
		var popSize = "width=400,height=550,resizable,scrollbars";
		popWindow = window.open(popPage,popName,popSize);
		popWindow.focus();
}




// *****************************************************************************************
// DOCUMENT: BuystreamTag.js
// DESCRIPTION:  Java Script to generate Merchant 3.5 content tags www.eHarlequin.com
// AUTHOR: Kevin Morton - kmorton@buystream.com or (800) 261-1726 ext.126
// DATE: March 21, 2002
// VERSION: 3.5
// APPLIES TO:  Implementation of Buystream Merchant 3.5 on www.eHarlequin.com
// MODIFICATIONS:
//	Mar.2002 - created
//  June.2002 - added code to handle various forms of home page
//            - added code to reject anything with an hp starting with 'harl'
// *****************************************************************************************



/********************************************************************
Function          	:  charValidityCheck(originalString)
Purpose             :  To ensure that the string is composed from a valid character set ($00 to $7f)
Parameters	       	:  Original String
Return		       	:  TRUE if valid, FALSE if invalid
Error				:
********************************************************************/

function charValidityCheck(originalString)
{
	var tOriginalString = new String(originalString);
	for(var x=0; x < tOriginalString.length; x++)
	{
		if( (tOriginalString.charCodeAt(x) >= 0) && (tOriginalString.charCodeAt(x) <= 127) )
		{
			continue;
		}
		else
		{
			return 0;
		}
	}
	return 1;
}

/********************************************************************
Function          	:  ASCIItoHEXconverter(originalString)
Purpose             :  To repalce special charaters with the corresponding HEX value
Parameters	       	:  Original String
Return		       	:  convertedString
Error				:
********************************************************************/

function ASCIItoHEXconverter(originalString)
{
	var tOriginalString = new String(originalString);
	var tConvertedString = new String("");
	var tCovertedChar = new  String("");
	var counter = new Number(0);
	for(var x=0; x < tOriginalString.length; x++)
	{
		if( ((tOriginalString.charCodeAt(x) >= 48) && (tOriginalString.charCodeAt(x) <= 57)) ||
			((tOriginalString.charCodeAt(x) >= 65) && (tOriginalString.charCodeAt(x) <= 90)) ||
			((tOriginalString.charCodeAt(x) >= 97) && (tOriginalString.charCodeAt(x) <= 122)) )

		{
			//valid character
			continue;
		}
		else
		{
			//invalid character
			//check to see if there is anything in the string before the special char is found
			if((tOriginalString.substring(0, x).length) > 0)
			{
				//the part of the string before the special char
				tConvertedString = tConvertedString.concat(tOriginalString.substring(counter, x));
			}
			counter = x + 1;
			tConvertedChar = HEXencoder(tOriginalString.substring(x,(x+1)));
			tConvertedString = tConvertedString.concat(tConvertedChar);
		}
	}
	//in case the last char is not a special char, get the last piece of the original string
	if(counter < (x + 1))
	{
		tConvertedString = tConvertedString.concat(tOriginalString.substring(counter, x));
	}
	return tConvertedString;
}

/********************************************************************
Function          	:  HEXencoder(specialChar)
Purpose             :  To repalce special charaters with the corresponding HEX value
Parameters	       	:  specialChar
Return		       	:  encoded string
Error				:
********************************************************************/

function HEXencoder(specialChar)
{
	var encodedChar = new String("");
	var tSpecialChar = new String(specialChar);
	switch(tSpecialChar.charCodeAt(0))
	{
		case 0:
		 	encodedChar = "$00";
			break;
		case 1:
			encodedChar = "$01";
			break;
		case 2:
		 	encodedChar = "$02";
			break;
		case 3:
			encodedChar = "$03";
			break;
		case 4:
		 	encodedChar = "$04";
			break;
		case 5:
			encodedChar = "$05";
			break;
		case 6:
		 	encodedChar = "$06";
			break;
		case 7:
			encodedChar = "$07";
			break;
		case 8:
		 	encodedChar = "$08";
			break;
		case 9:
			encodedChar = "$09";
			break;
		case 10:
		 	encodedChar = "$0a";
			break;
		case 11:
			encodedChar = "$0b";
			break;
		case 12:
		 	encodedChar = "$0c";
			break;
		case 13:
			encodedChar = "$0d";
			break;
		case 14:
		 	encodedChar = "$0e";
			break;
		case 15:
			encodedChar = "$0f";
			break;
		case 16:
		 	encodedChar = "$10";
			break;
		case 17:
			encodedChar = "$11";
			break;
		case 18:
		 	encodedChar = "$12";
			break;
		case 19:
			encodedChar = "$13";
			break;
		case 20:
		 	encodedChar = "$14";
			break;
		case 21:
			encodedChar = "$15";
			break;
		case 22:
		 	encodedChar = "$16";
			break;
		case 23:
			encodedChar = "$17";
			break;
		case 24:
		 	encodedChar = "$18";
			break;
		case 25:
			encodedChar = "$19";
			break;
		case 26:
		 	encodedChar = "$1a";
			break;
		case 27:
			encodedChar = "$1b";
			break;
		case 28:
		 	encodedChar = "$1c";
			break;
		case 29:
			encodedChar = "$1d";
			break;
		case 30:
		 	encodedChar = "$1e";
			break;
		case 31:
			encodedChar = "$1f";
			break;
		case 32:
		 	encodedChar = "$20";
			break;
		case 33:
			encodedChar = "$21";
			break;
		case 34:
		 	encodedChar = "$22";
			break;
		case 35:
			encodedChar = "$23";
			break;
		case 36:
		 	encodedChar = "$24";
			break;
		case 37:
			encodedChar = "$25";
			break;
		case 38:
			encodedChar = "$26";
			break;
		case 39:
		 	encodedChar = "$27";
			break;
		case 40:
			encodedChar = "$28";
			break;
		case 41:
			encodedChar = "$29";
			break;
		case 42:
		 	encodedChar = "$2a";
			break;
		case 43:
			encodedChar = "$2b";
			break;
		case 44:
			encodedChar = "$2c";
			break;
		case 45:
		 	encodedChar = "$2d";
			break;
		case 46:
			encodedChar = "$2e";
			break;
		case 47:
			encodedChar = "$2f";
			break;
		case 58:
			encodedChar = "$3a";
			break;
		case 59:
		 	encodedChar = "$3b";
			break;
		case 60:
			encodedChar = "$3c";
			break;
		case 61:
			encodedChar = "$3d";
			break;
		case 62:
			encodedChar = "$3e";
			break;
		case 63:
		 	encodedChar = "$3f";
			break;
		case 64:
			encodedChar = "$40";
			break;
		case 91:
			encodedChar = "$5b";
			break;
		case 92:
		 	encodedChar = "$5c";
			break;
		case 93:
			encodedChar = "$5d";
			break;
		case 94:
			encodedChar = "$5e";
			break;
		case 95:
			encodedChar = "$5f";
			break;
		case 96:
		 	encodedChar = "$60";
			break;
		case 123:
			encodedChar = "$7b";
			break;
		case 124:
		 	encodedChar = "$7c";
			break;
		case 125:
			encodedChar = "$7d";
			break;
		case 126:
			encodedChar = "$7e";
			break;
		case 127:
			encodedChar = "$7f";
			break;
		default:
			encodedChar = "$00";
			break;
	}
	return encodedChar;
}

/********************************************************************
Function          	:  getPageName
Purpose             :  Get the page name (e.g., index.htm) from the url
Parameters	       	:  url
Return		       	:  the file name of the page
Error				:
********************************************************************/

function getPageName(url)
{
	var start = -1;
	var end = -1;
	var pgName = new String("unknown");
	end = url.indexOf(".htm");
	if (end == -1)
	{
		return "index.htm";
	}
	start = url.lastIndexOf("/",end);
	if (start >= 0)
	{
		pgName = url.substring(start+1,end) + ".htm";
	}
	return pgName;
}

/********************************************************************
Function          	: getPath
Purpose             : Get the directory path from the url for the page.
Parameters	       	: url
Return		       	: The directory path of the page (from the url)
Error				:
********************************************************************/

function getPath(url)
{
	var start = -1;
	var end = -1;
	var path =  new String("unknown");

	start = url.indexOf("eharlequin.com");
	if (start == -1)
		return path;
	start = url.indexOf("/",start);
	if (start == -1)
		return path;

	end = url.indexOf(".htm");
	if (end == -1)
	{
		return path;
	}

	var path = new String("");
	end = url.lastIndexOf("/",end);
	if (end < start)
		return path;
	else if (end == start)
	{
		// no path
		path = "";
	}
	else
	{
		path = url.substring(start+1,end);
	}
	return path;
}

/********************************************************************
Function          	:  getHP
Purpose             :  Get the Buystream 'hierarchy path' from the
                       url (in preparation of generating the buystream
                       tag).
Parameters	       	:  url
Return		       	:  the hierarchy path (based on the directory
                       structure).
Error				:
********************************************************************/

function getHP(url)
{
	var path = new String(getPath(url));
	var hp = new String("");
	var segment = new String("");
	var start = 0;

	var i =0;
	for (i=0;i<path.length;i++)
	{
		if (path.charAt(i) == '/')
		{
			if (i > start)
			{
				segment = path.substring(start,i);
				segment = ASCIItoHEXconverter(segment);
				if (hp.length == 0)
				{
					hp = segment;
				}
				else
				{
					hp += "." + segment;
				}
			}
			start = i +1;
		}
	} // for
	if (i > start)
	{
		segment = path.substring(start,i);
		segment = ASCIItoHEXconverter(segment);
		if (hp.length == 0)
		{
			hp = segment;
		}
		else
		{
			hp += "." + segment;
		}
	}
	return hp;
}

/********************************************************************
Function          	:  getPageID
Purpose             :  Generate a unique id for the page in the given
                       url (in preparation of generating the buystream
                       tag).
Parameters	       	:  url
Return		       	:  the id of the page
Error				:
********************************************************************/

function getPageID(url)
{
	var id = new String(getPath(url));
	id = ASCIItoHEXconverter(id+"/");

	id += ASCIItoHEXconverter(getPageName(url));
	return id;
}

/********************************************************************
Function          	: getDisplayName
Purpose             : Generate a display name for the page in the given
                      url (in preparation of generating the buystream
                      tag). The display name is based in the title of
                      the page and the filename.
Parameters	       	: url
Return		       	: the display name
Error				:
********************************************************************/

function getDisplayName(url)
{
	var dn = new String(document.title);

	if (dn.length > 0)
	{
		dn = dn.toLowerCase();
		dn = dn.replace("eharlequin.com:","");
		dn = dn.replace("eharlequin.com :","");
	}
	if (dn.length > 50)
	{
		dn=dn.substring(0,50);
	}
	var pageName = getPageName(url);

	if (pageName.length > 0)
	{
        pageName = pageName.replace(".htm","");
		dn = pageName + " " + dn;
	}
	return ASCIItoHEXconverter(dn);
}

/********************************************************************
Function          	:  outputBuystreamTag
Purpose             :  Ouput the bm_identityform based on the url for
                       the page. This is basically a form with hidden
                       fields. Its a basic 'event tracking' tag (e.g,
                       page view).
Parameters	       	:
Return		       	:
Error				:

Example Tag:

	<!-- Buystream Merchant 3.5 code start -->');
	<form name="bm_identityForm">');
	   <input type=hidden name="na"
              value="uniqueid=hearts.htm&hp=magazine.blaze&dn=Hearts on Fire">
	</form>');

********************************************************************/

function outputBuystreamTag()
{
	var url = new String("");
	url = window.location.toString();
	url = url.toLowerCase();

	// check for the various forms of the home page
	if (url == "http://www.eharlequin.com")
	{
		url = "http://www.eharlequin.com/harl/index.htm";
	}
	else if (url == "http://www.eharlequin.com/")
	{
		url = "http://www.eharlequin.com/harl/index.htm";
	}

	// do some custom editing of the url
	url = url.replace("harl/life","harl/magazine");
	url = url.replace("harl/escapes","harl/magazine");

	var pageID = getPageID(url);
	if (pageID == "unknown")
	{
		return;
	}

	var hp;
	// check if this is a quiz page
	var isQuiz = url.indexOf("magazine/amusements/quiz");
	if (isQuiz != -1)
	{
		var quizName = getPageName(url);
		quizName = quizName.replace(".htm","");
		hp = "harl.quiz." + ASCIItoHEXconverter(quizName);
	}
	else
	{
		hp = getHP(url);
		if (hp == "unknown")
		{
			return;
		}
	}

	//If the hp does not begin with 'harl.' throw it out.
	var isValidHp = hp.indexOf("harl.");
	if (isValidHp != 0)
	{
		if (hp != "harl")
		{
		    return;
		}
	}

	var dn = getDisplayName(url);
	if (dn == "unknown")
		dn = pageID;

	document.writeln('<!-- Buystream Merchant 3.5 code start -->');
	document.writeln('<form name="bm_identityForm">');
	document.write('<input type=hidden name="na" value="uniqueid='+pageID);
	if (hp.length > 0)
	{
		document.write('&hp='+hp);
	}
	document.writeln('&dn='+dn+'">');
	document.writeln('</form>');

	document.writeln('<!-- Buystream Merchant code end -->');
// *******************************************************************************
//	alert("hp="+hp);
//	alert("id="+pageID);
//	alert("dn="+dn);
}


outputBuystreamTag();
