﻿//<!--
function validateQuery() {
   var email = document.getElementById(_email);
   var fn = document.getElementById(_fn);
   var ln = document.getElementById(_ln);
   var tel = document.getElementById(_tel);
   var ddl = document.getElementById(_country);

   if (fn.value.replace(/^\s+|\s+$/g, "") == "") {
      Alert("first name", fn);
      return false;
   }   
   if (ln.value.replace(/^\s+|\s+$/g, "") == "") {
      Alert("last name", ln);
      return false;
   }
   if (valEmail(email)) {
      return false;
   }
   if (tel.value.replace(/^\s+|\s+$/g, "") == "") {
      Alert("contact number", tel);
      return false;
   }
   if (ddl[ddl.selectedIndex].value == "") {
      Alert("country", ddl);
      return false;
   }
}

function Alert(control, field) {
   alert('Please enter your ' + control);
   field.focus();
}

function AlertServer(control, fieldStr) {
   var field = document.getElementById(fieldStr);
   alert('Please enter your' + control);
   field.focus();
}


function valEmail(el) {
    var invalidChars = " /:,;";
    if (el.value == "") {
        alert("Please enter an email address.");
        el.focus();
        return true;
    }
    for (i = 0; i < invalidChars.length; i++) {
        badChar = invalidChars.charAt(i);
        if (el.value.indexOf(badChar, 0) != -1) {
            alert("Your email address contains an invalid character, please correct it.");
            el.focus();
            return true;
        }
    }
    atPos = el.value.indexOf("@", 1);
    if (atPos == -1) {
        alert("Your email address must contain an @ character.");
        el.focus();
        return true;
    }
    if (el.value.indexOf("@", atPos + 1) != -1) {
        alert("Your email address must have letters before the @ character.");
        el.focus();
        return true;
    }
    periodPos = el.value.indexOf(".", atPos);
    if (periodPos == -1) {
        alert("Your email address must contain a . character.");
        el.focus();
        return true;
    }
    if (periodPos + 3 > el.value.length) {
        alert("Your email address must have letters after the . character.");
        el.focus();
        return true;
    }
    return false;
 }

 function getContent(id) {
    var url = '/Handlers/storeDetails.ashx?ID=' + id;
    $.ajax({
       url: url,
       success: function(data) {
       $("#storeDetailsDiv").html(data);
       }
    })
 }

 function MM_preloadImages() {
    var d = document;
    if (d.images) {
       if (!d.MM_p) {
          d.MM_p = new Array;
       }
       var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
       for (i = 0; i < a.length; i++) {
          if (a[i].indexOf("#") != 0) {
             d.MM_p[j] = new Image;
             d.MM_p[j++].src = a[i];
          }
       }
    }
 }

 function validateNewsletter() {

    /*var _email = '<%= txtEmail.ClientID %>';
    var _fn = '<%= txtFName.ClientID %>';
    var _ln = '<%= txtLName.ClientID %>';
    var _tel = '<%= txtContact.ClientID %>';
    var _province = '<%= txtProvince.ClientID %>';
    var _town = '<%= txtTown.ClientID %>';*/
 
    var email = document.getElementById(_email);
    var fn = document.getElementById(_fn);
    var ln = document.getElementById(_ln);
    var tel = document.getElementById(_tel);
    var province = document.getElementById(_province);
    var town = document.getElementById(_town);
    

    if (fn.value.replace(/^\s+|\s+$/g, "") == "") {
       Alert("first name", fn);
       return false;
    }
    if (ln.value.replace(/^\s+|\s+$/g, "") == "") {
       Alert("last name", ln);
       return false;
    }

    if (valEmail(email)) {
       return false;
    }
    
    if (tel.value.replace(/^\s+|\s+$/g, "") == "") {
       Alert("contact number", tel);
       return false;
    }    
    if (town.value.replace(/^\s+|\s+$/g, "") == "") {
       Alert("closest town/city", town);
       return false;
    }
    if (province.value.replace(/^\s+|\s+$/g, "") == "") {
       Alert("post code", province);
       return false;
    }
 }

 function showGBSize(title, url, width, height) {
    GB_showCenter(title, url, width, height);
 }

 function validateKidsQuery() {

    var fn = document.getElementById(_fn);
    var ln = document.getElementById(_ln);
    var age = document.getElementById(_age);
    var mobile = document.getElementById(_mobile);
    var email = document.getElementById(_email);
    var pemail = document.getElementById(_pemail);
    var card = document.getElementById(_cardnum);
   
    if (fn.value.replace(/^\s+|\s+$/g, "") == "") {
       Alert("first name", fn);
       return false;
    }
    if (ln.value.replace(/^\s+|\s+$/g, "") == "") {
       Alert("last name", ln);
       return false;
    }
    if (age.value.replace(/^\s+|\s+$/g, "") == "") {
       Alert("age", age);
       return false;
    }
    if (mobile.value.replace(/^\s+|\s+$/g, "") == "") {
       Alert("mobile number", mobile);
       return false;
    }    
    if (valEmail(email)) {
       return false;
    }
    if (valEmail(pemail)) {
       return false;
    }   
    return true;

}
function BlurAge(elem, word) {
    var txt = document.getElementById(_age);
    if (txt.value.toLowerCase() == '') { txt.value = word; }
}
function FocusAge(elem, word) {
    var txt = document.getElementById(_age);
    if (txt.value.toLowerCase() == word.toLowerCase()) { txt.value = ''; }
}
 //-->
