﻿// JScript File
function validate()
{
 var str_Errors = "";
 var str_Error_Header = "";

 try
   {
    
      //--{Validate user email address}
      if (document.getElementById("Email").value == "")
          {str_Errors += "Your email address is required to login. \n\n"; }
      else
       {
          //--{Validate user email address format}
          if (!validateEmail(document.getElementById("Email").value))
          {str_Errors += "The email address you entered is invalid. Please try again. \n\n"; }
       }
      
     //--{Validate exists of a password} 
      //if (!document.getElementById("Password").optional)
      // {
       //   if (document.getElementById("Password").value == "")
       //       {str_Errors += "Your password is required to login. \n\n"; }
       // }
       
     //--{Displays an error message if the email was invalid}      
      if (str_Errors.length > 0)
         {  
           str_Error_Header  = '______________________________________________________\n\n';
           str_Error_Header += 'The form was not submitted because of the following error(s).\n';
           str_Error_Header += 'Please correct these error(s) and re-submit.\n';
           str_Error_Header += '______________________________________________________\n\n';
           str_Error_Header += str_Errors;
           window.alert(str_Error_Header);
           return false;
         }
       else
         {
         
             if (document.getElementById("autosign").checked) {    
      	           if (window.navigator.cookieEnabled) {
      	                var oneDay= 1*24*60*60*1000;
                        var expDate = new Date();
                            expDate.setTime (expDate.getTime() + oneDay);
                        var cookieExpires = expDate.toGMTString();
              
                        //set your temprorary cookie
                          window.document.cookie="verifyCookie=test; expires="+cookieExpires
                          if (window.document.cookie.length>0) {
      	                       expDate = new Date('September 11, 2077');
      	                       var ncookie = SetCookie ('mynth', document.getElementById("Email").value + ',' + document.getElementById("Password").value + ',' , expDate, null, null, false);
      	                       return true;
      	                  } else {
      	                      window.alert('"Accept Cookies" must be enabled for your browser in order for this site to log you in automatically on your future visits.');
                              return false;      	     
      	                  }
              	   
      	           } else {
      	             window.alert('"Accept Cookies" must be enabled for your browser in order for this site to log you in automatically on your future visits.');
                     return false;      	     
      	           }
          	
      	     } else { return true; }
      	 
         return true; 
         
         }
    }
   catch(e) 
   {
   //--{Handle all error exceptions}
       window.alert(e.message);
    }
   finally {
   //--{Finalized the execution of this method}    
        window.status = "Ready";
    }
}

function validateEmail( strValue) {
/************************************************
DESCRIPTION: Validates that a string contains a
  valid email pattern.

 PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS: Accounts for email with country appended
  does not validate that email contains valid URL
  type (.com, .gov, etc.) or valid country suffix.
*************************************************/
var objRegExp  = /(^[a-z]([a-z_0-9\.\-]*)@([a-z_0-9\.\-]*)([.][a-z]{3})$)|(^[a-z]([a-z_0-9\.]*)@([a-z_0-9\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;

  //check for valid email
  return objRegExp.test(strValue);
}
function getCookieVal (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 SetCookie.
//  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 GetCookie (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 getCookieVal (j);
	i = document.cookie.indexOf(' ', i) + 1;
    if (i == 0) break; 
  }
return null;
}
//
//  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 SetCookie using name,
//  value and path, you would code:
//
//      SetCookie ("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:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + '=' + escape (value) +
    ((expires) ? '; expires=' + expires.toGMTString() : '') +
    ((path) ? '; path=' + path : '') +
    ((domain) ? '; domain=' + domain : '') +
    ((secure) ? '; secure' : '');
}

//  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 DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + '=' +
      ((path) ? '; path=' + path : '') +
      ((domain) ? '; domain=' + domain : '') +
      '; expires=Thu, 01-Jan-70 00:00:01 GMT';
  }
}

function autologin()
{
  if (window.navigator.cookieEnabled) {
	  var myCookie = GetCookie('mynth'); 
	   if (myCookie != null)  {
	    	var nLogin = myCookie.split(',');
			if (get_QueryString("logout") != "1")
	    	{
			document.getElementById("Email").value = nLogin[0];
			document.getElementById("Password").value = nLogin[1]; 
			window.document.location.href = 'myShows.aspx?user=' + nLogin[0]; 
		    }
		} 
  } 
     
}
function registration()
{
    //--{Purpose......}{This member sends the user to the current customer registration form.}\
    //--{Parameters...}{none}
    //--{Returns......}{none}
    
    //--{Define Local Variables}
    
    try
     {
         if (document.getElementById("rdoYes").checked) 
         { document.location.href = "register.aspx"; }
          else
         { document.location.href = "newcustomer.aspx"; }
         
     }
    catch(e) 
    {
    //--{Handle all error exceptions}
       window.alert(e.message);
     }
    finally {
    //--{Finalized the execution of this method}    
        window.status = "Ready";
    }
    
}
  function get_emailaddress()
{
 if (window.navigator.cookieEnabled) {
      var myCookie = GetCookie('mynth'); 
       if (myCookie != null)  {
	        var nLogin = myCookie.split(',');
	        document.getElementById("hidepass").value = nLogin[0];
	        //window.document.loginForm.Email.value = nLogin[0];
	        //window.document.loginForm.Password.value  = nLogin[1]; 
	        //window.document.loginForm.submit(); 
        } 
  } 
} 
 function return_emailaddress()
{
  var str_Return = "";
  
     if (window.navigator.cookieEnabled) {
          var myCookie = GetCookie('mynth'); 
           if (myCookie != null)  {
	            var nLogin = myCookie.split(',');
	            str_Return  = nLogin[0];
	        } 
      } 
      return str_Return;
      
} 

