/* NOTE:   
Additional Functions for window pop ups used in 
Personalization are in include.js*/


function personal_greeting()
{
//
// main function
//
var  hatDesc = new Object();
hatDesc[0] = "ravenclaw";
hatDesc[1] = "gryffindor";
hatDesc[2] = "slytherin";
hatDesc[3] = "hufflepuff";

var  wandDesc = new Object();
wandDesc[0] = "Unknown Length";
wandDesc[1] = "Phoenix Feather, Maple, 7 1/2 inches";
wandDesc[2] = "Dragon Heartstring, Cedar, 13 inches";
wandDesc[3] = "Unicorn Hair, Willow, 10 inches";
wandDesc[4] = "Phoenix Feather, Holly, 10 inches";
wandDesc[5] = "Phoenix Feather, Redwood, 8 3/4 inches";
wandDesc[6] = "Unicorn Hair, Yew, 9 inches";
wandDesc[7] = "Unicorn Hair, Mahogany, 8 inches";
wandDesc[8] = "Dragon Heartstring, Ash, 7 inches";

var HPcookieName = "wbhp_visitor_id=";
var HPcookieLen = HPcookieName.length;
var HPpfcookie = "wbhp_pf=";
var HPpfcookieLen = HPpfcookie.length;
var HPsproutcookie = "HPsprout";
var HPsproutcookieLen = HPsproutcookie.length;
var HPCookie = "";
var HPpf = "";
var HPsprout = "";
var sproutMsg = "";
var dc = document.cookie;
var dcLen = document.cookie.length;
var offset = 0;
var endstr = dcLen;
var cookieName=" ";
var cookieHat="-1";
var cookieWand = "-1";
//
// if the new cookie is there,  read the value
//
if (dcLen > 0) 
{
	var begstr = dc.indexOf(HPcookieName);
	if (begstr !=  -1)
	{
		offset = begstr + HPcookieLen;
		endstr = dc.indexOf(";", offset);
		if (endstr == -1)
			endstr = dcLen;
		HPCookie = unescape(dc.substring(offset,endstr));
	}
}

if (HPCookie != "") 
{
   var separator = HPCookie.indexOf("<^>");
   var hatptr = HPCookie.indexOf("=",separator);
   cookieName = HPCookie.substring(HPCookie.indexOf("=")+1,separator);
   cookieHat = HPCookie.substring(hatptr+1,HPCookie.length);
}

//Now, let get wand information
if (dcLen > 0)
{
        var begstr = dc.indexOf(HPpfcookie);
        if (begstr !=  -1)
        {
                offset = begstr + HPpfcookieLen;
                endstr = dc.indexOf(";", offset);
                if (endstr == -1)
                        endstr = dcLen;
                HPpf = unescape(dc.substring(offset,endstr));
        }
}
if (HPpf != "") 
{
   cookieWand = HPpf.substring(HPpf.indexOf("=")+1,HPpf.indexOf("<^>"));
}

//Okay, if sprout cookie exist and session equal to 5, they complete the class
if (dcLen > 0)
{
	var begstr = dc.indexOf(HPsproutcookie);
	if (begstr != -1)
	{
		offset = begstr + HPsproutcookieLen + 1;
		endstr = dc.indexOf(";",offset);
		if (endstr == -1)
			endstr = dcLen;
		HPsprout = unescape(dc.substring(offset,endstr));
		var dataArray = new Array(20);
		dataArray = HPsprout.split("^^");
		if (dataArray[13] == 5)
		{
			sproutMsg = '<span class="personalization">You have <b>passed</b>  Herbology Class</span><br><br>';
		}
	}
}

//  Let check the value
if (cookieHat <0 || cookieHat >3)
	cookieHat = "-1";
if (cookieWand <0 || cookieWand > 8)
	cookieWand = "-1";

if (cookieHat == "-1") {
   document.write('<table width="770" border="0" cellspacing="2" cellpadding="2">\n');
   document.write('<tr valign="top">\n');
   document.write('<td class="personalization">\n');
   document.write('<span class="personalization"><b>&nbsp;&nbsp;Welcome to harrypotter.com!</b>\n');
   if (cookieName == " ") {
	document.write('Click <a href="javascript:launchHogwarts();" class="personalization">here</a> to enroll at Hogwarts.<br></span>\n');
   } else { 
	document.write('<img src="/hogwarts/sortinghat/img/hogwarts_enroll_inprocess.gif"><br></span>\n');
   }
   document.write('</td>\n');
   document.write('</tr>\n');
   document.write('</table>\n');
} else {
   document.write('<table width="770" border="0" cellspacing="2" cellpadding="2">\n');
   document.write('<tr valign="top">\n');
   //Display welcome message
   document.write('<td class="personalization" valign="top"><b>&nbsp;&nbsp;Welcome '+ cookieName + '</b>,&nbsp;&nbsp;');
   if (cookieWand != "-1") {
   	document.write('Your Wand is ' + wandDesc[cookieWand]);
   } else {
   	document.write('<a href="javascript:launchWandshop();" class="personalization">Get your wand!</a>'); 
   }
   //Sprout message
   document.write(sproutMsg + '&nbsp;&nbsp;');
    //create the link to personalization page
	var newUrl = '/hogwarts/personalization/pp_' + hatDesc[cookieHat] + '.html';
	document.write('<a href=javascript:launchPersonalization("' + newUrl + '") class=personalization>Go to My Hogwarts Page</a>&nbsp;&nbsp;&nbsp;<a href=javascript:launchPersonalization("/web/hogwarts/sortinghat/index.jsp?HatSel=on") class=personalization>Return to the Great Hall</a></td>'); 
   document.write('</tr>\n');
   document.write('</table>\n');
}
}
