
/******************************
**
**	Iteracy Content Management System
**	(c) 2007 Iteracy Ltd
**	All rights reserved
**	www.iteracy.com
**
*******************************/

function preLoadImages() {
	imagesArray = new Array();
	n = 0;
	if (document.images) {
		for (i=0; i<document.images.length; i++) {
			if (document.images[i].src.indexOf("_n.png")>0) { 
				img_on = document.images[i].src;
				img_on = img_on.substring(0,img_on.length-5) + "h.png";
				imagesArray[n] = new Image();
				imagesArray[n].src = document.images[i].src;
				imagesArray[n+1] = new Image();
				imagesArray[n+1].src = img_on; 
				n = n+2;
			}
		}
	}
}


function mouseOut(imgName) {
	if (document.images) {
		img_on = document.images[imgName].src;
		document.images[imgName].src = img_on.substring(0,img_on.length-5) + "n.png";
	}
}


function mouseOver(imgName) {
	if (document.images) {	
		img_on = document.images[imgName].src;
		document.images[imgName].src = img_on.substring(0,img_on.length-5) + "h.png";
	}
}

function Element(sID) {
	// returns an element
	if (document.getElementById(sID)) {
		return document.getElementById(sID);
	} else {
		return null;
	}
}

function hideDiv(sID) {
	// hides an element
	if (Element(sID)) {
		Element(sID).style.display = "none";
	}
}

function showDiv(sID) {
	// shows an element
	if (Element(sID)) {
		Element(sID).style.display = "block";
	}
}

function showHide(sID) {
	if (Element(sID)) {
		if (Element(sID).style.display != "block") {
			showDiv(sID);
		} else {
			hideDiv(sID);
		}
	}
}

function quickLink(sParams) {
	sURL = sParams.split("|")[0];
	bNewWin = sParams.split("|")[1];
	if (bNewWin == "true") {
		window.open(sURL);
	} else {
		document.location = sURL;
	}
}

function setRate(oCompany) {
	document.forms[0].tas_rate.value = aRates[oCompany.value];
}

function setFormat() {
	if (Element("pf1").checked) {
		sFormat = Element("pf1").value;
	} else if (Element("pf2").checked) {
		sFormat = Element("pf2").value;
	} else {
		sFormat = Element("pf3").value;
	}
	if (navigator.userAgent.indexOf("MSIE") != -1) {
		displayStyle = "block";
	} else {
		displayStyle = "table-row";
	}
	if (sFormat == 'single') {
		Element("area1").style.display = "none";
		Element("area2").style.display = displayStyle;
		Element("area3").style.display = "none";
	}
	if (sFormat == 'two') {
		Element("area1").style.display = "none";
		Element("area2").style.display = displayStyle;
		Element("area3").style.display = displayStyle;
	}
	if (sFormat == 'two_header') {
		Element("area1").style.display = displayStyle;
		Element("area2").style.display = displayStyle;
		Element("area3").style.display = displayStyle;
	}
}

function showHelp(sID) {
	helpItems = getElementsByClassName("help", "div");
	for (keyVar in helpItems) {
		hideDiv(helpItems[keyVar].id);
	}
	showDiv(sID);
}

function getElementsByClassName(classname,tag) {
	if(!tag) {
		tag = "*";
	}
	var anchs =  document.getElementsByTagName(tag);
	var total_anchs = anchs.length;
	var regexp = new RegExp('\\b' + classname + '\\b');
	var class_items = new Array();
	
	for(var i=0;i<total_anchs;i++) { 
		var this_item = anchs[i];
		if(regexp.test(this_item.className)) {
			class_items.push(this_item);
		}
	}
	return class_items;
}

scoredArray = new Array();
scoredNum = 0;

function checkValue(elementValue, errorMsg) {
	if (elementValue == "") {
		alert(errorMsg);
		return false;	
	} else {
		return true;
	}
}

function anon() {
	alert("This item was submitted anonymously.");
}

s0 = new Image();
s0.src = "images/scores/0.png";
s1 = new Image();
s1.src = "images/scores/1.png";
s2 = new Image();
s2.src = "images/scores/2.png";
s3 = new Image();
s3.src = "images/scores/3.png";
s4 = new Image();
s4.src = "images/scores/4.png";
s5 = new Image();
s5.src = "images/scores/5.png";

function sc(itemID, score) {
	document.images['item' + itemID].useMap = "";
	document.images['item' + itemID].onmouseout= "";
	document.images['item' + itemID].src = "rate.php?id=" + itemID + "&score=" + score;
	document.images['item' + itemID].style.cursor = "default";
}

function ro(itemID, n) {
	if (document.images['item' + itemID].useMap != "") {
		document.images['item' + itemID].src = eval('s' + n).src;
	}
}
