
var bgImageArr = new Array(
    'Challaborough-Bay',
    'Cherry-Tree',
    'Grannies-Heilan-Hame',
    'Hayling-Island',
    'Looe-Bay',
    'Mullion',
    'Nairn-Lochloy',
    'Newquay',
    'Pendine-Sands',
    'Sandford',
    'Southerness',
    'St-Minver',
    'Sundrum-Castle',
    'Trecco-Bay',
    'Tummel-Valley',
    'Warmwell',
    'Wemyss-Bay',
    'West-Bay',
    'White-Acres',
    'Crantock-Beach',
    'Cornwall',
    'Devon',
    'Dorset',
    'Hampshire',
    'Norfolk',
    'Scotland',
    'Wales');
    
/* 
= JS Document  ============================
	
	Site: 			Parkdean Holidays
	
	Author: 		Jon Park | Union Room
	Created: 		June 26th, 2008
	Updated: 		
	
	Version: 		1.0.0
	Copyright: 	(c) 2008, Parkdean Holidays
	
=======================================
*/
$(function() {
	// Find out which background image to load for the visitor's screen size
	var $width = $('body').width();
	pathArray = window.location.pathname.split( '/' );
	var region = pathArray[1];
	var park = pathArray[2];
	var bgImage;
	/*This is checking if page name has aspx e.g. URL display like this 
    http://test.parkdeanholidayhomes.co.uk/scotland/scotland-holiday-parks.aspx
    region =  scotland
    park =    scotland-holiday-parks.aspx 
    we are checking here if park has aspx then set bgimage as region name otherwisise set as 
    bg as park 
	*/
			
    var imagePresent=0;

  

    
    
    
    if(park!=undefined && region!=undefined)
    {
        if( (park.indexOf('.aspx')>0 || park.indexOf('.htm')>0) )
            bgImage = region;
        else
            bgImage = park; 
    
        /*This code is checking if bg image we got from URL is not present then set default image */
    	for(i=0;i<bgImageArr.length;i++)
	    {
	        if(bgImage.toString().toUpperCase()==bgImageArr[i].toString().toUpperCase())
	        {imagePresent=1;break;}
	    }
    }
       
    if(imagePresent==0)
    {
	strUrl = window.location.pathname.toUpperCase()	
	
	switch(strUrl)
	{
	case '/locations.aspx'.toUpperCase():
	  bgImage='locations';
	  break;    
	case '/holiday-homes/index.aspx'.toUpperCase():
	  bgImage='holiday-homes';
	  break;
	case '/important-information/owners-benefits.aspx'.toUpperCase():
	  bgImage='important-info';
	  break;	  	  
	case '/news-and-events/index.aspx'.toUpperCase():
	  bgImage='news-and-events';
	  break;	  
	case '/contact-us/index.aspx'.toUpperCase():
	  bgImage='contact-us';
	  break;	  
  	  
	default:
	  bgImage='body';
	  break;	  
	}


    }   


        
	if ($width > 1024 && $width < 1300) {
		$('body').css({ backgroundImage : 'url(/resource/images/bg/'+bgImage+'-1280.jpg)' });
	} else if ($width > 1300) {
		$('body').css({ backgroundImage : 'url(/resource/images/bg/'+bgImage+'-1600.jpg)' });
	}else{
		$('body').css({ backgroundImage : 'url(/resource/images/bg/'+bgImage+'.jpg)' });
	}
	
	
	// Open external links in new window.
	$("a[@rel='external']").addClass("external").attr('title', function() { return this.title + ' (Opens in New Window)' }).click(function() { window.open(this.href); return false; });

	// Hijacks browser and scrolls the page to the top on link click
	$("a[href='#skiptotop']").click(function() { $.scrollTo(0, 500); return false; });
	
	// Replaces standard browser buttons with images
	$('input.btnReplace').hide();
	$('img.btnReplace').show();
	
	// --- Start Form Hijacks --- //
	$('#sendComments img.btnReplace').click(function() { $('#sendComments').submit(); });
	$('#brochureForm img.btnReplace').click(function() { $('#brochureForm').submit(); });
	$('#ownerLogin img.btnReplace').click(function() { $('#ownerLogin').submit(); });
	// --- End Form Hijacks --- //
});



