//form validation
//***************************************************** BEGIN: Marina Details *****************************************************************
function checkandsubmitMarinaDetails(thisform){
	var missing = false;	
	var str = "";	
	/*
		var filler = "      ";
	var str = "_______________________________________\n\n";
		str += "The information was not submitted because\nof the following error(s):\nPlease correct the error(s) and re-submit.\n";
		str += "_______________________________________\n\n";
		str += "-The following field(s) are required:\n";
	*/
	//make sure state is filled in if country is Canada or US
	if ((thisform.pk_country_id.value == 5)||(thisform.pk_country_id.value == 14))
		{
			if (thisform.pk_state_id.value == 0)
			{
				str += "State/Province is required.\n";
				missing = true;
			}
		}

	if (missing)
		{
		alert(str);
		return false;
		}
	else
		{
		return true;
		}
	}
//***************************************************** END: Marina Details *****************************************************************
	
//***************************************************** BEGIN: Fuel *****************************************************************
function checkandsubmitFuel(thisform)
	{
		var missing = false;
		var filler = "      ";
		var	str = "The following field(s) are required:\n";
		
		//alert("x");
		
		// Do Required Checks
		//Gasoline
		if ((thisform.ysn_gas[0].checked == false) && (thisform.ysn_gas[1].checked == false))
		{
			str += filler + "Offer Gasoline\n";
			missing = true;
		}
		else if (thisform.ysn_gas[0].checked == true)
			{
				if ((thisform.gas_dollars.value == 0)&&(thisform.gas_cents.value == 00))
				{
					str += filler + "You have 'Offer Gasoline' marked 'YES' but Gasoline Dollar and/or Cents is '0'\n";
					missing = true;
				}
			}
		else if (thisform.ysn_gas[1].checked == true)
			{
				if ((thisform.gas_dollars.value != 0)||(thisform.gas_cents.value != 00))
				{
					str += filler + "You have 'Offer Gasoline' marked 'NO' but Gasoline Dollar and/or Cents are NOT '0'\n";
					missing = true;
				}
				
			}
		//Diesel
		if ((thisform.ysn_diesel[0].checked == false) && (thisform.ysn_diesel[1].checked == false))
		{
			str += filler + "Offer Diesel\n";
			missing = true;
		}
		else if (thisform.ysn_diesel[0].checked == true)
			{
				if ((thisform.diesel_dollars.value == 0)&&(thisform.diesel_cents.value == 00))
				{
					str += filler + "You have 'Offer Diesel' marked 'YES' but Diesel Dollar and/or Cents is '0'\n";
					missing = true;
				}
			}
		else if (thisform.ysn_diesel[1].checked == true)
			{
				if ((thisform.diesel_dollars.value != 0)||(thisform.diesel_cents.value != 00))
				{
					str += filler + "You have 'Offer Diesel' marked 'NO' but Diesel Dollar and/or Cents are NOT '0'\n";
					missing = true;
				}
			}	
		//At least one checkbox must be checked
		if ((thisform.ysn_gas[0].checked == true) || (thisform.ysn_diesel[0].checked == true))
		{
			if ((thisform.ysn_cash.checked == false) && (thisform.ysn_check.checked == false) && (thisform.ysn_amex.checked == false) && (thisform.ysn_mastercard.checked == false)&& (thisform.ysn_visa.checked == false))
			{
				str += filler + "At least one Payment Method must be checked\n";
				missing = true;
			}
		}
		
		//Discounts
		if ((thisform.ysn_discount[0].checked == false) && (thisform.ysn_discount[1].checked == false))
		{
			str += filler + "Fuel Discounts\n";
			missing = true;
		}
		else if (thisform.ysn_discount[0].checked == true)
			{
			if (!thisform.fuel_discount_desc.value)
				{
					str += filler + "You have 'Offer Fuel Discounts' marked 'YES' but no Discount Description\n";
					missing = true;
				}
			}	
		
		/*
		if ((thisform.begin_date.value) && (thisform.begin_date.value != "mm/dd/yyyy"))
			{
				if (errDate(thisform.begin_date,'Start Date',false,true))
				{
					str += filler + "Start Date is Invalid\n";
					missing = true;
				}	
			}
		
		if ((thisform.end_date.value) && (thisform.end_date.value != "mm/dd/yyyy"))
			 {
				if (errDate(thisform.end_date,'End Date',false,true))
				{
					str += filler + "End Date is invalid\n";
					missing = true;
				}	
			}
		
		//start cannot be less than end date
		if ((thisform.begin_date.value) && (thisform.end_date.value))
		{
			if (Date.parse(thisform.begin_date.value) > Date.parse(thisform.end_date.value))
				{
					str += filler + "Start Date cannot be greater than the End Date.\n";
					missing = true
				}	
				
			if ((thisform.ysn_cancel_emails[0].checked == false) && (thisform.ysn_cancel_emails[1].checked == false))
			{
				str += filler + "Continue to receive fuel email updates\n";
				missing = true;
			}
		}
		*/
		//send to either process page or display
		if(missing)
			{
			alert(str);
			return false;
			}
		else
			{
			//alert("y");
			
			thisform.gas_price.value = thisform.gas_dollars.value + "." + thisform.gas_cents.value;
			thisform.diesel_price.value = thisform.diesel_dollars.value + "." + thisform.diesel_cents.value;
			return true;
			//alert(thisform.gas_price.value);
			//thisform.processFlag.value = true;
			//thisform.submit();
			}
	}

