//======================================================================================================================================================================
//Validation Functions === Validation Functions === Validation Functions === Validation Functions === Validation Functions === Validation Functions === Validation Funct
//Validation Functions === Validation Functions === Validation Functions === Validation Functions === Validation Functions === Validation Functions === Validation Funct
//Validation Functions === Validation Functions === Validation Functions === Validation Functions === Validation Functions === Validation Functions === Validation Funct
//======================================================================================================================================================================

//Function to validate the insert personal comment form
function valinsertusercomment()
{
	x = document.insertComment1
	comment = x.comment1.value
	userlogin = x.userLogin.value
	member = x.member.value
	
	if(userlogin == 0)
	{
		alert("Please log-in to place your comment")
		return false
	}
	if(userlogin == member)
	{
		alert("It is not possible to leave a comment for yourself!")	
		return false
	}
	else if(comment.length == 0)
	{
		alert("Please enter your comment. Thank you!")
		return false
	}
	else
	{
		return true;
	}
}

//Function to validate the insert comment form
function valinsertcomment()
{
	x = document.insertCommentForm
	comment = x.comment.value
	userlogin = x.userLogin.value
	
	if(userlogin == 0)
	{
		alert("Please log-in to place your comment")
		return false
	}
	else if(comment.length == 0)
	{
		alert("Please enter your comment. Thank you!")
		return false
	}
	else
	{
		return true;
	}
}

//Function to validate the send message form
function valsendmessage()
{
	x = document.sendMessage
	comment = x.message.value
	subject = x.subject.value
	if(subject.length == 0)
	{
		alert("Please the subject of the message. Thank you!")
		return false
	}
	if(comment.length == 0)
	{
		alert("Please enter your message. Thank you!")
		return false
	}
	else
	{
		return true;
	}
}

//Function to validate the top login form
function vallogin()
{
	x = document.loginForm
	email = x.eMail.value
	password = x.password.value
	
	if(email.length == 0)
	{
		alert("Please enter your E-Mail to login. Thank you!")
		return false
	}
	else if(!email.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/))
	{
		alert("Please enter a valid E-Mail. Thank you!")
		return false	
	}
	else if(password.length == 0)
	{
		alert("Please enter your password to login. Thank You!")
		return false
	}
	else
	{
		return true;
	}
}

//Function to validate the login.php page
function vallogin2()
{
	x = document.loginForm2
	email = x.eMail.value
	password = x.password.value
	
	if(email.length == 0)
	{
		alert("Please enter your E-Mail to login. Thank you!")
		return false
	}
	else if(!email.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/))
	{
		alert("Please enter a valid E-Mail. Thank you!")
		return false	
	}
	else if(password.length == 0)
	{
		alert("Please enter your password to login. Thank You!")
		return false
	}
	else
	{
		return true;
	}
}

//Function to validate the register form
function valregister()
{
	x = document.register
	firstname = x.first.value
	lastname = x.last.value
	username = x.username.value
	email = x.email.value
	dob = x.dob.value
	
	if(firstname.length == 0)
	{
		alert("Please enter your first name. Thank you!")
		return false
	}
	else if(lastname.length == 0)
	{
		alert("Please enter your last name. Thank you!")
		return false
	}
	else if(username.length == 0)
	{
		alert("Please enter a desired username. Thank you!")
		return false
	}
	else if(username.length < 6)
	{
		alert("Username has to be at least 6 characters long. Thank you!")
		return false
	}
	else if(username.length > 25)
	{
		alert("Username can't be longer than 25 characters. Thank you!")
		return false
	}
	else if(!username.match(/^[0-9a-zA-Z]+$/))
	{
		alert("Username can only exist of letters and numbers. Thank you!")
		return false;
	}
	else if(email.length == 0)
	{
		alert("Please enter your E-Mail. Thank you!")
		return false
	}
	else if(!email.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/))
	{
		alert("Please enter a valid E-Mail. Thank you!")
		return false	
	}
	else if(dob.length == 0)
	{
		alert("Please enter your date of birth. Thank you!")
		return false
	}
	else
	{
		return true;
	}
}

