﻿// JScript File


         $(document).ready(function() {    
         
         //Exclusive programs area pages scripts
         
         
         
//            $('.area-page1').css( { "display":"block" } );
//            $('.area-page2').css( { "display":"none" } );
//            $('#first-page-link').css ( { "display":"none"  } );             
//            $('#second-page-link').css ( { "display":"block"  } );
                                             
            $('.button-submit').val('');
                        
            
            $('#first-page-link').click(function() {                
                $('.area-page1').css( { "display":"block" } );
                $('.area-page2').css( { "display":"none" } );
                $('#first-page-link').css ( { "display":"none"  } );             
                $('#second-page-link').css ( { "display":"block"  } );
            });
            
            $('#second-page-link').click(function() {                
                $('.area-page1').css( { "display":"none" } );
                $('.area-page2').css( { "display":"block" } ); 
                $('#first-page-link').css ( { "display":"block"  } );             
                $('#second-page-link').css ( { "display":"none"  } );                
            });
            
            
            // End of Exclusives programs                                 
                     
            $('.first-step a').click(function() {
				ClickFirst();               
            });
            
            $('.second-step a').click(function() {             
				ClickSecond();			                    				
            });
            
            $('.third-step a').click(function() {
                ClickThird();                                              
            });
            
            $('.fourth-step a').click(function() {     
                if(!ValidateBasicInformation())
			    {
			        return;
			    }	
                if(!ValidateTravelInterest())
                {                    
                    return ;
                }
                
                if(!ValidateShareWithFriends())
                {
                    return;
                }               
                $('#first-step-container').css( { "display" : "none" } );
                $('#second-step-container').css( { "display" : "none" } );
                $('#third-step-container').css( { "display" : "none" } );                
                $('#fourth-step-container').css( { "display" : "block" } );
                $('.ul-signin-steps li a').removeClass('current');
                $(this).addClass('current');                       
				LoadReviewBasicInformation();
				LoadReviewTravelInterest();
				LoadReviewShareWithFriends();
                
            });
            
            $('#NextButton1').click(function() {
                
                $('.second-step a').trigger('click');
            });
            
            $('#BackButton2').click(function() {
                $('.first-step a').trigger('click');
            });
            
            $('#NextButton2').click(function() {
                $('.third-step a').trigger('click');
            });
            
            $('#BackButton3').click(function() {
                $('.second-step a').trigger('click');
            });
            
            $('#NextButton3').click(function() {
                $('.fourth-step a').trigger('click');
            });
            
            $('#BackButton4').click(function() {
                $('.third-step a').trigger('click');
            });
            
            $('#EditBasicInformation').click(function() {
                $('.first-step a').trigger('click');
            });
            
            $('#EditTravelInterestLink').click(function() {
                $('.second-step a').trigger('click');
            });
			
			$('#yes_travel_offers').click(function() {							
			    
				if ($(this).attr("checked") == true)
				{								    
					$('#no_travel_offers').attr("checked", false);										
				}
			});
			
			$('#no_travel_offers').click(function() {			    
				if ($(this).attr("checked") == true)
				{								    
					$('#yes_travel_offers').attr("checked", false);
				}
			});
			
			$('#ClearButton1').click(function() {
			    $('#user_first_name').val('');
			    $('#user_last_name').val('');
			    $('#user_address').val('');
			    $('#user_city').val('');			    
			    $('#user_country').val('us');
			    $('#user_state').val('(Select)');
			    $('#user_zip').val('');			    
			    $('#user_telephone').val('');
			    $('#user_fax').val('');
			    $('#user_email_address').val('');
			    $('#user_verify_email_address').val('');			
			});
			
			$('#ClearButton2').click(function() {
			    $('#planning_to_travel').val('Select');
			    $('#would_like_to_travel').val('Select');			    
			    $('.checkbox-layout-interestedin').attr("checked", false);
			    $('.checkbox-layout-visitingin').attr("checked", false);
			    $('.checkbox-layout-cruisevacation').attr("checked", false);
			    $('.checkbox-layout-traveled').attr("checked", false);
			    $('.checkbox-layout-cruised').attr("checked", false);
			    $('#questions_comments').val('');	
			    
			    //Clear other textboxes
			    $('#interested_in_visiting_other').val('Other')
			    $('#interested_in_cruises_other').val('Other')
			    $('#have_traveled_other').val('Other')
			    $('#have_cruised_other').val('Other')
			    		   				    					    		
			});
			
			$('#ClearButton3').click(function() {
			    $('#friend_first_name').val('');
			    $('#friend_last_name').val('');
			    $('#friend_address').val('');
			    $('#friend_city').val('');
			    $('#friend_country').val('us');
			    $('#friend_state').val('(Select)');
			    $('#friend_zip').val('');
			    $('#friend_telephone').val('');
			    $('#friend_fax').val('');
			    $('#friend_email_address').val('');
			    $('#friend_verify_email_address').val('');
			});
			
			$("#user_telephone").keypress(function (e)  
	        { 
	            //if the letter is not digit then display error and don't type anything
	            if(e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))
	            {
		            //display error message		            
	                return false;
                }	
	        });
	        
	        $("#friend_telephone").keypress(function (e)  
	        { 	            
	            if(e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))
	            {		        		            
	                return false;
                }	
	        });
            
         
        }); //end of ready function
                
		
		function ClickFirst()
		{
			$('#first-step-container').css( { "display" : "block" } );
                $('#second-step-container').css( { "display" : "none" } );
                $('#third-step-container').css( { "display" : "none" } );
                $('#fourth-step-container').css( { "display" : "none" } );
                $('.ul-signin-steps li a').removeClass('current');
                $('.first-step a').addClass('current');       
		}
		
		function ClickSecond()
		{		    
			
					var address =    $('#user_address').val();
					var city =       $('#user_city').val();
					var state =      $('#user_state').val();
					var country =    $('#user_country').val();
					var zipCode =    $('#user_zip').val();
					
				
			if(!ValidateBasicInformation())
		    {
		        return;
		    }	
			//if(!sendRequest("WebService2.asmx/validateAddress","GET","inputAddress="+address+"&inputCity="+city+"&inputState="+state+"&inputZip="+zipCode))
			//{
			
			sendRequest("WebService2.asmx/validateAddress","GET","inputAddress="+address+"&inputCity="+city+"&inputState="+state+"&inputZip="+zipCode);
		    //    return;
		  //  }	
		 
		/*	for(var x=0;x<=10000;x++)
			{
					for(var x=0;x<=10000;x++)
					{
				
				callmethodblank();
			
					
					}
			}*/
		//setTimeout(function(){sendRequest("WebService2.asmx/validateAddress","GET","inputAddress="+address+"&inputCity="+city+"&inputState="+state+"&inputZip="+zipCode)},0);
		
		//for(var x=0;x<=65;x++)
	//	{
			//	for(var y=0;y<=65;y++)
			//	{
			
				//setInterval("callmethodblank()",5);
			//	}
	//	}
	        alert("Verifying Address Details, Click ok to Continue...");
			
			var test = $('#addressvalidation').text();									
			if (test != '')
			{
				return;
			}
								
            $('#first-step-container').css( { "display" : "none" } );
            $('#second-step-container').css( { "display" : "block" } );
            $('#third-step-container').css( { "display" : "none" } );
            $('#fourth-step-container').css( { "display" : "none" } );
            $('.ul-signin-steps li a').removeClass('current');
            $('.second-step a').addClass('current');  
            SaveBasicInformation();
		}
	function callmethodblank()
					{
					var num1 = 0;
					var num2 = 0;
					var sum= 0;
					var prod = 0;
					sum = num1 + num2;
					prod = num2 * num2;
				
					
					return sum;
					}
	function testAddress()
			  {
					var isValid = false;
					var address =    $('#user_address').val();
					var city =       $('#user_city').val();
					var state =      $('#user_state').val();
					var country =    $('#user_country').val();
					var zipCode =    $('#user_zip').val();
			
			     $.ajax(
            {
                type: "POST",
                url:  "WebService2.asmx/validateAddress",
              
           //     data: "inputAddress:'" + address + "',inputCity:'" + city + "',inputState:'" + state + "',zipCode:'" + zipCode + "'",
  // data: "1,1,1,1",
	data: "inputAddress="+address+"&inputCity="+city+"&inputState="+state+"&inputZip="+zipCode,
	//data: "{\"inputAddress\":\"" + address + "\"" + ", \"inputCity\":\"" + city + "\", \"inputState\":\"" + state + "\", \"inputZip\":\"" + zipCode + "\"}",
				dataType: "json",
				contentLength: "length",
                contentType: "application/x-www-form-urlencoded",
				
                success: function(result) {     
						alert(result.d);				 
                }
            }); ///end of $.ajax(
			
				return isValid
			  }
		
			function sendRequest(url,callback,postData) {
			
					var message = "none"
					var req = createXMLHTTPObject();		
					
					if (!req) return;
					var method = (postData) ? "POST" : "GET";
					req.open(method,url,true);
					req.setRequestHeader('User-Agent','XMLHTTP/1.0');
					if (postData)
						req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
					req.onreadystatechange = function () {
						if (req.readyState != 4) return;
						if (req.status != 200 && req.status != 304) {
				//			alert('HTTP error ' + req.status);
						
							return;
						}
						else
						{
						
						
						
						 var xmldata=req.responseXML //retrieve result as an XML object
						 var validate=xmldata.getElementsByTagName("string");
						 
						 var getreturn = validate[0].firstChild.nodeValue.toString();
						
						var allOptionsArray = getreturn.split(",");
						
						
						 
						for (var i in allOptionsArray) {
						 
						   if(allOptionsArray[0] != "error")
						   {
								var erroraddress = allOptionsArray[0]
								//$('#addressvalidation').text(erroraddress);
								$('#addressvalidation').text('* Street not Found');																					
									
								
						   }
						   else
						   {
								$('#addressvalidation').text('');
								//$('#addressvalidation').html('');
								$('#user_address').val(allOptionsArray[1]);
								$('#user_city').val(allOptionsArray[2]);
								$('#user_state').val(allOptionsArray[3]);			             
								$('#user_zip').val(allOptionsArray[4]);
							
						
						   }
						 
						 }
						 
					
						 
						 
						/* var validate=xmldata.getElementsByTagName("string")
						 var address1 = xmldata.getElementsByTagName("adress")
						  
						 if(validate[0].firstChild.nodeValue != "Valid Address Details")
						 {
						
						 isValid = false;
						
						 alert(address1[0].firstChild.nodeValue)
						 }
						 else
						 {
						 
						 }*/
						 
						 
						}
					//	callback(req);
					

					}
					if (req.readyState == 4)						
					return;
					req.send(postData);
					
			//	setTimeout(function(){req.send(postData)}, 50)
					return message;
				}

				var XMLHttpFactories = [
					function () {return new XMLHttpRequest()},
					function () {return new ActiveXObject("Msxml2.XMLHTTP")},
					function () {return new ActiveXObject("Msxml3.XMLHTTP")},
					function () {return new ActiveXObject("Microsoft.XMLHTTP")}
				];

				function createXMLHTTPObject() {
					var xmlhttp = false;
					for (var i=0;i<XMLHttpFactories.length;i++) {
						try {
							xmlhttp = XMLHttpFactories[i]();
						}
						catch (e) {
							continue;
						}
						break;
					}
					return xmlhttp;
				}

		
		
		
		
		function ClickThird()
		{
			if(!ValidateBasicInformation())
			{
			    return;
			}	
            if(!ValidateTravelInterest())
            {                    
                return ;
            }
            $('#first-step-container').css( { "display" : "none" } );
            $('#second-step-container').css( { "display" : "none" } );
            $('#third-step-container').css( { "display" : "block" } );
            $('#fourth-step-container').css( { "display" : "none" } );
            $('.ul-signin-steps li a').removeClass('current');
            $('.third-step a').addClass('current');  
		}
    
		function LoadReviewBasicInformation()
		{
			var firstName =  $('#user_first_name').val();
			var lastName =   $('#user_last_name').val();
			var address =    $('#user_address').val();
			var city =       $('#user_city').val();
			var state =      $('#user_state').val();
			var country =    $('#user_country').val();
			var zipCode =    $('#user_zip').val();
			var phone =      $('#user_telephone').val();
			var fax =        $('#user_fax').val();
			var email =  	 $('#user_email_address').val();	
			var is =         $('#yes_travel_offers').attr("checked");
			$('#ReviewFirstNameSpan').html(firstName);
			$('#ReviewLastNameSpan').html(lastName);
			$('#ReviewAddressSpan').html(address);
			$('#ReviewCitySpan').html(city);
			$('#ReviewStateSpan').html(state);
			$('#ReviewCountrySpan').html(country);
			$('#ReviewZipCodeSpan').html(zipCode);
			$('#ReviewPhoneSpan').html(phone);
			$('#ReviewFaxSpan').html(fax);
			$('#ReviewEmailSpan').html(email);		
			if(is)
			{
			    $('#ReviewReceive').html('yes');
			}
			else
			{
			    $('#ReviewReceive').html('no');
		    }		
		}		
		
		function LoadReviewTravelInterest()
		{
			var travelInterest = $('#planning_to_travel').val();
			var tripLength = $('#would_like_to_travel').val();
			var interestedIn = "";
			$('.checkbox-layout-interestedin').each(function() {
                       if ($(this).attr("checked") == true) {
//                            var itemName = $(this).next();
							interestedIn += $(this).attr("title");
							interestedIn += ", ";
                        }
                    });                    
					
		    var visitingIn= "";
			$('.checkbox-layout-visitingin').each(function() {
                       if ($(this).attr("checked") == true) {
//                            var itemName = $(this).next();
							visitingIn += $(this).attr("title");
							visitingIn += ", ";
                        }
                    });
			var cruiseVacation = "";
			$('.checkbox-layout-cruisevacation').each(function() {
                       if ($(this).attr("checked") == true) {
//                            var itemName = $(this).next();
							cruiseVacation += $(this).attr("title");
							cruiseVacation += ", ";
                        }
                    });
			
			var traveled = "";
			$('.checkbox-layout-traveled').each(function() {
                       if ($(this).attr("checked") == true) {
//                            var itemName = $(this).next();
							traveled += $(this).attr("title");
							traveled += ", ";
                        }
                    });
			
			var cruised = "";
			$('.checkbox-layout-cruised').each(function() {
                       if ($(this).attr("checked") == true) {
//                            var itemName = $(this).next();
							cruised += $(this).attr("title");
							cruised += ", ";
                        }
                    });
					
			//Added by: Jairo - Harvey		
			var activities = "";
			$('.checkbox-layout-activities').each(function() {
                       if ($(this).attr("checked") == true) {
//                            var itemName = $(this).next();
							activities += $(this).attr("title");
							activities += ", ";
                        }
                    });

		//End of Added by: Jairo - Harvey				
					
					
			var comment = $('#questions_comments').val();
			
			$('#ReviewPlanningToTravelSpan').html(travelInterest);
			$('#ReviewTripLengthSpan').html(tripLength);
			$('#ReviewInterestedInSpan').html(interestedIn);
			$('#ReviewVisitingInSpan').html(visitingIn);
			$('#ReviewCruiseVacationSpan').html(cruiseVacation);
			$('#ReviewTraveledSpan').html(traveled);
			$('#ReviewCruisedSpan').html(cruised);
			
			//Added by: Jairo - Harvey	
			$('#ReviewActivitiesSpan').html(activities);
			//End of Added by: Jairo - Harvey	
			
			$('#ReviewCommentSpan').html(comment);								
		}
	
		function LoadReviewShareWithFriends()
		{
			var shareFirstName = $('#friend_first_name').val();
			var shareLastName = $('#friend_last_name').val();
			var shareAddress = $('#friend_address').val();
			var shareCity = $('#friend_city').val();
			var shareState = $('#friend_state').val();
			var shareCountry = $('#friend_country').val();
			var shareZipCode = $('#friend_zip').val();
			var sharePhone = $('#friend_telephone').val();
			var shareFax = $('#friend_fax').val();
			var shareEmail = $('#friend_email_address').val();			
			$('#ReviewShareFirstNameSpan').html(shareFirstName);
			$('#ReviewShareLastNameSpan').html(shareLastName);
			$('#ReviewShareAddressSpan').html(shareAddress);
			$('#ReviewShareCitySpan').html(shareCity);
			$('#ReviewShareStateSpan').html(shareState);
			$('#ReviewShareCountrySpan').html(shareCountry);
			$('#ReviewShareZipCodeSpan').html(shareZipCode);
			$('#ReviewSharePhoneSpan').html(sharePhone);
			$('#ReviewShareFaxSpan').html(shareFax);
			$('#ReviewShareEmailSpan').html(shareEmail);
			
		}
		
		function IsValidateEmail(elementValue){      
			var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
			return emailPattern.test(elementValue); 
		}
		
		function IsValidPhone(elementValue){      
			var phonePattern = /^\d{3}\-\d{3}\-\d{4}/;
			return phonePattern.test(elementValue); 
		}
		
		
