﻿
function GetCruiserTypeSelected() {
	var radioOptionList = document.forms[0].elements["RadioButtonListCruiserType"];
	for (var i = 0; i < radioOptionList.length; i++) {
		if (radioOptionList[i].checked) {
			return radioOptionList[i].value;
		}
	}

	return -1;
}

//rename to 2 just in case there are conflicts with both this .js and cheetah.js are included on the same page
function validatePageMethod2() {
	//alert('hello');
	//alert(PageMethods.get_path());

	var path = PageMethods.get_path();
	path = path.substring(path.lastIndexOf("/") + 1);
	if (PageMethods.get_path().startsWith('/'))
		//PageMethods.set_path(PageMethods.get_path().substring(1));
		PageMethods.set_path(path);
		
}

function ShowEmailDialog() {
	$get('TableEmail').style.visibility = 'visible';
	document.bgColor = 'E3E3E3';
	var s = s_gi('carnivalprod');
	s.linkTrackVars = 'prop20,prop21,prop50,events';
	s.linkTrackEvents = 'event15';
	s.prop20 = 'eBrochure';
	s.prop21 = 'eBrochure';
	s.prop50 = document.location.href;
	s.events = 'event15';
	s.tl(this, 'o', 'eBrochure_ShareFriend');
}

function ShowMailDialog() {
	document.getElementById('TableMail').style.visibility = 'visible';
	document.bgColor = 'E3E3E3';

	//UI business rules;
	//If we are working with intro brochure, then we need to check the DVD and disable it.
	var brochureID = getQuerystring('cbid');
	if (brochureID == 'C1') {
		$get('CheckBoxWantsDVD').checked = true;
		$get('CheckBoxWantsDVD').disabled = true;
	}



	//send omniture tags
	var s = s_gi('carnivalprod');
	s.linkTrackVars = 'prop20,prop21,prop50,events';
	s.linkTrackEvents = 'event15';
	s.prop20 = 'eBrochure';
	s.prop21 = 'eBrochure';
	s.prop50 = document.location.href;
	s.events = 'event15';
	s.tl(this, 'o', 'eBrochure_RequestMail');

}

function ChangeStatesToCanada(ddl) {



}

function ChangeStatesToUS(ddl) {


}

function SaveMailData() {
	var cruiserTypeSelected = GetCruiserTypeSelected();
	var customBrochureID = $get("HiddenFieldBrochureID").value;

	if (
		cruiserTypeSelected == -1 ||
		$get("TextBoxFirstName").value == '' ||
		$get("TextBoxLastName").value == '' ||
		$get("TextBoxAddress1").value == '' ||
		$get("TextBoxCity").value == '' ||
		$get("TextBoxZip").value == '' ||
		$get("TextBoxEmail").value == '') {
		alert('Some required fields have not been filled out');
	}
	else if (!CheckMailAddressOK($get("TextBoxEmail"))) {
		//do nothing, message comes from the checker
	}
	else if ($get("CheckBoxRequestVacationPlannerCall").checked && $get("TextBoxPhone").value == '') {
		alert('If you would like a vacation planner to call you, please enter a phone number.');
	}
	else {
		validatePageMethod2();
		PageMethods.SaveMailData(
				customBrochureID,
				cruiserTypeSelected,
				$get("TextBoxFirstName").value,
				$get("TextBoxLastName").value,
				$get("TextBoxAddress1").value,
				$get("TextBoxAddress2").value,
				$get("TextBoxCity").value,
				$get("DropDownListStates").value,
				$get("TextBoxZip").value,
				$get("DropDownListCountries").value,
				$get("CheckBoxEmailSignup").checked,
				$get("TextBoxEmail").value,
				$get("CheckBoxRequestVacationPlannerCall").checked,
				$get("TextBoxPhone").value,
				$get("CheckBoxWantsDVD").checked,
				OnMailSuccess, OnFailed);


	}
}

function SaveEmailData() {
	if ($get("TextBoxSenderName") == '' ||
		$get("TextBoxSenderEmail").value == '' ||
		$get("TextBoxRecipientName").value == '' ||
		$get("TextBoxRecipientEmail").value == '') {

		alert('Some required fields have not been filled out');
	}
	else if (CheckMailAddressOK($get("TextBoxSenderEmail")) && CheckMailAddressOK($get("TextBoxRecipientEmail"))) {

		validatePageMethod2();
		PageMethods.SaveEmailData(
			$get("TextBoxSenderName").value,
			$get("TextBoxSenderEmail").value,
			$get("TextBoxRecipientName").value,
			$get("TextBoxRecipientEmail").value,
			$get("TextBoxComments").value,
			$get("HiddenFieldBrochureID").value,
			$get("HiddenFieldCover").value, OnEmailSuccess, OnFailed);

		//clear sender fields
		$get("TextBoxRecipientName").value = '';
		$get("TextBoxRecipientEmail").value = '';

		//send omniture tags
		var s = s_gi('carnivalprod');
		s.linkTrackVars = 'prop20,prop21,prop50,events';
		s.linkTrackEvents = 'event15,event60';
		s.prop20 = 'eBrochure';
		s.prop21 = 'eBrochure';
		s.prop50 = document.location.href;
		s.events = 'event15,event60';
		s.tl(this, 'o', 'eBrochure_ShareConfirm');

	}
}



function OnEmailSuccess() {
	document.getElementById('emailConfimDialog').style.visibility = 'visible';
	document.getElementById('TableEmail').style.visibility = 'hidden';

	//send confirm omniture tags
	var s = s_gi('carnivalprod');
	s.linkTrackVars = 'prop20,prop21,prop50,events';
	s.linkTrackEvents = 'event15,event60';
	s.prop20 = 'eBrochure';
	s.prop21 = 'eBrochure';
	s.prop50 = document.location.href;
	s.events = 'event15,event60';
	s.tl(this, 'o', 'eBrochure_ShareConfirm');

}

function OnMailSuccess() {
	document.getElementById('regularMailConfirm').style.visibility = 'visible';
	document.getElementById('TableMail').style.visibility = 'hidden';


	//send omniture tags
	var s = s_gi('carnivalprod');
	s.linkTrackVars = 'prop20,prop21,prop50,events';
	s.linkTrackEvents = 'event15,event59';
	s.prop20 = 'eBrochure';
	s.prop21 = 'eBrochure';
	s.prop50 = document.location.href;
	s.events = 'event15,event59';
	s.tl(this, 'o', 'eBrochure_ MailConfirm');

	//send atlast tags
	AT_tags();

	//clear some of the fields to avoid excesive duplicates
	$get("TextBoxFirstName").value = '';
	$get("TextBoxLastName").value = '';
	$get("TextBoxAddress1").value = '';
	$get("TextBoxAddress2").value = '';
	$get("TextBoxCity").value = '';
	$get("TextBoxZip").value = '';
	$get("CheckBoxEmailSignup").checked = false;
	$get("TextBoxEmail").value = '';
	$get("CheckBoxRequestVacationPlannerCall").checked = false;
	$get("TextBoxPhone").value = '';	

}

function OnFailed() {
	window.alert("data saving failed!");
}

function ShowConfirmation(header, body) {
	//div is called
	confirmDialog = document.getElementById('ConfirmDialog');
}


//Step3MailDialog Specific functions
function RequirePVPIfPhoneEntered() {
	var checkBox = $get("CheckBoxRequestVacationPlannerCall");

	//alert(checkBox.checked);
	if ($get("TextBoxPhone").value.length > 0)
		checkBox.checked = true;
	else
		checkBox.checked = false;
}
