
function open_win(a,w,h) {
	window.open(a,'','toolbar=no,status=no,scrollbars=no,location=no,menubar=no,directories=no,width='+w+',height='+h)
}
function open_win2(a,w,h) {
	window.open(a,'','toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,width='+w+',height='+h)
}
function open_win_small(a,w,h) {
	window.open(a,'','toolbar=no,status=no,scrollbars=no,location=no,menubar=no,directories=no,width='+w+',height='+h)
}

// menu functions

var menuactive = false;
var currentmenu = 0;
function menuhover(n) {
	menuactive = true;
	currentmenu = n;
	document.getElementById('rolldownmenu'+n).style.display = 'inline';
}

function menuout(n) {
	menuactive = false;
	currentmenu = n;
	setTimeout("menutimeout("+n+")",100);
}

function menutimeout(n) {
	if(!menuactive) {
		document.getElementById('rolldownmenu'+n).style.display = 'none';
	} else if(n!=currentmenu) {
		document.getElementById('rolldownmenu'+n).style.display = 'none';
		currentmenu=n;	
	}
}

// video functions

var x,y;
document.onmousemove=getMousePos;
function getMousePos(e){
	if (navigator.appName == "Microsoft Internet Explorer") {
		x=event.x+document.body.scrollLeft;y=event.y+document.body.scrollTop;	
	} else {
		x=e.pageX;y=e.pageY;	
	}
}

function videovote(id,stars) {
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Din browser understøtter desværre ikke Javascript/AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			if(xmlHttp.responseText!='true') {
				alert("Der må kun stemmes en gang om dagen per video!");
			}
		}
	}
	xmlHttp.open("GET","vote_videos_send.php?id="+id+"&stars="+stars,true);
	xmlHttp.send(null);

	// hide stars
	document.getElementById('videovote').innerHTML = '&nbsp;&nbsp;&nbsp;<b>Stemme afsendt</b>';
	hidestar();
}
function picturevote(id,stars) {
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Din browser understøtter desværre ikke Javascript/AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			if(xmlHttp.responseText!='true') {
				alert("Der må kun stemmes en gang om dagen per billede serie!");
			}
		}
	}
	xmlHttp.open("GET","vote_pictures_send.php?id="+id+"&stars="+stars,true);
	xmlHttp.send(null);

	// hide stars
	document.getElementById('picturevote').innerHTML = '&nbsp;&nbsp;&nbsp;<b>Stemme afsendt</b>';
	hidestar();
}

var startext = new Array();
startext[0] = 'Virkelig skidt!';
startext[1] = 'Noget kedelig!';
startext[2] = 'Gennemsnitlig!';
startext[3] = 'Mums!';
startext[4] = 'Sublimt!';
function showstar(n) {
	document.getElementById('startext').style.top = y-30;
	document.getElementById('startext').style.left = x-50;
	document.getElementById('startext').style.display = 'block';
	document.getElementById('startext').innerHTML = (n+1)+' stjerner: '+startext[n];
	
}
function hidestar() {
	document.getElementById('startext').style.display = 'none';
}

var images = new Array();
function Array2D() {
	function setArray(length) { // set an array inside the object
		this.elem=new Array();
		for(i=0;i<length;i++) {
			this.elem[i]=null;
		}
	}
	this.setArray=setArray;
	this.elem=null; // our array
}

function loadthumb(n,type) {
	var typename = 'video';
	var folder = 'vthumbs';
	if(type==1) {
		typename = 'picture';
		folder = 'pthumbs';
	}
	images[n] = new Array2D();
  	images[n].setArray(10);
   	images[n].elem[0] = new Image;
   	images[n].elem[0].src = 'http://www.pornodownload.dk/images/'+folder+'/'+n+'/tb.jpg';
   	for(i=1; i<=10; i++) {
   		images[n].elem[i] = new Image;
     		images[n].elem[i].src = 'http://www.pornodownload.dk/images/'+folder+'/'+n+'/'+i+'.jpg';
   	}
}

