﻿// JScript File

$(document).ready(function() {   

	LoadBasicInformationFieldValues();
	LoadPreferenceFieldValues();
	LoadShareFriendFieldValues();
	
    $('.button-submit').click(function() {                  	
        SaveBasicInformationToCookie();
		SavePreferencesToCookie();
		SaveShareFriendToCookie();
		DeleteBasicInformation()
    });
});

function DeleteBasicInformation()
{
    var id = readCookie("BasicInformationID");
    if(id != null)
    {
         $.ajax(
        {
            type: "POST",
            url: "WebService.asmx/DeleteContent",
            data: "{\"contentID\":\"" + id + "\"}",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            success: function(list) {                                  
//                alert("basic information deleted");
            }
        }); 
    }            
}

function SaveBasicInformationToCookie()
{
    var firstName = $('#user_first_name').val();				
    createCookie('FirstName', firstName, 1);		 
     
     var lastName = $('#user_last_name').val();		
	 createCookie('LastName', lastName, 1);		 
	 
	 var address = $('#user_address').val();				
     createCookie('Address', address, 1);		 
     
     var city = $('#user_city').val();				
     createCookie('City', city, 1);		 
     
     var zipCode = $('#user_zip').val();				
     createCookie('ZipCode', zipCode, 1);		 
     
     var phone = $('#user_telephone').val();				
     createCookie('Phone', phone, 1);		 
     
     var fax = $('#user_fax').val();				
     createCookie('Fax', fax, 1);		 
     
     var email = $('#user_email_address').val();				
     createCookie('Email', email, 1);		 
	          
     var verifyEmail = $('#user_verify_email_address').val();
     createCookie('VerifyEmail', verifyEmail, 1);		 
     
     var country = $('#user_country').val();		
     createCookie('Country', country, 1);		 
     
     var state = $('#user_state').val();		
     createCookie('State', state, 1);		 
	 
	 var yesTravel = $('#yes_travel_offers').attr("checked");		 
	 createCookie('YesTravel', yesTravel, 1);		 
	 
	 var noTravel = $('#no_travel_offers').attr("checked");
	 createCookie('NoTravel', noTravel, 1);	    
}

function SavePreferencesToCookie()
{
	var planningToTravel 		= $('#planning_to_travel').val();
	createCookie("PlanningToTravel", planningToTravel, 1);
	var wouldLikeToTravel 		= $('#would_like_to_travel').val();
	createCookie("WouldLikeToTravel", wouldLikeToTravel, 1);
	var cruiseVacation 			= $('#cruise_vacation').attr("checked");
	createCookie("CruiseVacation", cruiseVacation, 1);
	var tourVacation			= $('#tour_vacation').attr("checked");
	createCookie("TourVacation", tourVacation, 1);
	
	var visitingIn = "";	
	$('.checkbox-layout-visitingin').each(function() {			      
	    var value = $(this).attr("checked");
	    visitingIn = visitingIn + value + ",";
    }); 
	createCookie('VisitingIn', visitingIn, 1);	
	var visitingOther = $('#interested_in_visiting_other').val();
    createCookie('VisitingOther', visitingOther, 1);
    
    var vacationWith = "";
    $('.checkbox-layout-cruisevacation').each(function() {			      
	    var value = $(this).attr("checked");
	    vacationWith = vacationWith + value + ",";
    }); 
    createCookie("VacationWith", vacationWith, 1);
    var cruisesOther = $('#interested_in_cruises_other').val();
    createCookie('CruisesOther', cruisesOther, 1);
    
    //Traveled previously
    var traveledPreviously = "";
    $('.checkbox-layout-traveled').each(function() {			      
	    var value = $(this).attr("checked");
	    traveledPreviously = traveledPreviously + value + ",";
    });         
    createCookie("TravelPreviously", traveledPreviously, 1);
    var traveledOther = $('#have_traveled_other').val();
    createCookie("TraveledOther", traveledOther, 1);
    
    //Cruised previously
    var cruisedPreviously = "";
    $('.checkbox-layout-cruised').each(function() {			      
	    var value = $(this).attr("checked");
	    cruisedPreviously = cruisedPreviously + value + ",";
    });         
    createCookie("CruisedPreviously", cruisedPreviously, 1);
    var cruisedOther = $('#have_cruised_other').val();
    
    var preferenceComment = $('#questions_comments').val();
    createCookie("PreferenceComment", preferenceComment, 1);    		
}

