// JavaScript Learn to Surf LA - lesson specific scripts

<!--

function setApptStatus()
{
    var lsnArray = new Array ("Fourth", "Fifth", "Sixth", "Seventh", "Eighth", "Ninth", "Tenth");
	var lsnIndex;
	var fieldsArray = new Array ("month", "day", "time");
	var fldIndex;
	var enableArray = new Array ();
	var disableArray = new Array ();
	var elementIndex;
	var nameStr = new String ();
	var tempElement = null;

	for (lsnIndex in lsnArray)
	{
		for (fldIndex in fieldsArray)
		{
			nameStr = lsnArray[lsnIndex] + "_" + fieldsArray[fldIndex] + "_requested";
			tempElement = document.getElementsByName (nameStr)[0];
			
			if (lsnIndex <= document.surf_info.Number_of_Lessons.value - 4)
			{
				if (tempElement) enableArray.push (tempElement);
			}
			else
			{
				if (tempElement) disableArray.push (tempElement);
			}
		}
	}
	
	for (elementIndex in disableArray)
	{
		disableArray[elementIndex].disabled = true;
	}

	for (elementIndex in enableArray)
	{
		enableArray[elementIndex].disabled = false;
	}
}


function calculateLessonPrice() 
{
	var lessonId = document.surf_info.Type_of_Lesson.id;
	var priceElement = document.surf_info.Total_Price;
	var studentsIndex = document.surf_info.Number_of_Students.selectedIndex + 1;
	var typeIndex = document.surf_info.Type_of_Lesson.selectedIndex;
	var numLessons = 0;
	var finalPrice = 0;
	var priceArray = null;
	
	if (isNaN (studentsIndex)) studentsIndex = 0;
	if (document.surf_info.Number_of_Lessons) numLessons = document.surf_info.Number_of_Lessons.value;
	if (lessonId.search("lessons") >= 0)
	{
		if ((typeIndex == 1) || (typeIndex == 3))
		{
			if (studentsIndex >= 20)finalPrice = (50 * studentsIndex) * numLessons;
			else if (studentsIndex >= 10)
			{
				if ((studentsIndex >= 17) && (studentsIndex <= 19)) finalPrice = 1000;
				else finalPrice = (60 * studentsIndex);
				finalPrice *= numLessons;
			}
			else
			{//calculate regular pricing
				if (numLessons < 3) //single lesson rates
				{
					if (studentsIndex >= 1) finalPrice = 120;
					if (studentsIndex >= 2) finalPrice += 80;
					if (studentsIndex >= 3) finalPrice += (60 * (studentsIndex - 2));
				}
				else if (numLessons < 5) //3 lesson pkg rates
				{
					if (studentsIndex >= 1) finalPrice = 110;
					if (studentsIndex >= 2) finalPrice += 75;
					if (studentsIndex >= 3) finalPrice += (50 * (studentsIndex - 2));
				}
				else if (numLessons < 7) //5 lesson pkg rates
				{
					if (studentsIndex >= 1) finalPrice = 105;
					if (studentsIndex >= 2) finalPrice += 75;
					if (studentsIndex >= 3) finalPrice += (40 * (studentsIndex - 2));
				}
				else //7 lesson pkg rates
				{
					if (studentsIndex >= 1) finalPrice = 100;
					if (studentsIndex >= 2) finalPrice += 75;
					if (studentsIndex >= 3) finalPrice += 45;
					if (studentsIndex >= 4) finalPrice += (40 * (studentsIndex - 3));
				}
				
				//correction for pre-discount lessons
				if (studentsIndex == 9) finalPrice = 600;
				
				finalPrice *= numLessons;
			}
		}
		else if (typeIndex == 2)
		{
			if (numLessons < 4) basePrice = 75;
			else basePrice = 70;
			finalPrice = numLessons * studentsIndex * basePrice;
		}

		/*priceArray = new Array (new Array ("0", "0", "0", "0", "0", "0"), //nothing selected
								new Array ("0", "120", "200", "260", "320", "380"), //private lesson
								new Array ("0", "75", "150", "225", "300", "375"),  //progressive group
								new Array ("0", "280", "560", "840", "1120", "1400"), //group pkg of 4
								new Array ("0", "0", "0", "0", "0", "0"),              //large/corporate group
								new Array ("0", "330", "550", "700", "850", "1000"), //3 lesson pkg
								new Array ("0", "525", "900", "1100", "1300", "1500"), //5 lesson pkg
								new Array ("0", "700", "1200", "1500", "1750", "2000"), //7 lesson pkg
								new Array ("0", "0", "0", "0", "0", "0"));         //other */
	}
	else if (lessonId.search("concierge") >= 0)
	{
		priceArray = new Array (new Array ("0", "0", "0", "0", "0", "0"), //nothing selected
								new Array ("0", "140", "240", "320", "400", "480"), //private lesson
								new Array ("0", "90", "180", "270", "360", "450"),  //progressive group
								new Array ("0", "420", "720", "960", "1200", "1440"), //3 lesson pkg
								new Array ("0", "700", "1200", "1600", "2000", "2400"), //5 lesson pkg
								new Array ("0", "980", "1680", "2240", "2800", "3360")); //7 lesson pkg
	}
	else if (lessonId.search("xperience_days") >= 0)
	{
		priceArray = new Array (new Array ("0", "0", "0", "0", "0", "0"), //nothing selected
								new Array ("0", "110", "174", "231", "288", "345"));
	}
	else if (lessonId.search("gad") >= 0)
	{
		priceArray = new Array (new Array ("0", "0", "0"), //nothing selected
								new Array ("0", "120", "180"),
								new Array ("0", "330", "500"));
	}
	else if (lessonId.search("cloud9") >= 0)
	{
		priceArray = new Array (new Array ("0", "0", "0"), //nothing selected
								new Array ("0", "108", "180"),
								new Array ("0", "270", "450"));
	}
	else if (lessonId.search("extravagift") >= 0)
	{
		priceArray = new Array (new Array ("0", "0", "0"), //nothing selected
								new Array ("0", "110", "190"));
	}
	else if (lessonId.search("smartbox") >= 0)
	{
		studentsIndex = document.surf_info.Number_of_Students.value;
		priceArray = new Array (new Array ("0", "0", "0", "0", "0"), //nothing selected
								new Array ( "0", "0", "210", "0", "0"),
								new Array ("0", "0", "0", "0", "210"));
	}
	else if (lessonId.search("american-pursuits") >= 0)
	{
		priceArray = new Array (new Array ("0", "0", "0", "0", "0", "0"), //nothing selected
								new Array ("0", "120", "200", "260", "320", "380"), //private lesson
								new Array ("0", "75", "150", "225", "300", "375"),  //progressive group
								new Array ("0", "280", "560", "840", "1120", "1400"), //group pkg of 4
								new Array ("0", "0", "0", "0", "0", "0"),              //large/corporate group
								new Array ("0", "330", "555", "705", "855", "1005"), //3 lesson pkg
								new Array ("0", "525", "900", "1100", "1300", "1500"), //5 lesson pkg
								new Array ("0", "700", "1190", "1505", "1785", "2065"), //7 lesson pkg
								new Array ("0", "0", "0", "0", "0", "0"));         //other
	}
	else if (lessonId.search("generic") >= 0)
	{
		if (studentsIndex >= 20)finalPrice = (50 * studentsIndex );
		else if (studentsIndex >= 10) finalPrice = (60 * studentsIndex );
		else
		{//calculate regular pricing
			if (studentsIndex >= 1) finalPrice = 120;
			if (studentsIndex >= 2) finalPrice += 80;
			if (studentsIndex >= 3) finalPrice += (60 * (studentsIndex - 2));
		}
	}

	if ((lessonId.search("generic") == -1) && (lessonId.search("lessons") == -1))
		finalPrice = Number (priceArray [typeIndex] [studentsIndex]);
	
	if (document.surf_info.Referral_Coupon) 
	{
		document.surf_info.Full_Price.value = finalPrice;
		calculateDiscount (document.surf_info);
		finalPrice -= Number (document.surf_info.Coupon_Discount.value);
	}
	
	priceElement.value = String(finalPrice.toFixed(2));
	document.surf_info.amount.value = String(finalPrice);
}


