function hasValue(obj, obj_type)    {
  if (obj_type == "TEXT" || obj_type == "PASSWORD")	{
	return (obj.value.length>0);
  	//return ((obj.value.length>0) && (obj.value.search("[\"\'>]")<0) );
  }
}

function isTelephoneValid(theForm) {
	if  (!hasValue(theForm.areacode, "TEXT" ))  res=false;
		objAreaCode=theForm.areacode;
		strAreaCode=theForm.areacode.value;
		res=true;
	if  (!hasValue(theForm.exchange, "TEXT" ))  res=false;
		objExchange=theForm.exchange;
		strExchange=theForm.exchange.value;
		res=true;
	if  (!hasValue(theForm.lastfour, "TEXT" ))  res=false;
		objLastFour=theForm.lastfour;
		strLastFour=theForm.lastfour.value;
		res=true;
	return !(theForm.areacode.value.length<3 || theForm.exchange.value.length<3 || theForm.lastfour.value.length<4) ;
}

function isEmailValid(theForm)  {
	var res=true;
	var email=theForm.emailaddress;
	if (!hasValue(email,"TEXT")) res=false; 
	rr=email.value.split("@");
	if (rr[0].search("['\"><:;,\\/{}[]| ]")>=0) res=false; // illegal char
	pos=email.value.search("@"); if (pos<1) res= false;
	emailval=email.value.slice(pos+1);
	ss=emailval.split(".");
	if (ss.length<=1) res= false; // no '.'
	if (ss[ss.length-1]=="") res=false; // last char '.'
	for (i=0; i<ss.length; i++)  {
		if (ss[i]=="") res= false; //consecutive '..'
		if (ss[i].search("[^A-Za-z0-9_\-]")>=0) res= false; // anything other than alphanumeric
	}
	return res;
}

function isDomainValid(theForm)  {
	var res=true;
	var domain=theForm.domainname;
	var dot=domain.value.indexOf(".");
	if (!hasValue(domain,"TEXT")) res=false; 
	if (dot==-1) res=false;
	return res;
}

//function isIPnumValid(theForm)  {
//	var res=true;
//	var ipnum=theForm.ipnum;
//	if (!hasValue(ipnum,"TEXT")) res=false;
//	if (ipnum.value!="5" && ipnum.value!="13" && ipnum.value!="29" && ipnum.value!="61" && ipnum.value!="125" && ipnum.value!="253") res=false;
//	return res;	
//}	

function isSharedReasonValid(theForm)  {
	var res=true;
	var sharedres=theForm.sharedreason;
	if (theForm.sharedip[1].checked)  {
		if (!hasValue(sharedres,"TEXT")) res=false;
	}
	else  {
		res=true;
	}
	return res;
}

function isOtherReasonValid(theForm)  {
	var res=true;
	var otherres=theForm.otherreason;
	if (theForm.sharedip[1].checked)  {
		if (theForm.sharedreason.value=="other") {
			if (!hasValue(otherres,"TEXT")) res=false;
		}
		else  {
			res=true;
		}
	}
	return res;
}

function myAlert(theForm,field,msg) { alert(msg); field.focus(); return (false); }

function  checkForm_1(_CF_this)    {

	//if (!isIPnumValid(_CF_this))
	//return myAlert(_CF_this,_CF_this.ipnum,"Please enter a valid number of IP's.");
	
	if (!hasValue(_CF_this.ipnum,"TEXT"))
	return myAlert(_CF_this,_CF_this.ipnum,"Please select the number of IP's you wish to add."); 		
		
	if (!hasValue(_CF_this.additional,"TEXT"))
	return myAlert(_CF_this,_CF_this.additional,"Please enter your list of domains."); 	

	if (_CF_this.sharedip[1].checked) {
		if (!hasValue(_CF_this.sharedreason,"TEXT"))
		return myAlert(_CF_this,_CF_this.sharedreason,"Please enter your reason for not using Name-based/shared IP hosting.");
		}
	
	//if(!isSharedReasonValid(_CF_this))
	//return myAlert(_CF_this,_CF_this.sharedreason,"Please enter your reason for not using Name-based/shared IP hosting.");

	if (_CF_this.sharedip[1].checked && _CF_this.sharedreason.value=="other") {
		if (!hasValue(_CF_this.otherreason,"TEXT"))
		return myAlert(_CF_this,_CF_this.otherreason,"Please specify your Other reason for not using Name-based/shared IP hosting.");
		}	
	
	//if(!isOtherReasonValid(_CF_this))
	//return myAlert(_CF_this,_CF_this.otherreason,"Please specify your Other reason for not using Name-based/shared IP hosting."); 	

	if (_CF_this.firstname.value.toLowerCase().match("[a-z][a-z0-9]*")==null) 
	return myAlert(_CF_this,_CF_this.firstname,"Please enter your first name.");

	if (_CF_this.lastname.value.toLowerCase().match("[a-z][a-z0-9]*")==null) 
	return myAlert(_CF_this,_CF_this.lastname,"Please enter your last name.");
	
	if (!isDomainValid(_CF_this))
	return myAlert(_CF_this,_CF_this.domainname,"Please enter a valid Domain Name");	
 
	if (!isTelephoneValid(_CF_this))				
	return myAlert(_CF_this,_CF_this.areacode,"Please enter a valid Daytime Phone Number."); 

	if (!isEmailValid(_CF_this))						
	return myAlert(_CF_this,_CF_this.emailaddress,"Please enter a valid Email Address");
		
	return true;
}