////////////////////////////////////////
function Goto(form_name, tmpl, pairs_to_set)
{
   var form = document.forms[form_name];
  
   if (typeof(form) != 'undefined') {
      form.template.value = tmpl;

      //
      // "Zero" the news_id if any...
      //
      if (typeof(form.news_id) != 'undefined') form.news_id.value = '';

      //
      // The user may pass several name & values to
      // be set, i.e. the user passes
      //    name1=value1&name2=value2&...&nameN=valueN
      // and we set
      // form.name1.value = value1, etc...
      //
      if (typeof(pairs_to_set) != 'undefined') {
         var array = pairs_to_set.split('&');
         for (var i = 0; i < array.length; i++) {
            var pair = array[i].split('=');
            var obj  = eval('form.' + pair[0]);
            if (typeof(obj) != 'undefined') {
               obj.value = pair[1];
            }
         }
      }

      form.submit();
   }
}

////////////////////////////////////////
function GotoEx(window_obj, form_name, tmpl)
{
   if (typeof(window_obj) != 'undefined') {
      window_obj.Goto(form_name, tmpl);
   }
}


////////////////////////////////////////
function Trim(str)
{
   str = str.replace(/^\s*/, "");
   str = str.replace(/\s*$/, "");

   return str;
}

////////////////////////////////////////
function IsValidInteger(str)
{
   str = Trim(str);
   return str.length > 0 && IsValid(str, '0123456789-');
}

////////////////////////////////////////
function IsValidNatural(str)
{
   str = Trim(str);
   return str.length > 0 && str.indexOf('0') != 0 && IsValid(str, '1234567890');
}

////////////////////////////////////////
function IsValidReal(str)
{
   str = Trim(str);
   return str.length > 0 && IsValid(str, '0123456789.-');
}

////////////////////////////////////////
function IsValid(str, alphabet)
{
   for (var i = 0; i < str.length; i++) {
      if (alphabet.indexOf(str.charAt(i)) == -1) return false;
   }

   return true;
}
