function Verisign(url) {
 sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=535,height=450');
 self.name = "mainWin";
 }




// Function Name: diffDays
// Purpose: Determines differance in days of date objects
// Parameters: d1 - First Date, d2 - Second Date
// Return: Int - difference between d1 and d2.
function diffDays(d1, d2)
{
	// Determine difference by dividing by number of milliseconds in a day
	return Math.round((d1 - d2)/864e5);
}

// Function Name: checkAge
// Purpose: Determines if the value passed in is a value age.
// Parameters: age - Value to be checked
// Return: String - converted value
function checkAge(age)
{
	var retVal = "";
	if ( age.toUpperCase() != "NA")
	{
		retVal = age;
	}
	return retVal;
}

// Function Name: convertMonth
// Purpose: Converts integer representation of the month into its english name
// Parameters: month - Integer representation of month, zero indexed
// Return: String - Month's name
function convertMonth(month)
{
	var retVal = "";

	switch(month)
	{
		case 0:
			retVal = "January";
			break;
		case 1:
			retVal = "February";
			break;
		case 2:
			retVal = "March";
			break;
		case 3:
			retVal = "April";
			break;
		case 4:
			retVal = "May";
			break;
		case 5:
			retVal = "June";
			break;
		case 6:
			retVal = "July";
			break;
		case 7:
			retVal = "August";
			break;
		case 8:
			retVal = "September";
			break;
		case 9:
			retVal = "October";
			break;
		case 10:
			retVal = "November";
			break;
		case 11:
			retVal = "December";
			break;
	}

	return retVal;
}


// Function Name: TRIM
// Purpose: Standard string trim function
// Parameters: s - string to be trimmed of whitespace
// Return: String - trimmed string
function TRIM(s) 
{
  // Remove leading spaces and carriage returns
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }
  // Remove trailing spaces and carriage returns
  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}


// Function Name: showPost
// Purpose: Displays an alert of the passed in forms values
// Parameters: theForm - form to be dispalyed
// Return: None
function showPost(theForm)
{
	var al = theForm.name;
	for (var x=0; x< theForm.elements.length; x++) {
		al += "\n" + theForm.elements[x].name + "=" + theForm.elements[x].value;
	}
	alert( al );
}

// Function Name: FIND
// Purpose: Finds an object on the page and returns a referance to it
// Parameters: item - name of object ot find
// Return: Object - referance to the found object, or false if not found
function FIND(item) {
	//if (document.all) 
	//	return(document.all[item]);
	if (document.getElementById) 
		return(document.getElementById(item));
	return(false);
}



// Function Name: validateDepartureDate
// Purpose: Validates that the departure date is not before today and is before the return date
// Parameters: None
// Return: Boolean - whether the date is valid
function validateDepartureDate()
{
	// Create a date object from the entered departure date 
	var departDateString = document.restool.gsDepartureDate.value;
    var departDate = new Date(departDateString);
	// Create a date object for today.
	var today = new Date();

	var retVal = true;

	// Adjust year from '05' to '2005'
	departDate = adjustYear(departDate);

	// Find warnings for departures
	// Invalid date entry warning
    var warning = FIND("trDepartureWarning");
	// Date is in the past warning
	var warningPast = FIND("trDepartureWarningPast");

	// If the departure date is still "mm/dd/yy" then don't do anything, the user hasn't entered anythign yet
	if (document.restool.gsDepartureDate.value != "mm/dd/yy")
	{
		// Check if the date is not a date at all, or fails at RegEx validations
		if (departDate == "NaN" || !validateDateFormat(departDateString))
		{
			// Show invalid date warning
		   warning.style.display = "block"
		   retVal = retVal && false;
		}
		else 
		{
			warning.style.display = "none"
			retVal = retVal && true;
		}

		// <- SDA 08/18/05 START
		// Check if departure date is before today
		if (departDate != "NaN" && validateDateFormat(departDateString)){
			if (departDate < today)
			{
				// Show date in past warning
			warningPast.style.display = "block"
			retVal = retVal && false;
			}
			else
			{
			warningPast.style.display = "none"
				retVal = retVal && true;
			}
		}else{
			warningPast.style.display = "none";
		}
		// <- SDA 08/18/05 END
	}
	else
	{
		// We can't validate the date since nothing was entered, so that's a failure
		retVal = false;
	}
	return retVal;
}

// Function Name: validateDepartureDateSubmit
// Purpose: Similar to validateDepartureDate, but only called on form submit, doesn't check for 'mm/dd/yy'
// Parameters: None
// Return: Boolean - whether the date is valid
function validateDepartureDateSubmit()
{ 
	// Create a date object from the entered departure date 
	var departDateString = document.restool.gsDepartureDate.value;
    var departDate = new Date(departDateString);
	// Create a date object for today.
	var today = new Date();

	var retVal = true;

	// Adjust year from '05' to '2005'
	departDate = adjustYear(departDate);

	// Find warnings for departures
	// Invalid date entry warning
    var warning = FIND("trDepartureWarning");
	// Date is in the past warning
	var warningPast = FIND("trDepartureWarningPast");

	// Check if the date is not a date at all, or fails at RegEx validations
	if (departDate == "NaN" || !validateDateFormat(departDateString))
	{
		// Show invalid date warning
	   warning.style.display = "block"
	   retVal = retVal && false;
	}
	else 
	{
		warning.style.display = "none"
		retVal = retVal && true;
	}

	// <- SDA 08/18/05 START
	// Check if departure date is before today
	if (departDate != "NaN" && validateDateFormat(departDateString)){
		if (departDate < today)
		{
			// Show date in past warning
		warningPast.style.display = "block"
		retVal = retVal && false;
		}
		else
		{
		warningPast.style.display = "none"
			retVal = retVal && true;
		}
	}else{
			warningPast.style.display = "none";
		}
	// <- SDA 08/18/05 END
	
	return retVal;
}

