// Cookies.js

/////////////////////////////////////////////////////////////////////////////////
// COOKIE CODE
/////////////////////////////////////////////////////////////////////////////////





//set to expire on December 31, 3099 at 11:59:59
var expiration = new Date();
expiration.setTime(35659382399621);


// Heinle's function for retrieving a cookie.
function getCookie(name){
  var cname = name + "=";
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}

// An adaptation of Dorcht's function for setting a cookie.
function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

// An adaptation of Dorcht's function for deleting a cookie.
function delCookie (name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


function SetName(NewName)
{
	//set this cookie
	setCookie('VisitorName', NewName, expiration);

}

function SetLastName(NewName)
{
	//set this cookie
	setCookie('VisitorLastName', NewName, expiration);

}

function GetName( )
{
	//get this cookie
	return getCookie('VisitorName');
}

function GetLastName( )
{
	//get this cookie
	return getCookie('VisitorLastName');
}

function SetBirthMonth(NewValue)
{
	//set this cookie
	setCookie('VisitorBirthMonth', NewValue, expiration);

}

function GetBirthMonth( )
{
	//get this cookie
	return getCookie('VisitorBirthMonth');
}
function SetBirthDate(NewValue)
{
	//set this cookie
	setCookie('VisitorBirthDate', NewValue, expiration);

}

function GetBirthDate( )
{
	//get this cookie
	return getCookie('VisitorBirthDate');
}

function SetGender(NewValue)
{
	//set this cookie
	setCookie('VisitorGender', NewValue, expiration);

}

function GetGender( )
{
	//get this cookie
	return getCookie('VisitorGender');
}


function DeleteName( )
{
	//delete this cookie
	delCookie('VisitorName');

}

function AskForName( )
{


	var NewName =  GetName();
	var Nada;

	if(NewName == Nada)
	{
		NewName = prompt("Hey, what's your name?");
		if(NewName == null || NewName == "null" || NewName == "" || NewName == Nada) NewName = Nada;
			SetName(NewName);
	}

	NewName =  GetName();
	return NewName;
}

function ResetName( )
{
	NewName = prompt("Hey, what's your name?");
	SetName(NewName);
	return NewName;
}

function Who( )
{
	// return AskForName( );
	return GetName( );
}

function GetWho( )
{
	if(Who( ) != null && Who( ) != 'null')
		return Who( );
	else
		return "";
}

function GetWhoWithText(text)
{
	var VisitorName = getCookie('VisitorName')
	var Nada;
	if(VisitorName != null && VisitorName != 'null' && VisitorName != ""  && VisitorName != Nada)
		return text +VisitorName;
	else
		return "";
}

function GetWhoWithTextBeforeAndAfter(Before, After)
{
	if(GetName( ) != null && GetName( ) != 'null' && GetName( ) != "")
		return Before + GetName( ) + After;
	else
		return "";
}

function WelcomeToTheShow( )
{
	var Nada;
	var VisitorName = getCookie('VisitorName')
	if(VisitorName != null && VisitorName != 'null' && VisitorName != "" && VisitorName != Nada)
		document.write("Welcome, " + VisitorName +"!");
	else
		document.write("Welcome To The Show!");
}

////////////////////////////////////////////////////////////
// THESE FUNCTIONS COMMUNICATE WITH THE USER.
////////////////////////////////////////////////////////////

function SpecialMessage( )
{
	var Nada;
	var VisitorName = getCookie('VisitorName')
	if(VisitorName != null && VisitorName != 'null' && VisitorName != "" && VisitorName != Nada)
		document.write("Hey, " + VisitorName +"!<br><br>Take the day off!");
	else
		document.write("The Carlos Eton Show invites you to check out upcoming shows.");
}


function WriteSpecialMessage( )
{
	var Nada;
	var VisitorName = getCookie('VisitorName');
	
	if(VisitorName == null && VisitorName == 'null' && VisitorName == "" && VisitorName == Nada) return;
	
	if (screen.width >= 1024 &&   screen.height >= 768)
	{
		document.write('<table style="text-align: left; margin-left: auto; margin-right: 0px; width: 198px; height: 120px; font-weight: bold; color: rgb(255, 255, 0);" border="5" cellpadding="5" cellspacing="5"><tr><td style="text-align: center;"background="images/happy-red.jpg"><big>');
		
		if(IsTodayBirthday( ))
		{
			CelebrateBirthDay( );
		}
		else
		{
			SpecialMessage( );
		}
		document.write('</big><br></td></tr></table>');
	}
}


function IsTodayBirthday( )
{
	var TodaysDate = new Date( );
	var UserMonth = GetBirthMonth( );
	var TodaysMonth = TodaysDate.getMonth( ) + 1;
	var UserDay = GetBirthDate( );
	var TodaysDay = TodaysDate.getDate( );
	
	return (UserMonth == TodaysMonth && UserDay == TodaysDay);
	
	
}

function CelebrateBirthDay( )
{
	if(IsTodayBirthday( ) == true)
	{
		var Nada;
		var VisitorName = getCookie('VisitorName');
		var Message = "Happy<br>freakin'<br> birthday";
		
		
		
		if(VisitorName != null && VisitorName != 'null' && VisitorName != "" && VisitorName != Nada)
		{
			Message += ",<br>";
			Message += VisitorName;
		}
		
		Message += " !!!";
		
		
		document.write(Message.toUpperCase( ));
			
	}
}

