//<![CDATA[
/*
 *	miserscripts.js
 *
 *	General purpose scripts for www.themisers.co.uk
 *
 *	by www.hothotfire.com
 */
 
function $m(anObject)	{ return document.getElementById(anObject); }
function oW(url) { window.open(url); }
function newTxt(text) { return document.createTextNode(text); }
function getXMLHTTPRequest(){
try { req = new XMLHttpRequest();} 
catch(err1){
	try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (err2){
		try	{ req = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch (err3) { req = false; }}}
	return req;}
var http = getXMLHTTPRequest();
function sendGet(sendString, phpFile){
	var myurl = 'http://www.themisers.co.uk/php/' + phpFile;
	myRand = parseInt(Math.random()*999999999999999);
	var modurl = myurl+"?whichContent="+sendString+"&rand="+myRand;
	http.open("GET", modurl, true);
	http.onreadystatechange = useHttpResponse;
	http.send(null);}
function getGigDetails(whichGig){
	sendGet('getGig,' + whichGig, 'getGigDetails.php');}
function showGigDetails(details){
	details = details.substr(7, details.length - 7);
	$m('info').innerHTML = details;}
function useHttpResponse(){
	if (http.readyState == 4){
		if(http.status == 200){
			var retTxt = http.responseText;
			respSplit = retTxt.split(',');
			switch (respSplit[0]){
				case 'getGig':
					showGigDetails(retTxt);
				break;
				case 'getAnswers':
					dispAns(retTxt);
				break;
					}}}}
function loadAudio(){
	var firstSong = $m('trackLink1').innerHTML;
	$m('flowAudio').innerHTML = '<div id="audio" href="http://www.themisers.co.uk/mp3player/media/' + escape(firstSong) + '.mp3"></div>';}
function playAudio(){
	$f("audio", "http://www.themisers.co.uk/broadview/flowplayer/flowplayer-3.1.5.swf", { 
    // fullscreen button not needed here 
    plugins: { 
        controls: { 
            fullscreen: false, 
            height: 30 
        } 
    }, 
    clip: { 
        autoPlay: true 
        }});}
function changeAudio(track){
		var thisSong = $m('trackLink' + track).innerHTML;
		$m('flowAudio').innerHTML = '<div id="audio" href="http://www.themisers.co.uk/mp3player/media/' + escape(thisSong) + '.mp3"></div>';
		var i;
		for (i = 1; i <= 4; i++)
		{
			$m('ind' + i).style.color = 'black';
		}
		$m('ind' + track).style.color = '#00FF00';
		playAudio();
		}
//Which Miser is Wiser?
function formatString(theString){
	var formattedString = "";
	for (var i=0;i<=theString.length - 1;i++){
		var thisChar = theString.charAt(i)
		if (thisChar == "'"){thisChar = "*aPoS";}
		if (thisChar == ","){thisChar = "*cOmA";}
		if (thisChar == "&"){thisChar = "%26";}
		if (thisChar == "+"){thisChar = "%2B";}
		if (thisChar == "£"){thisChar = "%C2%A3";}
		if (thisChar == "€"){thisChar = "%E2%82%AC";}
		if (thisChar == "<"){thisChar = "(";}
		if (thisChar == ">"){thisChar = ")";}						  
		formattedString = formattedString + thisChar;}
	return formattedString;}
function askQuestion(){
	$m('msgDiv').innerHTML = '';
	$m('questionBox').style.visibility = 'visible';}
function sendQuestion(){
	$m('msgDiv').innerHTML = '';
	var uName = formatString($m('userName').value);
	if (uName.length == 0){
	$m('msgDiv').innerHTML = '<span class="red">X You need to enter your name.</span>';
	return;}
	var uQuestion = formatString($m('userQuestion').value);
	if (uQuestion.length == 0){
	$m('msgDiv').innerHTML = '<span class="red">X You need to ask a question.</span>';
	return;}
	sendGet(('add,' + uName + ',' + uQuestion), 'questions.php');
	$m('questionBox').innerHTML = "<br /><br /><h2>Thanks for your question, The Misers will answer soon...</h2>";
	setTimeout("quitQuestion()", 5000);}
function quitQuestion(){
	$m('questionBox').style.visibility = 'hidden';}
function viewAnswer(qNo){
	sendGet(('get,' + qNo), 'questions.php');}
function dispAns(response){
	response = response.substr(11, response.length - 11);
	var retAns = response.split('dElImIt');
	$m('currentQ').innerHTML = '<span class="bold">' + retAns[0] + '</span> asked:<br />"' + retAns[1] + '"';
	$m('neilAnswer').innerHTML = retAns[2];
	$m('adamAnswer').innerHTML = retAns[3];}
function qCountdown(){
	var theValue = $m('userQuestion').value;
	var remaining = 150 - theValue.length;
	$m('charsLeft').innerHTML = remaining;
	if (remaining == 0){
		$m('userQuestion').value = theValue.substring(0,149);}}
function vote(whichMiser){
	//if (whichMiser == 'neil' || whichMiser == 'adam'){voted = true;}
	sendGet(('vote,' + whichMiser), 'questions.php');
	$m('voteString').innerHTML = '<h2>Thanks for your vote!</h2>';}
//function displayVotes(scores){
//	var results = scores.split(',');
//	var theTotal = parseInt(results[0]) + parseInt(results[1]);
//	var neilDec = results[0] / theTotal;
//	var adamDec = results[1] / theTotal;
//	$m('neilBar').style.width = 360 * neilDec + 'px';
//	$m('adamBar').style.width = 360 * adamDec + 'px';
//	$m('neilName').innerHTML = 'Neil (' + (neilDec * 100).toFixed(1) + '%)';
//	$m('adamName').innerHTML = 'Adam (' + (100 - (neilDec * 100).toFixed(1)).toFixed(1) + '%)';}
//function viewAllQ(){
//	ajaxId = 'getQs';
//	getContent('getQ', 'questions.php');}
//function dispQs(response){
//	$m('wiserMiser').innerHTML = response + '<a href="javascript:contentSelect(\'6\')">Back to Q&amp;A main page...<a/>';}
//]]>