var isDHTML = 0;
var isID = 0;
var isAll = 0;
var isLayers = 0;
var isIE = 0;
var content;
var temp;

if (navigator.appName.indexOf('Microsoft Internet Explorer') != -1) {isIE = 1;}

if (document.getElementById) {
	isID = 1; 
	isDHTML = 1;
} else {
	if (document.all) {
		isAll = 1; 
		isDHTML = 1;
	} else {
		browserVersion = parseInt(navigator.appVersion);
		if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {
			isLayers = 1; 
			isDHTML = 1;
		}
	}
} 

function click(e) {
	var warn = 'Sorry, you do not have permission to right-click';
	if (document.all) {
		if (event.button == 2) {
			alert(warn);
			return false;
		}
	}
	if (document.layers) {
		if (e.which == 3) {
			alert(warn);
			return false;
		}
	}
	if (document.layers) {
		document.captureEvents(Event.MOUSEDOWN);
	}
}

document.onmousedown = click;

function findDOM(objectID,withStyle) {
//alert('Z'+objectID);
	if (withStyle == 1) {
		if (isID) {
			return (document.getElementById(objectID).style); 
		} else { 
			if (isAll) { 
				return (document.all[objectID].style); 
			} else {
				if (isLayers) { 
					return (document.layers[objectID]); 
				}
			};
		}
	} else {
		if (isID) { 
			return (document.getElementById(objectID)) ; 
		} else { 
			if (isAll) { 
				return (document.all[objectID]); 
			} else {
				if (isLayers) { 
					return (document.layers[objectID]); 
				}
			};
		}
	}
}

function scrollPageTo(x,y) {
	if (isIE) {
		document.body.scrollLeft = x;
		document.body.scrollTop = y;
		return;
	} else {
		scrollTo(x,y);
		return;
	}
}

var tintArray = new Array('#dddddd','#ccccff','#ffffff','#ff0000','#0000ff','#fab0b0','#cccccc','#000000','transparent')
//0 pale grey, 1 pale blue, 2 white, 3 red, 4 blue, 5 pale red, 6 grey, 7 black, 8 transparent)

function setBackgrd(objectID, tint) {
	var dom = findDOM(objectID,1);
	dom.background = tintArray[tint];
}

function setColor(objectID, tint) {
	var dom = findDOM(objectID,1);
	dom.color = tintArray[tint];
}

function showVisibility(objectID) {
//alert('S '+objectID);
	var dom = findDOM(objectID,1);
	dom.visibility = 'visible';
}

function hideVisibility(objectID) {
//alert('H '+objectID);
	var dom = findDOM(objectID,1);
	dom.visibility = 'hidden';
}

function isVisible(objectID) {
	var dom = findDOM(objectID,1);
	if ((dom.visibility == 'show') || (dom.visibility == 'visible')) { return true; }
	return false;
}

//type 0 - value in px, 1 - value in %
function setTop(objectID, amt, type) {
//alert('T '+objectID);
	var dom = findDOM(objectID,1);
	if (type == 0) {
		dom.top = amt + 'px';
	} else {
		dom.top = amt + '%';
	}	
}

function setLeft(objectID, amt, type) {
	var dom = findDOM(objectID,1);
	if (type == 0) {
		dom.left = amt + 'px';
	} else {
		dom.left = amt + '%';
	}
}

function setWidth(objectID, amt, type) {
	var dom = findDOM(objectID,1);
	if (type == 0) {
		dom.width = amt + 'px';
	} else {
		dom.width = amt + '%';
	}
}

function setHeight(objectID, amt) {
	var dom = findDOM(objectID,1);
	dom.height = amt + 'px';
}

var newWindow;
function reqDemo() {
	newWindow = window.open("requestDemo.htm", "", "width=560,height=440");
}

function reqCat() {
	newWindow = window.open("requestCat.htm", "", "width=560,height=365");
}

function init() {
	writeCtr();
	writeHdr();
	instruction();
	writeLink();
	writeIcons();
	if (scrnSize == 'B') {
		setBParams();
	}
}

var screenHeight = screen.height;
var scrnSize;

if (screenHeight > 700) { 
	scrnSize = 'A';
} else {
	scrnSize = 'B';
}

var destinationArray = new Array('index','contact','Directional%20Map','mailList','siteMap','printOverview',
'printHSeries','printVSeries','printApollo','printDatamax','printDataMCL','printLabMast','printStandAlone',
'printConnection','printOptions','el5','elSpecial','elAdvanced','elChoose','appRTL','appOverview','appApply',
'appTopBottom','appPrt&Apply','applLab','appOptions','appQuote','custOverview','custMultiple','custUnusual',
'bcVerifier','bcChecker','bcReaders','dataColl','RFID','gs1uk','labQuote','catalog','servCustomer','labelling%20news',
'specOffer','http://www.gs1uk.org/','group','http://www.ctg-web.co.uk/employment');

