/* This is the script for all articles
*/

var gbSoftApproachHasTopAd
var gsSoftApproachSearchBoxPrefix

/* 

To write the google ad and the layout
- bIsBottom: Bottom instead of the top ad, no effect for Link Unit
- bIsCategory: See getPath()
- bIsLinkUnit: The Link Unit ad instead of the regular text ad.  This overwrite bIsBottom.
- bNoAlternativeURL: No alternative page

- bNoSearchBox: No google search box
- sSearchBoxPrefix: Specify path for the software search's file, such as visio_

Using this function:
- After this function is executed, google will write the ad HTML Starting from the bottom of the written code, therefore:
1. Tip will always be at the top
2. This code needs to be added to the HTML page:


This is obsolete: Table to the left works better.  Logic added to switch the display back to left
See below
<table align="left">

<table>
<tr>
<td>
<div>
<script>
writeGoogleAd(1 for bottom or missing for top)
</script>
</div>
</td>
</tr>
</table>

<p>&nbsp;</p>

where </div> is needed so that the ad won't be displayed after the div display and <div> is needed so that FrontPage won't take </div> away.

See also: 
- writeGooleLinkAd() for the link unit ad
- writeGoogleAdiFrame() for the dedicated iFrame Ad, NEED to sync parm changes
- bIsBottom: Use -1 to keep the Ad, use 1 or true to show the search box (Default)
haibo
*/
function writeGoogleAd(
	bIsBottom, 
	bIsCategory, 
	bIsLinkUnit, 
	bNoAlternativeURL, 
	bNoSearchBox,
	sSearchBoxPrefix)
{

// For free reading, use the link ad as top, top one hide
var sURL = location.href
if(sURL.indexOf('Articles') >= 0)
{
if(!bIsBottom && !bIsLinkUnit)
{
return 
}
}

// Aug 20, 2006
showAd(bIsBottom, sSearchBoxPrefix)



return



/* May 15, 2006==============================================
 Point to the top

June 15, 2006
Add search and link ad
*/
if(bIsBottom)
{
var sHTML = "<p>" + 
"<a href='#top'><big><b><font color='#ff0000'><u>Click Here for More Information...</u></font></b></big></a>" + 
"<br><iframe src='../../ifrm-link-and-search-bottom.htm' width=220 height=180 scrolling=no frameborder=0></iframe>" +
"</p>\n" 

// Disable the google search box 
document.write(sHTML)
return
}

/* May 15, 2006
For the top one, push the content display to the right to leave more room
*/
if(!bIsBottom && !bIsCategory && !bIsLinkUnit)
{
document.write("\n<table width=300><tr><td>&nbsp;</td></tr></table>\n")
return
}


/* May 15, 2006
1. Use one ad only, no bottom or link ad
2. Use the link unit position to write one ad
*/
if(!bIsLinkUnit)
{
return
}
else
{
bIsLinkUnit = false
bIsBottom = false
}



var iWidth = getAdWidth(bIsBottom, bIsLinkUnit)
var iHeight = getAdHeight(bIsBottom, bIsLinkUnit) 


/* May 15, 2006
Ad moved to top already
*/
//iWidth = 0
//iHeight = 0

// See comment for this variable below
var bBottomSearch = (bIsBottom > 0) && gbSoftApproachHasTopAd

if(bBottomSearch)
{
	iHeight += 15
}


var sPath = getPath(bIsCategory)
var sHTML


/* 
Switch the top ad display back to left:

- Currently, align=right table has been used for the top ad 
- Howerer, the ad may be far away from the context, esp. when the text has been forced to wrapped
  by the author for quick scan
- Therefore the logic below switchs the display back to the left by closing the hard-coded table

- Do NOT touch the category ones that are currently on the left side already
- Do NOT touch the index page other wise the search boxes will be misplaced
*/
if(
	!bIsBottom && 
	!bIsLinkUnit && 
	!bIsCategory &&
	fiGetSubStringPos(window.location.href, "index.htm") < 0
	)
{
	// 1***. May 15, 2006
	//sHTML = "</td></tr></table><table align='left' cellpadding=2 cellspacing=0><tr><td>\n"
	

// May 15 logic
//sHTML = "</td></tr></table><table aliaaagn='left' cellpadding=2 cellspacing=0><tr><td width=" + iWidth + ">\n"

//sHTML = '</td></tr></table><table border="1" cellpadding="0" cellspacing="0" width="100%" bgcolor="#FFFF00"><tr><td>\n'

//sHTML = "</td><td bgcolor=#FFFF00<br><br>haibohaibo\n"


//sHTML = "</td></tr></table>\n<table width=100% bgcolor=yellow><tr><td>\n"
sHTML=""
}
else
{
	sHTML = ""
}


sHTML += 
/* Layout:
- Width is needed for the 336x280 (Originally: 300x250) ad so that the tip disply won't push the overall layout too big
- Height is automatic: Ad + Tip + borders
*/

// Close the dummy div of the inserted code on page with the leading </div>
/*
'\n</div><div' + 
'; " class="AdSense">\n' + 
2***. May 15, 2006
*/


// Tip: Center for bottom ad
//'\n<center>' + getURLTip() + '</center>\n' +


// Google ad
'<script>\n' +
'google_ad_client = "pub-4092937126439254";\n' +
'google_ad_width = ' + iWidth + ';\n' + 
'google_ad_height = ' + iHeight + ';\n' 



/*------------------------------------------------------ 
To write the cancer alert instead of the ad

	document.write("<iframe width=100% height=38 SRC='" + 
		"http://www.softapproach.com/Articles/" + 
		"Mesothelioma-Asbestos/Cancer-Alert/ifrm_CancerAlert.htm' FrameBorder=0 Scrolling='NO'></iframe>"); 

	return

------------------------------------------------------*/
if(bIsLinkUnit)
{
	//Link unit ad logic:
	sHTML += 'google_ad_format = "' + iWidth + 'x' + iHeight + '_0ads_al";\n' 
		'google_alternate_ad_url = "";\n' 

}
else
{

	sHTML += 
		'google_ad_format = "' + iWidth + 'x' + iHeight + '_as";\n' +
		'google_ad_type = "text_image";\n' 
}

/*------------------------------------------------------ 
If there is a top ad already, replace the bottom one with a search box.
i.e. the bottom ad shows only when there is no top one since the ads are cheap
------------------------------------------------------*/
/* See logic at the end of this function for both values
*/
if(bBottomSearch)
{


	document.write(getSearchBox(bIsCategory, gsSoftApproachSearchBoxPrefix))
	return
}




/* With alternate page?
   Not applicable for the link unit ad which:
- At least has a search box
- When testing on local machine, to show part of the alternative page is confusing 
*/
if(!bNoAlternativeURL && !bIsLinkUnit)
{

/* May 15, 2006
Use the resource box to show other sites
	sHTML += 
		'google_alternate_ad_url = "' + sPath + 'adSenseAlternate.html";\n' 
*/
	sHTML += 
		'google_alternate_ad_url = "http://www.talk-n-mail.com/Articles/ifrm-alternative.htm";\n' 

}


/* 'google_color_link = "3E8EE7";\n' + 

- This color is invisible for 728 ad:
'google_color_url = "b9b9b9";\n' + 
'google_color_text = "666666";\n' +


May 15, 2006: Leave enough room at the bottom
*/
sHTML += 
'google_ad_channel ="";\n' +
'google_color_border = "f9f9f9";\n' + 
'google_color_bg = "f9f9f9";\n' + 
'google_color_link = "3E8EE7";\n' + 
'google_color_url = "b9b9b9";\n' + 
'google_color_text = "000000";\n' +

'</script>\n' + 
'<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js">\n' + 
'</script>\n' 


// Top ad
if(!bIsBottom && !bIsLinkUnit)
{





	/* 1. Keep the information for the bottom ad
	*/
	gbSoftApproachHasTopAd = true
	gsSoftApproachSearchBoxPrefix = sSearchBoxPrefix

	// 2. Add search box
	if(!bNoSearchBox)
	{
// Remove since the search box is at the bottom already
// This way, the top ad is blended in
//		sHTML += getSearchBox(bIsCategory, sSearchBoxPrefix)
	}


// Replace with Oxado ads
//sHTML = '<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript" SRC="http://pub.oxado.com/insert_ad?pub=37920"></SCRIPT>'

}


//show
//alert(sHTML)
document.write(sHTML)

}



