function countClick(qs) {
	var clickUrl = "/apps/public/mw/click.php?"+qs;
	clickUrl += "&rand="+Math.round(Math.random()*Math.pow(10, 10));
	var img = new Image();
	img.src = clickUrl;
	return true;
}

function openProfile(target, w, h) {
	var width = w || 680;
	var height = h || 700;
	var brochure = window.open(target, "brochure", "width="+width+",height="+height+",menubar=no,toolbar=no,status=no,links=no,directories=no,personalbar=no,scrollbars=yes,resizable=yes");
	brochure.focus();
	return false;
}

function toProfile(direction) {
	document.changeProfile.referrer.value = window.location.href;
	document.changeProfile.direction.value = direction;
	document.changeProfile.submit();
}

function AJAXInteraction(pURL, pCallbackFunction, pAsText, source_block_id) {
	var vRequest = init();
	vRequest.onreadystatechange = processRequest;

	function init() {
		if(window.XMLHttpRequest) return new XMLHttpRequest();
		else if(window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
	}

	function processRequest () {
		if(vRequest.readyState == 4) {
			if(vRequest.status == 200) {
				if(pCallbackFunction) {
					if(pAsText) pCallbackFunction(vRequest.responseText,source_block_id);
					else pCallbackFunction(vRequest.responseXML,source_block_id);
				}
			}
		}
	}

	this.doGet = function() {
		vRequest.open("GET", pURL, true);
		vRequest.send(null);
	}

	this.doPost = function(pBody) {
		vRequest.open("POST", pURL, true);
		vRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		vRequest.send(pBody);
	}
}

function feedback_update(input, block_id){
	block_id = 'feedback-form-' + block_id;
	document.getElementById(block_id).innerHTML = input;
}

function feedback_submit(form){
	var answer;

	if(form.answer.length > 0){
		for (i=form.answer.length-1; i > -1; i--) {
			if (form.answer[i].checked) {
				answer = form.answer[i].value;
			}
		}

	} else {
		answer = form.answer.value;
	}

	if(answer != "" && answer != undefined){
	req = new AJAXInteraction(form.action + '?qid=' + form.qid.value + '&answer=' + encodeURIComponent(answer),feedback_update,true,form.qid.value);
	req.doGet();
	}
	return false;
}

function openPortfolio (bid) {

	if (!document.getElementById('portfolio_player')) {

		var callback =
		{
		  success: function(o) {
		  	if(o.responseText == 1) {
		  		displayPortfolio(bid);
		  	} else {
		  		alert('Sorry, but this portfolio is temporarily unvailable');
		  	}
		  },
		  failure: function(o) {alert('Sorry, but this portfolio is temporarily unvailable');}
		}

		var transaction = YAHOO.util.Connect.asyncRequest('GET', '/apps/public/guides/portfolio_data.php?check=1&business=' + bid, callback, null);

	}
}

function displayPortfolio(bid) {
	document.getElementById('tab_brochure').className = '';
	document.getElementById('tab_contact').className = '';
	document.getElementById('tab_mylist').className = '';
	document.getElementById('tab_portfolio').className = 'on';

	var	so = new SWFObject("/main/flash/ssp/slideshow_brochure.swf",	"portfolio_player",	"520","400", 7,"#666666");
	so.addParam("allowScriptAccess", "always");
	so.addVariable("xmlfile", "/apps/public/guides/portfolio_data.php?business=" + bid);
	so.write("copy_container");
}

/**
 * Displays a random banner from an array of banners injected into the guide page template.
 */
function showRandomBanner(parent) {
	if (banners.length > 0) {
		var randIndex = Math.floor(Math.random() * banners.length);
		var rand = banners[randIndex];
		parent.innerHTML = rand;
		parent.className = 'sidebar';
	}
}