//
// JavaScript:
// cruise.js
// Dong Chen
//
// WARNING: MAKE SURE YOU KNOW WHAT YOU ARE DOING BEFORE MODIFING ...

////////////////////////////////////
function populateDestination(inForm)
{
	var month = inForm.FROM.options[document.Search.FROM.options.selectedIndex].value;

	month = month.replace(/-/gi, "");

	var selectedArray = eval("Cruise" + month + "Array");

   var selectedLength = selectedArray.length;

   while (selectedLength < inForm.REGIONCODE.options.length) 
	{
      inForm.REGIONCODE.options[(inForm.REGIONCODE.options.length - 1)] = null;
   }

   for (var i=0; i < selectedArray.length; i++) 
	{
      eval("inForm.REGIONCODE.options[i]=" + "new Option" + selectedArray[i]);
   }

   if (inForm.REGIONCODE.options[0].value == '') 
	{
      inForm.REGIONCODE.options[0]= null;
      if ( navigator.appName == 'Netscape') 
		{
         if (parseInt(navigator.appVersion) < 4) 
			{
            window.history.go(0);
         }
         else 
			{
            if (navigator.platform == 'Win32' || navigator.platform == 'Win16') 
				{
               window.history.go(0);
            }
         }
      }
   }
}

///////////////////////////////////
function populateCruiseDest(inForm)
{
   var month = inForm.FROM.options[document.Search.FROM.options.selectedIndex].value;

   month = month.replace(/-/gi, "");

	var line = inForm.CRZCODE.value;

   var selectedArray = eval("Cruise" + month + line + "Array");

   var selectedLength = selectedArray.length;

   while (selectedLength < inForm.REGIONCODE.options.length)
   {
      inForm.REGIONCODE.options[(inForm.REGIONCODE.options.length - 1)] = null;
   }

   for (var i=0; i < selectedArray.length; i++)
   {
      eval("inForm.REGIONCODE.options[i]=" + "new Option" + selectedArray[i]);
   }

   if (inForm.REGIONCODE.options[0].value == '')
   {
      inForm.REGIONCODE.options[0]= null;
      if ( navigator.appName == 'Netscape')
      {
         if (parseInt(navigator.appVersion) < 4)
         {
            window.history.go(0);
         }
         else
         {
            if (navigator.platform == 'Win32' || navigator.platform == 'Win16')
            {
               window.history.go(0);
            }
         }
      }
   }
}

/////////////////////////////
function populateLine(inForm)
{
	var month = inForm.FROM.options[document.Search.FROM.options.selectedIndex].value;

	if (month == "")
	{
		alert("Please Choose Month First!");
		inForm.REGIONCODE.options[0].selected = true;
		return false; 
	}

	month = month.replace(/-/gi, "");

	var dest = inForm.REGIONCODE.options[document.Search.REGIONCODE.options.selectedIndex].value;
	
	var selectedArray = eval("Cruise" + month + dest + "Array");
	
	var selectedLength = selectedArray.length;

   while (selectedLength < inForm.CRZCODE.options.length)
	{
      inForm.CRZCODE.options[(inForm.CRZCODE.options.length - 1)] = null;
   }

   for (var i=0; i < selectedArray.length; i++) 
	{
      eval("inForm.CRZCODE.options[i] = " + "new Option" + selectedArray[i]);
   }

   if (inForm.CRZCODE.options[0].value == '')
	{
      inForm.CRZCODE.options[0] = null;
      if ( navigator.appName == 'Netscape') 
		{
         if (parseInt(navigator.appVersion) < 4) 
			{
            window.history.go(0);
         }
         else 
			{
            if (navigator.platform == 'Win32' || navigator.platform == 'Win16') 
				{
               window.history.go(0);
            }
         }
      }
   }
}