/*This function is used to validate email address it return true or false
Created by : Nas

*/
/* These 2 functions are used to make sure user can only enter int value using that in phone number text box*/
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

 function Emailcheck(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 will check user enter numeric value in text box
Created by :Nas
Created on :12/08/2008
*/	
function checkNumber(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */

  if (cCode < 48 || cCode > 57 ) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  return false;
}


/*This function is used to check whether the date is valid or not
Created By: Nas
Created On : 12/08/2008

*/

function isDate(dateStr) {

    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
    var matchArray = dateStr.match(datePat); // is the format ok?

    if (matchArray == null) {
        //alert("Please enter date in one of the following formats:\nmm/dd/yy, mm/dd/yyyy, mm-dd-yyyy, or mm-dd-yyyy.");
        return false;
    }

    month = matchArray[3]; // parse date into variables
    day = matchArray[1];
    year = matchArray[4];

    if (month < 1 || month > 12) { // check month range
        alert("Month must be between 1 and 12.");
        return false;
    }

    if (day < 1 || day > 31) {
        alert("Day must be between 1 and 31.");
        return false;
    }

    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        alert("Month "+month+" doesn't have 31 days!")
        return false;
    }

    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) {
            alert("February " + year + " doesn't have " + day + " days!");
            return false;
        }
    }
    return true; // date is valid
}


function stringIntoDate(stringDate){

    var myDayStr = stringDate.substring(0,2)
    var myMonthStr = stringDate.substring(3,5)-1
    var myYearStr = stringDate.substring(6,10)

    var myDate = new Date();
    myDate.setFullYear(myYearStr, myMonthStr, myDayStr );
    return myDate;
}

  
    //* isdate function end
  
   /*This function is used in whole web site which by which owners can enter there username and password
  created 05-11-2008
  */
  function validateOwner(strUsername,strPassword){
    
    if(document.getElementById(strUsername).value=='' || document.getElementById(strPassword).value=='' )
    {

        $('#brochureRequest_lblLoginErrMsg').html("<p style='color:#000000; font-weight:bold; font-size:12px;'>Please enter your username and password and then submit.</p>");
        return false;
    }
    return true;    
  }
  
  
  function confirmLogout()
  {
    var where_to= confirm("Are you sure you want to logout?");
    return where_to;
  }
  
  
  function validateForgotonPassword ()
  {
     str = document.getElementById('forgotenEmail').value;
     if(!Emailcheck(str))
     {
        alert("Please enter a valid email address.");
        return false;
     }   
     return true;
     
  }
  /*This function is used when user hit return key then submit specific area of form used in onload event*/
  function setRetunKeyHit(e)
  {
    
    if(!e) e=window.event;
    key = e.keycode ? e.keycode : e.which;
    
    if (key==13)
    {
        document.getElementById('brochureRequest_btnOwnerLogin').focus();
    }
  
  }


    function forceClick(e, elemId) {
        var elem = document.getElementById(elemId);


        if(!e) e=window.event;
        var intKey = e.keyCode ? e.keyCode : e.which;
        
        if(intKey == 13) {
            e.returnValue = false;
            if(elem == null)
                alert('Button not found!');
            else 
            {
                if(e.which)
                  elem.focus();
                else  
                  elem.click();
            }
        }
    }
  
    function subscribe() {
    
    if(! Emailcheck(document.getElementById('tEmail').value))
    {
     alert("Please enter a valid email address.")
     document.getElementById('tEmail').focus();
     return false;
    }
    else
    {
       var email=document.getElementById('tEmail').value;
       document.location.replace("http://www.parkdeanholidayhomes.co.uk/contact-us/subscribers.aspx?email="+email);
    }
    
}

    function reloadBroReqPanelForParks()
    {
        var currLoc = window.location.href;
        document.location.replace(currLoc+"?reload=1");
    } 
    
  
  