function ajaxRequests(id, mode){
	var xmlhttp = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){}
	}
	var url = 'PAGES/settings_files/ajax/ajax_requests.php';
	var post_vars = 'mode='+mode+'&show='+id;
	xmlhttp.open('POST', url+'?'+post_vars, true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlhttp.send(post_vars);
}

function addShow(obj) {
	obj.className = 'name added';
	
	obj.onclick = 'return false;';
	
	obj.title = 'you have already added '+obj.name;
	
	var destination = document.getElementById('listShows');
	
	var bottomCorners = document.getElementById('bottomCorners');
	
	addedShows.push(obj.name+'_'+obj.rel+'_'+addedShows.length+'_'+obj.href);
	
	ajaxRequests(obj.rel, 'add');
	
	if(addedShows.length%2 == 0 && addedShows.length > 0) {
		bottomCorners.className = 'bottom bottomLast';
	} else {
		bottomCorners.className = 'bottom';
	}
	
	destination.innerHTML = '';
	
	var className = '';
	
	var relAttribute = new Array();
	
	for(i = 0; i<addedShows.length; i++) {
		
		relAttribute = addedShows[i].split("_");
		
		className = 'class="';
		if(i == 0) {
			className += 'first ';
		}
		if((i%2) != 0) {
			className += ' even ';
		}
		if(i == (addedShows.length-1)) {
			className += 'last';
		}
		className += '"';
		
		destination.innerHTML += '<li '+className+'><a href="'+relAttribute[3]+'" class="name">'+relAttribute[0]+'</a><a href="#" rel="'+relAttribute[0]+'_'+relAttribute[1]+'_'+i+'" title="remove '+relAttribute[0]+'" class="remove" onclick="removeShow(this); return false;"></a><br class="clear" /></li>';
		
	}
}
function removeShow(obj) {
	var destination = document.getElementById('listShows');
	
	var bottomCorners = document.getElementById('bottomCorners');
	
	var relObj = new Array();
		
	relObj = obj.rel.split("_");
	
	addedShows.splice(relObj[2], 1);
	
	ajaxRequests(relObj[1], 'edit');
	
	if(document.getElementById('show_'+relObj[1])) {
	
		var otherObj = document.getElementById('show_'+relObj[1]);
		
		otherObj.className = 'add';
		
		otherObj.onclick = function() {
			addShow(this); 
			return false;
		}
		
		otherObj.title = 'add '+relObj[0];
	}
	
	obj.className = 'add added';
	
	obj.onclick = 'return false;';
	
	obj.title = 'you have already added '+obj.name;
	
	if(addedShows.length%2 == 0 && addedShows.length > 0) {
		bottomCorners.className = 'bottom bottomLast';
	} else {
		bottomCorners.className = 'bottom';
	}
	
	destination.innerHTML = '';
	
	var className = '';
	
	var relAttribute = new Array();
	
	if(addedShows.length > 0) {
	
		for(i = 0; i<addedShows.length; i++) {
			
			relAttribute = addedShows[i].split("_");
			
			className = 'class="';
			if(i == 0) {
				className += 'first ';
			}
			if((i%2) != 0) {
				className += ' even ';
			}
			if(i == (addedShows.length-1)) {
				className += 'last';
			}
			className += '"';
			
			destination.innerHTML += '<li '+className+'><a href="'+relAttribute[3]+'" class="name">'+relAttribute[0]+'</a><a href="'+relAttribute[3]+'" rel="'+relAttribute[0]+'_'+relAttribute[1]+'_'+i+'" title="remove '+relAttribute[0]+'" class="remove" onclick="removeShow(this); return false;"></a><br class="clear" /></li>';
			
		}
	
	} else {
		destination.innerHTML += '<li class="first last"><span class="name">There are no shows added yet</span><br class="clear" /></li>';
	}
}