VBNone = 0; VBCross = 1; VBQuest = 2; VBExclam = 3; VBInfo = 4;
VBok = 0; VBokCan = 1; VBabRetIg = 2; VBYesNoCan = 3; VBYesNo = 4;
VBRetCan = 5; VBDefBut1 = 0; VBDefBut2 = 1; VBDefBut3 = 2;

vbOK = 1; vbCancel = 2; vbAbort = 3; vbRetry = 4; vbIgnore = 5;
vbYes = 6; vbNo = 7;

var IE_Supported = false;

var AdvertsTimeOut;
var AdvertsCount=0;
var AdvertsHREF = new Array();
var AdvertsIMG = new Array();

if (navigator.userAgent.indexOf("MSIE")    != -1 && 
	navigator.userAgent.indexOf("Windows") != -1 && 
	navigator.appVersion.substring(0,1) > 3)
{
	IE_Supported = true;
}

function vbAlert(title,mess,icon,mods)
{
	if (IE_Supported) {
		makeMsgBox(title,mess,icon,VBok,VBDefBut1,mods); }
	else {
		altert(mess); }
}

function vbConfirm(title,mess,icon,defbut,mods)
{
	if (IE_Supported) {
		icon = (icon==0) ? 0 : 2;
		defbut = (defbut==0) ? 0 : 1;
		retVal = makeMsgBox(title,mess,icon,VBYesNo,defbut,mods);
		retVal = (retVal==6); }
	else {
		retVal = confirm(mess);	}

	return retVal;
}

function vbBox(title,mess,icon,buts,defbut,mods)
{
	if (IE_Supported) {
		retVal = makeMsgBox(title,mess,icon,buts,defbut,mods); }
	else {
		retVal = null; }

	return retVal;
}

function RTrim(str)
{
	if (str.length == 0) {
		str = ""; }
	else {
		while (str.substr(str.length-1)==" ") {
			str = str.substring(0,str.length-1); } }
	return str;
}

function LTrim(str)
{
	if (str.length == 0) {
		str = ""; }
	else {
		while (str.substr(0,1)==" ") {
			str = str.substring(1,str.length+1); } }
	return str;
}

function Trim(str)
{
	str = RTrim(str);
	str = LTrim(str);	
	return str;
}

function Left(str, num)
{
	str = str.substring(0,num);
	return str;
}

function Right(str, num)
{
	str = str.substring(str.length-num,str.length+1);
	return str;
}

function Len(str)
{
	return str.length;
}

function ErrMsg(str)
{	myInt = vbBox("Error Handler",str,VBCross,VBok,VBDefBut1,0); }

function isBlank(str)
{
	if (LTrim(str) == "") {
		return true; }
	else {
		return false; }
}

function isAlpha(str, chkType)
{
	var Tstr = Trim(str.value);
	Tstr = Tstr.toUpperCase();
	var Err = true;
	var TMsg = "";
	if (isBlank(Tstr) && (chkType == 0)) { }
	else {
		if (isBlank(Tstr)) {
			TMsg += "Empty Field. \n";
			Err = false; }
		for (var loop=0; loop < Tstr.length; loop++) {
			if ((Tstr.charAt(loop) < "A") || (Tstr.charAt(loop) > "Z")) {
				TMsg += "Character not an Alpha. \n";
				Err = false;
				break; } }
	}
	if (!Err) {
		TMsg += "Please try again!";
		ErrMsg(TMsg);
		str.focus(); }
	return Err;
}

function isAlphaNumeric(str, chkType)
{
	var Tstr = Trim(str.value);
	Tstr = Tstr.toUpperCase();
	var Err = true;
	var TMsg = "";
	if (isBlank(Tstr) && (chkType == 0)) { }
	else {
		if (isBlank(Tstr)) {
			TMsg += "Empty Field. \n";
			Err = false; }
		for (var loop=0; loop < Tstr.length; loop++) {
			if ((Tstr.charAt(loop) == " ") || (Tstr.charAt(loop) == ".")) { }
                        else {
				if (((Tstr.charAt(loop) < "A") || (Tstr.charAt(loop) > "Z")) &&
			    	    ((Tstr.charAt(loop) < "0") || (Tstr.charAt(loop) > "9"))) {
					TMsg += "Character not an AlphaNumeric. \n";
					Err = false;
					break; }
			}
		 }
	}
	if (!Err) {
		TMsg += "Please try again!";
		ErrMsg(TMsg);
		str.focus(); }
	return Err;
}

