var cookieExpire = 12 * 30 * 24 * 60 * 60 * 1000;    // 1 year
var dir = "";
var Qid = "0305";
var surveyTitle = '<div class=\"H3\">May Poll</div>';
var surveyQuestion = 'Do you favor new laws to:';
var surveyAnswers = new Array (
						"Protect short people from discrimination in general.",
						"Provide Equal Employment Opportunities only.",
						"No new laws needed.");
						
	var quotes = new Array ("It's not the size of the dreamer, it's the size of the dream.|Josh Ryan Evans|448|",
	"Even the smallest person can change the course of the future.|J. R. R. Tolkien|414|",
    "Aunt Vorthys: \"A nice young man ... A pity he's so short.\"<br>Lady Ekaterin: \"He's not so short ... He's just concentrated\"|Lois McMaster Bujold, in <I>Komarr</I>|0|",
	"I don't want to play Charlton Heston parts, but there are a lot of roles I can do.|Michael Dunn|218|",
	"Sometimes I think someone upstairs saved me from being ordinary.|Michel Petrucciani|435|",
	"It's not the size of the dog in the fight, its the size of the fight in the dog.|Mark Twain|0|",
	"A man can be short and dumpy and getting bald but if he has fire, women will like him.|Mae West|22|",
	"Good things, when short, are twice as good.|Tom Stoppard|0|",
	"You can often measure a person by the size of his dream.|Robert H. Schuller|0|",
	"I'm very short so I always say, 'If you haven't got it, you've got to fake it, man'.|Emma Bunton|0|",	
	"America is not like a blanket-one piece of unbroken cloth, the same color, the same texture, the same size. America is more like a quilt-many patches, many pieces, many colors, many sizes, all woven and held together by a common thread.|Jesse Jackson|0|",
	"There are no great things, only small things with great love. Happy are those.|Mother Theresa|116|",
	"At 34 she is an extremely beautiful woman, lavishly endowed by nature with a few flaws in the masterpiece: She has an insipid double chin, her legs are too short and she has a slight potbelly. She has a wonderful bosom, though.|Richard Burton|0|",
	"Short people are human and not in need of a cure!|Chris Hamre|0|",
	"If you haven't got it. Fake it! Too short? Wear big high heels, but do practice walking!|Victoria Beckham|0|",
	"If size did matter, the dinosaurs would still be alive.|Wendelin Wiedeking|0|",
	"One raindrop raises the sea.|James Gurney, <I>Dinotopia</I>|0|", 
	"The worst thing is not taking the chance for yourself. No Matter your Height...or pursuit...always Aim High!|Isobella Jade|0|",
    "Do we call a short man a boy, or a small dog a cat? No! This is a mountain, our mountain, and if it needs to be a thousand feet, then by God let's make it a thousand feet!|Colm Meaney as Morgan the Goat in <I>The Englishman Who Went Up a Hill But Came Down a Mountain</I>|0|",
	"It's been hard to be a show in L.A. and be trendsetting, because the fashions are in New York... Not to mention that most actresses are all, give or take, the same size, between five-two and five-five, and 95 to 125 pounds.|Sarah Michelle Gellar|0|",
    "Short people are human beings too.  Don't mock them just because they were born short.  They did not choose to be short.|Steven B. Goldsmith|0|",
	"Good things come in small packages.|Unknown|0|",
	"Short people get rained on last.|Unknown|0|",
	"Attitude determines altitude.|Unknown|0|",
	"Size matters not.  Look at me.  Judge me by my size, do you?  Hmm?  And well you should not.|Master Yoda in <I>The Empire Strikes Back</I>|0|"

	);
						

var home = 'http://www.shortsupport.org' ;

browser = navigator.appName + parseInt(navigator.appVersion);
	
HomeUp = new Image();
ResourcesUp = new Image();
HealthUp = new Image();
NewsUp = new Image();
LibraryUp = new Image();
ResearchUp = new Image();
WhowhoUp = new Image();
MediaUp = new Image();
EssaysUp = new Image();


