// Javascript function to generate Mailto tags


CheckForCurrentPage();

function InsertMailToTag( userName, domainName)
{
var EmailId;
var atSign = "&#64;"
var fullStop = "&#46";

EmailId = userName;
EmailId = "" + EmailId + atSign; 
EmailId = EmailId + domainName;

document.write( "<a href='mail" + "to:" + EmailId + "'>" + EmailId +"</A>" );
}

//
// functions to set current location
//
// Globals 
var LastErrCount = 0


function CheckForCurrentPage()
{

for (var i= 0; i < document.links.length; i++)
	{

 
	if (window.document.links[i].className == "top-link")
	{
	if (window.location.href == window.document.links[i])
		{window.document.links[i].className = "top-current"
		}
	}
	{ //Else
	
	// special case for home page
	if (window.location.href + "index.html" == window.document.links[i])
          {
            if (window.document.links[i].className == "top-link")
		{window.document.links[i].className = "top-current"
		// alert(window.location.href)
		//alert(window.document.links[i].className)
		}

           }
         if (window.document.links[i].className == "LeftNav")
	  {
	    if (window.location.href == window.document.links[i])
		{window.document.links[i].className = "LeftNavCurrent"
		} 
           
           }
	}


	}

return 
}



function CheckForThisTopLinkText(linkText)

//
// Change top navigation link text for a given input 
// NB only works for IE (need to find something for other browers)
{

for (var i= 0; i < document.links.length; i++)
	{
 	if (window.document.links[i].className == "top-link")
	{

	if (window.document.links[i].innerHTML == linkText)
		{window.document.links[i].className = "top-current"
		}
	}
	}

return 
}



//
// Validate form fields
//

 function ValidateFormFields()
{

 var FirstErrField = -1;
 var FormValidatedOK = true ; // default to being OK
 var thisErrCount = 0;

 // add an entry in here for any form fields that are mandatory

// These fields are always required


 document.downloadTrial.elements["LastName"].required = true;
 document.downloadTrial.elements["FirstName"].required = true;
 document.downloadTrial.elements["email"].required = true;
 document.downloadTrial.elements["subject"].required = true;
 document.downloadTrial.elements["AddressLine1"].required = true;
 document.downloadTrial.elements["Town"].required = true;
 document.downloadTrial.elements["County"].required = true;
 document.downloadTrial.elements["PostCode"].required = true;
 document.downloadTrial.elements["Company"].required = true;

var namestring  =   document.downloadTrial.elements["LastName"].value;
document.downloadTrial.elements["LastName"].value   = Trim(namestring);
namestring  =   document.downloadTrial.elements["FirstName"].value;
document.downloadTrial.elements["FirstName"].value   = Trim(namestring);

 MissingFields = "";

 for (i=0; i < document.downloadTrial.elements.length; i++)
    { if (document.downloadTrial.elements[i].required == true)
      {if (document.downloadTrial.elements[i].value == "")
        { if (FirstErrField == -1) {FirstErrField = i};
          thisErrCount = thisErrCount + 1;
          MissingFields = MissingFields + document.downloadTrial.elements[i].name + "\n";};
      }
    }
 if ((MissingFields != "") )
       {
         LastErrCount = thisErrCount;
         alert("The following fields have not been supplied:" + "\n\n" +
                MissingFields + "\n" + "Please correct and re-send");
         FormValidatedOK = false;
	document.downloadTrial.elements[FirstErrField].focus();
         }



 if (FormValidatedOK == true) // Emaild_id has a value but is it correct
 	{
 	if (document.downloadTrial.elements["email"].value.indexOf('@') == -1)
 	 	{
 		alert("Email id invalid :  does not contain @"+ "\n" + "Please correct and re-send");
 		FormValidatedOK = false;
 		}

 	}


 if (FormValidatedOK == true)
          {
          return true;
          }
          else
          {return false};
 }



function LTrim(str) {
 for (var i=0; str.charAt(i)<=" "; i++);
 return str.substring(i,str.length);
}

function RTrim(str) {
 for (var i=str.length-1; str.charAt(i)<=" "; i--);
 return str.substring(0,i+1);
}

function Trim(str) {
if (str == "")
{
return "";
} 
else
{
 return LTrim(RTrim(str));
}
}


function email_a_friend(email_to,email_subject,email_body) 
{ 
if ((email_subject=="") || (email_subject==null)) 
email_subject="Ueeful calculator"; 
window.location="mailto:"+email_to+"?subject="+email_subject+"&body="+email_body; 
//temp= "mailto:"+email_to+"?subject="+email_subject+"&body="+email_body; 
//alert (temp);
} 