/* ---------------------------- */
/* XMLHTTPRequest Enable 		  */
/* ---------------------------- */

function createObject() 
{
	var request_type;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer")
	{
		request_type = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		request_type = new XMLHttpRequest();
	}
	return request_type;
}

var http = createObject();


/* -------------------------- */
/* LOGIN 							*/
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */

var nocache = 0;

function login()
{		
	// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
	var email = encodeURI(document.getElementById('emailLogin').value);
	var psw = encodeURI(document.getElementById('pswLogin').value);

	var url = "login.php";
	var params = 'email='+email+'&psw='+psw;
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{
		//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			loginReply();
		}
	}
	http.send(params);
}


function loginReply() 
{
	if(http.readyState == 4)
	{	
		var response = http.responseText;
		if(response == 'noemail')
		{
			// if email not in db
			var status = 'error';
			var message = 'email address is not valid';
			showStatusBox(status, message, 'login');
			new Effect.Highlight('emailLogin', 
				{
					startcolor: "#FF00CD",
					duration: .7
				 });
		}
		else if(response == 'nopassword')
		{
			// if incorrect password
			var status = 'error';
			var message = 'password is incorrect';
			showStatusBox(status, message, 'login');
			new Effect.Highlight('pswLogin', 
				{
					startcolor: "#FF00CD",
					duration: .7
				 });
		}
		else if(response == 'Unable to Select Database')
		{
			var status = 'error';
			var message = 'unable to connect to database';
			showStatusBox(status, message, 'main');
		}
		else if(response == 'noaccess')
		{
			var status = 'error';
			var message = 'parameters not sent';
			showStatusBox(status, message, 'main');		
		}
		else if(response == 'success')
		{
			document.getElementById('logindisplay').style.display = "none";
			var status = 'success';
			var message = 'logging in... page will refresh in a second or <a href="">manually reload page</a>';
			showStatusBox(status, message, 'main');
			refreshPage(1000);					
		}
		else 
		{
			var status = 'error';
			var message = 'unknown exception';
			showStatusBox(status, message, 'main');
		}
		document.getElementById('pswLogin').value = '';
	}
}

/* -------------------------- */
/* LOGOUT 							*/
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */

function logout()
{		
	var url = "logout.php";
	var params = '';
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{
		//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			logoutReply();
		}
	}
	http.send(params);
}

function logoutReply() 
{
	if(http.readyState == 4)
	{	
		var response = http.responseText;
		if(response == 'noaccess')
		{
			var status = 'error';
			var message = 'parameters not sent';
			showStatusBox(status, message, 'main');		
		}
		else if(response == 'success')
		{
			var status = 'success';
			var message = 'logging out... page will refresh in a second or <a href="">manually reload page</a>';
			showStatusBox(status, message, 'main');
			refreshPage(1000);					
		}
		else 
		{
			var status = 'error';
			var message = 'unknown exception';
			showStatusBox(status, message, 'main');
		}
	}
}

/*----------------
Mailing List Email
------------------*/

function sendMailingListEmail()
{
	
	// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
	var from = encodeURI(document.getElementById('ml_from').value);
	var to = encodeURI(document.getElementById('ml_to').vaule);
	var subject = encodeURI(document.getElementById('ml_subject').value);

  	var url = "addtomailinglist.php";
	var params = 'from=' + from + '&to=' + to+ '&subject=' +subject;
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{	
		//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			checkMailStatus(from);
		}
	}
	http.send(params);
}

function checkMailStatus(email)
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response == 'noaccess')
		{
			var status = 'error';
			var message = 'parameters not sent';
			showStatusBox(status, message, 'main');	
		} 
		else if(response == 'success')
		{
			var status = 'success';
			var message = 'Thank you! ' + email + ' will be added to our mailing list shortly!';
			showStatusBox(status, message, 'join');			
		}
		else
		{
			var status = 'error';
			var message = 'unknown exception';
			showStatusBox(status, message, 'main');			
		}
		//reset form fields
		document.mailinglist.reset();		
	}	
}

/*----------------
Contact us email
------------------*/

