<!--
var fe_timer = 500;
var fe_limit = 10000;
var fe_pos = 1;
var galpos = 0;
var galchange = Array('7','13','19','25','31','37','43','49','55','61','67');

//************ Start Default Commands ************
function sortNumber(a,b){ return a - b; }

function getQuery(val){
  var querystring = location.search.substring(1,location.search.length);
  var o = "";
  var tSec = querystring.indexOf(val+"=");
  var tStr = querystring.substring( (tSec+(val.length+1)),querystring.length);
  
  if(tSec != -1){
    if(tStr.indexOf('&') != -1){
      o = tStr.substring(0,tStr.indexOf('&'));
    } else {
      o = tStr;
    }
  }
  return o;
}

function inArray(needle, haystack) {
  var length = haystack.length;
  for(var i = 0; i < length; i++) {
    if(haystack[i] == needle) return true;
  }
  return false;
}

function replaceSubstring(s,f,w){
  rtn = "";
  flg = 0;
  
  for(i = 0; i < s.length; i++){
    if(s.substr(i,f.length) == f){
      rtn += w;
      i += (f.length - 1);
    } else {
      rtn += s.charAt(i);
    }
  }
  return (rtn);
}

function urlencode(str) {
  str = replaceSubstring(escape(str),'/',"");
  str = str.replace('+', '%2B');
  str = str.replace('%20', '+');
  str = str.replace('*', '%2A');
  str = str.replace('@', '%40');
  return str;
}

function testAlphaPassword(f,d){
  if(d == ""){ d = 0; }
  var doc = document.forms[d];
  var ele = doc.elements[f];
  var str = false;

  if(ele.value == ""){
    alert("Please enter a password");
  } else {
    if(/[^a-zA-z0-9]/i.test(ele.value)){
      alert("Sorry, your password may only contain letters and numbers");
    } else {
      str = true;
    }
  }
  return str;
}

function getCookie(Name){ 
  var search = Name + "=" 
  if(document.cookie.length > 0){
    offset = document.cookie.indexOf(search);
    if(offset != -1){
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if(end == -1){ end = document.cookie.length; }
      return unescape(document.cookie.substring(offset, end)) ;
    }
  } 
} 

function setCookie(name, value) {
  var today = new Date(); 
  expires = new Date(); 
  expires.setTime(today.getTime() + 1000*60*60*24*1);
  document.cookie = name + "=" + value + ";path=/;expires=" + expires.toGMTString();
}

function goPage(u){
  location.href = u;
}

//************ End Default Commands ************
function updatePage(d){
  if(d == ""){ d = 0; }
  var doc = document.forms[d];
  doc.submit();
}

//********* jQuery **********
function loopForthcomingEvents(){
  var num = $('.forthcomingevent').size();
  if(num > 1){
    if((fe_pos+1) > num){ fe_pos = 1; } else { fe_pos = (fe_pos+1); }

    $('.forthcomingevent').each(function(){ $(this).fadeOut(); $(this).css({'position':'absolute','width':'271px'}) });
    $('#e' + fe_pos).fadeIn();

    if(fe_timer){ clearTimeout(fe_timer); }
    fe_timer = setTimeout("loopForthcomingEvents();",fe_limit);
  } else {
    if(fe_timer){ clearTimeout(fe_timer); }
  }
}