// Function Name: validateReturnDate
// Purpose: Validates that the return date is not before today and is after depart date, and valid format
// Parameters: None
// Return: Boolean - whether the date is valid
function validateReturnDate()
{
	// Create a date object from the entered return date 
	var returnDateString = document.restool.ReturnDate.value
    var returnDate = new Date(returnDateString);
	// Create a date object from the entered departure date 
    var departDate = new Date(document.restool.gsDepartureDate.value);
	// Create a date object for today.
	var today = new Date();

	var retVal = true;

	// Adjust year from '05' to '2005'
	returnDate = adjustYear(returnDate);
	departDate = adjustYear(departDate);

	// Find warnings for returns
	// Date in the past warning
    var warning = FIND("trReturnWarning");
	// Depart > Return warnging
    var warning2 = FIND("trReturnWarning2");
	// Invalid date format warning
    var warningPast = FIND("trReturnWarningPast");
    // Check if the date entered is before today
    
	// Check if user has changed value from default value
	if (document.restool.ReturnDate.value != "mm/dd/yy")
	{
		// Check if valid date format was entered
		if (returnDate == "NaN" || !validateDateFormat(returnDateString))
		{
			// Show invalid date format warning
		   warning.style.display = "block"    
			retVal = retVal && false;
		}
		else
		{
		   warning.style.display = "none"    
			retVal = retVal && true;
		}
		// <- SDA 08/18/05 START
		// Check if the date entered is before today
		if (returnDate != "NaN" && validateDateFormat(returnDateString)){
			if (returnDate < today)
			{
				// Show past date warning
				warning2.style.display = "block"
				retVal = retVal && false;
			}
			else
			{
				warning2.style.display = "none"
				retVal = retVal && true;
			}
		}else{
			warning2.style.display = "none";
		}
		// Check if depart date is after return date	
		
		if (returnDate != "NaN" && validateDateFormat(returnDateString)){
			if (returnDate > today){		
				if ((departDate >= returnDate) && (departDate != "NaN"))
				{
					// Show Depart > Return date warning
					warning.style.display = "none";
					warning2.style.display = "none";
					warningPast.style.display = "block";
					retVal = retVal && false;
				}
				else
				{
					warningPast.style.display = "none";
					retVal = retVal && true;
				}
			}else{
				warningPast.style.display = "none";
			}
		}else{
			warningPast.style.display = "none";
		}
		// <- SDA 08/18/05 END
	}
	else
	{
		// If we are still in the default entry, then return false.
		retVal = false;
	}
	return retVal;
}

// Function Name: validateReturnDateSubmit
// Purpose: Similar to validateReturnDate, but only called on form submit, doesn't check for 'mm/dd/yy'
// Parameters: None
// Return: Boolean - whether the date is valid
function validateReturnDateSubmit()
{
	// Create a date object from the entered return date 
	var returnDateString = document.restool.ReturnDate.value
    var returnDate = new Date(returnDateString);
	// Create a date object from the entered departure date 
    var departDate = new Date(document.restool.gsDepartureDate.value);
	// Create a date object for today.
	var today = new Date();

	var retVal = true;

	// Adjust year from '05' to '2005'
	returnDate = adjustYear(returnDate);
	departDate = adjustYear(departDate);
   
	// Find warnings for returns
	// Date in the past warning
    var warning = FIND("trReturnWarning");
	// Depart > Return warnging
   var warning2 = FIND("trReturnWarning2");
	// Invalid date format warning
    var warningPast = FIND("trReturnWarningPast");
    
    // Check if the date is not a date at all, or fails at RegEx validations
	if (returnDate == "NaN" || !validateDateFormat(returnDateString))
	{
		// Show invalid date format warning
	   warning.style.display = "block"    
		retVal = retVal && false;
	}
	else
	{
	   warning.style.display = "none"    
		retVal = retVal && true;
	}
	
    // <- SDA 08/18/05 START
	// Check if the date entered is before today
	if (returnDate != "NaN" && validateDateFormat(returnDateString)){
		if (returnDate < today)
		{
			// Show past date warning
			warning2.style.display = "block"
			retVal = retVal && false;
		}
		else
		{
			warning2.style.display = "none"
			retVal = retVal && true;
		}
	}else{
		warning2.style.display = "none";
	}
	// Check if depart date is after return date		
	if (returnDate != "NaN" && validateDateFormat(returnDateString)){
		if (returnDate > today){		
			if ((departDate >= returnDate) && (departDate != "NaN"))
			{
				// Show Depart > Return date warning
				warning.style.display = "none";
				warning2.style.display = "none";
				warningPast.style.display = "block";
				retVal = retVal && false;
			}
			else
			{
				warningPast.style.display = "none";
				retVal = retVal && true;
			}
		}else{
			warningPast.style.display = "none";
		}
	}else{
		warningPast.style.display = "none";
	}
	// <- SDA 08/18/05 END
	
	return retVal;
}

// Function Name: adjustYear
// Purpose: Adjusts year from 2 digit to proper four digit
// Parameters: date - Date object to have adjusted year
// Return: Date - object with adjusted date
function adjustYear(date)
{
	// Check if full year returns as less then 2000
	if (parseInt(date.getFullYear(),10) < 2000)
	{
		// Take year and add 2000
		date.setFullYear(2000 + date.getYear());
		return date;
	}
	else
	{
		return date;
	}
}

// Function Name: validateDateFormat
// Purpose: Validates entered date against a regular expression and valid values, accounts for leap years in february.
// Parameters: inDate - string representation of date
// Return: Boolean - whether the date is valid
function validateDateFormat( inDate ) 
{

  // Generate regular expression for "mm/dd/yy" where the month and day can be 1 or 2 digits
  var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/;

	// Test against ergular expression
	if(!objRegExp.test(inDate))
	{
		// Failure
		return false; 
	}
	else
	{
		// Parse out date components and determine if it is a valid day for the month
		// Find seperator
		var sSeparator = findSeperator(inDate);
		// Split date into array
		var arrayDate = inDate.split(sSeparator);
		// Create array of valid days for each month
		var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31, '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
		// Parse day from array
		var intDay = parseInt(arrayDate[1],10);

		// Determine if month exists
		if(arrayLookup[padAge(arrayDate[0])] != null) {
		  // Determine if the day entered is less then or equal to valid max day
		  if(intDay <= arrayLookup[padAge(arrayDate[0])] && intDay != 0)
			return true; 
	}

	// Process Feruary differently.
    var intMonth = parseInt(arrayDate[0],10);
    if (intMonth == 2) { 
	   // Pull year out of array
       var intYear = parseInt(arrayDate[2],10);
	   // Determine valid max day for February based on leap year or not.
       if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
          return true; 
       }
  }
  return false; 
}

// Function Name: findSeperator
// Purpose: Helper function for validateDateFormat to find the seperator in the date string
// Parameters: inDate - date to find seperator in
// Return: Char - Seperator used in date string
function findSeperator(inDate)
{
	var i;
	var retVal = "";

	// Loop through each Char in String
	for (i = 0; i < inDate.length; i++)
	{
		// If the current index value is not a number, then it is the seperator
		if (isNaN(inDate.substr(i,1)))
		{
			retVal = inDate.substr(i,1);
		}
	}
	return retVal;
}