//Marina Specials
function checkandsubmitSpecials(thisform)
	{
		var missing = false;
		var filler = "      ";
		var	str = "The following field(s) are required if adding a NEW Special Offer:\n";
			

	var special_desc = ColdFusion.getElementValue('special_desc', 'specialsForm');
	//var special_title = ColdFusion.getElementValue('special_title', 'specialsForm');
	//alert("xx " + special_desc);
	//alert("xx " + special_title);
	//Checking if addding new Special Offer: if any are not blank then assume trying to enter new special offer
	
	if ((thisform.special_title.value != 0) || (special_desc != '') || (thisform.begin_date.value != '') || (thisform.end_date.value != ''))
		{
		//check special offers form		
			if (thisform.special_title.value == 0)
					{
						str += filler + "NEW RECORD: Special Title\n";
						missing = true;
					}
			else if ((thisform.special_title.value == "Other") && (!thisform.special_title_other.value))
				{
					str += filler + "NEW RECORD: Special Title 'Other'\n";
					missing = true;
				}
				
		if (special_desc == '')
				{
					str += filler + "NEW RECORD: Special Offer Description\n";
					missing = true;
				}
	
		if (thisform.begin_date.value == '')
				{
					str += filler + "NEW RECORD: Start Date\n";
					missing = true;
				}	
			
		if (thisform.end_date.value == '')
				{
					str += filler + "NEW RECORD: End Date\n";
					missing = true;
				}	
		}
			
	//send to either process page or display
		if(missing)
			{
			alert(str);
			return false;
			}
		else
			{
			//thisform.processFlag.value = true;
			return true;
			//return true;
			//thisform.submit();
			}
	}
	



	
//DISCOUNT VALIDATION	
function checkandsubmitDiscounts(thisform)
	{
		var missing = false;
		var filler = "      ";
		var	str = "The following field(s) are required if adding a NEW Discount:\n";
			
		// Do Required Checks
		//alert(thisform.fk_discount_category_id.value);
		//alert(thisform.discount_condition_1.value);
		//missing catefory but has description
		if ((thisform.fk_discount_category_id.value == 0) && (thisform.discount_condition_1.value != ''))
			{
				if (thisform.fk_discount_category_id.value == 0)
				{
					str += filler + "NEW RECORD: Discount Category\n";
					missing = true;
				}
			}
		//missiing desc but has category
		if ((thisform.fk_discount_category_id.value != 0) && (thisform.discount_condition_1.value == ''))
			{
				if (thisform.discount_condition_1.value == '')
				{
					str += filler + "NEW RECORD: Discount Description\n";
					missing = true;
				}
			}
		/*
		if (!thisform.ysn_agree_discounts.checked)
			{
				str += filler + "Please check that you agree to the listed discounts.\n";
				missing = true;
			}
		*/
		if(missing)
			{
			alert(str);
			return false;
			}
		else
			{
			return true;
			//thisform.processFlagCompany.value = 1;
			//thisform.processFlag.value = true;
			//thisform.submit();
			}
	}

//EVENTS VALIDATION	
function checkandsubmitEvents(thisform)
	{
		var missing = false;
		var filler = "      ";
		var	str = "The following field(s) are required if adding a NEW Event:\n";
		
		// Do Required Checks
		if ((thisform.event_name.value != '') || (thisform.event_desc.value != '') || (thisform.event_start_date.value != '') || (thisform.event_end_date.value != ''))
		{
		if (thisform.event_name.value == '')
			{
				str += filler + "NEW RECORD: Event Title/Name\n";
				missing = true;
			}
				
		if (thisform.event_desc.value == '')
			{
				str += filler + "NEW RECORD: Event Description\n";
				missing = true;
			}
	
		if (thisform.event_start_date.value == '')
			{
				str += filler + "NEW RECORD: Start Date\n";
				missing = true;
			}	
			
		if (thisform.event_end_date.value == '')
				{
					str += filler + "NEW RECORD: End Date\n";
					missing = true;
				}	
		}
		if(missing)
			{
			alert(str);
			return false;
			}
		else
			{
			return true;
			//thisform.processFlagCompany.value = 1;
			//thisform.processFlag.value = true;
			//thisform.submit();
			}
	}
	
