// <![CDATA[  
	// === Global Javascript === //
	$(function() {
		$('a[rel=external]').addClass("external").attr('title', function() { return this.title + ' (Opens in New Window)' }).click(function() { window.open(this.href); return false; });
		$('div#callUs h3.telNo').html(getTel());
		$('div#colRight p.telNo').html(getTel());
		$('span.telNo').html(getTel());
		
		/*$.sifr({
			path : 'http://www.parkdeanholidays.co.uk/flash/sIFR/',
			font : 'metaNormal',
			textAlign: 'left'
		});
		$('.flashReplace').sifr();
		
		$('h3.telNo').html(getTel()).sifr();
		$('p.telNo').html(getTel()).sifr();
		
		$('.flashReplaceRight').sifr({textAlign: 'right'});
		$.sifr({
			path : 'http://www.parkdeanholidays.co.uk/flash/sIFR/',
			font : 'metaBold',
			textAlign: 'left'
		});
		$('.flashReplaceBold').sifr();
		$('.flashReplaceBoldRight').sifr({textAlign: 'right'});	*/
		$('a.btnReplace').css('display', 'block').click(function() { var $r = $(this).attr('rel'); /*$('form#' + $r).submit(); */return false; });
		$('input.btnReplace').hide();
		$('#findPark select').change(function() { $('#findPark form').submit(); });
		
		$('#hdrForm a.btnReplace').click(function(){
               
		if($('#globalSearch').val()=='')
		{
			alert('Please enter your search keyword then submit');
			$('#globalSearch').focus();
		}
		else	
	                $('#cse-search-box').submit();
                return false;
                });
		
		$('#globalSearch')
			.focus(function() { if ($(this).val() == '') { $(this).val(''); } })
			.blur(function() { if ($(this).val() == '') { $(this).val(''); } });
			
		$('#emailID')
			.focus(function() { if ($(this).val() == 'Enter your email address') { $(this).val(''); } })
			.blur(function() { if ($(this).val() == '') { $(this).val('Enter your email address'); } });
		$('#findParkPostcode')
			.focus(function() { if ($(this).val() == 'Enter your postcode') { $(this).val(''); } })
			.blur(function() { if ($(this).val() == '') { $(this).val('Enter your postcode'); } });
		$('#comment')
			.focus(function() { if ($(this).val() == 'Send us your suggestions') { $(this).val(''); } })
			.blur(function() { if ($(this).val() == '') { $(this).val('Send us your suggestions'); } });
			
		
		$('a.contentSwitch').click(function() {
		
			if (!$(this).hasClass('animating')) {
				var $l = $(this);
				var $r = $l.attr('rel');
				$l.addClass('animating').toggleClass('closed');
				$('div#contentBox-' + $r + ' div.inner').slideToggle('normal', function() { $l.removeClass('animating'); });
				$('div#contentBox-' + $r).toggleClass('noBG');
			}
			return false;
		});
		
	});
// ]]>