// Function Name: popupcalendar
// Purpose: Pops up a calendar for selecting dates
// Parameters: url - URL to pop
// Return: None
function popupcalendar(url,the_field)
{	
	var dDate = document.restool.gsDepartureDate.value;
	//windowHandle = window.open(url + "&dDate=" + dDate,'','location=no,directories=no,status=no,menubar=no,resizable=no,width=180,height=180');
	var the_field = the_field;
	
	// PSD - Positions the popup window next to the calendar for consistency and "mouse convenience"
	if (the_field == "depart")
	{
		// PSD - added "gsDepartPopup" in anchor for id and name reference
		var anchorname = 'gsDepartPopup';
		var obj = document.all[anchorname];
		var x=0;
		var y=0;
		x=findPosX(obj);
		y=findPosY(obj);

		// 02/23/06 DSM - begin to update calendar positioning due to UV comp redesign.  
		// update my changes dated 12/01/05.  See VSS to see what used to be here
		x=x+window.screenLeft;
		y=y+window.screenTop-327;
		
		// 02/23/06 DSM - end to update calendar positioning due to UV comp redesign.  See VSS to see what used to be here

	} else {
		// PSD - added "gsReturnPopup" in anchor for id and name reference
		var anchorname = 'gsReturnPopup';
		var obj = document.all[anchorname];
		var x=0;
		var y=0;
		x=findPosX(obj);
		y=findPosY(obj);

		// 02/23/06 DSM - begin to update calendar positioning due to UV comp redesign.  
		// update my changes dated 12/01/05.  See VSS to see what used to be here
		x=x+window.screenLeft-140;
		y=y+window.screenTop+20;
		// 02/23/06 DSM - end to update calendar positioning due to UV comp redesign.  See VSS to see what used to be here

	}
	thispop = "'location=no,directories=no,status=no,menubar=no,resizable=yes,width=180,height=170,left=" + x + ",top=" + y + "'";
	var calpop = window.open(url + "&dDate=" + dDate,'calwin',thispop);
	// 08/25/05 Patrick Duemling - End
}

// Function Name: onload
// Purpose: preforms init page functionality
// Parameters: None
// Return: None
window.onload=function(){
	
	FIND("trSubmitReal").style.display = "block";
	FIND("trSubmitFake").style.display = "none";	
	initSearchParameters();

}



// Function Name: initSearchParameters
// Purpose: Grabs parameters that were setup through request variables and configures ResTool
// Parameters: None
// Return: None
function initSearchParameters()
{
    // initDepartureDate
    if (g_PostDepartureDate != "")
    {  
        //FIND("gsDepartureDate").value = longDateTimeStringToShortDateString(g_PostDepartureDate);
		var DepartDateInput = FIND("gsDepartureDate");
		var d = new Date(g_PostDepartureDate);
		d.setDate(d.getDate());
		DepartDateInput.value = padAge((d.getMonth() + 1).toString()) + "/" + padAge(d.getDate().toString()) + "/" +  d.getFullYear().toString().substr(2,2);
    }
    else
    {
        initDepartureDate();
    }
    // initDepartureTime
    if (g_PostDepartureTime != "")
    {
		document.restool.DepartureTime.value = document.restool.DepartureTime.value;

    }
    // initReturnDate
    if (g_PostReturnDate != "")
    {
        FIND("ReturnDate").value = longDateTimeStringToShortDateString(g_PostReturnDate);
    }
    else
    {
        lengthOfStayChange();
        //initReturnDate();
    }
    // initReturnTime
    if (g_PostReturnTime != "")
    {
		document.restool.ReturnTime.value = document.restool.ReturnTime.value;
    }

    // initPromoCode
    if (g_PostPromoCode != "")
    {
        document.restool.gsPromotionCode.value = g_PostPromoCode;
    }
}

// Function Name: longDateTimeStringToShortDateString
// Purpose: Converts a string from format "yyyy-MM-ddT12:34:00" to "MM/dd/yy"
// Parameters: longDateTime - String of long date time
// Return: String - short Date Time
function longDateTimeStringToShortDateString(longDateTime)
{
    var retVal = ""; 
    // Trim down input string to just the date portion   
    var workString = longDateTime.substring(0, (longDateTime.length - longDateTime.indexOf("T") + 1));
    // Split the date into its componenets
    var workArray = workString.split("-");
    
    // Build up return value from date array
    retVal = padAge(workArray[1]).toString() + "/" + padAge(workArray[2]).toString() + "/" + workArray[0].toString().substr(2,2);
    
    return retVal;
}


// Function Name: initDepartureDate
// Purpose: Initializes the departure date to how many days specified out as in the global variables
// Parameters: None
// Return: None
function initDepartureDate()
{
	var DepartDateInput = FIND("gsDepartureDate");

	var d = new Date();

	d.setDate(d.getDate() + g_DepartOffset);

	DepartDateInput.value = padAge((d.getMonth() + 1).toString()) + "/" + padAge(d.getDate().toString()) + "/" +  d.getFullYear().toString().substr(2,2);
}

// Function Name: initReturnDate
// Purpose: Initializes the return date to how many days specified out as in the global variables
// Parameters: None
// Return: None
function initReturnDate()
{
	var ReturnDateInput = FIND("ReturnDate");
	var d = new Date();
	d.setDate(d.getDate() + g_ReturnOffset);
	ReturnDateInput.value = padAge((d.getMonth() + 1).toString()) + "/" + padAge(d.getDate().toString()) + "/" +  d.getFullYear().toString().substr(2,2);
}

