function trim(s1) {
  s=new String(s1);
  while ((s.length>0) && (s.charAt(s.length-1)==" ")) 
    s = s.substr(s,s.length-1);
  return s;
}

function EMailChecker(ss)
  {var qq;
   if (ss.length>0)
      {qq = ss.match(/\w+(\.\w+)*@\w+(\.\w+)*/);
       if (qq) {qq=qq[0];}
       if (!qq || (qq!=ss))
              {return false;}
      }
   else
      {return false;}
   return true;
  }

function Too_Mach(s1) {
  s=new String(s1);
  var ss, max_len, word;
  max_len = 100;
  var enter = String.fromCharCode(13, 10);
  s.replace(enter, ' ');
  ss = s.split(' ');
  for (word in ss)
  	if (ss[word].length > max_len)
		return true
  return false;
}

function form_valid() {
    var newstr;
	newstr="";
	var bper;
	bper=0;
	document.form1.radiof.value="";
	document.form1.checkf.value="";
	document.form1.radios.value="";
	document.form1.radiot.value="";
	document.form1.radioc.value="";
	document.form1.techn.value="";
	document.form1.db.value="";
	document.form1.serv.value="";
	document.form1.cms.value="";
	document.form1.site_feat.value="";
	document.form1.payments.value="";
	if (trim(document.form1.name.value)==""){
    	alert("The field 'Name' can not be empty!");
		return false;}
	if (Too_Mach(document.form1.name.value)){
    	alert("The field 'Name' contains too long word!");
		return false;}
	if (trim(document.form1.email.value)==""){
    	alert("The field 'Email' can not be empty!");
		return false;}
	if (!EMailChecker(document.form1.email.value)){	
	    alert("Your Email is wrong!");
		return false;}
	if (trim(document.form1.description.value)==""){
    	alert("The field with detail decription can not be empty!");
		return false;}
	if (Too_Mach(document.form1.description.value)){
    	alert("The field with detail decription contains too long word!");
		return false;}

	if (document.form1.radio1[0].checked)
	   {document.form1.radiof.value=document.form1.radio1[0].value;} 
	if (document.form1.radio1[1].checked)
	   {if (trim(document.form1.site_url.value).length<10){
	    	alert("Please, specify url of 'Maintenance or upgrade of an existing site'!");
			return false;}
	    else
		   {document.form1.radiof.value="Maintenance or upgrade of an existing site "+document.form1.site_url.value;} 
	   } 
	if (document.form1.radio1[2].checked)
	   {if (trim(document.form1.des_site_url.value).length<10){
	    	alert("Please, specify url of similar site!");
			return false;}
	    else
		   {document.form1.radiof.value="Design of a site similar to "+document.form1.des_site_url.value;} 
	   }
	if (document.form1.radio1[3].checked)
	   {if (trim(document.form1.other.value)==""){
	    	alert("Please, enter type of site design!");
			return false;}
	    else
		   {document.form1.radiof.value=document.form1.other.value;} 
	   }   
	
	     if (document.form1.check1.checked)  
	         {document.form1.checkf.value=document.form1.checkf.value+document.form1.check1.value+"; ";}
	
	     if (document.form1.check2.checked)  
	         {document.form1.checkf.value=document.form1.checkf.value+document.form1.check2.value+"; ";}
	
	     if (document.form1.check3.checked)  
	         {document.form1.checkf.value=document.form1.checkf.value+document.form1.check3.value+"; ";}
	
	     if (document.form1.check4.checked)  
	         {document.form1.checkf.value=document.form1.checkf.value+document.form1.check4.value+"; ";}
	
//	     if (document.form1.check5.checked)  
//	         {document.form1.checkf.value=document.form1.checkf.value+document.form1.check5.value+"; ";}
	
	//alert(document.form1.checkf.value);
	for (i=0;i<6;i++)
	     {if (document.form1.radio2[i].checked)  
	         {document.form1.radios.value=document.form1.radio2[i].value;}
		 }	 

	for (i=0;i<8;i++)
	     {if (document.form1.technology[i].checked)  
	         {document.form1.techn.value=document.form1.technology[i].value;}
		 }	
	if (document.form1.technology[8].checked)
	   {if (trim(document.form1.other_tech.value)==""){
	    	alert("Please, specify prefered technology!");
			return false;}
	    else
		   {document.form1.techn.value=document.form1.other_tech.value;} 
	   }  
	for (i=0;i<5;i++)
	     {if (document.form1.databases[i].checked)  
	         {document.form1.db.value=document.form1.databases[i].value;}
		 }	
	if (document.form1.databases[5].checked)
	   {if (trim(document.form1.other_db.value)==""){
	    	alert("Please, specify prefered databases!");
			return false;}
	    else
		   {document.form1.db.value=document.form1.other_db.value;} 
	   }       	 
	for (i=0;i<4;i++)
	     {if (document.form1.server[i].checked)  
	         {document.form1.serv.value=document.form1.server[i].value;}
		 }	
	if (document.form1.server[4].checked)
	   {if (trim(document.form1.other_srv.value)==""){
	    	alert("Please, specify type of your web server!");
			return false;}
	    else
		   {document.form1.serv.value=document.form1.other_srv.value;} 
	   }
	for (i=0;i<2;i++)
	     {if (document.form1.need[i].checked)  
	         {document.form1.cms.value=document.form1.need[i].value;}
		 }	
	
	     if (document.form1.fcheck1.checked)  
	         {document.form1.site_feat.value=document.form1.site_feat.value+document.form1.fcheck1.value+"; ";}
	
	     if (document.form1.fcheck2.checked)  
	         {document.form1.site_feat.value=document.form1.site_feat.value+document.form1.fcheck2.value+"; ";}
	
	     if (document.form1.fcheck3.checked)  
	         {document.form1.site_feat.value=document.form1.site_feat.value+document.form1.fcheck3.value+"; ";}
	
	     if (document.form1.fcheck4.checked)  
	         {document.form1.site_feat.value=document.form1.site_feat.value+document.form1.fcheck4.value+"; ";}
	
	     if (document.form1.fcheck5.checked)  
	         {document.form1.site_feat.value=document.form1.site_feat.value+document.form1.fcheck5.value+"; ";}
	
	     if (document.form1.fcheck6.checked)  
	         {document.form1.site_feat.value=document.form1.site_feat.value+document.form1.fcheck6.value+"; ";}
	
	for (i=0;i<5;i++)
	     {if (document.form1.payment[i].checked)  
	         {document.form1.payments.value=document.form1.payment[i].value;}
		 }	
	if (document.form1.payment[5].checked)
	   {if (trim(document.form1.other_pay.value)==""){
	    	alert("Please, specify prefered payment system!");
			return false;}
	    else
		   {document.form1.payments.value=document.form1.other_pay.value;} 
	   }

	for (i=0;i<3;i++)
	     {if (document.form1.radio3[i].checked)  
	         {document.form1.radiot.value=document.form1.radio3[i].value;}
		 }	
	for (i=0;i<4;i++)
	     {if (document.form1.radio4[i].checked)  
	         {document.form1.radioc.value=document.form1.radio4[i].value;}
		 }	
	if (document.form1.radio4[4].checked)
	   {if (trim(document.form1.other_start.value)==""){
	    	alert("Please, specify when would you like the project to start!");
			return false;}
	    else
		   {document.form1.radioc.value=document.form1.other_start.value;} 
	   }
	  return true;
}  
