// --------------------------------------------------------------------------
// Copyright © 1999-2008 KB Group (UK) Ltd.  All Rights Reserved.
// www.kbgroupuk.com
// --------------------------------------------------------------------------
// Amendments:
//
//  Date		By	Description
//  ----		--	---------------------------------------------------------
//  15/11/06	SK	Deployed updated keypress detection routines
//  14/09/04	SK	Added resize parameter to launchCenter
//  17/03/04	SK	Modified error message for IsValidText
//  13/11/03	SK	Added checkOKslash2 for address validation
//  02/06/03	SK	Added version control
// --------------------------------------------------------------------------

var checkOKletters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ'- \t\r\n\f";
var checkOKnumbers = "1234567890"
var checkOKspace = " "
var checkOKslash = "/"
var checkOKdecimal = "."
var checkOKcomma = ","
var checkOKslash2 = "\\"

// --------------------------------------------------------------------------
function NumericOnly(e) { 

	if (!e)
		e = window.event;

	var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
	// backspace = 8, delete = 46,<- = 37, -> = 39, 9 = tab
	if ((keyCode < 48 || keyCode > 57) && keyCode != 8 && keyCode != 46 && keyCode != 37 && keyCode != 39 && keyCode != 9) { 
		if (document.all)
			keyCode = 0;
		return false;
	}
	return true;
}

// --------------------------------------------------------------------------
function NumericSpOnly(e) { 

	if (!e)
		e = window.event;

	var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
	
	if ((keyCode < 48 || keyCode > 57) && keyCode != 32 && keyCode != 8 && keyCode != 46 && keyCode != 37 && keyCode != 39 && keyCode != 9) { 
		if (document.all)
			keyCode = 0;
		return false;
	}
	return true;
}

// --------------------------------------------------------------------------
function CreditCardDate(e) { 

	if (!e)
		e = window.event;

	var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
	// backspace = 8, delete = 46,<- = 37, -> = 39, 47 = /
	if ((keyCode < 48 || keyCode > 57) && keyCode != 47 && keyCode != 8 && keyCode != 46 && keyCode != 37 && keyCode != 39 && keyCode != 9) { 
		if(document.all)
			keyCode = 0;
		return false;
	}
	return true;
}

// -------------------------------------------------------------------------
function IsValidText(theField, sName, checkOK, iMinLen, iMaxLen) {

if (iMinLen > 0) {
	if (theField.value == "") {
		alert("Please enter a value for the " + sName + " field.");
		return (false);
	}

	if (theField.value.length < iMinLen) {
		alert("Please enter at least " + iMinLen + " characters in the " + sName + " field.");
		return false;
	}
}

if (theField.value.length > iMaxLen) {
	alert("Please enter no more than " + iMaxLen + " characters in the " + sName + " field.");
	theField.focus();
	return false;
}

var checkStr = theField.value;
var allValid = true;

for (i = 0; i < checkStr.length; i++) {
	ch = checkStr.charAt(i);
	for (j = 0; j < checkOK.length; j++)
	if (ch == checkOK.charAt(j))
		break;
	if (j == checkOK.length) {
		allValid = false;
		break;
	}
}

if (!allValid) {
	// The error message is dependent on the valid input types
	if (checkOK.length == 10) {
		alert("Please enter only numbers in the " + sName + " field.");
	}
	else
		if (checkOK.length == 11) {
			if (checkOK.charAt(10) == "/") 	{
				alert("Please enter only numbers and a slash in the " + sName + " field.");
			}
			else {
				alert("Please enter only numbers or spaces in the " + sName + " field.");
			}
		}
		else {
			alert("Please enter only letters, numbers or spaces in the " + sName + " field.");
		}
	theField.focus();
	return false;
}

return true;

}

// -------------------------------------------------------------------------
function isEmail(email) {

var str = email.value;

if (window.RegExp) {
	// Create 2 variables containing the strings we want our 
	// regular expression objects to contain
	var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
	var reg2str = "^[a-zA-Z0-9\\-\\_\\.]+\\@[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})$";

	// Create 2 more variables. Tell Javascript to create 2 new RegExp
	// objects, the first constructed using the reg1str variables' 
	// contents, the second will contain the same string as reg2str.
	// Then assign the outcome of these new object creation processes
	// to the variables reg1 and reg2 so that we have some way of
	// referencing or using these freshly created regular expression objects
	var reg1 = new RegExp(reg1str);
	var reg2 = new RegExp(reg2str);

	// Use the RegExp objects 'test' method to test whether str contains
	// what we have specified it SHOULD contain (reg2.test(str)) and to
	// ensure it doesn't contain the items in reg1 (!reg1.test(str)).
	if (!reg1.test(str) && reg2.test(str))
		return true;
	else
		return false;
}

// If the user's browser doesn't support the RegExp object we need an 
// alternative method to test their email entry
else {

	// minimal valid form: a@b.cd
	var invalidChars = " /;,:#!$^&*()+";
	for (var i=0; i< invalidChars.length; i++) {
		var badChar = invalidChars.charAt(i);
		if (str.indexOf(badChar,0) > -1) {
			return false;
		}
	}

	var atPos = str.indexOf("@",1)
	// There must be one "@" symbol
	if (atPos == -1) {
		return false;
	}
		
	if (str.indexOf("@", atPos+1) != -1) {
		// and only one "@" symbol
		return false;
	}
		
	var periodPos = str.indexOf(".",atPos)
	if(periodPos == -1) {
		// And at least one "." after the "@"
		return false;
	}

	if (atPos +2 > periodPos) {
		// And at least one character between "@" and "."
		return false;
	}

	if (periodPos +3 > str.length) {
		// There should also be at least 2 characters after the "."
		return false;
	}
	return true;
}
}

// --------------------------------------------------------------------------
function fnClickReturn() {

var bAgent = window.navigator.userAgent; 
var bAppName = window.navigator.appName;

if ((bAppName.indexOf("Explorer") >= 0) && (bAgent.indexOf("Mozilla/3") >= 0) && (bAgent.indexOf("Mac") >= 0))
	return true; 	// follow link
else
	return false; 	// do not follow link
}

// --------------------------------------------------------------------------
function fnNewWin(sURL, sWidth, sHeight) {

var oNewWin = open(sURL,'', 'width='+sWidth+', height='+sHeight+', toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, screenX=500, screenY=200');

}

// --------------------------------------------------------------------------
function launchCenter(url, name, height, width, vscroll, resize) {

var str = "height=" + height + ",innerHeight=" + height;
str += ",width=" + width + ",innerWidth=" + width;

if (window.screen) {
	var ah = screen.availHeight - 30;
	var aw = screen.availWidth - 10;
	var xc = (aw - width) / 2;
	var yc = (ah - height) / 2;

	str += ",left=" + xc + ",screenX=" + xc;
	str += ",top=" + yc + ",screenY=" + yc;
	str += ",scrollbars=" + vscroll;
	str += ",resizable=" + resize;
}

return window.open(url, name, str);

}

// --------------------------------------------------------------------------
function clickback() {
// Detect the browser because the back command is different for the different browsers

var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
var NS4 = (bName == "Netscape" && bVer >= 4);
var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);

if (NS4) { 
	// load browser specific code to go back
	history.go(-1);
} 
else { 
	// Internet Explorer 4.0+
	history.back();
}
}

// --------------------------------------------------------------------------
function changeImages() {
// Change the mouseover image

if (document.images) {
	for (var i=0; i<changeImages.arguments.length; i+=2) {
		document[changeImages.arguments[i]].src = eval(changeImages.arguments[i+1] + ".src");
	}
}
}