function contactEmail()
{
	
	 var from = encodeURI(document.getElementById('from').value);
	 var to = encodeURI(document.getElementById('to').value);
	 var fromname = encodeURI(document.getElementById('fromname').value);
	 var subject = encodeURI(document.getElementById('subject').value);
	 var message = encodeURI(document.getElementById('message').value);
	 var to = encodeURI(document.getElementById('to').value);
	 

	 
	var url = "contactemail.php";
	var params = 'from=' + from + '&fromname=' + fromname + '&to=' + to + '&subject=' + subject + '&message=' + message;
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{		
		//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			checkContactUsStatus();
		}
	}
	http.send(params);
}

function checkContactUsStatus()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response == 'noaccess')
		{
			var status = 'error';
			var message = 'parameters not sent';
			showStatusBox(status, message, 'main');	
		} 
		else if(response == 'success')
		{
			var status = 'success';
			var message = 'Thank you for your email, we will get back to you as soon as possible.';
			showStatusBox(status, message, 'main');			
		}
		else
		{
			var status = 'error';
			var message = 'unknown exception';
			showStatusBox(status, message, 'main');			
		}
		//reset contact us fields
		document.contactform.reset();
	}	
}

/*----------------
Create Event Item Regular
-----------------*/

function createEvent()
{
	// Required: verify that all fields are not empty.  Use encodeURI() to solve some issues about character encoding.
	var title = encodeURI(document.getElementById('formfieldTitle').value);
	var host = encodeURI(document.getElementById('formfieldHost').value);
	var location = encodeURI(document.getElementById('formfieldLocation').value);
	var time = encodeURI(document.getElementById('formfieldTime').value);
	var type = encodeURI(document.getElementById('formfieldEventType').value);
	var restrictions = encodeURI(document.getElementById('formfieldRestrictions').value);
	var address = encodeURI(document.getElementById('formfieldAddress').value);
	var description = encodeURI(document.getElementById('formfieldDescription').value);
	var banner = encodeURI(document.getElementById('formbannerlink').value);
	var poster = encodeURI(document.getElementById('formposterlink').value);


	
	var startMonth = encodeURI(document.getElementById('formfieldStartMonth').value);
	if(startMonth.length == 1)
	{
		startMonth = '0' + startMonth;
	}
	var startDay = encodeURI(document.getElementById('formfieldStartDay').value);
	if(startDay.length == 1)
	{
		startDay = '0' + startDay;
	}
	var startYear = encodeURI(document.getElementById('formfieldStartYear').value);
	var startDate = startYear + '-' + startMonth + '-' + startDay;
	
	var endMonth = encodeURI(document.getElementById('formfieldEndMonth').value);
	if(endMonth.length == 1)
	{
		endMonth = '0' + endMonth;
	}
	var endDay = encodeURI(document.getElementById('formfieldEndDay').value);
	if(endDay.length == 1)
	{
		endDay = '0' + endDay;
	}
	var endYear = encodeURI(document.getElementById('formfieldEndYear').value);
	var endDate = endYear + '-' + endMonth + '-' + endDay;

	var url = "createEvent.php";
	var params = 'title=' + title + '&description=' + description + '&startDate=' + startDate + '&endDate=' + endDate + '&host=' + host + '&location=' + location + '&time=' + time + '&type=' + type + '&restrictions=' + restrictions + '&startDate=' + startDate + '&endDate=' + endDate + '&address=' + address + '&banner=' + banner + '&poster=' + poster;
	http.open("POST", url, true);
	
	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	
	http.onreadystatechange = function() 
	{
		//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			checkEvents();
		}
	}
	http.send(params);

}
function checkEvents()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response == 'noaccess')
		{
			var status = 'error';
			var message = 'parameters not sent';
			showStatusBox(status, message, 'main');
			document.addEvent.reset();
		}
		else if(response == 'Unable to Select Database')
		{
			var status = 'error';
			var message = 'unable to connect to database';
			showStatusBox(status, message, 'events');
		}
		else if(response == 'notadmin')
		{
			var status = 'error';
			var message = 'You must be logged in as an admin to post news.<br />Reloading page in a second or <a href="">manually reload page</a>.';
			showStatusBox(status, message, 'main');
			document.addEvent.reset();
			refreshPage(1000);				
		}
		else if(response == 'success')
		{
			var status = 'success';
			var message = 'Posting news item. Reloading page in a second or <a href="">manually reload page</a>.';
			showStatusBox(status, message, 'main');
			document.addEvent.reset();
			refreshPage(1000);	
		}
		else 
		{
			var status = 'error';
			var message = 'unknown exception';
			showStatusBox(status, message, 'main');	
		}
	}
}

/*------------------
Edit Event Regular
-------------------*/

