/* These are utility functions specifically
for the Peter's Software website */

function GetDocShortName() {
/* This function returns the pageid for the current page
"http://www.peterssoftware.com/ss2.htm" will return "ss" */
    var strURL = document.URL
    var pos1 = 0
    var pos2 = 0
    var strCurrDocName = ""
    var adj = 0
    
    if (strURL.substring(0,7) == "file://") {
    	pos1 = strURL.lastIndexOf("\\")
    } else {
    	pos1 = strURL.lastIndexOf("/")
    }
    pos2 = strURL.lastIndexOf(".")
    
	// If there is a number in the last position, chop it off
	// This lets us validate pages with numeric suffixes like
	// ss.htm, ss2.htm, ss3.htm, etc...
	if (isNaN(strURL.substring(pos2-1,pos2))) {
	} else {
		adj = 1
	}
	
    if (pos2 > pos1) {
    	return strURL.substring(pos1+1,pos2 - adj)
    } else {
    	return "unknown"
    }
} 

function PSGetPage(pageid) {
/* This function returns the fully qualified web page based on the
pageid passed. The pageid is a shortcut name for the page. This
function makes it easy to direct all links to a page. */
    var strrtn = ""
    //var pf = "http://www.peterssoftware.com/"
	var pf = ""
	var suf = ".htm"
	
	//Redirect pages by changing this var value
	//var pagesuf = "2"
	var pagesuf = ""
	
	//Default
	strrtn = pageid
	
    //if (pageid == "abs") {strrtn = "abs" + pagesuf}
	//if (pageid == "bcg") {strrtn = "bcg" + pagesuf}
	////if (pageid == "buy") {strrtn = "buy" + pagesuf}
	//if (pageid == "cal") {strrtn = "cal" + pagesuf}
	if (pageid == "ce") {strrtn = "ce" + pagesuf}
	////if (pageid == "clrbtn") {strrtn = "clrbtn" + pagesuf}
	////if (pageid == "consult") {strrtn = "consult" + pagesuf}
	if (pageid == "cr") {strrtn = "cr" + pagesuf}
	if (pageid == "dd") {strrtn = "dd" + pagesuf}
	////if (pageid == "fv") {strrtn = "fv" + pagesuf}
	////if (pageid == "help") {strrtn = "help" + pagesuf}
	////if (pageid == "index") {strrtn = "index" + pagesuf}
	////if (pageid == "info") {strrtn = "info" + pagesuf}
	//if (pageid == "isd") {strrtn = "isd" + pagesuf}
	if (pageid == "las") {strrtn = "las" + pagesuf}
	//if (pageid == "ls") {strrtn = "ls" + pagesuf}
	if (pageid == "moe") {strrtn = "moe" + pagesuf}
	if (pageid == "sel") {strrtn = "sel" + pagesuf}
	if (pageid == "ss") {strrtn = "ss" + pagesuf}
	//if (pageid == "strfn") {strrtn = "strfn" + pagesuf}
	////if (pageid == "trm") {strrtn = "trm" + pagesuf}
	//if (pageid == "winmanip") {strrtn = "winmanip" + pagesuf}
    
	strrtn = pf + strrtn + suf
	//document.write (strrtn)
    return strrtn
} 

function PShref(pageid) {
/* This function returnsan "<a href=...>" link html string for the 
page identified by "pageid". The terminating "</a>" is not included */
	var strrtn = ""
	strrtn = "<a href='" + PSGetPage(pageid) + "'>"
	document.write (strrtn)
	return strrtn
}

function PSWriteOMPLogo() {
/* This function returns the html code for the graphic and link to
the MS Office Marketplace site */
	document.write ("<a href='http://office.microsoft.com/marketplace'><img src='http://r.office.microsoft.com/r/rlidMarketplaceLogo' width='250' height='52' vspace='15' hspace='20' align='right' border='0' alt='Microsoft Office Marketplace logo'></a>")
}

function IsOMPPage(pageid) {
/* Returns True if the page identified by "pageid" is included 
in the Microsoft Office Marketplace */
	var blnRtn = false

    //if (pageid == "abs") {blnRtn = true}
	//if (pageid == "bcg") {blnRtn = true}
	//if (pageid == "cal") {blnRtn = true}
	//if (pageid == "cr") {blnRtn = true}
	//if (pageid == "dd") {blnRtn = true}
	//if (pageid == "isd") {blnRtn = true}
	//if (pageid == "las") {blnRtn = true}
	//if (pageid == "ls") {blnRtn = true}
	//if (pageid == "moe") {blnRtn = true}
	//if (pageid == "sel") {blnRtn = true}
	//if (pageid == "ss") {blnRtn = true}
	//if (pageid == "strfn") {blnRtn = true}
	//if (pageid == "winmanip") {blnRtn = true}
	if (pageid == "omjumpform") {blnRtn = true}
	if (pageid == "omjumputility") {blnRtn = true}
	if (pageid == "ka") {blnRtn = true}
	if (pageid == "vf") {blnRtn = true}
	if (pageid == "ci") {blnRtn = true}
	if (pageid == "lm") {blnRtn = true}
	if (pageid == "aps") {blnRtn = true}
	if (pageid == "tlk") {blnRtn = true}
	return blnRtn
}

