function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

function myFileBrowser (field_name, url, type, win) {
  tinyMCE.activeEditor.windowManager.open({
    file: "/admin/media_library/mini_browse",
    width: 420,
    close_previous : "no",
    resizable : "yes",
    inline : "yes"
  }, {
    input : field_name,
    window : win
  });
  return false;
}

function select_forum_item(item_id, container_id, row)
{

  var container = document.getElementById(container_id);

  if (container.value.match(new RegExp("," + item_id + ",")))
  {
    row.className = row.className.replace(/\s*\highlighted\b|$/, " ");
    container.value = container.value.replace(new RegExp("," + item_id + ","), "");
  }
  else
  {
    row.className = row.className.replace(/\s*\highlighted\b|$/, " highlighted");
    container.value += "," + item_id + ",";
  }

  if(container.value != "")
  {
    ["move_objects"].each(Element.show);
  }
  else
  {
    ["move_objects", "mini_forums"].each(Element.hide);
  }

}

function select_item(item_id,container_id,row)
{
  var container=document.getElementById(container_id);
  if (container.value.match(new RegExp(","+item_id+",")))
  {
    row.className = row.className.replace(/\s*\highlighted\b|$/, " ");
    container.value=container.value.replace(new RegExp(","+item_id+","), "");
  }
  else
  {
    row.className = row.className.replace(/\s*\highlighted\b|$/, " highlighted");
    container.value+=","+item_id+",";
  }

  if(container.value!="")
  {
    ["move_objects"].each(Element.show);
  }
  else
  {
    ["move_objects"].each(Element.hide);
  }
}

function reset_container(container_id)
{
  var container=document.getElementById(container_id);
  container.value = "";
  ["move_objects"].each(Element.hide);
}

Object.extend(String.prototype, 
{

  upcase: function()
  {
    return this.toUpperCase();
  },

  downcase: function()
  {
    return this.toLowerCase();
  },
  
  strip: function()
  {
    return this.replace(/^\s+/, '').replace(/\s+$/, '');
  },
  
  toInteger: function()
  {
    return parseInt(this);
  },
  
  toSlug: function() {
    return this.strip().downcase().replace(/[^-a-z0-9~\s\.:;+=_]/g, '').replace(/[\s\.:;=+]+/g, '_');
  }

});

function check_form()  {
  for (i = 0; i < document.contact_us_form.elements.length; i++)
  {
    oElem = document.contact_us_form.elements[i];
    if (oElem.type != "submit")      {
      oElem.style.borderColor="";
    }
  }

  var error_field=document.getElementById('error');

  if (document.contact_us_form.name.value=='')
  {
    document.contact_us_form.name.focus();
    error_field.innerHTML = 'Имя не может быть пустым.';
    document.contact_us_form.name.style.borderColor="red"
    return false;
  }

  if (document.contact_us_form.email_address.value=='')
  {
    document.contact_us_form.email_address.focus();
    error_field.innerHTML = 'E-mail не может быть пустым.';
    document.contact_us_form.email_address.style.borderColor="red"
    return false;
  }

  var pattern = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  if (!document.contact_us_form.email_address.value.match(new RegExp(pattern)))
  {
    document.contact_us_form.email_address.focus();
    error_field.innerHTML = "Не правильный формат E-mail.";
    document.contact_us_form.email_address.style.borderColor="red"
    return false;
  }

  if (document.contact_us_form.subject.value=='')
  {
    document.contact_us_form.subject.focus();
    error_field.innerHTML = 'Не указана тема.';
    document.contact_us_form.subject.style.borderColor="red"
    return false;
  }

  if (document.contact_us_form.message.value=='')
  {
    document.contact_us_form.message.focus();
    error_field.innerHTML = 'Не указано сообщение.';
    document.contact_us_form.message.style.borderColor="red"
    return false;
  }



  return true;
}               