//Function to validate the contact form
function valcontact()
{
	x = document.contact
	naam = x.naam.value
	email = x.email.value
	onderwerp = x.onderwerp.value
	tekst = x.tekst.value
	
	if(naam.length == 0)
	{
		alert("Please insert your full name")
		return false
	}
	else if(email.length == 0)
	{
		alert("Please insert your E-Mail")
		return false
	}
	else if(!email.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/))
	{
		alert("Please insert a valid E-Mail")
		return false
	}
	else if(onderwerp.length == 0)
	{
		alert("Please insert a subject")
		return false
	}
	else if(tekst.length == 0)
	{
		alert("Please insert your message")
		return false
	}
	else
	{
		return true;
	}
}

//Function to validate the retreive password form
function valgetpass()
{
	x = document.getPass
	email = x.email.value
	if(email.length == 0)
	{
		alert("Please insert your E-Mail to retreive your password.")
		return false
	}
	else if(!email.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/))
	{
		alert("Please insert a valid E-Mail so you can retreive your password.")
		return false
	}
	else
	{
		return true;
	}
}

//Function to confirm that you want to delete a media
//Function to confirm that you want to accept a certain comment
function confirmdeletemedia(type, page, name) 
{
	var answer = confirm("Are you sure you want to delete "+name+" from your list of uploaded "+type+"?")
	if (answer)
	{
		alert(name +" has been deleted from your list of "+type+"!")
		window.location = page
	}
	else
	{
		alert("No problem, we all make mistakes!")
	}
}

//Function to add tag
function confirmtag(picid, memid) 
{
	var answer = confirm("Are you sure you want to tag this picture?")
	if (answer)
	{
		alert(name +" has been deleted from your list of "+type+"!")
		//window.location = page
	}
	else
	{
		alert("No problem, we all make mistakes!")
	}
}

//Function to confirm that you want to accept a certain comment
function confirmacceptcomment(username, cid) 
{
	var answer = confirm("Are you sure you want to accept this comment from "+ username +"?")
	if (answer)
	{
		alert("Comment added to your comments list!")
		window.location = 'getMyComments.php?x=1&cid='+ cid
	}
	else
	{
		alert("No problem, we all make mistakes!")
	}
}

//Function to confirm that you want to delete a certain comment
function confirmdeletecomment(username, cid) 
{
	var answer = confirm("Are you sure you want to delete this comment from "+ username +"?")
	if (answer)
	{
		alert("Comment deleted succesfully!")
		window.location = 'getMyComments.php?x=2&cid='+ cid
	}
	else
	{
		alert("No problem, we all make mistakes!")
	}
}

//Function to confirm that you want to add someone as friend
function confirmaddfriend(username, userlogin, memberid, total) 
{
	var answer = confirm("Are you sure you want to add "+ username +" to your friends list?")
	if(userlogin == 0)
	{
		alert("Please login to add "+ username +" as friend")
		return false
	}
	else if(total != 0)
	{
		alert("You have already sent a request to "+username)
		return false
	}
	else if(userlogin == memberid)
	{
		alert("It is not possible to add yourself as friend!")
		return false
	}
	else if(userlogin != 0)
	{
		if (answer)
		{
			alert("A friend request has been sent to "+username+"!")
			preload('navigation/getFriends.php?t=20&x=1&u='+ userlogin+'&memberId='+memberid, 'updateDiv')
		}
		else
		{
			alert("No problem, we all make mistakes!")
			preload('profile.php?m='+memberid, 'main')
		}
	}
	else
	{
		return true;	
	}
}

//Function to confirm that you want to accept a certain friend request
function confirmacceptfriend(username, fid) 
{
	var answer = confirm("Are you sure you want to add "+ username +" as a friend?")
	if (answer)
	{
		alert(username +" added succesfully to your friends list!")
		window.location = 'getMyFriends.php?x=1&fid='+fid
	}
	else
	{
		alert("No problem, we all make mistakes!")
	}
}

//Function to confirm that you want to accept a certain friend request
function confirmdeletefriend(username, fid) 
{
	var answer = confirm("Are you sure you want to reject "+ username +" as a friend?")
	if (answer)
	{
		alert(username +" rejected from your friends list!")
		window.location = 'getMyFriends.php?x=2&fid='+fid
	}
	else
	{
		alert("No problem, we all make mistakes!")
		preload('userFriends.php', 'main')
	}
}

