
function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	if (browser == "Microsoft Internet Explorer") {
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		ro = new XMLHttpRequest();
	}
	return ro;
}

var httpvote = createRequestObject();

function rosta(definition, rost) {
	var thedate = new Date();
	httpvote.open("get", "/rosta/?definition=" + definition + "&rosta=" + rost + "&tid=" + thedate.getTime());
	httpvote.onreadystatechange = spararost;
	httpvote.send(null);
}

function spararost() {
	if(httpvote.readyState == 4){
		var response = httpvote.responseText;
		var update = new Array();
		if(response.indexOf('|' != -1)) {
			update = response.split('|');
			if (update[0] == 'ok') {
				var uv = "upvotes" + update[1];
				var dv = "downvotes" + update[1];
				document.getElementById(uv).innerHTML = parseInt(document.getElementById(uv).innerHTML) + (parseInt(update[2]));
				document.getElementById(dv).innerHTML = parseInt(document.getElementById(dv).innerHTML) + (parseInt(update[3]));
			}
		}
	}
}


var httpnarliggande = createRequestObject();
var globalfirstword = '';
var globallastword = '';

function narliggande(ordet, riktningen) {
	var thedate = new Date();
	if (globallastword != '' && riktningen == 'down') {
		ordet = globallastword;
	}
	
	if (globalfirstword != '' && riktningen == 'up') {
		ordet = globalfirstword;
	}
	globalfirstword = '';
	globallastword = '';
	
	httpnarliggande.open('get', '/ordlistan/?ord=' + ordet + '&riktning=' + riktningen + "&ordnu=" + ordnu + '&time=' + thedate.getTime());
	httpnarliggande.onreadystatechange = hamtanarliggandeord;
	httpnarliggande.send(null);
}

function dodadecode(str) {
	var ret = str;
	ret = ret.toString();
	ret = unescape(ret);
	ret = ret.replace(/%20/g, ' ');
	ret = ret.replace(/\+/g, ' ');
	ret = ret.replace(/\"/g, '\"');
	return ret;
}

function hamtanarliggandeord() {
	if(httpnarliggande.readyState == 4){
		var response = httpnarliggande.responseText;
		if(response.indexOf('|' != -1)) {
			globalfirstword = '';
			var str_out = '';
			var thewords = new Array();
			thewords = response.split('>');
			var updatelength = thewords.length;
			var thearr = new Array;
			for (i = 0; i < updatelength; i++) {
				thearr = thewords[i].split('<');
				if (parseInt(thearr[2]) == 0) {
					str_out += "<li><a href=\"/ordlista/?ord=" + thearr[0] + "\">" + thearr[1] + "</a></li>\n"
				} else {
					str_out += "<li id=\"theword\"><a href=\"/ordlista/?ord=" + thearr[0] + "\"><b>" + thearr[1] + "</b></a></li>\n"
				}
				if (globalfirstword == '') {
					globalfirstword = dodadecode(thearr[0]);
				}
				globallastword = dodadecode(thearr[0]);
			}
			
			str_out = '<ul>\n' + str_out + '</ul>';
			document.getElementById("closewords").innerHTML = str_out;
			str_out = '';
		}
	}
}

function getMailLink() {
	var s;
	s = 'ilto:inf';
	s = '<a href="ma'+ s;
	s += 'o@slangopedia.se" style="color:#fff;">in';
	return(s + 'fo@slangopedia.se</a>');
}

function getMailLinkBlack() {
	var s;
	s = 'ilto:inf';
	s = '<a href="ma'+ s;
	s += 'o@slangopedia.se">in';
	return(s + 'fo@slangopedia.se</a>');
}


// kommentarer


function comment(theid) {
	var d=new Date();
	$('#comments' + theid).toggle(250);
	$('#comments' + theid).addClass('comments');
	$('#commentscontent' + theid).html('<img src="/bilder/ajax-loader.gif" alt="Vänta..." border="0" />');
	$('#commentscontent' + theid).load('/kommentarer/xml.asp?id=' + theid + '&tid=' + d.getTime());
	return false;
}
	
function savecomment(theid) {

	var d=new Date();
	var f = document.forms['commentform' + theid];
	var n = $('[name=namn]', f).val();
	var k = $('[name=kommentar]', f).val();
	if (n != '' && k != '' && k != 'Kommentar...' && n != 'Ditt namn...') {
		$.post("/kommentarer/xml.asp?action=spara&id=" + theid, $(document.forms['commentform' + theid]).serialize());
		$('#commentscontent' + theid).load('/kommentarer/xml.asp?id=' + theid + '&tid=' + d.getTime());
	}
	return false;
}

function checkcommentfield(theobj, theid, theaction) {
	var o = $('[name=kommentar]', document.forms['commentform' + theid]);
	var v = o.val();
	
	if (v == 'Kommentar...' || v == '') {
		if (theaction == 'un') {
			o.val('Kommentar...');
			theobj.style.color = '#aaa';
		} else {
			theobj.value = '';
			theobj.style.color = '#000';
		}
	} else {
		theobj.style.color = '#000';
	}
}

function checknamefield(theobj, theid, theaction) {
	var o = $('[name=namn]', document.forms['commentform' + theid]);
	var v = o.val();
	
	if (v == 'Ditt namn...' || v == '') {
		if (theaction == 'un') {
			o.val('Ditt namn...');
			theobj.style.color = '#aaa';
		} else {
			theobj.value = '';
			theobj.style.color = '#000';
		}
	} else {
		theobj.style.color = '#000';
	}
}
