var xxxon = 0;
var qruiserchatwin = null;

function dropUpDown(thisid) {
	if (document.getElementById(thisid).style.display == "block") {
		document.getElementById(thisid).style.display = "none";
	}
	else {
		document.getElementById(thisid).style.display = "block";
	}
}

function dropUpDownArrow(thisid) {
	if (document.getElementById) {
		if (document.getElementById(thisid+'_text').style.display == "block") {
			document.getElementById(thisid+'_text').style.display = "none";
			document.getElementById(thisid+'_downicon').style.display = "none";
			document.getElementById(thisid+'_upicon').style.display = "block";
		}
		else {
			document.getElementById(thisid+'_text').style.display = "block";
			document.getElementById(thisid+'_downicon').style.display = "block";
			document.getElementById(thisid+'_upicon').style.display = "none";
		}
	}
}

function blogDate(unixtime,spanid) {
	if (unixtime == 0)
		var date = new Date();
	else
		var date = new Date(unixtime * 1000);

	var text = ("" + date.getDate()).slice(-2) + "/" + ("" + (date.getMonth() + 1)).slice(-2) + " " + ("0" + date.getHours()).slice(-2) + ":" + ("0" + date.getMinutes()).slice(-2) ;

	var spanid = document.getElementById(spanid);
	if ( spanid !== undefined ) spanid.innerHTML = text ;

}

function localTime(unixtime,spanid) {
	if (unixtime == 0)
		var date = new Date();
	else
		var date = new Date(unixtime * 1000);

	var text = ("0" + date.getHours()).slice(-2) + 
	"." + ("0" + date.getMinutes()).slice(-2) + 
	" " + ("000" + date.getFullYear()).slice(-4) + 
	"-" + ("0" + (date.getMonth() + 1)).slice(-2) +
	"-" + ("0" + date.getDate()).slice(-2);
	
	var spanid = document.getElementById(spanid);
	if ( spanid && spanid !== undefined ) spanid.innerHTML = text ;
}

function localDate(unixtime,spanid) {
	if (unixtime == 0)
		var date = new Date();
	else
		var date = new Date(unixtime * 1000);

	var text = ("000" + date.getFullYear()).slice(-4) + 
	"-" + ("0" + (date.getMonth() + 1)).slice(-2) +
	"-" + ("0" + date.getDate()).slice(-2) ;
	
	var spanid = document.getElementById(spanid);
	if ( spanid && spanid !== undefined ) spanid.innerHTML = text ;
}

/* Do note:
		- That when this function is used to deal with required radio buttons, the value of
			the "required" attributes should be the same for all radio buttons sharing the same name.
*/
function handleForm(theform) {
	var error_end = '';
	var radio_arr	= [];
	for (i=0; i<theform.length; i++) {
		var tempobj = theform.elements[i];

		var input_type = null;
		var no_length_error = true;
		if (maxlength = parseInt(tempobj.getAttribute('maxlength'))) {
			if (tempobj.nodeName == 'TEXTAREA') {
				if (tempobj.textLength)
					var textLength = parseInt(tempobj.textLength);
				else {
					var textLength = parseInt(tempobj.value.length);
				}
				if (!isNaN(textLength) && textLength > maxlength) {
					error_end += tempobj.getAttribute('required') + ', ';
					no_length_error = false;
				}
			}
			else if (input_type == 'text') {
				if (tempobj.value.length > maxlength) {
					error_end += tempobj.getAttribute('required') + ', ';
					no_length_error = false;
				}
			}
		}
		if (tempobj.getAttribute('required') && no_length_error) {
			/* For each found radio button, see if its name matches a previous
				one. If it does, and this radio button is checked, overwrite the old one.
				The only thing we need is one radio button matching each name and the above makes certain that radio button is the checked one if such a radio button exist. Else, it's any one of the radio buttons (first encountered).
			*/
			if (tempobj.getAttribute("type") == 'radio') {
				var name = tempobj.getAttribute("name");
				var first_of_group = true;
				// See if a radio object with this name allready has been found...
				for (var j = 0; j < radio_arr.length; ++j) {
					if (radio_arr[j].name == name) {
						// ... and if this radio button is checked, store this object instead
						if (tempobj.checked == true) {
							radio_arr[j] = tempobj;
						}
						// Since we found a matching name, this radio button obviously is NOT the first radio button encountered in this group of radio buttons.
						first_of_group = false;
					}
				}
				// If this was the first radio button of the group (having this name), add it to the end of our radio button group array
				if (first_of_group) {
					radio_arr[radio_arr.length]	= tempobj;
				}
			}
			else if(tempobj.getAttribute("type") == 'checkbox') {
				if (tempobj.checked == false)
					error_end += tempobj.getAttribute('required') + ', ';
			}
			else if (!tempobj.value) {
				error_end += tempobj.getAttribute('required') + ', ';
			}
		}
	}
	/* When all form elements have been inspected, loop over the array of radio buttons.
	   	If a radio button is found with ".checked == false", then no radio button in that group has been selected.
	*/
	for (var j = 0; j < radio_arr.length; ++j) {
		if (radio_arr[j].checked == false)
			error_end += radio_arr[j].getAttribute('required') + ', ';
	}
	if (error_end != '') {
		var errormessage = '<p>'+error_start+' '+error_end.substr(0, error_end.length-2)+'</p>';
		var frmErrors = document.getElementById('formerrors');
		if (frmErrors && frmErrors !== undefined) {
			document.getElementById('formerrors').innerHTML = errormessage;
			document.getElementById('formerrors').style.display = "block";
		}
		return false;
	}
	else {
		document.getElementById('formerrors').style.display = "none";
		for (i=0; i<theform.length; i++) {
			var tempobj = theform.elements[i];
			if (tempobj.type == 'submit' && tempobj.name == 'submit') tempobj.disabled = true;
		}		
	}

	return true;
}

