// JavaScript Document
// Note that cookieList[accessIndex] must be a string for switch statement 
// v1.aa: Site license: Aug 18, 2004.
var footnote; 
var lastName=ThermoCookieList[lastNameIndex];
var message=new String('<table width=100%  border=0 cellpadding=2 cellspacing=0><tr><td><hr><font face=\"verdana\" size=\"-1\">Visit "My Account" to renew/upgrade your license at any time before '+getExpiryDate()+'.<hr></font></td></tr></table>');
if(ThermoCookieList[mediaIndex]=="WEB") message=new String('<table width=100%  border=0 cellpadding=2 cellspacing=0><tr><td><hr><font face=\"verdana\" size=\"-1\">Each session lasts for 2 hours or until you log out. You have until '+getExpiryDate()+' to renew your license by visiting the My Account page. <hr></font></td></tr></table>');


function loginForm(){
	var modeColor=" #d07500 "; var width=" width=80% ";
    var testCookie = GetTestCookie('testCookie');

    // guest access on the web
    //
    var modeColorWidth, secondString="My Account", firstString="", accountURL=myaccountURL;
    if(ThermoCookieList[mediaIndex]=="LOCAL") accountURL=tomyaccountURL;

    if(ThermoCookieList[accessIndex] == 0 && ThermoCookieList[mediaIndex]=="WEB" && lastName == "Guest" && testCookie == 1 ) {
		document.write('<form name="loginForm" method="post" action='+loginURL+' >');
		document.write("<input type=hidden name=operation value=\"login\">");
		document.write("<table width=\"100%\" bgcolor=\"dddddd\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
	
		document.write("<tr>");
		document.write("  <td width=\"2\">&nbsp;</td>");
		document.write('  <td height=20 colspan=1><font face=verdana size=-1> Log in or <a href='+signupURL+' >create an account.</a></font></td>');
		document.write("  <td width=\"2\">&nbsp;</td>");
		document.write('  <td height=20  colspan=3>[ <A href='+forgotURL+' ><font face=arial size=-1>Forgot password?</font></A>&nbsp;&nbsp;&nbsp;<A href='+changeURL+' ><font face=arial size=-1>Change password</font></A>&nbsp;&nbsp;&nbsp;<A href='+myaccountURL+' target="_top"><font face=arial size=-1>My Account</font></A> ]</td>');
		document.write("</tr>");
	
		document.write("<tr>");
		document.write("  <td width=\"2\">&nbsp;</td>");
		document.write("  <td width=\"190\" height=\"5\" valign=\"middle\"><font face=\"verdana\" size=\"-2\">Login id (e-mail address):</font></td>");
		document.write("  <td width=\"2\">&nbsp;</td>");
		document.write("  <td  height=\"5\" colspan=\"3\" valign=\"middle\"><font face=\"verdana\" size=\"-2\">Password: (Site-licensed users directly click Log In.)</font></td>");
		document.write("</tr>");
	
		document.write("<tr>");
		document.write("  <td width=\"2\">&nbsp;</td>");
		document.write("  <td width=\"190\" height=\"5\" valign=\"top\"><font face=\"verdana\" size=\"-1\"><INPUT name=userid id=\"userid\" size=\"30\" maxLength=\"40\" tabindex=\"1\"></font></td>");
		document.write("  <td width=\"2\">&nbsp;</td>");
		document.write("  <td  height=\"5\" valign=\"top\"><font face=\"verdana\" size=\"-1\"><INPUT name=password type=password id=\"password\" size=\"15\" maxLength=\"15\" tabindex=\"2\"></font></td>");
		today = new Date();
		ts = today.getTime();
		document.write("  <td  colspan=2  width=150><INPUT type=hidden value=\"" + ts + "\" name=\"clientTime\">");
		document.write("  <INPUT type=submit value=\"Log In\" name=log ></td>");

		document.write("</tr>");
	
		document.write("<tr>");
		document.write("  <td width=\"2\">&nbsp;</td>");
		document.write("  <td colspan=\"5\"><INPUT type=checkbox CHECKED value=YES name=SAVEOPTION tabindex=\"4\">");
		document.write("  <font face=\"verdana\" size=\"-1\">Remember my e-mail address and password on this computer.&nbsp;&nbsp;&nbsp;</font></td>");
		document.write("</tr>");
	
		document.write("</table>");
		document.write("</form>");
    }
    else {  
	// web expired, web active, and all local accounts
	//
	var salute=ThermoCookieList[saluteIndex];

	//alert("salutation is: "+salute+" lastname "+lastName);
	if (salute=="Site") {
	    lastName="Licensed User"; 
	    //accountURL=tomyaccountURL; // site licensed users must log in to see the account page.
	}
	
	if(ThermoCookieList[accessIndex] == 0 && ThermoCookieList[mediaIndex]=="WEB") {

	    modeColor=" #d07500 "; width=" width=60% ";

	    if( testCookie == 0 ) {

		document.write('<table align=center width=100% bgcolor=dddddd border=0 cellpadding=5 cellspacing=0 height=20><tr><td BGCOLOR=ffff55'+width+' align=left><font color=#ff0000 face=verdana size=-1><strong>Log In Warning: If you see this message, it means your browser is not allowing cookies to be created. Lower the privacy to Low from the Tools>Internet Options..>Privacy tab. Read the Getting Started section of the Tutorial to make TEST work in your browser. &nbsp;</strong></td></tr></table>');
		return;
	    }

	    firstString="License Alert*" + testCookie;
	    secondString="My Account";
	}
	else if(ThermoCookieList[accessIndex] == 0 && ThermoCookieList[mediaIndex]=="LOCAL") {
	    modeColor=" #d07500 "; width=" width=80% ";
	    firstString="Activate TEST before use.";
	    secondString="My Account";
	}
	else if(ThermoCookieList[accessIndex] ==5 ) {
	    modeColor="#4aa02c"; width=" width=60% ";
	}
	else if(ThermoCookieList[accessIndex] ==10) {
	    modeColor="#5555aa"; width=" width=60% ";
	}
	else if(ThermoCookieList[accessIndex] ==15) {
	    modeColor="#d07500";
	    width=" width=60% ";
	}

	var thirdString="";

	if(ThermoCookieList[mediaIndex]=="WEB") 
	    thirdString="Log Out,";

	//document.write('<table align=center width=100% bgcolor=dddddd border=0 cellpadding=0 cellspacing=0 height=20><tr><td BGCOLOR='+modeColor+width+' align=center><font color=#ffffff face=verdana size=-1><strong>&nbsp;Greetings, ' + ThermoCookieList[saluteIndex] + '&nbsp;' + lastName +  '! </strong>'+firstString+'<font></td><td align=center><a href='+logoutURL+'><font color='+modeColor+' face=verdana size=-1 width=200>'+thirdString+'</a></font>&nbsp&nbsp&nbsp<a href= '+accountURL+' ><font color='+modeColor+' face=verdana size=-1 width=200>'+secondString+'</font></a></td></tr></table>');

	document.write('<table align=center width=100% bgcolor=dddddd border=0 cellpadding=0 cellspacing=0 height=20><tr><td BGCOLOR='+modeColor+width+' align=center><font color=#ffffff face=verdana size=-1><strong>&nbsp;Greetings, ' + ThermoCookieList[saluteIndex] + '&nbsp;' + lastName +  '! </strong>'+firstString+'<font></td><td align=center><a href='+logoutURL+'><font color='+modeColor+' face=verdana size=-1 width=200>'+thirdString+'</a></font>&nbsp&nbsp&nbsp<a href= '+accountURL+' target="_top"><font color='+modeColor+' face=verdana size=-1 width=200>'+secondString+'</font></a></td></tr></table>');

    }
}

function writeHomeHeader(){
	//defalut declaration: Guest Access
	//var headerPart1="headerPart1Guest", headerPart2="headerPart2Guest";
	var headerPart1, headerPart2;
	if(getExpiryStatus()=="true") ThermoCookieList[accessIndex]="0";
				//alert("In case, media, and lastname, "+ThermoCookieList[accessIndex]+actualMedia+ThermoCookieList[lastNameIndex]+message);

	switch(ThermoCookieList[accessIndex]) {
	case "0":

		headerPart1="headerPart1Guest"; headerPart2="headerPart2Guest";
		footnote=new String("Guest Mode/WEB: This is the default mode with very limited access. You may browse the Tutorial or the Slide Show pages to learn about TEST, but you must log in in order to use TEST effectively.");
		message=new String('<br><table width=100%  boder=2 cellpadding=2 cellspacing=0><tr><td><font face=\"verdana\" size=\"-1\" color=blue><hr>Activation Procedure: You must activate this Local Edition of TEST. Activation means downloading a license file and save it in a particular folder. The following instructions assume that you have already copied the entire content of the CD into a local folder named "myTEST" (in your C drive or desktop) and bookmarked this local page in your browser. More detailed instructions can be found in the README.txt file in the CD.<ol><li>If you are not connected to the Internet, go to step-2. Click on the "My Account" link above or point your browser to www.thermofluids.net/myaccount. It will take you to the TEST registration site, where you must log in to access your account. If you do not have an account, you can create one in minutes following the "create an account" link. In case you forgot your password it will be emailed to you as long as you remember your login id (the email address you use during registration). <p>After you log in, you can see your account status in the "My Account" page. There you will see a button  "Send CDROM License" prominantly displayed. Click on it to receive the license file "license.txt" as an email attachment (should take less than a minute). The license file contains the expiration date of your subscription. Log out of "My Account" and check your email. After the "license.txt" file arrives as an attachment, save it in the "testcenter" folder, located inside the "myTEST" folder. The new file replaces an old  file with the same name copied from the CD. <p>Launch TEST again (using your local bookmark or clicking the index.html file in the "myTEST" folder).  A personalized greetings on the home page will indicate that TEST has been successfully activated. Also, this instruction block will disappear until it is time for you to renew your license.<p><li>If you are off line, you have to go to a networked computer, log on to www.thermofluids.net/myaccount, and get the "license.txt" file as described in Step-1. After the file arrives, copy it into a floppy disk or some other moveable media, and transfer it to the "myTEST/testcenter" folder.  <p><li>Once activated, the Local Edition of TEST does not require any network connection. After your license period expires, these instructions will reappear on this page. To extend your license, log on to "My Account" (www.thermofluids.net/myaccount), renew your license,  obtain a fresh license.txt file to update your existing one. Users who renew license before it expires receive significant discounts. <p><li>If you received the cd from a colleague, follow the same procedure starting at Step-1. Of course, you have to create an account first by registering (click on "Register Now" in the "My Account" page). </ol><hr></font></td></tr></table>');


		if(actualMedia=="WEB"&& lastName=="Guest") 		message=new String('<table width=100%   cellpadding=0 cellspacing=0><tr><td width=5></td><td><font face=\"verdana\" size=\"-2\">First time users are recommended to read the Getting Started section of the Tutorial before creating an account. Your browser must be set to allow cookies, and run Javascript, Java, and Flash - again, Getting Started is the right place to start.  </font></td><td width=5></td></tr></table><hr>');
		//if(actualMedia=="WEB" && lastName!="Guest") 		{
			//alert("media and lastname"+actualMedia+" "+getExpiryStatus());
		//if(actualMedia=="WEB" && lastName!="Guest"){ //account expired
		if(actualMedia=="WEB" && getExpiryStatus()=="true"){ //account expired, web user
			//message=new String('<hr><table width=100%   cellpadding=2 cellspacing=0><tr><td width=5></td><td><font face=\"verdana\" size=\"-2\">*Your license needs to be renewed, it expired on '+getExpiryDate()+'. Please use the "My Account" link above to re-activate/upgrade your license.</font></td><td width=5></td></tr></table><hr>');
			message=new String('Dear '+ThermoCookieList[saluteIndex] + ' ' + lastName +',\n\nYour license to use TEST needs to be renewed, which apparently expired on '+getExpiryDate()+'. Click the \"OK\" button \nto close this window and go to \"My Account\" page, where you can renew/upgrade your license in minutes. TEST cannot work in its full capacity in the Guest Mode.\n\nThank you for your support! \n\nS. Bhattacharjee, Author of TEST\nsupport@thermofluids.net');
			alert(message);
			//window.parent.location=myaccountURL;
		}

		if(actualMedia=="LOCAL"){
			headerPart1="headerPart1GuestLocal"; 
			footnote=new String("Guest Mode/Local Edition: This is the default mode with very limited access. You must activate this local edition in order to use TEST effectively.");

		}
			

	    break;
	  case "5":
		headerPart1="headerPart1Evaluation"; headerPart2="headerPart2Evaluation";
		footnote=new String("Evaluation Mode: This mode gives you almost as much access as the Academic Mode for a limited period of time. In the Evaluation Mode run a few daemons to make sure that everything works before upgrading your license to Academic or Professional Mode.");

		if(actualMedia=="LOCAL"){
			headerPart1="headerPart1EvaluationLocal"; 
		}
	    break;
	  case "10":
		headerPart1="headerPart1Academic"; headerPart2="headerPart2Academic";
		footnote=new String("Academic Mode/Web Edition: This mode gives you access to an adequate set of working substances used in thermodynamics education.  Web Edition means you are accessing the latest version of TEST. The access speed is, however, limited by the speed of your connection. If you would like to run TEST locally to enjoy its native performance, order a TEST-CD. The Professional Edition of TEST contains a much larger data base and comes with a CD for local installation. ");

		if(actualMedia=="LOCAL"){
			headerPart1="headerPart1AcademicLocal"; 
					footnote=new String("Academic Mode/Local Edition: This mode gives you access to an adequate set of working substances used in thermodynamics education. Local installation means access speed is at its fastest and no Internet connection is necessary. The Professional Edition of TEST contains a much larger data base. ");

		}
	    break;
	  case "15":
		headerPart1="headerPart1Professional"; headerPart2="headerPart2Professional";
		footnote=new String("Professional Mode/Web Edition: This mode gives you complete access to the growing list of working substances available in the TEST database. Web Edition means you are accessing the latest version of TEST. The access speed is, however, limited by the speed of your connection. For best access, obtain a license with a CD so that you can run TEST locally for speed and access the Web Edition to use the latest version from anywhere. ");

		if(actualMedia=="LOCAL"){
			headerPart1="headerPart1ProfessionalLocal"; 
		footnote=new String("Professional Mode/Local Edition: This mode gives you complete access to the growing list of working substances available in the TEST database. Local installation means access speed is at its fastest. Occasionally access TEST on line to see if the on line version has improved sufficiently to justify an upgrade.");
		}
	    break;
	  default:
 break;
	}
		document.write('<tr><td bgcolor=#ffffff valign=top align=center width=20%><img src="testcentericons/testLogoEd.jpg" Alt="TEST Logo" nosave border=0 width=100 height=90 usemap="#m_testLogoEd"><map name="m_testLogoEd"><area shape="rect" coords="17,0,24,6" href='+adminURL+'><area shape="rect" coords="25,0,31,6" href="http://energy.sdsu.edu/awstats/awstats.pl?config=energy.sdsu.edu"></map></td><td width=75% valign=top align=middle ><a target="_top" href="http://www.thermofluids.net"><img src="testcentericons/'+headerPart1+'.jpg" nosave border=0 width=590 height=90></a></td><td bgcolor=#ffffff valign=top align=middle width=5%><img src="testcentericons/'+headerPart2+'.jpg" width=40 height=90  alt="About TEST-Pro" border=0></td></tr>');


}

function writeHomeMessage(){
	document.write(message);
	}

function writeHomeFootnote(){
	document.write('<font color=999999>'+footnote+'</font>');
}

function writeMirror(){
	var mirrorFile="webEdition.jpg";
	if(actualMedia=="WEB") mirrorFile="webMirror.jpg";
	document.write('<img src=testcentericons/'+mirrorFile+'>');
}
function writeHomeCount(){	
		document.write('<td bgcolor=dddddd></td><td bgcolor=#eeeeee valign=middle><img src=testcentericons/footer.jpg valign=top NOSAVE></td>');

/*	if(ThermoCookieList[mediaIndex]=="WEB") {
		//document.write('<img src=testcentericons/counter.jpg valign=top NOSAVE><img valign=top  src="http://thermo.sdsu.edu/stats/total.php">');
		document.write('<td bgcolor=#eeeeee valign=middle    height=34 colspan=2><table width=100% border=0 cellpadding=0 cellspacing=0 align=center><tr><td align=center colspan=3><font face=verdana size="-2">Registered Users</font></td><td align=center><font face=verdana size="-2">Pages Browsed (since 2004)</font></td></tr><td align=center ><img valign=top   align=center src='+studentCount+' ></td><td align=center><img valign=top  src='+eduCount+'></td><td align=center><img valign=top   src='+proCount+'></td><td align=center><img valign=top  src='+pageCount+'></td></tr></table></td>');
		
		


	}
	else {
	}*/
}

function openPopUpWindow(winURL, winWidth, winHeight, winFeatures, winLeft, winTop){
  var defaultPixelLeft = 200
  var defaultPixelTop = 20
  windowName = "popUpWindow" + windowCount++ //unique name for each pop-up window
  closePopUpWindow()
  if (openPopUpWindow.arguments.length >= 4)
    winFeatures = "," + winFeatures
  else
    winFeatures = ""
  if (openPopUpWindow.arguments.length == 6)
    winFeatures += getLocation(winWidth, winHeight, winLeft, winTop)
		 
  else 
    winFeatures += getLocation(winWidth, winHeight, defaultPixelLeft, defaultPixelTop)
  
  popUpWindow = window.open(winURL, windowName, "width=" + winWidth
           + ",height=" + winHeight +  winFeatures)
  //popUpWindow.moveTo(screen.availWidth-winWidth,0)
  //popUpWindow.resizeTo(winWidth,screen.availHeight)
  //alert("resizing in bottom.html");
	//popUpWindow.moveTo(screen.availWidth/2-100,0)		
    //resizeTo(screen.availWidth*.4,screen.availHeight*.8)
   
  }