/*============================================================================== 
To use the alternative page intead of the standard search box for the 
- Target: All the articles where an alternative page is always available
- Reason: There are hints (related keywords) for user's convenience
- Rule: Applicable to the bottom search box only 

This function is called from getSearchBoxEx
*/
function getAlternativeSearchBox(sPrefix)
{


	// Not the bottom ad?
	if(!gbSoftApproachHasTopAd) return

	// Not an article page?
	if(sPrefix != "article_") return	


// Height needs to have room for 2 lines of keywords
var sHTML =
		"<table border='5' cellpadding='0' cellspacing='0' bordercolor=E5e5e5><tr><td>" + 
		"<iframe width=" + getSearchBoxWidth() + 
		"; height=150 SRC='" + getPath() + 
		"adSenseAlternate.html' FrameBorder=0 Scrolling='NO'></iframe>" + 
		"</td></tr></table>" 

	return sHTML

}


// Search box width for both functions
function getSearchBoxWidth()
{
	return 400
}


/* To add the search box iframe that shows the google search window
*/
function writeGoogleSearchBoxiFrame(sURL)
{

	document.write("<iframe width=100%" + 
		"; height=230" +
		"; SRC='" + sURL + "' FrameBorder=0 Scrolling='NO'></iframe>"); 
}

