
/*
SMMiLe JavaScript Object Model
Version 1.0
By Daryl Beattie
Copyright 2000, ScreamingMedia

SAMPLE USAGE [note that "script" tag is broken as "sc ript" so that it does not end this script]:

The code blow goes in the <HEAD> section of your HTML file
replace "JSDir/ContentSetID" with your JavaScript file path and name

	<sc ript language="JavaScript" src="JSDir/ContentSetID.js"></sc ript>
	<sc ript language="JavaScript">
		if(typeof SMChosenContent != \'undefined\') {
			document.write("<scri" + "pt language=\"JavaScript\" src=\"JSDir/ContentSetID" + SMChosenContent + ".js\"></sc" + "ript>");
		}
	</scr ipt>

The JavaScript objects are modelled after the SMMiLe XML structure:

<content-set>
	<content>
		<article>
			<title>...</title>
			<metadata>...</metadata>
			<core>...</core>
			<body>...</body>
		</article>
	</content>
</content-set>

As for the JavaScript, it is structured like this:

contentSet[0](id, name, language, publishedDate, contents)
|--	contents[i](id, revisionId, type, language, role, article) 
	|
	|--	article(title, metadata, core, body)
		|
		|--	metadata(documentMetadata, publicationMetadata, structuralMetadata, subjectMetadata, relatedContentMetadata, processingMetadata)
		|	|--	documentMetadata(storage, publisherReleaseDate)
		|	|--	publicationMetadata(publicationName)
		|	|--	structuralMetadata()
		|	|--	subjectMetadata()
		|	|--	relatedContentMetadata()
		|	|--	processingMetadata()
		|
		|--	core(summaryHeadline, docAbstract, headline, author, copyright, dateLine, dateTime, type)

An example of using this object model to print out the body of the second
article is:

	document.write(SMContentSet[0].contents[1].article.body);

*/


function displayContentPage(url, contentNum) {
	window.location = url + "?SMContentIndex=" + contentNum + "&SMContentSet=" + 0;
}

function displayContentPage(url, contentNum, contentSetNum) {
	window.location = url + "?SMContentIndex=" + contentNum + "&SMContentSet=" + contentSetNum;
}

function getParamValue(matchString, defaultValue) {
	var thisURL = window.location.toString();
	var value = defaultValue;
	if ((thisURL.indexOf("?") != -1) &&
	    (thisURL.indexOf(matchString) != -1) &&
	    (thisURL.charAt(thisURL.indexOf(matchString) + matchString.length) != "&")) {
		start = thisURL.indexOf(matchString) + matchString.length;
		if (thisURL.indexOf("&", start) > -1) {
			value = thisURL.substring(start, (thisURL.indexOf("&", start)));
		}
		else {
			value = thisURL.substring(start, thisURL.length);
		}
	}
	if (value == "NaN") {
		value = devaultValue;
	}
	return value;
}

var SMChosenContent = Number(getParamValue("SMContentIndex=", -1));
var SMChosenContentSet = Number(getParamValue("SMContentSet=", 0));

function prettyDate(date) {
	var result;
	if (date.substring(5,7) == "01") {result = "January ";}
	else if (date.substring(5,7) == "02") {result = "February ";}
	else if (date.substring(5,7) == "03") {result = "March ";}
	else if (date.substring(5,7) == "04") {result = "April ";}
	else if (date.substring(5,7) == "05") {result = "May ";}
	else if (date.substring(5,7) == "06") {result = "June ";}
	else if (date.substring(5,7) == "07") {result = "July ";}
	else if (date.substring(5,7) == "08") {result = "August ";}
	else if (date.substring(5,7) == "09") {result = "September ";}
	else if (date.substring(5,7) == "10") {result = "October ";}
	else if (date.substring(5,7) == "11") {result = "November ";}
	else {result = "December ";}
	if (date.charAt(8) == "0") {result += date.charAt(9);}
	else {result += date.substring(8,10);}
	return result + ", " + date.substring(0,4);
}

// Metadata sub-type element objects.
function MakeDocumentMetadata(myStorage, myPublisherReleaseDate) {
	this.storage = myStorage;
	this.publisherReleaseDate = myPublisherReleaseDate;
}
function MakePublicationMetadata(myPublicationName) {
	this.publicationName = myPublicationName;
}
function MakeStructuralMetadata() { }
function MakeSubjectMetadata() { }
function MakeRelatedContentMetadata() { }
function MakeProcessingMetadata() { }