//Function to confirm that you want to delete a picture from a album
function confirmdeletepicture(pid, aid) 
{
	var answer = confirm("Are you sure you want to delete this picture from this album?")
	if (answer)
	{
		alert("Picture deleted!")
		window.location = 'editAlbums.php?x=2&aid='+aid+'&pid='+pid
	}
	else
	{
		alert("No problem, we all make mistakes!")
	}
}

//Function to validate the upload video form
function valuploadvideo()
{
	x = document.uploadVideo
	name = x.videoName.value
	descr = x.videoDescr.value
	tags = x.videoTags.value
	group = x.videoGroup.value
	file = x.file.value
	
	if(name.length == 0)
	{
		alert("Please enter a name for your video. Thank you!")
		return false
	}
	else if(descr.length == 0)
	{
		alert("Please enter a description for your video. Thank you!")
		return false
	}
	else if(tags.length == 0)
	{
		alert("Please enter one or two keywords as tags for your video. Thank you!")
		return false
	}
	else if(group.length == 0)
	{
		alert("Please select a group for your video. Thank you!")
		return false
	}
	else if(file.length == 0)
	{
		alert("Please select a video to upload. Thank you!")
		return false
	}
	else
	{
		return true;
	}
}

//Function to validate the upload video form
function valuploadaudio()
{
	x = document.uploadAudio
	name = x.audioName.value
	artist = x.audioArtist.value
	tags = x.audioTags.value
	group = x.audioGenre.value
	file = x.file.value
	
	if(name.length == 0)
	{
		alert("Please enter a name for your audio. Thank you!")
		return false
	}
	else if(artist.length == 0)
	{
		alert("Please enter an artist for your audio. Thank you!")
		return false
	}
	else if(tags.length == 0)
	{
		alert("Please enter one or two keywords as tags for your audio. Thank you!")
		return false
	}
	else if(group.length == 0)
	{
		alert("Please select a genre for your audio. Thank you!")
		return false
	}
	else if(file.length == 0)
	{
		alert("Please select an audio to upload. Thank you!")
		return false
	}
	else
	{
		return true;
	}
}

//Function to validate the edit personal page
function valeditpers()
{
	x = document.editPersonal
	firstname = x.first.value
	lastname = x.last.value
	dob = x.dob.value
	
	if(firstname.length == 0)
	{
		alert("Please enter your first name. Thank you!")
		return false
	}
	else if(lastname.length == 0)
	{
		alert("Please enter your last name. Thank you!")
		return false
	}
	else if(dob.length == 0)
	{
		alert("Please enter your date of birth. Thank you!")
		return false
	}
	else
	{
		return true;
	}
}

//Function to validate the change password page
function valchangepassword()
{
	x = document.changePassword
	old = x.old.value
	newpass = x.newPass.value
	newpass2 = x.newPass2.value
	
	if(old.length == 0)
	{
		alert("Please enter your old password. Thank you!")
		return false
	}
	else if(newpass.length == 0)
	{
		alert("Please enter your new password. Thank you!")
		return false
	}
	else if(newpass2.length == 0)
	{
		alert("Please confirm your new password. Thank you!")
		return false
	}
	else if(newpass2 != newpass)
	{
		alert("Confirmation password and new passord need to be the same. Thank you!")
		return false
	}
	else
	{
		return true;
	}
}

//Function to validate the edit avatar page
function valchangeavatar()
{
	x = document.form1
	file = x.file.value
	
	if(file.length == 0)
	{
		alert("Please select a picture to upload for your display. Thank you!")
		return false
	}
	else
	{
		return true;
	}
}

//Function to validate the add picture page
function valaddpic()
{
	x = document.addPicture
	album = x.album.value
	file = x.file.value
	
	if(album.length == 0)
	{
		alert("Please select an album to upload a picture. Thank you!")
		return false
	}
	if(file.length == 0)
	{
		alert("Please select a picture to upload. Thank you!")
		return false
	}
	else
	{
		return true;
	}
}

//Function to validate the edit avatar page
function valnewalbum()
{
	x = document.newAlbum
	name = x.albumName.value
	
	if(name.length == 0)
	{
		alert("Please insert a name for your album. Thank you!")
		return false
	}
	else
	{
		return true;
	}
}