HomeOver = new Image();
ResourcesOver = new Image();
HealthOver = new Image();
NewsOver = new Image();
LibraryOver = new Image();
ResearchOver = new Image();
WhowhoOver = new Image();
MediaOver = new Image();
EssaysOver = new Image();


if(window.event + "" == "undefined") event = null;
function HM_f_PopUp(){return false};
function HM_f_PopDown(){return false};
popUp = HM_f_PopUp;
popDown = HM_f_PopDown;
	
var dir;


 
function importJs(jsFile) {
	if ( imported ) return;
	var scriptElt = document.createElement('script');
	scriptElt.type = 'text/javascript';
	scriptElt.src = jsFile;
	document.getElementsByTagName('head')[0].appendChild(scriptElt);
	imported = true;
}
 		
function Header(level, h, section) {
	
	var title = new Array();
	var url   = new Array();
	var linkName = new Array();

	var buttons = 8;
	var border = 0;
	
	switch (level)
	{
		case 0:	dir='./';
			break;
			
		case 1:	dir='../';
			break;
			
		case 2:	dir='../../';
			break;
					
	}
	
	titleHome = 'Home';	
	title[1] = 'Resources';
	title[2] = 'Health';
	title[3] = 'News';
	title[4] = 'Library';
	title[5] = 'Research';
	title[6] = 'Whowho';
	title[7] = 'Media';
	title[8] = 'Essays';


	urlHome = 'index.html';
	url[1] = 'Resources/index.html';
	url[2] = 'Health/index.html';	
	url[3] = 'cgi-bin/news_index.cgi';
	url[4] = 'cgi-bin/book_index.cgi';
	url[5] = 'Research/index.html';
	url[6] = 'cgi-bin/whowho_list.cgi';	
	url[7] = 'TheMedia/index.html';
	url[8] = 'Essays/index.html';

	
	HomeUp.src = dir + 'gif/Buttons/HomeUp.gif' ; 
	ResourcesUp.src = dir + 'gif/Buttons/ResourcesUp.gif' ; 
	HealthUp.src = dir + 'gif/Buttons/HealthUp.gif' ; 	
	NewsUp.src = dir + 'gif/Buttons/NewsUp.gif' ;
	LibraryUp.src = dir + 'gif/Buttons/LibraryUp.gif' ; 	
	ResearchUp.src = dir + 'gif/Buttons/ResearchUp.gif' ;
	WhowhoUp.src = dir + 'gif/Buttons/WhowhoUp.gif' ;
	MediaUp.src = dir + 'gif/Buttons/MediaUp.gif' ; 
	EssaysUp.src = dir + 'gif/Buttons/EssaysUp.gif' ; 
	
	HomeOver.src = dir + 'gif/Buttons/HomeOver.gif' ; 
	ResourcesOver.src = dir + 'gif/Buttons/ResourcesOver.gif' ; 
	HealthOver.src = dir + 'gif/Buttons/HealthOver.gif' ; 	
	NewsOver.src = dir + 'gif/Buttons/NewsOver.gif' ; 
	LibraryOver.src = dir + 'gif/Buttons/LibraryOver.gif' ; 
	ResearchOver.src = dir + 'gif/Buttons/ResearchOver.gif' ; 
	WhowhoOver.src = dir + 'gif/Buttons/WhowhoOver.gif' ; 	
	MediaOver.src = dir + 'gif/Buttons/MediaOver.gif' ; 
	EssaysOver.src = dir + 'gif/Buttons/EssaysOver.gif' ; 	

	Blank = '<img src="' + dir + 'gif/Buttons/Blank.gif" Border=0>' ;
	//Bar   = '<img src="' + dir + 'gif/Buttons/Bar.gif" Border=0>' ;
	thisGif = '<img src="' + dir + 'gif/Buttons/' + titleHome + 'Up.gif" name=' + titleHome + 'Link Border=0>' ;
	Bar = '<a href="' + dir + urlHome + '" onMouseOver="' + titleHome + 'Link.src=' + titleHome + 'Over.src" onMouseOut="' + titleHome + 'Link.src=' + titleHome + 'Up.src">' + thisGif + '</a>' ;
	
	Logo   = '<a href="' + dir + 'index.html"><img src="' + dir + 'gif/Buttons/sps.gif" align=right width=100 Border=0></a>' ;
	
	Header = '<div id="pageTitle" class="' + h + '">' + section + '</div>';
 
	document.writeln ('<table width=100% border=' + border + '><tr><td valign=bottom width=30%>' + Bar + '</td> <td>' + Header + '</td> <td alight=right width=10%>' + Logo + '</td></tr></table>');
	document.writeln ('<table cellpadding=0 cellspacing=0 border=' + border + ' align=left>');
	document.writeln ('<tr><td valign="top">');
	//document.writeln ('<tr><td colspan=2>'  + Bar + '</td> <td>' + Logo + '</td></tr><tr><td valign="top">');

	document.writeln ('<table  cellpadding=0 cellspacing=0  border=' + border + ' valign="top" >');

	/*
	 *	Write two blank lines for aesthetics
	 */
	for (i=1; i <= 2; i++)
	{
		document.writeln ('<tr><td width="150">&nbsp;</td></tr>');
	}
	
	/*
	 *	Write out each button
	 */
	for (i=1; i <= title.length-1; i++)
	{
		linkName[i] = title[i] + 'Link'
		
		thisGif = '<img src="' + dir + 'gif/Buttons/' + title[i] + 'Up.gif" name=' + linkName[i] + ' Border=0>' ;
//alert ('thisGif done')

		text = '<tr><td width="130"><a href="' + dir + url[i] + '" onMouseOver="' + title[i] + 'Link.src=' + title[i] + 'Over.src; HM_f_PopUp(\'elMenu' + i + '\',event)" onMouseOut="' + title[i] + 'Link.src=' + title[i] + 'Up.src; HM_f_PopDown(\'elMenu' + i + '\')">' + thisGif + '</a></td></tr>' ;
//alert ('i= ' + i + ',  text=' + text);
		document.writeln (text);
	}
	/*
	 *	Write search
	 
	var style;
	if ( browser == "Netscape4" )
	{
	 	style = ' style="font-size: 8pt" ';
	} else {
	 	style = '';
	}*/
	
	document.writeln ('<tr><td><P><br><div id="searchForm"></div></td></tr>\n');
	
	/*
	 *	Write Notification option
	 */

	if ( false ) // navigator.userAgent.indexOf("Q312461") != -1 )
	{
		document.writeln ('<tr><td><a href="javascript:mailme()">Notify Me When<br>This Page Changes</a></td></tr>');
	}


	/*
	 *	End header table and start body table, to be closed later by a call to Footer
	 */
	document.writeln ('</table>');
	document.writeln ('</td><td></td><td valign="top"><div id="searchcontrol"></div></td><td valign="top">\n<div id="normaltext"><P>&nbsp;<P>');

  
}


