function isEmail(emailStr)
{  
	
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>=%@,;:#`!~$\\^&*+\\?{}'\\|/\\\\\\\"\\.\\[\\]"
	var validCharsUser="\[^\\s" + specialChars + "\]"
	var validCharsDomain="\[^\\s" + specialChars + "\[^_" + "\]"
	var atomUser=validCharsUser + '+'
	var atomDomain=validCharsDomain + '+'
	var word="(" + atomUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atomDomain + "(\\." + atomDomain+")*$")
	
	    var matchArray=emailStr.match(emailPat)
	    if (matchArray==null)
		{		
		return false;
		}
	    
		var user=matchArray[1]
	    var domain=matchArray[2]
	    if (user.match(userPat)==null) 
		{
		return false;
		}

	    var domainArray=domain.match(domainPat)
	    if (domainArray==null) 
		{
		return false;
		}

	    var atomPat=new RegExp(atomDomain,"g")
	    var domArr=domain.match(atomPat)
	    var len=domArr.length
	    /*if (domArr[domArr.length-1].length<2 ||	domArr[domArr.length-1].length>3) 
		{
		alert("qwqw");
		return false;
		}*/

	    var endWord="\[^0123456789\]+"
	    var endPat=new RegExp("^(" + endWord + ")+$","g")
	    var endDom = domArr[domArr.length-1].match(endPat)	    
	    if (endDom==null) 
		{
		return false;
		}

	    if (len<2) 
		{
		   //var errStr="This address is missing a hostname!"
		   return false;
		}

	return "true";
  
}

function validateAction(action,label,url){
		regExpForWhSpaces=/^(http:\/\/(www\.)?|https:\/\/(www\.)?|ftp:\/\/(www\.)?){1}([0-9A-Za-z]+((\.){1}[0-9A-Za-z]{2,3})+)$/;
		if(document.getElementById(action).value!=""){
			if(document.getElementById(label).value=="" && document.getElementById(url).value!=""){
				alert("URL cannot exist without label");	
				document.getElementById(label).focus();
				return false;
			}
			if(document.getElementById(url).value=="" && document.getElementById(label).value!=""){
				alert("Label cannot exist without URL");	
				document.getElementById(url).focus();
				return false;
			}
			if(document.getElementById(action).value=="link"){
				if(!regExpForWhSpaces.test(document.getElementById(url).value)){
		    		alert("Only Valid URL is allowed");	
					document.getElementById(url).focus();
					return false;
		    	}	
			}else if(document.getElementById(action).value=="tel:" || document.getElementById(action).value=="sms:"){
				   regExpForWhSpaces=/^\d+$/;
    				if(!regExpForWhSpaces.test(document.getElementById(url).value) || document.getElementById(url).value<1) {
		    		alert("Only Valid telephone/mobile number is allowed");	
					document.getElementById(url).focus();
					return false;
		    	}
			}else if(document.getElementById(action).value=="mailto:"){
				if(!isEmail(document.getElementById(url).value)){
		    		alert("Invalid Email");	
					document.getElementById(url).focus();
					return false;
		    	}
			}
		}
		return true;
}
function funSubmit()
{	
	/*validations here*/
		
		if(document.getElementById("email").value!="" && !isEmail(document.getElementById("email").value) ){
			alert("Invalid Email");
			document.getElementById("email").focus();
			return false;
		}
		if(document.getElementById("title").value=="")
		{
			alert("Title cannot be blank");
			document.getElementById("title").focus();
			return false;
		}
		if(document.getElementById('type').value=="")
		{
			alert("Please select an option from Type");	
			document.getElementById("type").focus();
			return false;
		}
		if(!validateAction('action1','actionlabel1','actionurl1')){
			return false;
		}
		if(!validateAction('action2','actionlabel2','actionurl2')){
			return false;
		}
		if(!validateAction('action3','actionlabel3','actionurl3')){
			return false;
		}
		if(!validateAction('action4','actionlabel4','actionurl4')){
			return false;
		}

		
		regExpForWhSpaces=/^-?\d+(.(\d)+|\d)*$/;
   		if(document.getElementById('latitude').value=="")
		{
			alert("Latitude cannot be blank");	
			document.getElementById("latitude").focus();
			return false;
		}
    	if(document.getElementById('latitude').value!="" && !regExpForWhSpaces.test(document.getElementById('latitude').value)){
    		alert("Only numeric is allowed");	
			document.getElementById("latitude").focus();
			return false;
    	}
    	if(document.getElementById('longitude').value=="")
		{
			alert("Longitude cannot be blank");	
			document.getElementById("longitude").focus();
			return false;
		}
    	if(document.getElementById('longitude').value!="" && !regExpForWhSpaces.test(document.getElementById('longitude').value)){
    		alert("Only numeric is allowed");	
			document.getElementById("longitude").focus();
			return false;
    	}
    	if(document.getElementById('image').value!=""){
			fileValue=document.getElementById('file').value;
			fileExt=fileValue.substring(fileValue.lastIndexOf(".")+1,fileValue.length);
			if(fileExt=="jpeg" || fileExt=="jpg" || fileExt=="bmp" || fileExt=="png" || fileExt=="gif"){
			;
			}else{
				alert("Accepts only image");	
				document.getElementById("image").focus();
				return false;
			}
    	}
	/*validations here*/
		verify_Captcha();
		return false;
}
function funfeedbackSubmit()
{	
	/*validations here*/
		
		if(document.getElementById("email").value=="")
		{
			alert("Email cannot be blank");
			document.getElementById("email").focus();
			return false;
		}
		if( !isEmail(document.getElementById("email").value) ){
			alert("Invalid Email");
			document.getElementById("email").focus();
			return false;
		}
		if(document.getElementById("feedback").value=="")
		{
			alert("Feedback cannot be blank");
			document.getElementById("feedback").focus();
			return false;
		}
		if(document.getElementById("feedback").value.length>8000){
			alert("Feedback cannot exceed 8000 characters.");
			document.getElementById("feedback").focus();
			return false;
		}
	/*validations here*/
		verify_Captcha();
		return false;
}

function submit_form(){

	//alert("submit_form");	
	document.getElementById("form").submit();
}