function editEventAJAX(eventID)
{
	var title = encodeURI(document.getElementById('formfieldTitle').value);
	var host = encodeURI(document.getElementById('formfieldHost').value);
	var location = encodeURI(document.getElementById('formfieldLocation').value);
	var time = encodeURI(document.getElementById('formfieldTime').value);
	var type = encodeURI(document.getElementById('formfieldEventType').value);
	var restrictions = encodeURI(document.getElementById('formfieldRestrictions').value);
	var address = encodeURI(document.getElementById('formfieldAddress').value);
	var description = encodeURI(document.getElementById('formfieldDescription').value);
	var banner = encodeURI(document.getElementById('formbannerlink').value);
	var poster = encodeURI(document.getElementById('formposterlink').value);
	
	var startMonth = encodeURI(document.getElementById('formfieldStartMonth').value);
	if(startMonth.length == 1)
	{
		startMonth = '0' + startMonth;
	}
	var startDay = encodeURI(document.getElementById('formfieldStartDay').value);
	if(startDay.length == 1)
	{
		startDay = '0' + startDay;
	}
	var startYear = encodeURI(document.getElementById('formfieldStartYear').value);
	var startDate = startYear + '-' + startMonth + '-' + startDay;
	
	var endMonth = encodeURI(document.getElementById('formfieldEndMonth').value);
	if(endMonth.length == 1)
	{
		endMonth = '0' + endMonth;
	}
	var endDay = encodeURI(document.getElementById('formfieldEndDay').value);
	if(endDay.length == 1)
	{
		endDay = '0' + endDay;
	}
	var endYear = encodeURI(document.getElementById('formfieldEndYear').value);
	var endDate = endYear + '-' + endMonth + '-' + endDay;
	
	
	
	var url = "editEvent.php";
	var params = 'id=' + eventID + '&title=' + title + '&description=' + description + '&startDate=' + startDate + '&endDate=' + endDate + '&host=' + host + '&location=' + location + '&time=' + time + '&type=' + type + '&restrictions=' + restrictions + '&startDate=' + startDate + '&endDate=' + endDate + '&address=' + address + '&banner=' + banner + '&poster=' + poster;
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{
		//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			checkEditEvent();
		}
	}
	http.send(params);
}

function checkEditEvent()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response == 'noaccess')
		{
			var status = 'error';
			var message = 'parameters not sent';
			showStatusBox(status, message, 'main');
		}
		else if(response == 'Unable to Select Database')
		{
			var status = 'error';
			var message = 'unable to connect to database';
			showStatusBox(status, message, 'events');
		}
		else if(response == 'notadmin')
		{
			var status = 'error';
			var message = 'You must be logged in as an admin to edit events.<br />Reloading page in a second or <a href="">manually reload page</a>.';
			showStatusBox(status, message, 'main');
			refreshPage(1000);				
		}
		else if(response == 'success')
		{
			var status = 'success';
			var message = 'Editing event. Reloading page in a second or <a href="">manually reload page</a>.';
			showStatusBox(status, message, 'main');
			refreshPage(1000);	
		}
		else 
		{
			var status = 'error';
			var message = 'unknown exception';
			showStatusBox(status, message, 'main');	
		}
	}
}


/*------------------
Delete Event
-------------------*/

function deleteEvent(eventID)
{
	var confirmdel = confirm('Are you sure you want to delete?');
	if(confirmdel == true)
	{	
		var url = "deleteEvent.php";
		var params = 'id=' + eventID;
		http.open("POST", url, true);
	
		//Send the proper header information along with the request
		http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");
	
		http.onreadystatechange = function() 
		{
			//Call a function when the state changes.
			if(http.readyState == 4 && http.status == 200) 
			{
				checkDeleteEvent();
			}
		}
		http.send(params);
	}
}

function checkDeleteEvent()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response == 'noaccess')
		{
			var status = 'error';
			var message = 'parameters not sent';
			showStatusBox(status, message, 'main');
		}
		else if(response == 'Unable to Select Database')
		{
			var status = 'error';
			var message = 'unable to connect to database';
			showStatusBox(status, message, 'events');
		}
		else if(response == 'notadmin')
		{
			var status = 'error';
			var message = 'You must be logged in as an admin to delete events.<br />Reloading page in a second or <a href="">manually reload page</a>.';
			showStatusBox(status, message, 'main');
			refreshPage(1000);				
		}
		else if(response == 'success')
		{
			var status = 'success';
			var message = 'Deleting event. Reloading page in a second or <a href="">manually reload page</a>.';
			showStatusBox(status, message, 'main');			
			refreshPage(1000);	
		}
		else 
		{
			var status = 'error';
			var message = 'unknown exception';
			showStatusBox(status, message, 'main');	
		}
	}
}







