// All this date processing is used to get yesterday's date

var myDate = new Date();
		//document.write ("Today is: " + myDate + "<br>"); // Testing only
var myDay = myDate.getDate();
var myMonth = myDate.getMonth();
var myYear = myDate.getYear();
	if(navigator.appName == "Netscape"){
 		myYear = 1900 + myYear;
	}
		//document.write  ("The year is: " + myYear + "<br><br>"); // Testing only
var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var numdays = new Array("31","28","31","30","31","30","31","31","30","31","30","31")
var myToday = months[myMonth] + " " + myDay + ", " + myYear;

	myYDay = myDay-1; // Subtract a day

		//document.write("myMonth is: " + myMonth + "<br>"); //Testing only
		//document.write("myDay is: " + myDay + "<br>"); //Testing only
		//document.write("myYDay is: " + myYDay + "<br>"); //Testing only
		//document.write("myYear is: " + myYear + "<br>"); //Testing only


	if (myYDay == 0) { // If the day is the first day of the month then yesterday will be zero
 			 // -- Change the previous month
			 // -- Set the previous day to the last day of the previous month	
		// document.write("myYDay is equal to " + myYDay + "<br>") 	//Testing only
		// document.write ("myMonth is equal to " + myMonth + "<br>") // Testing only
		myMonth = myMonth - 1;   

		if (myMonth == -1) {   // If the month is a -1 value (0 is January)
			myMonth = 11;    // Then set the month to December
			myYear = myYear - 1 // and Set the year to one previous
		}
	
		myYDay = numdays[myMonth]	
	}

	myYesterday = months[myMonth] + " " + myYDay + ", " + myYear;

		// document.write("Today is: " + myToday); // Testing only
		// document.write("<br>Yesterday was: " + myYesterday); // Testing only

var INSTALL_INSTRUCTIONS = "<center><a href=../versions/install_instructions.php target='_blank'>(PC-DMIS Installation Instructions)</center></a>";

var SMA_DATE_INSTRUCTIONS = "This version of PC-DMIS will not install unless you have a current Software Maintenance Agreement (SMA). \n\nTo find out if your SMA is current - \n\n1) Run the \'custprog.exe\' program found in the directory where you currently have PC-DMIS installed.  \n2) Click on the \'Save Module List\' button. This allows you to export the options you have programmed in your port lock to a text file. \n3) Specify a path and filename to which you will export the data. \n4) Open the text file inside a text editor such as NotePad. \n\n About the fifth line down you will see a date. It is the only date in the file. This is the date that your SMA expires. If this date is earlier than the date listed above in this message, then this version you are about to download will not install. Please contact your PC-DMIS Reseller for information on updating your SMA. \n\nClick OK to continue with the download or Cancel to quit downloading.";

var SMA_DATE_INSTRUCTIONS_HTML = "<p>This version of PC-DMIS will not install unless you have a current Software Maintenance Agreement (SMA). <p>To find out if your SMA is current - <p><ol><li>Run the <b>custprog.exe</b> program found in the directory where you currently have PC-DMIS installed.  <li>Click on the <b>Save Module List</b> button. This allows you to export the options you have programmed in your port lock to a text file. <li>Specify a path and filename to which you will export the data. <li>Open the text file inside a text editor such as NotePad. About the fifth line down you will see a date. It is the only date in the file. This is the date that your SMA expires. <font color = red>If this date is earlier than the date listed for this file, then this version you are about to download will not install.</font> In this case, you will need to contact your PC-DMIS Reseller for information on updating your SMA.</ol><p>Click <b>Continue</b> to continue with the download or <b>Close</b> to quit downloading.</p><p>" + INSTALL_INSTRUCTIONS + "</p>";

var SMA_DATE_INSTRUCTIONS_HTML_STEP_PATCH = "<p>This version you are downloading will not install if your SMA expired earlier than December 20, 2004 (the original release date of PC-DMIS 3.7.) <p>To find out your SMA's expiration date:<p><ol><li>Run the <b>custprog.exe</b> program found in the directory where you currently have PC-DMIS installed.  <li>Click on the <b>Save Module List</b> button. This allows you to export the options you have programmed in your port lock to a text file. <li>Specify a path and filename to which you will export the data. <li>Open the text file inside a text editor such as NotePad. About the fifth line down you will see a date. It is the only date in the file. This is the date that your SMA expires. <font color = red>If this date is earlier than December 20, 2004, then this version you are downloading will not install.</font> In this case, you will need to contact your PC-DMIS Reseller for information on updating your SMA.</ol><p>" + INSTALL_INSTRUCTIONS + "</p>";

