// JavaScript Document

function DoingSearch(ButtonOption){
	//Spcies name less than 2 letter
	if (document.SpeciesSearchForm.Name.value != "") {
		var SpeciesName = document.SpeciesSearchForm.Name.value;
		if(SpeciesName.length <= 2){
			alert("Incorrect Species name.");
			return false;
		}
	}
	//Incorrect location
	if (document.SpeciesSearchForm.Location.value != "") {
		var LocationName = document.SpeciesSearchForm.Location.value;
		if(LocationName.length <= 2){
			alert("Incorrect Location name.");
			return false;
		}
	}
	// Search species within specific location and year
	if (document.SpeciesSearchForm.RangeFrom.value != "" && document.SpeciesSearchForm.RangeEnd.value != "" && document.SpeciesSearchForm.Name.value == ""){
			if(document.SpeciesSearchForm.Location.value == ""){
				alert("To minimise the search result. Please specify search location.");
				return false;
			}
			if (document.SpeciesSearchForm.RangeFrom.value > document.SpeciesSearchForm.RangeEnd.value){
				alert("Please specify correct search year.");
				return false;
			}
		}
	// if false in Year Range
		else if (document.SpeciesSearchForm.RangeFrom.value > document.SpeciesSearchForm.RangeEnd.value){
			alert("Please specify correct search year.");
			return false;
		}
	// Resume search
			//document.SpeciesSearchForm.SubmitButton.value = "Searching please wait...........................";	
			if (ButtonOption == "True"){
				document.SpeciesSearchForm.SubmitButton.disabled = true;
				SearchLoadingPleaseWait();
			}
			//CreateMessage();
	}
var Dot = ".";	
function SearchLoadingPleaseWait(){
	setTimeout("SearchLoadingPleaseWait()",500);
	document.SpeciesSearchForm.SubmitButton.value = "Searching please wait" + Dot;
	Dot += ".";
	if (Dot.length > 30) Dot = ".";
}
	
function DoingSearchByExtent(){
	// Check extent
	Extent = document.SpeciesSearchForm.Extent.value;
	Species = document.SpeciesSearchForm.Name.value;
	x1 = Math.round(Extent.split(" ")[0]);
	x3 = Math.round(Extent.split(" ")[2]);
	Distance =  Math.round((x3 - x1)/1000);
	//If no species request then check the search year.
	if (Species != ""){
		if (Distance < 2){
			alert("Current search area is "+ Distance +" Km square.\nMimimum search area from the map is 2 Km square. \nPlease Zoom Out.\nNote: Search area must be between 2 - 30 Km square.");
			return false;
		}
		if (Distance > 30){
			alert("Current search area is "+ Distance +" Km square.\nMaximum search area from the map is 30 Km square. \nPlease Zoom In.\nNote: Search area must be between 2 - 30 Km square.");
			return false;
		}
	}
	// if false in Year Range
	if (document.SpeciesSearchForm.RangeFrom.value > document.SpeciesSearchForm.RangeEnd.value){
		alert("Please specify correct search year.");
		return false;
	}
	// Limit range year search
	YearLimit = document.SpeciesSearchForm.RangeEnd.value - document.SpeciesSearchForm.RangeFrom.value;
	if (YearLimit > 10){
		alert("Search by range year is limited by 10 years.");
		return false;
	}
	// Resume search
			document.SpeciesSearchForm.SubmitButton.value = "Loading please wait..........";
			document.SpeciesSearchForm.SubmitButton.disabled = true;		
	}
	


function ChangeLayout(selObj){
	var ChangeLayoutConfirm = confirm('Do you really want to change the layout?\nNote: If you change layout from 2 saparated content to 1. You will lose the data from content 2.\nClick OK to continue.');
	if (ChangeLayoutConfirm == true){
		document.Layout.LayoutID.value = selObj.options[selObj.selectedIndex].value;
		document.Layout.submit();
	}
}

function RemoveDownloadCategoryConfirm(CategoryID){
	var Conf = confirm("Do you really want to delete?") ;
	if (Conf == true) document.location = "?Mod=Admin&Area=Downloads&Func=DeleteDownloadCategory&CategoryID="+ CategoryID;
}

function RemoveDownloadFileConfirm(FileID){
	var Conf = confirm("Do you really want to delete?") ;
	if (Conf == true) document.location = "?Mod=Admin&Area=Downloads&Func=DeleteFile&DownloadID="+ FileID ;
}


function TaxonDic(SpeciesName){
		//SpeciesSearchForm.Name.value = Species[0] +" "+ Species[1];
		if (SpeciesName != "undefined")	document.SpeciesSearchForm.Name.value = SpeciesName;
}
	
function MM_openBrWindow(theURL,winName,features) { //v2.0
  	window.open(theURL,winName,features);
}
function OpenPopup(NewSite,WinWidth,WinHeight){
	var leftVal=(screen.width / 2) - 400;
	var topVal = (screen.height / 2) - 350;
	newWindow = window.open(NewSite,"Help","toolbar=yes,location=yes,scrollbars=yes,status=no,resizeable=yes,width="+WinWidth+",height="+WinHeight+",left="+leftVal+",top="+topVal+"");
}
function OpenRODIS() { //v2.0
	var leftVal=(screen.width / 2) - 480;
	var topVal = (screen.height / 2) - 330;
	newWindow = window.open("http://www.record-lrc.co.uk/RODISCore/RODIS.aspx", "RODIS", "resizeable=no,toolbar=no,location=no,scrollbars=no,status=no,width=960,height=660,left="+leftVal+",top="+topVal+"")
}