function updateStudentNumber ()
{
	var lessonId = document.surf_info.Type_of_Lesson.id;
	var studentsValue = document.surf_info.Number_of_Students.selectedIndex;
	var typeIndex = document.surf_info.Type_of_Lesson.selectedIndex;

	if (lessonId.search("smartbox") >= 0)
	{
		document.surf_info.Number_of_Students.value = typeIndex * 2;
	}
}


function updateLocation ()
{
	var optionExists = false;
	var optionBelongs = false;
	var removeIndex = null;
	var lessonMonth;
	var lessonDay;
	var lessonNumIndex;
    var lessonNumArray = 
		new Array ("Primary", "Secondary", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth", "Ninth", "Tenth");
		
	//check if location is already an option in the select
	for (index = 0; index < document.surf_info.Location_of_Lesson.length; ++index)
	{
		if (document.surf_info.Location_of_Lesson.options[index].text.search("Manhattan/Dockweiler") >= 0)
		{
			optionExists = true;
			removeIndex = index;
		}
	}

	//check if location should be listed as an option
	for (lessonNumIndex in lessonNumArray)
	{
		lessonMonth = document.getElementsByName (lessonNumArray[lessonNumIndex] + "_month_requested")[0];
		lessonDay = document.getElementsByName (lessonNumArray[lessonNumIndex] + "_day_requested")[0];

		if (lessonMonth && lessonDay)
		{
			optionBelongs |= (((lessonMonth.selectedIndex == 5) && (lessonDay.selectedIndex ==  31)) ||
							  ((lessonMonth.selectedIndex >= 6) && (lessonMonth.selectedIndex <= 8)) ||
							  ((lessonMonth.selectedIndex == 9) && (lessonDay.selectedIndex <=  6)));
		}
	}
	
	//add option if it should be there, remove it if it shouldn't
	if (!optionExists && optionBelongs)
	{
			var newLoc = document.createElement ('option');
			newLoc.value = "Manhattan/Dockweiler - Tower 49";
			newLoc.text = "Manhattan/Dockweiler - Tower 49";
			
			try 
			{
				document.surf_info.Location_of_Lesson.add (newLoc, null);
			}
			catch (ex)
			{
				document.surf_info.Location_of_Lesson.add (newLoc); //ie fix
			}
	}
	else if (optionExists && !optionBelongs) document.surf_info.Location_of_Lesson.remove (removeIndex);

	//update locations for group lessons
	if (document.surf_info.Type_of_Lesson.value.search("Group") >= 0)
	{
		for (index = 0; index < document.surf_info.Location_of_Lesson.length; ++index)
		{
			if (document.surf_info.Location_of_Lesson.options[index].text.search("Santa Monica") >= 0)
			{
  				document.surf_info.Location_of_Lesson.options[index].value = "Santa Monica - Navy St. Tower";
				document.surf_info.Location_of_Lesson.options[index].text = "Santa Monica - Navy St. Tower";
			}
		}
	}
	else
	{
		for (index = 0; index < document.surf_info.Location_of_Lesson.length; ++index)
		{
			if (document.surf_info.Location_of_Lesson.options[index].text.search("Santa Monica") >= 0)
			{
  				document.surf_info.Location_of_Lesson.options[index].value = "Santa Monica";
				document.surf_info.Location_of_Lesson.options[index].text = "Santa Monica";
			}
		}
	}
}


function set3pNumberOfLessons ()
{
	var lessonType = document.surf_info.Type_of_Lesson.value;

	if (lessonType.search("Package") >= 0) document.surf_info.Number_of_Lessons.value = lessonType.split(" ")[1];
}


function setLessonRegCookies()
{
	var objArray = new Array (document.surf_info.Type_of_Lesson, document.surf_info.Number_of_Students, 
							  document.surf_info.Number_of_Lessons);
	for (objIndex in objArray)
	{
		if (objArray [objIndex].type.search ("select") >= 0) 
			document.cookie = objArray [objIndex].name + "=" + objArray [objIndex].selectedIndex;
	}
}

function getLessonRegCookies()
{
	var cookies = document.cookie.split(';');
	var objArray = new Array (document.surf_info.Type_of_Lesson, document.surf_info.Number_of_Students, 
							  document.surf_info.Number_of_Lessons);
	
	for ( var i = 0; i < cookies.length; ++i)
	{
		var readValue = cookies[i];
		var eqPos = readValue.indexOf ("=");
		var readValue = readValue.substring (eqPos + 1);

		for (objIndex in objArray)
		{
			if (cookies[i].search (objArray [objIndex].name) >= 0)
			{
				if (objArray [objIndex].type.search ("select") >= 0) objArray [objIndex].selectedIndex = readValue;
			}
		}
	}
}

-->