//alert("Loading Global Code")
/* ********************** cookie monster library ***************************
functions for cookies originally taken from 'JavaScript & DHTML Cookbook" - p16, O'Reilly Press. 
uploaded 2/10/2005 TJS */

function Init() {
	(document.getElementById('PCounter') != null) ? document.getElementById('PCounter').style.display = 'none' : "";
	MM_preloadImages('/Images/PNG/ContactOn.gif','/Images/PNG/NewsOn.gif','/Images/PNG/CaseOn.gif','/Images/PNG/FundingOn.gif','/Images/PNG/CommunityOn.gif','/Images/PNG/SM1_WhoAreWeOn.gif','/Images/PNG/SM1_OurVisionOn.gif','/Images/addtofavorites_on.gif','../Home/Images/menus/Favorites_on.gif','/Images/WWW_on.gif','/Images/Phone_on.gif','/Images/Email_on.gif','/Images/Welcome_on.gif','/Images/Eventing_on.gif','/Images/Services_on.gif','/Images/Facilities_on.gif','/Images/TheTeam_on.gif','/Images/Training_on.gif','/Images/Gallery_on.gif','/Images/NewsViews_on.gif','/Images/Location_on.gif','/Images/Links_on.gif','/Images/ContactUs_on.gif','/Images/Welcome_on.gif','/Images/Eventing_on.gif','/Images/Services_on.gif','/Images/Facilities_on.gif','/Images/TheTeam_on.gif','/Images/Training_on.gif','/Images/Gallery_on.gif','/Images/NewsViews_on.gif','/Images/Location_on.gif','/Images/Links_on.gif','/Images/ContactUs_on.gif','/Images/HorseLegs2.gif','/Images/WWW_on.gif','/Images/Phone_on.gif','/Images/Email_on.gif')
}

window.onload = Init;

/* utility function to retrieve an expiration date in proper format; pass three integer parameters for days, hours and minutes from now that you want the cookie to expire (use -ve value for a past date); all three parameters are required, so use zeros where appropriate */
function getExpDate(days, hours, minutes) {
	var expDate = new Date();
	if (typeof days == "number" && typeof hours == "number" && typeof minutes == "number") {
	    expDate.setDate(expDate.getDate() + parseInt(days)); 
		expDate.setHours(expDate.getHours() + parseInt(hours));
		expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
		return expDate.toGMTString();
	}
}

// utility function called by getCookie();
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

// primary function to retrieve cookie by name
function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i,j) == arg) {
			return getCookieVal(j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i ==0) break;
	}
	return "";
}

// store cookie value with optional details as needed
function setCookie(name, value, expires, path, domain, secure) {
		document.cookie = name + "=" + escape (value) +
			((expires) ? "; expires=" + expires : "") +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			((secure) ? "; secure" : ""); 
}

// remove the cookie by setting an old expiration date
function deleteCookie(name, path,domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "");
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}


function MM_preloadImages() { //v3.0
    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 MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
    }




    //---------------------------|    START: Email Address Validation    |------------------------------------------------------------------//
    

    function check_email(e) {
        ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

        for (i = 0; i < e.length; i++) {
            if (ok.indexOf(e.charAt(i)) < 0) {
                return (false);
            }
        }

        if (document.images) {
            re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
            re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
            if (!e.match(re) && e.match(re_two)) {
                return (-1);
            }

        }

    }


    function check_form(f) { // f is the form (passed using the this keyword)
        alert('start')
        if (f.name.value.length < 1) {
            alert("You entered less than one character in the name field.");
            f.name.focus(); // put the prompt in the name field 
            // if the browser is Netscape 6 or IE
            if (document.all || document.getElementByID) {
                // change the color of text field
                f.name.style.background = "yellow";
            }
            // make sure the form is not submitted
            return false;
        }

        // check the first email address ( the exclamation means "not" )
        if (!check_email(f.email.value)) {
            alert("Invalid email detected.");
            f.email.focus();
            // if the browser is Netscape 6 or IE
            if (document.all || document.getElementByID) {
                // change the color of text field
                f.email.style.background = "yellow";
            }
            // make sure the form is not submitted
            return false;
        }

        // check the second email address
        if (!check_email(f.another_email.value)) {
            alert("Invalid email detected.");
            f.another_email.focus();
            if (document.all || document.getElementByID) {
                f.another_email.style.background = "yellow";
            }
            return false;
        }
    }



    //---------------------------|    FINISH: Email Address Validation    |------------------------------------------------------------------//

    
    if (typeof document.getElementById("ctl00_CPH_txtMailFrom") == 'object'){

        var mailFrom = document.getElementById("ctl00_CPH_txtMailFrom");
        if (mailFrom != 'undefined' && mailFrom != null)
            mailFrom.onchange = check_form;
    }