var markaction = true;
function markunmark(theform) {
	for (i=0; i<document.forms[theform].length; i++) {
		var tempobj = document.forms[theform].elements[i];
		if (tempobj.type == 'checkbox') tempobj.checked = markaction;
	}
	markaction = !markaction;
}

function getAbsX(elt) {
	return /*(elt.x) ? elt.x :*/ getAbsPos(elt,"Left");
}

function getAbsY(elt) {
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1)
		return getAbsPos(elt,"Top") - 21; // Don't know why 21 exactly...
	return /*(elt.y) ? elt.y :*/ getAbsPos(elt,"Top");
}

function getAbsPos(elt,which) {
	iPos = 0;
	while (elt != null) {
		iPos += elt["offset" + which];
		elt = elt.offsetParent;
	}
	return iPos;
}
/********************************************************
 * Copyright (C) 2002-2003, CodeHouse.com. All rights reserved.
 * CodeHouse(TM) is a registered trademark.
 *
 * THIS SOURCE CODE MAY BE USED FREELY PROVIDED THAT
 * IT IS NOT MODIFIED OR DISTRIBUTED, AND IT IS USED
 * ON A PUBLICLY ACCESSIBLE INTERNET WEB SITE.
 * 
 * CodeHouse.com JavaScript Library Module: Get Current Style Method
 *
 * You can obtain this script at http://www.codehouse.com
 ********************************************************/
function CJL_getCurrentStyle(elem, prop) {
	if (elem.currentStyle) {  
		var ar = prop.match(/\w[^-]*/g);
		var s = ar[0];
		for (var i = 1; i < ar.length; ++i) {
			s += ar[i].replace(/\w/, ar[i].charAt(0).toUpperCase());
		}
		return elem.currentStyle[s]
	}
	else if (document.defaultView.getComputedStyle) {
		return document.defaultView.getComputedStyle(elem, null).getPropertyValue(prop);
   }
}

var timerid=0;

function hideThumb() {
	if (timerid != 0) window.clearTimeout(timerid);
	document.getElementById("thumb").style.display = 'none';
	return true;
}

function hideThumbIO() {
	if (timerid != 0) window.clearTimeout(timerid);
}

function showThumbDiv() {
	document.getElementById("thumb").style.display = 'block';
}

function showUploadDetails(event, name) {
	var tg = (event.target) ? event.target : event.srcElement;
	var x = getAbsX(tg) - 160;
	var y = getAbsY(tg) - 8;
	var block = document.getElementById("documentspecs");
	block.innerHTML = document.getElementById(name).innerHTML;
	block.style.left = x + 'px';
	block.style.top = y + 'px';
	block.style.display = 'block';
	return true;
}

function hideUploadDetails(name) {
	document.getElementById(name).style.display = 'none';
	return true;
}

function openMovie(member, url, xxx, emsg) {
	if (xxx && !xxxon) {
		alert(emsg);
	} else {
		window.open (url, "qruiser_movie");
		registerVisit (member, 8);
	}
}

function registerVisit(member,feature) {
	rand=Math.random();
	rand=rand*10000000000000000000;
	document.getElementById('callback').src = '/registervisit.php?member='+member+'&feature='+feature+'&rand='+rand;
}

function satellite() {
	swin = window.open(urlpath+"/satellite.php", "satellite", "scrollbars=1,resizable=1,width=300,height=200");
	if (window.focus) swin.focus();
}

function messagebox(id) {
	window.open(urlpath+"/messagebox.php?id="+id, "", "scrollbars=1,resizable=1,width=410,height=510");
}