///////////////////////////////////////////////////////////////////////////////////////
function departDateChange()
{ 
	var m_index, m_day, m_month, JS_date, nonJS_date, cont_flag;
    
    //m_index = getIndex(document.restool.departDay);
    m_index = document.restool.gsDepartureDate.value;

	var DepartDateText = m_index;
	// Create a Date object from the departure date to use in filling in the TARS form
	var DepartDate = new Date(DepartDateText);

	DepartDate = adjustYear(DepartDate);
	// Convert date to what resengine.asp is expecting
	//var d = padAge((DepartDate.getMonth() + 1).toString()) + "/" + padAge(DepartDate.getDate().toString()) + "/" +  DepartDate.getYear().toString().substr(g_YearIndex,2);
	var d = padAge(DepartDate.getDate().toString());
	var m = (DepartDate.getMonth() ).toString();
	var y = DepartDate.getFullYear().toString().substr(g_YearIndex,2);
	
	    m_day = d;//document.restool.departDay.options[m_index].value;
		m_month = m; //document.restool.departMonth.options[m_index].value;
		var m_year;
		m_year = y;
		
	//alert("Day - " + m_day + " / Month - " + m_month + " / Year - " + m_year);

	JS_date = getNewDate(m_day, m_month, m_year);	
	
    nonJS_date = getNonJSDate(JS_date);
	cont_flag = checkDates(JS_date, "moreorequal");

	if (cont_flag == true)
    {  
	   // make sure new depart date is fine
	   //cont_flag = setDateDropDown(nonJS_date, document.restool.departDay, document.restool.departMonth);       
	   //cont_flag = setDateDropDown(nonJS_date, d, m); 
	   if (cont_flag == true)
       {

          // 12/05/05 DSM - begin
          // we now use numOfNights dropdown instead
          var num_of_nights;
          num_of_nights = parseInt(document.restool.numOfNights.options[document.restool.numOfNights.options.selectedIndex].value, 10);
          
	      // make sure new return date caused by this new depart date is also fine.  Otherwise, we'll roll everything back
	      //cont_flag = getNewReturnDate(nonJS_date, parseInt(document.restool.gsLengthOfStay.value, 10), "depart date");  
	      cont_flag = getNewReturnDate(nonJS_date, num_of_nights, "depart date");  

          // 12/05/05 DSM - end
          
	      if (cont_flag == true)
          {
             //document.restool.gsDepartureDate.value = nonJS_date;   
             //document.restool.gsOrigDepartureDate.value = nonJS_date;   
	         updateDOW(JS_date, "depart");
 	         //alert("good date: " + JS_date + " || " + nonJS_date);
          }
          else
          {
	         resetDepartDate();
          }
	   }
	   else
       {
	      alert("New depart date is beyond allowed date range.  Please choose another date");
  	      resetDepartDate();
	   }
    }
    else
    {  
       //alert("New depart date is less than allowed date range.  Please choose another date");  
	   //resetDepartDate();
	   
	   updateDOW(JS_date, "depart");
       //alert("bad date: " + JS_date + " || " + nonJS_date);
    }
}
      
        
        
function getIndex(m_obj)
{
	var m_num;
    
    for (m_num = 0; m_num < m_obj.length; m_num++)
    {
	   if (m_obj.options[m_num].selected)
	   {  return m_num;  }
    }
}

function getNewDate(day_value, month_value, year_value)
{
	var opts, m_day, m_month, m_year, new_date_value; 
	m_day = day_value;
	//opts = month_value.split("/");
	m_month = month_value; //parseInt((opts[0] - 1), 10);  
	m_year = 20 + year_value; //parseInt(opts[1], 10);
	new_date_value = new Date(m_year, m_month, m_day);   
    //alert("in getNewDate: " + new_date_value + " => " + day_value + " || " + month_value);
    return(new_date_value);
}

function getNonJSDate(date_value)
{
	var n_day, n_month, n_year, n_yy, nonJS_date;
    
	n_day = date_value.getDate() - 0;
	n_month = date_value.getMonth() + 1;
    n_year = date_value.getYear() + " ";  // this needs to be a string since we're using substr later on!!

	if (n_day < 10)
    {  
       n_day = "0" + n_day;
    }
    
    if (n_month < 10)
    {
       n_month = "0" + n_month;
    }

	if (n_year < 2000)
    {  
       n_year = parseInt(n_year, 10) + 1900;
       n_year = n_year + " ";
    }
	n_year = n_year.substr(2,2);
	
	nonJS_date = n_month + "/" + n_day + "/" + n_year;
	//alert("nonJS_date: " + nonJS_date);
    
    return(nonJS_date);
}


function checkDates(JS_date, ck_type)
{
	var m_day, m_month, m_year, opts, min_dep_date;
    
	opts = document.restool.minDepartDate.value.split("/");
	m_month = opts[0];              
	m_day = opts[1] - 0;   // to make sure this is converted to integer
	m_year = opts[2];

	m_month = m_month - 1;   // in javascript, month array starts at 0, so need to subtract current m_month value by 1

	if (parseInt(m_year, 10) < 2000)
    { m_year = "20" + m_year; }

	min_dep_date = new Date(m_year, m_month, m_day);   
	//alert("new date: " + JS_date + "  vs  " + "min_dep_date: " + min_dep_date);
    
	if (ck_type == "moreorequal")
    {
	   if (JS_date >= min_dep_date)
       {  return true; }
       else
       { return false; }
	}
}

function setDateDropDown(nonJS_date, day_obj, month_obj)
{
	// use this function to reset date drop down or to update date drop down if the next date should be automatically selected!!
    
	var m_num, m_day, m_month, m_year, opts, m_month_str, cont_flag;
    
	opts = nonJS_date.split("/");
	m_month = opts[0] - 0;              
	m_day = opts[1] - 0;
	m_year = "20" + opts[2];
	m_month_str = m_month + "/" + m_year; 	

	cont_flag = true;
    return cont_flag;
}

function getJSDate(date_value)
{
	var m_num, m_day, m_month, m_year, opts, m_month_str, JS_date;

	opts = date_value.split("/");
	m_month = opts[0] - 1;              
	m_day = opts[1] - 0;   // this is to convert this to numeric from possibly a value w/ 0 in front of it like 02, 03, etc.
	m_year = parseInt(("20" + opts[2]), 10);

	JS_date = new Date(m_year, m_month, m_day);   
	return JS_date;
}

function getNonJSDate(date_value)
{
	var n_day, n_month, n_year, n_yy, nonJS_date;
    
	n_day = date_value.getDate() - 0;
	n_month = date_value.getMonth() + 1;
    n_year = date_value.getYear() + " ";  // this needs to be a string since we're using substr later on!!

	if (n_day < 10)
    {  
       n_day = "0" + n_day;
    }
    
    if (n_month < 10)
    {
       n_month = "0" + n_month;
    }

	if (n_year < 2000)
    {  
       n_year = parseInt(n_year, 10) + 1900;
       n_year = n_year + " ";
    }
	n_year = n_year.substr(2,2);
	
	nonJS_date = n_month + "/" + n_day + "/" + n_year;
	//alert("nonJS_date: " + nonJS_date);
    
    return(nonJS_date);
}

function updateDOW(JS_date, dow_type)
{
	//var day_of_week = new Array("SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY");
	//alert("updateDOW: " + JS_date + " " + day_value);
	var day_of_week = new Array("SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"); //new Array("SUN","MON","TUE","WED","THU","FRI","SAT");
	var day_value = JS_date.getDay();
   
	// have to use FIND since non IE browser just doesn't like below code!!!
	//if (dow_type == "depart")
    //{  document.all.departDOW.innerText = day_of_week[day_value];  }
    //else
    //{  document.all.returnDOW.innerText = day_of_week[day_value];  }

	var depDOW = FIND("departDOW");
	var retDOW = FIND("returnDOW");
	var dow = day_of_week[day_value].substring(0,1).toUpperCase() + day_of_week[day_value].substring(1).toLowerCase()
    
	if (dow_type == "depart")	
    {  depDOW.innerHTML = dow;  }
    else
    {  retDOW.innerHTML = dow;  }
    //alert("updateDOW: " + JS_date + " = " + day_value + " = " + day_of_week[day_value]);

}


