
	function checkLogin(){
		var failMessage=""; 
		var valid=false;
		
		var reg=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
		if(reg.test(document.frmuserlogin.txtlogin.value))
		{ // if syntax is valid
			valid=true;
		}
		else
		{		
			failMessage="You don't appear to have entered a valid email address - please make changes and re-submit...";
			alert("Please enter a valid email address");
		}
		//test pass
		if(document.frmuserlogin.txtpassword.value.length<6 && valid)
		{	
						
				failMessage="Your password should be at least 6 characters..";
				alert(failMessage);
				valid=false;
		}
		
		if(valid)
		{
			document.frmuserlogin.method="POST";
			document.frmuserlogin.action="loginUserAction.php";
			document.frmuserlogin.submit();
		}
	
	}//end checkLogin

	//handles standard user registration
	function sendUserRegister(){
			var failMessage="";
			var valid=false;
			//newsletter value for php
			document.frmuserregistration.txtuser_newsletter.value=document.frmuserregistration.txtuser_newsletter.checked;

			for(var i=0;i<document.frmuserregistration.elements.length;i++)
			{
				//values in all boxes
				if(document.frmuserregistration.elements[i].value=="")
				{
					alert("You have not completed all field values"); 
					return;
				}
			}
			
			
			//do some checking on the mail field
			
  			var reg=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
			//tests
			//email
			if (reg.test(document.frmuserregistration.txtuser_id.value)) 
			{ // if syntax is valid
				valid=true;
			}
			else
			{		
				failMessage="You don't appear to have entered a valid email address - please make changes and re-submit...";
				alert(failMessage);
				return;
			}	
		
			//pass length
			if(document.frmuserregistration.txtuser_password.value.length<6)
			{	
				
				failMessage="Your password needs to be at least 6 characters..";
				alert(failMessage);
				return;
			}
			//pass matches
			else if(document.frmuserregistration.txtuser_password.value != document.frmuserregistration.txtuser_password_confirm.value)
			{
				failMessage="Your passwords dont match?";
				alert(failMessage);
				return;
			}

			//firstnames commas
			var keys=new RegExp("^[a-zA-Z0-9,-]*$","i");
 
			if(!keys.test(document.frmuserregistration.txtuser_firstnames.value))
			{
				alert("Please separate firstnames with comma's and no white space.");
				return;
			}

				document.frmuserregistration.method="POST";
				document.frmuserregistration.action="registerUserAction.php";
				document.frmuserregistration.submit();
		}
		//useredit on smartyUserViewDetails
		function sendUserEdit(val){
	
			
			if(val=="submit")
			{
				if(document.frmauthor.txtuser_password.value.length>0 && document.frmauthor.txtuser_password.value.length<6)
				{	
					
					failMessage="Your password needs to be at least 6 characters..";
					alert(failMessage);
					return;
				}
					//pass matches
				if(document.frmauthor.txtuser_password.value.length>0 && (document.frmauthor.txtuser_password.value != document.frmauthor.txtuser_confirm_password.value) )
				{
					failMessage="Your passwords dont match?";
					alert(failMessage);
					return;
				}
			}

			document.frmauthor.method="POST";
			document.frmauthor.action="userEditDetails.php";
			document.frmauthor.bContentMode.value=val;
			document.frmauthor.submit();
		}
		//author detail submit function
			function sendAuthorEdit(val){
				
			if(val=="submit")
			{
				if(document.frmauthor.txtauthor_password.value.length>0 && document.frmauthor.txtauthor_password.value.length<6)
				{	
					
					failMessage="Your password needs to be at least 6 characters..";
					alert(failMessage);
					return;
				}
					//pass matches
				if(document.frmauthor.txtauthor_password.value.length>0 && (document.frmauthor.txtauthor_password.value != document.frmauthor.txtauthor_confirm_password.value) )
				{
					failMessage="Your passwords dont match?";
					alert(failMessage);
					return;
				}
				//telephone
				var tele=/^\d+\s*\d*\s*\d*\s*\d*$/;
		
				if(!tele.test(document.frmauthor.txtauthor_telephone.value) )
				{
					alert("Please don't use any non-numeric characters in the telephone field");
					return;
				}
			}
			document.frmauthor.method="POST";
			document.frmauthor.action="authorEditDetails.php";
			document.frmauthor.bContentMode.value=val;
			document.frmauthor.submit();
		}
		//add author functionality
		function sendAuthor(){
			//check for inputs
			for(var i=0;i<document.frmauthor.elements.length;i++)
			{
				//values in all boxes
				if(document.frmauthor.elements[i].value=="")
				{
					alert("You have not completed all field values"); 
					return;
				}
			}
		
		
			//telephone
			var tele=/^\d+\s*\d*\s*\d*\s*\d*$/;
		
			if(!tele.test(document.frmauthor.txtauthor_telephone.value) )
			{
				alert("Please enter telephone field as area code<space>number");
				return;
			}
		
			document.frmauthor.method="POST";
			document.frmauthor.bContentSubmitted.value=true;
			document.frmauthor.action="authorAddDetails.php";
			document.frmauthor.submit();
		}
		//add Map post function
		function sendMap(val){
		
		
		if(val=="summary_submit")
		{
			var mapfile=document.frmmap.txtmapsumm_map.value;
			var artfile=document.frmmap.txtmapsumm_article.value;
			
			if(!document.frmmap.txtmapsumm_alt_transfer_option.checked) 
			{
				//have we got anything?
				if(mapfile=="" || artfile=="") 
				{
					alert("You havent entered a map file upload");
					return;
				}
				//ok, something there but are they the right type - map first
				var strpdf= /.pdf/i;
				var strdoc= /.doc/i;
				var strrtf= /.rtf/i;
				var strdocx= /.docx/i;

				if(mapfile.search(strpdf)==-1)
				{
					alert("We can only accept map's as pdf documents. Please convert you document to pdf.");
					return;
				}
				if(artfile.search(strdoc)==-1 && artfile.search(strrtf)==-1 && artfile.search(strpdf)==-1)
				{
					alert("We can only accept article's as Microsoft Word (doc), or Rich Text Format (rtf) format's.");
					return;
				}

				if(artfile.search(strdocx)!=-1)
				{
					alert("We donot accept DOCX. Please save your file in Microsoft Word DOC format.");
					return;
				}					
					
			}
			else
			{
				if(document.frmmap.txtmapsumm_map.value.length>0||document.frmmap.txtmapsumm_article.value.length>0)
				{
					alert("If you are transferring files using our alternative upload feature please ensure both map and article boxes are left blank.");
					return;
				}
				document.frmmap.txtmapsumm_alt_transfer_option.value=1;
			}
			if(!(document.frmmap.txtmapsumm_termsconds.checked) )
			{
				alert("You need to accept our Terms and Conditions to publish!");
				return;
			}
		}
		else if(val=="basic_submit")
		{
			for(var i=0;i<document.frmmap.elements.length;i++)
			{
				//values in all boxes
				if(document.frmmap.elements[i].value=="")
				{
					alert("You have not completed all field values"); 
					return;
				}
			}
			
			//are both referee boxes actually email addresses
			//var reg=/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
 			var reg=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
			if (!reg.test(document.frmmap.txtmapbasic_referee1_email.value))
				{
					alert("Please make sure your first referee email address is valid");
					return;
				}
				if(!reg.test(document.frmmap.txtmapbasic_referee2_email.value)) 
				{
					alert("Please make sure your second referee email address is valid");
					return;
				}
			//check both referees are differnt
			if(document.frmmap.txtmapbasic_referee1_email.value==document.frmmap.txtmapbasic_referee2_email.value)
			{
				alert("You appear to have entered the same referee twice!");
				return;
			}
			document.frmmap.txtmapbasic_abstract.value=trimAll(document.frmmap.txtmapbasic_abstract.value);
			
			//keyword commas
			var keys=new RegExp("^[a-zA-Z0-9,-]*$","i");
 
		if(!keys.test(document.frmmap.txtmapbasic_keyword.value))
			{
				alert("Please separate keywords with comma's and no white space.");
				return;
			}
			//firtsname commas
 
			if(!keys.test(document.frmmap.txtmapbasic_referee1_firstnames.value))
			{
				alert("Please separate referee 1 firstnames with comma's and no white space.");
				return;
			}
			if(!keys.test(document.frmmap.txtmapbasic_referee2_firstnames.value))
			{
				alert("Please separate referee 2 firstnames with comma's and no white space.");
				return;
			}
		}
		else if(val=="geog_submit")
		{

			//geog
			for(var i=0;i<document.frmmap.elements.length;i++)
			{
				if(document.frmmap.elements[i].value=="")
				{
					if(!(document.frmmap.elements[i].name=="txtmapgeog_authornotes"))
					{
						alert("You have not completed all field values"); 
						return;
					}

				}

			}
			
			var reg=/^[+-]\d+[.]*\d+$/i;
			if((!reg.test(document.frmmap.txtmapgeog_lower_left_x.value))||(!reg.test(document.frmmap.txtmapgeog_lower_left_y.value))||(!reg.test(document.frmmap.txtmapgeog_upper_right_x.value))||(!reg.test(document.frmmap.txtmapgeog_upper_right_y.value)))
			{
				alert("Your coordinate fields should contain either + or -, followed by no more than 8 digits, with an optional decimal point. Some users may need to add the decimal point to proceed.");
				return;
			}
			
		
		
		}
		document.frmmap.method="POST";
		document.frmmap.bMapWizardMode.value=val;
		document.frmmap.action="authorAddMap.php";
		document.frmmap.submit();	
		}
		
		
		//add Map wizard go back
		function sendMapGoBack(val){
			document.frmmap.method="POST";
			document.frmmap.bMapWizardMode.value=val;
			document.frmmap.action="authorAddMap.php";
			document.frmmap.submit();
		}
		//change handler to disable/enable region search box
		function searchRegionEnabler(){
			if(document.getElementById('se_region_search').checked)
			{
				document.getElementById('se_region_select').disabled=true;
			}
			else
			{
				document.getElementById('se_region_select').disabled=false;
			}
		}
		//function to handle the text search facility on index.php
		function submitTextSearch(){
			//check user hasnt tried all regions, no text
			
			//alert("The search engine is not yet enabled. We are currently accepting maps for review and publication and will enable the search once the first publication is due.");
			
			if(document.frm_txt_searchengine.se_region_select.value==-1 && document.frm_txt_searchengine.se_keywords.value=="")
			{
					alert("Please enter a keyword to search all regions for..");
					return false;
			}
			
			document.frm_txt_searchengine.method="POST";
			document.frm_txt_searchengine.bSearchSubmitted.value=true;
			document.frm_txt_searchengine.action="index.php";
			document.frm_txt_searchengine.submit();
			return;
		}
		//request report
		function requestReport(mapid,userid){
			document.frmRequestReport.method="POST";
			document.frmRequestReport.mid.value=mapid;
			document.frmRequestReport.uid.value=userid;
			document.frmRequestReport.action="submitReport.php";
			document.frmRequestReport.submit();
		}
		//request editor report
		function requestEditorReport(mapid,userid){
			document.frmRequestReport.method="POST";
			document.frmRequestReport.mid.value=mapid;
			document.frmRequestReport.uid.value=userid;
			document.frmRequestReport.action="submitReportEditor.php";
			document.frmRequestReport.submit();
		}
		//function to submit a report
		function submitReport(){
		
			var strpdf= /.pdf/i;
			var strdoc= /.doc/i;
			var strrtf= /.rtf/i;

			var docfile=document.frmsubmitreport.txtsubmit_file.value;

			if(docfile.search(strdoc)==-1 && docfile.search(strrtf)==-1 && docfile.search(strpdf)==-1)
			{
					alert("We can only accept article's as Microsoft Word (doc),Rich Text Format (rtf) or Portable Document Format(pdf).");
					return;
			}
			document.frmsubmitreport.method="POST";
			document.frmsubmitreport.action="submitReport.php";
			if(document.frmsubmitreport.txtsubmit_file.value != null)
			{
				document.frmsubmitreport.contentsubmitted.value=true;
			}
			document.frmsubmitreport.submit();
		}
		//function to submit a report
		function submitReportEditor(){

			var strpdf= /.pdf/i;
			var strdoc= /.doc/i;
			var strrtf= /.rtf/i;

			docfile=document.frmsubmitreport.txtsubmit_file.value;

			
			if((docfile.search(strdoc)==-1) && (docfile.search(strrtf)==-1) && (docfile.search(strpdf)==-1))
						{
								alert("We can only accept article's as Microsoft Word (doc),Rich Text Format (rtf) or Portable Document Format(pdf).");
								return;
			}
			
			document.frmsubmitreport.method="POST";
			document.frmsubmitreport.action="submitReportEditor.php";
			if(document.frmsubmitreport.txtsubmit_file.value != null)
			{
				document.frmsubmitreport.contentsubmitted.value=true;
			}
			document.frmsubmitreport.submit();
		}
		function trimAll( strValue ) {
	/************************************************
	DESCRIPTION: Removes leading and trailing spaces.
	
	PARAMETERS: Source string from which spaces will
	  be removed;
	
	RETURNS: Source string with whitespaces removed.
	*************************************************/
	 var objRegExp = /^(\s*)$/;
	
		//check for all spaces
		if(objRegExp.test(strValue)) {
		   strValue = strValue.replace(objRegExp, '');
		   if( strValue.length == 0)
			  return strValue;
		}
	
	   //check for leading & trailing spaces
	   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
	   if(objRegExp.test(strValue)) {
		   //remove leading and trailing whitespace characters
		   strValue = strValue.replace(objRegExp, '$2');
		}
	  return strValue;
	}