///////////////////////////////////
function populateCruiseLine(inForm)
{
   var month = inForm.FROM.options[document.Search.FROM.options.selectedIndex].value;

   if (month == "")
   {
      alert("Please Choose Month First!");
      inForm.REGIONCODE.options[0].selected = true;
      return false;
   }

   month = month.replace(/-/gi, "");

   //var dest = inForm.REGIONCODE.options[document.Search.REGIONCODE.options.selectedIndex].value;
	var dest = inForm.REGIONCODE.value;

   var selectedArray = eval("Cruise" + month + dest + "Array");

   var selectedLength = selectedArray.length;

   while (selectedLength < inForm.CRZCODE.options.length)
   {
      inForm.CRZCODE.options[(inForm.CRZCODE.options.length - 1)] = null;
   }

   for (var i=0; i < selectedArray.length; i++)
   {
      eval("inForm.CRZCODE.options[i] = " + "new Option" + selectedArray[i]);
   }

   if (inForm.CRZCODE.options[0].value == '')
   {
      inForm.CRZCODE.options[0] = null;
      if ( navigator.appName == 'Netscape')
      {
         if (parseInt(navigator.appVersion) < 4)
         {
            window.history.go(0);
         }
         else
         {
            if (navigator.platform == 'Win32' || navigator.platform == 'Win16')
            {
               window.history.go(0);
            }
         }
      }
   }
}

////////////////////////////////////
function checkRequiredFields(inForm)
{
   var month = inForm.FROM.options[document.Search.FROM.options.selectedIndex].value;
   var dest = inForm.REGIONCODE.options[document.Search.REGIONCODE.options.selectedIndex].value;

   if (month == "")
   {
      alert("Please Choose Month First!");
      inForm.REGIONCODE.options[0].selected = true;
		inForm.CRZCODE.options[0].selected = true;
      return false;
   }

	if (dest == "All")
	{
		alert("Please Select Destination & then Select Cruise Line!");
		inForm.CRZCODE.options[0].selected = true;
		return false;
	}

	return;
}

////////////////////////////////////////
function checkLineRequiredFields(inForm)
{
   var month = inForm.FROM.options[document.Search.FROM.options.selectedIndex].value;
   var dest = inForm.REGIONCODE.options[document.Search.REGIONCODE.options.selectedIndex].value;

   if (month == "")
   {
      alert("Please Choose Month First!");
      inForm.REGIONCODE.options[0].selected = true;
		//inForm.CRZCODE.options[0].selected = true;
      return false;
   }

	//if (dest == " ")
	//{
	//	alert("Please Select Destination & then Select Cruise Line!");
	//	inForm.CRZCODE.options[0].selected = true;
	//	return false;
	//}

	return;
}

////////////////////////////////////////
function checkDestRequiredFields(inForm)
{
   var month = inForm.FROM.options[document.Search.FROM.options.selectedIndex].value;
   var line = inForm.CRZCODE.options[document.Search.CRZCODE.options.selectedIndex].value;

   if (month == "")
   {
      alert("Please Choose Month First!");
      //inForm.REGIONCODE.options[0].selected = true;
      inForm.CRZCODE.options[0].selected = true;
      return false;
   }

   //if (dest == " ")
   //{
   // alert("Please Select Destination & then Select Cruise Line!");
   // inForm.CRZCODE.options[0].selected = true;
   // return false;
   //}

   return;
}

