// JavaScript Document

function chgImg(imgField,newImg) {
	if (document.images) {
		document[imgField].src= eval(newImg + ".src")
	}
}


function navselect(dropdown) {
var URL = dropdown.options[dropdown.selectedIndex].value;
if(URL != "") {
document.location.href=URL;
}
}

function catselect(dropdown) {
var URL = dropdown.options[dropdown.selectedIndex].value;
if(URL != "") {
document.location.href=URL;
}
}

function newwindow(dropdown) {
	var URL = dropdown.options[dropdown.selectedIndex].value;
	if(URL == "") {
	
	} else {
		window.open(URL,'mywindow','toolbar=yes, location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes, resizable=yes');
	}
}


function isFilled(elm) {
    if (elm.value == "") 
    return false;
    else return true;
}

function isEmail(elm) {
    if (elm.value.indexOf("@") + "" != "-1" &&
        elm.value.indexOf(".") + "" != "-1" &&
        elm.value != "") 
    return true;
    else return false;
}


function isReady(form){    
	if (isFilled(form.fullname) == false) { 
    	alert("Please enter your name.");
    	form.fullname.focus();
    	return false;
    }
	
	if (isFilled(form.subject) == false) { 
    	alert("Please enter a Subject.");
    	form.subject.focus();
    	return false;
    }
	
	if (isEmail(form.email) == false) { 
    	alert("Please enter a valid email address.");
    	form.email.focus();
    	return false;
    }
		
	if (isFilled(form.comments) == false) { 
    	alert("Please enter your comments.");
    	form.comments.focus();
    	return false;
    }
	
	return true;
}

function clear_val(elm, text){
	if (elm.value == text){
		elm.value = "";
	}
}

function enter_val(elm, text){
	if (elm.value == ""){
		elm.value = text;
	}
}
function confirmDelete(section, id) {
	var answer = confirm("Are you sure you want to delete this?");
	if(answer) {
		window.location.href="processDelete.php?action="+section+"&id="+id+"";
	} else {
		return false;
	}
}
function deleteMedia(section, id) {
	
	var answer = confirm("Are you sure you want to delete this "+section+"?");
	if(answer) {
		window.location.href="deleteMedia.php?action="+section+"&id="+id+"";
	} else {
		return false;
	}
}
function deletePlusMedia(section, id, type) {
	
	var answer = confirm("Are you sure you want to delete this image?");
	if(answer) {
		window.location.href="deleteMedia.php?action="+section+"&id="+id+"";
	} else {
		return false;
	}
}
function deleteImage(section, id) {
	
	var answer = confirm("Are you sure you want to delete this image?");
	if(answer) {
		window.location.href="deleteImage.php?action="+section+"&id="+id+"";
	} else {
		return false;
	}
}
function deleteImagery(section, id, type) {
	
	var answer = confirm("Are you sure you want to delete this image?");
	if(answer) {
		window.location.href="deleteImage.php?action="+section+"&id="+id+"&type="+type+"";
	} else {
		return false;
	}
}
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;

function showMessage(thisDiv) {
	
	thisDiv = thisDiv;
	thisDiv = document.getElementById(thisDiv);

	thisDiv.style.display = "block";
	
}
function hideMessage(thisDiv) {
	
	thisDiv = thisDiv;
	thisDiv = document.getElementById(thisDiv);

	thisDiv.style.display = "none";
	
}

function showAll(num) {
	
	for(var i = 1; i <= num; i++) {
		thisDiv = document.getElementById("message"+i);
		thisDiv.style.display = "block";
	}
}

function closeAll(num) {
	for(var i = 1; i <= num; i++) {
		thisDiv = document.getElementById("message"+i);
		thisDiv.style.display = "none";
	}	
}

function selectAll(input) {

	input.focus();
	input.select();
	
}