// registration validation
function checkform(thisform)
{
    var errorString = 'Please correct the following errors:\n\n';

    if (thisform.name.value.length<2 || thisform.name.value.length>50) {
        errorString += '* Company/farmer name must be between 2 and 50 characters long\n';
    }

    if (thisform.town.value.length>50) {
        errorString += '* Town/city must be up to 50 characters long\n';
    }

    if (thisform.address.value.length>200) {
        errorString += '* Address must be up to 200 characters long\n';
    }

    if (thisform.postcode.value.length>20) {
        errorString += '* Postcode must be up to 20 characters long\n';
    }

    if (thisform.email.value.indexOf('.') == -1 || thisform.email.value.indexOf('.') < 2 || thisform.email.value.indexOf('@') < 2 || thisform.email.value.length>50) {
        errorString += '* Enter a valid email address, up to 50 characters long\n';
    }

    if (thisform.email.value != thisform.email2.value) {
        errorString += '* Email addresses do not match\n';
    }

    if (thisform.password.value.length<4 || thisform.password.value.length>16) {
        errorString += '* Password must be between 4 and 16 characters long\n';
    }

    if (thisform.password.value != thisform.password2.value) {
        errorString += '* Passwords do not match\n';
    }

    if (thisform.telephone.value.length>15) {
        errorString += '* Telephone number must be up to 15 characters long\n';
    }
    
    if (thisform.fax.value.length>15) {
        errorString += '* Fax number must be up to 15 characters long\n';
    }

    if (thisform.url.value.length > 100 || thisform.url.value.indexOf('http://') != 0 || thisform.url.value.length < 10 || thisform.url.value.indexOf('.') < 8) {
        errorString += '* URL must be from 10 to 100 characters long, and must start with http://\n';
    }

    if (thisform.product1.value.length == 0 || thisform.product1.value == 'please select...') {
        errorString += '* At least one product/heading must be selected\n';
    }

    if (thisform.about.value.length > 250) {
        errorString += '* Up to 250 characters are allowed in the "About" field\n';
    }

    // FINALLY... ***************
    if (errorString != 'Please correct the following errors:\n\n') { 
        alert (errorString);
        return false; 
    } else { 
        return true; 
    }   

}


// printer friendly version
function Clickheretoprint()
{ 
  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
      disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 
  var content_vlue = document.getElementById("print_content").innerHTML; 
  
  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><title>www.farminguk.com/</title></head>'); 
   docprint.document.write('<body onLoad="self.print()"><div align="left">');          
   docprint.document.write(content_vlue);          
   docprint.document.write('</div></body></html>'); 
   docprint.document.close(); 
   docprint.focus(); 
}


// just clears the content of a text field
function clearField (frm) {
    frm.value = '';
}

// validates and email address in registration/updates
function validateEmail(frm) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = frm.email.value;
    if(reg.test(address) == false) {
        alert('Invalid email address. Please correct.');
        return false;
    }
    return true;    
}

// redirects for different RSS feeds
function redirect(rssSelector)
{
	if(rssSelector.options[rssSelector.selectedIndex].value != "")
		location = "/rss.asp?category=" + rssSelector.options[rssSelector.selectedIndex].value;
}