function ValidateEmailForm(emailID){

	var emailID=document.getElementById(emailID)

	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please enter your email address")
		emailID.focus()
		return false
		
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	document.getElementById('monthlyDraw').submit();
	return true	
 }
 
 function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Please enter a valid email address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please enter a valid email address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please enter a valid email address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please enter a valid email address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please enter a valid email address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please enter a valid email address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please enter a valid email address")
		    return false
		 }

 		 return true					
	}
	
	/*This code is used to validate email address

Created :Nas

Created on : 15/12/2008

*/

 

 function isValidEmail(str) {

 

            var at="@"

            var dot="."

            var lat=str.indexOf(at)

            var lstr=str.length

            var ldot=str.indexOf(dot)

            if (str.indexOf(at)==-1){

               return false

            }

 

            if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

               return false

            }

 

            if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

                return false

            }

 

             if (str.indexOf(at,(lat+1))!=-1){

                return false

             }

 

             if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

                return false

             }

 

             if (str.indexOf(dot,(lat+2))==-1){

                return false

             }

            

             if (str.indexOf(" ")!=-1){

                return false

             }

 

             return true                              

      }
      
 function checkIt(evt) {

    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
   
    /*Allow arrow keys home end keys*/		
    if(charCode==35 || charCode==36 || charCode==46 || charCode==37 || charCode==39  )
    	return true;

    if (charCode > 31   && (charCode < 48 || charCode > 57)) {
        return false
    }
    return true
}

    /*
    Created on : 25/11/2008
    Created By : Nas
    Descript : This funcation can be used to get the cookies if no cookie present then it 
                returns empty string
    */

    function getPageVisitedCookies(pageName,intMaxCookiesStores)        
    {        
    var clientVisisted = 'numberOfTimesClientVisitOn'+pageName;
    var intVisited=0;
   
    if(getCookie(clientVisisted)=='')
    {
        intVisited = intVisited+1;
        setCookie(clientVisisted,intVisited,30);
    }
    else
    {
        intVisited = parseInt(getCookie(clientVisisted)) + 1;
        if(parseInt(intVisited)>intMaxCookiesStores)
        {intVisited = 1;}
        setCookie(clientVisisted,intVisited,30);
    }
    
    return getCookie(clientVisisted);
    }




    /*
    Created on : 25/11/2008
    Created By : Nas
    Descript : This funcation can be used to get the cookies if no cookie present then it 
                returns empty string
    */
    

    function getCookie(c_name)
    {
    if (document.cookie.length>0)
    {
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1)
        { 
        c_start=c_start + c_name.length+1; 
        c_end=document.cookie.indexOf(";",c_start);
        if (c_end==-1) c_end=document.cookie.length;
        return unescape(document.cookie.substring(c_start,c_end));
        } 
    }
    return "";
    }

    /*
    Created on : 25/11/2008
    Created By : Nas
    Descript : This funcation can be used to set the cookies in clinet machine we need to pass 3 argumnets
               name of the cookie,value of cookie and days you want to expire thuis cookie     
    */
    
    function setCookie(c_name,value,expiredays)
    {
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
    }

    /*
    Created on : 25/11/2008
    Created By : Nas
    Descript : This function can be used to delete cookies we need to pass name of cookie we want to delete
               from client machine
    
    */
    
    function deleteCookie (cookie_name)
    {
    var cookie_date = new Date ( );  // current date & time
    cookie_date.setTime ( cookie_date.getTime() - 1 );
    document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
    }

		
    /*
    Created on : 25/11/2008
    Created By : Nas
    Descript : This function can be used when we want to display different image on a page and 
               store number of times user visisted so every time user comes it changes the image
               can be used on any page we need to pass 2 arguments in this function 1 is page name 
               we want to set as cookies and number of time you want to loop lets say if there 5 image 
               in a page then you need to pass 5, this is used to change the number visisted from start
               if user visisted more than 5 times
    */

    function setBannerSlide(pageName,intMaxCookiesStores)
    {
    var intPageVisited = getPageVisitedCookies(pageName,intMaxCookiesStores)

    var $new = $('#jGallery .galleryImages .galleryImage-'+intPageVisited); // set the image
    $new.fadeIn('slow').addClass('active');
    var linksArray = $('#jGallery .galleryOverlay .galleryTitleStrip a') // gets the array object of <a> tag and loop through rel tage and selet relevent tage
    
    for (var i = 0; i < linksArray.length; i++){
        if(linksArray[i].rel==intPageVisited)
        {
            $(linksArray[i]).addClass('active');
            $('#jGallery .galleryOverlay .galleryTitleStrip p').html($(linksArray[i]).attr('title'))
        }
     } 
    }


