﻿//<!--
function showDiv(div) {
    var d = document.getElementById(div);
    if (d.style.display == 'block') {
        d.style.display = 'none';
    }
    else {
        d.style.display = 'block';
    }
}

function validatePassword(pw) {
    var RegularExpression = new RegExp("[0-9a-zA-Z]{7,12}+(?:\.[0-9a-zA-]*)?");
    var PW = document.getElementById(pw);

    if (!RegularExpression.test(PW.value)) {
        alert('Your password must be between 7 and 12 characters long, please correct it');
        PW.focus();
        return false;
    }
    else {
        return true;
    }
}
function checkDate() {
   var RegularExpression = new RegExp("(^((((0[1-9])|([1-2][0-9])|(3[0-1]))|([1-9]))\x2F(((0[1-9])|(1[0-2]))|([1-9]))\x2F(([0-9]{2})|(((19)|([2]([0]{1})))([0-9]{2}))))$)");
   
   var date = document.getElementById("txtBday");
   if (!RegularExpression.test(date.value)) {
      alert('Invalid date, please correct it');
      date.focus();
      return false;
   }
   else {
      return true;
   }
}
function validateEmail(elem){
    var RegularExpression = new RegExp(/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/);
    var field = document.getElementById(elem);
    field.value = clean(elem);
    if (!RegularExpression.test(field.value)){
        alert('Please enter your email address');
        field.focus();
        return false;        
    }
    else{
        return true;
    }
}
function Blur(elem, word) {
   var txt = document.getElementById(elem);
   if (txt.value.toLowerCase() == '') { txt.value = word; }
}
function Focus(elem, word) {
   var txt = document.getElementById(elem);
   if (txt.value.toLowerCase() == word.toLowerCase()) { txt.value = ''; }
}
function clean(elem){
    var f = document.getElementById(elem);    
    f.focus();
    f = f.value.replace(/^\s+|\s+$/g, "");    
    return f;
}
function Alert(control, field) {   
   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;

}

//faq function
function showFAQ(id) {
    var str = "#" + id + "_content";
    if ($(str).css('display') == 'block') {
        $(str).slideUp('1000');
        $(str).parent("div").removeClass("current");
        $(str).siblings('a').children('img').attr('src', '/images/ico_faq_closed.gif');
    }
    else {
        $("#faqs div[id*='_content']:visible").slideUp('1000', slideit(str));

        $("#faqs div.current").each(function() { $(this).removeClass("current"); $(this).children("a").children("img").attr('src', '/images/ico_faq_closed.gif'); });

        $(str).parent("div").addClass("current");
        $(str).siblings('a').children('img').attr('src', '/images/ico_faq_open.gif');
    }
}
function changecolour(ar) {
    for (i = 0; i < ar.length; i++) {
        if (
            document.getElementById(ar[i]).value == '') {
            document.getElementById(ar[i]).style.backgroundColor = '#ffeeee';
        }
        else {
            document.getElementById(ar[i]).style.backgroundColor = '#ffffff';
        }
    }
}
function changecolourddl(ar) {    
    for (i = 0; i < ar.length; i++) {
        var ddl = document.getElementById(ar[i]);
        if (ddl.selectedIndex == 0) {            
            ddl.style.backgroundColor = '#ffeeee';
        }
        else {
            ddl.style.backgroundColor = '#ffffff';
        }
    }
}
function validateBoxes(ar) {
    for (i = 0; i < ar.length; i++) {
        if (validation1[i].toLowerCase().indexOf('email') > -1) {
            if (!validateEmail(ar[i])) {
                return false;
            }
        }
        if (clean(ar[i]) == '') {
            alert('Please enter all the required fields\nRequired fields are highlighted');
            return false;
        }
    }
    return true;
}
function validateDDL(ar) {
    for (i = 0; i < ar.length; i++) {
        var ddl = document.getElementById(ar[i]);
        if (ddl.selectedIndex == 0) {
            alert('Please enter all the required fields\nRequired fields are highlighted');
            ddl.focus();
            return false;
        }
    }
    return true;
}

function slideit(str) {
    $(str).slideDown('1000');
}


function checkTotal(i, id, targetctl) {

    var txt = document.getElementById(id);
    var target = document.getElementById(targetctl);

    if (txt.value.length >= 3) {
        target.focus();
    }    
}

//show more content function
function showContent(id) {
    var str = "#" + id + "_content";

    $('div[id*="_content"]:visible').slideUp('1000', function() {
        $("a[id*='content']").css('display', "block");
        $("#" + id).css('display', 'none');
    });
    
    $("#" + id).css('display', 'none');
    $(str).slideDown('1000');

    
}	

this.tooltip = function() { xOffset = 10; yOffset = 20; $(".tooltip").hover(function(e) { this.t = this.id; this.id = ""; $("body").append("<p id='tooltip'>" + this.t + "</p>"); $("#tooltip").css("top", (e.pageY - xOffset) + "px").css("left", (e.pageX + yOffset) + "px").fadeIn("fast"); }, function() { this.id = this.t; $("#tooltip").remove(); }); $(".tooltip").mousemove(function(e) { $("#tooltip").css("top", (e.pageY - xOffset) + "px").css("left", (e.pageX + yOffset) + "px"); }); }; $(document).ready(function() { tooltip(); });


function showPopup(url, title, height, width) {
    leftVal = (width - screen.width) / 2;
    topVal = (height - screen.height) / 2;
    window.open(url, "", "location=0,status=0,scrollbars=1,width=" + width + ",height=" + height + ",left=" + leftVal + ",top=" + topVal);
}

function preloadImages(arrImgs) { //v3.0
    try {
        for (i = 0; i < arrImgs.length; i++) {
            pic = new Image(100, 25);            
            pic.src = arrImgs[i];
        }
    } catch (err) { }
}



//-->
