	//Added so that we can use the same functionality in different directories 
	var sPath =  window.location.pathname; // string of URL
	var sFind = "/"; // find if it's a subdirectory
	var iCount = 0;
	var dirLoc ="";
	for (var i=0;i<sPath.length;i++) 
	{
		if (sFind == sPath.substr(i,sFind.length))
		{
			iCount++;
		}
	}
	if(iCount >=0){ dirLoc = "../";}


function preloadHome() {
	var img1 = new Image();
	var img1 = dirLoc+'images/solution_2.jpg';
	var img2 = new Image();
	var img2 = dirLoc+'images/solution_3.jpg';
	var img3 = new Image();
	var img3 = dirLoc+'images/solution_4.jpg';
	var img4 = new Image();
	var img4 = dirLoc+'images/1_bl.jpg';
	var img5 = new Image();
	var img5 = dirLoc+'images/2_bl.jpg';
	var img6 = new Image();
	var img6 = dirLoc+'images/3_bl.jpg';
	var img7 = new Image();
	var img7 = dirLoc+'images/4_bl.jpg';
	var img7 = new Image();
	var img7 = dirLoc+'images/1_gr.jpg';
	var img8 = new Image();
	var img8 = dirLoc+'images/2_gr.jpg';
	var img10 = new Image();
	var img10 = dirLoc+'images/3_gr.jpg';
	var img11 = new Image();
	var img11 = dirLoc+'images/4_gr.jpg';
	var img12 = new Image();
	var img12 = dirLoc+'images/5_bl.jpg';
	var img13 = new Image();
	var img13 = dirLoc+'images/6_bl.jpg';
}

function preloadLeft() {
}

function doubleSwap(img, imgLoc, img2Loc) {
	document.images[img].src = imgLoc;
	document.imgSolutions.src = img2Loc;
}

function mOver(n, img) {
	document.images[n].src = img;
}

function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
		// otherwise, update 'characters left' counter
	else
		cntfield.value = maxlimit - field.value.length;
}

function getHTTPObject() {
	if (window.ActiveXObject)
		return new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest)
		return new XMLHttpRequest();
	else {      
		alert("Your browser does not support AJAX.");
		return null;   
	}
}

var reload_after = 10000;
var timer;

function nextAd(ct, totNum, stc) {
	if (parseInt(ct) > parseInt(totNum)) { ct = 1; }
	
	httpObject = getHTTPObject();
	
	if (httpObject != null) {
		var now = new Date();
		thisSolutid = parseInt(ct);
		
		nextSolutID = (parseInt(ct) + 1);

		var url = dirLoc+'ajax-solutions.php?s=' + thisSolutid + '&ts=' + now.getTime();
		
		httpObject.open("GET", url, true);
		httpObject.send(null);
		httpObject.onreadystatechange = setOutput;
		
		if (stc == '')
			timer = setTimeout("nextAd(\"" + nextSolutID + "\", \"" + totNum + "\", \"" + stc + "\")", parseInt(reload_after));
		else
			clearTimeout(timer);
	}
}

function setOutput() {
	if(httpObject.readyState == 4) {
		if (httpObject.responseText == '')
			nextAd();
		else
			document.getElementById('ajax-solution-09').innerHTML = httpObject.responseText;
	}
}

function resetNums(ct, totNum) {
	for (var i=1; i<=totNum; i++) {
		if (parseInt(ct) == parseInt(i)) {
			document.images["bl" + i].src = dirLoc+'images/' + i + '_bl.gif'; 
		} else {
			document.images["bl" + i].src = dirLoc+'images/' + i + '_gr.gif'; 
		}
	}
}

function getNav(p, n, nb, nc, cl, clb, clc) {
	httpObject = getHTTPObject();

	if (httpObject != null) {
		var now = new Date();
		var url = dirLoc+'ajax-nav.php?cl=' + escape(cl) + '&clb=' + escape(clb) + '&clc=' + escape(clc) + '&p=' + escape(p) + '&n=' + escape(n) + '&nb=' + escape(nb) + '&nc=' + escape(nc) + '&ts=' + now.getTime();
		
		httpObject.open("GET", url, true);
		httpObject.send(null);
		httpObject.onreadystatechange = setOutputNav;
	}
}

function setOutputNav() {
	if(httpObject.readyState == 4) {
		if (httpObject.responseText == '')
			nextAd();
		else
			document.getElementById('ajax-nav').innerHTML = httpObject.responseText;
	}
}

function checkSearch() {
	if (document.frm1.q.value == "") {
		alert("Please fill in a search value.");
		return false;
	} else {
		return true;
	}
}