/* Car maker list
    <div><script>
writeCarMakerList()
</script>
</div>
*/
function writeCarMakerList()
{

	document.write("<iframe width=100% height=80 SRC='../iframe_CarMakers.htm' FrameBorder=0 Scrolling='NO'></iframe>"); 

}



/* See also: getSearchBox */
function getSearchBoxEx(sPath, sPrefix)
{
var sHTML

/* May 20, 2006
Make the search box on the main page work
*/
if(!sPath && !sPrefix)
{

// The search never return any result anyways
return "";


	sHTML = 	"<table border='1' cellpadding='0' cellspacing='0' bordercolor=E5e5e5><tr><td>" + 
		"<iframe width=" + getSearchBoxWidth() + 
		"; height=70 SRC='article_GoogleSearch.htm' FrameBorder=0 Scrolling='NO'></iframe>" + 
		"</td></tr>" + 
		"<tr><td height='1'>" +
		"<font color='C91F1F'><center><b>Search to find more to read -- quickly</b><center></font>" + 
		"</td></tr></table>"

return sHTML
}



	if(!sPath)
	{
		sPath = ""
	}

	if(sPrefix)
	{
		// All software
		sPath = ""
	}
	else
	{
		// All articles
		sPrefix = "article_"
	}


	/* There is a better one?
	*/
	sAlternative = getAlternativeSearchBox(sPrefix)



	if(sAlternative)
	{
		return sAlternative
	}
	
	/* Width to fit into the top ad space as alternatve
	*/
	sHTML = 	"<table border='1' cellpadding='0' cellspacing='0' bordercolor=E5e5e5><tr><td>" + 
		"<iframe width=" + getSearchBoxWidth() + 
		"; height=70 SRC='" + sPath + sPrefix + 
		"GoogleSearch.htm' FrameBorder=0 Scrolling='NO'></iframe>" + 
		"</td></tr>" + 
		"<tr><td height='1'>" +
		"<font color='C91F1F'><center><b>Search to find more to read -- quickly</b><center></font>" + 
		"</td></tr></table>"


//alert(sHTML)
return sHTML
}

/* To set the user clicked keywords to the search form 
*/
function keywordToForm(sKeyword)
{
var oiFrame = document.frames[0] 

	oiFrame.document.forms[0].q.value = sKeyword
}


/* Trim a string 
*/
function trimString(str) 
{ 
  var i = 0, j = 0; 
  while ( str.charAt(i)==" " ) i++; 
  j = str.length-1; 
  while ( str.charAt(j)==" " ) j--; 
  return str.substring(i,j+1); 
} 