/*----------------
Create News item
------------------*/
function createNews()
{
	// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
	var title = encodeURI(document.getElementById('newsTitle').value);
	var text = encodeURI(document.getElementById('newsText').value);
	var category = encodeURI(document.getElementById('newsCategory').value);
	//var eventID = encodeURI(document.getElementById('newsEventID').value);
	var eventID = '';
	
	var url = "createNews.php";
	var params = 'title=' + title + '&text=' + text + '&category=' + category + '&eventID=' + eventID;
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{
		//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			checkNews();
		}
	}
	http.send(params);

}

function checkNews()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response == 'noaccess')
		{
			var status = 'error';
			var message = 'parameters not sent';
			showStatusBox(status, message, 'main');
			document.addNewsItem.reset();
		}
		else if(response == 'Unable to Select Database')
		{
			var status = 'error';
			var message = 'unable to connect to database';
			showStatusBox(status, message, 'news');
		}
		else if(response == 'notitle')
		{
			var status = 'error';
			var message = 'you must create a title for a news item.';
			showStatusBox(status, message, 'news');
			new Effect.Highlight('newsTitle', 
				{
					startcolor: "#FF00CD",
					duration: .7
				 });
		}
		else if(response == 'notadmin')
		{
			var status = 'error';
			var message = 'You must be logged in as an admin to post news.<br />Reloading page in a second or <a href="">manually reload page</a>.';
			showStatusBox(status, message, 'main');
			document.addNewsItem.reset();
			refreshPage(1000);				
		}
		else if(response == 'success')
		{
			var status = 'success';
			var message = 'Posting news item. Reloading page in a second or <a href="">manually reload page</a>.';
			showStatusBox(status, message, 'main');
			document.addNewsItem.reset();			
			refreshPage(1000);	
		}
		else 
		{
			var status = 'error';
			var message = 'unknown exception';
			showStatusBox(status, message, 'main');	
		}
	}
}



/*------------------
Edit News Item
-------------------*/

function editNewsAJAX(newsID)
{
	// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
	var title = encodeURI(document.getElementById('newsTitle').value);
	var text = encodeURI(document.getElementById('newsText').value);
	var category = encodeURI(document.getElementById('newsCategory').value);
	//var eventID = encodeURI(document.getElementById('newsEventID').value);
	var eventID = '';
	
	var url = "editNews.php";
	var params = 'id=' + newsID + '&title=' + title + '&text=' + text + '&category=' + category + '&eventID=' + eventID;
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{
		//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			checkEditNews();
		}
	}
	http.send(params);

}

function checkEditNews()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response == 'noaccess')
		{
			var status = 'error';
			var message = 'parameters not sent';
			showStatusBox(status, message, 'main');
			document.addNewsItem.reset();
		}
		else if(response == 'Unable to Select Database')
		{
			var status = 'error';
			var message = 'unable to connect to database';
			showStatusBox(status, message, 'news');
		}
		else if(response == 'notitle')
		{
			var status = 'error';
			var message = 'you must create a title for a news item.';
			showStatusBox(status, message, 'news');
			new Effect.Highlight('newsTitle', 
				{
					startcolor: "#FF00CD",
					duration: .7
				 });
		}
		else if(response == 'notadmin')
		{
			var status = 'error';
			var message = 'You must be logged in as an admin to edit news.<br />Reloading page in a second or <a href="">manually reload page</a>.';
			showStatusBox(status, message, 'main');
			document.addNewsItem.reset();
			refreshPage(1000);				
		}
		else if(response == 'success')
		{
			var status = 'success';
			var message = 'Editing news item. Reloading page in a second or <a href="">manually reload page</a>.';
			showStatusBox(status, message, 'main');
			document.addNewsItem.reset();			
			refreshPage(1000);	
		}
		else 
		{
			var status = 'error';
			var message = 'unknown exception';
			showStatusBox(status, message, 'main');	
		}
	}
}


/*------------------
Delete News Item
-------------------*/