function getNewReturnDate(curr_date, stay_length, msg_value)
{
	var opts, m_day, m_month, m_year, nonJS_date, JS_date, cont_flag, dummy_flag;
    
	opts = curr_date.split("/");
    m_month = parseInt((opts[0] - 1), 10);  
	m_day = parseInt(opts[1], 10);
	m_year = "20" + opts[2];
    
    //alert("Month - " + m_month + " Day - " + m_day + " Year - " + m_year);

	JS_date = new Date(m_year, m_month, m_day + stay_length);  
	nonJS_date = getNonJSDate(JS_date);
	//alert("Return Date Should be set to  - " + nonJS_date);
	cont_flag = setDateDropDown(nonJS_date, m_day, m_month);       
	
	if (cont_flag == true)
    {
       document.restool.ReturnDate.value = nonJS_date;   
	   updateDOW(JS_date, "return");
	}
	else
    {
	   alert("New " + msg_value + " causes a new return date that is beyond allowed date range.  Please choose another " + msg_value);
	   //dummy_flag = setDateDropDown(document.restool.gsOrigReturnDate.value, document.restool.returnDay, document.restool.returnMonth);       
	   //JS_date = getJSDate(document.restool.gsOrigReturnDate.value);
       updateDOW(JS_date, "return");
    }    

	return cont_flag;

}

function resetDepartDate()
{
	var JS_date, cont_flag;
	var DepartDateInput = FIND("gsDepartureDate");
	var d = new Date();
	d.setDate(d.getDate() + g_DepartOffset);
	DepartDateInput.value = padAge((d.getMonth() + 1).toString()) + "/" + padAge(d.getDate().toString()) + "/" +  d.getFullYear().toString().substr(2,2);

	cont_flag = DepartDateInput.value; //setDateDropDown(document.restool.gsOrigDepartureDate.value, document.restool.departDay, document.restool.departMonth);       
	JS_date = getJSDate(DepartDateInput.value); //getJSDate(document.restool.gsOrigDepartureDate.value);
    updateDOW(JS_date, "depart");
}
// Function Name: padAge
// Purpose: Places a leading zero on values that are a single digit.  Needed for OVM
// Parameters: age - value to be padded
// Return: String - padded value
function padAge(age)
{
	if (age.length < 2 && age != 0)
	{
		age = '0' + age;
		//alert("age now is: " + age);
	}
	return age;
}


// 08/25/05 Patrick Duemling - Supports window positioning in popUpCalendar()
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function numOfNightsChange()
{
	var cont_flag = false;
	var curr_item_array, new_item_array;
            
    stay_length = parseInt(document.restool.numOfNights.options[document.restool.numOfNights.options.selectedIndex].value, 10);
    
	// array starts 1 count less than numOfNights value
    curr_item_array = parseInt(document.restool.numOfNights.options[document.restool.numOfNights.options.selectedIndex].value, 10) - 1;
    
	cont_flag = getNewReturnDate(document.restool.gsDepartureDate.value, stay_length, "Number of nights");  
	if (cont_flag == true)
    {
	   document.restool.gsOrigLengthOfStay.value = document.restool.numOfNights.options[document.restool.numOfNights.options.selectedIndex].value;
	   //alert("good -> gsOrigLengthOfStay: " + document.restool.gsOrigLengthOfStay.value);
    }
    else
    {
       document.restool.gsLengthOfStay.value = document.restool.gsOrigLengthOfStay.value;
	   //alert("bad -> gsLengthOfStay: " + document.restool.gsOrigLengthOfStay.value);
       document.restool.numOfNights.options[curr_item_array].selected = false;
	   new_item_array = document.restool.gsOrigLengthOfStay.value - 1;
	   document.restool.numOfNights.options[new_item_array].selected = true;
    }
    
}
function lengthOfStayChange()
{
	var min_stay, max_stay, stay_length;
	var cont_flag = false;
            
	min_stay = parseInt(document.restool.minStay.value, 10);
	max_stay = parseInt(document.restool.maxStay.value, 10);
    stay_length = parseInt(document.restool.gsLengthOfStay.value, 10);
    
	//alert("lengthOfStayChange: " + stay_length + " => " + min_stay + " to " + max_stay);
    
	if (isNaN(stay_length)) 
	{
	   alert("Non-numeric length of stay was entered. Please enter a valid length of stay between " + min_stay + " and " + max_stay);
       document.restool.gsLengthOfStay.value = document.restool.gsOrigLengthOfStay.value;
	}
	else
	{
   	   if (stay_length < min_stay)
       { 
   	      alert("Invalid length of stay value was entered. Please enter a valid length of stay between " + min_stay + " and " + max_stay);
   	      document.restool.gsLengthOfStay.value = document.restool.gsOrigLengthOfStay.value;
   	   }
       else
       {
   	      if (stay_length > max_stay)
          {
      	     alert("Invalid length of stay value was entered. Please enter a valid length of stay between " + min_stay + " and " + max_stay);
      	     document.restool.gsLengthOfStay.value = document.restool.gsOrigLengthOfStay.value;
          }    
      	  else
          {
      	     cont_flag = getNewReturnDate(document.restool.gsDepartureDate.value, stay_length, "length of stay");  
	         if (cont_flag == true)
             {
	            document.restool.gsOrigLengthOfStay.value = document.restool.gsLengthOfStay.value;
             }
             else
             {
      	        document.restool.gsLengthOfStay.value = document.restool.gsOrigLengthOfStay.value;
             }
          }
       }    
	}
    
}