/* To make a keyword list clickable to fill into the search form
*/
function keywordToClickable(sKeywords)
{
var sTokens = sKeywords.split(",")
var sToken
var sComma 
var iTh

	sKeywords = ""
	for(iTh = 0; iTh < sTokens.length; iTh ++)
	{

		sToken = trimString(sTokens[iTh])


		// Comma in between
		sComma = iTh > 0 ? ", " : ""


		sKeywords += sComma + "<a href=\"JavaScript:keywordToForm('" + 
			sToken + "')\">" + sToken + "</a>"
	}


	return sKeywords
}

/* To write a tip for the alternative page 
such as from this page: Articles\Advertising\adSenseAlternate.html
Logic in this function will make the suggested keywords clickable to fill the form so that the user can use
the mouse instead of the keyboard


<script>writeAlternativePageTip("")</script>

*/
function writeAlternativePageTip(sCategory, sKeywords)
{
var sMessage = 
	'<b>Tip - Search for more hot articles for <u>' + sCategory + ':</u></b>'

	if(sKeywords) 
	{
		sKeywords = keywordToClickable(sKeywords)


		sMessage += "<br>\n<small>(<font color='#ff0000'><u>Click to choose:</u> </font>" + sKeywords + ")</small>"
	}

	/* Force to align left
	Reason:
	- Default layout of the table cell is centered
	- While the width is not big enough to show all the keywords for the top ad (when replaced by the search box)
	*/
	sMessage = "<div align=left>" + sMessage + "</div>"

	document.write(sMessage)
}


/* To return the path:
- bIsCategory: The current path, this is for the htmls in each category, such as Marketing
- No: One level up.  This is for the article pages, such as Marketing\Marketing1\xxx.html
*/
function getPath(bIsCategory)
{
var sPath = window.location.href

var iTh
var iTotal = bIsCategory ? 1 : 2


	for(iTh = 0; iTh < iTotal; iTh++) 
	{
		sPath = sPath.substring(0, sPath.lastIndexOf("/")); 
	}

	sPath += "/"

	return sPath


}


function toPreviousPage()
{
	history.back()
}

/* Tip to keep the current page untouched */
function getURLTip()
{

// No tip
return ""

	// The old one needs 99%
	return '<table bgcolor="#FFFFbb" width=99%>' +  
              '<tr>' + 
                '<td><center><span style="font-size: 9pt"><strong>Tip:</strong> Right click a Web link and then choose <em><b>Open' + 
                ' in New Window</b></em> to avoid overwriting this page</span></center></td>' + 
              '</tr></table>'

}

/* Compatibility with the existing code (no dedicated iframe ad)*/
function addURLTip()
{
// No tip
return
	document.write(getURLTip())
}

/* sPos=left, top, right bottom */ 
function addExtraIframe(sPos, bRoot)
{
var sPath 

	// Root index page?
	if(bRoot)
	{
		sPath = ""
	}
	else
	{
		sPath = "../../"
	}



	if(sPos == "bottom")
	{
return
    		document.write("<iframe width=100% height=50 SRC='" + sPath + "article_IframeExtraBottom.htm' FrameBorder=0 Scrolling='NO'></iframe>"); 
	}

// Disabled for now
return



	if(sPos == "top")
	{
    		document.write("<iframe width=100% height=50 SRC='../../article_IframeExtraTop.htm' FrameBorder=0 Scrolling='NO'></iframe>"); 
	}



	else if(sPos == "left")
	{
    		document.write("<iframe width=100 height=100% SRC='../../article_IframeExtraLeft.htm' FrameBorder=0 Scrolling='NO'></iframe>"); 
	}

	else
	{
    		document.write("<iframe width=100 height=100% SRC='../../article_IframeExtraRight.htm' FrameBorder=0 Scrolling='NO'></iframe>"); 
	}
}

/* Tell a friend */
function tellAFriend(asPath)
{


/*
	if(!asPath){asPath = ""}
	window.open(asPath + "article_TellAFriend.htm")
*/
	window.open("/TellAFriend/index.php")


}

function searchSite(asPath)
{
	if(!asPath){asPath = ""}
	window.open(asPath + "article_GoogleSearch.htm")
}
function printPage()
{
	print()
}

function fiGetSubStringPos(asString, asSubString, abCaseSensitive)
{
// Return: 0 - n, -1 = not found
var lsString
var lsSubString

	lsString = new String(asString)
	lsSubString = new String(asSubString)

	if(!abCaseSensitive)
	{
		lsString = lsString.toLowerCase()
		lsSubString = lsSubString.toLowerCase()
	}

	return lsString.indexOf(lsSubString)
}