function SaveShareFriendToCookie()
{
     var firstName = $('#friend_first_name').val();				
     createCookie('FriendFirstName', firstName, 1);		 
     
     var lastName = $('#friend_last_name').val();		
	 createCookie('FriendLastName', lastName, 1);		 
	 
	 var address = $('#friend_address').val();				
     createCookie('FriendAddress', address, 1);		 
     
     var city = $('#friend_city').val();				
     createCookie('FriendCity', city, 1);		 
     
     var zipCode = $('#friend_zip').val();				
     createCookie('FriendZipCode', zipCode, 1);		 
     
     var phone = $('#friend_telephone').val();				
     createCookie('FriendPhone', phone, 1);		 
     
     var fax = $('#friend_fax').val();				
     createCookie('FriendFax', fax, 1);		 
     
     var email = $('#friend_email_address').val();				
     createCookie('FriendEmail', email, 1);		 
	          
     var verifyEmail = $('#friend_verify_email_address').val();
     createCookie('FriendVerifyEmail', verifyEmail, 1);		 
     
     var country = $('#friend_country').val();		
     createCookie('FriendCountry', country, 1);		 
     
     var state = $('#friend_state').val();		
     createCookie('FriendState', state, 1);		 
}

function LoadBasicInformationFieldValues()
{
	var firstName 		= readCookie('FirstName') == null ? "" : readCookie('FirstName');
	$('#user_first_name').val(firstName);
	
	var lastName 		= readCookie('LastName') == null ? "" : readCookie('LastName');
	$('#user_last_name').val(lastName);
	
	var address 		= readCookie('Address') == null ? "" : readCookie('Address');
	$('#user_address').val(address);
	
	var city 			= readCookie('City') == null ? "" : readCookie('City');
	$('#user_city').val(city);
	
	var zipCode			= readCookie('ZipCode') == null ? "" : readCookie('ZipCode');
	$('#user_zip').val(zipCode);
	var phone			= readCookie('Phone') == null ? "" : readCookie('Phone');
	$('#user_telephone').val(phone);
	
	var fax	 			= readCookie('Fax') == null ? "" : readCookie('Fax');
	$('#user_fax').val(fax);
	
	var email			= readCookie('Email') == null ? "" : readCookie('Email');
	$('#user_email_address').val(email);
	
	var verifyEmail		= readCookie('VerifyEmail') == null ? "" : readCookie('VerifyEmail');
	$('#user_verify_email_address').val(verifyEmail);	
	
	var country			= readCookie('Country') == null ? "us" : readCookie('Country');
	$('#user_country').val(country);
	
	var state			= readCookie('State') == null ? "(Select)" : readCookie('State');
	$('#user_state').val(state);
	
//	var yesTravel		= readCookie('YesTravel') == null ? true : readCookie('YesTravel');
	var noTravel		= readCookie('NoTravel') == null ? "false" : readCookie('NoTravel');	
    
//	$('#yes_travel_offers').attr("checked",yesTravel);
    if (noTravel == "false")
    {
       $('#yes_travel_offers').attr("checked", true);
       $('#no_travel_offers').attr("checked", false);
    }
    else
    {
        $('#yes_travel_offers').attr("checked", false);
        $('#no_travel_offers').attr("checked", true);
    }	
}