// Function Name: submitSearch
// Purpose: Determines what form to submit the search to.
// Parameters: None
// Return: None
function submitSearch()
{ //alert("submit");
    var packageType = document.restool.gsVacationType.value;
	//alert("Radios \n OVM :" + OVMCharterRadio.checked + " SBT : " + SBTCharterRadio.checked + " SKED: " + SBTSkedRadio.checked + "\n Package Type: " + packageType + " \nRisk:" + g_UARisk + "\nSBT Charter:" + g_SBTCharter + "\nTARS: " + g_TARS);
	// Determine if the form is valid and ready to submit.
	//alert(validateDes());
	var vendorFrom = document.restool.gsVendor.value;
	var validForm = validateDes();
	validForm = validateOrg() && validForm;
	validForm = validateDepartureDateSubmit() && validForm;
	validForm = validateReturnDateSubmit() && validForm;
	validForm = validateText() && validForm;
	//validForm = occupancyTest() && validForm;
	
	validForm = validateUPCCheck() && validForm;
	//alert("Valid Form: " + validForm);
	
	// If the form was valid, then determine what form to submit
	if (validForm)
	{ 
	       
			submitSBT();
		
	}

	return false;
}
// Function Name: submitOVM
// Purpose: Submits the serch parameters to resengine.asp, which massages the data and submits to OVM
// Parameters: None
// Return: None
function submitOVM()
{
	// Find the OVM form, the original search form
	var OVMForm = FIND("OVMresTool");
	var SearchForm = FIND("resTool");
	var DepartDateText = FIND("gsDepartureDate");
    var packageType = SearchForm.gsVacationType.value;
	
	// Create date objects out of return and departure date
    var returnDate = new Date(document.restool.ReturnDate.value);
    var departDate = new Date(document.restool.gsDepartureDate.value);

	// Adjust year from '05' to '2005'
	returnDate = adjustYear(returnDate);
	departDate = adjustYear(departDate);

	// Begin setting up the OVM form with values from the search form	
	OVMForm.PT.value = SearchForm.gsVacationType.value;
	OVMForm.VF.value = SearchForm.gsVendor.value;
	OVMForm.UPID.value = SearchForm.UPID.value;
	OVMForm.OR.value = SearchForm.gsOriginHidden.value;
	OVMForm.DEST.value = SearchForm.gsDestinationHidden.value;
	OVMForm.PAX.value = trimAge(g_PAXCount);
	OVMForm.LEN.value = SearchForm.gsLengthOfStay.value;//diffDays(returnDate, departDate);
	//OVM Date Formatting
	// Create a Date object from the departure date to use in filling in the TARS form
	var ovmDepartDate = new Date(DepartDateText.value);
		ovmDepartDate= adjustYear(ovmDepartDate);
	// Convert date to what resengine.asp is expecting
	OVMForm.Date.value = padAge((ovmDepartDate.getMonth() + 1).toString()) + "/" + padAge(ovmDepartDate.getDate().toString()) + "/" +  ovmDepartDate.getYear().toString().substr(g_YearIndex,2);
	//OVM needs the NumberTravelers to be Adults only, so create a temp var (OVM_paxCount)
	//and set it equal to g_PAXCount and subtract any children.
	var OVM_paxCount = g_PAXCount;
	var ChildAge1 = TRIM(document.restool.gsAge1.value.toUpperCase());
	var ChildAge2 = TRIM(document.restool.gsAge2.value.toUpperCase());
	var ChildAge3 = TRIM(document.restool.gsAge3.value.toUpperCase());
	var ChildAge4 = TRIM(document.restool.gsAge4.value.toUpperCase());
	if (ChildAge1 !="" && ChildAge1.toUpperCase() != "NA")
	{
		OVM_paxCount--;
	}
	if (ChildAge2 !="" && ChildAge2.toUpperCase() != "NA")
	{
		OVM_paxCount--;
	}
	if (ChildAge3 !="" && ChildAge3.toUpperCase() != "NA")
	{
		OVM_paxCount--;
	}	
	if (ChildAge4 !="" && ChildAge4.toUpperCase() != "NA")
	{
		OVM_paxCount--;
	}

	//OVMForm.OVMgsNumberOfTravelers.value = OVM_paxCount;
	OVMForm.CH1.value = padAge(SearchForm.gsAge1.value);
	OVMForm.CH2.value = padAge(SearchForm.gsAge2.value);
	OVMForm.CH3.value = padAge(SearchForm.gsAge3.value);
	OVMForm.CH4.value = padAge(SearchForm.gsAge4.value);	
	OVMForm.PC.value = SearchForm.gsPromotionCode.value;
	OVMForm.SourceCode.value = SearchForm.SourceCode.value;
	if(g_Referrer != "")
	{
		OVMForm.RF.value = g_Referrer;
	}
	if(g_PLCode != "")
	{
	    OVMForm.plCode.value = g_PLCode;
	}

	//showPost(OVMForm);
	OVMForm.submit();
    return false;
}

// Function Name: submitSBT
// Purpose: Submits the SBT form directly to SBT
// Parameters: vendor - Vendor to subit as.
// Return: None
function submitSBT()
{
	// Find SBT form and original search form
	var SBTForm = FIND("submitResTool");
	var SearchForm = FIND("restool");

	var packageType = document.restool.gsVacationType.value;

	// Create date objects out of return and departure date
    var returnDate = new Date(document.restool.ReturnDate.value);
    var departDate = new Date(document.restool.gsDepartureDate.value);

	// Adjust year from '05' to '2005'
	returnDate = adjustYear(returnDate);
	departDate = adjustYear(departDate);
	
	SBTForm.action = g_SBTSearch;

	// Fill in SBT form from values from the original Search form
	SBTForm.gsVendor.value = "UNT";//SearchForm.gsVendor.value;
	SBTForm.gsVacationType.value = packageType;
	SBTForm.gsDestination.value = SearchForm.gsDestinationHidden.value;
	
    if (SearchForm.gsOriginHidden.value != "")
	    SBTForm.gsOrigin.value = SearchForm.gsOriginHidden.value;
	else
	    SBTForm.gsOrigin.value = "XXX";
	    
		
		var Passengers = SearchForm.PAX.value;
		var gsAge1 = SearchForm.gsAge1.value.toUpperCase();
		var gsAge2 = SearchForm.gsAge2.value.toUpperCase();
		var gsAge3 = SearchForm.gsAge3.value.toUpperCase();
		var gsAge4 = SearchForm.gsAge4.value.toUpperCase();

		if (gsAge1 !="")
			{Passengers++;	}

		if (gsAge2 !="")
			{Passengers++;	}

		if (gsAge3 !="")
			{Passengers++;	}

		if (gsAge4 !="")
			{Passengers++;	}	

	SBTForm.gsNumberOfTravelers.value = trimAge(Passengers);	
	
	//SBTForm.gsNumberOfTravelers.value = trimAge(g_PAXCount);
	SBTForm.gsDepartureDate.value = SearchForm.gsDepartureDate.value;
	//SBTForm.hoCheckInDate.value = SearchForm.DepartDate.value;
	//SBTForm.coPickUpDate.value = SearchForm.DepartDate.value;
	SBTForm.gsReturnDate.value = SearchForm.ReturnDate.value;
	//SBTForm.hoCheckOutDate.value = SearchForm.ReturnDate.value;
	//SBTForm.coDropOffDate.value = SearchForm.ReturnDate.value;
	SBTForm.gsLengthOfStay.value = diffDays(returnDate, departDate);
	SBTForm.gsAge1.value = checkAge(SearchForm.gsAge1.value);
	SBTForm.gsAge2.value = checkAge(SearchForm.gsAge2.value);
	SBTForm.gsAge3.value = checkAge(SearchForm.gsAge3.value);
	SBTForm.gsAge4.value = checkAge(SearchForm.gsAge4.value);
	SBTForm.gsPromotionCode.value = SearchForm.gsPromotionCode.value;
	//SBTForm.gsSourceCode.value = SearchForm.gsSourceCode.value;
	
	
	if(g_Referrer != "")
	{
		SBTForm.Referrer.value = g_Referrer;
	}
	
	if(g_PLCode != "")
	{
	    SBTForm.plCode.value = g_PLCode;
	}
	if((g_PostCartID != "") && (g_PostActivePkgSeq != ""))
	{
	    SBTForm.ActivePkgSeq.value = g_PostActivePkgSeq
	    SBTForm.CartID.value = g_PostCartID;
	}

	//showPost(SBTForm);
	//showWaitIndicator('WaitIndicator','Main')
	SBTForm.submit();
    return false;
}