//Function to confirm that you want to delete an album
function confirmdeletealbum(aid, total) 
{
	if(total > 0)
	{
		alert("Please delete all the picture from this album before deleting the album. Thank you!")
		return false
	}
	else
	{
		var answer = confirm("Are you sure you want to delete this album?")
		if (answer)
		{
			alert("Album deleted!")
			window.location = 'editAlbums.php?x=1&aid='+aid
		}
		else
		{
			alert("No problem, we all make mistakes!")
		}
	}

}

//Function to confirm that you want to delete an album
function confirmmsg(m, u, un) 
{
	if(u == m)
	{
		alert("It is not possible to send yourself a message!")
		return false
	}
	if(u == 0)
	{
		alert("Please login to send a personal message to "+un+"!")
		return false
	}
	else
	{
		toggleDiv('div1',1)
	}
}

//Function to validate the send message page
function valsendmsg()
{
	x = document.insertComment
	message = x.comment.value
	subject = x.subject.value
	
	if(subject.length == 0)
	{
		alert("Please insert a subject for this message. Thank you!")
		return false
	}
	else if(message.length == 0)
	{
		alert("Please insert a message. Thank you!")
		return false
	}
	else
	{
		return true;
	}
}

//Function to confirm that you want to delete a message
function confirmdelmsg(mid)
{
	var answer = confirm("Are you sure you want to delete this message?")
	if (answer)
	{
		alert("Message deleted!")
		window.location = 'getInbox.php?x=1&mid='+mid
	}
	else
	{
		alert("No problem, we all make mistakes!")
	}
}

//Function to confirm that you want to delete certain picture in the events gallery
function confirmdeleteeventpicture(pid, eid, page)
{
	var answer = confirm("Are you sure you want to delete this picture?")
	if (answer)
	{
		alert("Picture deleted!")
		window.location = 'pic.php?x=1&eid='+eid+'&pid='+pid+'&page='+page
	}
	else
	{
		alert("No problem, we all make mistakes!")
	}
}
//======================================================================================================================================================================
//Preloading Functions === Preloading Functions === Preloading Functions === Preloading Functions === Preloading Functions === Preloading Functions === Preloading Funct
//Preloading Functions === Preloading Functions === Preloading Functions === Preloading Functions === Preloading Functions === Preloading Functions === Preloading Funct
//Preloading Functions === Preloading Functions === Preloading Functions === Preloading Functions === Preloading Functions === Preloading Functions === Preloading Funct
//=====================================================================================================================================================================

