/*
 * Description: Javascript code for the Advogato 2 FOAF Utility
 *
 * Author: Leigh Dodds, leigh@ldodds.com 
 *
 * Dependencies: depends on Paul Johnston's SHA1 Javascript implementation
 *                     see http://pajhome.org.uk/crypt/md5/ for details. 
 */
 
gTidyUrl='http://cgi.w3.org/cgi-bin/tidy?docAddr=';
gXSLTUrl='http://www.w3.org/2000/06/webdata/xslt?xslfile=';
gStylesheet='http://www.ldodds.com/foaf/advogato/person2foaf.xsl';

function generate()
{
   if (validate())
   {
      sha1sum = calcSHA1('mailto:' + document.details.mbox.value);

      params = 'sha1sum=' + sha1sum;

      if (!document.details.spamProtect.checked)
      {
         params = params + '&mbox=' + document.details.mbox.value;
      }

      profile = 'http://www.advogato.org/person/' + document.details.nick.value;
      
      tidyurl = escape(gTidyUrl + profile);
      
      url = gXSLTUrl + gStylesheet + "&" + params + "&xmlfile=" + tidyurl;
      
      windowbits = "width=500,height=400,toolbar=no,location=yes,status=yes,menubar=no,scrollbar=yes";
      
      window.open(url, 'FOAF', windowbits ); 
   }
   
}

function validate()
{
    isValid = true;
    msg = 'You must complete these fields\n';

    if (document.details.nick.value=='')
    {
        isValid=false;
        msg = msg + 'Your nickname\n';
    }

    if (document.details.mbox.value=='')
    {
        isValid=false;
        msg = msg + 'Your email\n';
    }

    if (!isValid)
    {
      alert(msg);
      return false;
    }
    
    return true;
}