function validateText () 
{
    var validtext;
    if (document.restool.gsPromotionCode.value != ""){
        if (validate(document.restool.gsPromotionCode.value, "PROMOCODE") == false) {
			if(document.getElementById("promoCodeWarning")!=null){
			    document.getElementById("promoCodeWarning").style.display = "block"
			    validtext = false;
			} 
		}
        else{
        document.getElementById("promoCodeWarning").style.display = "none";
        validtext = true;
        }
    }
     else{
        document.getElementById("promoCodeWarning").style.display = "none";
        validtext = true;
    }
    
    return 	validtext;
 }
// Function Name: validateDes
// Purpose: Validates that the destination in the text box exists in the list box.
// Parameters: None
// Return: Boolean - whether the destination was found or not
function validateDes()
{

	var destFound = false;

	  var desSel = TRIM(document.restool.gsDestination.value).toUpperCase();
	  var destWarn
	  var destRow

		document.restool.gsDestinationHidden.value = document.restool.gsDestination.value;
		destFound=true;
	   //------ Display Error message for Invalid Destination.
	   destWarn = FIND('trDestinationWarning');
	   destRow = FIND('trDestinationClientH');

		if(destFound)
		{
		  //destWarn.style.display = "none"; destRow.style.display = "none"; //document.restool.gsDestinationHidden.value = desSel; 
		}
	   if(destFound)
			return true;
	   else
			return false;
}