var GEAR_DOWNLOAD_HTML = "<p>PC-DMIS Gear will not run unless you have a current Software Maintenance Agreement (SMA).";

var DATAPAGE_PLUS_DOWNLOAD_HTML = "<p>Datapage+ will not run with full functionality unless you have a current Software Maintenance Agreement (SMA). <p>To find out if your SMA is current - <p><ol><li>Start Datapage+. <li>Select the <b>Help | About</b> menu item. <li>The dialog box that appears contains an Expiry Date for your SMA. <font color = red>If this date is earlier than the date listed for this file, then this file you are downloading will not run.</font> In this case, you will need to contact your Datapage+ reseller for information on updating your SMA.</ol></p>";

var BLADE_DOWNLOAD_HTML = "<p>PC-DMIS Blade will not install unless you have a current Software Maintenance Agreement (SMA). <p>To find out if your SMA is current - <p><ol><li>Run the <b>custprog.exe</b> program found in the directory where you currently have PC-DMIS installed.  <li>Click on the <b>Save Module List</b> button. This allows you to export the options you have programmed in your port lock to a text file. <li>Specify a path and filename to which you will export the data. <li>Open the text file inside a text editor such as NotePad. About the fifth line down you will see a date. It is the only date in the file. This is the date that your SMA expires. <font color = red>If this date is earlier than the date listed for this file, then this file you are downloading will not install.</font> In this case, you will need to contact your PC-DMIS Reseller for information on updating your SMA.</ol></p>";

var MULTIGAGE_DOWNLOAD_HTML = "<p>PC-DMIS MultiGage will not install unless you have a current Software Maintenance Agreement (SMA). <p>To find out if your SMA is current - <p><ol><li>Run the <b>custprog.exe</b> program found in the directory where you currently have PC-DMIS installed.  <li>Click on the <b>Save Module List</b> button. This allows you to export the options you have programmed in your port lock to a text file. <li>Specify a path and filename to which you will export the data. <li>Open the text file inside a text editor such as NotePad. About the fifth line down you will see a date. It is the only date in the file. This is the date that your SMA expires. <font color = red>If this date is earlier than the date listed for this file, then this file you are about to download will not install.</font> In this case, you will need to contact your PC-DMIS Reseller for information on updating your SMA.</ol><p>Click <b>Continue</b> to continue with the download or <b>Close</b> to quit downloading.</p>";

var SUPPLEMENTAL_MODULES_HTML = "<p>These supplemental modules will not install unless you have a current Software Maintenance Agreement (SMA). <p>To find out if your SMA is current - <p><ol><li>Run the <b>custprog.exe</b> program found in the directory where you currently have PC-DMIS installed.  <li>Click on the <b>Save Module List</b> button. This allows you to export the options you have programmed in your port lock to a text file. <li>Specify a path and filename to which you will export the data. <li>Open the text file inside a text editor such as NotePad. About the fifth line down you will see a date. It is the only date in the file. This is the date that your SMA expires. <font color = red>If this date is earlier than the date listed for this file, then this version you are about to download will not install.</font> In this case, you will need to contact your PC-DMIS Reseller for information on updating your SMA.</ol><p>Click <b>Continue</b> to continue with the download or <b>Close</b> to quit downloading.</p><p> To install, unzip the contents of the file and double-click on the SupplementalCD.exe file. A dialog box will appear allowing you to install selected modules.";

var GENERIC_SOFTWARE_DOWNLOAD_HTML = "<p>The software you are downloading will only install if you have a current Software Maintenance Agreement (SMA). <p>To find out if your SMA is current - <p><ol><li>Run the <b>custprog.exe</b> program found in the directory where you currently have PC-DMIS installed.  <li>Click on the <b>Save Module List</b> button. This allows you to export the options you have programmed in your port lock to a text file. <li>Specify a path and filename to which you will export the data. <li>Open the text file inside a text editor such as NotePad. About the fifth line down you will see a date. It is the only date in the file. This is the date that your SMA expires. <font color = red>If this date is earlier than the date listed for this file, then this software will not install.</font> In this case, you will need to contact your software reseller for information on updating your SMA.</ol></p><p>" + INSTALL_INSTRUCTIONS + "</p>";