function deleteNews(newsID)
{
	var confirmdel = confirm('Are you sure you want to delete?');
	if(confirmdel == true)
	{	
		var url = "deleteNews.php";
		var params = 'id=' + newsID;
		http.open("POST", url, true);
	
		//Send the proper header information along with the request
		http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");
	
		http.onreadystatechange = function() 
		{
			//Call a function when the state changes.
			if(http.readyState == 4 && http.status == 200) 
			{
				checkDeleteNews();
			}
		}
		http.send(params);
	}
}

function checkDeleteNews()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response == 'noaccess')
		{
			var status = 'error';
			var message = 'parameters not sent';
			showStatusBox(status, message, 'main');
			document.addNewsItem.reset();
		}
		else if(response == 'Unable to Select Database')
		{
			var status = 'error';
			var message = 'unable to connect to database';
			showStatusBox(status, message, 'news');
		}
		else if(response == 'notadmin')
		{
			var status = 'error';
			var message = 'You must be logged in as an admin to delete news.<br />Reloading page in a second or <a href="">manually reload page</a>.';
			showStatusBox(status, message, 'main');
			document.addNewsItem.reset();
			refreshPage(1000);				
		}
		else if(response == 'success')
		{
			var status = 'success';
			var message = 'Deleting news item. Reloading page in a second or <a href="">manually reload page</a>.';
			showStatusBox(status, message, 'main');
			document.addNewsItem.reset();			
			refreshPage(1000);	
		}
		else 
		{
			var status = 'error';
			var message = 'unknown exception';
			showStatusBox(status, message, 'main');	
		}
	}
}


/*------------------
Refresh page script
-------------------*/
function refreshPage(timeoutPeriod)
{
	setTimeout("location.reload(true);",timeoutPeriod);
}



/*------------------
Edit DJ Profile Page
-------------------*/

function editDJProfileInformation()
{
	var editAssociationsValue = encodeURI(document.getElementById('field_Associations').value);
	var editBookingsValue = encodeURI(document.getElementById('field_Bookings').value);
	var checkProfileID = encodeURI(document.getElementById('djProfileID').value);
	
	var url = "../../editBasicInformation.php";
	// pass associations bookings and the id of the dj whose page we are on
	var params = 'associations=' + editAssociationsValue + '&bookings=' + editBookingsValue + '&profilepageid=' + checkProfileID;
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{		
		//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			editDJProfileInformationCheck();
		}
	}
	http.send(params);
}

function editDJProfileInformationCheck()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response == 'noaccess')
		{
			var status = 'error';
			var message = 'parameters not sent';
			showProfileStatusBox(status, message);
		}
		else if(response == 'Unable to Select Database')
		{
			var status = 'error';
			var message = 'unable to connect to database';
			showProfileStatusBox(status, message);
		}
		else if(response == 'wrongowner')
		{
			var status = 'error';
			var message = 'you can only edit your own profile';
			showProfileStatusBox(status, message);		
		}
		else if(response == 'success')
		{
			var status = 'success';
			var message = 'Changed profile information.<br />Reloading page in a seconds or <a href="">manually reload page</a>.';			
			showProfileStatusBox(status, message);		
			refreshPage(1000);	
		}
		else 
		{
			var status = 'error';
			var message = 'unknown exception';
			showProfileStatusBox(status, message);		
		}
	}
}


function editDJProfileProfile()
{
	var profiletext = encodeURI(document.getElementById('field_Profile').value);
	var checkProfileID = encodeURI(document.getElementById('djProfileId2').value);
	
	var url = "../../editdjprofiletext.php";
	var params = 'profiletext=' + profiletext + '&profilepageid=' + checkProfileID;
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{		
		//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			editDJProfileInformationCheck();
		}
	}
	http.send(params);
}

function editDJProfileAppearances()
{
	var appearances = encodeURI(document.getElementById('field_appearances').value);
	var checkProfileID = encodeURI(document.getElementById('djProfileId3').value);
	
	var url = "../../editdjprofileappearances.php";
	var params = 'appearances=' + appearances + '&profilepageid=' + checkProfileID;
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{		
		//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			editDJProfileInformationCheck();
		}
	}
	http.send(params);
}


/*------------------
Add Link
-------------------*/
function addLinkAJAX()
{
	var description = encodeURI(document.getElementById('field_linkName').value);
	var linkurl = encodeURI(document.getElementById('field_linkURL').value);
	var checkProfileID = encodeURI(document.getElementById('djProfileID').value);
	
	var url = "../../addLink.php";
	var params = 'description=' + description + '&linkurl=' + linkurl + '&profilepageid=' + checkProfileID;
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{		
		//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			addLinkCheck();
		}
	}
	http.send(params);
}


