/* Directory JS file */

function lightRow(id, status) {
	rowa = document.getElementById('dirRow'+id+'a');
	rowb = document.getElementById('dirRow'+id+'b');
	if (status == 1) {
		// Highlighting row
		rowa.style.backgroundColor='#E6F2F2';
		rowb.style.backgroundColor='#f3ece7';
	} else if (status == 2) {
		// Dimming row
		rowa.style.backgroundColor='#FFFFFF';
		rowb.style.backgroundColor='#FFFFFF';
	} else {
		// Dimming alternative row
		rowa.style.backgroundColor='#F2F2F2';
		rowb.style.backgroundColor='#F2F2F2';
	}
}

function toggleCheck(id) {
	cb = document.getElementById("lst-"+id);
	td = document.getElementById("lst-"+id+"-td");
	if (cb && td) {
		if (cb.value == "false") {
			cb.value = "true";	
			td.style.backgroundColor = "#FF0000 !important";
			td.style.color = "#FFFFFF";
		} else {
			cb.value = "false";
			td.style.backgroundColor = "";
			td.style.color = "#000000";
		}
	}
}

// Checks any checkbox is checked for submission
function checkOK(cb) {
	check = document.getElementById(cb);
	if (check) {
		if (check.checked) {
			return true;
		} else {
			alert('Please agree to the terms and conditions before continuing');	
			return false;
		}
	} else {
		return false;
	}
}

// Checks that the requisets are ok for add/edit listings
function submitOK(mode) {
	title = document.getElementById('title');
	url = document.getElementById('url');
	
	if ((mode == 'approve') || (mode == 'publish')) {
		status = document.getElementById('status');
		published = document.getElementById('published');
		if (status && published) {
			status.value = "OK";
			published.checked = true;
		}
	}

	if (mode == 'unpublish') {
		status = document.getElementById('status');
		published = document.getElementById('published');
		if (status && published) {
			status.value = "Unpublished";
			published.checked = false;
		}
	}

	if (title && url) {
		if (title.value.length < 3) {
			alert('Please enter a proper title for the listing');
			return;
		}
		if (url.value.length < 6) {
			alert('Please enter a full URL, begginging with http://');
			return;
		}
	} else {
		alert('An error has been detected in the form. We can not continue.');
		return;
	}	
	document.lstForm.submit();
}

function setOption(val) {
	option = document.getElementById('option');
	if (option) {
		option.value = val;
		submitOK();
	}
}

function adminSubmit(mode) {
	document.getElementById('mode').value = mode;	
	document.dirAdminForm.submit();	
}


