// all support other ajax calls


//tabs controller (show hide tabs on all pages )
function showChart(objVal,maxTab){
		if(objVal == ""){alert('Please select all required field'); return;	}
		curSelectedTab = objVal.substring(3,objVal.length)
		if(document.getElementById("curSelectedTabVal") != null){
		document.getElementById("curSelectedTabVal").value = curSelectedTab
		}

		for(a=1 ; a <= maxTab ; a++){
							document.getElementById("tab"+a).style.display ="none"
			
				document.getElementById("a_tab"+a+"Link").style.backgroundPosition ="0% 0px"
				document.getElementById("s_tab"+a+"Link").style.backgroundPosition ="100% 0px"
		
		}

		document.getElementById(objVal).style.display ="block"
		document.getElementById("a_"+objVal+"Link").style.backgroundPosition ="0% -42px"
		document.getElementById("s_"+objVal+"Link").style.backgroundPosition ="100% -42px"
}
	
// display coordinator info in blank window. getting state code from link to generate file name
		function showCoordInfo(objVal){
			if(objVal == "coordState"){
				objVal = coordState
			}
			stateCode = objVal //document.getElementById('region').value
			var load = window.open('index.cfm?fuseaction=app.coordinatorContact&region=' + stateCode + '&goBtn=true','','scrollbars=yes,menubar=no,height=600,width=900,resizable=yes,toolbar=no,location=no,status=no');
}

/* function showCoordInfo(objVal){
			if(objVal == "coordState"){
				objVal = coordState
			}
			stateCode = objVal //document.getElementById('region').value
			stateCodeFile = 'regions/' +stateCode.substring(2,4)+'.html'
			var load = window.open(stateCodeFile,'','scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
} */
	
			
function buildChart(){
				region =document.getElementById('region').value
				speciesid = document.getElementById('speciesid').value
				urlObj = 'getChart.cfm?region=' +region + "&speciesid="+ speciesid
				buildXMLObj(urlObj)
}


// ajax loading div
function loadingMessage(action){
		if (document.getElementById("loadingMessage") == null){return;}
		if(action == "s"){
				var winW = 255;
				var winH = 138;
				var winX = (screen.availWidth - winW) / 2;
				var winY = (screen.availHeight - winH) / 2;
	
				var features = 'left='+winX+',top='+winY+',width='+winW+',height='+winH+',toolbar=0,location=0,status=0,scrollbars= 1,resizable=0';
				document.getElementById("loadingMessage").innerHTML = '<img src="images/loadingFrog.gif" alt="Loading Please Wait" />';
				document.getElementById("loadingMessage").style.display = "block";
				document.getElementById("loadingMessage").style.top = winY+'px';
				document.getElementById("loadingMessage").style.left = winX+'px';	
		}else{
			document.getElementById("loadingMessage").innerHTML = "";
			document.getElementById("loadingMessage").style.display = "none";
		
		}
}

// show frog quiz results in blank wondow
function showTestResult(testResultID){
			stateCode = document.getElementById('region').value
			stateCodeFile = "dsp_testResults.cfm?"
			var load = window.open(stateCodeFile,'','scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
}
	
// show/hide map keys on all maps
function showMapKeys(actionRef){
	if(actionRef == 's'){
				document.getElementById("mapKeys").style.display = 'block'
	}
	else{
			document.getElementById("mapKeys").style.display = 'none'
	}
}

//select/deselect select list
function enableMe(activeObj, inactiveObj){
		inactiveObj= document.getElementById(inactiveObj)		
		activeObj= document.getElementById(activeObj)
		inactiveObj.selectedIndex = -1
}
		

// used in data download for data error checking (sorry I wasn't a good programmer)
function echeck(str) {
		if(curSelectedTab != 3){
			toYear = document.getElementById("toYear"+curSelectedTab).value
			fromYear = document.getElementById("fromYear"+curSelectedTab).value
		}
		nameStr = document.getElementById("name"+curSelectedTab).value
		str = document.getElementById("email"+curSelectedTab).value

		//alert(nameStr +","+ str +","+ toYear+","+ fromYear )
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if(curSelectedTab != 3){
				if(toYear != -1 && fromYear == -1){
						alert("Invalid year range")	
						return false;
				}
		
				if(toYear == -1 && fromYear != -1){
						alert("Invalid year range")	
						return false;				
				}
		}
		if((nameStr == "") || (nameStr == null)){
		   alert("Please enter your name")
		   return false
		}

		if ((str==null)||(str=="")){
			alert("Please enter your email address")
			return false
		}

		if (str.indexOf(at)==-1){
		   alert("Invalid email address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid email address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid email address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid email address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid email address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid email address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid email address")
		    return false
		 }
			document.getElementById("goBtn"+curSelectedTab).value = "generate"
			document.daForm.submit()
 		 return true					
	}