/* This ad is for the bottom instread of top? 
Not in use
function isBottomAd()
{

	return fiGetSubStringPos(document.location, "#bottom", false) > 0
}
*/


/* Width */
function getAdWidth(bIsBottom, bIsLinkUnit)
{
	if(bIsLinkUnit)
	{
		return 728
	}
	else if(bIsBottom)
	{
		return 728
	}
	else
	{
		return 336
	}
}

/* height */
function getAdHeight(bIsBottom, bIsLinkUnit)
{
	if(bIsLinkUnit)
	{
		return 15
	}
	else if(bIsBottom)
	{
		return 90
	}
	else
	{
		return 280
	}
	
}

/* To write the logic to insert an iFrame with targeted keywords.  Otherwise, the ad served may
be totally inrelevent and therefore zero revenue

- siFramePrefix: visio_ desktop_ tnm_
- sPosition: link, top, bottom

Use:
<script>
writeadSenseiFrame("visio_", "top")
</script>


*/
function writeadSenseiFrame(siFramePrefix, sPosition, sPath)
{
var sAd
var iWidth 
var iHeight

var siFrame



	if(!sPath)
	{
		sPath = ""
	}

	siFramePrefix = siFramePrefix.toLowerCase()
	sPosition = sPosition.toLowerCase()

	if(sPosition  == "link")
	{

        	sAd = "0,0,1,1"

	}
	else if(sPosition  == "top")
	{
		sAd = "0,0,0,1,0," + siFramePrefix

	}
	// Bottom
	else
	{
		sAd = "1,0,0,1,1"

	}


	// Logic for iFrame to run
	sAd = "<script>softapproach_iFrame_adSense = \"" + sAd + "\"</script>"

	//document.write(sAd)


	// iFrame itself
	iWidth = getAdWidth(sPosition == "bottom", sPosition == "link")
	iHeight = getAdHeight(sPosition == "bottom", sPosition == "link")


	siFrame = "<iframe width=" + iWidth + "; height=" + iHeight + 
		 "; SRC='" + sPath + siFramePrefix + 
		"iFrame_adSense.htm'; FrameBorder=0 scrolling='NO'></iframe>"


   	document.write(sAd + "\n" + siFrame); 

}
/* To write the Ad logic for visio_iFrame_adSense.htm 
- The parms are prepared by writeadSenseiFrame and passed to the iFrame
- This function is then called by the iFrame to insert the Ad

*/
function writeGoogleAdiFrame(sParmString)
{
var sParms

	// Inform adSense to use the iFrame text
	google_page_url = document.location;

	sParms = sParmString.split(",")

	writeGoogleAd(
		parseInt(sParms[0]), 
		parseInt(sParms[1]), 
		parseInt(sParms[2]), 
		parseInt(sParms[3]), 
		parseInt(sParms[4]), 
		sParms[5])
	
	
}



/* To write the link unit ad 

<div>
<script>
writeGoogleLinkAd()
</script>
</div>

*/
function writeGoogleLinkAd()
{
	writeGoogleAd(false, false, true)
}



/* To produce the search box HTML 
- sPrefix: The prefix for others, such as visio_(GoogleSearch
*/
function getSearchBox(bIsCategory, sPrefix)
{
var sPath = bIsCategory ? "../" : "../../"
	return getSearchBoxEx(sPath, sPrefix)
}



/* To write a link to the category group from a category page
- sBookmark: The bookmark for the group, such as Personal for Personal / Family

<script>
writeGroupLink("Personal")
</script>

*/
function writeGroupLink(sBookmark)
{
var sPrompt 
var sHTML

	// Prompt
	sPrompt = sBookmark

	if(sPrompt == "Copywriting")
	{
		sPrompt += " / Newsletter"
	}
	else if(sPrompt == "Personal")
	{
		sPrompt += " / Family"
	}
	else if(sPrompt == "Web")
	{
		sPrompt += " / Online Marketing"
	}
	

	// Full URL
	sBookmark = "../../index_Group.htm#" + sBookmark
	
sHTML =  

'<table border="1" width="100%" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">\n' +
'<tr>\n' +
'<td><img valign="middle" src="../../../right_arrow.gif"> \n' +
'More articles are available under group <strong>' + sPrompt + '</strong>.\n' +
'&nbsp; <a href="' + sBookmark + '"><b>Click here</b></a> to find out...</td></tr></table>\n'

document.write(sHTML)

}