function addLinkCheck()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response == 'noaccess')
		{
			var status = 'error';
			var message = 'parameters not sent';
			showProfileStatusBox(status, message);
		}
		else if(response == 'Unable to Select Database')
		{
			var status = 'error';
			var message = 'unable to connect to database';
			showProfileStatusBox(status, message);
		}
		else if(response == 'wrongowner')
		{
			var status = 'error';
			var message = 'you can only add links to your own profile';
			showProfileStatusBox(status, message);		
		}
		else if(response == 'success')
		{
			var status = 'success';
			var message = 'Added a link.<br />Reloading page in a seconds or <a href="">manually reload page</a>.';			
			showProfileStatusBox(status, message);		
			refreshPage(1000);	
		}
		else 
		{
			var status = 'error';
			var message = 'unknown exception';
			showProfileStatusBox(status, message);		
		}
	}
}

function editLinkAJAX(linkID)
{
	var description = encodeURI(document.getElementById('field_linkName').value);
	var linkurl = encodeURI(document.getElementById('field_linkURL').value);
	var checkProfileID = encodeURI(document.getElementById('djProfileID').value);
	
	var url = "../../editLink.php";
	var params = 'id=' + linkID + '&description=' + description + '&linkurl=' + linkurl + '&profilepageid=' + checkProfileID;
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{		
		//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			editLinkCheck();
		}
	}
	http.send(params);
}

function editLinkCheck()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response == 'noaccess')
		{
			var status = 'error';
			var message = 'parameters not sent';
			showProfileStatusBox(status, message);
		}
		else if(response == 'Unable to Select Database')
		{
			var status = 'error';
			var message = 'unable to connect to database';
			showProfileStatusBox(status, message);
		}
		else if(response == 'wrongowner')
		{
			var status = 'error';
			var message = 'you can only edit links on your own profile';
			showProfileStatusBox(status, message);		
		}
		else if(response == 'success')
		{
			var status = 'success';
			var message = 'Edited a link.<br />Reloading page in a seconds or <a href="">manually reload page</a>.';			
			showProfileStatusBox(status, message);		
			refreshPage(1000);	
		}
		else 
		{
			var status = 'error';
			var message = 'unknown exception';
			showProfileStatusBox(status, message);		
		}
	}
}

function deleteLink(linkID)
{
	var confirmdel = confirm('Are you sure you want to delete?');
	if(confirmdel == true)
	{	
		var checkProfileID = encodeURI(document.getElementById('djProfileID').value);
		
		var url = "../../deleteLink.php";
		var params = 'id=' + linkID + '&profilepageid=' + checkProfileID;
		http.open("POST", url, true);
	
		//Send the proper header information along with the request
		http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");
	
		http.onreadystatechange = function() 
		{		
			//Call a function when the state changes.
			if(http.readyState == 4 && http.status == 200) 
			{
				deleteLinkCheck();
			}
		}
		http.send(params);
	}
}

function deleteLinkCheck()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response == 'noaccess')
		{
			var status = 'error';
			var message = 'parameters not sent';
			showProfileStatusBox(status, message);
		}
		else if(response == 'Unable to Select Database')
		{
			var status = 'error';
			var message = 'unable to connect to database';
			showProfileStatusBox(status, message);
		}
		else if(response == 'wrongowner')
		{
			var status = 'error';
			var message = 'you can only delete links on your own profile';
			showProfileStatusBox(status, message);		
		}
		else if(response == 'success')
		{
			var status = 'success';
			var message = 'Deleted a link.<br />Reloading page in a seconds or <a href="">manually reload page</a>.';			
			showProfileStatusBox(status, message);		
			refreshPage(1000);	
		}
		else 
		{
			var status = 'error';
			var message = 'unknown exception';
			showProfileStatusBox(status, message);		
		}
	}
}