var tb_number = 0;
var tb_type = '';
function tb_hover(n,type) {
	loadthumb(n,type);
	tb_number=n;
	tb_type=type;
	var typename = 'video';
	if(type==1) { typename = 'picture'; }
	document.getElementById(typename+n).src = eval('images['+n+'].elem[1].src');
	thumbslides = setInterval("slideshow("+n+",'"+typename+"')", 700);
}

function tb_out() {
	clearInterval(thumbslides);
	current_tb = 2;
	var typename = 'video';
	if(tb_type==1) { typename = 'picture'; }
	document.getElementById(typename+tb_number).src = eval('images['+tb_number+'].elem[0].src');
}

function open_video(id) {
	tb_out();
	top.location='showvideo.php?id='+id;
}
function open_video_bank(id) {
	tb_out();
	top.location='showvideo.php?id='+id+'&bank=1';
}

function open_pictures(id) {
	tb_out();
	top.location='showpictures.php?id='+id;
}


var current_tb = 2;
function slideshow(n,typename) {
	if (current_tb == 10) {
		current_tb = 1;
	}
	document.getElementById(typename+n).src = eval('images['+n+'].elem['+current_tb+'].src');
	current_tb++;
}

function showconditions() {
	if(document.getElementById('conditionsbox').style.display=='block') {
		document.getElementById('conditionsbox').style.display='none';
	}
	else {
		document.getElementById('conditionsbox').style.top = y+10;
		document.getElementById('conditionsbox').style.left = x-100;
		document.getElementById('conditionsbox').style.display = 'block';
	}
}
function closeconditions() {
	document.getElementById('conditionsbox').style.display = 'none';
}
function checksignup() {
	var submitform = true;

	// check username
	if(!(/^[a-zA-Z\d]+$/.test(document.getElementById('username').value)) || document.getElementById('username').value.length<6) {
		alert('Brugernavnet er enten for kort eller forkert sammensæt. Brug kun bogstaver og/eller tal!');
		submitform = false;
	}

	// check password
	else if(!(/^[a-zA-Z\d]+$/.test(document.getElementById('pw1').value)) || document.getElementById('pw1').value.length<6) {
		alert('Adgangskoden er enten for kort eller forkert sammensæt. Brug kun bogstaver og/eller tal!');
		submitform = false;
	}

	// check confirmed password
	else if(document.getElementById('pw1').value != document.getElementById('pw2').value) {
		alert('Den bekræftede adgangskode er ikke korrekt!');
		submitform = false;
	}

	// check nickname
	else if(!(/^[a-zA-Z\d]+$/.test(document.getElementById('nickname').value)) || document.getElementById('nickname').value.length<6) {
		alert('Profilnavn er enten for kort eller forkert sammensæt. Brug kun bogstaver og/eller tal!');
		submitform = false;
	}

	// check email
	else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('email').value)) || document.getElementById('email').value.length<6){
		alert("Email adressen er ugyldig!")
		submitform = false;
	}

	// check conditions
	else if(!document.getElementById('conditions').checked) {
		alert("Du skal godkende betingelserne for at blive medlem!")
		submitform = false;	
	}

	if(submitform) {
		document.getElementById('form').submit();
	}
}
function forgot_email() {
	// check email
	if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('email').value))){
		alert("Email adressen er ugyldig!");
	}
	else {
		document.getElementById('form').submit();
	}
}
function send_video_comment() {
	if(!document.commentform.nickname.value) {alert('Du skal være logget på for at skrive kommentarer!');}
	else if(document.commentform.comment.value=='') {
		alert('Skriv venligst en kommentar!');
	} else if((/(http|www|@|\.dk|\.se|\.com|\.no|\.de|\.nu|\.uk|\.es|\.it|\.cn|\.cc|\.ru|\.fr|\.nl|\.us|\.fi)/i.test(document.commentform.comment.value))) {
		alert('Din kommentar må ikke indeholde links til andre websites eller E-mail adresser!');
	} else {
		var xmlHttp;
		try {
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		} catch (e) {
			// Internet Explorer
			try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					alert("Din browser understøtter desværre ikke Javascript/AJAX!");
					return false;
				}
			}
		}
		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState==4) {
				if(xmlHttp.responseText=='true') {
					var new_comment = '<b>'+document.commentform.nickname.value+'</b> '+document.commentform.comment.value+'<div class="videocommentseperate"></div>';
					document.getElementById('videocomments').innerHTML += new_comment;
				} else {
					alert("Der må kun sendes en kommentar per video i timen!");
				}
				document.commentform.comment.value='';
			}
		}
		xmlHttp.open("GET","comment_video_send.php?videos_id="+document.commentform.videos_id.value+"&comment="+document.commentform.comment.value,true);
		xmlHttp.send(null);
	}
}
function send_picture_comment() {
	if(!document.commentform.nickname.value) {alert('Du skal være logget på for at skrive kommentarer!');}
	else if(document.commentform.comment.value=='') {
		alert('Skriv venligst en kommentar!');
	}
	else if((/(http|www|@|\.dk|\.se|\.com|\.no|\.de|\.nu|\.uk|\.es|\.it|\.cn|\.cc|\.ru|\.fr|\.nl|\.us|\.fi)/i.test(document.commentform.comment.value))) {
			alert('Din kommentar må ikke indeholde links til andre websites eller E-mail adresser!');
	} else {
		var xmlHttp;
		try {
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		} catch (e) {
			// Internet Explorer
			try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					alert("Din browser understøtter desværre ikke Javascript/AJAX!");
					return false;
				}
			}
		}
		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState==4) {
				if(xmlHttp.responseText=='true') {
					var new_comment = '<b>'+document.commentform.nickname.value+'</b> '+document.commentform.comment.value+'<div class="picturecommentseperate"></div>';
					document.getElementById('picturecomments').innerHTML += new_comment;
				} else {
					alert("Der må kun sendes en kommentar per billede serie i timen!");
				}
				document.commentform.comment.value='';
			}
		}
		xmlHttp.open("GET","comment_picture_send.php?pictures_id="+document.commentform.pictures_id.value+"&comment="+document.commentform.comment.value,true);
		xmlHttp.send(null);
	}
}
function show_add_favorite() {
	document.getElementById('favorite').style.top = y+10;
	document.getElementById('favorite').style.left = x-200;
	if(document.getElementById('favorite').style.display=='none' || document.getElementById('favorite').style.display=='') {
		document.getElementById('favorite').style.display='block';
	} else {
		document.getElementById('favorite').style.display='none';
	}
}
function add_favorite() {
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Din browser understøtter desværre ikke Javascript/AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			if(xmlHttp.responseText=='exist') {
				alert("Mediet eksisterer allerede blandt dine favoritter!");
			}
			else if(xmlHttp.responseText=='full') {
				alert("Du kan desværre ikke tilføje mediet, da dit favorit arkiv er fyldt op til grænsen på 100 medier. For at tilføje nye favoritter, slet da venligst nogle af de gamle.");
			}
		}
	}
	xmlHttp.open("GET","favorite_add.php?id="+document.getElementById('content_id').value+"&type="+document.getElementById('content_type').value+"&comment="+document.getElementById('favoritecomment').value);
	xmlHttp.send(null);
	document.getElementById('favorite').style.display='none';
	document.getElementById('favoritecomment').value='';
}
function show_edit_favorite(id,comment) {
	document.getElementById('favorite').style.top = y+10;
	document.getElementById('favorite').style.left = x-200;
	if(document.getElementById('favorite').style.display=='none' || document.getElementById('favorite').style.display=='') {
		document.getElementById('favorite').style.display='block';
		document.getElementById('content_id').value=id;
		document.getElementById('comment').value=comment;
	} else {
		document.getElementById('favorite').style.display='none';
	}
}
function favorite_edit () {
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Din browser understøtter desværre ikke Javascript/AJAX!");
				return false;
			}
		}
	}
	xmlHttp.open("GET","favorite_edit.php?content_id="+document.getElementById('content_id').value+"&content_type="+document.getElementById('content_type').value+"&comment="+document.getElementById('comment').value);
	xmlHttp.send(null);
	document.getElementById('favorite').style.display='none';
	document.getElementById('comment'+document.getElementById('content_id').value).innerHTML=document.getElementById('comment').value;
	document.getElementById('comment').value='';
}
function favorite_delete (id,type) {
	var ok = confirm('Er du sikker på, du vil slette favoritten?');
	if(ok) {
		var xmlHttp;
		try {
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		} catch (e) {
			// Internet Explorer
			try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					alert("Din browser understøtter desværre ikke Javascript/AJAX!");
					return false;
				}
			}
		}
		xmlHttp.open("GET","favorite_delete.php?id="+id+"&type="+type);
		xmlHttp.send(null);
		window.location=top.location;
	}
}
function favorite_bank(id) {
	var ok = confirm('Er du sikker på, du vil føje denne favorit til din opsparing?');
	if(ok) {
		var xmlHttp;
		try {
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		} catch (e) {
			// Internet Explorer
			try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					alert("Din browser understøtter desværre ikke Javascript/AJAX!");
					return false;
				}
			}
		}
		xmlHttp.onreadystatechange=function() {
			if(xmlHttp.readyState==4) {
				if(xmlHttp.responseText=='exist') {
					alert("Videoen eksisterer allerede i din opsparing!");
				}
				else if(xmlHttp.responseText=='full') {
					alert("Du har allerede lagt en video i din opsparing idag. Du kan først tilføje den næste i morgen!");
				}
				else if(xmlHttp.responseText=='max') {
					alert("Du er desværre nået dit maximum på 10 videoer i opsparingen. Du kan dog slette fra opsparingen og gøre plads til nye videoer.");
				}
			}
		}
		xmlHttp.open("GET","favorite_bank.php?id="+id);
		xmlHttp.send(null);
	}
}
function bank_delete (id) {
	var ok = confirm('Er du sikker på, du vil slette denne video fra opsparingen?');
	if(ok) {
		var xmlHttp;
		try {
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		} catch (e) {
			// Internet Explorer
			try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					alert("Din browser understøtter desværre ikke Javascript/AJAX!");
					return false;
				}
			}
		}
		xmlHttp.open("GET","bank_delete.php?id="+id);
		xmlHttp.send(null);
		window.location=top.location;
	}
}
var newmovurl;
function makevideourl(id,purl) {
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Din browser understøtter desværre ikke Javascript/AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			newmovurl = eval(xmlHttp.responseText);
		}
	}
	xmlHttp.open("GET","getvideourl.php?id="+id+"&purl="+purl);
	xmlHttp.send(null);
	return newmovurl;
}
function showtipmail() {
	if(document.getElementById('tipmail').style.display=='block') {
		document.getElementById('tipmail').style.display='none';
	}
	else {
		document.getElementById('tipmail').style.top = y+10;
		document.getElementById('tipmail').style.left = x-100;
		document.getElementById('tipmail').style.display = 'block';
	}
}
function closetipmail() {
	document.getElementById('tipmail').style.display = 'none';
}

var shown = 0;
function show_answer(n,obj) {
	if(shown==0) {
		document.getElementById('faqanswer').style.top = y+10;
		document.getElementById('faqanswer').style.left = x-50;
		document.getElementById('faqanswer').style.display='block';
		document.getElementById('faqanswertext').innerHTML=answers[n];
		shown=1;
	} else {
		close_answer();
	}
}
function close_answer() {
		document.getElementById('faqanswer').style.display='none';
		shown = 0;
}