function LoadPreferenceFieldValues()
{
    var planningToTravel            = readCookie("PlanningToTravel") == null ? "Select" : readCookie("PlanningToTravel");
    $('#planning_to_travel').val(planningToTravel);
    
    var wouldLikeToTravel           = readCookie("WouldLikeToTravel") == null ? "Select" : readCookie("WouldLikeToTravel");
    $('#would_like_to_travel').val(wouldLikeToTravel);
    
    var cruiseVacation              = readCookie("CruiseVacation") == null ? "false" : readCookie("CruiseVacation");
    if(cruiseVacation == "true")
    {
        $('#cruise_vacation').attr("checked", true);
    }
    else
    {
        $('#cruise_vacation').attr("checked", false);
    }
    
    var tourVacation                = readCookie("TourVacation") == null ? "false" : readCookie("TourVacation");
    if (tourVacation == "true")
    {
        $('#tour_vacation').attr("checked", true);
    }
    else
    {
        $('#tour_vacation').attr("checked", false);
    }
    
    //Load Interested Visiting in
	var visitingInCounter = 0;
	var visitingIn = readCookie('VisitingIn');	
	if(visitingIn != null)
	{	    	    
	    var visitingInSplitted = visitingIn.split(",");	
        $('.checkbox-layout-visitingin').each(function() {
            if (visitingInSplitted[visitingInCounter] == "true")
            {
                $(this).attr("checked", true); 		
            }
            else
            {
                $(this).attr("checked", false); 		
            }            
    	    visitingInCounter++;
        });	    
	}
	var visitingOther = readCookie('VisitingOther') == null ? "Other" : readCookie('VisitingOther');	
	$('#interested_in_visiting_other').val(visitingOther);
	
	//Load Interested in Cruise Vacation With
	var vacationCounter = 0;
	var vacationWith = readCookie("VacationWith");
	if (vacationWith != null)
	{
	    var vacationWithSplitted = vacationWith.split(",");
	    $('.checkbox-layout-cruisevacation').each(function() {
            if (vacationWithSplitted[vacationCounter] == "true")
            {
                $(this).attr("checked", true); 		
            }
            else
            {
                $(this).attr("checked", false); 		
            }            
    	    vacationCounter++;
        });	
	}
	var cruisesOther = readCookie("CruisesOther") == null ? "Other" : readCookie("CruisesOther");
	$('#interested_in_cruises_other').val(cruisesOther);
	
	//Load Traveled Previously
	var traveledCounter = 0;
	var traveled = readCookie("TravelPreviously");
	if (traveled != null)
	{
	    var traveledSplitted = traveled.split(",");
	    $('.checkbox-layout-traveled').each(function() {
            if (traveledSplitted[traveledCounter] == "true")
            {
                $(this).attr("checked", true); 		
            }
            else
            {
                $(this).attr("checked", false); 		
            }            
    	    traveledCounter++;
        });	
	}	
	var traveledOther = readCookie("TraveledOther") == null ? "Other" : readCookie("TraveledOther");
	$('#have_traveled_other').val(traveledOther);
	
	//Load Cruised Previously
	var cruisedCounter = 0;
	var cruised = readCookie("CruisedPreviously");
	if (cruised != null)
	{
	    var cruisedSplitted = cruised.split(",");
	    $('.checkbox-layout-cruised').each(function() {
            if (cruisedSplitted[cruisedCounter] == "true")
            {
                $(this).attr("checked", true); 		
            }
            else
            {
                $(this).attr("checked", false); 		
            }            
    	    cruisedCounter++;
        });	
	}
	var cruisedOther = readCookie("CruisedOther") == null ? "Other" : readCookie("CruisedOther");
	$('#have_cruised_other').val(cruisedOther);	
	
	var preferenceComment = readCookie("PreferenceComment") == null ? "" : readCookie("PreferenceComment");
	$('#questions_comments').val(preferenceComment);		
}

function LoadShareFriendFieldValues()
{
    var firstName 		= readCookie('FriendFirstName') == null ? "" : readCookie('FriendFirstName');
	$('#friend_first_name').val(firstName);
	
	var lastName 		= readCookie('FriendLastName') == null ? "" : readCookie('FriendLastName');
	$('#friend_last_name').val(lastName);
	
	var address 		= readCookie('FriendAddress') == null ? "" : readCookie('FriendAddress');
	$('#friend_address').val(address);
	
	var city 			= readCookie('FriendCity') == null ? "" : readCookie('FriendCity');
	$('#friend_city').val(city);
	
	var zipCode			= readCookie('FriendZipCode') == null ? "" : readCookie('FriendZipCode');
	$('#friend_zip').val(zipCode);
	
	var phone			= readCookie('FriendPhone') == null ? "" : readCookie('FriendPhone');
	$('#friend_telephone').val(phone);
	
	var fax	 			= readCookie('FriendFax') == null ? "" : readCookie('FriendFax');
	$('#friend_fax').val(fax);
	
	var email			= readCookie('FriendEmail') == null ? "" : readCookie('FriendEmail');
	$('#friend_email_address').val(email);
	
	var verifyEmail		= readCookie('FriendVerifyEmail') == null ? "" : readCookie('FriendVerifyEmail');
	$('#friend_verify_email_address').val(verifyEmail);	
	
	var country			= readCookie('FriendCountry') == null ? "us" : readCookie('FriendCountry');
	$('#friend_country').val(country);
	
	var state			= readCookie('FriendState') == null ? "(Select)" : readCookie('FriendState');
	$('#friend_state').val(state);
}