// Metadata element object (made up of the sub-types).
function MakeMetadata(myDocumentMetadata, myPublicationMetadata, myStructuralMetadata, mySubjectMetadata, myRelatedContentMetadata, myProcessingMetadata) {
	this.documentMetadata = myDocumentMetadata;
	this.publicationMetadata = myPublicationMetadata;
	this.structuralMetadata = myStructuralMetadata;
	this.subjectMetadata = mySubjectMetadata;
	this.relatedContentMetadata = myRelatedContentMetadata;
	this.processingMetadata = myProcessingMetadata;
}

// Core element object
function MakeCore(mySummaryHeadline, myAbstract, myHeadline, myAuthor, myCopyright, myDateLine, myDateTime, myType) {
	this.summaryHeadline = mySummaryHeadline;
	this.docAbstract = myAbstract;
	this.headline = myHeadline;
	this.author = myAuthor;
	this.copyright = myCopyright;
	this.dateLine = myDateLine;
	this.dateTime = myDateTime;
	this.type = myType;
}

// Article element object
function MakeArticle(myTitle, myMetadata, myCore, myBody) {
	this.title = myTitle;
	this.metadata = myMetadata;
	this.core = myCore;
	this.body = myBody;
}

// Content element object
function MakeContent(myId, myRevisionId, myType, myLanguage, myRole, myArticle) {
	this.id = myId;
	this.revisionId = myRevisionId;
	this.type = myType;
	this.language = myLanguage;
	this.role = myRole;
	this.article = myArticle;
}

// Content-set master element object
function MakeContentSet(myId, myName, myLanguage, myPublishedDate, myContents) {
	this.id = myId;
	this.name = myName;
	this.language = myLanguage;
	this.publishedDate = myPublishedDate;
	this.contents = myContents;
}