var nameArray = new Array('Home Page','Contact Us','How to Find Us','Sign up for Newsletter','Site Map','Label Printers Overview',
'H Series','V Series','CAB Apollo Printers','Datamax Printers','Datamax and MCL','Label Master Colour Printer',
'Stand-alone Label Printing','Network &amp; Main Frame','Printer Options','Easylabel 5 Overview','Easylabel Special Features',
'Easylabel Advanced Features','Choose the Package','Real-time Print Applicator','Applicator Overview','Apply-only Applicators',
'Top and Bottom Labelling','Print and Apply','Examples of Applied Labels','Applicator Options','Request Applicator Quote',
'Custom Applicator Overview','Multiple Labellers','Unusual Applicator Examples','Barcode Verifiers','Barcode Checkers',
'Barcode Readers','Data Collection','RFID Update','Accreditation and Award','Labels and Ribbons','View Catalogue',
'Customer Service and Tech Suppport','Newsletter','Special Offers','Barcode Standards Information','Group Companies',
'Group Employment Opportunities');

function writeLink() {
	content = '<DIV ID="linkTable">';
	for (var index = 0; index < destinationArray.length; index++) {
		if (index == 2 || index == 39) {
			content += '<A CLASS="navLink" HREF="' + destinationArray[index] + '.pdf">' + nameArray[index] + '</A> | ';
		} else if (index == 41) {
			content += '<A CLASS="navLink" HREF="' + destinationArray[index] + '">' + nameArray[index] + '</A> | ';
		} else if (index == destinationArray.length - 1) {
			content += '<A CLASS="navLink" HREF="' + destinationArray[index] + '.htm">' + nameArray[index] + '</A></DIV>';
		} else if (index == 7 || index == 12 || index == 17 || index == 22 || index == 27 || index == 33 || index == 38) {
			content += '<A CLASS="navLink" HREF="' + destinationArray[index] + '.htm">' + nameArray[index] + '</A><BR>';
		} else {
			content += '<A CLASS="navLink" HREF="' + destinationArray[index] + '.htm">' + nameArray[index] + '</A> | ';
		}
	}
//alert('writeLink '+content);
	document.write(content);
	if (scrnSize == 'B') {
		setLeft('linkTable','4',1); // final argument 0 - px, 
		setLeft('madeUK','83',1); // 1 - % (not used for setHeight)
		setTop('madeUK','-95',0);
		setLeft('estb','83',1);
	}
} 

// ctrArray[0] - name, [1] - pic width A, [2] - pic height A, [3] - pic1 link, [4] - pic1 src, [5] - alt text, [6] - page title,
// [optional beyond here] [7] - pic2 width A, [8] - pic2 height A, [9] - pic2 link, [10] - pic2 src, [11] - alt text2,
// [12] - pic3 width A, [13] - pic3 height A, [14] - pic3 link, [15] - pic3 src, [16] - alt text3,
// [17] - pic4 width A, [18] - pic4 height A, [19] - pic4 link [20] - pic4 src, [21] - alt text4 
// [22] - pic5 width A, [23] - pic5 height A, [24] - pic5 link [25] - pic5 src, [26] - alt text5 