function openChatWindow(args) {
	if (!args) args = "";
	if (qruiserchatwin == null || qruiserchatwin.closed == true || args == "?reset=1") {
		if (args == "") {
			args = args + "?restart=1";
		} else {
			args = args + "&restart=1";
		}
		qruiserchatwin = window.open(urlpath+"/chat.php"+args, "qchatwin", "scrollbars=1,resizable=1,width=600,height=600");
	} else {
		document.getElementById('callback').src = urlpath+"/chat.php"+args;
		if (window.focus) qruiserchatwin.focus();
	}
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function showAllPicsCheckbox(box) {
	if (box.checked) showAllPics(1);
	else showAllPics(0);
}

function showAllPics(value) {
	var hide = document.getElementById('hidexxx');
	if (value==1) hide.disabled = true;
	else hide.disabled = false;
	xxxon = value;
	document.cookie = "showallpics="+value+"; path=/; domain=.qruiser.com";
}

function changelogin() {
	window.open('/selectgeo.php?changelogin=1', 'selectgeo', 'resizable=yes,width=500,height=300');
}

function editimage(req) {
	window.open ('/editimage.php?' + req, 'editimage', 'resizable=yes,width=500,height=470,scrollbars=yes');
}

function edittext(req) {
	window.open ('/edittext.php?' + req, 'edittext', 'resizable=yes,width=500,height=470,scrollbars=yes');
}

function editmovie(req) {
	window.open ('/editmovie.php?' + req, 'editmovie', 'resizable=yes,width=500,height=470,scrollbars=yes');
}


/**** color picker functions ****/

var wasinPicker = false;
var startColor = '';
var picker = '';
function pickColor(color, pickname) {
	document.getElementById(pickname).value = color;
	document.getElementById(pickname).focus();
	document.getElementById(picker + "_color").style.backgroundColor = '#' + color;
	hidePicker ();
	if ( document.getElementById('colorpicker_blog') )
		updatePreview(pickname);		
}

function openPicker(event, pickname) {
	var tg = (event.target) ? event.target : event.srcElement;
	var x = getAbsX(tg);
	var y = getAbsY(tg);
	wasinPicker = false;
	startColor = document.getElementById(pickname).value;
	picker = pickname;
	block = document.getElementById("colorpicker");
	block.innerHTML = document.getElementById(pickname + "_colors").innerHTML;
	block.style.left = (x-1)+'px';
	block.style.top = (y+14)+'px';
	block.style.display = 'block';
}

function hidePicker() {
	document.getElementById("colorpicker").style.display='none';
	document.getElementById("colorpicker").innerHTML = '';
	wasinPicker = false;
	startColor = '';
	picker = '';
}

function changeColorValue(pickname, color) {
	document.getElementById(pickname + "_color").style.backgroundColor = '#' + color;
	//document.getElementById(pickname).value = color;
}

function changeColorEntered(field) {
	document.getElementById(field.name + "_color").style.backgroundColor = '#' + field.value;
}

function maybeHidePicker(event) {
	var tg = (event.target) ? event.target : event.srcElement;
	if (tg.getAttribute('id') == 'colorpicker') {
		if (!wasinPicker) {
			wasinPicker = true;
		} else {
			if (picker) changeColorValue (picker, startColor);
			hidePicker();
		}
	}
}

function changeColor(pickname, obj) {
	if (obj.href.substring (21,22) == "%")
		changeColorValue (pickname, obj.href.substring(24,30));
	else
		changeColorValue (pickname, obj.href.substring(22,28));
}

/**** end color picker ****/

function nothing() { }

function opensurvey(id) {
	window.open ("/survey.php?survey="+id, "survey", "width=450,height=450,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes");
}

function buygold(id) {
	window.open ("/order_gold_other.php?id="+id, "order_gold_other", "width=600,height=600,directories=no,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,resizable=yes");
}

function dropUpDownHome(thisid,member,iconcolor) {
	if (document.getElementById) {
		if (document.getElementById(thisid).style.display == "block") {
			document.getElementById(thisid).style.display = "none";
			document.getElementById(thisid+'_droparrow').src = 'http://icon.qruiser.com/images/dropup_'+iconcolor+'.gif';
		}
		else {
			document.getElementById(thisid).style.display = "block";
			document.getElementById(thisid+'_droparrow').src = 'http://icon.qruiser.com/images/dropdown_'+iconcolor+'.gif';
			if (thisid == 'homepageinfo') registerVisit(member,2);
		}
	}
}

function openVerify(memberid,verify_type) {
	if (verify_type == 'request') var page = 'me'; else var page = '';
	window.open("/verify"+page+"_popup.php?member_id="+memberid, "verify", "scrollbars=1,resizable=1,width=400,height=600,status=0,menubar=0,toolbar=0");
}

function openEdit(block,id,domain) {
	if ( block == undefined ) block = '-1' ;
	if ( id == undefined ) id = null ;
	if ( domain == undefined ) domain = urlpath ;
	if ( id == null )
		var url = domain+"/edit_popup.php?block="+block;
	else
		var url = domain+"/edit_popup.php?block="+block+"&id="+id;
	qedit = window.open(url, "qedit", "scrollbars=1,resizable=1,width=530,height=700,status=0,menubar=0,toolbar=0");
	qedit.focus();
}

function openPhotoPopup(memberid,albumid,photoid) {
	if('undefined' == typeof photo) { photo = 0; }
	if ((screen.width>=1024) && (screen.height>=768)) window.open(urlpath+"/photoalbum.php?memberid="+memberid+"&albumid="+albumid+'&photoid='+photoid, "Photoalbum", "scrollbars=0,resizable=1,width=900,height=720,status=0,menubar=0,toolbar=0");
	else window.open(urlpath+"/photoalbum.php?memberid="+memberid+"&albumid="+albumid+'&photoid='+photoid, "Photoalbum", "scrollbars=0,resizable=1,width=600,height=550,status=0,menubar=0,toolbar=0");
	registerVisit (memberid, 4);
}

function openPhotoAlbum(owner,id,photo) {
	if('undefined' == typeof photo) { photo = 0; }
	window.name = "Qruiser";
	if ((screen.width>=1024) && (screen.height>=768)) window.open("/photoalbum.php?owner="+owner+"&id="+id+'&photo='+photo, "Photoalbum", "scrollbars=0,resizable=1,width=900,height=720,status=0,menubar=0,toolbar=0");
	else window.open("/photoalbum.php?owner="+owner+"&id="+id+'&photo='+photo, "Photoalbum", "scrollbars=0,resizable=1,width=600,height=550,status=0,menubar=0,toolbar=0");
	registerVisit (owner, 4);
}

function dropContent(thisid,id,action) {
	if (document.getElementById) {
		// set hidden form values
		document.getElementById('dropcontent_action').value = action ;
		document.getElementById('dropcontent_id').value = id ;
		document.getElementById('dropcontent').submit() ;
		
		if ( action == 'delete' || action == 'unmark' ) {
			document.getElementById(thisid).style.display = "none";
		} else if ( action == 'zero' ) {
			// remove text-div about how many 
			var unread = 'unread' + id ;
			var unreadbtn = 'unreadbtn' + id ;
			document.getElementById(unread).innerHTML = '' ;
			document.getElementById(unreadbtn).style.display = "none";
		}

	}
}

function toggleAbuse(id) {
	abusediv = document.getElementById(id) ;
	abusediv.style.display = (abusediv.style.display == "none" ? "block" : "none");
}
	
function handleAbuse(id) {
	if (document.getElementById(id+'_form').reporttext.value == '') {
		document.getElementById(id+'_error').style.display = "block";
		return false;
	}
	document.getElementById(id).style.display = "none";
	document.getElementById(id+'_thanks').style.display = "block";
	return true ;
}

function registerVideoStatistics(id) {
	if (id == null || id == '')
		return false;
	var d = document;
	var oFrame = d.getElementById('callback');
	if (oFrame == undefined || oFrame.toString() != '[object HTMLIFrameElement]') {
		return false;
	}
	oFrame.src = '/videohit.php?video='+id ;
}

function openMovie_hq(videoid) {
	if ( videoid == undefined || parseInt(videoid) == 0) return false ;
	qvideo = window.open('/showmovie_hq.php?id='+parseInt(videoid), "qvideo"+parseInt(videoid), "scrollbars=1,resizable=1,width=680,height=570,status=0,menubar=0,toolbar=0");
	qvideo.focus();
}

function addOption(optCount) {
	for ( x = optCount ; x >= 0 ; --x ) {
		if ( option = document.getElementById('newoption_'+x) ) {
			if ( option.style.display == 'block' ) {
				// light up next option
				document.getElementById('newoption_'+(x+1)).style.display = 'block' ;
				if (x >= (optCount - 2))
					document.getElementById('addoption').style.display = 'none' ;
			}
		}
	}
}

function pollsubmit(theform,pollkey,event) {

	var d = document;
	
	var oAJAXdig = new AJAX();
	oAJAXdig.setEvent(event); 
	oAJAXdig.rp += "poll_vote.php";

	var redirect = theform.elements['redirect'].value ;
	var pollid = theform.elements['pollid'].value ;
	var option = theform.elements['option'] ;
	var chosenoptions = '' ;

// Poll skapad av "bugtestar" för att samla in information från Zidane
if (pollid == 1053) {
	oAJAXdig.callback.failure = function (o) { var s = 'rp: ' + oAJAXdig.rp + '\npost: ' + oAJAXdig.POST + '\n\no:\n';
	for (x in o)
		s += x + ': ' + o[x] +'\n';
	
	alert(s);}
}


	if ( "undefined" != typeof option && option.length > 0 ) {
		for ( x = 0 ; x < option.length ; x++ ) {
			if ( option[x].checked ) chosenoptions += option[x].value + ";" ;
		}
	}

	oAJAXdig.POST = "pollid="+parseInt(pollid)+"&options="+escape(chosenoptions)+"&posttoken="+escape(posttoken);

	//oAJAXdig.debug = function(str) { alert(str); } 
	oAJAXdig.resultHandler = function(data, meta) {

		if ( data[0] !== undefined ) {
			alert(data[0]["message"]) ;

			// redirect to requested page
			if ( typeof redirect != "undefined" && redirect != '' ) {
				setTimeout("location.href='"+redirect+"'",1);
			} else {
				// remove poll and place result there instead
				var polldiv = document.getElementById('poll'+pollkey);
				polldiv.parentNode.innerHTML = data[0]['html'] 
			}
		}
	}

	oAJAXdig.startRequest();
	return false ;
}

function pollcheckoptions(pollkey) {
	chosen = false ;
	if ( theform = document.getElementById('poll_'+pollkey) ) {
		var option = theform.elements['option'] ;
		for ( x = 0 ; x < option.length ; x++ ) {
			if ( option[x].checked ) {
			chosen = true ; break ;}
		}
	}
	if ( chosen == true ) {
		document.getElementById('submit_'+pollkey).disabled = false ;
	} else {
		document.getElementById('submit_'+pollkey).disabled = true ;
	}
	return chosen ;
}

function pollview(displaytype,pollid,pollkey,redirect,memberbox,commentlink,event) {
	if ( displaytype != 'result' && displaytype != 'question' && displaytype != 'question+vote' ) return ;

	var oAJAXpoll = new AJAX();
	oAJAXpoll.rp += "poll_result.php";
	
	oAJAXpoll.setEvent(event); 
	oAJAXpoll.POST = "pollid="+parseInt(pollid)+"&displaytype="+escape(displaytype)+"&memberbox="+escape(memberbox)+"&commentlink="+escape(commentlink) ;

	//oAJAXpoll.debug = function(str) { alert(str); } 
	oAJAXpoll.resultHandler = function(data, meta) {

		if ( data[0] !== undefined ) {
			// remove poll and place result there instead
			var polldiv = document.getElementById('poll'+pollkey);
			polldiv.parentNode.innerHTML = data[0]['html'];
		}
	}

	if ( typeof redirect != "undefined" && redirect != '' ) {
		setTimeout("location.href='"+redirect+"'",1);
	} else {
		oAJAXpoll.startRequest();
	}
}


function pollshowvoters(poll_id,answer_id,pollkey, event) {
	var oAJAXdig = new AJAX();
	oAJAXdig.rp += "poll_voters.php";
	oAJAXdig.setEvent(event);
	oAJAXdig.POST = "poll_id="+parseInt(poll_id)+"&option_id="+parseInt(answer_id)+"&pollkey="+escape(pollkey) ;
	//oAJAXdig.debug = function(str) { alert(str); } 
	oAJAXdig.resultHandler = function(data, meta) {

		if ( data[0] !== undefined ) {
			// hide comments
			if ( commentdiv = document.getElementById('pollcomments') )
				commentdiv.style.display = 'none' ;
			// place voters in voter div
			if ( voterdiv = document.getElementById('pollvoters'+pollkey) ) {
				voterdiv.innerHTML = data[0]['html'] ;
				voterdiv.style.display = 'block' ;
			}
		}
	}

	oAJAXdig.startRequest();
}

function closevoters(pollkey) {
	// place voters in voter div
	if ( voterdiv = document.getElementById('pollvoters'+pollkey) )
		voterdiv.style.display = 'none' ;	

	// show comments
	if ( commentdiv = document.getElementById('pollcomments') )
		commentdiv.style.display = 'block' ;
}



function abusereport(type,func,id,event) {
	// function inserts an abusereport form on a poll (or blogentry)
	var d = document ;
	// if abuse report already opened, close if new open command
	if ( func == 'open' && d.getElementById('abusereport_'+type+id) )
		func = "close" ;

	if ( func == 'open')
		var abusediv = d.getElementById(type+id) ;
	else if ( func == 'close' || func == 'report' )
		var abusediv = d.getElementById('abusereport_'+type+id) ;

	if ( typeof abusediv == undefined || abusediv === null) return ;
	
	var oAJAXdig = new AJAX();
	oAJAXdig.rp += "abusereport.php";
	oAJAXdig.setEvent(event); 
	
	if ( func == 'open' ) {

		// get html for form back from function and place last in blogentry-div
		oAJAXdig.POST = "function=gethtml&type="+escape(type)+"&id="+escape(id)+"&posttoken="+escape(posttoken) ;
		//oAJAXdig.debug = function(str) { alert(str); }
		oAJAXdig.resultHandler = function(data, meta) {
			if (data[0] !== undefined && data[0]['html'] !== undefined ) {
				// create new div with content
				newDiv = document.createElement("div") ;
				newDiv.className = "" ;
				newDiv.id = 'abusereport_'+ type + id ;
				newDiv.style.paddingTop = "10px" ;
				newDiv.innerHTML = data[0]['html'] ;
				abusediv.appendChild(newDiv);
			}
		}
	
		// do the request, if abuseform don't already exist
		if ( !d.getElementById('abusereport_'+type+id) ) {
			oAJAXdig.startRequest();
		}
		
	// remove an abuseform
	} else if ( func == 'close' ) {
		abusediv.parentNode.removeChild(abusediv);
	
	// submit a report
	} else if ( func == 'report' ) {
		// first check that everything is filled in
		reporttext = d.getElementById('reporttext_'+type+id).value ;
		// give error if no text have been filled in
		if ( reporttext == '' )
			d.getElementById('reporttext_'+type+id+'_error').style.display = 'block' ;
		else {
			// if a poll is reported we need the poll id, id before is the pollkey
			if ( type == "poll" ) {
				reportedid = parseInt(d.getElementById('pollid'+id).value) ;
				if ( reportedid == 0 ) return false ;
			} else
				reportedid = parseInt(id);

			// try to submit the report, get a true or false response (or error)
			oAJAXdig.POST = "function=report&type="+escape(type)+"&id="+reportedid+"&posttoken="+escape(posttoken)+'&reporttext='+encodeURIComponent(reporttext) ;
			//oAJAXdig.debug = function(str) { alert(str); } 
			oAJAXdig.resultHandler = function(data, meta) {
				if (data[0]['result'] == true) {
					// hide the report box as well as report icon
					if ( abusediv = d.getElementById('abusereport_'+type+id) )
						abusediv.parentNode.removeChild(abusediv);
					
					if ( abuseicon = d.getElementById('abuseicon_'+type+id) )
						abuseicon.style.display='none';
					
					// print thank you message
					alert(data[0]['message']);
				}
			}
			oAJAXdig.startRequest();
		}
	}
}

/*******************************
 * showDivPopup
 * and its utility functions.
 * used for ajax errors
 ******************************/
var divPopUpZIndex = 10;

 /*	Can take an additional 4th argument used to prefix the css classes
	prefixText and prefixContainer. Default is errorText and errorContainer.
	
	returns: element node, the enclosing div
	*/

function showDivPopup(oError, e, closeText, classPrefix, position) {
	var d = document;

	var outer = d.createElement('div');
	outer.style.zIndex = divPopUpZIndex++;
	var inner = d.createElement('div');
	outer.appendChild(inner);
	
	if (classPrefix != null && classPrefix != "")
		var prefix = classPrefix;
	else
		var prefix = "error";


	inner.className = prefix + "Text";
	inner.style.display = "block";

	outer.className = prefix + "Container";
	if (prefix == 'error') {
		var ediv = d.getElementById('errorPopupContainer');
		if (ediv)
			ediv.parentNode.removeChild(ediv);
		outer.id = 'errorPopupContainer';
	}
	
	for (var i = 0; i < oError.length; ++i) {
		inner.appendChild(buildDomFromArray(oError[i]));
	}

	var close = d.createElement('input');
	close.type = "button";
	close.style.cssFloat = 'right';
	close.value = closeText;
	if (close.addEventListener) {
		close.addEventListener("click", function(e) {outer.parentNode.removeChild(outer);},false);
	}
	else if (close.attachEvent) {
		close.attachEvent("onclick", function(e) {outer.parentNode.removeChild(outer);},false);
	}
	else {
		var toid = window.setTimeout(
				function() {
					if (outer && outer.parentNode)
						outer.parentNode.removeChild(outer);
					else
						window.clearTimeout(toid);
				},
				10000);
	}
	inner.appendChild(d.createElement('br'));
	inner.appendChild(close);
	
	var resetFloat = d.createElement('div');
	resetFloat.style.clear = 'both';
	resetFloat.style.height = '0px';
	inner.appendChild(resetFloat);

	if (position && position == "center")
		positionCenter(outer);
	else if (position && position == "event")
		positionByEvent(outer, e);
	createShadowBorder(outer);
	// IE fix to actually show the text without the user accidentally moving mouse pointer over the div. Insane... once again. Thank you Bill.
	if (navigator.userAgent.indexOf("MSIE 8") > -1) {
		inner.style.display = "none";
		inner.style.display = "block";
	}
	
	return outer;
}

function addStaticEventFromTemplate(control, eventType, codeString) {
	var c = control;
	var x = eventType;
	var code = codeString;

	if (YAHOO && YAHOO.util.Event) {
		YAHOO.util.Event.addListener( c, x.substr(2), function(event) {eval(code);});
	}
}

function addEvent(control, eventType, f) {
	var c = control;
	var x = eventType;
	if (c.addEventListener) {
		c.addEventListener(x.substr(2), f, false);	
	}
	else if (c.attachEvent) {
		c.attachEvent(x, f, false);	
	}
}

function buildDomFromArray(o) {
	// No info about what node to create.
	if (o == null || o.type == null) {
		return null;
	}
	
	var d = document;
	
	var z = 0;

	// Text nodes can't contain other nodes.
	if (o.type == "span" && o.attrs && o.attrs.id == "nbspspan") {
	}

	if (o.type == "#text" || o.type == "#cdata-section") {
		var text = d.createTextNode(o.content);
		return text;
//		return d.createTextNode(o.content.replace(/\\xa0/g, "\xa0"));
	}
	else if (o.type == "script" || o.type == "#comment") {
		return d.createTextNode("");
	}
	// Create no <span> for text that goes into option elements.
	else if (o.type == "option") {
		var opt = d.createElement('option');
		opt.value = o.attrs.value;
		opt.appendChild(d.createTextNode(o.content[0].content));
		return opt;
	}
	
	try {
		var n = d.createElement(o.type);
	}
	catch (e) {
		alert("Invalid type: " + o.type);
		var n = d.createElement('div');
	}
	for (x in o.attrs) {
		if (x.indexOf("on") === 0) {
			addStaticEventFromTemplate(n, x, o.attrs[x]);
		}
		else switch (x) {
			case "class":
				n.className = o.attrs[x];
				break;
			case "type":
				if (o.type == "input") {
					n.value = o.attrs.value;
					n.type = o.attrs[x];
				}
			default:
				try {
					n.setAttribute(x, o.attrs[x])
				}
				catch (e) {
				}
		}
	}
	if (o.attrs && o.attrs.style ) {
		var styles = o.attrs.style.split(";");
		for (var i = 0; i < styles.length; ++i) {
			// IE8 can't handle values like " bold"
			styles[i] = styles[i].replace(/:\s*/, ":");
			var sarr = styles[i].split(":");
			sarr[0] = sarr[0].replace(/\s/g, "");
			var di = -1
			var stop = 0;
			while((di = sarr[0].indexOf("-")) !== -1 && stop < 3) {
				sarr[0] = sarr[0].substr(0, di) + sarr[0].substr(di+1,1).toUpperCase() + sarr[0].substr(di+2);
				stop++;
			}
			try {
				// Only do this if sarr[0] is not ""
				if (sarr[0]) {
					if (sarr[0] == 'float') {
						n.style['cssFloat'] = sarr[1];
						n.style['styleFloat'] = sarr[1];	
					}
					n.style[sarr[0]] = sarr[1];
				}
			}
			catch (err) {
				alert(sarr[0] + "\n" + sarr[1]);
			}
		}
	}
	
	// Return node without content
	if (o.content == null) {
		return n;
	}
	/* Go through this nodes contents (child nodes) and append them */
	else {
		/*	The textarea element needs to be dealt with separately.
			PHP DOM consider textarea content to be child nodes, and
			those can either by text nodes or br elements.
			However, br elements aren't of any use in a textarea element.
			LF chars should be used instead, so we create just one text node. */
		if (n.type == 'textarea') {
			var s = "";
			for (var i = 0; i < o.content.length; ++i) {
				if (o.content[i].type == "#text")
					s += o.content[i].content;
				else if (o.content[i].type == "br")
					s += "\n";
			}
			n.appendChild(d.createTextNode(s));
		}
		else {
			for (var i = 0; i < o.content.length; ++i) {
				try {
					n.appendChild(buildDomFromArray(o.content[i]));
				}
				catch (e) {
					var s = '';
					for (x in o.content[i]) {
						s += x + ': ' + o.content[i][x] + '\n';
						if (x == 'content') {
							for (y in o.content[i]['content'])
								s += '&nbsp;&nbsp;&nbsp;' + o.content[i]['content'][y]['content'];
						}
					}
					alert(e + '\n\n' + 'error for: ' + n + '\ncontent:\n' + s);
				}
			}
		}
	}
	return n;
}

function hideHelpText() {
	var d = document;
	
	// Remove existing help text container
	var div = d.getElementById("blogHelpTextContainer");
	if (div)
		div.parentNode.removeChild(div);
}

// The div to give a shadow for right and bottom sides
function createShadowBorder(containerDiv) {
	var d = document;

	/*	Use custom function to retrieve the style attribute value since IE8 doesn't have
		styleObject.styleAttribute, but rather styleObject[styleAttribute].
		i.e. it's an array in IE8, not an object. */
	var containerDivstyle = getPortableComputedStyle(containerDiv, "");
	var computedHeight = getPortableComputedStyleValue(containerDivstyle, "height");
	var computedWidth = getPortableComputedStyleValue(containerDivstyle, "width");

	var urc	= d.createElement('div');		// Upper Right Corner
	urc.style.backgroundColor = 'transparent';
	var r	= d.createElement('div');		// right side
	r.style.backgroundColor = 'transparent';
	var lrc	= d.createElement('div');		// Lower Right Corner
	lrc.style.backgroundColor = 'transparent';
	var llc = d.createElement('div');		// Lower Left Corner
	llc.style.backgroundColor = 'transparent';
	var b	= d.createElement('div');		// bottom side
	b.style.backgroundColor = 'transparent';

	var divstyle = getPortableComputedStyle(containerDiv, "");

	// The corner images are 8x8 (depending on the corner)
	urc.style.width		= "8px";
	urc.style.height	= "8px";
	lrc.style.width		= "8px";
	lrc.style.height	= "8px";
	r.style.width		= "8px";
	
	/*	The right border should go along the right side of containerDiv, from
		where upper right corner ends to where lower right corner begins. (full height - 16px)
		The right side shadow must also extend beyond containerDiv equal to the width of
		the bottom shadow (+9). Should be +8, but an additional 1px is needed for Safari and FF. */
	var tempHeight = getPortableComputedStyleValue(divstyle, "height");
	// Yet another IE8 fix
	if (tempHeight == "auto") {
		tempHeight = containerDiv.clientHeight;
	}
	rheight = (parseInt(tempHeight) - 16 + 8  + parseInt(getPortableComputedStyleValue(divstyle, "borderTopWidth")) + parseInt(getPortableComputedStyleValue(divstyle, "borderBottomWidth")));

	/*	Error in IE8 if trying to assign a negative value to height
		Do NOT modify rheight itself here. It's needed later on to correct too large corner
		border images when rheight < 16. */
	if (rheight < 0) {
		r.style.height = "0px";
	}
	else {
		r.style.height = rheight + "px";
	}

	llc.style.height	= "8px";
	llc.style.width		= "8px";
	b.style.height		= "8px";
	b.style.width		= (parseInt(getPortableComputedStyleValue(containerDivstyle, "width")) - 8) + "px";

	var borderLeftPos = (parseInt(getPortableComputedStyleValue(containerDivstyle, "width"))) + "px";


	urc.style.position	= "absolute";
	lrc.style.position	= "absolute";
	r.style.position	= "absolute";

	urc.style.left	= borderLeftPos;
	lrc.style.left	= borderLeftPos;
	r.style.left	= borderLeftPos;
	urc.style.top	= "0px";
	lrc.style.top	= (8 + parseInt(r.style.height)) + "px";
	r.style.top		= "8px";
	
	llc.style.position	= "absolute";
	b.style.position	= "absolute";
	llc.style.left		= "0px";
	b.style.left		= "8px";

	// Images used for the shadow effect
	urc.style.backgroundImage	= "url('http://icon.qruiser.com/images/shadow/trc.png')";
	lrc.style.backgroundImage	= "url('http://icon.qruiser.com/images/shadow/brc.png')";
	r.style.backgroundImage		= "url('http://icon.qruiser.com/images/shadow/right.png')";
	llc.style.backgroundImage	= "url('http://icon.qruiser.com/images/shadow/blc.png')";
	b.style.backgroundImage		= "url('http://icon.qruiser.com/images/shadow/bottom.png')";
	r.style.backgroundReapeat	= "repeat";
	b.style.backgroundReapeat	= "repeat";
	
	/*	Now deal with the special case where the height of the containerDiv is less than 16px,
		which is the needed height to fit the full images for upper right corner and lower right corner. */
	if (rheight < 0) {
		var sharedH = rheight * (-1);
		var topHalf = parseInt(sharedH / 2);
		if (2*topHalf != sharedH)
			var bottomHalf = topHalf + 1;
		else
			var bottomHalf = topHalf;
		
		urc.style.height = (parseInt(urc.style.height) - topHalf) + "px";
		lrc.style.height = (parseInt(lrc.style.height) - bottomHalf) + "px";
		
		urc.style.overflowY = "hidden";
		lrc.style.overflowY = "hidden";
		lrc.style.backgroundPosition = "0px " + ((8 - bottomHalf) + "px");
		lrc.style.top = (parseInt(urc.style.height)) + "px";
		
	}

	containerDiv.appendChild(urc);
	containerDiv.appendChild(r);
	containerDiv.appendChild(lrc);
	containerDiv.appendChild(b);
	containerDiv.appendChild(llc);
}

// Used in place of element.getComputedStyle which is standard and therefor not supported by IE.
function getPortableComputedStyle(oElm, pseudo){
	var strValue = "";
	// standard
	if (oElm.getComputedStyle)
		return oElm.getComputedStyle(pseudo);
	// others
	if(document.defaultView && document.defaultView.getComputedStyle){
		return document.defaultView.getComputedStyle(oElm, pseudo);
	}
	// ie
	else if(oElm.currentStyle){
		return oElm.currentStyle;
	}
}

function getPortableComputedStyleValue(oStyle, str) {
	if (!oStyle || !str || str == "")
		return false;

	if(oStyle[str]) {
		return oStyle[str];
	}
	else {
		return false;
	}
}

function getClientAreaDimension() {
	var xScroll, yScroll;

	// all except Explorer
	if (self.innerHeight) {
		if(document.documentElement.clientWidth) {
			winW = document.documentElement.clientWidth; 
		}
		else {
			winW = self.innerWidth;
		}
		winH = self.innerHeight;
	}
	// Explorer 6 Strict Mode
	else if (document.documentElement && document.documentElement.clientHeight) {
		winW = document.documentElement.clientWidth;
		winH = document.documentElement.clientHeight;
	}
	// other Explorers
	else if (document.body) {
		winW = document.body.clientWidth;
		winH = document.body.clientHeight;
	}
	
	var sw = getScrollWidth();
	if (sw) {
		winW -= sw;
		winH -= sw;
	}
	return {width: winW, height: winH};
}
/*	Displays the argument div next to the event that took place.
*/
function positionByEvent(div, e) {
	var d = document;

	// How far off from the mouse pointer we want the div to appear, for both x and y coords.
	var offset = 8;

	// where the event took place
	var coords = getPageEventCoords(e);
	var x = coords.left;
	var y = coords.top;

	var winDim = getClientAreaDimension();	

/*
	var body = d.getElementsByTagName("body");
	body[0].insertBefore(div, body[0].firstChild);
*/
	var body = d.getElementsByTagName('body');
	body = body[0];
	body.insertBefore(div, body.firstChild);

	if (div.childNodes.length === 0)
		return;
	else
		var innerBlock = div.childNodes[0];

	var innerBlockstyle = getPortableComputedStyle(innerBlock, "");
	
	// These MUST come after div.style.display = block AND body.insertBefore(), else they are 0
	var divW = parseInt(innerBlock.clientWidth) + parseInt(getPortableComputedStyleValue(innerBlockstyle, "borderLeftWidth")) + parseInt(getPortableComputedStyleValue(innerBlockstyle, "borderRightWidth"));
	div.style.width = divW + "px";
	var divH = parseInt(innerBlock.clientHeight) + parseInt(getPortableComputedStyleValue(innerBlockstyle, "borderTopWidth")) + parseInt(getPortableComputedStyleValue(innerBlockstyle, "borderBottomWidth"));
	div.style.height = divH + "px";

	// Call custom function for "getComputedStyle" to deal with IEs lack of standard compliance
	var divstyle = getPortableComputedStyle(div, "");
	
	// Default positioning is above and to the right of the cursor
	var divX = x + offset;
	var divY = y - divH - offset;

	// Make sure we don't try to go off screen
	if (divY < 0)
		divY = 0;

	// Padding for the helpdiv's containerDiv
	var innerBlockpadding = {
							left:	parseInt(getPortableComputedStyleValue(innerBlockstyle, "paddingLeft")),
							right:	parseInt(getPortableComputedStyleValue(innerBlockstyle, "paddingRight")),
							top:	parseInt(getPortableComputedStyleValue(innerBlockstyle, "paddingTop")),
							bottom:	parseInt(getPortableComputedStyleValue(innerBlockstyle, "paddingBottom"))
					};
	/*	Padding for the container containerDiv - should be 10px 10px 0px 0px.
		Right and Bottom matches the shadow width. Top and left are 0px. */
	var divpadding = {
							left:	parseInt(getPortableComputedStyleValue(divstyle, "paddingLeft")),
							right:	parseInt(getPortableComputedStyleValue(divstyle, "paddingRight")),
							top:	parseInt(getPortableComputedStyleValue(divstyle, "paddingTop")),
							bottom:	parseInt(getPortableComputedStyleValue(divstyle, "paddingBottom"))
					};

	// Possibly position to the left of cursor
	if (x > (winDim.width / 2) && ((divX + divW) > winDim.width)) {
		var divX = x - divW - offset;
		if (divX < 0) {
			divX = 0;

			div.style.width = (x - offset - divpadding.left - divpadding.right - divpadding.left - divpadding.right) + "px";
			innerBlock.style.width = (parseInt(div.style.width) - divpadding.left - divpadding.right) + "px";
			div.style.height = (parseInt(div.clientHeight)) + "px";
		}
	}

	// Position the container
	div.style.left = divX + "px";
	div.style.top = divY + "px";
}
function getPageEventCoords(evt) {
	var coords = {left:0, top:0};

	if (evt.clientX) {
		/*	Should not have to take scrolling into account for fixed positioning.
			Still, it is needed in IE. */
		if (navigator.userAgent.indexOf("MSIE") > 0) {
			coords.left = evt.clientX + document.body.scrollLeft - document.body.clientLeft;
			coords.top = evt.clientY + document.body.scrollTop - document.body.clientTop;
		}
		else {
			coords.left = evt.clientX; // + document.body.scrollLeft - document.body.clientLeft;
			coords.top = evt.clientY; // + document.body.scrollTop - document.body.clientTop;
		}
	}
	else if (evt.pageX) {
		coords.left = evt.pageX;
		coords.top = evt.pageY;
	}
	return coords;
}

// Center horizontally. Default from top is 200px
function positionCenter(div) {
	var d = document;
	var win = window;
	var topDefault = 50;
	
	var dim = getClientAreaDimension();
	
	var body = d.getElementsByTagName('body');
	body = body[0];
	body.insertBefore(div, body.firstChild);
	div.style.position = "fixed";

	var divStyle = getPortableComputedStyle(div, "");
	var divWidth = parseInt(getPortableComputedStyleValue(divStyle, "width"));
	var divHeight = parseInt(getPortableComputedStyleValue(divStyle, "height"));

	if (dim.width < 750 && divWidth > 750)
		dim.width = 750;
	
	if (divWidth > dim.width)
		div.style.width = dim.width;

	var divLeft = parseInt((dim.width - divWidth) / 2);
	
	var moveUp = ((divHeight + topDefault) - dim.height);
	if (moveUp > 0)
		divTop = topDefault - moveUp;
	else
		divTop = topDefault;
	if (divTop < 0)
		divTop = 0;

	div.style.top = divTop + "px";
	div.style.left = divLeft + "px";

}

// Does not check if scrollbars are there or not, just calculates their width
function getScrollWidth() {
	var d = document;
	var div = d.createElement("div");
	div.style.width = "60px";
	div.style.height = "60px"; // IE8 needs enough height or width is 0...
	div.style.overflow = "scroll";
	div.style.padding = "0px";
	div.style.margin = "0px";
	div.style.visibility = "hidden";

	var body = d.getElementsByTagName('body');
	body = body[0];
	body.appendChild(div);

	var sw = 60 - parseInt(div.clientWidth);
	
	div.parentNode.removeChild(div);
	return sw;
}

/******************************
 * END: showDivPopup
 ******************************/

function blogEulaAccepted(o) {
	var d = document;
	var ins = d.getElementsByTagName('input');
	for (var i = 0; i < ins.length; ++i) {
		if (ins[i].type == 'submit') {
			ins[i].disabled = !o.checked;
		}
	}
}