/*------------------
Add A Mix
-------------------*/
function addMixAJAX()
{
	var title = encodeURI(document.getElementById('mixtitle').value);
	var mixurl = encodeURI(document.getElementById('mixlink').value);
	var description = encodeURI(document.getElementById('mixdescription').value);
	var tracks = encodeURI(document.getElementById('mixtracks').value);
	var checkProfileID = encodeURI(document.getElementById('djProfileID').value);
	
	var url = "../../addMix.php";
	var params = 'title=' + title + '&mixurl=' + mixurl + '&description=' + description + '&tracks=' + tracks + '&profilepageid=' + checkProfileID;
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{		
		//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			addMixCheck();
		}
	}
	http.send(params);
}


function addMixCheck()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response == 'noaccess')
		{
			var status = 'error';
			var message = 'parameters not sent';
			showProfileStatusBox(status, message);
		}
		else if(response == 'Unable to Select Database')
		{
			var status = 'error';
			var message = 'unable to connect to database';
			showProfileStatusBox(status, message);
		}
		else if(response == 'wrongowner')
		{
			var status = 'error';
			var message = 'you can only add mixes to your own profile';
			showProfileStatusBox(status, message);		
		}
		else if(response == 'success')
		{
			var status = 'success';
			var message = 'Added a mix.<br />Reloading page in a seconds or <a href="">manually reload page</a>.';			
			showProfileStatusBox(status, message);		
			refreshPage(1000);	
		}
		else 
		{
			var status = 'error';
			var message = 'unknown exception';
			showProfileStatusBox(status, message);		
		}
	}
}

function editMixAJAX(mixId)
{
	var title = encodeURI(document.getElementById('mixtitle').value);
	var mixurl = encodeURI(document.getElementById('mixlink').value);
	var description = encodeURI(document.getElementById('mixdescription').value);
	var tracks = encodeURI(document.getElementById('mixtracks').value);
	var checkProfileID = encodeURI(document.getElementById('djProfileID').value);
	
	var url = "../../editMix.php";
	var params = 'id=' + mixId + '&title=' + title + '&mixurl=' + mixurl + '&description=' + description + '&tracks=' + tracks + '&profilepageid=' + checkProfileID;
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() 
	{		
		//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) 
		{
			editMixCheck();
		}
	}
	http.send(params);
}


function editMixCheck()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response == 'noaccess')
		{
			var status = 'error';
			var message = 'parameters not sent';
			showProfileStatusBox(status, message);
		}
		else if(response == 'Unable to Select Database')
		{
			var status = 'error';
			var message = 'unable to connect to database';
			showProfileStatusBox(status, message);
		}
		else if(response == 'wrongowner')
		{
			var status = 'error';
			var message = 'you can only edit mixes on your own profile';
			showProfileStatusBox(status, message);		
		}
		else if(response == 'success')
		{
			var status = 'success';
			var message = 'Edited a mix.<br />Reloading page in a seconds or <a href="">manually reload page</a>.';			
			showProfileStatusBox(status, message);		
			refreshPage(1000);	
		}
		else 
		{
			var status = 'error';
			var message = 'unknown exception';
			showProfileStatusBox(status, message);		
		}
	}
}

function deleteMix(mixID)
{
	var confirmdel = confirm('Are you sure you want to delete?');
	if(confirmdel == true)
	{	
		var checkProfileID = encodeURI(document.getElementById('djProfileID').value);
		
		var url = "../../deleteMix.php";
		var params = 'id=' + mixID + '&profilepageid=' + checkProfileID;
		http.open("POST", url, true);
	
		//Send the proper header information along with the request
		http.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");
	
		http.onreadystatechange = function() 
		{		
			//Call a function when the state changes.
			if(http.readyState == 4 && http.status == 200) 
			{
				deleteMixCheck();
			}
		}
		http.send(params);
	}
}

function deleteMixCheck()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response == 'noaccess')
		{
			var status = 'error';
			var message = 'parameters not sent';
			showProfileStatusBox(status, message);
		}
		else if(response == 'Unable to Select Database')
		{
			var status = 'error';
			var message = 'unable to connect to database';
			showProfileStatusBox(status, message);
		}
		else if(response == 'wrongowner')
		{
			var status = 'error';
			var message = 'you can only delete mixes on your own profile';
			showProfileStatusBox(status, message);		
		}
		else if(response == 'success')
		{
			var status = 'success';
			var message = 'Deleted a mix.<br />Reloading page in a seconds or <a href="">manually reload page</a>.';			
			showProfileStatusBox(status, message);		
			refreshPage(1000);	
		}
		else 
		{
			var status = 'error';
			var message = 'unknown exception';
			showProfileStatusBox(status, message);		
		}
	}
}