///////////////////////////////
function checkAllFields(inForm)
{
	var month = inForm.FROM.options[document.Search.FROM.options.selectedIndex].value;
	var dest = inForm.REGIONCODE.options[document.Search.REGIONCODE.options.selectedIndex].value;
	var line = inForm.CRZCODE.options[document.Search.CRZCODE.options.selectedIndex].value;
	var flag = 1; 

	if (month == "")
	{
		flag = false;
		alert("Please Choose Month First!");
		inForm.REGIONCODE.options[0].selected = true;
		inForm.CRZCODE.options[0].selected = true;
		return false;
	}

	if (dest == "All")
	{
		flag = false;
		alert("Please Select Destination & then Select Cruise Line!");
		inForm.CRZCODE.options[0].selected = true;
		return false;
	}

	if (line == "All")
	{
		flag = false;
		alert("Please Select Cruise Line & Continue!");
		return false;
	}

	if (flag == 1) 
	{
		var from = document.Search.FROM;
		var from2 = from.options[from.selectedIndex].value;

		var region = document.Search.REGIONCODE;
		var region2 = region.options[region.selectedIndex].value;

		var len = document.Search.LENGTH;
		var len2 = document.Search.LENGTH.value;

		var crz = document.Search.CRZCODE;
		var crz2 = crz.options[crz.selectedIndex].value;

		var lpos = (screen.width) ? (screen.width - 660) /2 :0;
		var tpos = (screen.height) ? (screen.height - 660) /2 : 0;

		var settings = 'height=500,width=660,top='+tpos+',left='+lpos+',menubar=no,toolbar=yes,scrollbars=yes,resizable=yes'

		// remove popup, use framed page instead ...
		//win_result = window.open('frameset3.shtml?FROM='+from2+'&REGIONCODE='+region2+'&CRZCODE='+crz2+'&LENGTH='+len2, 'middle', settings);
		//win_result.focus();
	
		self.location.href = "./index2.shtml?FROM="+from2+"&REGIONCODE="+region2+"&CRZCODE="+crz2+"&LENGTH="+len2;
	
		return false;
	}
	
	return true;
}

///////////////////////////////////////
function checkAllFields_cruises(inForm)
{
   var month = inForm.FROM.options[document.Search.FROM.options.selectedIndex].value;
   var dest = inForm.REGIONCODE.options[document.Search.REGIONCODE.options.selectedIndex].value;
   var line = inForm.CRZCODE.options[document.Search.CRZCODE.options.selectedIndex].value;
   var flag = 1;

   if (month == "")
   {
      flag = false;
      alert("Please Choose Month First!");
      inForm.REGIONCODE.options[0].selected = true;
      inForm.CRZCODE.options[0].selected = true;
      return false;
   }

   if (dest == "All")
   {
      flag = false;
      alert("Please Select Destination & then Select Cruise Line!");
      inForm.CRZCODE.options[0].selected = true;
      return false;
   }

   if (line == "All")
   {
      flag = false;
      alert("Please Select Cruise Line & Continue!");
      return false;
   }

   if (flag == 1)
   {
      var from = document.Search.FROM;
      var from2 = from.options[from.selectedIndex].value;

      var region = document.Search.REGIONCODE;
      var region2 = region.options[region.selectedIndex].value;

      var len = document.Search.LENGTH;
      var len2 = document.Search.LENGTH.value;

      var crz = document.Search.CRZCODE;
      var crz2 = crz.options[crz.selectedIndex].value;

      //var lpos = (screen.width) ? (screen.width - 660) /2 :0;
      //var tpos = (screen.height) ? (screen.height - 660) /2 : 0;

      //var settings = 'height=500,width=660,top='+tpos+',left='+lpos+',menubar=no,toolbar=yes,scrollbars=yes,resizable=yes'

		self.location.href = "/frame_cruisesfinder.shtml?FROM="+from2+"&REGIONCODE="+region2+"&CRZCODE="+crz2+"&LENGTH="+len2;

      return false;
   }

   return true;
}

//////////////////////////////////
function checkAllFields_CD(inForm)
{
   var month = inForm.FROM.options[document.Search.FROM.options.selectedIndex].value;
   var dest = inForm.REGIONCODE.options[document.Search.REGIONCODE.options.selectedIndex].value;
   var line = inForm.CRZCODE.options[document.Search.CRZCODE.options.selectedIndex].value;
   var flag = 1;

   if (month == "")
   {
      flag = false;
      alert("Please Choose Month First!");
      inForm.REGIONCODE.options[0].selected = true;
      inForm.CRZCODE.options[0].selected = true;
      return false;
   }

   if (dest == "All")
   {
      flag = false;
      alert("Please Select Destination & then Select Cruise Line!");
      inForm.CRZCODE.options[0].selected = true;
      return false;
   }

   if (line == "All")
   {
      flag = false;
      alert("Please Select Cruise Line & Continue!");
      return false;
   }

   if (flag == 1)
   {
      var from = document.Search.FROM;
      var from2 = from.options[from.selectedIndex].value;

      var region = document.Search.REGIONCODE;
      var region2 = region.options[region.selectedIndex].value;

      var len = document.Search.LENGTH;
      var len2 = document.Search.LENGTH.value;

      var crz = document.Search.CRZCODE;
      var crz2 = crz.options[crz.selectedIndex].value;

		self.location.href = "./index2.shtml?FROM="+from2+"&REGIONCODE="+region2+"&CRZCODE="+crz2+"&LENGTH="+len2;

      return false;
   }

   return true;
}