function isReal(str, chkType)
{
	var Tstr = Trim(str.value);
	var Err = true;
	var TMsg = "";
	if (isBlank(Tstr) && (chkType == 0)) { }
	else {
		if (isBlank(Tstr)) {
			TMsg += "Empty Field. \n";
			Err = false; }
		if (isNaN(Tstr)) {
			TMsg += "Field is not a Real Number. \n";
			Err = false; }
	}
	if (!Err) {
		TMsg += "Please try again!";
		ErrMsg(TMsg);
		str.focus(); }
	return Err;
}

function isInteger(str, chkType)
{
	var Tstr = Trim(str.value);
	var Err = true;
	var TMsg = "";
	if (isBlank(Tstr) && (chkType == 0)) { }
	else {
		if (isBlank(Tstr)) {
			TMsg += "Empty Field. \n";
			Err = false; }
		if ((Tstr.charAt(0) == "-") || (Tstr.charAt(0) == "+")) {
			Tstr = Tstr.substring(1,Tstr.length+1); }		
		for (var loop=0; loop < Tstr.length; loop++) {
			if ((Tstr.charAt(loop) < "0") || (Tstr.charAt(loop) > "9")) {
				TMsg += "Field is not an Integer. \n";
				Err = false;
				break; } }
	}
	if (!Err) {
		TMsg += "Please try again!";
		ErrMsg(TMsg);
		str.focus(); }
	return Err;
}

function isPCode(str, chkType)
{
	var Tstr = Trim(str.value);
	var Err = true;
	var TMsg = "";
	if (isBlank(Tstr) && (chkType == 0)) { }
	else {
		if (isBlank(Tstr)) {
			TMsg += "Empty Field. \n";
			Err = false; }
		if (Tstr.length != 4) {
			TMsg += "Post Code must be 4 digits in length. \n";
			Err = false; }
		for (var loop=0; loop < Tstr.length; loop++) {
			if ((Tstr.charAt(loop) < "0") || (Tstr.charAt(loop) > "9")) {
				TMsg += "Character not a digit. \n";
				Err = false;
				break; } }
	}
	if (!Err) {
		TMsg += "Please try again!";
		ErrMsg(TMsg);
		str.focus(); }
	return Err;
}

function Now()
{
	var aDate = new Date();
	var the_month = aDate.getMonth()+1;
	var the_day = aDate.getDate();
	var the_year = aDate.getYear();
	if (the_year < 1000) {
		the_year += 1900; }
	var the_date = the_day+"/"+the_month+"/"+the_year;
	return the_date;
}

function FormatDate(str)
{
	var Tstr = str;
	var aDate = new Date();
	var the_month = aDate.getMonth()+1;
	var the_day = aDate.getDate();
	var the_year = aDate.getYear();
	if (the_year < 1000) { the_year += 1900; }

	if (isBlank(str)) { Tstr = Now(); }
	var date_array = Tstr.split("/");

	switch (date_array.length) {
		case 1:
			Tstr += "/"+the_month+"/"+the_year;
		break;
		case 2:
			if (date_array[1] == "") { Tstr += the_month+"/"+the_year; }
			else { Tstr += "/"+the_year; }
		break;
		case 3:
			if (date_array[2] == "") { Tstr += the_year; }
			if (date_array[2].length == 1) { date_array[2] = "0"+date_array[2]; }
			
		break;
	}
	if (Tstr.indexOf("/") == 1) {Tstr = "0"+Tstr; }
	if (Tstr.lastIndexOf("/") == 4) {Tstr = Tstr.substring(0,3)+"0"+Tstr.substring(3,Tstr.length+1); }
	return Tstr;
}

