function setMultiCheck (checked)
{
  var form = document.getElementById('multiForm');
  if (!form)
  {
    return;
  }
  var checkBoxes = form.elements['multi[]'];
  if (!checkBoxes)
  {
    return;
  }
  var countCheckBoxes = checkBoxes.length;
	if(!countCheckBoxes)
  {
		checkBoxes.checked = checked;
    return true;
  }
  for(var i = 0; i < checkBoxes.length; i++)
  {
    checkBoxes[i].checked = checked;
  }
  return true;
}

function showMultiChilds (name, prefix, start, end)
{
  var select = document.getElementById(prefix + name + '-input');
  if (typeof select != 'undefined')
  {
    var numFieldsets = parseInt(select.value);
    for (var i = start; i < end; i++)
    {
      var fieldset = document.getElementById('fieldset-' + name + '-' + i);
      if (typeof fieldset != 'undefined')
      {
        if (i < numFieldsets)
        {
          fieldset.style.display = 'block';
        }
        else
        {
          fieldset.style.display = 'none';
        }
      }
      else 
      {
        alert('fieldset-' + name + '-' + i);
      }
    }
  }
}
function showSubOptions (input, name)
{
  var fieldset = document.getElementById(name);
  if (typeof fieldset != 'undefined')
  {
    if (input.checked)
    {
      fieldset.style.display = 'block';
    }
    else
    {
      fieldset.style.display = 'none';
    }
  }
}

function setFormId(form, id)
{
  var input = document.createElement('input');
  input.type = 'hidden';
  input.id = 'formId-input';
  input.name = 'formId';
  input.value = id;
  form.appendChild(input);
}
function setCookie(name, value, expires, path, domain, secure) {
		if (!expires)
		{
			exp = new Date;
			expires = new Date(exp.getTime() + 365*24*60*60*1000);
		}
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


function formManager (formId, doShowThrobber, options)
{

  this.form = document.getElementById(formId);
  this.form.manager = this;

  $(this.form).submit(function() {
    this.manager.handleSubmit();
  });
  this.doShowThrobber = doShowThrobber;
  if (doShowThrobber)
  {
    this.addThrobber(options);
  }
}
formManager.prototype.loadCallback = function (options)
{
  var url = this.form.getAttribute('action');
  url += '/callback=' + options.path;
  var element = document.getElementById(options.load);
  $(element).hide();
  element.innerHTML = '<img src="/images/common/throbber.gif" alt="loading" />';
  $(element).fadeIn();
  $(element).load(url, options.data);
}
formManager.prototype.addThrobber = function (options)
{
  this.flashUrl = '/images/common/loading.swf';
  this.flashWidth = 126;
  this.flashHeight = 22;
  this.text = '';
  this.textHeight = 0;
  if (options)
  {
    if (options.flashUrl) {this.flashUrl = options.flashUrl};
    if (options.flashWidth) {this.flashWidth = options.flashWidth};
    if (options.flashHeight) {this.flashHeight = options.flashHeight};
    if (options.text) {this.text = options.text};
    if (options.textHeight) {this.textHeight = options.textHeight};
  }
  var submitOverlay = document.getElementById('submit-overlay');
  if (typeof submitOverlay == 'undefined' || !submitOverlay)
  {
    submitOverlay = document.createElement('div');
    submitOverlay.id = 'submit-overlay';

    var dialogDiv = document.createElement('div');
    dialogDiv.id = 'submit-dialog';
    dialogDiv.style.position = 'absolute';

    var loadingDiv = document.createElement('div');
    loadingDiv.id = 'submit-loading';
    loadingDiv.style.width = '126px';
    loadingDiv.style.marginLeft = 'auto';
    loadingDiv.style.marginRight = 'auto';

    dialogDiv.appendChild(loadingDiv);
    dialogDiv.innerHTML += this.text;
    submitOverlay.appendChild(dialogDiv);

    var so = {movie: '/images/common/loading.swf', width: 126, height: 22, majorversion: 7, build: 0, wmode: 'transparent', menu: 0};
    UFO.create(so, 'submit-loading');
    $('body').append(submitOverlay);
    //submitOverlay.style.display = 'none';
  }
}
formManager.prototype.handleSubmit = function ()
{
  //this.validate ();
  if (this.doShowThrobber)
  {
    this.showThrobber();
  }
  return false;
}

formManager.prototype.showThrobber = function ()
{
  var windowDimensions = getWindowDimensions ();
  var scroll = getScrollPosition ();
  var posTop = Math.round((windowDimensions['height'] - this.flashHeight / 2 - this.textHeight) / 2) + scroll - 10;
  var posLeft = Math.round(windowDimensions['width'] / 2) - 101;
  $('#submit-dialog').css({
    top: posTop + 'px',
    left: posLeft + 'px'
  })
  var dimensions = getPageDimensions();
  $('#submit-overlay').css({
    display: 'block',
    height: dimensions.height + 'px'
  });
}
function CheckboxDivToggler (checkbox, div, revert)
{
  if (checkbox && (typeof checkbox != 'undefined') && div && (typeof div != 'undefined'))
  {
    this.revert = revert;
    checkbox.toggler = this;
    this.div = div;
    if ((!revert && checkbox.checked) || (revert && !checkbox.checked))
    {
      $(div).show();
    }
    else
    {
      $(div).hide();
    }
    $(checkbox).click(function () {
      if ((!this.toggler.revert && this.checked) || (this.toggler.revert && !this.checked))
      {
        $(this.toggler.div).show();
      }
      else
      {
        $(this.toggler.div).hide();
      }
    })
  }
}
/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Date: 2/19/2008
 * @author Ariel Flesler
 * @version 1.3.3
 */
;(function($){var o=$.scrollTo=function(a,b,c){o.window().scrollTo(a,b,c)};o.defaults={axis:'y',duration:1};o.window=function(){return $($.browser.safari?'body':'html')};$.fn.scrollTo=function(l,m,n){if(typeof m=='object'){n=m;m=0}n=$.extend({},o.defaults,n);m=m||n.speed||n.duration;n.queue=n.queue&&n.axis.length>1;if(n.queue)m/=2;n.offset=j(n.offset);n.over=j(n.over);return this.each(function(){var a=this,b=$(a),t=l,c,d={},w=b.is('html,body');switch(typeof t){case'number':case'string':if(/^([+-]=)?\d+(px)?$/.test(t)){t=j(t);break}t=$(t,this);case'object':if(t.is||t.style)c=(t=$(t)).offset()}$.each(n.axis.split(''),function(i,f){var P=f=='x'?'Left':'Top',p=P.toLowerCase(),k='scroll'+P,e=a[k],D=f=='x'?'Width':'Height';if(c){d[k]=c[p]+(w?0:e-b.offset()[p]);if(n.margin){d[k]-=parseInt(t.css('margin'+P))||0;d[k]-=parseInt(t.css('border'+P+'Width'))||0}d[k]+=n.offset[p]||0;if(n.over[p])d[k]+=t[D.toLowerCase()]()*n.over[p]}else d[k]=t[p];if(/^\d+$/.test(d[k]))d[k]=d[k]<=0?0:Math.min(d[k],h(D));if(!i&&n.queue){if(e!=d[k])g(n.onAfterFirst);delete d[k]}});g(n.onAfter);function g(a){b.animate(d,m,n.easing,a&&function(){a.call(this,l)})};function h(D){var b=w?$.browser.opera?document.body:document.documentElement:a;return b['scroll'+D]-b['client'+D]}})};function j(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