{ // This block intializes the data objects.

	var Index = -1;
	if (typeof SMContentSet == "undefined") {
		var SMContentSet = new Array();
	}
	var contents = new Array();
//////////////////////// This section is made PER CONTENT (because the actual data is written in here)

	
	documentMetadata = new MakeDocumentMetadata('internal', '2008-05-03T12:34:28');
	publicationMetadata = new MakePublicationMetadata('International Herald Tribune');

	title = 'Phone Makers Face Tough Arena';
	metadata = new MakeMetadata(documentMetadata, publicationMetadata, '', '', '', '');

	core = new MakeCore(
		'Phone Makers Face Tough Arena',
		'Providers of wireless phone services are facing a tough environment. Conditions may be even tougher for makers of the phones themselves.',
		'Phone Makers Face Tough Arena',
		'Conrad de Aenlle The New York Times Media Group',
		'(C) 2008 International Herald Tribune. via ProQuest Information and Learning Company; All Rights Reserved',
		'',
		'',
		''
		);

	article = new MakeArticle(title, metadata, core, '');

	contents[++Index] = new MakeContent(
		'bhsuper_2008_05_04_INHT_0000-1180-KEYWORD.Missing',
		'01210006939476',
		'article',
		'en-US',
		'',
		article
		);

		
	documentMetadata = new MakeDocumentMetadata('internal', '2008-05-02T15:39:55');
	publicationMetadata = new MakePublicationMetadata('Associated Press');

	title = 'Court supports FCC deadline for Sprint to vacate channels';
	metadata = new MakeMetadata(documentMetadata, publicationMetadata, '', '', '', '');

	core = new MakeCore(
		'Court supports FCC deadline for Sprint to vacate channels',
		'WASHINGTON - A federal appeals court on Friday said regulators were reasonable in sticking to a June deadline that requires Sprint Nextel Corp. to vacate some wireless channels that will be used by public safety agencies.',
		'Court supports FCC deadline for Sprint to vacate channels',
		'By DIBYA SARKAR (AP Business Writer)',
		'Copyright 2008 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.',
		'',
		'',
		''
		);

	article = new MakeArticle(title, metadata, core, '');

	contents[++Index] = new MakeContent(
		'ap_2008_05_02_ap.online.all_D90DNPL00_news_ap_org.anpa',
		'01210006939476',
		'article',
		'en-US',
		'',
		article
		);

		
	documentMetadata = new MakeDocumentMetadata('internal', '2008-05-12T10:45:18');
	publicationMetadata = new MakePublicationMetadata('Associated Press');

	title = 'Sprint affiliate sues to block Clearwire deal';
	metadata = new MakeMetadata(documentMetadata, publicationMetadata, '', '', '', '');

	core = new MakeCore(
		'Sprint affiliate sues to block Clearwire deal',
		'KANSAS CITY, Mo. - An affiliate of Sprint Nextel Corp., iPCS Inc., said Monday it is seeking to block Sprint from forming a wireless broadband company with Clearwire Corp.',
		'Sprint affiliate sues to block Clearwire deal',
		'By DAVID TWIDDY (AP Business Writer)',
		'Copyright 2008 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.',
		'',
		'',
		''
		);

	article = new MakeArticle(title, metadata, core, '');

	contents[++Index] = new MakeContent(
		'apdigital_2008_05_12_ap.online.high-tech_D90K6DIG0_news_ap_org.anpa',
		'01210608664234',
		'article',
		'en-US',
		'',
		article
		);

		
	documentMetadata = new MakeDocumentMetadata('internal', '2008-05-09T09:04:00');
	publicationMetadata = new MakePublicationMetadata('Business Wire');

	title = 'More Than 550 Million GPS-Enabled Handsets Will Ship by 2012, Says ABI Research';
	metadata = new MakeMetadata(documentMetadata, publicationMetadata, '', '', '', '');

	core = new MakeCore(
		'More Than 550 Million GPS-Enabled Handsets Will Ship by 2012, Says ABI Research',
		'LONDON, May 09, 2008 (BUSINESS WIRE) -- In the wake of personal navigation devices\' success, cellular carriers have started to offer on-board and off-board navigation solutions, as well as a range of LBS (Location Based Services) such as friend finder...',
		'More Than 550 Million GPS-Enabled Handsets Will Ship by 2012, Says ABI Research',
		'',
		'Copyright Business Wire 2008',
		'LONDON, May 09, 2008 (BUSINESS WIRE)',
		'',
		'pr'
		);

	article = new MakeArticle(title, metadata, core, '');

	contents[++Index] = new MakeContent(
		'comtex_2008_05_09_bw_0000-7343-abi-research',
		'01210606039961',
		'article',
		'en-US',
		'',
		article
		);

		
	documentMetadata = new MakeDocumentMetadata('internal', '2008-05-12T08:12:01');
	publicationMetadata = new MakePublicationMetadata('McClatchy-Tribune Information Services -- Unrestricted');

	title = 'Video resumes? Not there yet: Not quite.';
	metadata = new MakeMetadata(documentMetadata, publicationMetadata, '', '', '', '');

	core = new MakeCore(
		'Video resumes? Not there yet: Not quite.',
		'Only a couple of years ago, Internet trollers were predicting that video resumes were the wave of the future for job applicants.',
		'Video resumes? Not there yet: Not quite.',
		'Sara Kennedy',
		'Copyright (C) 2008 The Bradenton Herald, Fla.',
		'MANATEE, May 12, 2008 (The Bradenton Herald - McClatchy-Tribune Information Services via COMTEX) --',
		'',
		''
		);

	article = new MakeArticle(title, metadata, core, '');

	contents[++Index] = new MakeContent(
		'comtex_xml_2008_05_12_comtex_comtex_071307_4945925364916935015',
		'01210608755047',
		'article',
		'en-US',
		'',
		article
		);

		
	

//////////////////////// End PER ARTICLE section

	contentSetId = '9434_EmployTrends';
	contentSetName = 'EmployTrends';
	contentSetLanguage = '';
	contentSetPublishedDate = '2008-05-12T11:12:48';

	id = '9434_EmployTrends';
	contentType = '';

} // End data initialization block.

if (typeof ContentIndex == "undefined") {
	ContentIndex = -1;
}

SMContentSet[++ContentIndex] = new MakeContentSet(contentSetId, contentSetName, contentSetLanguage, contentSetPublishedDate, contents);