function ratestore(shop, gender)
{

	cgi = '/cgi-bin/ratestore_form.cgi?shop=' + shop + '&gender=' + gender;
	options = setWindowOptions(500, 550);

	window.open(cgi, "RateStore", options);
}



function mailme()
{
	var email, newEmail;
	var page;

	var intro = 'Short Persons Support: '
	var cgi;
	var options = "toolbar=no, menubar=no, location=no, directories=no, status=no, resizable=yes, scrollbars=yes, width=450, height=400";

	/*
	 *	Get page and title characteristics and pass on to cgi scripts.
	 */
	page  = '' + document.location;
	title = '' + document.title;
	page = page.substring(home.length, page.length);
	page = massagePage(page);
	title = escape(title.substring(intro.length, title.length));

	/*
	 *	Ask for email if we don't already have it
	 */
	email = getCookie("sPs_email");
	if ( email == null )
	{
		/*
		 *	Cookie not yet set.  Ask and set
		 */
		cgi = home + '/cgi-bin/mailme_email_form.cgi?page=' + page + '&title=' + title;
	} else {
		cgi = home + '/cgi-bin/mailme.cgi?email=' + email + '&page=' + page + '&title=' + title;
	}
	window.open(cgi, "Notification", options);
}

/*
 *	This function massages real URLS to that entries in the mailme and hierarchy tables are 
 *	easier to match.
 */
