function isValidEmail(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){		   
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){		   	
		   return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){		    
		    return false
		}
		if (str.indexOf(at,(lat+1))!=-1){		    
		   return false
		}
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){		    
		    return false
		}
		if (str.indexOf(dot,(lat+2))==-1){		    
		    return false
		}
		if (str.indexOf(" ")!=-1){		    
		    return false
		}
	 return true					
}

function isNumber(fieldName){
	if (isNaN((document.getElementById(fieldName).value).replace(/^\s+|\s+$/,''))){
		return false;
	}else{
		return true;
	}
}

function isBlank(fieldName){
	if ((document.getElementById(fieldName).value).replace(/^\s+|\s+$/,'')==""){
		return true;
	}else{
		return false;
	}
}

function validateGeneralForm(){		
	errorTxt = ""	
	if (isBlank('generalform_input_email')){
		if (isBlank('generalform_input_tel')){
			errorTxt = "Please enter a valid email address or telephone number<br />" 
		}
		if (!isNumber('generalform_input_tel')){
			errorTxt = "Please enter a valid email address or telephone number<br />" 
		}
	}
	if (!isValidEmail(document.getElementById('generalform_input_email').value)){
		if (isBlank('generalform_input_tel')){
			errorTxt = "Please enter a valid email address or telephone number<br />" 
		}
		if (!isNumber('generalform_input_tel')){	
			errorTxt = "Please enter a valid email address or telephone number<br />" 
		}
	}
		
	if (errorTxt!=""){		
		document.getElementById("generalDetailErrorTxt").innerHTML = "<span>" + errorTxt + "</span>"
		return false;
	}else{
		return true;
	}	
}

function validateMeetingForm(){		
	errorTxt = ""	
	if (isBlank('meetingform_input_tel')){
		errorTxt = "Please enter a telephone number<br />" 
	}
	if (!isNumber('meetingform_input_tel')){
		errorTxt = "Please enter a valid telephone number<br />" 
	}	
	if (isBlank('meetingform_input_email')){
		errorTxt = "Please enter a valid email address<br />" 		
	}
	if (!isValidEmail(document.getElementById('meetingform_input_email').value)){		
		errorTxt = "Please enter a valid email address<br />" 		
	}
	
		
	if (errorTxt!=""){		
		document.getElementById("meetingDetailErrorTxt").innerHTML = "<span>" + errorTxt + "</span>"
		return false;
	}else{
		return true;
	}	
}

function validateWeddingForm(){		
	errorTxt = ""			
	if (isBlank('weddingform_input_tel')){
		errorTxt = "Please enter a telephone number<br />" 
	}
	if (!isNumber('weddingform_input_tel')){
		errorTxt = "Please enter a valid telephone number<br />" 
	}	
	if (isBlank('weddingform_input_email')){
		errorTxt = "Please enter a valid email address<br />" 		
	}
	if (!isValidEmail(document.getElementById('weddingform_input_email').value)){		
		errorTxt = "Please enter a valid email address<br />" 		
	}
	if (errorTxt!=""){		
		document.getElementById("weddingDetailErrorTxt").innerHTML = "<span>" + errorTxt + "</span>"
		return false;
	}else{
		return true;
	}	
}