// Function Name: validateOrg
// Purpose: Validates that the origin in the text box exists in the list box.
// Parameters: None
// Return: Boolean - whether the Origin was found or not
function validateOrg()
{
	  var orgSel = TRIM(document.restool.gsOrigin.value).toUpperCase();
	  var originWarn
	  var originRow
	  var orgFound = true;
	  
	originWarn = FIND('trOriginWarning');
	originRow = FIND('trOriginClientH');

		if(orgFound)
		{
			//originWarn.style.display = "none"; originRow.style.display = "none"; //document.restool.gsOriginHidden.value = orgSel; 
		} 
	   if(orgFound)
			return true;
	   else
			return false;
}
// Function Name: trimAge
// Purpose: Trims leading zeroes from a value.
// Parameters: age - value to be trimmed
// Return: String - trimmed value
function trimAge(age)
{
	if (age.length >= 2 && age.substr(0,1) == '0')
	{
		age = age.substr(1, age.substr.length - 1);
		//alert("age now is: " + age);
	}
	return age;
}
function validateUPCCheck(){
	var retVal = true;
	
	var UPCCheck = document.restool.UPCCheck.value;
	
	if (UPCCheck == "T") {
		var upccode	= document.restool.UPCCode.value;
		if ( (upccode == "4900000030")|| (upccode == "4900000036") || (upccode == "4900000044") || 
		(upccode == "4900000045") || (upccode == "4900000046") || (upccode == "4900000050") || (upccode == "4900000132") ||
		(upccode == "4900000243") || (upccode == "4900000248") || (upccode == "4900000264") || (upccode == "4900000365") || 
		(upccode == "4900000367") || (upccode == "4900000411") || (upccode == "4900000551") || (upccode == "4900000572") || 
		(upccode == "4900000634") || (upccode == "4900000639") ||(upccode == "4900000658") || (upccode == "4900000663") || 
		(upccode == "4900000715") || (upccode == "4900000725") || (upccode == "4900000764") ||(upccode == "4900000877") || 
		(upccode == "4900000887") || (upccode == "4900000889") || (upccode == "4900000929") || (upccode == "4900000935") ||
		(upccode == "4900001063") || (upccode == "4900001178") || (upccode == "4900001278") || (upccode == "4900001423") || 
		(upccode == "4900001424") ||(upccode == "4900001631") || (upccode == "4900001632") || (upccode == "4900001634") || 
		(upccode == "4900001635") || (upccode == "4900001679") ||(upccode == "4900001702") || (upccode == "4900001801") || 
		(upccode == "4900001916") || (upccode == "4900001938") || (upccode == "4900002385") ||(upccode == "4900002392") || 
		(upccode == "4900002395") || (upccode == "4900002398") || (upccode == "4900002468") || (upccode == "4900002469") ||
		(upccode == "4900002470") || (upccode == "4900002542") || (upccode == "4900002543") || (upccode == "4900002620") || 
		(upccode == "4900002627") ||(upccode == "4900002820") || (upccode == "4900002889") ||(upccode == "4900002890") || 
		(upccode == "4900002891") ||(upccode == "4900002892") ||(upccode == "4900002893") ||(upccode == "4900002933") || 
		(upccode == "4900002934") ||(upccode == "4900002936") ||(upccode == "4900002979") ||(upccode == "4900002990") || 
		(upccode == "4900003012") ||(upccode == "4900003073") ||(upccode == "4900003074") ||(upccode == "4900003077") ||
		(upccode == "4900003103") ||(upccode == "4900003105") ||(upccode == "4900003108") ||(upccode == "4900003117") || 
		(upccode == "4900003124") ||(upccode == "4900003133") ||(upccode == "4900003309") ||(upccode == "4900003629") || 
		(upccode == "4900003637") ||(upccode == "4900003647") ||(upccode == "4900003655") ||(upccode == "4900003711") || 
		(upccode == "4900003717") ||(upccode == "4900003719") ||(upccode == "4900003724") ||(upccode == "4900004069") || 
		(upccode == "4900004070") ||(upccode == "4900004071") ||(upccode == "4900004072") ||(upccode == "4900004086") || 
		(upccode == "4900004119") ||(upccode == "4900004120") ||(upccode == "4900004121") ||(upccode == "4900004206") || 
		(upccode == "4900004207") ||(upccode == "4900004208") ||(upccode == "4900004209") ||(upccode == "4900004255") || 
		(upccode == "4900004256") ||(upccode == "4900004258") ||(upccode == "4900004266") ||(upccode == "4900004267") || 
		(upccode == "4900004268") ||(upccode == "4900004269") ||(upccode == "4900004284") ||(upccode == "4900004327") || 
		(upccode == "4900004336") ||(upccode == "4900004382") ||(upccode == "4900004449") ||(upccode == "4900004456") || 
		(upccode == "4900004463") ||(upccode == "4900004465") ||(upccode == "4900004467") ||(upccode == "4900004750") || 
		(upccode == "4900004751") ||(upccode == "4900004753") ||(upccode == "4900004754") ||(upccode == "4900004756") || 
		(upccode == "4900004808") ||(upccode == "4900004809") ||(upccode == "4900004810") ||(upccode == "4900004823") || 
		(upccode == "4900004824") ||(upccode == "4900004825") ||(upccode == "4900004827") ||(upccode == "7297900018") || 
		(upccode == "7297900025") ||(upccode == "7297900254") ||(upccode == "7297900305") ||(upccode == "7297900307") || 
		(upccode == "7297900334") ||(upccode == "4900004601") ||(upccode == "200802001") ||(upccode == "200802002") ||
		//New UPC Codes MF
		(upccode == "049000044362")||(upccode == "049000042559")||(upccode == "049000042849")||(upccode == "049000042566")||
		(upccode == "049000042580")||(upccode == "0490000408690")||(upccode == "049000024685")||(upccode == "049000006209")||
		(upccode == "049000005226")||(upccode == "049000028904")||(upccode == "049000012781")||(upccode == "049000006346")||
		(upccode == "049000040692")||(upccode == "04900000794704979407")||(upccode == "049000049541")||(upccode == "04900000640704964007")||
		(upccode == "04900000639104963901")||(upccode == "04900000044304904403")||(upccode == "49000018349")||(upccode == "049000035179")||
		(upccode == "049000049909")||(upccode == "04900000182204918202")||(upccode == "049000028294")||(upccode == "049000049749")||
		(upccode == "04900000012204901202")||(upccode == "049000024692")||(upccode == "049000014884")||(upccode == "04900000524004952400")||
		(upccode == "049000028911")||(upccode == "049000024692")||(upccode == "049000014884")||(upccode == "04900000524004952400")||
		(upccode == "049000028911")||(upccode == "049000010633")||(upccode == "04900000658204965802")||(upccode == "049000049558")||
		(upccode == "04900000663604966306")||(upccode == "04900000045004904500")||(upccode == "049000018998")||(upccode == "04900000183904918309")||
		(upccode == "4900004436")||(upccode == "4900004255")||(upccode == "4900004284")||(upccode == "4900004256")||
		(upccode == "4900004258")||(upccode == "4900004086")||(upccode == "4900002468")||(upccode == "4900000620496200")||
		(upccode == "4900000522495220")||(upccode == "4900002890")||(upccode == "4900001278")||(upccode == "49000006346496340")||
		(upccode == "4900004069")||(upccode == "4900000794497940")||(upccode == "4900004954")||(upccode == "4900000640496400")||
		(upccode == "49000006394963909")||(upccode == "4900000044490440")||(upccode == "4900001834")||(upccode == "4900003517")||
		(upccode == "4900004990")||(upccode == "4900000182491820")||(upccode == "4900002829")||(upccode == "4900004974")||
		(upccode == "4900000012490120")||(upccode == "4900002469")||(upccode == "4900001488")||(upccode == "4900000524495240")||
		(upccode == "49000028911")||(upccode == "4900001063")||(upccode == "4900000658496580")||(upccode == "49000049558")||
		(upccode == "4900000663496630")||(upccode == "4900000045490450")||(upccode == "4900001899")||(upccode == "4900000183491830")||
		//New UPC Codes PV
		(upccode=="049000001822")||(upccode=="049000018349")||(upccode=="049000047608")||(upccode=="049000049930")||(upccode=="049000005486")||
		(upccode=="049000040692")||(upccode=="049000006346")||(upccode=="049000043105")||(upccode=="049000028904")||(upccode=="049000012781")||
		(upccode=="049000052497")||(upccode=="049000000443")||(upccode=="049000024685")||(upccode=="049000005226")||(upccode=="049000050103")||
		(upccode=="049000006391")||(upccode=="04918202")||(upccode=="04954806")||(upccode=="04963406")||(upccode=="04904403")||(upccode=="04952206")||
		(upccode=="04963901")||(upccode=="049000047639")||(upccode=="049000000313")||(upccode=="049000049978")||(upccode=="049000049947")||(upccode=="049000042566")||
		(upccode=="049000043907")||(upccode=="049000042559")||(upccode=="049000042849")||(upccode=="049000052503")||(upccode=="049000006841")||(upccode=="049000043822")||
		(upccode=="049000040869")||(upccode=="049000045840")||(upccode=="049000050141")||(upccode=="049000042580")||(upccode=="04903103")||(upccode=="04968401")||
		(upccode=="049000050998")||(upccode=="049000006582")||(upccode=="049000043112")||(upccode=="049000052510")||(upccode=="049000010633")||(upccode=="049000047486")||
		(upccode=="049000005943")||(upccode=="049000040708")||(upccode=="049000024692")||(upccode=="049000000450")||(upccode=="049000005240")||(upccode=="049000050110")||
		(upccode=="049000006636")||(upccode=="04965802")||(upccode=="04959403")||(upccode=="04904500")||(upccode=="04952400")||(upccode=="04966306")
		
		) {
			retVal = retVal && true;
		
		}else{
			alert("Please enter a valid Coke UPC code to take advantage of this offer.");
			retVal = retVal && false;
			
		}	
	}	
	return retVal;
}
function getFieldDescriptionsPop(sbtRootURL, MID) {
	var ghiURL;	// this is the URL to the .aspx page that gives back the included features
	var FieldDescription;
	ghiURL = sbtRootURL + "/Search/FieldDescription.aspx?FieldName=" + MID;
	//alert("getFieldDescriptionPop('"  + MID + "') called page: " + ghiURL );
	FieldDescription = window.open(ghiURL, "FieldDescription", "width=765,height=200,resizable=1,status=1,scrollbars=0,toolbar=0");
    FieldDescription.focus()
}
	
function deleteCookie(name, path, domain) {
   var expiredate = new Date();
    expiredate.setTime(expiredate.getDay() - 30);
    document.cookie = name + "=" +( ( path ) ? ";path=" + path : "") +( ( domain ) ? ";domain=" + domain : "" ) +
";expires=" + expiredate.toGMTString();
}