function showSelectedOtherSpecialTitle(val)
	{
	//display 'other' if selected
	if(val == "Other")
		{	
		document.getElementById("otherSpecialTitle").style.display = "table-row"; 
		//document.getElementById("otherSpecialText").style.display = "block";
		}
	else if(val != "Other")
		{
		document.getElementById("otherSpecialTitle").style.display = "none"; 
		} 
	}
//for collapsing and displaying content
function showContent(val)
	{
	//display 'other' if selected
	if(val == "display")
		{	
		//document.getElementById("otherSpecialTitle").style.display = "table-row"; 
		document.getElementById("thisContent").style.display = "block";
		}
	else if(val != "display")
		{
		document.getElementById("thisContent").style.display = "none"; 
		} 
	}
	
function showSelectedDollarGas(val)
	{			
		document.getElementById
		('selectedResultDollarGas').innerHTML = "$" 
		+ val;
	}
	
function showSelectedCentsGas(val)
	{
		document.getElementById
		('selectedResultCentsGas').innerHTML = "." 
		+ val;
	}
	
function showSelectedDollarDiesel(val)
	{
		document.getElementById
		('selectedResultDollarDiesel').innerHTML = "$" 
		+ val;
	}
function showSelectedCentsDiesel(val)
	{
			document.getElementById
			('selectedResultCentsDiesel').innerHTML = "." 
			+ val;
		}
		
	/////////////////////////////////////old//////////////////
	//Photos
//form validation
/*
function checkandsubmitPhoto(thisform)
	{
		var missing = false;
		var filler = "      ";
		var str = "_______________________________________\n\n";
			str += "The information was not submitted because\nof the following error(s):\nPlease correct the error(s) and re-submit.\n";
			str += "_______________________________________\n\n";
			str += "-The following field(s) are required:\n";
			
		
		if(missing)
			{
			alert(str);
			}
		else
			{
			//thisform.processFlagCompany.value = 1;
			thisform.processFlag.value = true;
			thisform.submit();
			}
	}
	*/
	
	//form validation
/*
function checkandsubmitContacts(thisform)
	{
		var missing = false;
		var filler = "      ";
		var str = "_______________________________________\n\n";
			str += "The information was not submitted because\nof the following error(s):\nPlease correct the error(s) and re-submit.\n";
			str += "_______________________________________\n\n";
			str += "-The following field(s) are required:\n";
			
		// Do Required Checks
		//Company Name	
		
		if (!thisform.contact_first_name.value)
			{
				str += filler + "Contact First Name\n";
				missing = true;
			}
		if (!thisform.contact_last_name.value)
			{
				str += filler + "Contact Last Name\n";
				missing = true;
			}
		if (!thisform.contact_email.value)
			{
				str += filler + "Contact Email\n";
				missing = true;
			}

		if(missing)
			{
			alert(str);
			}
		else
			{
			//thisform.processFlagCompany.value = 1;
			thisform.processFlag.value = true;
			thisform.submit();
			}
	}
*/

//form validation
/*
function checkandsubmitAmenities(thisform)
	{
		var missing = false;
		var filler = "      ";
		var str = "_______________________________________\n\n";
			str += "The information was not submitted because\nof the following error(s):\nPlease correct the error(s) and re-submit.\n";
			str += "_______________________________________\n\n";
			str += "-The following field(s) are required:\n";
			

		if(missing)
			{
			alert(str);
			}
		else
			{
			//thisform.processFlagCompany.value = 1;
			thisform.processFlag.value = true;
			thisform.submit();
			}
	}
	*/
	
//fuel
/*

//Fuel Contacts
		//Only show if gas and diesel are marked 'NO'
		/*
		if ((thisform.ysn_gas[0].checked == true) || (thisform.ysn_diesel[0].checked == true))
			{
			if (!thisform.contact_name.value)
				{
					str += filler + "Fuel Contact Name\n";
					missing = true;
				}
			if (!thisform.contact_email.value)
				{
					str += filler + "Fuel Contact Email\n";
					missing = true;
				}		
			}	
		*/
		//DATES
		// Do Required Checks
		/*
		
		*/	