var iSiteID = 10


// Show RevenuePilot ads
function showAd(bBottom, sSearchBoxPrefix)
{
var sText = getKeywordString()

// Null?  Try again by moving one dir level up
if(!sText)
{
sText = getKeywordString(true)
}

sText = sText.split(':')

// With different keywords?
var sKeywords = sText.length > 2 ? sText[2] : sText[0]

// Get rid of -
sKeywords = sKeywords.replace(/-/g, ' ')

var iSiteID = sText[1]


//alert(sKeywords)
//alert(iSiteID)

// Missing keyword?
if(!sKeywords)
{
sKeywords = "skin care"
}

// Missing sID?
if(!iSiteID)
{
// The starting number for free articles
iSiteID = 1000
}

showAdEx(iSiteID,sKeywords, bBottom, sSearchBoxPrefix)

if(bBottom)
{
showSearchBox(iSiteID)
}

}

// Called by showAd()
function showAdEx(iSiteID, sKeywords, bBottom, sSearchBoxPrefix)
{
var iLength = 2
var iTemplate = 2

var sHTML
var sVisioLabelTop
var sVisioLabelBottom

// MS Visio?
if(sKeywords.indexOf('visio') >= 0)
{

// Disable all
return

// Left justified ad? (embeded with text)
if(sSearchBoxPrefix == 'visio_')
{
return
}

// Top?
if(!bBottom)
{


/* Add the functionality first
Add to the top ad since it always exists
*/
adWebStat()

}

/*
sHTML = '<p align=center><table border=0 width=470><tr><td><h1><u>Special Today</u>! Buy Microsoft Visio ' + 
'<u>' + sVisioLabelTop + '</u>' +
' from Amazon.com and Save:</h1></td></tr><tr><td>' + sHTML + sVisioLabelBottom + '</td></tr></table><br><br><br></p>'
*/

}

//else
{
// &sid= (site ID)
// &test=on (testing mode)
sHTML = '<script ' +
'src="http://search.revenuepilot.com/servlet/search?mode=js&id=20139&tid=' + iTemplate + '&perpage=' + iLength + '&filter=off' +
'&skip=0&by=off&sid=' + iSiteID + '&keyword=' + sKeywords + '"></script>\n'
}

document.write(sHTML)
}




