gNews = null;

function displayItem(section, id) {
	var item = section+id;
	var header = section+'Head'+id;
	var element = document.getElementById(item);
	if( element.style.display != 'block') {
		element.style.display = 'block';
		document.getElementById(header).style.backgroundColor = '#062c43';
	} else {
		element.style.display = 'none';
		document.getElementById(header).style.backgroundColor = '#000000';
	}
}

function deleteItems(section, category_id) {
	var deleteItems = new Array();
	for(var i = 0; i < items.length; i++) {
		if(document.getElementById('delete'+items[i]).checked) {
			deleteItems.push(items[i]);
		}
	}
	if( deleteItems.length > 0 && confirm("Do you really want to delete those items?")) {
		window.location = 'xt_delete_'+section+'.php?category_id='+category_id+'&ids='+deleteItems;
	}
}

function switchSelection() {
	for(var i = 0; i < items.length; i++) {
		document.getElementById('delete'+items[i]).checked = document.getElementById('deleteCheck').checked;
	}
}

function switchVisuals(choice) {
	var choices = new Array();
	choices['video'] = 'picture';
	choices['picture'] = 'video';
	document.getElementById(choices[choice]).disabled = true;
	document.getElementById(choice).disabled = false;
}

function displayProduct(item) {
	var element = document.getElementById(item);
	if( element.style.display != 'block') {
		element.style.display = 'block';
	} else {
		element.style.display = 'none';
	}
}

function onMouseOverList(item) {
	item.style.background = "url('images/bg_list_on.jpg')";
}

function onMouseOutList(item) {
	item.style.background = "url('images/bg_list_off.jpg')";
}


function closeLightWindow() {
	$('lightwindow_iframe').contentWindow.document.close();
}

function openWindow(page, param) {	
	var top = (screen.height-475)/2;
	var left = (screen.width-394)/2;
	var page = page+'.php';
	if( param != null) page += '?id='+param;
	window.open(page, '', 'width = 394, height = 475, top = '+top+', left = '+left);
}

function teamValidation(item, id) {
	if( item.checked || confirm("Unvalid this team ?")) {
		var myAjax = new Ajax.Request(
			"xt_team_validation.php", 
			{
				method: 'get', 
				parameters: 'team_id='+id, 
				onComplete: showResponse
			});
	} else {
		item.checked = true;
	}
}

function showResponse(originalRequest) {
	if( originalRequest.responseText != "false" ) {
		var item = $('storyCbx'+originalRequest.responseText);
		if( item.checked) {
			$('storyHead'+originalRequest.responseText).setAttribute("validated", "true");
			alert("Story validated");
		} else {
			$('storyHead'+originalRequest.responseText).setAttribute("validated", "false");
			alert("Story unvalidated");
		}
	} else {
		alert("Server error");
	}
}