﻿function recommend() {
		var thislocation = window.location.href;
			window.open('/send/recommend.php?page='+ thislocation, 'recommendpage', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=500,left=400,top=262');
}
function delicious() {
	var title = document.title.split(' | ')[2];
	window.open('http://del.icio.us/post/?url=' + encodeURIComponent(location.href)+'&title='+encodeURIComponent(title), '_blank');
}
function diggThis() {
	var title = document.title.split(' | ')[2];
	window.open('http://digg.com/submit?phase=2&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(title)+'&topic=videos_comedy','_blank');
}
function sendaim() {
	window.open(location.href='aim:goim?screenname=Choose+a+buddy+from+this+box&message=' + location.href, '_self');
}
function urlEncode(str) {
	var result = "";
	for (i = 0; i < str.length; i++) {
		if (str.charAt(i) == " ") result += "+";
		else result += str.charAt(i);
	}
	return result;
}
function contact() {
	window.open(location.href='/contact/?ref=' + encodeURIComponent(location.href), '_self');
}
function loadSuggest() {
	var suggest = document.getElementById('suggest');
	if (suggest) {
		var urlInput = document.createElement('input');
		urlInput.setAttribute('name', 'url');
		urlInput.setAttribute('type', 'text');
		urlInput.setAttribute('value', 'Suggest a Link');
		urlInput.id = "suggest-url";
		var submitButton = document.createElement('input');
		submitButton.setAttribute('name', 'Submit');
		submitButton.setAttribute('type', 'submit');
		submitButton.setAttribute('value', 'Suggest a Link');
		submitButton.onclick = function() {
			if (!f) {
				var submitUrl = document.getElementById('suggest-url');
				content = "url=" + urlEncode(submitUrl.value);
				http.open("POST", "/dev/suggest/suggest.php", true);
				http.onreadystatechange = function() {
					if ((http.readyState == 4) && (http.status == 200)) {
						var response = http.responseText;
						if (response == "true") {
							document.getElementById('suggest-url').value = "";
							document.getElementById('suggest-message').innerHTML = "Thank You!";
						}
					}
					f = false;
				};
				http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				http.setRequestHeader('Accept','text/xml');
				http.send(content);
				f = true;
			}
		}
		var message = document.createElement('div');
		message.id = "suggest-message";
		suggest.appendChild(message);
		suggest.appendChild(urlInput);
		suggest.appendChild(submitButton);
	}
}

var f = false;
var http = XMLHTTPObject(); // Create the XMLHttpRequest Object.

function XMLHTTPObject() {
	var xmlhttp = null;
		
	if (window.ActiveXObject) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (ex1) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (ex2) {
				// do nothing
			}
		}
	} else if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}
	
	return xmlhttp;
}
