errorTitle = 'Error:';
msg1 = 'No Companyname!';
msg2 = 'No Contact Person!';
msg3 = 'Not Checked Offer or Demand!';
msg4= 'No Address or PO box!';
msg5 = 'No City!';
msg6 = 'No text for Trade Advert!';
msg7 = 'No Telephone Number!';
msg8 = 'Password not filled in or is less than 5 characters!';
msg9 = 'Password 2 not filled in or is less than 5 characters!';
msg10 = 'Passwords are not equal!';
msg11 = 'Short Business Description is longer then 255 characters!';
msg12 = 'You must fill in at least one line of description and one keyword!';
msg13 = 'No Fax Number!';
hyperlinkMSG1 = 'The hyperlink does not start with "http://", is it alright to add this?'
var comma='';
var keywords='';
var errormsg = '';
var tDescription='';
var tmp='';

function CheckForm() {
	
  if(!document.dataform.CompanyName.value) errormsg += msg1 + '\n';
  //if(!document.dataform.Contact.value) errormsg += msg2 + '\n';
  var Addr=document.dataform.Address1.value + document.dataform.Address2.value + document.dataform.Address3.value
  if(!Addr) errormsg += msg4 + '\n';
  if(!document.dataform.City.value) errormsg += msg5 + '\n';
  if(!document.dataform.Telephone.value) errormsg += msg7 + '\n';
  if(document.dataform.Telephone.value=="+") errormsg += msg7 + '\n';
  if(!document.dataform.Fax.value) errormsg += msg13 + '\n';
  if(document.dataform.Fax.value=="+") errormsg += msg13 + '\n';
  if(document.dataform.Password.value.length < 5) errormsg += msg8 + '\n';
  if(document.dataform.Password2.value.length < 5) errormsg += msg9 + '\n';  
  if(document.dataform.Password.value != document.dataform.Password2.value) errormsg += msg10 + '\n';
  //var cb = document.dataform.CoreBusiness.value;
  //if(cb.length > 255) errormsg += msg11 + '\n';
  
  
  if((!document.dataform.Type[0].checked) && (!document.dataform.Type[1].checked)) errormsg += msg3 + '\n';
  
  //if(!document.dataform.Tradedescription.value) errormsg += msg6 + '\n';
  tDescription=document.dataform.Tradedescription1.value+' '+document.dataform.Tradedescription2.value;
  tmp='';
  for(var c=0; c<tDescription.length; c++) {
    if(tDescription.charAt(c)!=''||tDescription.charAt(c)!=' ') tmp+=tDescription.charAt(c);
  }
  tDescription=tmp;
  if(tDescription==' ') tDescription='';
  if(tDescription!='') tDescription=tDescription.toLowerCase();
  for(var i=1; i<=5; i++) {
  	if(document.dataform.elements['keyword'+i].value!='') {
	  keywords+=comma+document.dataform.elements['keyword'+i].value;
	  comma=',';
	}
  }
  document.dataform.Tradedescription.value=tDescription+' \n'+keywords;  
  if(keywords==''||tDescription=='') errormsg += msg12 + '\n';
  
	if(errormsg) {
		alert(errorTitle + '\n\n' + errormsg + '\n')
		errormsg = '';
		return;
	} else {
		
		var hyperlink = document.dataform.URL.value;
			if(hyperlink && hyperlink.indexOf('http://')==-1) {
				if (confirm(hyperlinkMSG1)) { document.dataform.URL.value = 'http://' + hyperlink }
			}
		
		document.dataform.submit();
    	
		//alert('OKAY');	
	}
}