///////////////////////////////////
function checkAllLineFields(inForm)
{
	var month = inForm.FROM.options[document.Search.FROM.options.selectedIndex].value;
	var dest = inForm.REGIONCODE.options[document.Search.REGIONCODE.options.selectedIndex].value;
	var flag = 1; 

	if (month == "")
	{
		flag = false;
		alert("Please Choose Month First!");
		inForm.REGIONCODE.options[0].selected = true;
		return false;
	}

	if (dest == "All")
	{
		flag = false;
		alert("Please Select Destination & Continue!");
		return false;
	}

	if (flag == 1) 
	{
		// center popups ...	
		var lpos = (screen.width) ? (screen.width - 660) / 2 :0;
		var tpos = (screen.height) ? (screen.height - 660) / 2 : 0;

		var settings = 'height=500,width=660,top='+tpos+',left='+lpos+',menubar=no,toolbar=yes,scrollbars=yes,resizable=yes'

		var from = document.Search.FROM;
		var from2 = from.options[from.selectedIndex].value;

		var region = document.Search.REGIONCODE;
		var region2 = region.options[region.selectedIndex].value;

		var len = document.Search.LENGTH;
		var len2 = document.Search.LENGTH.value;
	
		var crz = document.Search.CRZCODE;
		var crz2 = document.Search.CRZCODE.value;

		// remove popup, change it to framed page
		//win_result3 = window.open('frameset3.shtml?FROM='+from2+'&REGIONCODE='+region2+'&CRZCODE='+crz2+'&LENGTH='+len2, 'middle', settings);
		//win_result3.focus();

		self.location.href = "./index2.shtml?FROM="+from2+"&REGIONCODE="+region2+"&CRZCODE="+crz2+"&LENGTH="+len2;

		return false;	
	}
	
	return true;
}

///////////////////////////////////
function checkAllDestFields(inForm)
{
   var month = inForm.FROM.options[document.Search.FROM.options.selectedIndex].value;
   var line = inForm.CRZCODE.options[document.Search.CRZCODE.options.selectedIndex].value;
   var flag = 1;

   if (month == "")
   {
      flag = false;
      alert("Please Choose Month First!");
      inForm.CRZCODE.options[0].selected = true;
      return false;
   }

   if (line == "All")
   {
      flag = false;
      alert("Please Select Cruise Line & Continue!");
      return false;
   }

   if (flag == 1)
   {
	   var lpos = (screen.width) ? (screen.width - 660) /2 : 0;
	   var tpos = (screen.height) ? (screen.height - 660) /2 : 0;

	   var settings = 'height=500,width=660,top='+tpos+',left='+lpos+',menubar=no,toolbar=yes,scrollbars=yes,resizable=yes'
	
	   var from = document.Search.FROM;
	   var from2 = from.options[from.selectedIndex].value;

	   var region = document.Search.REGIONCODE;
	   var region2 = document.Search.REGIONCODE.value;

	   var len = document.Search.LENGTH;
	   var len2 = document.Search.LENGTH.value;

	   var crz = document.Search.CRZCODE;
	   var crz2 = crz.options[crz.selectedIndex].value;

		// remove popup, use framed page instead 
	   //win_result2 = window.open('frameset3.shtml?FROM='+from2+'&REGIONCODE='+region2+'&CRZCODE='+crz2+'&LENGTH='+len2, 'middle', settings);
	   //win_result2.focus();

		self.location.href = "./index2.shtml?FROM="+from2+"&REGIONCODE="+region2+"&CRZCODE="+crz2+"&LENGTH="+len2;

	   return false;
	}

	return true;
}