function massagePage(page)
{
	var options = new Array ("orderby=", "direction=", "sortby=", "textonly=");
	var i;		 // Simple for loop counte
	var j, k; 	 // containers of indexOf.
	var oldPage = page;  // used only for debugging
	
	if ( getCookie("sPs_email") == "sgoldsmith@goldkeys.com" )
	{
		debug = true;
	} else {
		debug = false;
	}
	
	/*
	 *		Remove trailing index.html so all directories look the same whether or 
	 *		not index.html was part of the page used in the URL.
	 */
	if ( (j = page.indexOf("index.html")) != -1 )
	{
		page = page.substring(0, j);
	}

	/* if ( (j  = page.indexOf("_")) != -1)
	{
		k = page.indexOf(".cgi");
		page = page.substring(0, j) + page.substring(k , page.length);
	} */
	
	/*
	 *	Remove portions or url that point within a page.  This is only used in whowho.
	 */
	if ( (j = page.indexOf("#")) != -1)
	{
		page = page.substring(0, j) ;
	}
	page = page + "&" ; // temporarily add "&" at end so searchs work well, then remove it later
	
	/*
	 *	remove each option that we do not care about (e.g, sorting options)
	 */
	for (i=0; i < options.length; i++)
	{
		if ( (j = page.indexOf(options[i])) != -1 )
		{
			k = page.indexOf("&", j) ;
			page = page.substring(0, j) + page.substring(k+1, page.length);
		}
	}
	page = page.substring(0, page.length-1); // remove "&" that we added previously
	
	if (debug) alert (oldPage + " -> " + page);
	return (escape(page));
}


function getCookie(name) {
	var result = null;
	var myCookie = " " + document.cookie + ";";
	var searchName = " " + name + "=";
	var startOfCookie = myCookie.indexOf(searchName);
	var endOfCookie;
	if (startOfCookie != -1) {
		startOfCookie += searchName.length;
		endOfCookie = myCookie.indexOf(";", startOfCookie);
		result = unescape(myCookie.substring(startOfCookie, endOfCookie));
	}

	return result;
}

function setCookie(name, value)
{
	var expDate = new Date();
	expDate.setTime(expDate.getTime() + cookieExpire );

	document.cookie = name + "=" + escape(value) + "; expires=" + expDate.toGMTString() + "; path=/";	

}

function checkSetEmail(form) 
{
	var email = form.email.value;

	if (email.indexOf('@') == -1 || email.indexOf('.') == -1)
	{
		alert ('\'' + email + '\' does not appear to be a valid email address.\nPlease enter an email address in the form of youremail@company.com     ');
		return false;
	} else {
		setCookie ('sPs_email', email);
		return true;
	}
}

function setWindowOptions(w,h)
{

	
	height = "";
	width = "";
	if (true || browser == "Netscape5" || browser == "Netscape6" )
	{
		height = ", height=" + h;
		width = ", width=" + w;
	}

	/* if (browser == "Netscape4")
	{
		alert ("sPs Warning:  This feature may not work well with Netscape 4.x.\n We recommend Netscape 6 or Microsoft Internet Explorer.");
	} */
	
	return ("toolbar=no, menubar=no, location=no, directories=no, status=no, resizable=yes, scrollbars=yes" + width +  height);
}


function survey()
{
	var i;
	
	var options = setWindowOptions(550, 530);
	var cgi = "/cgi-bin/survey_past.cgi?current=0306";
	//alert ("options = " + options);
	
	document.writeln('<table align="right" width=135 bgcolor="#d9ffe8" rules=rows border=1 bordercolor="Gray" cellspacing=0><tr><td colspan="2">'); // + surveyTitle);
	document.writeln("The monthly poll is going on hiatus for a while.<P>");
	document.writeln("If you have any suggestions for future polls, please let us know.<P>");
	document.writeln("<a href=\"javascript:openWin('" + cgi + "', 'Poll', '" + options + "')\">Show Past Results</a><P></td></tr></table>" );


	return;
}