//		function isPhoneNumber(s) 
//        {
//             // Check for correct phone number
//             rePhoneNumber = new RegExp(/^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/);

//             if (!rePhoneNumber.test(s)) {
//                  alert("Phone Number Must Be Entered As: (555) 555-1234");
//                  return false;
//             }
//            return true;
//        }
		
		function ValidateBasicInformation()
		{
			var isValid = true;
			
			if ($('#user_state').val() == '(Select)')
			{					    
				isValid = false;
				$('#errorState').html('Please select a State.');
			}				
			else
			{
			    $('#errorState').html('');
			}
			
			if ($('#user_first_name').val() == '')
			{													
				isValid = false;
				$('#errorFirstName').html('First Name is required.');
			}	
			else
			{
			    $('#errorFirstName').html('');
			}
						
			if ($('#user_last_name').val() == '')
			{								
				isValid = false;
				$('#errorLastName').html('Last Name is required.');
			}
			else
			{
			    $('#errorLastName').html('');
			}
						
			if ($('#user_address').val() == '')
			{								
				isValid = false;								
				$('#errorAddress').html('Address is required.');
			}			
			else
			{
			    $('#errorAddress').html('');
		    }

			if ($('#user_city').val() == '')
			{								
				isValid = false;
				$('#errorCity').html('City is required.');
			}	
			else
			{
			    $('#errorCity').html('');
			}		
			
			if ($('#user_zip').val() == '')
			{								
				isValid = false;
				$('#errorZip').html('Zip Code is required.');
			}
			else
			{
			    $('#errorZip').html('');
			}
			
			var phone = $('#user_telephone').val();
			if ($('#user_telephone').val() == '')
			{								
				isValid = false;
				$('#spanErrorPhone').html('Telephone is required.');
			}
			else
			{
				if(!IsValidPhone(phone))
			    {				
			        $('#spanErrorPhone').html('Invalid Phone Format, format should be ###-###-####')
				    isValid = false;	
			    }			    
			    else
			    {
			        $('#spanErrorPhone').css ( { "display" : "none"  } );			    
			        $('#spanErrorPhone').html('');
			    }
			}			
			
			
			var email = $('#user_email_address').val();
			var verifyEmail = $('#user_verify_email_address').val();
			if ($('#user_email_address').val() == '')
			{								
				isValid = false;
				$('#errorEmail').html('Email is required');				
			}
			else
			{			    			   
			    if (email == verifyEmail)
			    {								
                    // do nothing    	
                    $('#errorEmail').html('');			
			    }					
			    else
			    {		
			        $('#user_verify_email_address').css( { "border" : "dashed 2px red" } );
			        isValid = false;			        
			        $('#errorEmail').html("Email doesn't match");
			    }			
			}									
			
			if(!IsValidateEmail(email))
			{				
				isValid = false;	
				$('#errorEmail').html("Invalid Email.");
			}			
			else
			{
			    $('#errorEmail').html("");
			}
			return isValid;
		}
		 
		 
	
		function ValidateTravelInterest()
		{
		    var isValid = true;
		    if ($('#planning_to_travel').val() == 'Select')
			{		
			    $('#planningToTravelError').html('Please select when to travel.');
				isValid = false;				
			}			
			else
			{
			    $('#planningToTravelError').html('');
			}
			
			if ($('#would_like_to_travel').val() == 'Select')
			{								
			    $('#wouldLikeToTravelError').html('Please select the desired trip length.');
				isValid = false;								
			}
			else
			{
			    $('#wouldLikeToTravelError').html('');
			}
			
			
			var isInterested = ValidateInterestedIn();			
			
            if((isValid == true) && (isInterested == true))
            {
                return true;
            }
            else
            {
                return false;
            }
			                                   
            return isValid;                        
		}
		
		function ValidateInterestedIn()
		{		    		 
		    var isInterestingInValid = false;		    
		    var isCruiseVacationValid = $('#cruise_vacation').attr("checked");
		    var isTourVacationValid = $('#tour_vacation').attr("checked");
		    if (isCruiseVacationValid == true || isTourVacationValid == true)
		    {		        
		        $('#InterestedInError').html('');
		        isInterestingInValid = true;
		    }
		    else
		    {
		        $('#InterestedInError').html('<br>Please check at least one');
		    }		       		    
            return isInterestingInValid;
		}
		
		function ValidateShareWithFriends()
		{
		    var isValid = true;
//		    var spanShareEmailError = $('#shareEmailError');
		    var email = $('#friend_email_address').val();
			var verifyEmail = $('#friend_verify_email_address').val();		
			var sharePhone = $('#friend_telephone').val();			
			//Validate Phone if not empty
			if(sharePhone != '')
			{
			    if (!IsValidPhone(sharePhone))
			    {
			        $('#friend_telephone').css ( { "border" : "dashed 2px red" } );
					$('#spanErrorFriendPhone').html('Invalid Phone Format, format should be ( ) _____-________');
                    $('#spanErrorFriendPhone').css ( { "display" : "block"  } );
				    isValid = false;
				    return isValid;	
			    }			    			    
				else
				{
					$('#spanErrorFriendPhone').css ( { "display" : "none"  } );
				}
			}			
			
			
			if ((email == "") && (verifyEmail == ""))
			{				
				return true;
			}
			if (email == verifyEmail)
			{								                    
				// do nothing
			}					
			else
			{			    
				$('#friend_verify_email_address').css ( { "border" : "dashed 2px red" } );
				isValid = false;			        
				return isValid;
			}	
			
			if(!IsValidateEmail(email))
			{
				$('#friend_email_address').css ( { "border" : "dashed 2px red" } );
				isValid = false;	
				return isValid;
			}			

		    return isValid;
		}
		
		function SaveBasicInformation()
		{
		    var sb = "";		    
		    sb += "<p>First Name: ";
		    sb += $('#user_first_name').val();
		    sb += "</p>";
		    sb += "<p>Last Name: ";
		    sb += $('#user_last_name').val();
		    sb += "</p>";
		    sb += "<p>Address: ";
		    sb += $('#user_address').val();
		    sb += "</p>";		    
		    sb += "<p>City: ";
		    sb += $('#user_city').val();
		    sb += "</p>";
		    sb += "<p>Country: ";
		    sb += $('#user_country').val();
		    sb += "</p>";
		    sb += "<p>State: ";
		    sb += $('#user_state').val();
		    sb += "</p>";
		    sb += "<p>Zip Code: ";
		    sb += $('#user_zip').val();
		    sb += "</p>";
		    sb += "<p>Phone: ";
		    sb += $('#user_telephone').val();
		    sb += "</p>";
		    sb += "<p>Fax: ";
		    sb += $('#user_fax').val();
		    sb += "</p>";
		    sb += "<p>Email: ";
		    sb += $('#user_email_address').val();
		    sb += "</p>";		    		    		   	                            
		    var cookieID = readCookie("BasicInformationID");		
		    if (cookieID == null)
		    {
		        cookieID = "";
		    }    		    
            $.ajax(
            {
                type: "POST",
                url: "WebService.asmx/InsertBasicInformation",
//                url: "~/Workarea/webservices/WebServiceAPI/Content/Content.asmx/AddContent",                
                data: "{\"sb\":\"" + sb + "\"" + ", \"cookieID\":\"" + cookieID + "\"}",
//                data: "{\"sb\":\"" + sb + "\"}",
//                data: "{\"UserName\":\"" + catCode + "\"" + ", \"manCode\":\"" + manCode + "\"}",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function(list) {                                      
                    createCookie("BasicInformationID", list.toString(), 1);
                }
            }); ///end of $.ajax(  
            
		}
		
		

