//JAVA SCRIPT  COOKIE FUNCTIONS 
//
//

function checkPicture()
{
  if (window.document.forms[0].pic.value == "")	
  {
  	var ret;
  	ret = confirm('You have not indicated a picture file; it is not required. Do you wish to sign the roster without submitting a picture?');
	if (ret)
	{
  	   window.document.forms[0].NO_PIC.value = '1';
	}
	else
	{
		window.document.forms[0].NO_PIC.value = '2';
	}
  }
}

function testit()
{
	alert( "A BAFA NAPOLI!!");
	return false;
}

function redirect(sURL)
{
	location.href=sURL;	
}

function valLoginPassword()
{
 var sUID,sPassword, sConfirmPW, sAnswer;
 
 //get the variables from the form
 sUID        = new String(window.document.forms[0].UID.value);
 sPassword   = new String(window.document.forms[0].password.value);
 sConfirmPW	 = new String(window.document.forms[0].confirmpw.value);
 sAnswer	 = new String(window.document.forms[0].securityanswer.value);
 
 //test variables for blanks
 if (window.document.forms[0].UID.value.length == 0)
 {
  alert("Please enter a Log-in ID");
  return false;
 }
  
 if (window.document.forms[0].password.value.length == 0)
 {
  alert("Please enter a password [8 or more characters, please use letters and numbers]");
  return false;
 }
 
 if (window.document.forms[0].confirmpw.value.length == 0)
 {
  alert("Please enter your password again to confirm it");
  return false;
 }
 
 if (window.document.forms[0].securityanswer.value.length == 0)
 {
  alert("Please enter an answer to the security question you selected");
  return false;
 }
 
  return true; 
}

function goHome()
{
	location.href="index.html";
}

function getHelp()
{
   open( "help.html", 
   		 "Project Help", 
		 width=800, 
		 height=400, 
		 scrollbars=yes, 
		 resizable=yes, 
		 toolbar=yes, 
		 location=no, 
		 directories=no, 
		 menubar=no );
}

function Stripper( sVal )
{
  var i,iLen,iCode,cChr,sRet,sWork;
  
  sWork = new String(sVal);
  iLen = sWork.length;
  sRet = "";
  
  for( i=0; i < iLen; i++ )
  {
     cChr = sWork.charAt(i);
	 iCode= sWork.charCodeAt(i);
	 	 
	 /* allow only a-z, A-Z, 0-9 */
	 if ( (iCode >=97 && iCode <=122) || 
	      (iCode >=65 && iCode <=90) || 
		  (iCode >=48 && iCode <=57) )
	    sRet = sRet + cChr 
  }/* end for */
  
 return ( new String(sRet) );
}


function SubmitProj()
{
 var sProjDir;
 var sDateTime;
 var aVal;
 var sTemp;
 var cChar;
 var sVal;
 var iLen;
 var i,x;
 
 /* get the project name, create string obj, create an array of tokens */
 sProjVal  = new String(window.document.forms[0].ProjName.value);
 
 /* validate for project name */
 if ( sProjVal == "" )
 {
    alert( "Please enter a 'Project Name'." );
	window.document.forms[0].ProjName.focus();
	return( false );
 }   
 
 /* validate for project type */
 iIndex = window.document.forms[0].lstProjType.selectedIndex;
 FieldVal = window.document.forms[0].lstProjType[iIndex].text;
 if ( FieldVal == "Select a Project Type:" )
 {
    alert( "Please select a a 'Project Type'");
    window.document.forms[0].lstProjType.focus();
    return( false );
 }	
  
 /* split the supplied info into tokens */ 
 aVal = sProjVal.split(" ");
 iLen = aVal.length;
 sVal = new String("");
 
 /* start building the directory name from the tokens */
 for ( i = 0,x = 0; i < iLen; i++ )
 {
     if (x==0)
	 {
        sVal = sVal + Stripper(aVal[i]);
		x = 1;
     }
	 else
	 {
       sTemp = Stripper(aVal[i]);
	   sVal = sVal + sTemp.charAt(0);
	 }
 }/* end for */
 
 /* add data-time component; minutes,seconds */
 sTemp = "";
 sDateTime = new String(Date());
 sTemp = Stripper( sDateTime.substring(14,19) );
 sVal = sVal + sTemp;
   
 /* populate the hidden fields */
 
 window.document.forms[0].Project.value = sVal;
 window.document.forms[0].ProjLink.value = sVal+".shtml";

 return(true);
}  

// "Internal" function to return the decoded value of a cookie

function editEntry()
{
   document.write( "this will replace the current document!" );
}

//
function JCgetCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}


//
//  Function to correct for 2.x Mac date bug.  Call this function to
//  fix a date object prior to passing it to JCSetCookie.
//  IMPORTANT:  This function should only be called *once* for
//  any given date object!  See example at the end of this document.
//
function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}


//
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
//
function JCGetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
 
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return JCgetCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  //return null;
  return ""
  
}


//
//  Function to create or update a cookie.
//    name - String object containing the cookie name.
//    value - String object containing the cookie value.  May contain
//      any valid string characters.
//    [expires] - Date object containing the expiration data of the cookie.  If
//      omitted or null, expires the cookie at the end of the current session.
//    [path] - String object indicating the path for which the cookie is valid.
//      If omitted or null, uses the path of the calling document.
//    [domain] - String object indicating the domain for which the cookie is
//      valid.  If omitted or null, uses the domain of the calling document.
//    [secure] - Boolean (true/false) value indicating whether cookie transmission
//      requires a secure channel (HTTPS).  
//
//  The first two parameters are required.  The others, if supplied, must
//  be passed in the order listed above.  To omit an unused optional field,
//  use null as a place holder.  For example, to call JCSetCookie using name,
//  value and path, you would code:
//
//      JCSetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//
//  To set a secure cookie for path "/myPath", that expires after the
//  current session, you might code:
//
//      JCSetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//
function JCSetCookie (name,value,expires,path,domain,secure) {
var MyCookie

/*
MyCookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
*/
    
MyCookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=/" : "; path=/") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");



    document.cookie = MyCookie
    
}


//  Function to delete a cookie. (Sets expiration date to start of epoch)
//    name -   String object containing the cookie name
//    path -   String object containing the path of the cookie to delete.  This MUST
//             be the same as the path used to create the cookie, or null/omitted if
//             no path was specified when creating the cookie.
//    domain - String object containing the domain of the cookie to delete.  This MUST
//             be the same as the domain used to create the cookie, or null/omitted if
//             no domain was specified when creating the cookie.
//
function JCDeleteCookie (name,path,domain) {
  if (JCGetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