function PSCopyright() {
/*  This function writes the copyright notice to the html page */
	var strcr = "Copyright © 1998-2009 <a href='index.htm'>Peter's Software</a>"
	if (IsOMPPage(GetDocShortName())) {
		strcr = strcr + "<br>"
		strcr = strcr + "Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries."
	}
	document.write (strcr)
}

function PSWriteDonations() {
/* This function returns the html code for the "Donations" section of PS web pages*/
  if (1 == 0) {
	document.write ("<br>")
	document.write ("<h3><font face='Verdana, Arial, Helvetica, sans-serif'>Donations</font></h3>")
	document.write ("<p><font face='Verdana, Arial, Helvetica, sans-serif' size='-1'>Is this software useful to you? Your donation will encourage us to add more features, and create new and better MS Access tools for developers such as yourself. Donations are voluntary and will not affect our level of support for this software. Thanks!</font></p>")
	document.write ("<form action='https://www.paypal.com/cgi-bin/webscr' method='post'>")
	document.write ("<input size='6' name='amount' value=''>")
	document.write ("<select name='currency_code'>")
	document.write ("  <option value='USD'>U.S. Dollar</option>")
	document.write ("  <option value='CAD'>Canadian Dollar</option>")
	document.write ("  <option value='EUR'>Euro</option>")
	document.write ("  <option value='GBP'>Pound Sterling</option>")
	document.write ("  <option value='JPY'>Yen</option>")
	document.write ("</select>")
	document.write ("<input type='hidden' name='cmd' value='_xclick'>")
	document.write ("<input type='hidden' name='business' value='info@peterssoftware.com'>")
	document.write ("<input type='hidden' name='item_name' value='Peters Software'>")
	document.write ("<input type='hidden' name='item_number' value='" + GetDocShortName() + "'>")
	document.write ("<input type='hidden' name='no_shipping' value='1'>")
	document.write ("<input type='hidden' name='cn' value='Optional Comments'>")
	document.write ("<input type='hidden' name='tax' value='0'>")
	document.write ("<input type='image' align=left src='https://www.paypal.com/en_US/i/btn/x-click-but21.gif' border='0' name='submit' alt='Make payments with PayPal - it\'s fast, free and secure!'>")
	document.write ("</form>")
  }
}

function PSRedirectByReferrer() {
/* This function returns the html code for the "Donations" section of PS web pages*/
  var strreferrer = ""
  strreferrer = document.referrer
  if (strreferrer.length > 12) {
    //document.writeln (strreferrer.substring(strreferrer.length - 12,strreferrer.length + 1) + "***")
    if (strreferrer.substring(strreferrer.length - 12,strreferrer.length + 1) == "/gen0002.htm") {
      //document.writeln ("...")
      window.location.replace ("http://www.peterssoftware.com/" + PSGetPage("ss"))
    }
  }
}

function NewUpdated(dtYMD,strNewOrUpdated) {
  // This function prints " - New M/D!" in red text for 60 days from the passed date
  // The passed date must be m/d/yyyy format
  try {
    var s = ""
    var dtNow = new Date()
    var pos1 = dtYMD.indexOf("/")
    var pos2 = dtYMD.lastIndexOf("/")
    // First parm is year, month-1, and date
    var dtPassed = new Date(dtYMD.substr(pos2+1,4),dtYMD.substr(0,pos1)-1,dtYMD.substr(pos1+1,pos2-pos1-1))
    var nDaysDiff = parseInt((dtNow.valueOf() - dtPassed.valueOf())/(3600000 * 24))
    //document.write ("<br>" + "days diff=" + nDaysDiff)
    //message will appear for 2.5 months
    if (nDaysDiff > 90) {
      // Do Nothimg
    } else {
      if (strNewOrUpdated == "u") {
        s = "UPDATED"
      } else {
        s = "NEW"
      }
      document.write ("<font color='red'><b> - " + s + "! " + (dtPassed.getMonth() + 1) + "/" + dtPassed.getDate() + "</b></font>")
    }
  }
  catch(e) {
    // Do nothing on error
  }
}
