﻿function pollresults(pollid) {
	var newwin = window.open("pollresults.asp?pollid=" + pollid, "pollresults", "width=800,height=600,location=0,menubar=0,personalbar=0,status=0,scrollbars=0,resizable=0,titlebar=0")
}
function removehref(id) {
	document.getElementById(id).href = ""
	//document.write('<a class="title red">RSS<img class="rss" src="graphics/feed-icon-16x16.gif" alt="RSS Feed" title="RSS Feed" /></a>')
}
function send2friend() {
	var newwin = window.open("send2friend.aspx?url=" + escape(document.location.href), "send2friend", "width=500,height=300,location=0,menubar=0,personalbar=0,status=0,scrollbars=0,resizable=0,titlebar=0")
}
function emailpage() {
	var emailpage = window.open("emailpage.asp?pageurl=" + escape(document.location.href), "emailpage", "width=400,height=400,locationbar=0,menubar=0,personalbar=0,status=0,scrollbars=0,resizable=0");
}
function validatesendfriendform() {
	if (sendfriendrequiredfield() && emailCheck(document.getElementById("yemail").value) && emailCheck(document.getElementById("remail").value)) {
		return true;
	}
	else {
		return false;
	}
}
function sendfriendrequiredfield() {
	var themessage = "You are required to complete the following fields:\n";
	if (document.getElementById("rname").value == "") {
		themessage = themessage + " - Recipient Name\n";
	}
	if (document.getElementById("remail").value == "") {
		themessage = themessage + " - Recipient Email\n";
	}
	if (document.getElementById("yname").value == "") {
		themessage = themessage + " - Your Name\n";
	}
	if (document.getElementById("yemail").value == "") {
		themessage = themessage + " - Your Email\n";
	}
	//alert if fields are empty and cancel form submit
	if (themessage == "You are required to complete the following fields:\n") {
		return true;
	}
	else {
		alert(themessage);
		return false;
	}
}
function bookmark() {
	title = document.title
	url = document.location.href
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url, "");
	}
	else if (window.external) { // IE Favorite
		window.external.AddFavorite(url, title);
	}
	else if (window.opera && window.print) { // Opera Hotlist
		return true;
	}
}
function checkNumber(e) {
	var keycode
	var numcheck

	if (window.event) // IE
	{
		keycode = e.keyCode
	}
	else if (e.which) // Netscape/Firefox/Opera
	{
		keycode = e.which
	}
	if (keycode >= 48 && keycode <= 57 || keycode >= 96 && keycode <= 105 || keycode == 8 || keycode == 46 || keycode >= 37 && keycode <= 40) {
		return true;
	}
	else {
		return false
	}
}