$(document).ready(function(){
  $('#homepagecontent .column').last().css({'width':'286px','margin-right':'0'});
  $('#leftnavigation .nav2').last().css({'padding-bottom':'9px'});
  var hary = new Array();
  $('#homepagecontent .column').each(function(){ hary.push(parseInt($(this).height())); }); hary.sort(sortNumber);
  $('#homepagecontent .column').each(function(){ $(this).css('height',hary[hary.length-1] + 'px'); });

  $('.news_story').last().css({'border':'0','padding':'0','margin':'0'});

  $('ul.events .row').each(function(){
    if($(this).height() > 15){
      var a = $(this).attr('class').split(' ');
      var row = a[a.length-1];
      $('.' + row).css('height',$(this).height() + 'px');
    }
  });

  $('#eventsearch').click(function(){
    location.href = $('#searchhref').val() + "/search/" + urlencode($('#eventcategory').val()) + "/" + urlencode($('#eventmonth').val());
  });

  $('#directorysearch').click(function(){
    if($('#directoryquery').val() == "Enter First Name or Last Name"){ var qry = ""; } else { var qry = $('#directoryquery').val(); }
    location.href = $('#searchhref').val() + "/search/" + urlencode($('#directoryform').val()) + "/" + urlencode($('#directorygroup').val()) + "/" + urlencode(qry);
  });

  $('#oldgirlsearch').click(function(){
    if($('#directoryform').val() == "DD/MM/YYYY" || $('#directoryform').val() == ""){ var dob = "all"; } else { var dob = $('#directoryform').val(); }
    if($('#directoryquery').val() == "Enter First Name or Maiden Name"){ var qry = ""; } else { var qry = $('#directoryquery').val(); }
    if(dob != "" || qry != ""){
      location.href = $('#searchhref').val() + "/search/" + urlencode(dob) + "/" + urlencode(qry);
    }
  });

  $('.staff_list p.cleft').first().css('display','none');

  $('.form_expand').click(function(){
    var id = $(this).attr('id');
    if($(this).hasClass('form_expandsel')){
      $(this).removeClass('form_expandsel');
      $('#' + id + 'details').slideUp('fast');
    } else {
      $(this).addClass('form_expandsel');
      $('#' + id + 'details').slideDown('fast');
    }
  });

  $('#showguardian2').click(function(){ if($(this).hasClass('form_expandsel')){ $('#data_guardian_num').val('2'); } else { $('#data_guardian_num').val('1'); } });
  $('#showchild2').click(function(){ if($(this).hasClass('form_expandsel')){ $('#data_child_num').val('2'); } else { $('#data_child_num').val('1'); } });
  $('#showchild3').click(function(){ if($(this).hasClass('form_expandsel')){ $('#data_child_num').val('3'); } else { $('#data_child_num').val('2'); } });
  $('#showchild4').click(function(){ if($(this).hasClass('form_expandsel')){ $('#data_child_num').val('4'); } else { $('#data_child_num').val('3'); } });

  $('.enquiry_submit').click(function(){ $('#enquiry').submit(); });

  $("#enquiry").bind("submit", function() {
    if( ($("#data_guardian1_firstname").val().length < 1) || ($("#data_guardian1_lastname").val().length < 1) || ($("#data_guardian1_email").val().length < 1) || ($("#data_child1_firstname").val().length < 1) || ($("#data_child1_lastname").val().length < 1) || ($("#data_child1_dob").val() == 'DD/MM/YYYY') ){
      $("p.error").slideDown('normal').delay(3000).slideUp('normal');
      return false;
    } else {
      $.ajax({
        url: "/process/enquiry_form.php",
        cache: false,
        type: "POST",
        data: $(this).serializeArray(),
        success: function(data) {
          location.href = location.href + "/enquiry-thanks";
        },
        error: function(){
          //$("p.error").html('Sorry, that username already exists in our system, please try again').slideDown('normal').delay(3000).slideUp('normal');
        }
      });
    }
  });

  $('.forthcomingevent:first').css('display','block');
  if(fe_timer){ clearTimeout(fe_timer); }
  fe_timer = setTimeout('loopForthcomingEvents()',fe_limit);


/* -------- PARENTS LOGIN ------ */
  $('.parent_login_submit').click(function(){ $("#parentlogin").submit(); });

  $("#parentlogin").bind("submit", function() {
    if( ($("#login_username").val().length < 1) || ($("#login_password").val().length < 1) ){
      $("#parentlogin p.error").html('Please enter your Log-in details below.').slideDown().delay('3000').slideUp();
      return false;
    } else {
      $.ajax({
        url: "/process/parent_login_form.php",
        cache: false,
        type: "POST",
        data: $(this).serializeArray(),
        success: function(data) {
          location.href = data;
        },
        error: function(data){
          $("#parentlogin p.error").html('Sorry, we could not find your details, please try again').slideDown().delay('3000').slideUp();
        }
      });
    }
  });

/* -------- OLD GIRLS LOGIN ------ */
  $('.oldgirl_login_submit').click(function(){ $("#oldgirllogin").submit(); });

  $("#oldgirllogin").bind("submit", function() {
    if( ($("#login_username").val().length < 1) || ($("#login_password").val().length < 1) ){
      $("#oldgirllogin p.error").html('Please enter your Log-in details below.').slideDown().delay('3000').slideUp();
      return false;
    } else {
      $.ajax({
        url: "/process/oldgirl_login_form.php",
        cache: false,
        type: "POST",
        data: $(this).serializeArray(),
        success: function(data) {
          location.href = data;
        },
        error: function(data){
          $("#oldgirllogin p.error").html('Sorry, we could not find your details, please try again').slideDown().delay('3000').slideUp();
        }
      });
    }
  });

/* ----- PARENTS REGISTER ----- */
  $('.parentregister_submit').click(function(){ $('#parentregister').submit(); });
  $("#parentregister").bind("submit", function() {
    if( ($("#data_guardian1_firstname").val().length < 1) || ($("#data_guardian1_lastname").val().length < 1) || ($("#data_guardian1_connection").val().length < 1) || ($("#data_guardian1_email").val().length < 1) || ($("#data_child1_firstname").val().length < 1) || ($("#data_child1_lastname").val().length < 1) || ($("#data_child1_dob").val() == 'DD/MM/YYYY') ){
      $("p.error").html('Please make sure you complete all <span class=\"mandatory\">mandatory</span> fields').slideDown('normal').delay(3000).slideUp('normal');
      return false;
    } else {
      $('#submitbutton').css('display','none');
      $.ajax({
        url: "/process/parent_registration_form.php",
        cache: false,
        type: "POST",
        data: $(this).serializeArray(),
        success: function(data) {
          location.href = location.href + "/thank-you";
        },
        error: function(){
          $('#submitbutton').css('display','block');
          $("p.error").html('Sorry, that username already exists in our system, please try again').slideDown('normal').delay(3000).slideUp('normal');
        }
      });
    }
  });


/* ----- OLD GIRL REGISTER ----- */
  $('.oldgirl_submit').click(function(){ $('#oldgirlregister').submit(); });

  $("#oldgirlregister").bind("submit", function() {
    if( ($("#data_title").val().length < 1) || ($("#data_firstname").val().length < 1) || ($("#data_maiden_name").val().length < 1) || ($("#data_username").val().length < 1) || ($("#data_password").val().length < 1) ){
      $("p.error").html('Please make sure you complete all <span class=\"mandatory\">mandatory</span> fields').slideDown('normal').delay(3000).slideUp('normal');
      return false;
    } else {
      $('#submitbutton').css('display','none');
      $.ajax({
        url: "/process/old_girl_registration_form.php",
        cache: false,
        type: "POST",
        data: $(this).serializeArray(),
        success: function(data) {
          location.href = location.href + "/thank-you";
        },
        error: function(){
          $('#submitbutton').css('display','block');
          $("p.error").html('Sorry, that username already exists in our system, please try again').slideDown('normal').delay(3000).slideUp('normal');
        }
      });
    }
  });

/* -------- FORGOT USERNAME ------ */
  $('.forgotusername_submit').click(function(){ $("#forgotusername").submit(); });

  $("#forgotusername").bind("submit", function() {
    if( ($("#forgot_emailaddress").val().length < 1) ){
      $("#forgotusername p.error").html('Please enter your email address.').slideDown().delay('3000').slideUp();
      return false;
    } else {
      $.ajax({
        url: "/process/forgot_username.php",
        cache: false,
        type: "POST",
        data: $(this).serializeArray(),
        success: function(data) {
          location.href = data;
        },
        error: function(data){
          $("#forgotusername p.error").html('Sorry, we could not find your details, please try again').slideDown().delay('3000').slideUp();
        }
      });
    }
  });

/* -------- FORGOT PASSWORD ------ */
  $('.forgotpassword_submit').click(function(){ $("#forgotpassword").submit(); });

  $("#forgotpassword").bind("submit", function() {
    if( ($("#forgot_emailaddress").val().length < 1) ){
      $("#forgotpassword p.error").html('Please enter your email address.').slideDown().delay('3000').slideUp();
      return false;
    } else {
      $.ajax({
        url: "/process/forgot_password.php",
        cache: false,
        type: "POST",
        data: $(this).serializeArray(),
        success: function(data) {
          location.href = data;
        },
        error: function(data){
          $("#forgotpassword p.error").html('Sorry, we could not find your details, please try again').slideDown().delay('3000').slideUp();
        }
      });
    }
  });

/* ----- PARENTS UPDATE ----- */
  $('.parentupdate_submit').click(function(){ $('#parentupdate').submit(); });
  $("#parentupdate").bind("submit", function() {
    if( ($("#data_guardian1_firstname").val().length < 1) || ($("#data_guardian1_lastname").val().length < 1) || ($("#data_guardian1_connection").val().length < 1) || ($("#data_guardian1_email").val().length < 1) || ($("#data_child1_firstname").val().length < 1) || ($("#data_child1_lastname").val().length < 1) || ($("#data_child1_dob").val() == 'DD/MM/YYYY') ){
      $("p.error").html('Please make sure you complete all <span class=\"mandatory\">mandatory</span> fields').slideDown('normal').delay(3000).slideUp('normal');
      return false;
    } else {
      $('#submitbutton').css('display','none');
      $.ajax({
        url: "/process/parent_update_form.php",
        cache: false,
        type: "POST",
        data: $(this).serializeArray(),
        success: function(data) {
          location.href = location.href + "/thank-you";
        },
        error: function(){
          $('#submitbutton').css('display','block');
          $("p.error").html('Sorry, there was an error processing your details.').slideDown('normal').delay(3000).slideUp('normal');
        }
      });
    }
  });

/* ----- OLD GIRL UPDATE ----- */
  $('.oldgirlupdate_submit').click(function(){ $('#updateoldgirldetails').submit(); });

  $("#updateoldgirldetails").bind("submit", function() {
    if( ($("#data_title").val().length < 1) || ($("#data_firstname").val().length < 1) || ($("#data_maiden_name").val().length < 1) || ($("#data_username").val().length < 1) || ($("#data_password").val().length < 1) ){
      $("p.error").html('Please make sure you complete all mandatory fields').slideDown('normal').delay(3000).slideUp('normal');
      return false;
    } else {
      $('#submitbutton').css('display','none');
      $.ajax({
        url: "/process/oldgirls_update_form.php",
        cache: false,
        type: "POST",
        data: $(this).serializeArray(),
        success: function(data) {
          location.href = location.href + "/thank-you";
        },
        error: function(){
          $('#submitbutton').css('display','block');
          $("p.error").html('Sorry, there was an error processing your details.').slideDown('normal').delay(3000).slideUp('normal');
        }
      });
    }
  });

/* ----- Gallery ----- */
  $('.gallery_thumb').click(function(){
    var galend = $('#galend').val();
    $('.gallery_thumb').each(function(){ $(this).parent().removeClass('sel'); });
    $(this).parent().addClass('sel');

    galpos = $(this).attr('id').substring(3);
    if(galpos > 1){ $('#prevlrg').css('display','block'); } else { $('#prevlrg').css('display','none'); }
    if(galpos == galend){ $('#nextlrg').css('display','none'); } else { $('#nextlrg').css('display','block'); }

    $('#img_title').html($(this).children().attr('title'));
    $('#img_desc').html($(this).children().attr('longdesc'));
    var u = replaceSubstring($(this).children().attr('src'),"/h80/","/492x360/");
    $('#gallery_large').attr('src',u);
  });

  $('#nextlrg').click(function(){
    var galend = $('#galend').val();

    if(galpos+1 <= galend){
      $('.gallery_thumb').each(function(){ $(this).parent().removeClass('sel'); });
      var img = $('#img' + (galpos+1)).children();
      $('#img' + (galpos+1)).parent().addClass('sel');
      $('#img_title').html(img.attr('title'));
      $('#img_desc').html(img.attr('longdesc'));
      var u = replaceSubstring(img.attr('src'),"/h80/","/492x360/");
      $('#gallery_large').attr('src',u);
      galpos++;

      if(inArray(galpos,galchange)){ $('#thumbs .next').click(); }
      if(galpos > 1){ $('#prevlrg').css('display','block'); } else { $('#prevlrg').css('display','none'); }
      if(galpos == galend){ $('#nextlrg').css('display','none'); } else { $('#nextlrg').css('display','block'); }
    }
  });

  $('#prevlrg').click(function(){
    var galend = $('#galend').val();

    if(galpos-1 >= 1){
      $('.gallery_thumb').each(function(){ $(this).parent().removeClass('sel'); });
      var img = $('#img' + (galpos-1)).children();
      $('#img' + (galpos-1)).parent().addClass('sel');
      $('#img_title').html(img.attr('title'));
      $('#img_desc').html(img.attr('longdesc'));
      var u = replaceSubstring(img.attr('src'),"/h80/","/492x360/");
      $('#gallery_large').attr('src',u);
      if(inArray(galpos,galchange)){ $('#thumbs .prev').click(); }
      galpos--;

      if(galpos > 1){ $('#prevlrg').css('display','block'); } else { $('#prevlrg').css('display','none'); }
      if(galpos == galend){ $('#nextlrg').css('display','none'); } else { $('#nextlrg').css('display','block'); }
    }
  });

});


//-->