//Function to process an XMLHttpRequest
function preload(serverPage, obj)
{
	toPage = obj
	preloadMsg('', toPage);
	document.getElementById(obj).style.visibility = "visible";
	
	xmlhttp = getxmlhttp();
	xmlhttp.open("GET", serverPage, true);
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			document.getElementById(obj).innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

//Function to output a loading image and message
function preloadMsg(msg, obj)
{
	hidden = document.getElementById(obj);
	hidden.innerHTML = 'Loading...';
}//Function to process an XMLHttpRequest

//Preloader for other pages
function preload2(serverPage, obj)
{
	preloadMsg2('<span class="textSeven">Loading...</span>');
	document.getElementById(obj).style.visibility = "visible";
	
	xmlhttp = getxmlhttp();
	xmlhttp.open("GET", serverPage, true);
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			document.getElementById(obj).innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

//Function to output a loading image and message
function preloadMsg2(msg)
{
	hidden = document.getElementById('main2');
	hidden.innerHTML = msg;
}

//Function to process an XMLHttpRequest
function preload3(serverPage, obj)
{
	preloadMsg3('Loading...');
	document.getElementById(obj).style.visibility = "visible";
	
	xmlhttp = getxmlhttp();
	xmlhttp.open("GET", serverPage, true);
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			document.getElementById(obj).innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

//Function to output a loading image and message
function preloadMsg3(msg)
{
	hidden = document.getElementById('main3');
	hidden.innerHTML = ' <img src="../images/preloader3.gif" alt="" /> </br>' + msg;
}

//Function to process an XMLHttpRequest
function preload4(serverPage, obj)
{
	preloadMsg4('');
	document.getElementById(obj).style.visibility = "visible";
	
	xmlhttp = getxmlhttp();
	xmlhttp.open("GET", serverPage, true);
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			document.getElementById(obj).innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

//Function to output a loading image and message
function preloadMsg4(msg)
{
	hidden = document.getElementById('main4');
	hidden.innerHTML = ' <img src="../images/preloader3.gif" alt="" /> </br>' + msg;
}
//=====================================================================================================================================================================
//Form & Process Ajax Functions === Form & Process Ajax Functions === Form & Process Ajax Functions === Form & Process Ajax Functions === Form & Process Ajax Functions 
//Form & Process Ajax Functions === Form & Process Ajax Functions === Form & Process Ajax Functions === Form & Process Ajax Functions === Form & Process Ajax Functions
//Form & Process Ajax Functions === Form & Process Ajax Functions === Form & Process Ajax Functions === Form & Process Ajax Functions === Form & Process Ajax Functions
//=====================================================================================================================================================================

//Function for insertion of smillies in textarea
function addsmilietext(val)
{
	var txtArea = document.getElementById('comment').value += val;
	txtArea.value = val;
}

//Function for insertion of smillies in textarea
function addsmilietextcom(val)
{
	var txtArea = document.getElementById('comment1').value += val;
	txtArea.value = val;
}

//Functions to submit a form
function getformvalues(fobj, valfunc)
{
	var str = "";
	aok = true;
	var val;
	
	//Run through a list of all objects contained within the form
	for(var i = 0; i < fobj.elements.length; i++)
	{
		if(valfunc)
		{
			if(aok == true)
			{
				val = valfunc(fobj.elements[i].value,fobj.elements[i].name);
				if(val == false)
				{
					aok = false;
				}
			}
		}
		str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
	}
	//Then return the string values
	return str;
}

//Function to submit a form
function submitform(theform, serverPage, objID, valfunc)
{
	var file = serverPage;
	var str = getformvalues(theform, valfunc);
	//If validation is o.k.
	if(aok == true)
	{
		obj = document.getElementById(objID);
		processajax(serverPage, obj, "post", str);
	}
}

//Function to process an XMLHttpRequest
function processajax(serverPage, obj, getOrPost, str)
{
	//Get an XMLHttpRequest object for use.
	xmlhttp = getxmlhttp();
	if(getOrPost == "get")
	{
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function()
		{
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
			{
				obj.innerHTML = xmlhttp.respnseText;
			}
		}
		xmlhttp.send(null);
	}
	else
	{
		xmlhttp.open("POST", serverPage, true);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.onreadystatechange = function()
		{
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
			{
				obj.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(str);
	}
}

//Function to create an XMLHttp object
function getxmlhttp()
{
	//Create boolean variable to check for a valid Microsoft active x instance
	var xmlhttp = false;
	
	//Check if we are using microsoft internet explorer
	try
	{
		//Javascript greater than 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		//If not the use older active x object.
		try
		{
			//Are we using Microsoft internet explorer
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E)
		{
			//We must be using a non microsoft browser
			xmlhttp = false;
		}
	}
	//If we are not using IE create a javascript instance of the object.
	if(!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

//======================================================================================================================================================================
//Other Functions === Other Functions === Other Functions === Other Functions === Other Functions === Other Functions === Other Functions === Other Functions === Other 
//Other Functions === Other Functions === Other Functions === Other Functions === Other Functions === Other Functions === Other Functions === Other Functions === Other
//Other Functions === Other Functions === Other Functions === Other Functions === Other Functions === Other Functions === Other Functions === Other Functions === Other
//======================================================================================================================================================================
function selectall()
{
	var text_val=eval("document.formEmbed.embed");
	text_val.focus();
	text_val.select();	
}

function goAnchor(id_elem)
{
  document.getElementById(id_elem).scrollIntoView(true);
}
function popDiv(id,flagit) {
if (flagit=="1"){
if (document.layers) document.layers[''+id+''].visibility = "show"
else if (document.all) document.all[''+id+''].style.visibility = "visible"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
}
else
if (flagit=="0"){
if (document.layers) document.layers[''+id+''].visibility = "hide"
else if (document.all) document.all[''+id+''].style.visibility = "hidden"
else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
}
}
//======================================================================================================================================================================
//Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === N
//Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === N
//Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === Not Secure === N
//======================================================================================================================================================================