/* return the ad keywords and sub id
Format: url-substring:SID:[optional]Search Keyword(If diffrent from url-substring)
e.g. 'domain:1130:domainname,,online marketing'

- bRetry: Try the 2nd time after getting NULL? Such auto-car/ford
This time move one level up
*/
function getKeywordString(bRetry)
{
var sText = 'advertising:1000\n' +
'advice:1010\n' +
'affiliate:1020\n' +
'auto:1030:CAR INSURANCE,,car loan,,buy car,,car\n' +
'award:1040\n' +
'business:1050:HOME BUSINESS\n' +
'career:1060\n' +
'cgi:1070:ecommerce,,WEB SERVER,,cgi\n' +
'communication:1080:voip,,communication skill\n' +
'computer:1090\n' +
'copywriting:1100:writing\n' +
'css:1110:ecommerce,,web,,css\n' +
'direct:1120:EMAIL MARKETING\n' +
'domain:1130:DOMAIN NAME,,DOMAIN HOSTING\n' +
'ebook:1140\n' +
'ecommerce:1150\n' +
'education:1160student loan,,education\n' +
'email:1170:home business,,email marketing\n' +
'entertainment:1180:casino,,gambling,,entertainment\n' +
'environment:1190\n' +
'family:1200:DEBT CONSOLIDATION,,loan,,mortgage,,family\n' +
'finance:1210:refinance,,finance,,loan,,mortgage\n' +
'fitness:1220:lose weight,,diet,,fitnett\n' +
'food:1230:diet,,food\n' +
'free:1240:free,,cheap,,free stuff\n' +
'gardening:1250\n' +
'government:1260:tax,,tax return,,government\n' +
'health:1270:life insurance,,health insurance,,health\n' +
'hobbies:1280\n' +
'home-business:1290:home business,,small business,,make money online\n' +
'home-repair:1300\n' +
'html:1310:ecommerce,,web server,,html\n' +
'humor:1320:entertainment,,humor\n' +
'internet:1330:ecommerce,,internet\n' +
'javascript:1340:ecommerce,,web server,,javascript\n' +
'law:1350:attorney,,lawyer,,law\n' +
'link-popularity:1360:online marketing,,online promotion,,link popularity\n' +
'management:1370:business management\n' +
'marketing:1380:online marketing,,marketing\n' +
'marriage:1390:dating,,relationship,,marriage\n' +
'mesothelioma:1400\n' +
'metaphysics:1500:dating,,PSYCHIC READING,astrology,metaphysics\n' +
'mlm:1510\n' +
'motivation:1520\n' +
'multimedia:1530\n' +
'newsletter:1540\n' +
'offline:1550:marketing,,offlie promotion\n' +
'online:1560\n' +
'others:1570:DEBT CONSOLIDATION,,career,,entertainment\n' +
'pets:1580\n' +
'politics:1590\n' +
'powerpoint:1600:business,,powerpoint\n' +
'psychology:1610\n' +
'publishing:1620\n' +
'religion:1630:CHRISTIAN,,religion\n' +
'sales:1640:marketing,,sales\n' +
'scams:1650:scurity,,scam\n' +
'science:1670\n' +
'search:1680:SEARCH ENGINE SUBMISSION,,seo\n' +
'self-help:1690\n' +
'sex:1700:adult dating\n' +
'social:1710:education,,medicare,,social issue\n' +
'spam:1720:adware,,virus,,spam\n' +
'sports:1730:weight loss,,fitness,,sports\n' +
'technology:1740\n' +
'travel:1750\n' +
'viral:1760:marketing,,viral marketing\n' +
'visio:1770:visio,,visio\n' +
'web-design:1780\n' +
'web-hosting:1790\n' +
'webmaster:1800\n' +
'website:1810:online security,,website security\n' +
'web-traffic:1820\n' +
'weight:1830\n' +
'womens:1840:wrinkle,,aging,,skin care,,weight loss,,education,,job\n' +
'writing:1850\n' 
// ATT: Keep the \n sign for the folling logic

var sURL = document.location.href
sURL = sURL.toLowerCase()


// tnm?
if(sURL.indexOf('tnm_') >= 0)
{
return 'tnm:70:dating,,ringtone,,greeting card,,email'
}


// visio?
if(sURL.indexOf('visio_') >= 0)
{
//return 'visio:80:make money online'
return 'visio:80:visio'
}


// For local testing
sURL = sURL.replace(/\\/g, '/')

// Get the last dir 
// Move one level up if retry, such as auto-car/ford
var iOffset = bRetry ? 1 : 0
//
sURL = sURL.split('/')
sURL = sURL[sURL.length - 2 - iOffset] + ':'

// Get the first chunk only, such as auto-car --> auto
sURL = sURL.split('-')

// Web traffic, etc.
// The second word has to be coded here (for others in the future)
sURL = 	sURL[0] == 'web' ||
	sURL[0] == 'home' ? 
	sURL[0] + '-' + sURL[1] : sURL[0]

var iPos = sText.indexOf(sURL) 
// Not found?
if(iPos < 0)
{
return
}

// Long enough
sURL = sText.substring(iPos)

// Till the newline sign
sURL = sURL.split('\n')
sURL = sURL[0]

//alert(sURL)
return sURL
}


