﻿//Venues.WeddingFairs.js
//<%--
alert("This javascript file needs to be included in a master template");
//--%>
$(document).ready(function(){
        
    PopupFancyBox();
        
    var hdnCurrentTab = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'hdnCurrentTab');
      var hdnEmailStatus = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'hdnEmailStatus');
    if ($(hdnCurrentTab).val()=="Fair")
      DisplaySelectedTab(); 
       if ($(hdnEmailStatus).val()==1)
       {
          $('.ancemail').click();    
          var lblCommonMessage = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'lblCommonMessage');                                        
          $(lblCommonMessage).css('display','block'); 
          Showsucsessmessage();
          $(hdnEmailStatus).val(0);
       }            
     $('.ancemail').click(function(){

     if ($(hdnEmailStatus).val()==0) 
        HideErrormessage();
        ClearFields();
     }); 
          
}); 

function DisplyMessages()
{
 var hdnEmailStatus = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'hdnEmailStatus');
 if ($(hdnEmailStatus).val()==0) 
        HideErrormessage();
        ClearFields();
    
}
  
function DisplaySelectedTab()
{
    var hdnCurrentTab = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'hdnCurrentTab');
    var tabName =   $(hdnCurrentTab).val();    
    
    var $tabs;
    if ($('#tabs')){
    	$tabs = $('#tabs').tabs();
    }
    if($tabs){     
		$tabs.tabs('select', tabName);
	}  
       
}

function PopupFancyBox(){  
	$(".ancemail").fancybox({'overlayOpacity': 0.7,
		'hideOnContentClick': false			                            
	});			                              
}

function HideErrormessage()
{
        var errorDiv = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'errorDiv');
        var sucsessDiv = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'sucsessDiv'); 
        var lblCommonMessage = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'lblCommonMessage');      
            $(lblCommonMessage).text('');
            $(lblCommonMessage).css('display','none');
            $(errorDiv).css('display','none');                            
            $(sucsessDiv).css('display','none');   
}

function ShowErrormessage(message)
{    
        
        var lblCommonMessage = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'lblCommonMessage'); 
         var lblErrorMessage = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'lblErrorMessage');
        $(lblCommonMessage).css('display','block');      
        $(lblCommonMessage).text(message);        
        $(lblCommonMessage).attr('class','CommonMessageError');     
         
}
function ShowErrormessage1(message)
{    
              
         var errorDiv = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'errorDiv');
         var lblErrorMessage = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'lblErrorMessage');
        $(lblErrorMessage).css('display','block');  
        $(errorDiv).css('display','block');        
        $(errorDiv).html(message);       
        $(lblErrorMessage).attr('class','lblErrorMessage');    
         
}
function ClearFields()
{

 var txtYourName = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'txtYourName');
    var txtYourEmail = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'txtYourEmail');   
    var txtFriendName = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'txtFriendName');
    var txtFriendEmail = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'txtFriendEmail');    
    var txtSecurity='#' + $('.lblClientId').attr('id').replace('lblClientId','txtSecurity');
    $(txtYourName).val('');
    $(txtYourEmail).val('');
    $(txtFriendName).val('');
    $(txtFriendEmail).val('');
    $(txtSecurity).val('');    
}
function Showsucsessmessage()
{                
         var sucsessDiv = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'sucsessDiv');               
        $(sucsessDiv).css('display','block');                                            
}

function ValidateEmailFields()

