function Validate(val){
	//check to see if this is a number, if it is an integer and if it is > 0
      	if(isNaN(val) || val.indexOf(".") >0 || val < 1){
         	return false;
	} else {
         	return true;
      	}
}

function CheckEmpty(val){
      	if(val == "" || val == "Type gene name(s) here" || val == "Type any word(s) here")
        	return false;
      	else {
		if(val.match(/\w+/)){
			return true;
		} else {
			return false;
		}
	}
}

function trimIt(e) {
      	// Trim leading blanks
      	while (e.value.charAt(0) == " ") {
         	e.value = e.value.substr(1,e.value.length)
      	}
      	// Trim trailing blanks
      	while (e.value.charAt(e.value.length-1) == " ") {
         	e.value = e.value.substr(0,e.value.length-1)
      	}
}

function ConfirmDownload(val){
    	if(val < 10000){
        	return true;
    	} else {
        	var answer = confirm("You have requested a very large file.  Would you like to continue this download?");
        	if(answer){
            		return true;
        	} else {
            		return false;
        	}
    	}
}
    
function ConfirmDownload(val,stringval){
        if(val < 10000)
        	return true;
        else if( stringval == "XMLPage" || stringval == "CSVPage" || stringval == "ExcelPage")
           	return true;
        else{
            	var answer = confirm("You have requested a very large file.  Would you like to continue this download?");
            	if(answer)
                	return true;
            	else
                	return false;
        }
}

function CompareString(val){
        if(val == "XML" || val == "CSV" || val == "Excel" || val == "XMLPage" || val == "CSVPage" || val == "ExcelPage")
                return true;
        else {
		alert("Please choose a download format from the 'Download:' list");
                return false;
	}
}

var openImg = new Image();
openImg.src = "open.gif";
var closedImg = new Image();
closedImg.src = "closed.gif";

function showBranch(branch){
	var objBranch = document.getElementById(branch).style;
        if(objBranch.display=="block")
        	objBranch.display="none";
        else
             	objBranch.display="block";
}

function swapFolder(img) {
   	objImg = document.getElementById(img);
        if(objImg.src.indexOf('closed.gif')>-1)
             	objImg.src = openImg.src;
        else
             	objImg.src = closedImg.src;
       	}
   
function displayMenu(menu1, menu2) {
      	var menuA = document.getElementById(menu1).style;
      	menuA.display="block";
      	var menuB = document.getElementById(menu2).style;
      	menuB.display="none";
}

function trim (str) {
        str = this != window? this : str;
        return str.replace(/^\s+/, '').replace(/\s+$/, '');
}

function doesNonBooleanTermExist(input){
        var query = trim(input.toLowerCase());
	var nonBooleanTermExists = false;
	var queryArray = query.split(" ");
	for(var i = 0; i < queryArray.length; i++){
		var current = queryArray[i];
		if(current != "" &&
		   current != "and" &&
		   current != "not" &&
		   current != "or" &&
		   current != "&&" &&
		   current != "||"){
			nonBooleanTermExists = true;
			break;
		}
	}
	return nonBooleanTermExists;
}

function selectDeselectArticle(article, articleLink, articleNumber, checked){
        var art = document.getElementById(article).style;
	var artLink = document.getElementById(articleLink).style;
	var artNumber = document.getElementById(articleNumber).style;
        if(checked == true){
                art.color = "#003366";
		artLink.color = "#993333";
		artNumber.color = "#003366";
        } else {
                art.color = "grey";
		artLink.color = "grey";
                artNumber.color = "grey";
	}
}