var PLANNER_SOFTWARE_DOWNLOAD_HTML = "<p>The PC-DMIS Planner software you are downloading will only install if you have a current Software Maintenance Agreement (SMA) and if your portlock is programmed with the PC-DMIS Planner option. <p>To find out if your SMA is current - <p><ol><li>Run the <b>custprog.exe</b> program found in the directory where you currently have PC-DMIS installed.  <li>Click on the <b>Save Module List</b> button. This allows you to export the options you have programmed in your port lock to a text file. <li>Specify a path and filename to which you will export the data. <li>Open the text file inside a text editor such as NotePad. About the fifth line down you will see a date. It is the only date in the file. This is the date that your SMA expires. <font color = red>If this date is earlier than the date listed for this file, then this software will not install.</font> In this case, you will need to contact your software reseller for information on updating your SMA.</ol></p><p></p>";

var NCGAGE_DOWNLOAD_HTML = "<p>PC-DMIS NC Gage will run in a demo mode until the software is properly licensed. Follow the licensing instructions when you run NC Gage for more information.</p>";

// VERSION 30 DOWNLOAD MESSAGES
var V30_REL_MESSAGE = "The date of the version of PC-DMIS you are about to download is: January 24, 2000. \n\n " + SMA_DATE_INSTRUCTIONS;

var V30_BETA_MESSAGE = "**Before downloading, be aware that beta versions are not supported by Technical Support.** \n\n The date of the version of PC-DMIS you are about to download is: March 28, 2001. \n\n " + SMA_DATE_INSTRUCTIONS;


// VERSION 32 DOWNLOAD MESSAGES
var V32_REL_MESSAGE = "The date of the version of PC-DMIS you are about to download is: May 29, 2001. \n\n " + SMA_DATE_INSTRUCTIONS;

var V32_MR3_MESSAGE = "The date of the version of PC-DMIS you are about to download is: January 23, 2002. \n\n " + SMA_DATE_INSTRUCTIONS;

var V32_BETA_MESSAGE = "**Before downloading, be aware that beta versions are not supported by Technical Support.** \n\n The date of the version of PC-DMIS you are about to download is: September 4, 2002 \n\n " + SMA_DATE_INSTRUCTIONS;

// VERSION 325 DOWNLOAD MESSAGES
var V325_REL_MESSAGE = "The date of the version of PC-DMIS you are about to download is: March 19, 2002. \n\n " + SMA_DATE_INSTRUCTIONS;

var V325_MR1_MESSAGE = "The date of the version of PC-DMIS you are about to download is: May 31, 2002. \n\n " + SMA_DATE_INSTRUCTIONS;

var V325_MR2_MESSAGE = "The date of the version of PC-DMIS you are about to download is: December 17, 2002. \n\n " + SMA_DATE_INSTRUCTIONS;

var V325_MR3_MESSAGE = "The date of the version of PC-DMIS you are about to download is: June 23, 2003. \n\n " + SMA_DATE_INSTRUCTIONS;

var V325_BETA_MESSAGE = "**Before downloading, be aware that beta versions are not supported by Technical Support.** \n\n The date of the version of PC-DMIS you are about to download is: May 25, 2005 \n\n" + SMA_DATE_INSTRUCTIONS;

// VERSION 3.5 DOWNLOAD MESSAGES
var V35_REL_MESSAGE = "The date of the version of PC-DMIS you are about to download is: October 24, 2002. \n\n " + SMA_DATE_INSTRUCTIONS;

var V35_MR1_MESSAGE = "The date of the version of PC-DMIS you are about to download is: March 06, 2003. \n\n " + SMA_DATE_INSTRUCTIONS;

var V35_MR2_MESSAGE = "The date of the version of PC-DMIS you are about to download is: December 03, 2003. \n\n " + SMA_DATE_INSTRUCTIONS;

var V35_BETA_MESSAGE = "**Before downloading, be aware that beta versions are not supported by Technical Support.** \n\n The date of the version of PC-DMIS you are about to download is: " + myYesterday + ". \n\n " + SMA_DATE_INSTRUCTIONS;