function writeCtr() { // ie. write Centre block
	var repeat = (ctrArray.length - 7) / 5;
	content = '<DIV ID="' + ctrArray[0] + 'Border' + scrnSize + '">';
	if (ctrArray[0] != 'index') {
		content += '<SPAN ID="' + ctrArray[0] + 'TitleBorder' + scrnSize + '"></SPAN>';
		content += '<SPAN ID="' + ctrArray[0] + 'Title' + scrnSize + '">' + ctrArray[6] + '</SPAN>';
		if (ctrArray[0] == 'verifier') {
			content += '<SPAN ID="healthCheck' + scrnSize + '"><SPAN ID="checkTitle">FREE barcode health check&nbsp;&nbsp;</SPAN>We can come to you and examine your barcodes using the leading barcode ';
			content += 'verifying equipment to check that your barcodes meet the standards required by the major retailers and GS1 UK.  This FREE barcode health check service ';
			content += 'even includes a free printed report for you to keep.<BR><BR>This free health check is limited to mainland UK registered companies supplying product for resale by ';
			content += 'the major retailers. Only one health check visit per company. Charges may be made for other companies. Please ask for details</SPAN>';
			content += '<SPAN ID="axiconLogo' + scrnSize + '"><IMG SRC="picsN/AxiconLogo.jpg" ALT="Axicon Logo" WIDTH="175" HEIGHT="60" BORDER="0"></SPAN>';
		}
	}
	var start, picNo;
	for (var iR = 0; iR <= repeat; iR++) {
		if (iR == 0) { 
			start = 1; 
			picNo = '';
		} else {
			start = 5 * iR + 2;
			picNo = iR + 1;
		}
		content += '<SPAN ID="' + ctrArray[0] + 'Pic' + picNo + scrnSize + '">';
		tempWid = parseInt(ctrArray[start]);
		tempHt = parseInt(ctrArray[start + 1]);
		if (scrnSize == 'B') {
			tempWid = parseInt(tempWid * .78125 + .5);
			tempHt = parseInt(tempHt * .78125 + .5);
		} 
		if (ctrArray[start + 2] != '-') {
			content += '<A HREF="';
			if (ctrArray[0] == 'group') {
				content += 'http://www.ctg-web.co.uk/';
			}
			if (ctrArray[start + 2].substr(0,1) == '*') {
				content += ctrArray[start + 2].substr(1) + '">';
			} else { 
				content += ctrArray[start + 2] + '.htm">';
			}
		}
		content += '<IMG SRC="picsN/' + ctrArray[start + 3] + '.jpg" WIDTH="';
		content += tempWid + '" HEIGHT="' + tempHt + '" ALT="';
		if ((ctrArray[0] != 'elChoose') && (ctrArray[0] != 'elSpecial') && (ctrArray[0] != 'elAdvanced')) {


 		
			content += ctrArray[start + 4];
		}
		content += '" BORDER="0">';
		if (ctrArray[start + 2] != '-') {
			content += '</A>';
		}
		content += '</SPAN>';
		if (ctrArray[0] != 'group') {
			content += '<SPAN ID="' + ctrArray[0] + 'Txt' + picNo + scrnSize + '">' + ctrArray[start + 4] + '</SPAN>';
		}
	}
	content += '</DIV>';
//alert('writeCtr '+content);
	document.write(content);
}

function writeIcons() {
	content = '<DIV ID="linkBoxBorder' + scrnSize + '"></DIV><DIV ID="linkBox">';
//orderArray[index] = new Array([0 pic title],[1 pic width A],[2 pic height A],[space][3 pic left A],[4 pic left B],
//[5 text left A],[6 text left B],[7 total height A],[8 total height B],[9 alt text],[10 link page]);
//localArray takes its file description from orderArray

	for (var index = 0; index < arrange.length; index++) {
		localArray = arrange[index];
		content += '<SPAN ID="P' + index + 'Pic">';
		tempWid = parseInt(localArray[1]);
		tempHt = parseInt(localArray[2]);
		if (scrnSize == 'B') {
			tempWid = parseInt(tempWid * .78125 + .5);
			tempHt = parseInt(tempHt * .78125 + .5);
//alert('Ht'+tempHt);
//incr tempHt causes the pic to overlap the text and doesn't alter the relationship to the text
//to the pic below. What sets the position of the text?
		}
		if  ((ctrArray[0] != 'quoteLab') && (ctrArray[0] != 'reqSample') && (ctrArray[0] != 'labStock')) {
			content += '<A HREF="';
			if (ctrArray[0] == 'group') {
				content += 'http://www.ctg-web.co.uk/';
			}
			content += localArray[10] + '.htm">';
		}
		var alt;
		if (ctrArray[0] == 'reqSample') {
			alt = '';
		} else {
			alt = localArray[9];
		}
		content += '<IMG SRC="picsN/' + localArray[0] + '.jpg" WIDTH="' + tempWid;
		content += '" HEIGHT="' + tempHt + '" ALT="' + alt + '" BORDER="0"';
		if (ctrArray[0] == 'labStock') {
			content += ' ONCLICK="showTable(' + localArray[10] + ')">';
		} else {
			if ((ctrArray[0] == 'quoteLab') || (ctrArray[0] == 'reqSample')) {
				content += ' ONCLICK="showContact(' + localArray[10] + ')">';
			} else {		
				content += '></A>';
			}
		}
		content += '</SPAN><SPAN ID="P' + index + 'Txt">' + localArray[9] + '</SPAN>';
	}
	content += '</DIV>';
//alert('writeIcons '+content);
	document.write(content);

	var tempPicL;
	var tempTxtL; 
	var iconTop = 10;
	var textTop;
	var totalHeightHold = 0;
	for (var index = 0; index < arrange.length; index++) {
		var localArray = arrange[index];
		if (index == 0) {
			iconTop = 10;
		} else {
			iconTop += totalHeightHold;
		}
//alert('IT'+iconTop);
		tempHt = parseInt(localArray[2]);
		if (scrnSize == 'B') {
			tempHt = parseInt(tempHt * .78125 + .5);
		}
		if (scrnSize == 'A') {
			tempPicL = localArray[3];
			tempTxtL = localArray[5];
			totalHeightHold = parseInt(localArray[7]);
			textTop = iconTop + tempHt + 10;
		} else {
			tempPicL = localArray[4];
			tempTxtL = localArray[6];
			totalHeightHold = parseInt(localArray[8]);
			textTop = iconTop + tempHt + 7;
//alert('TT'+textTop);
		}
		temp = 'P' + index + 'Pic';
		setLeft(temp, tempPicL,0);
		setTop(temp, iconTop,0);
		temp = 'P' + index + 'Txt';
		setLeft(temp, tempTxtL,0);
		setTop(temp, textTop,0);
	}
	if (scrnSize == 'A') {
		setHeight('linkBoxBorderA',totalHeightHold+iconTop+10);
	} else {
		setHeight('linkBoxBorderB',totalHeightHold+iconTop+7);
	}
}

