function ChangeSelectProduct( Step ) {

 if( Step < 0 || Step > 5 )
   Step = 1;

 Str = "";
 Anchor = "";

 if( Step >= 1 ) {
   Str += "Groupe=" + document.SelectProduct.Groupe.value;
   Anchor = "typeuse";
 }

 if( Step >= 2 ) {
   if( Str )
    Str += "&";

   Str += "TypeUse=" + document.SelectProduct.TypeUse.value;
   Anchor = "purpose";
 }

 if( Step >= 3 ) {
   if( Str )
    Str += "&";

   Str += "Purpose=" + document.SelectProduct.Purpose.value;
   Anchor = "typework";
 }

 if( Step >= 4 ) {
   if( Str )
    Str += "&";

   Str += "TypeWork=" + document.SelectProduct.TypeWork.value;
   Anchor = "function";
 }

 if( Step >= 5 ) {
   if( Str )
    Str += "&";

   Str += "Function=" + document.SelectProduct.Function.value;
   Anchor = "function";
 }

 location.href = "?" + Str + "#" + Anchor;
}

function Add2Favor() {

  if( navigator.appName == "Microsoft Internet Explorer"
      && parseFloat(navigator.appVersion) >= 4.0 )
    window.external.AddFavorite(location.href, document.title);
  else
    window.alert("Ваш браузер не поддерживает данную функцию. Нажмите Ctrl+D, чтобы добавить в Favorites.");
}

function OpenPhoto( HRef, width, height ) {

 window.open(HRef,'_blank','statusbar=0,toolbar=0,location=0,scrollbars=1,resizable=0,width='+width+',height='+height);

}

function ShowSorry() {

 window.alert("Извините, но пока этот раздел не доступен...");
 return false;

}

var aMonths = new Array( 'Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь')
var aMonthsG = new Array( 'Января', 'Февраля', 'Марта', 'Апреля', 'Мая', 'Июня', 'Июля', 'Августа', 'Сентября', 'Октября', 'Ноября', 'Декабря')
var aDays = new Array('вс', 'пн', 'вт', 'ср', 'чт', 'пт', 'сб');

function FormatDate(dDate, sFormat) {

  if( !dDate )
    return "";
    
  var Str = "";
  
  if( sFormat == "dd.mm" )
    Str = FormatNumber(dDate.getDate()) + "." + FormatNumber((dDate.getMonth()+1));
  else if( sFormat == "ddd, d mmm" )
    Str = aDays[dDate.getDay()] + ", " + dDate.getDate() + " " + aMonths[dDate.getMonth()].substr(0, 3).toLowerCase();
  else if( sFormat == "ddmmyyyy" )
    Str = FormatNumber(dDate.getDate()) + FormatNumber((dDate.getMonth()+1)) + FormatNumber(dDate.getFullYear());
  else if( sFormat == "yyyy-mm-dd" )
    Str = FormatNumber(dDate.getFullYear()) + "-" + FormatNumber((dDate.getMonth()+1)) + "-" + FormatNumber(dDate.getDate());
  else  
    Str = FormatNumber(dDate.getDate()) + "." + FormatNumber((dDate.getMonth()+1)) + "." + FormatNumber(dDate.getFullYear());

  return Str;
}

function FormatNumber(sNum) {

  re = /^(\d{0,1})(\d{1})$/
  aResult = re.exec(sNum)

  if( aResult
      && !aResult[1] )
    return "0" + parseInt(aResult[2]);

  return sNum;
}

function ChangeDateSelect(sName) {

  var oHidden = ElementByID(sName);
  var oDay = ElementByID(sName + "Day");
  var oMonth = ElementByID(sName + "Month");
  var oYear = ElementByID(sName + "Year");

  var dDate = new Date(oYear.value, oMonth.value-1, oDay.value);
  
  if( dDate.getDate() == parseInt(oDay.value*1)
      && dDate.getMonth()+1 == parseInt(oMonth.value*1)
      && dDate.getYear() == parseInt(oYear.value*1) ) {
      
    oHidden.value = FormatDate(dDate);
    
    //if( oHidden.onchange )
    //  SetValue(oHidden.name, oHidden.value, "string");
    
    window.status = "";
  }
  else {
    window.status = "Внимание: выбрана неверная дата!";
    return;
  }

}

function ElementByID(ID) {

  return document.all ? document.all[ID] : document.getElementById(ID);
}

function SetCount(Obj, Price) {

  SetValue($(Obj).name, $(Obj).value, "int");
  $("sum-"+Obj).innerHTML = $(Obj).value * Price;

  SumCount = 0;
  SumPrice = 0;

  document.getElementsByClassName("goods").each(function(Item) {
     SumCount += parseInt(Item.value);
     SumPrice += parseInt($("sum-"+Item.id).innerHTML);
  });

  $("sum-count").innerHTML = SumCount;
  $("sum-price").innerHTML = SumPrice;
  $("sum-final").innerHTML = SumPrice;

  ShowBaggage(SumCount, SumPrice);
}

function UpCount(Obj, Price) {

  if( $(Obj).value >= 0 )
    $(Obj).value++;
  else
    $(Obj).value = 0;

  SetCount(Obj, Price);
}

function DownCount(Obj, Price) {

  if( $(Obj).value > 0 )
    $(Obj).value--;
  else
    $(Obj).value = 0;

  SetCount(Obj, Price);
}

function ShowBaggage(SumCount, SumPrice) {

  if( SumCount )
    $("baggage").innerHTML = "Товаров: <b>" + SumCount + "</b> шт. на <b>" + SumPrice + " руб.</b>";
  else
    $("baggage").innerHTML = "";
}

function ChangeCount(Obj, Value, Price) {

  if( $(Obj).checked )
    SetValue($(Obj).name, Value, "int");
  else {
    SetValue($(Obj).name, 0, "int");
    Value = -Value;
  }

  /* это глобальные переменные */
  SumCount += Value;
  SumPrice += Value * Price;

  ShowBaggage(SumCount, SumPrice);
}

function SelectCount(Name, Value, Price) {

  SetValue($(Obj).name, 1, "int");

  /* это глобальные переменные */
  SumCount += Value;
  SumPrice += Value * Price;

  ShowBaggage(SumCount, SumPrice);
}

function showPreView(Id, Action) {

  if( $('img-' + Id) )
    $('img-' + Id).style.display = (Action?'block':'none');
}