function isDate(str, chkType)
{
	var Tstr = Trim(str.value);
	var Err = true;
	var TMsg = "";
	if (isBlank(Tstr) && (chkType == 0)) { }
	else {
		switch (chkType) {
			case 1:
				if (isBlank(Tstr)) {
				TMsg += "Empty Field. \n";
				Err = false; }
			break;
			case 2:
				if (isBlank(Tstr)) {
					str.value = Now();
					Tstr = str.value; }
				break;
		}
		Tstr = FormatDate(Tstr);
		if (str.value != Tstr) { str.value = Tstr; }
		var date_array = Tstr.split("/");
		if (date_array.length != 3) {
			TMsg += "Date format should be dd/mm/yyyy. \n";
			Err = false; }
		if ((date_array[0] < 0) || (date_array[0] > 31)) {
			TMsg += "Day must be in the range 1 - 31. \n";
			Err = false; }
		if ((date_array[1] < 0) || (date_array[1] > 12)) {
			TMsg += "Month must be in the range 1 - 12. \n";
			Err = false; }
		if ((date_array[2] < 1900) || (date_array[2] > 2019)) {
			TMsg += "Year must be greater than 1900 and less than 2020. \n";
			Err = false; }
	}
	if (!Err) {
		TMsg += "Please try again!";
		ErrMsg(TMsg);
		str.focus(); }
	return Err;
}

function isEmail(str, chkType)
{
	var Tstr = Trim(str.value);
	var Err = true;
	var TMsg = "";
	if (isBlank(Tstr) && (chkType == 0)) { }
	else {
		if (isBlank(Tstr)) {
			TMsg += "Empty Field. \n";
			Err = false; }
		invalidChars = "/;,:";
		for (var i=0; i < invalidChars.length; i++) {
			badChar = invalidChars.charAt(i);
			if (Tstr.indexOf(badChar,0) > -1) {
				TMsg += "Illegal character ["+badChar+"]. \n";
				Err = false; }
		}
		atPos = Tstr.indexOf("@",1);
		if (atPos == -1) {
			TMsg += "[@] missing in address. \n";
			Err = false; }
		if (Tstr.indexOf("@",atPos+1) != -1) {
			TMsg += "Only one [@] symbol allowed in address. \n";
			Err = false; }
		periodPos = Tstr.indexOf(".",atPos);
		if (periodPos == -1) {
			TMsg += "Must have at least one period [.] after the [@] symbol. \n";
			Err = false; }
		if (atPos+2 > periodPos) {
			TMsg += "Must have at least one character between the period [.] and [@] symbol. \n";
			Err = false; }
		if (periodPos+3 > Tstr.length) {
			TMsg += "Must have at least two characters after the period [.]. \n";
			Err = false; }
	}
	if (!Err) {
		TMsg += "Please try again!";
		ErrMsg(TMsg);
		str.focus(); }
	return Err;
}

function checkDate(objDate,aFlag) {
	if ((aFlag == false) && (objDate.value == "")) { return }
	var	strDate = objDate.value;
	var	date_array = strDate.split("/");
	var	sDay, sMonth, sYear;
	var	Err = false;
	if (date_array.length != 3) {
		alert("Date should be dd/mm/yyyy");
		Err = true; }
	else {
		sDay = date_array[0];
		sMonth = date_array[1] - 1;
		sYear = date_array[2];
		var	aDate = new Date(sYear,sMonth,sDay);
		
		aDate.setDate(sDay);
		if (sDay != aDate.getDate()) {
			alert("Invalid Day: dd ");
			Err = true; }
		else {
			sDay = "" + aDate.getDate();	
			if (sDay.length < 2) { sDay = "0" + sDay; }
		
			aDate.setMonth(sMonth);
			if (sMonth != aDate.getMonth()) {
				alert("Invalid Month: mm");
				Err = true; }
			else {
				sMonth = "" + (aDate.getMonth() + 1);
				if (sMonth.length < 2) { sMonth = "0" + sMonth; }

				aDate.setFullYear(sYear);
				if (sYear != aDate.getFullYear()) {
					alert("Invalid Year: yyyy");
					Err = true; }
			}
		}
	}
	if (Err == true) { objDate.focus(); }
	else { objDate.value = sDay+"/"+sMonth+"/"+sYear; }
}
function Y2K(No) { return (No < 1000) ? No + 1900 : No; }