// VERSION 3.6 DOWNLOAD MESSAGES
var V36_REL_MESSAGE = "The date of the version of PC-DMIS you are about to download is: June 15, 2004. \n\n " + SMA_DATE_INSTRUCTIONS;

var V36_MR1_MESSAGE = "The date of the version of PC-DMIS you are about to download is: September 08, 2004. \n\n " + SMA_DATE_INSTRUCTIONS;

var V36_BETA_MESSAGE = "**Before downloading, be aware that beta versions are not supported by Technical Support.** \n\n The date of the version of PC-DMIS you are about to download is: " + myYesterday + ". \n\n " + SMA_DATE_INSTRUCTIONS;

// VERSION 3.7 DOWNLOAD MESSAGES
var V37_REL_MESSAGE = "The date of the version of PC-DMIS you are about to download is: December 10, 2004. \n\n " + SMA_DATE_INSTRUCTIONS;

var V37_MR1_MESSAGE = "The date of the version of PC-DMIS you are about to download is: March 11, 2005. \n\n " + SMA_DATE_INSTRUCTIONS;

var V37_MR2_MESSAGE = "The date of the version of PC-DMIS you are about to download is: June 24, 2005. \n\n " + SMA_DATE_INSTRUCTIONS;

var V37_BETA_MESSAGE = "**Before downloading, be aware that beta versions are not supported by Technical Support.** \n\n The date of the version of PC-DMIS you are about to download is: " + myYesterday + ". \n\n " + SMA_DATE_INSTRUCTIONS;

var MYMESSAGE = "This is a test message:<br> " + SMA_DATE_INSTRUCTIONS_HTML;


function MM_popupMsg(theMsg) { //v2.0
  alert (theMsg);
} // ------------------- END OF MM_popupMsg FUNCTION -------------------//


function MM_popupMsg_Confirm(theMsg,theHref) { //v2.0
  if (confirm(theMsg)){
	  // Begin the download
	  window.location = theHref;
	  //InterfaceLoad(theHref);
  }	
  else {
	  // Otherwise do nothing.
  }
	
} // ------------------- END OF MM_popupMsg_Confirm FUNCTION -------------------//




// ===== THE FUNCTIONS BELOW ARE CURRENTLY NOT USED. WORKS IN PROGRESS. ===== //


// This function creates a new window.
function messageWindow(title, msg, size, date, url)
{
  	
  // Get file name from URL, get strings from right side up until slash
	var array1 = url.split('//');
	var array2 = array1[1].split('/'); // second element which is the rest part of the string
	var filename = array2[array2.length-1];
	
  // Find out if it's a beta file // Search in side url for term 'beta'. 
  // If its there then print out beta message.
  
var IsBeta = url.indexOf("beta");
if (IsBeta > 0){
	var BETA_MESSAGE = "<p><b>**You are downloading a beta version. Before continuing, be aware that beta versions are <u>not</u> supported by Technical Support.**</b>";
  } else {
    var BETA_MESSAGE = "";
} 
  	
  var width="550", height="650";
  var left = (screen.width/2) - width/2;
  var top = (screen.height/2) - height/2;
  var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  var msgWindow = window.open("","msgWindow", styleStr);
  var head = '<head><title>'+title+'</title></head>';
  var str2 = '<center><h3>Downloading ' + filename + ' </h3></center><p><b>Size:</b> ' + size + '<br><b>Date:</b> ' + date + '</left>';
  var str1 = '<Left>' + msg + '</Left>'; 
  var str3 = '<center>' + BETA_MESSAGE + '<br><br><br><form><input type="button" value="Continue" onClick="window.location = \'' + url + '\' "><input type="button" value="Close" onClick="self.close()"></form></center>';
  var str4 = '<center><a href="' + url +'">(Download here if the above <b>Continue</b> button doesn\'t work)</a></center>';
  msgWindow.document.write(head + str2 + str1 + str3 + str4);
}

