var win1;  // image window

function Info(infodoc)
{
   // close any existing description window
   if(win1 && win1.open && !win1.closed) win1.close();  

   w = 650; h = 300;
   o='toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,scrollbars=1';
   o+=',width='+w+',innerWidth='+w+',height='+h+',innerHeight='+h;
   padding='';
   for(var i=0; i<100; i++){padding+='&nbsp;';}
   win1=window.open(infodoc,'win',o);

   win1.focus(); 
}

function Calculator(url)
{
   // close any existing description window
   if(win1 && win1.open && !win1.closed) win1.close();  

   w = 800; h = 700;
   o='toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,scrollbars=1';
   o+=',width='+w+',innerWidth='+w+',height='+h+',innerHeight='+h;
   padding='';
   for(var i=0; i<100; i++){padding+='&nbsp;';}
   win1=window.open(url,'win',o);

   win1.focus(); 
}

function ToggleVis(objname) 
{
   prop = document.getElementById(objname).style;
   prop.display = (prop.display=='none') ? 'block' : 'none';
   twisty0 = document.getElementById('twisty0'+objname).style;
   twisty0.display = (twisty0.display=='none') ? 'inline' : 'none';
   twisty1 = document.getElementById('twisty1'+objname).style;
   twisty1.display = (twisty1.display=='none') ? 'inline' : 'none';
   return false;
};

function Toggle(objname1,objname2)
{
   ToggleOn(objname1);
   ToggleOff(objname2);
   return false;
}

function ToggleOn(objname)
{
   prop = document.getElementById(objname).style;
   prop.display = 'block';
   return false;
}

function ToggleOff(objname)
{
   prop = document.getElementById(objname).style;
   prop.display = 'none';
   return false;
}

function checkForm_register(f)
{
   msg = "Some required fields are not completed. Please complete them and try submitting again."
   if(!valid(f.firstname,   'text'))   {window.alert(msg);                               return false;}
   if(!valid(f.lastname,    'text'))   {window.alert(msg);                               return false;}
   if(!valid(f.telephone,   'number')) {window.alert('telephone not valid');             return false;}
   if(!valid(f.address,     'text'))   {window.alert(msg);                               return false;}
   if(!valid(f.city,        'text'))   {window.alert(msg);                               return false;}
   if(!valid(f.postcode,    'text'))   {window.alert(msg);                               return false;}
   if(!valid(f.email,       'email'))  {window.alert('email not valid');                 return false;}
   if(f.password.value.length < 6)     {window.alert('password less than 6 chars');      return false;}
   if(f.security_code.value.length < 6){window.alert('security code less than 6 chars'); return false;}
   if(!valid(f.privacy,     'request')){window.alert('privacy not checked');             return false;}
   return true;
}

function checkForm_member(f)
{
   if(!valid(f.username,    'text'))   {window.alert('username not valid');         return false;}
   if(f.password.value.length < 6)     {window.alert('password less than 6 chars'); return false;}
   if(f.password.value != f.password_again.value)     
                                       {window.alert('passwords do not match');     return false;}
   if(!valid(f.firstname,   'text'))   {window.alert('firstname not valid');        return false;}
   if(!valid(f.lastname,    'text'))   {window.alert('lastname not valid');         return false;}
   if(!valid(f.email,       'email'))  {window.alert('email not valid');            return false;}
   if(!valid(f.email,       'email'))  {window.alert('email not valid');            return false;}
   if(f.email.value != f.email_again.value)  
                                       {window.alert('emails do not match');        return false;}
   return true;
}

function removeSpaces(str)
{
   nstr = '';
   for(var pos=0; pos<str.length; pos++)
   {
      var c=str.charAt(pos);
      if(c != ' ') nstr = nstr+c;
   }
   return nstr;
}

function valid(field,type)
{
   var fv=field.value;
   var ret=true;
   switch(type)
   {
      case 'number':
         if(!fv) {ret=false;}
         fvns = removeSpaces(fv);
         for(var pos=0; pos<fvns.length; pos++)
         {
            var c=fvns.charAt(pos);
            if(c != '' + parseInt(c) + '') ret=false;
         } 
         break;
      case 'email':
         ret=(fv && !fv.replace( /[\w\-\+]+(\.[\w\-\+]+)*@[\w\-]+(\.[\w\-]+)+/i, "" ) );
         break;
      case 'request':
         if(!field.checked){ret=false;}
         break;
      case 'text':
         if(!fv) {ret=false;}
         break;      
   }
   return ret;
}