function password_Change_Validate()
{
 var str_Errors = "";
 var str_Error_Header = "";

 try
   {
      
     //--{Validate exists of a password} 
      if ((document.getElementById("Password").value == "") || (document.getElementById("Password").value.length < 4))
              {str_Errors += "The password field is required and must be greater than 4 characters. \n\n"; }
      
      if (document.getElementById("Password").value != document.getElementById("ConfirmPassword").value)
              {str_Errors += "Your passwords do not match. Make sure both Password and Confirm Password are the same. \n\n"; }
       
     //--{Displays an error message if the email was invalid}      
      if (str_Errors.length > 0)
         {  
           str_Error_Header  = '______________________________________________________\n\n';
           str_Error_Header += 'The form was not submitted because of the following error(s).\n';
           str_Error_Header += 'Please correct these error(s) and re-submit.\n';
           str_Error_Header += '______________________________________________________\n\n';
           str_Error_Header += str_Errors;
           window.alert(str_Error_Header);
           return false;
         }
       else
        { return true;  }
    }
   catch(e) 
   {
   //--{Handle all error exceptions}
       window.alert(e.message);
    }
   finally {
   //--{Finalized the execution of this method}    
        window.status = "Ready";
    }
}

function get_AccountManagers()
{
  
  var str_value = return_emailaddress();
  window.open('accountmanagement.aspx?acct=' + str_value, 'accountmanager' , 'toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=no, width=420, height=350 top=5 left=5');
  
}
function change_Password()
{
  window.open('changepassword.aspx', 'changepassword' , 'toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=no, width=520, height=300 top=5 left=5');
}
function validateUSDate( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid dates with 2 digit month, 2 digit day,
    4 digit year. Date separator can be ., -, or /.
    Uses combination of regular expressions and
    string parsing to validate date.
    Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS:
   Avoids some of the limitations of the Date.parse()
   method such as the date separator character.
*************************************************/
  var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
 
  //check to see if in correct format
  if(!objRegExp.test(strValue))
    return false; //doesn't match pattern, bad date
  else{
    var strSeparator = strValue.substring(2,3) 
    var arrayDate = strValue.split(strSeparator); 
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, 
                        '04' : 30,'05' : 31,
                        '06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,
                        '10' : 31,'11' : 30,'12' : 31}
    var intDay = parseInt(arrayDate[1],10); 

    //check if month value and day value agree
    if(arrayLookup[arrayDate[0]] != null) {
      if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
        return true; //found in lookup table, good date
    }
    
    //check for February (bugfix 20050322)
    //bugfix  for parseInt kevin
    //bugfix  biss year  O.Jp Voutat
    var intMonth = parseInt(arrayDate[0],10);
    if (intMonth == 2) { 
       var intYear = parseInt(arrayDate[2]);
       if (intDay > 0 && intDay < 29) {
           return true;
       }
       else if (intDay == 29) {
         if ((intYear % 4 == 0) && (intYear % 100 != 0) || 
             (intYear % 400 == 0)) {
              // year div by 4 and ((not div by 100) or div by 400) ->ok
             return true;
         }   
       }
    }
  }  
  return false; //any other values, bad date
}

function validate_SearchForm()
{
   
 var str_Errors = "";
 var str_Error_Header = "";

 try
   {
   
    
     if (document.getElementById("startdate").value != "")
      {
         if (!validateUSDate(document.getElementById("startdate").value))
         {str_Errors += "The date in the first date field is invalid . Please enter a valid date. \n\n"; } }
         
      if (document.getElementById("enddate").value != "")
      {
         if (!validateUSDate(document.getElementById("enddate").value))
         {str_Errors += "The date in the second date field is invalid . Please enter a valid date. \n\n"; } }
    
      if ((document.getElementById("startdate").value != "") && (document.getElementById("enddate").value != ""))
       {
            var sDate = new Date(document.getElementById("startdate").value);
            var eDate = new Date(document.getElementById("enddate").value);
            
            if (sDate > eDate)
            {str_Errors += "The second date field must be greater than the first date field. Please try again. \n\n"; } 
       } 
       
     //--{Displays an error message if the email was invalid}      
      if (str_Errors.length > 0)
         {  
           str_Error_Header  = '______________________________________________________\n\n';
           str_Error_Header += 'The form was not submitted because of the following error(s).\n';
           str_Error_Header += 'Please correct these error(s) and re-submit.\n';
           str_Error_Header += '______________________________________________________\n\n';
           str_Error_Header += str_Errors;
           window.alert(str_Error_Header);
           return false;
         }
        else {return true; }
     }
   
   catch(e) 
   {
   //--{Handle all error exceptions}
       window.alert(e.message);
    }
   finally {
   //--{Finalized the execution of this method}    
        window.status = "Ready";
    }
}
function get_QueryString( name )
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}