function trimSpace(x)
{
	if(navigator.appName == "Netscape")
		formobj = document.layers['Layer1'].document.frmQuestionarrie;
	else
		formobj = document.frmQuestionarrie;
	var emptySpace = / /g;
	var trimAfter = x.replace(emptySpace,"");
	return(trimAfter);
}

function emailCheck () {
if(navigator.appName == "Netscape")
		formobj = document.layers['Layer1'].document.frmQuestionarrie;
	else
		formobj = document.frmQuestionarrie;
frmSubmit();
var emailStr
emailStr=formobj.email.value;

var emailPat=/^(.+)@(.+)$/

var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

var validChars="\[^\\s" + specialChars + "\]"

var quotedUser="(\"[^\"]*\")"

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

var atom=validChars + '+'

var word="(" + atom + "|" + quotedUser + ")"

var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")



var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  
	alert("Email address is not valid")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]


if (user.match(userPat)==null) {
    
    alert("The username doesn't seem to be valid.")
    return false
}

var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}
var phone=formobj.phone.value

if(trimSpace(phone).length == 0)  {

  alert("Contact phone is required");
  formobj.phone.focus();
  formobj.phone.value = "";
		formobj.phone.focus();	
  
  return false;
 }
 
 if (isNaN(formobj.phone.value))
 {
    alert ("Contact phone should be Numeric....");
    if (navigator.appName=="Microsoft Internet Explorer")
    {
    formobj.phone.style.color="red";
    }
    formobj.phone.focus();
    return false;
 }
 
 
 
 var City=formobj.city.value
 if(trimSpace(City).length == 0||formobj.city.value == "City")
  {
  alert(" City is required");
  {
  formobj.city.focus();
  formobj.city.value = "";
  }
	formobj.city.focus();	  
  return false;
 }
 
 if(City.search(/[^a-zA-Z ]/g) != -1)
	{
		alert("Only characters and spaces are allowed in City.")
			formobj.city.focus();		
		return false;
	}
	
	

 if (formobj.country.options[formobj.country.selectedIndex].value == "notset") {
	  formobj.country.focus();
        alert ("ERROR - Select Your Country");
	  return false;
	} 
  

var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    return false
}


var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("The email address must end in a three-letter domain, or two letter country.")
   return false
}


if (len<2) {
   var errStr="This email address is missing a hostname!"
   alert(errStr)
  
return false
}


return true;
}

  
function frmSubmit()
{
	if(navigator.appName == "Netscape")
		formobj = document.layers['Layer1'].document.frmQuestionarrie;
	else
		formobj = document.frmQuestionarrie;
	
	userName = formobj.T1.value;
	
	if(trimSpace(userName).length == 0  ) 
	{
		alert("Name cannot be empty.");
		formobj.T1.value = "";
		formobj.T1.focus();
		return false;	
	}
	else if(userName.search(/[^a-zA-Z ]/g) != -1)
	{
		alert("Only characters and spaces are allowed in Name.")
		formobj.T1.select();
		formobj.T1.focus();		
		return false;
	}
	

      else if(formobj.T1.value == "Name")

       {
                alert("Give your name");
		formobj.T1.value = "";
		formobj.T1.focus();
		return false;	
       }
	

}

function formsubmit()
{

if(navigator.appName == "Netscape")
		formobj = document.layers['Layer1'].document.frmQuestionarrie;
	else
		formobj = document.frmQuestionarrie;

if(!(emailCheck ()) )
{
return false;
}


else {

var t1,userName,userEmail,t2,web,t3,t4,t5,t6
userName = formobj.T1.value;
	userEmail = formobj.email.value;
	web=formobj.website.value;
	t4 = formobj.phone.value;
	t5 = formobj.city.value;
	t6=formobj.country.options[formobj.country.selectedIndex].value;

	
	t1="?"+"T1"+"="+userName+"&"+"T2"+"="+userEmail+"&"+"website"+"="+web+"&"+"T4"+"="+t4+"&"+"city"+"="+t5+"&"+"country"+"="+t6
	t3="http://www.stratstats.com/rca/enadu/citiform.asp"+t1; 
 window.open(t3,width="600", height="600" );
 formobj.reset();
}

}