{
   var errorList = new Array();
    var txtYourName = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'txtYourName');
    var txtYourEmail = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'txtYourEmail');   
    var txtFriendName = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'txtFriendName');
    var txtFriendEmail = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'txtFriendEmail');
    var hdnSecurityID='#' + $('.lblClientId').attr('id').replace('lblClientId','hdnSecurityID');
    var txtSecurity='#' + $('.lblClientId').attr('id').replace('lblClientId','txtSecurity');
 
        
     function IsValidEmailAddress(EmailAddress) 
     {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(EmailAddress);
	}  
	
	                               
	       
       if (jQuery.trim($(txtYourName).val()) == '')
       {        
         
             errorList.push("The <b>your name </b> field can't be empty.");
             
       }
                       if (jQuery.trim($(txtYourEmail).val()) =='')
                       {
                       
                             errorList.push("The <b>your email address</b> field can't be empty.");
                           
                       }    
      else
        {
                       if (IsValidEmailAddress($(txtYourEmail).val())==false)
                       {        
                        
                          errorList.push("The <b>your email address</b> field must be valid.");
                       }
             
        }           
        
        if (jQuery.trim($(txtFriendName).val()) == '')
        {        
          
           errorList.push("The <b>your friend name </b> field can't be empty.");
             
        }
                      if (jQuery.trim($(txtFriendEmail).val()) =='')
                      {
                     
                          errorList.push("The <b>your friend email address</b> field can't be empty.");
                         
                      } 
        else 
           {
                      if (IsValidEmailAddress($(txtFriendEmail).val())==false)
                      {        
                        
                          errorList.push("The <b>your friend email address</b> field must be valid.");
                         
                      }	                
           }           
                                        if ($(txtSecurity).val()=='')
                                                  {                                     
                                              
                                                  errorList.push("The <b>security code </b> field can't be empty.");
                                                  }
                                    else
                                      {
                                            
                                             if($(txtSecurity).val().toUpperCase()!=$(hdnSecurityID).val())
                                               {
                                         
                                                   errorList.push("The <b>security code</b> field must be valid.");                                 
                                               }
                                       }
                                       
                 if(errorList.length>0)
                 {
                   var message="";
                 jQuery.each(errorList, function(index, item) {
              
                     message=message+(index+1)+'. '+item+"<br/>"; 
                        var lblErrorMessage = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'lblErrorMessage');
                                       
                 });
                  ShowErrormessage('Sorry, there was error because...');
                  ShowErrormessage1(message);
                return false
                  }                      
    
 return true
}


function ExecuteSubmit()
 {
            var hdnEmailStatus = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'hdnEmailStatus');             
            
           if (ValidateEmailFields())
           {              
                var hdnCheckStatus = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'hdnCheckStatus');                
                var chkYourself = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'chkYourself');
                $(hdnCheckStatus).val(); 
                               
                if ($(chkYourself).is(':checked'))
                {
                   
                  $(hdnCheckStatus).val(1);
                }     
            $('.btnSend').click();
             
               	
           }
    else
          {
           return false;
          }
              
 }          

 
 
function PostCode(id)
{
    <%If ConfigurationManager.AppSettings("Mandatory.Postcode") Then %>
	if($(id).val()=="Enter your postcode")
    {
        $(id).val('') ;
    } 
    var lblCommonMessage1 = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'lblCommonMessage1');
    $(lblCommonMessage1).hide();
	<% End If%>
	
}
 function PostCodeChange(id)
 {
	<%If ConfigurationManager.AppSettings("Mandatory.Postcode") Then %>
		if($(id).val()=='')
		{
			$(id).val('Enter your postcode') ;
		} 
		var lblCommonMessage1 = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'lblCommonMessage1');
			$(lblCommonMessage1).hide();
	<% End If%>
}
 function GetDirections(hddnPostcode,txtPostCode)
 {
        if( $(txtPostCode).val()!= "Enter your postcode" || $(txtPostCode).val()!= "" )
        {
             $(txtPostCode).keypress(function(e) {           
                       if((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13) )
                       {         
                         MyDirections(hddnPostcode,txtPostCode); 
                         return false;            
                       }             
             });
        }
        var hdnCurrentTab = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'hdnCurrentTab');    
        $(hdnCurrentTab).val("Fair");                     	                                
 }
function MyDirections(hddnPostcode,txtPostCode)
{

    var sourceAddress = $(txtPostCode).val();
    var googleUrl = "<% =ConfigurationManager.AppSettings("Googlemaps.BaseURL") %>?";   
    var destinationAddress = $(hddnPostcode).val();    
    var link =  googleUrl + "saddr=" +sourceAddress + "&daddr=" +  destinationAddress + "&hl=en";      
    window.open(link,'getDirection','resizable=yes ,scrollbars=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes');                   
    var lblCommonMessage1 = '#' + $('.lblClientId').attr('id').replace('lblClientId', 'lblCommonMessage1');
    $(lblCommonMessage1).hide();
     
}

function Directions(hddnPostcode,txtPostCode)
{

      if($(txtPostCode).val()!= "Enter your postcode" || $(txtPostCode).val()!= "")
      {
           MyDirections(hddnPostcode,txtPostCode);           
      }
      
}