// Add to a page
function adWebStat()
{


var sHTML = '<script type="text/javascript">\n' +
'var page_name = \'\';\n' +
'var invisible = \'\';\n' +
'function sE(){return true;}window.onError=sE;var wtsui=\'haibop\';\n' +
'try{var wtsb=top.document;var wtsr=wtsb.referrer;var wtsu=wtsb.URL;}\n' +
'catch(e){var wtsb=document;var wtsr=wtsb.referrer;var wtsu=wtsb.URL;}\n' +
'var wtsrn=Math.random();var qry=wtsui+\':4::\'+escape(wtsr)+\'::\'\n' +
'+screen.width+\'x\'+screen.height+\'::\'+screen.colorDepth+\'::\'\n' +
'+escape(page_name)+\'::\'+invisible+\'::\'+wtsrn+\'::\'+escape(wtsu);\n' +
'document.write(\'<a href="http://www.web-stat.com/stats/\'+wtsui+\'.htm" \');\n' +
'document.write(\'target="new"><img src="http://server3.web-stat.com/count.pl?\');\n' +
'document.write(qry+\'" border="0" alt="web stats script"><\/a>\');\n' +
'</script><noscript><a href="http://www.web-stat.com">\n' +
'<img src="http://server3.web-stat.com/4/haibop.gif"\n' +
'border="0" alt="web stats script"></a></noscript>\n' 
  

//alert(sHTML)
document.write(sHTML)
}


// Search Box
function showSearchBox(iSiteID)
{


// Obsolete
var sHTML = '<form name="form" method="get" action="http://search.revenuepilot.com/servlet/search">\n' +
'  <table align="center" width="321" border="0" cellspacing="0" cellpadding="0">\n' +
'    <tr>\n' +
'      <td><img src="http://www.revenuepilot.com/userimages/searchbox/searchbox_09_01.jpg" width="321" height="16" alt="" /></td>\n' +
'    </tr>\n' +
'    <tr>\n' +
'      <td background="http://www.revenuepilot.com/userimages/searchbox/searchbox_09_02.jpg" height="69" valign="bottom">\n' +
'        <table align="center" width="100%" border="0" cellspacing="0" cellpadding="0">\n' +
'          <tr>\n' +
'            <td align="center">\n' +
'               <input type="text" name="keyword" style="border: solid 1px black;">\n' +
'               <input type="hidden" name="id" value="20139">\n' +
'         <input type="hidden" name="tid" value="0">\n' +
'               <input type="hidden" name="sid" value="' + iSiteID + '">\n' +
'               <input type="hidden" name="filter" value="off">\n' +
'               <input type="hidden" name="tid" value="0">\n' +
'               <input type="hidden" name="mode" value="search">\n' +
'               <input type="image" src="http://www.revenuepilot.com/userimages/searchbox/search_01.gif" align="center" value=Search border=0 width="57" height="16">\n' +
'            </td>\n' +
'          </tr>\n' +
'          <tr>\n' +
'            <td><img src="http://www.revenuepilot.com/userimages/searchbox/5.gif" width="1" height="5" alt="" /></td>\n' +
'          </tr>\n' +
'        </table>\n' +
'      </td>\n' +
'    </tr>\n' +
'  </table>\n' +
'</form>\n' 


/* Amazon search
sHTML = '<center><iframe src="http://rcm.amazon.com/e/cm?t=microsoft-visio-20&o=1&p=27&l=qs1&f=ifr" width="180" height="150" frameborder="0" scrolling="no"></iframe></center>'
*/

/* Link to make money at home
sHTML = "<center><a target=_blank href='http://www.theworkathomeopportunities.com/?sid=AvSaSEO'><big><b>Is Work-at-Home All Scam? Click Here to Find Out...</big></b></a></center>"
*/
sHTML = "<iframe src='Articles/ifrm-makemoney.htm' width=100% height=180 frameborder=0 scrolling=no></iframe>"


//document.write(sHTML)
}


/* 
visio_: 80
*/
var iSiteID = 80

function showAd()
{
showAdEx("debt consolidation")
showAdEx("make money")
}

// Called by showAd()
function showAdEx(sKeywords, iLength, iTemplate)
{
var sHTML

// Default template
if(!iTemplate)
{
iTemplate = 0
}

// Default length
if(!iLength)
{
iLength = 2
}

// &sid= (site ID)
// &test=on (testing mode)
sHTML = '<script ' +
'src="http://search.revenuepilot.com/servlet/search?mode=js&id=20139&tid=' + iTemplate + '&perpage=' + iLength + '&filter=off' +
'&skip=0&by=off&sid=' + iSiteID + '&keyword=' + sKeywords + '"></script>\n'

document.write(sHTML)
}
