function validateSurveyForm(frm)
{
    if(frm.txtName.value=="")
    {
        alert("Oops! Name is missing        ")
        frm.txtName.focus();
        return false;
    }
    
    if(frm.txtEmail.value=="")
    {
        alert("Oops! Email Address is missing        ")
        frm.txtEmail.focus();
        return false;
    }
    else
    {
    	if(!checkEmail(frm.txtEmail))
    	{
    		return false;
    	}
    }
    
    if(frm.txtPhone.value=="")
    {
        alert("Oops! Phone Number is missing       ")
        frm.txtPhone.focus();
        return false;
    }
    

    for(i=1; i<7; i++)
    {
        q=document.getElementsByName("q"+i);
        var checked;
        checked=false;
        for(var j = 0; j < q.length; j++)
        {
		    if(q[j].checked)
		    {
			    checked=true;
			}
//			if(i==5 && j==1)
//			{
//			    if(q[1].checked && q5details.value=="")
//			    {
//			        alert("Please enter the details for Question 5.");
//			        return false;
//			    }
//			}
		}
		if(!checked)
		{
		    alert("Please answer Question " + i + ".")
		    return false;
		}
    }

    return true;
}



function checkEmail(emailAddr)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailAddr.value))
	{
		return (true)
	}
	alert("Invalid E-mail Address! Please re-enter.")
	emailAddr.focus();
	emailAddr.select();
	return false;
}


function validPhone(field,val)
{
	string =val
	values =""
	n=string.length

	for (i=0;i<n;i++)
		{
			if(string.charCodeAt(i)!=32)
				{
					
				    if (string.charCodeAt(i)<45 || string.charCodeAt(i)>57 || string.charCodeAt(i)==46 || string.charCodeAt(i)==47 )
						{
				    		alert(string.charAt(i)+"  Invalid character")
							window.document.getElementById(field).value=values
							window.document.getElementById(field).focus();
							return false;
						}
					
			values=values+string.charAt(i)
		}
	}
}

function validEntry(field,val)
{
	string =val
	values =""
	n=string.length

	for (i=0;i<n;i++)
		{
			if(string.charCodeAt(i)!=32)
				{
	
				    if(string.charCodeAt(i)<=47 || (string.charCodeAt(i)>57 && string.charCodeAt(i)<65))
						{
				    		alert(string.charAt(i)+"  Invalid character")
							window.document.all.item(field).value=values
							window.document.all.item(field).focus();
							return false;
						}
					for(x=91;x<97;x++) 
						{
							if((string.charCodeAt(i)==x))
							{
								alert(string.charAt(i)+"  Invalid character")
								window.document.all.item(field).value=values
								window.document.all.item(field).focus();
								return false;
							}
						}
						

					if(string.charCodeAt(i)>122)
						{
							alert(string.charAt(i)+"  Invalid character")
							window.document.all.item(field).value=values
							window.document.all.item(field).focus();
							return false;
						}
			values=values+string.charAt(i)
		}
	}
}

function validCity(field,val)
{
	string =val
	values =""
	n=string.length

	for (i=0;i<n;i++)
		{
			if(string.charCodeAt(i)!=32)
				{
				    //if(string.charCodeAt(i)<=47 || (string.charCodeAt(i)>57 && string.charCodeAt(i)<65))
					if((string.charCodeAt(i)<44) || (string.charCodeAt(i)==45) || (string.charCodeAt(i)==46) || (string.charCodeAt(i)==47) || (string.charCodeAt(i)>57 && string.charCodeAt(i)<65))
						{
				    		alert(string.charAt(i)+"  Invalid character")
							window.document.getElementById(field).value=values
							window.document.getElementById(field).focus();
							return false;
						}
					for(x=91;x<97;x++) 
						{
							if((string.charCodeAt(i)==x))
							{
								alert(string.charAt(i)+"  Invalid character")
								window.document.getElementById(field).value=values
								window.document.getElementById(field).focus();
								return false;
							}
						}
						

					if(string.charCodeAt(i)>122)
						{
							alert(string.charAt(i)+"  Invalid character")
							window.document.getElementById(field).value=values
							window.document.getElementById(field).focus();
							return false;
						}
			values=values+string.charAt(i)
		}
	}
}
function validData(field,val)
{
	string =val
	values =""
	n=string.length

	for (i=0;i<n;i++)
		{
			if(string.charCodeAt(i)!=32)
				{
	
				    if(string.charCodeAt(i)<=47 || (string.charCodeAt(i)>57 && string.charCodeAt(i)<65))
						{
				    		alert(string.charAt(i)+"  Invalid character")
							window.document.getElementById(field).value=values
							window.document.getElementById(field).focus();
							return false;
						}
					for(x=91;x<97;x++) 
						{
							if((string.charCodeAt(i)==x))
							{
								alert(string.charAt(i)+"  Invalid character")
								window.document.getElementById(field).value=values
								window.document.getElementById(field).focus();
								return false;
							}
						}
						

					if(string.charCodeAt(i)>122)
						{
							alert(string.charAt(i)+"  Invalid character")
							window.document.getElementById(field).value=values
							window.document.getElementById(field).focus();
							return false;
						}
			values=values+string.charAt(i)
		}
	}
}
function validEntryText(field,val)
{
	string =val
	values =""
	n=string.length
	

	for (i=0;i<n;i++)
		{
			if((string.charCodeAt(i)!=32) && (string.charCodeAt(i)!=33) && (string.charCodeAt(i)!=44) && (string.charCodeAt(i)!=45) && (string.charCodeAt(i)!=46) && (string.charCodeAt(i)!=58))
				{
	
				   if(string.charCodeAt(i)<65)
						{
				    		window.alert(string.charAt(i)+"  Invalid character");
							window.document.getElementById(field).value=values
							window.document.getElementById(field).focus();
							return false;
						}
					for(x=91;x<97;x++) 
						{
							if((string.charCodeAt(i)==x))
							{
								alert(string.charAt(i)+"  Invalid character")
								window.document.getElementById(field).value=values
								window.document.getElementById(field).focus();
								return false;
							}
						}

					if(string.charCodeAt(i)>122)
						{
							alert(string.charAt(i)+"  Invalid character")
							window.document.getElementById(field).value=values
							window.document.getElementById(field).focus();
							return false;
						}
			values=values+string.charAt(i)
		}
	}
}
function validNumber(field,val)
{
	string =val
	values =""
	n=string.length

	for (i=0;i<n;i++)
		{
			if(string.charCodeAt(i)!=32)
				{
	
				   //if(string.charCodeAt(i)<=57 || (string.charCodeAt(i)>57 && string.charCodeAt(i)<65))
				  
				    if (string.charCodeAt(i)<47 || string.charCodeAt(i)>57)
						{
				    		alert("Invalid Number: " + string.charAt(i))
							window.document.getElementById(field).value=values
							window.document.getElementById(field).focus();
							return false;
						}
					
			values=values+string.charAt(i)
		}
	}
}