/*This code is used to validate email address
Created :Nas
Created on : 15/12/2008
*/

 function isValidEmail(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}

        /*This function is used to toggle the tags*/
	function toggleThis(id)
	{
	    $('#'+id).slideToggle();
	}  
	
	/*This function can be used anywhere in html or aspx page which will get cheapest price
	from offer table and display in specififed location
	*/
	function getDynamicCheapestPrice(divId,parkId,regionId,typeId)
	{
	    $('#'+divId).html('');
        $.post('http://www.parkdeanholidays.co.uk/dynamicCheapPrice.aspx',{'parkid':parkId,'regionid':regionId,'typeid':typeId}, function (data){
        $('#'+divId).html(data);
        });
		
		 $("#"+divId).ajaxError(function(request, settings){
         $(this).append("Error requesting page " + settings.url + "");
        });

	}   
	
	//	alert(displayAffiliateId());
	
	
	function displayAffiliateId()
	{
		// for testing purpose deleting cookies
//		deleteCookie('affiliateid');
			
		/*If there is no cooky before for affliate id then create one*/
		var affiliateidFromUrl = getURLParam('affiliateid');
		
		// this code will check if url has affilte id then check cookies and get cookies
		if(affiliateidFromUrl != '')
		{
			if(getCookie('affiliateid')=='' || getCookie('affiliateid')=='undefined')
			{
				setCookie('affiliateid',affiliateidFromUrl,1);
			}
		}
		
		var affiliateFromCookies = getCookie('affiliateid');

		if(affiliateFromCookies != 'undefined' && affiliateFromCookies!='')
			affiliateFromCookies = 'Quote ref: ' + affiliateFromCookies
		else
			affiliateFromCookies='';
		document.write(affiliateFromCookies);
	}

	
	// This function is used to get query sting parameer
	// Created by : nas
	// Created on : 24/03/2009
	// purpose to create this can be used to get afflicationid passing in query string
     
	function getURLParam(strParamName)
	{
		var strReturn = "";
		var strHref = window.location.href;
		if ( strHref.indexOf("?") > -1 )
		{
			var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
			var aQueryString = strQueryString.split("&");
			for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
			{
				if(aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 )
				{
					var aParam = aQueryString[iParam].split("=");
					strReturn = aParam[1];
					break;
				}
			}
		return unescape(strReturn);
		}
	}   

	 // This function insert html code for special offer into specified div id
	// it is very easy to update in whole web site
	// created by : nas
	// created on  : 04/08/2009
	function specialOfferHtml(divId)
	{
	
        var url = window.location.pathname.toLowerCase();
	var displayBrcohure='1';
        if( url.indexOf('request-brochure')!=-1 ||   
            url.indexOf('attractions-in')!=-1 || 
            url.indexOf('beaches-in')!=-1 || 
            url.indexOf('walking-in')!=-1 || 
            url.indexOf('cycling-in')!=-1 || 
            url.indexOf('golf-courses-in')!=-1 || 
            url.indexOf('towns-in')!=-1 || 
            url.indexOf('child-friendly')!=-1
            ){
                displayBrcohure='0';
            }

	
            
        var urlArray = url.split('/');
        var parkArray = new Array("ruda","white-acres","sea-acres","nairn-lochloy","west-bay","tummel-valley",
                        "sundrum-castle","trecco-bay","st-minver","holywell-bay","crantock-beach","newquay",
                        "challaborough-bay","grannies-heilan-hame","southerness","torquay","warmwell","cherry-tree",
                        "wemyss-bay","pendine-sands","mullion","looe-bay","sandford","hayling-island"
                        );
        var regionArray = new Array("scotland-holidays","wales-holidays","cornwall-holidays",
                                    "devon-holidays","dorset-holidays","dorset-holidays",
                                    "hampshire-holidays","norfolk-holidays"
                                    );

        var parkPageName="";
        var regionPageName="";
        
        for(i=0;i<urlArray.length;i++){
            
            for(j=0;j<regionArray.length;j++){
                if(urlArray[i]==regionArray[j]){
                    regionPageName=regionArray[j];
                    break;
                }
            }
            for(j=0;j<parkArray.length;j++){
                if(urlArray[i]==parkArray[j]){
                    parkPageName=parkArray[j];
                    break;
                }
            }
                    
        }
        
//        alert(parkPageName)
//        alert(regionPageName)
        $.post('http://www.parkdeanholidays.co.uk/resource/Ajax/righthand-panel-data.aspx',{'park':parkPageName,'region':regionPageName,'displayBrcohure':displayBrcohure}, function (data){
            $('#'+divId).html(data);
        });
    
	}   
	
	function touringOfferHtml(divId)
	{
	
		var url = location.href.toLowerCase();
		
		var startDiv='<!-- START Latest Deals -->';
		var brochReq = '<h6 class="imgReplace" id="requestBrochure"><a class="imgReplace" href="http://www.parkdeanholidays.co.uk/contact-us/request-brochure.aspx" title="Request a free Parkdean Holidays brochure"><span>Request a free brochure</span></a></h6>';
			
	        
       		 var specialOffer=       		        
			'<div class="latestDeals">'+
				'<h6><a class="imgReplace" href="#" title="Latest Deals"><span>Latest Deals</span></a></h6>'+
				'<div class="inner">'+ 
		    '<h6 id="eBird"><a class="imgReplace" href="http://www.parkdeanholidays.co.uk/touring-camping/touring-special-offers.htm" title="Save 20% at selected parks"><span>Save 20% at selected parks</span></a></h6>'+
		    '<h6 id="offPeak"><a class="imgReplace" href="http://www.parkdeanholidays.co.uk/touring-camping/touring-special-offers.htm" title="Save &#163;3 per night on off peak holidays"><span>Save £3 per night on off peak holidays</span></a></h6>';		    
		   
		
		if(url.indexOf('request-brochure-v2')!=-1 || url.indexOf('attractions-in')!=-1 || url.indexOf('beaches-in')!=-1 || url.indexOf('walking-in')!=-1 || url.indexOf('cycling-in')!=-1 || url.indexOf('golf-courses-in')!=-1 || url.indexOf('towns-in')!=-1)
		{
			specialOffer = 	startDiv  + specialOffer;
		}
		else
			specialOffer = 	startDiv  + brochReq + specialOffer;
			
		
		
		if(url.indexOf('thousand-monkeys')!=-1  )
		{
			specialOffer = specialOffer+'<h6 id="nye"><a href="http://www.parkdeanholidays.co.uk/latest-deals/new-year-breaks.aspx" class="imgReplace" title="There are still a few New Year breaks available, don\'t miss out!"><span>There are still a few New Year breaks available, don\'t miss out!</span></a></h6>';
		}						

		specialOffer = specialOffer + '</div></div>';
			      									
		$('#'+divId).html(specialOffer);
	}     	 
	
	