function selectCol(n) {
	document.all["col"+n].style.cursor = "hand";
	if (currentCol != 0) {
		deSelectCol(currentCol); }
	if (currentSubMenu > 0) {
		if (currentRow > 0) { deSelectRow(currentSubMenu,currentRow); }
		hideSubMenu(currentSubMenu); currentSubMenu = 0; }
	if (currentSub2Menu  > 0) { hideSubMenu(currentSub2Menu); currentSub2Menu = 0; }
	currentRow = 0;
	currentRow2 = 0;
	SubMenuLvl = 0;
	document.all["col"+n].style.border = "inset"; 
	document.all["col"+n].style.borderWidth = "2px";
	currentCol = n;
}
function deSelectCol(n) {
	document.all["col"+n].style.border = "outset"; 
	document.all["col"+n].style.borderWidth = "2px";
}
function selectRow(m1,r1) {
	var strX = "row" + m1;
	strX += r1;
	document.all[strX].style.cursor = "hand";
	if (currentRow != 0) { deSelectRow(m1,currentRow); 
		if (currentCol > 0) {
			document.all["col"+currentCol].style.border = "inset"; 
			document.all["col"+currentCol].style.borderWidth = "2px"; } }
	document.all[strX].style.background = "#000000";
	document.all[strX].style.color = "#ffffff";
	currentRow = r1;
	showSubMenu(m1,SubMenuLvl);
}
function deSelectRow(m1,r1) {
	var strX = "row" + m1;
	strX += r1;
	document.all[strX].style.background = MenuBckColor;
	document.all[strX].style.color = MenuColor;
	hideSubMenu(m1);
	if (currentSub2Menu  > 0) { hideSubMenu(currentSub2Menu); currentSub2Menu = 0; }
	deSelectCol(currentCol); 
}
function selectRow2(m1,r1) {
	var strX = "row" + m1;
	strX += r1;
	document.all[strX].style.cursor = "hand";
	if (currentRow2 != 0) { deSelectRow2(m1,currentRow2); }
	document.all[strX].style.background = "#000000";
	document.all[strX].style.color = "#ffffff";
	currentRow2 = r1;
	showSubMenu(m1,SubMenuLvl);
}
function deSelectRow2(m1,r1) {
	var strX = "row" + m1;
	strX += r1;
	document.all[strX].style.background = MenuBckColor;
	document.all[strX].style.color = MenuColor;
	hideSubMenu(m1);
}
function selectPage(the_url) {
	if (the_url == "closeWin") { window.close();  }
	else { window.location = the_url; }
}
function InitMenu() {
	var str;
	document.writeln("<DIV id='MenuTop' STYLE='position:absolute; top:" + MenuOffsetY + ";  left:" + MenuOffsetX + "; visibility:visible;'>");
	document.writeln("<TABLE class=Menu  CELLSPACING='0' CELLPADDING='0' BORDER='0'>");
	document.writeln("<TR>");
	for (var loop = 0; loop < Menu00.length; loop++) {
		str = "<td id=col"+(loop+1)+" align='center' style='border-style:outset; border-width:2px;' onMouseOver='selectCol(" + (loop+1) + ");  ";
		if (Menu00[loop][1].charAt(0) == "#") {
			str += " showSubMenu(" + Menu00[loop][1].substring(1,Menu00[loop][1].length)  +",1); '"; }
		else { str += "' onClick=\"selectPage(\'" + Menu00[loop][1] + "\');\" onMouseOut='deSelectCol("+(loop+1)+");' " }
		str += ">&nbsp;&nbsp;"+Menu00[loop][0]+"&nbsp;&nbsp;</TD>";
		document.writeln(str); }
	document.writeln("<td width='100%'></td></TR>");
	document.writeln("</TABLE></DIV>");
	for (var loop = 0; loop < Menu00.length; loop++) {
		if (Menu00[loop][1].charAt(0) == "#") { InitSubMenu( loop,Menu00[loop][1].substring(1,Menu00[loop][1].length) ); } }
}
function InitSubMenu(No,aNo) {
	var SubMenu;
	var str = "Menu" + aNo;
	var strX = "row" + aNo;
	document.writeln("<DIV id=" + str + " STYLE='position:absolute; top:" +(Menu00[No][2] + MenuOffsetY) + "; left:" + (Menu00[No][3]+MenuOffsetX) + "; visibility:hidden;'>");
	document.writeln("<TABLE  CELLSPACING='0' CELLPADDING='0' BORDER='0'>");
	SubMenu = eval(str); 
	for (var x = 0; x < SubMenu.length; x++) {
		if (SubMenu[x][1].charAt(0) == "#") { 
			document.write("<tr id=" + strX + (x+1) + " class=Menu onMouseOver='selectRow("+aNo +"," + (x+1)+"); ");
			document.write("showSubMenu("+ SubMenu[x][1].substring(1,SubMenu[x][1].length) + ",2);' ");
			document.write(">"); }
		else { 
			document.write("<tr id=" + strX + (x+1) + " class=Menu onMouseOver='selectRow("+aNo +"," + (x+1)+");' ");
			document.write("onMouseOut='deSelectRow("+aNo+","+(x+1)+");' ");
			document.write("onClick=\"selectPage(\'" + SubMenu[x][1] + "\');\">"); }
		document.write("<td style='border-style:outset; border-width:1px;'>");
		document.write("&nbsp;<IMG SRC='../images/arrowleft3.gif' width='7' height='12'>");
		document.write("&nbsp;&nbsp;" + SubMenu[x][0] + "&nbsp;");
		if (SubMenu[x][1].charAt(0) == "#") { document.write("<IMG SRC='../images/dotbl.gif' width='5' height='5'>&nbsp;"); }
		else  { document.write("&nbsp;"); }
		document.write("</td></tr>");	}
	document.writeln("</TABLE></DIV>");
	for (var x = 0; x < SubMenu.length; x++) {
		if (SubMenu[x][1].charAt(0) == "#") { InitSub2Menu(x,SubMenu[x][1].substring(1,SubMenu[x][1].length)); } }
}
function InitSub2Menu(No,aNo) {
	var SubMenu;
	var str = "Menu" + aNo;
	var strX = "row" + aNo;
	SubMenu = eval(str); 
	document.writeln("<DIV id=" + str + " STYLE='position:absolute; top:" +(SubMenu[0][3] + MenuOffsetY) + "; left:" + (SubMenu[0][2] +MenuOffsetX) + "; visibility:hidden;'>");
	document.writeln("<TABLE  CELLSPACING='0' CELLPADDING='0' BORDER='0'>");
	for (var x = 0; x < SubMenu.length; x++) {
		document.write("<tr id=" + strX + (x+1) + " class=Menu onMouseOver='selectRow2("+aNo +"," + (x+1)+");' ");
		document.write("onMouseOut='deSelectRow2("+aNo+","+(x+1)+"); ' ");
		document.write("onClick=\"selectPage(\'" + SubMenu[x][1] + "\');\" "); 
		document.write("><td style='border-style:outset; border-width:1px;'>");
		document.write("&nbsp;<IMG SRC='../images/arrowleft3.gif' width='7' height='12'>");
		document.write("&nbsp;&nbsp;" + SubMenu[x][0] + "&nbsp;&nbsp;");
		document.write("</td></tr>");	}
	document.writeln("</TABLE></DIV>");
}
function showSubMenu(aNo,Lvl) {
	SubMenuLvl  = Lvl;
	var objMenu = eval("window.document.all.Menu"+aNo+".style");
	objMenu.visibility = "visible";
	if (SubMenuLvl == 1) { currentSubMenu = aNo; }
	if (SubMenuLvl == 2) { currentSub2Menu = aNo; }
}
function hideSubMenu(aNo) {
	var objMenu = eval("window.document.all.Menu"+aNo+".style");
	objMenu.visibility = "hidden";
}

function ShowAdverts() {
	AdvertsCount++;
	if (AdvertsCount >= AdvertsIMG.length) { AdvertsCount = 0; }	
	document.advertsIMG.src = AdvertsIMG[AdvertsCount].src;
	AdvertsTimeOut = setTimeout("ShowAdverts();",1800); } 
function CallAdverts() {
	clearTimeout(AdvertsTimeOut);
	window.location = AdvertsHREF[AdvertsCount]; } 