function emailCheck(emailStr) {

	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */
	var checkTLD = 1;

	/* The following is the list of known TLDs that an e-mail address must end with. */
	var knownDomsPat = /^(arpa|root|aero|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|travel|xxx)$/;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */
	var emailPat = /^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */
	var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/
	var validChars = "\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */
	var quotedUser = "(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */
	var atom = validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */
	var word = "(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user
	var userPat = new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */
	var domainPat = new RegExp("^" + atom + "(\\." + atom + ")*$");

	/* Finally, let's start trying to figure out if the supplied address is valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	var matchArray = emailStr.match(emailPat);
	if (matchArray == null) {

		/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user = matchArray[1];
	var domain = matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i = 0; i < user.length; i++) {
		if (user.charCodeAt(i) > 127) {
			alert("Ths username contains invalid characters.");
			return false;
		}
	}
	for (i = 0; i < domain.length; i++) {
		if (domain.charCodeAt(i) > 127) {
			alert("Ths domain name contains invalid characters.");
			return false;
		}
	}

	// See if "user" is valid 
	if (user.match(userPat) == null) {

		// user is not valid
		alert("The username doesn't seem to be valid.");
		return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */
	var IPArray = domain.match(ipDomainPat);
	if (IPArray != null) {

		// this is an IP address
		for (var i = 1; i <= 4; i++) {
			if (IPArray[i] > 255) {
				alert("Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}

	// Domain is symbolic name.  Check if it's valid.
	var atomPat = new RegExp("^" + atom + "$");
	var domArr = domain.split(".");
	var len = domArr.length;
	for (i = 0; i < len; i++) {
		if (domArr[i].search(atomPat) == -1) {
			alert("The domain name does not seem to be valid.");
			return false;
		}
	}

	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */
	if (checkTLD && domArr[domArr.length - 1].length != 2 &&
domArr[domArr.length - 1].search(knownDomsPat) == -1) {
		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}

	// Make sure there's a host name preceding the domain.
	if (len < 2) {
		alert("This address is missing a hostname!");
		return false;
	}
	// If we've gotten this far, everything's valid!
	return true;
}
function rollover(buttonid, image) {
	document.getElementById(buttonid).src = image
}
function clearfield(fieldid) {
	if (document.getElementById(fieldid).value == document.getElementById(fieldid).defaultValue) {
		document.getElementById(fieldid).value = ""
	}
}
function unclearfield(fieldid, email) {
	if (email) {
		if (document.getElementById(fieldid).value == "" || document.getElementById(fieldid).value == document.getElementById(fieldid).defaultValue) {
			document.getElementById(fieldid).value = document.getElementById(fieldid).defaultValue
		}
		else {
			emailCheck(document.getElementById(fieldid).value)
		}
	}
	else {
		if (document.getElementById(fieldid).value == "") {
			document.getElementById(fieldid).value = document.getElementById(fieldid).defaultValue
		}
	}
}
function regrequiredfield() {
	var themessage = "";
	if (document.getElementById("fname").value == "") {
		themessage = themessage + " - First Name";
	}
	if (document.getElementById("lname").value == "") {
		themessage = themessage + " - Last Name";
	}
	if (document.getElementById("usernamereg").value == "") {
		themessage = themessage + " -  Username";
	}
	if (document.getElementById("email").value == "") {
		themessage = themessage + " -  E-mail Address";
	}
	if (document.getElementById("passwordreg").value == "") {
		themessage = themessage + " -  Password";
	}
	if (document.getElementById("passwordreg2").value == "") {
		themessage = themessage + " -  Re-enter Password";
	}
	//alert if fields are empty and cancel form submit
	if (themessage == "") {
		return true;
	}
	else {
		alert("You are required to complete the following fields: " + themessage);
		return false;
	}
}
function lengthcheck(fieldlabel, usernamefield, usermin, usermax) {
	username = document.getElementById(usernamefield).value
	if (username.length >= usermin && username.length <= usermax) {
		return true;
	}
	else {
		alert(fieldlabel + " must be " + usermin + "-" + usermax + " characters long.")
		return false;
	}
}
function fieldmatch(fieldlabel, field1, field2) {
	field1 = document.getElementById(field1).value
	field2 = document.getElementById(field2).value
	if (field1 == field2) {
		return true;
	}
	else {
		alert(fieldlabel + " fields must be identical.")
		return false;
	}
}
function validateregform(action, form) {
	if (regrequiredfield() && emailCheck(document.getElementById('email').value) && lengthcheck("Username", "usernamereg", 8, 20) && lengthcheck("Password", "passwordreg", 8, 20) && fieldmatch("Password", "passwordreg", "passwordreg2")) {
		document.getElementById(form).action = action
		document.getElementById(form).submit()
	}
	else {
		return false;
	}
}
function validateeditform(action, form) {
	if (editrequiredfield() && emailCheck(document.getElementById('email').value) && lengthcheck("Username", "username", 8, 20)) {
		document.getElementById(form).action = action
		document.getElementById(form).submit()
	}
	else {
		return false;
	}
}
function editrequiredfield() {
	var themessage = "You are required to complete the following fields: ";
	if (document.getElementById("fname").value == "") {
		themessage = themessage + " - First Name";
	}
	if (document.getElementById("lname").value == "") {
		themessage = themessage + " - Last Name";
	}
	if (document.getElementById("username").value == "") {
		themessage = themessage + " -  User Name";
	}
	if (document.getElementById("email").value == "") {
		themessage = themessage + " -  E-mail Address";
	}
	//alert if fields are empty and cancel form submit
	if (themessage == "You are required to complete the following fields: ") {
		return true;
	}
	else {
		alert(themessage);
		return false;
	}
}
function send2friendrequiredfield() {
	var themessage = "You are required to complete the following fields: ";
	if (document.getElementById("friendsname").value == "") {
		themessage = themessage + " - Friend's Name";
	}
	if (document.getElementById("friendsemail").value == "") {
		themessage = themessage + " - Friend's Email";
	}
	if (document.getElementById("myname").value == "") {
		themessage = themessage + " - Your Name";
	}
	if (document.getElementById("myemail").value == "") {
		themessage = themessage + " - Your Email";
	}
	//alert if fields are empty and cancel form submit
	if (themessage == "You are required to complete the following fields: ") {
		return true;
	}
	else {
		alert(themessage);
		return false;
	}
}
function validatesend2friendform() {
	if (send2friendrequiredfield() && emailCheck(document.getElementById('friendsemail').value) && emailCheck(document.getElementById('myemail').value)) {
		return true;
	}
	else {
		return false;
	}
}

function validatecontactform() {
	if (contactrequiredfield() && emailCheck(document.getElementById('email').value)) {
		return true;
	}
	else {
		return false;
	}
}

function contactrequiredfield() {
	var themessage = "You are required to complete the following fields:\n";
	if (document.getElementById("name").value == "") {
		themessage = themessage + " - Your name\n";
	}
	if (document.getElementById("email").value == "") {
		themessage = themessage + " - Your e-mail address\n";
	}
	if (document.getElementById("comments").value == "") {
		themessage = themessage + " - Your comments\n";
	}
	//alert if fields are empty and cancel form submit
	if (themessage == "You are required to complete the following fields:\n") {
		return true;
	}
	else {
		alert(themessage);
		return false;
	}
}

function validatecasestudyform(casestudy) {
	if (casestudyrequiredfield(casestudy) && emailCheck(document.getElementById("email" + casestudy).value)) {
		return true;
	}
	else {
		return false;
	}
}

function casestudyrequiredfield(casestudy) {
	var themessage = "You are required to complete the following fields:\n";
	if (document.getElementById("name" + casestudy).value == "") {
		themessage = themessage + " - Your name\n";
	}
	if (document.getElementById("email" + casestudy).value == "") {
		themessage = themessage + " - Your e-mail address\n";
	}
	//alert if fields are empty and cancel form submit
	if (themessage == "You are required to complete the following fields:\n") {
		return true;
	}
	else {
		alert(themessage);
		return false;
	}
}


function setCookie(c_name, value, expiredays) {
	var exdate = new Date()
	exdate.setDate(exdate.getDate() + expiredays)
	document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
}
function getCookie(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=")
		if (c_start != -1) {
			c_start = c_start + c_name.length + 1
			c_end = document.cookie.indexOf(";", c_start)
			if (c_end == -1) c_end = document.cookie.length
			{
				return unescape(document.cookie.substring(c_start, c_end))
			}
		}
	}
	return ""
}

function externalLinks() {
	if (!document.getElementsByTagName) {
		return;
	}
	var anchors = document.getElementsByTagName("a");
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
			anchor.title = (anchor.title != "") ? anchor.title + " (opens in a new window)" : "opens in a new window";
			anchor.className = (anchor.className != '') ? anchor.className + ' external' : 'external';
		}
	}
}
function init() {
	navbar2("topmenuitem");
	externalLinks();
	v = document.getElementsByTagName("h1")
	if (v.length > 0) {
		for (i = 0; i < v.length; i++) {
			//v[i].style.height="30px"
		}
	}
	x = document.getElementsByTagName("body")
	if (x.length > 0) {
		y = getElementsByClassName(x[0], "div", "comptitle")
		if (y.length > 0) {
			for (i = 0; i < y.length; i++) {
				y[i].style.height = "23px"
			}
		}
	}
	pagecustom();
}

function openform(casestudy) {
	body = document.getElementsByTagName("body")
	if (body != null) {
		x = getElementsByClassName(body[0], "form", "caseform")
		if (x.length > 0) {
			for (i = 0; i < x.length; i++) {
				if (x[i].id == "caseform" + casestudy) {
					if (x[i].style.display == "block") {
						x[i].style.display = "none"
					}
					else {
						x[i].style.display = "block"
					}
				}
				else {
					x[i].style.display = "none"
				}
			}
			/*y=document.getElementById("caseform" + casestudy)
			if (y!=null)
			{
			if (y.style.display=="block")
			{
			y.style.display="none"
			}
			else
			{
			y.style.display="block"
			}
			}*/
		}
	}
}

function getElementsByClassName(oElm, strTagName, strClassName) {
	var arrElements = (strTagName == "*" && oElm.all) ? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for (var i = 0; i < arrElements.length; i++) {
		oElement = arrElements[i];
		if (oRegExp.test(oElement.className)) {
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}
//////////////////////////////////////
//          IE6 dropdown            //
//////////////////////////////////////
function navbar2(id) {
	if (document.all && document.getElementById) {
		navRoot = document.getElementById(id);
		if (navRoot != null) {
			for (i = 0; i < navRoot.getElementsByTagName("LI").length; i++) {
				node = navRoot.getElementsByTagName("LI")[i];
				if (node.nodeName == "LI") {
					node.onmouseover = function() {
						if (this.className == "") {
							this.className = "over";
						}
						else {
							this.className = " over";
						}
					}
					node.onmouseout = function() {
						if (this.className == "over") {
							this.className = "";
						}
					}
				}
			}
		}
	}
}
function changetab(tabscontainerid, current, content) {
	tabscontainer = document.getElementById(tabscontainerid);
	tabslist = getElementsByClassName(tabscontainer, "ol", "tabs")
	if (tabslist.length > 0) {
		tabs = tabslist[0].getElementsByTagName("li")
		if (tabs.length > 0) {
			for (i = 0; i < tabs.length; i++) {
				tabs[i].className = ""
			}
			current.className = "current"
			tabscontent = getElementsByClassName(tabscontainer, "*", "tabcontent")
			if (tabscontent.length > 0) {
				for (j = 0; j < tabscontent.length; j++) {
					tabscontent[j].className = tabscontent[j].className.replace(/ current/g, "")
				}
				tabscurrentcontent = getElementsByClassName(tabscontainer, "*", content)
				if (tabscurrentcontent.length > 0) {
					for (k = 0; k < tabscurrentcontent.length; k++) {
						tabscurrentcontent[k].className = tabscurrentcontent[k].className + " current"
					}
				}
			}
		}
	}
}

function copyaddress() {
	x = document.getElementById("ctl00_contentplaceholder_sameasbillingx");
	if (x != null) {
		xaddone = document.getElementById("ctl00_contentplaceholder_tbxShippingAddrLine1")
		xaddtwo = document.getElementById("ctl00_contentplaceholder_tbxShippingAddrLine2")
		xcity = document.getElementById("ctl00_contentplaceholder_tbxShippingCity")
		xstate = document.getElementById("ctl00_contentplaceholder_tbxShippingState")
		xpc = document.getElementById("ctl00_contentplaceholder_tbxShippingPostCode")
		xcountry = document.getElementById("ctl00_contentplaceholder_dpdShippingCountryList")
		if (xaddone != null && xaddtwo != null && xcity != null && xstate != null && xpc != null && xcountry != null) {
			if (x.checked) {
				xaddone.value = document.getElementById("ctl00_contentplaceholder_tbxHBillingAddrLine1").value
				xaddtwo.value = document.getElementById("ctl00_contentplaceholder_tbxHBillingAddrLine2").value
				xcity.value = document.getElementById("ctl00_contentplaceholder_tbxHBillingCity").value
				xstate.value = document.getElementById("ctl00_contentplaceholder_tbxHBillingState").value
				xpc.value = document.getElementById("ctl00_contentplaceholder_tbxHBillingPostCode").value
				xbillcountry = document.getElementById("ctl00_contentplaceholder_tbxHBillingCountry")
				if (xbillcountry != null) {
					for (i = 0; i < xcountry.length; i++) {
						if (xcountry.options[i].value == xbillcountry.value) {
							xcountry.options[i].selected = true;
						}
					}
				}
			}
			else {
				xaddone.value = ""
				xaddtwo.value = ""
				xcity.value = ""
				xstate.value = ""
				xpc.value = ""
				xcountry.selectedIndex = 0
			}
		}
	}
}