function popSurvey()
{
	var i;
	
	var options = setWindowOptions(550, 530);
	var cgi = "/cgi-bin/survey_past.cgi?current=0306";
	openWin(cgi, 'Poll', options);

	return;
}


function surveyCookie (form, Qid, options)
{
	var oldQid = getCookie("sPs_poll");
	var newQid;
	
	form.errno.value = 0;
	if ( oldQid == Qid )  
	{
		form.errno.value = 1;
		window.open('', 'Poll', options);
		return true;
	} else {
		setCookie ('sPs_poll', Qid);
		newQid = getCookie("sPs_poll");
		if ( newQid == null || newQid != Qid )
		{
			alert ("Sorry, the poll feature only works if cookies are allowed.");
			return false;
		} else {
			window.open('', 'Poll', options);
			return true;
		}
	}
}
		
function openWin(url, name, options)
{
	window.open(url, name, options);
}

function quote()
{

	
	var millInDay, day, index, quote, speaker, whowho;
	var href, end, previous;
	var sep = new Array(3);					
	millInDay = 24 * 60 * 60 * 1000;

	day =  Math.floor ( new Date().getTime() / millInDay )
	index = day % quotes.length;
	//alert ("day = " + day + ", index = " + index + "length = " + quotes.length);	
	//alert ("quote = " + quotes[index]);
	for (i=0; i < sep.length; i++)
	{
		if ( i == 0)
		{
			previous = 0;
		} else {
			previous = sep[i-1] + 1;
		}
		sep[i] = quotes[index].indexOf("|", previous);
		//alert ('sep[' + i + '] = ' + sep[i]);
	}
	
	quote   = quotes[index].substring(0, sep[0]);
	speaker = quotes[index].substring(sep[0]+1, sep[1]);
	whowho = quotes[index].substring(sep[1]+1, sep[2]);
	
	if ( whowho != 	0 )
	{
		href = '<a href="/cgi-bin/whowho_bio.cgi?seq=' + whowho + '"><font color=blue>';
		end = '</font></a>';
	} else {
		href = "";
		end = "";
	}
	document.writeln('<TABLE align="center" border="0" cellspacing="-10"><TR><TD><font color="purple"><I>' + quote + '</I></font></TD></TR>');
	document.writeln('<TD align="right">--&nbsp;' + href + speaker + end + '&nbsp;&nbsp;</TD></TR></TABLE><P>');

}

var dir;
 
function OnLoad() 
{      

	
   // alert("OnLoad starts");
	// Create a search control      
	var searchControl = new GSearchControl();
	
    // Add in set of searchers
	var webSearch = new GwebSearch();
	webSearch.setSiteRestriction("shortsupport.org", "",  "field __QUERY__ and  __HL__");
	webSearch.setUserDefinedLabel("Short Persons Support");

	var options = new GsearcherOptions();
	options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
	searchControl.addSearcher(webSearch, options);     
      
	// create a drawOptions object
	var drawOptions = new GdrawOptions();

	// tell the searcher to draw itself in linear mode
	
	drawOptions.setSearchFormRoot(document.getElementById("searchForm"));
	drawOptions.setDrawMode(GSearchControl.DRAW_MODE_LINEAR);
	
	searchControl.setResultSetSize(GSearch.LARGE_RESULTSET );
	searchControl.setNoResultsString("Your search did not match any documents")
	searchControl.draw(document.getElementById("searchcontrol"), drawOptions);
	searchControl.setSearchCompleteCallback(this, OnSearchComplete);
	
	if ( getCookie("googleSearchString") )
	{
		searchControl.input.value = getCookie("googleSearchString");
	}
	
	searchCol = document.getElementById("searchcontrol");
	searchCol.style.width = "0px";
	searchCol.innerHTML = "";

}