// This function creates a new window. This one does something different when the continue button is pressed: it runs a download php file to track file downloads.
function messageWindowWithFileTracking(title, msg, size, date, url)
{
  	
  // Get file name from URL, get strings from right side up until slash
	var array1 = url.split('//');
	var array2 = array1[1].split('/'); // second element which is the rest part of the string
	var filename = array2[array2.length-1];
	var php = '../php/download_ftp.php?file=';
	
  // Find out if it's a beta file // Search in side url for term 'beta'. 
  // If its there then print out beta message.
  
var IsBeta = url.indexOf("beta");
if (IsBeta > 0){
	var BETA_MESSAGE = "<p><b>**You are downloading a beta version. Before continuing, be aware that beta versions are <u>not</u> supported by Technical Support.**</b>";
  } else {
    var BETA_MESSAGE = "";
} 
  	
  var width="550", height="650";
  var left = (screen.width/2) - width/2;
  var top = (screen.height/2) - height/2;
  var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  var msgWindow = window.open("","msgWindow", styleStr);
  var head = '<head><title>'+title+'</title></head>';
  var str2 = '<center><h3>Downloading ' + filename + ' </h3></center><p><b>Size:</b> ' + size + '<br><b>Date:</b> ' + date + '</left>';
  var str1 = '<Left>' + msg + '</Left>'; 
  var str3 = '<center>' + BETA_MESSAGE + '<br><br><br><form><input type="button" value="Continue" onClick="window.location = \'' + php + url + '\' "><input type="button" value="Close" onClick="self.close()"></form></center>';
  var str4 = '<center><a href="' + php + url +'">(Download here if the above <b>Continue</b> button doesn\'t work)</a></center>';
  msgWindow.document.write(head + str2 + str1 + str3 + str4);
}


// This function loads the appropriate interface page
function InterfaceLoad(theHref){
	var newWindow
	newWindow = window.open();
	myPause(10000);
	if(newWindow.confirm("Your download should have started. New interfaces may exist for your version. Do you want to check for new interfaces? Clicking OK will open a browser window to a list of available interfaces.")){   
		newWindow.location = "ftp://ftp.wilcoxassoc.com/PC-DMIS-versions/Release/v37/Interfaces/";
	} else {
		newWindow.close();
	}	  	
}

// This function pauses for a certain number of milliseconds
function myPause(myMSec){
	date2 = new Date();
	var date1 = null;
	while(date1-date2 < myMSec){
		var date1 = new Date();
		newWindow.status = date1-date2;
	}
}

// This function writes a text message in a blank <p id="message"></p> and changes its style to "shade".
function messageInCurrentWindow(message,size, date, url)
{  	
  // Get file name from URL, get strings from right side up until slash
	var array1 = url.split('//');
	var array2 = array1[1].split('/'); // second element which is the rest part of the string
	var filename = array2[array2.length-1];
	var closebutton = '<center><form name="form"><input name="Close" value="Close Message" type="button" onClick="clearMsg()"></form></center>';
	var msg = 'Your download should have started or will start in a few seconds. If not, <a href='+ url +'>click here.</a></p><hr>' + message + closebutton;	
    var str1 = '<a name=Message></a><center><h3 class="blueheader2">Downloading ' + filename + ' </h3></center>';
	var str2 = '<p><b>Size:</b> ' + size + '<br><b>Date:</b> ' + date;
    var str3 = '<p><Left>' + msg + '</Left>'; 
  document.getElementById("message").setAttribute("class","shade");
  document.getElementById("message").innerHTML=str1 + str2 + str3;
  location.href="#Message";

}

function messageInCurrentWindow37Step(size, date, url)
{  	
  // Get file name from URL, get strings from right side up until slash
	var array1 = url.split('//');
	var array2 = array1[1].split('/'); // second element which is the rest part of the string
	var filename = array2[array2.length-1];
	//var php = '../php/download_ftp.php?file=';
	var closebutton = '<center><form name="form"><input name="Close" value="Close Message" type="button" onClick="clearMsg()"></form></center>';
	var msg = 'Your download should have started or will start in a few seconds. If not, <a href='+ url +'>click here.</a></p>' + SMA_DATE_INSTRUCTIONS_HTML_STEP_PATCH + closebutton;	
    var str1 = '<a name=Message></a><center><h3 class="blueheader2">Downloading ' + filename + ' </h3></center>';
	var str2 = '<p><b>Size:</b> ' + size + '<br><b>Date:</b> ' + date;
    var str3 = '<p><Left>' + msg + '</Left>'; 
  document.getElementById("message").setAttribute("class","shade");
  document.getElementById("message").innerHTML=str1 + str2 + str3;
  location.href="#Message";

}

function clearMsg() 
{
  document.getElementById("message").setAttribute("class","");
  document.getElementById("message").innerHTML="";
}