function instruction() {
	iconArray = new Array('el5','elSpecial','elAdvanced','elChoose');
	aboveArray = new Array('pallet','data','ean','quote','group','bcRead','bcQuiz','contact');
	content = '<SPAN ID="instr' + scrnSize + '">';
	if (ctrArray[0] == 'quoteLab') {
		content += 'Click on the icon above for the quote you require; this will display the contact details form.</SPAN>';
	} else {
		if ((ctrArray[0] == 'labStock') || (ctrArray[0] == 'labStock1')) {
			content += 'Click on the icon above for the quote you require; this will display the list of stock items.</SPAN>';
		} else {
			if (ctrArray[0] == 'reqSample') {
				content += 'Click on the icon above for the free sample you require; this will display the contact details form.</SPAN>';
			} else {
				content += 'Click on ';
				for (var i = 0; i < iconArray.length; i++) {
					if (ctrArray[0] == iconArray[i]) {
						content += 'an icon';
						break;
					}
				}
				if (i == iconArray.length) {
					content += 'a picture';
				}
				for (var i = 0; i < aboveArray.length; i++) {
					if (ctrArray[0] == aboveArray[i]) {
						content += ' (above)';
						break;
					} 
				}
				if (i == aboveArray.length) {
					if (ctrArray[0] != 'index' && ctrArray[0] != 'H426Rew' && ctrArray[0] != 'RTLA' ) {
						content += ' (right)';
					}
				}
				content += ' to go to a page detailing that product.</SPAN>';
			}
		}

	}
	document.write(content);
}

function writeHdr() {
	content = '<DIV ID="titleBorder">';
	content += '<A HREF="javascript: reqDemo()"><SPAN ID="demoBlock">UK-wide<BR>Demonstration<BR>Service</SPAN></A>';
	content += '<SPAN ID="demoPic"><A HREF="javascript: reqDemo()">';
	content += '<IMG SRC="buttons/demonstration.jpg" ALT="UK-wide Demonstration Service" BORDER="0"WIDTH="160" HEIGHT="120"></A></SPAN>';
	content += '<SPAN ID="weyLogo' + scrnSize + '"><IMG SRC="picsN/new%20logo.jpg" WIDTH="376" HEIGHT="77" BORDER="0" ALT="Weyfringe Logo" ALIGN="TOP"></SPAN>';
//	content += '<A HREF="bcVerifier.htm"><SPAN ID="reqCatBlock' + scrnSize + '">Free Barcode<BR>Health Check</SPAN></A>';
	content += '<A HREF="javascript: reqCat()"><SPAN ID="reqCatBlock' + scrnSize + '">Request our free<BR>NEW labelling<BR>catalogue</SPAN></A>';
	content += '<SPAN ID="reqCatPic' + scrnSize + '"><A HREF="javascript: reqCat()">';
	content += '<IMG SRC="buttons/demonstration.jpg" ALT="Request free catalogue" BORDER="0" WIDTH="160" HEIGHT="120"></A></SPAN></DIV>';
	document.write(content);
}

function setFocus(objectID) {
	temp = document.getElementById(objectID);
	temp.focus();
}	