function OnSearchComplete(sc, searcher) {

	normalText = document.getElementById("normaltext");
	normalText.innerHTML = ""; 
	
	var searchControl = document.getElementById("searchcontrol");
	searchControl.style.width = ""; 
	
	var myresult = "<P><br><P><strong>Search Results:</strong><br>\n"; 
	
	var label = "Short Persons Support: ";
	var spsUrl = "shortsupport.org";
	
	
  	if ( ! searcher.results || searcher.results.length == 0) {
		searchControl.innerHTML =  "<P><br><P><strong>No Search Results Found</strong><P>";
    	return;
	}
	
	setCookie("googleSearchString", sc.input.value);
	
    for (var i = 0; i < searcher.results.length; i++) {
    	var result = searcher.results[i];
	    var url = result.unescapedUrl;
		var title = result.title;
	    if (result.unescapedUrl.indexOf("whowho_list") != -1 && result.unescapedUrl.indexOf("orderby=") != -1 ) continue;

	    if ( title.indexOf(label) != -1 ) {
	      	title = title.substring(label.length);
	    }
	  
	  	if ( url.indexOf("/News/") != -1 )  {
	      	title = "News: " + title;
	  	}
	
	  	var orderby = url.indexOf("&orderby=");
	  	if ( orderby != -1 )
	  	{
	      	url = url.substring(0,orderby);
	  	}
	  
	   	var orderby = url.indexOf("&sortby=");
	  	if ( orderby != -1 )
	  	{	
	      url = url.substring(0,orderby);
	  	}
		
		url =  replace(url, "/cgi/", "/cgi-bin/");
		
		var index = url.indexOf(spsUrl);
		var relativeUrl = url;
		if ( index != -1 )
		{
			relatveUrl = url.substring(index + spsUrl.length);
		}
		
		myresult += "\n";
	  	myresult += "<a href=\"" + relatveUrl + "\"><strong>" + title + "</strong></a><br>";
	  	myresult += result.content + "<br>\n"
	  	myresult += "<a href=\"" +relatveUrl + "\">" + url + "</a><br>";
	  	myresult += "<P>";
    }  // end of search results loop
	
	myresult += "</UL><a href=\"" + searcher.gwsUrl + "\">More ...</a>";
	searchControl.innerHTML = myresult;
	var pageTitle  = document.getElementById("pageTitle");
	pageTitle.innerHTML = "Search Results";
	pageTitle.style.fontSize = "16pt";
	

}

function replace(str, from, to) {
	var pos1 = str.indexOf(from);
	if ( pos1 == -1 ) return str;
	var rtn = str.substring(0,pos1) + to + str.substring(pos1 + from.length);
	return rtn;
}

function getMyresult()
{
	document.writeln(myresult);
}

function Footer(url, title)
{

	hdir = '<a href="' + dir + 'Misc/';
	
	if (url == "#REF")
	{
		url = document.referrer;
	}
	
	if (url != '')
	{
		document.writeln ('<center><P>&nbsp;<P><a href="' + url + '">Return to ' + title + '</a></center>' );
	}
	
	document.writeln ('<center><P>&nbsp;<P>');
	document.write (hdir + 'site.html">Site Map</a>&nbsp;&nbsp;|&nbsp;&nbsp;');
	document.write (hdir + 'aboutus.html">About Us</a>&nbsp&nbsp;|&nbsp;&nbsp;');
	document.write (hdir + 'faq.html">FAQ</a>&nbsp;&nbsp;|&nbsp;&nbsp;');
	document.write (hdir + 'contactus.html">Contact Us</a>&nbsp&nbsp;|&nbsp;&nbsp;');
	document.write ("<a href='javascript:ruler()'>in/cm Ruler</a>&nbsp&nbsp;|&nbsp;&nbsp;");
	document.write (hdir + 'glossary.html">Glossary</a>');
	document.write ('<P>&#169; Copyright 2000 - 2012, Short Persons Support <br><a href="mailto:editor@shortsupport.org">editor@shortsupport.org</a></center>');

	document.writeln ('</DIV></td></tr></table></body></html>');
	GSearch.setOnLoadCallback(OnLoad);
	
}

function ruler()
{
	var options = "toolbar=no, menubar=no, location=no, directories=no, status=no, resizable=yes, scrollbars=no, width=185, height=635";

	window.open(dir + "Misc/ruler.gif", "Ruler", options);
}

