

var ordStep3LogChecked = false;

function ValidateOrderForm()
{

    $('#al1 .important').html('nutno vyplnit').addClass('important_neutral');
    $('#al2 .important').html('nutno vyplnit').addClass('important_neutral');
    
    
    
      

   $('#al4 .important').html('nutno vyplnit').addClass('important_neutral');
   $('#al5 .important').html('nutno vyplnit').addClass('important_neutral');
  
	
       
   
   
    $('#al11 .important').html('nutno vyplnit').addClass('important_neutral');
    $('#al12 .important').html('nutno vyplnit').addClass('important_neutral');
    $('#al13 .important').html('nutno vyplnit').addClass('important_neutral');
    $('#al14 .important').html('nutno vyplnit').addClass('important_neutral');
    $('#al15 .important').html('nutno vyplnit').addClass('important_neutral');

   
   
    $('#UserDataForm :input').each(function() {
        if ($(this).val() != '')
        {
           ValidateInputs($(this),0);
        }
    });
}


$(function () {
  $('#UserDataForm :input').blur(function() {
     $('#UserDataForm :input').each(function() {
          if ($(this).val() != '')
          {
             ValidateInputs($(this),0);
          }
      });
    })
    
  $('select').change(function() {
     $('#UserDataForm :input').each(function() {
          if ($(this).val() != '')
          {
             ValidateInputs($(this),0);
          }
      });
    })
    
    
})


  
function ValidateInputs(inp, type)
{
    // V prve rade validuje order formular, v druhe rade take slouzi k uchovani dat v cookies 
    //type = 1 - return pokud chybne zadano


    var nPscLengthGlobal = ;
    var bDiferentDeliveryAdress = getF('UserDataForm').SameAdress.checked;
    var bAlertOnly = false;
  
    
      
    var sInputsNotToCookies = '|mm-system-mplace|paymentSelTemp|email|ordersendinfoalert|RegisterOrderAddUpd|OrderPart|WithRegistration|Step|b2cPrices|priceAdd|PaymentType|DeliveryPayments|DeliveryType|nPriceSumB2c|';
    
    // VALIDACE + COOKIES
     
     
     
     
    // FirstName
   if ((sValidateInputs.indexOf('|' + inp.attr("name") + '|') != -1)) 
   {
    if (inp.attr("name") == 'FirstName')
    {
      if (inp.val() == '')
      {
        if (bAlertOnly){
          alert('V poli Jméno jste udělali chybu.');
          if (type == 1) {return false;}
        } else {
        $('#important_FirstName').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>Nic není zadáno.');
        if (type == 1) {return false;}
        }
      }

      if (inp.val() != '')
      {
        $('#important_FirstName').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
        InsertOrderCookie('FirstName',inp.val());
       
      }
    }
    
    // LastName2
  /*  
    if (inp.attr("name") == 'LastName2')
    {
      if (inp.val() == '')
      {
        if (bAlertOnly){
          alert('V poli Otčestvo jste udělali chybu.');
          if (type == 1) {return false;}
        } else {
        $('#important_LastName2').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>Nic není zadáno.');
        if (type == 1) {return false;}
        }
      }

      if (inp.val() != '')
      {
        $('#important_LastName2').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
        InsertOrderCookie('LastName2',inp.val());
      }
    }
   */ 
    
    // LastName
    
    if (inp.attr("name") == 'LastName')
    {
      if (inp.val() == '')
      {
        if (bAlertOnly){
          alert('V poli Příjmení jste udělali chybu.');
          if (type == 1) {return false;}
        } else {

        $('#important_LastName').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>Nic není zadáno.');
        if (type == 1) {return false;}
        }
      }

      if (inp.val() != '')
      {
        $('#important_LastName').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
        InsertOrderCookie('LastName',inp.val());
      }
    }
    



    // Street
    
    if (inp.attr("name") == 'Street')
    {
      if (inp.val() == '')
      {
        $('#important_Street').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>Nic není zadáno.');
        if (type == 1) {return false;}
      }

      if (inp.val() != '')
      {
        $('#important_Street').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
        InsertOrderCookie('Street',inp.val());
      }
    }

    // StreetNumber
    
    if (inp.attr("name") == 'sStreetNumber')
    {
      if (inp.val() == '')
      {
        $('#important_Street').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>Nic není zadáno.');
        if (type == 1) {return false;}
      }

      if (inp.val() != '')
      {
        $('#important_Street').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
        InsertOrderCookie('sStreetNumber',inp.val());
      }
    }

    // City
    
    if (inp.attr("name") == 'City')
    {
      if (inp.val() == '')
      {
        $('#important_City').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>Nic není zadáno.');
        if (type == 1) {return false;}
      }

      if (inp.val() != '')
      {
        $('#important_City').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
        InsertOrderCookie('City',inp.val());
      }
    }
    
    
    // ZipCode
    
    if (inp.attr("name") == 'ZipCode')
    {
    
      if ((inp.val() == '') || (inp.val().length  < nPscLengthGlobal) || (inp.val().length > nPscLengthGlobal))
      {
        $('#important_ZipCode').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>špatně zadané PSČ.');
        if (type == 1) {return false;}
      }

      if ((inp.val() != '') && (inp.val().length == nPscLengthGlobal))
      {
        $('#important_ZipCode').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
        InsertOrderCookie('ZipCode',inp.val());
      }
    }  
    
    
    // Phone
    
    if (inp.attr("name") == 'Phone')
    {
      if (inp.val() == '')
      {
        if (bAlertOnly){
          alert('V poli Telefon jste udělali chybu.');
          if (type == 1) {return false;}
        } else {
        $('#important_Phone').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>Nic není zadáno.');
        if (type == 1) {return false;}
        }
      }

      if (inp.val() != '')
      {
        $('#important_Phone').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
        InsertOrderCookie('Phone',inp.val());
      }
    }
    
    // District
    
    if (inp.attr("name") == 'District')
    {
      if (inp.val() == '')
      {
        $('#important_District').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>Nic není zadáno.');
        if (type == 1) {return false;}
      }

      if (inp.val() != '')
      {
        $('#important_District').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
        InsertOrderCookie('District',inp.val());
      }
    }
    
    // Region
    
    if (inp.attr("name") == 'Region')
    {
      if (inp.val() == '')
      {
        $('#important_Region').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>Nic není zadáno.');
        if (type == 1) {return false;}
      }

      if (inp.val() != '')
      {
        $('#important_Region').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
        InsertOrderCookie('Region',inp.val());
      }
    }
  
    
   if (bDiferentDeliveryAdress) 
    {
      // DeliveryFirstName
    
        if (inp.attr("name") == 'DeliveryFirstName')
        {
          if (inp.val() == '')
          {
          if (bAlertOnly){
            alert('V poli Jméno jste udělali chybu.');
            if (type == 1) {return false;}
          } else {          
            $('#important_DeliveryFirstName').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>Nic není zadáno.');
            if (type == 1) {return false;}
            }
          }
    
          if (inp.val() != '')
          {
            $('#important_DeliveryFirstName').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
            InsertOrderCookie('DeliveryFirstName',inp.val());
          }
        }
        
        // DeliveryLastName
        
        if (inp.attr("name") == 'DeliveryLastName')
        {
          if (inp.val() == '')
          {
          if (bAlertOnly){
            alert('V poli Příjmení jste udělali chybu.');
            if (type == 1) {return false;}
          } else {
            $('#important_DeliveryLastName').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>Nic není zadáno.');
            if (type == 1) {return false;}
            }
          }
    
          if (inp.val() != '')
          {
            $('#important_DeliveryLastName').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
            InsertOrderCookie('DeliveryLastName',inp.val());
          }
        }
        
        // DeliveryLastName2
        /*
        if (inp.attr("name") == 'DeliveryLastName2')
        {
          if (inp.val() == '')
          {
          if (bAlertOnly){
            alert('V poli Otčestvo jste udělali chybu.');
            if (type == 1) {return false;}
          } else {

            $('#important_DeliveryLastName2').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>Nic není zadáno.');
            if (type == 1) {return false;}
            }
          }
          
    
          if (inp.val() != '')
          {
            $('#important_DeliveryLastName2').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
            InsertOrderCookie('DeliveryLastName2',inp.val());
          }
        }
        */
    
        // DeliveryStreet
        
        if (inp.attr("name") == 'DeliveryStreet')
        {
          if (inp.val() == '')
          {
          if (bAlertOnly){
            alert('V poli Ulice jste udělali chybu.');
            if (type == 1) {return false;}
          } else {

            $('#important_DeliveryStreet').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>Nic není zadáno.');
            if (type == 1) {return false;}
            }
          }
    
          if (inp.val() != '')
          {
            $('#important_DeliveryStreet').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
            InsertOrderCookie('DeliveryStreet',inp.val());
          }
        }

        // DeliveryStreetNumber
        
        if (inp.attr("name") == 'sDeliveryStreetNumber')
        {
          if (inp.val() == '')
          {
          if (bAlertOnly){
            alert('V poli Telefon jste udělali chybu.');
            if (type == 1) {return false;}
          } else {

            $('#important_DeliveryStreet').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>Nic není zadáno.');
            if (type == 1) {return false;}
            }
          }
    
          if (inp.val() != '')
          {
            $('#important_DeliveryStreet').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
            InsertOrderCookie('sDeliveryStreetNumber',inp.val());
          }
        }    
    
        // DeliveryCity
        
        if (inp.attr("name") == 'DeliveryCity')
        {
          if (inp.val() == '')
          {
          if (bAlertOnly){
            alert('V poli Město jste udělali chybu.');
            if (type == 1) {return false;}
          } else {

            $('#important_DeliveryCity').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>Nic není zadáno.');
            if (type == 1) {return false;}
          }
          }
    
          if (inp.val() != '')
          {
            $('#important_DeliveryCity').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
            InsertOrderCookie('DeliveryCity',inp.val());
          }
        }
        
        
        // DeliveryZipCode
        
        if (inp.attr("name") == 'DeliveryZipCode')
        {
          if ((inp.val() == '') || (inp.val().length  < nPscLengthGlobal) || (inp.val().length > nPscLengthGlobal))
          {
          if (bAlertOnly){
            alert('Pole PSČ musí obsahovat minimálně  znaků.');
            if (type == 1) {return false;}
          } else {
          
            $('#important_DeliveryZipCode').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>špatně zadané PSČ.');
            if (type == 1) {return false;}
          }
          }
    
          if ((inp.val() != '') &&  (inp.val().length  == nPscLengthGlobal))
          {
            $('#important_DeliveryZipCode').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
            InsertOrderCookie('DeliveryZipCode',inp.val());
          }
        }
        
        
        
          // DeliveryDistrict
        
        if (inp.attr("name") == 'DeliveryDistrict')
        {
          if (inp.val() == '')
          {
          if (bAlertOnly){
            alert('V poli Telefon jste udělali chybu.');
            if (type == 1) {return false;}
          } else {

            $('#important_DeliveryDistrict').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>Nic není zadáno.');
            if (type == 1) {return false;}
            }
          }
    
          if (inp.val() != '')
          {
            $('#important_DeliveryDistrict').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
            InsertOrderCookie('DeliveryDistrict',inp.val());
          }
        }
        
        // Region
        
        if (inp.attr("name") == 'DeliveryRegion')
        {
          if (inp.val() == '')
          {
          if (bAlertOnly){
            alert('V poli Telefon jste udělali chybu.');
            if (type == 1) {return false;}
          } else {

            $('#important_DeliveryRegion').removeClass('important_neutral').removeClass('important_ok').addClass('important_notok').html('<span>Chyba</span>Nic není zadáno.');
            if (type == 1) {return false;}
            }
          }
    
          if (inp.val() != '')
          {
            $('#important_DeliveryRegion').removeClass('important_neutral').removeClass('important_notok').addClass('important_ok').html('');
            InsertOrderCookie('DeliveryRegion',inp.val());
          }
        }
        
        
      }    
    }
    
    
    // COOKIES ONLY
	
      if ((sValidateInputs.indexOf('|' + inp.attr("name") + '|') == -1) && (sInputsNotToCookies.indexOf('|' + inp.attr("name") + '|') == -1))
      {
        if(inp.attr("name") != "") {
          InsertOrderCookie(inp.attr("name"),inp.val());
        }
      }
  
    
}


// From order
function ControlDataOrderUser(){

    var bWrongInputs = false;
    $('#UserDataForm :input').each(function() {
      if (ValidateInputs($(this),1) != undefined)
      {
        if (ValidateInputs($(this),1) == false) {bWrongInputs = true; input = $(this);}
      }
    });

    if (bWrongInputs == true) {
        input.focus();
        return false;
      
      }
  
       //MM place
     
     if ($('input:radio[name=DeliveryType]:checked').val() == 216 && $('#mm-system-mplace').val() == 0)
     {
        alert('Není zvoleno žádné výdejní místo. Objednávku nelze odeslat.');
        return false;
     }
     
  
  // Kontrola na zadane PSC, pouze z CZ na SK a naopak        

  
  
   
  showOrderSendInfo();
  
  if (checkOnlineAvail() == true) {
    
    //pageTracker._trackPageview('/kosik_frm/pokracovat');     
    getE('UserDataForm').submit();
    return true;
  
  } else {
  
    getE('dynamicDiv').style.display='none';  
    return false;  
  }

  
}

// From order
function ControlDataOrderUserUa(){

    var bWrongInputs = false;
    $('#UserDataForm :input').each(function() {
      var status = ValidateInputs($(this),1);
     
      if (status != undefined)
      {
        if (status == false) {bWrongInputs = true; input = $(this); return false;}
      }
    });


    if (bWrongInputs == true) {
        input.focus();
        return false;
      
      }
  
  showOrderSendInfo();
  
  if (checkOnlineAvail() == true) {
    
//    pageTracker._trackPageview('/kosik_frm/pokracovat');     
    getE('UserDataForm').submit();
    return true;
  
  } else {
  
    getE('dynamicDiv').style.display='none';  
    return false;  
  }

  
}

function checkOnlineAvail() {
      var ret = true;
 
     $.ajax({
             type: "POST",
             url: "/OrderOnlineAvailBack.asp",
             cache: false,
             async: false,
             data: ({ task: 'checkAvail'}),
             dataType: "html",
             success: function (data) {
                if (data != "") {
                    $('#order').html(data);
                    ret = false;
                  }
             }
         });


    return ret;

}

function showOrderSendInfo() {
    
    if (getE('dynamicDiv') == null || getE('dynamicDiv').childNodes.length > 0 || getE('OrderSendInfoBck') == null) return false;
    getE('dynamicDiv').innerHTML = getE('OrderSendInfoBck').innerHTML;    

    showdeadcenterdiv(320,98,'OrderSendInfo');
  
    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById('dynamicDiv').style.visibility = 'visible';
    } else {
        if (document.layers) { // Netscape 4
            document.dynamicDiv.visibility = 'visible';
        } else { // IE 4
            document.all.dynamicDiv.style.visibility = 'visible';
        }
    }

}


function setAlertPart(id) {
  
  var sMessage = "";  
  getE('al'+id).className = 'alert';  
    
  switch (id)
  {
  case 1:
    sMessage = "V poli Jméno jste udělali chybu."
    break
  case 2:
    sMessage = "V poli Příjmení jste udělali chybu."
    break
  case 3:
    sMessage = "V poli Email jste udělali chybu, nebo byl Email chybně zadán."
    break
  case 4:
    sMessage = "V poli Telefon jste udělali chybu."
    break
  case 5:
    sMessage = "V poli Ulice jste udělali chybu."
    break
  case 6:
    sMessage = "V poli Město jste udělali chybu."
    break
  case 7:
    sMessage = "Pole PSČ musí obsahovat minimálně  znaků."
    break
  case 11:
    sMessage = "V poli Jméno jste udělali chybu."
    break
  case 12:
    sMessage = "V poli Příjmení jste udělali chybu."
    break
  case 13:
    sMessage = "V poli Ulice jste udělali chybu."
    break
  case 14:
    sMessage = "V poli Město jste udělali chybu."
    break
  case 35:
    sMessage = "Pole Kontrola hesla se neshoduje s polem Heslo."
    break
  case 36:
    sMessage = "Pole Heslo musí obsahovat minimálně 5 znaků."    
    break
  case 37:
    sMessage = "Vyberte ze seznamu pole Judet."    
    break
  case 137:
    sMessage = "Vyberte ze seznamu pole Judet."    
    break
  case 401:
    sMessage = "Vyberte ze seznamu pole Region."    
    break
  case 402:
    sMessage = "Vyberte ze seznamu pole Okres."
    break
  case 403:
    sMessage = "Vyberte ze seznamu pole Město."
    break  
  case 404:
    sMessage = "Vyberte ze seznamu pole Psč."
    break
  case 405:
    sMessage = "V poli Otčestvo jste udělali chybu."
    break
  case 411:
    sMessage = "Vyberte ze seznamu pole Region."
    break
  case 412:
    sMessage = "Vyberte ze seznamu pole Okres."
    break
  case 413:
    sMessage = "Vyberte ze seznamu pole Město."
    break
  case 414:
    sMessage = "Vyberte ze seznamu pole Psč."
    break
  case 415:
    sMessage = "V poli Otčestvo jste udělali chybu."
    break    
  }

  getE('alertmess').innerHTML = sMessage;  
  getE('alertMain').style.display = 'block'; 

}

function alertClear(id) {
      id.parentNode.className = '';      
      getE('alertMain').style.display = 'none';

 } 

function showHideFidel(id) {
  	for (var x=0; x<getF('fidelNotLogged').userLog.length + 1;x++){
      if (getE('fidel'+x) != null) {
        getE('fidel'+x).style.display='none';
      }          
    }
    
    if (getE('fidel'+id) != null) {
        getE('fidel'+id).style.display='block';
      }    

}

function LoginFromBasket() {
  var frm = getF('fidelNotLogged');  
        
  if (frm.Logon_login.value != "" || frm.password.value != "") {
    frm.Logon_login.value = frm.cEmail.value;  
    frm.submit();
  } else {
    alert('Zadejte svůj e-mail a heslo.');
  }

  
}

function step1() {
  getF('UserDataForm').action = '/order.asp';  
  getF('UserDataForm').OrderPart.value = 1;  
  getF('UserDataForm').Step.value = 0;
      
  // Pokud je neprihlasen  , tak zkontrolujeme zda je zadano heslo pro vytvoreni registrace  

  
  var fForm = getF('fidelNotLogged');    
  var fOrderForm = getF('UserDataForm');
    
  if (fForm != undefined) {
    if (fForm.cEmail.value != "" && fForm.userLog[1].checked == true) 
    {
      if ((fForm.passwordR.value != fForm.passwordR1.value) || fForm.passwordR.value == "") {
        alert('Zadaná hesla se neshodují..')        
        return false;
      } else {
        
        fOrderForm.Password.value = fForm.passwordR.value;
        fOrderForm.PasswordCheck.value = fForm.passwordR.value;        
      }     
    }
   }  


  getF('UserDataForm').submit();
}

function step2() {

  var fForm = getF('fidelNotLogged');    
  var fOrderForm = getF('OrderForm');
  var fGiftForm = getF('FrmGifts');
  
  var giftIdSel = null;
  
  if(fGiftForm != undefined)
  {
    // Zvoleny darek
    for (var x=0; x<fGiftForm.giftSel.length;x++){
      if (fGiftForm.giftSel[x].checked) {
            giftIdSel =fGiftForm.giftSel[x].value;
        }
    }
    
    if(getE('giftSizeColor_' + giftIdSel) != null) {    
     gsC = getE('giftSizeColor_' + giftIdSel).options[getE('giftSizeColor_' + giftIdSel).selectedIndex].text;
     
      if(getE('giftSizeColor_' + giftIdSel).selectedIndex == 0) {
            alert('Není zvolena velikost u dárku. Nelze pokračocvat.');
            return false;        
       }
   
      var gfSC = 'giftSizeColorCz_' + giftIdSel;
      var gfSV = getE('giftSizeColor_' + giftIdSel).options[getE('giftSizeColor_' + giftIdSel).selectedIndex].value;
      
      InsertOrderCookie('OrderGiftId',giftIdSel);
      InsertOrderCookie('OrderGiftSize',gsC);
      InsertOrderCookie('OrderGiftSizeCz',gfSV);

    }    
  } else {
      InsertOrderCookie('OrderGiftId','');
      InsertOrderCookie('OrderGiftSize','');
      InsertOrderCookie('OrderGiftSizeCz','');
  }
 
  return true;
 
}

function step2_old() {

  var fForm = getF('fidelNotLogged');    
  var fOrderForm = getF('OrderForm');
  var fGiftForm = getF('FrmGifts');
  
  var giftIdSel = null;

  if(getF('OrderForm').DeliveryType == undefined) {alert('Nejsou definovány žádné dopravy. Nelze pokračovat.'); return false;}
    
    
  if(fGiftForm != undefined)
  {
  
    // Zvoleny darek
    for (var x=0; x<fGiftForm.giftSel.length;x++){
      if (fGiftForm.giftSel[x].checked) {
            giftIdSel =fGiftForm.giftSel[x].value;
        }
    }
    
    if(getE('giftSizeColor_' + giftIdSel) != null) {    
      fOrderForm.giftSizeColor.value = getE('giftSizeColor_' + giftIdSel).options[getE('giftSizeColor_' + giftIdSel).selectedIndex].text;
    
     
        if(getE('giftSizeColor_' + giftIdSel).selectedIndex == 0) {
              alert('Není zvolena velikost u dárku. Nelze pokračocvat.');
              return;        
         }

      InsertCookies('OrderGiftId',giftIdSel);
      InsertCookies('OrderGiftSize',fOrderForm.giftSizeColor.value);    

   
      var gfSC = 'giftSizeColorCz_' + giftIdSel;
      var gfSV = getE('giftSizeColor_' + giftIdSel).options[getE('giftSizeColor_' + giftIdSel).selectedIndex].value;
      
      fOrderForm.giftSizeColorCz.value = getE(gfSC+gfSV).value;
    }    
    
    fOrderForm.giftId.value = giftIdSel;
  }  
    
    
  if (fForm != undefined) {
    if (fForm.cEmail.value != "" && fForm.userLog[1].checked == true) 
    {
      if ((fForm.passwordR.value != fForm.passwordR1.value) || fForm.passwordR.value == "") {
        alert('Zadaná hesla se neshodují.')        
        return false;
      } else {
        
        fOrderForm.passwordR.value = fForm.passwordR.value;
        fOrderForm.cEmail.value = fForm.cEmail.value;        
        fOrderForm.submit();        
      }     
    } else
    {
      fOrderForm.submit();
    }    

  } else {
    fOrderForm.submit();
  } 
 
}

function setLogin(obj) {
  if (getE('login_from_reg') != null) {
    getE('login_from_reg').innerHTML = obj.value;     
  }  
}

function LostPassFromOrderStep1(){

  var sEmail;  
  if (getF('fidelNotLogged').cEmail.value != '')  
      {
        sEmail = getF('fidelNotLogged').cEmail.value;
      }

  window.location.href = '/LostPass.asp?urlback=order.asp&Email=' + sEmail;
  
}


// Reg form
function ControlUserDataSubmit(){

  var sPscControl;
  var nPscLength = ;  


	if(getF('UserDataForm').Email.value == ""){setAlertPart(3);getF('UserDataForm').Email.focus();return false}
	if (EmailControlRegExp(getF('UserDataForm').Email.value, false) == false) {setAlertPart(3);getF('UserDataForm').Email.focus();return false;}

	if(getF('UserDataForm').Password.value == ""){setAlertPart(36);getF('UserDataForm').Password.focus();return false}
  if (getF('UserDataForm').Password.value != getF('UserDataForm').PasswordCheck.value) {setAlertPart(35);getF('UserDataForm').PasswordCheck.focus();return false}
  if (getF('UserDataForm').Password.value.length < 5) {setAlertPart(36);getF('UserDataForm').Password.focus();return false}
  
	if(getF('UserDataForm').Phone.value == ""){setAlertPart(4);getF('UserDataForm').Phone.focus();return false}

	if(getF('UserDataForm').FirstName.value == ""){setAlertPart(1);getF('UserDataForm').FirstName.focus();return false}
	if(getF('UserDataForm').LastName.value == ""){setAlertPart(2);getF('UserDataForm').LastName.focus();return false}
  
      

  if(getF('UserDataForm').Street.value == ""){setAlertPart(5);getF('UserDataForm').Street.focus();return false}
	
     

  sPscControl = getF('UserDataForm').ZipCode.value;  


      





  if (getF('UserDataForm').SameAdress.checked == false) {
	    if (document.forms['UserDataForm'].DeliveryFirstName.value == "")            {setAlertPart(11);document.forms['UserDataForm'].DeliveryFirstName.focus();return false;}
	    if (document.forms['UserDataForm'].DeliveryLastName.value == "")            {setAlertPart(12);document.forms['UserDataForm'].DeliveryLastName.focus();return false;}

      

	    if (document.forms['UserDataForm'].DeliveryStreet.value == "")            {setAlertPart(13);document.forms['UserDataForm'].DeliveryStreet.focus();return false;}

      

      
      sPscControl = getF('UserDataForm').DeliveryZipCode.value; 
  }
  
  return true;
}



function ControlProvisionRegistration()
{
  var frm = getF('ProvisionRegistration');


	if(frm.strEmailInfo.value == ""){alert("Vyplňte email.");frm.strEmailInfo.focus();return false}
	if (EmailControl(frm.strEmailInfo.value)==false) {frm.strEmailInfo.focus();return false;}
  
  if(frm.strLogin.value == ""){alert("Vyplňte přihlašovací údaje.");frm.strLogin.focus();return false}
  if ((frm.Password.value != frm.PasswordCheck.value) || frm.Password.value == "") {
        alert('Zadaná hesla se neshodují.');        
        return false;
      }
  if(frm.strServerAddress.value == "" || frm.strServerAddress.value == "http://"){alert("Vyplňte URL e-shopu.");frm.strServerAddress.focus();return false}  
  
}

function FillUADistricts(bDelivery) {
	var bIsDelivery = ((bDelivery == undefined) ? false : bDelivery);

	function FillUADistrictsCBF(sText) {
		var cboDistrict = getE("cbo" + ((bIsDelivery) ? "Delivery" : "") + "District");
		if (cboDistrict) {
			cboDistrict.options.length = 0;
			var aDst = sText.split("|");
	
			if (aDst.length > 2) {
				var eOpt = document.createElement("option");
				eOpt.value = "";
				eOpt.text = "-- zvolte --";
				cboDistrict.options.add(eOpt);
			}
	
			for (var i = 0; i < aDst.length - 1; i++) {
				var eOpt = document.createElement("option");
				eOpt.value = aDst[i];
				eOpt.text = aDst[i];
				cboDistrict.options.add(eOpt);
			}
	
			FillUACities(bDelivery);
		}
	}

	var cboRegion = getE("cbo" + ((bIsDelivery) ? "Delivery" : "") + "Region");
	var cboDistrict = getE("cbo" + ((bIsDelivery) ? "Delivery" : "") + "District");

	if (cboRegion && cboDistrict) {
		if (cboRegion.value == "") {
			cboDistrict.options.length = 0;

			var opt = document.createElement("option");
			opt.value = "";
			opt.text = "-- zvolte kraj --";
			cboDistrict.options.add(opt);

			FillUACities(bDelivery);
		}
		else {
			var ajax = new Ajax("/Back_UAregions.asp?a=getdst&reg=" + encodeURIComponent(cboRegion.value) + "&l=", "get", FillUADistrictsCBF);
			ajax.sendRQ("", false);
		}
	}

	return true;
}

function FillUACities(bDelivery) {
	var bIsDelivery = ((bDelivery == undefined) ? false : bDelivery);

	function FillUACitiesCBF(sText) {
		var cboCity = getE("cbo" + ((bIsDelivery) ? "Delivery" : "") + "City");
		if (cboCity) {
			cboCity.options.length = 0;
			var aCty = sText.split("|");
	
			if (aCty.length > 2) {
				var eOpt = document.createElement("option");
				eOpt.value = "";
				eOpt.text = "-- zvolte --";
				cboCity.options.add(eOpt);
			}
	
			for (var i = 0; i < aCty.length - 1; i++) {
				var eOpt = document.createElement("option");
				eOpt.value = aCty[i];
				eOpt.text = aCty[i];
				cboCity.options.add(eOpt);
			}
	
			FillUAZipCodes(bDelivery);
		}
	}

	var cboDistrict = getE("cbo" + ((bIsDelivery) ? "Delivery" : "") + "District");
	var cboCity = getE("cbo" + ((bIsDelivery) ? "Delivery" : "") + "City");

	if (cboDistrict && cboCity) {
		if (cboDistrict.value == "") {
			cboCity.options.length = 0;

			var opt = document.createElement("option");
			opt.value = "";
			opt.text = "-- zvolte okres --";
			cboCity.options.add(opt);

			FillUAZipCodes(bDelivery);
		}
		else {
			var ajax = new Ajax("/Back_UAregions.asp?a=getct&dst=" + encodeURIComponent(cboDistrict.value) + "&l=", "get", FillUACitiesCBF);
			ajax.sendRQ("", false);
		}
	}

	return true;
}

function FillUAZipCodes(bDelivery) {
	var bIsDelivery = ((bDelivery == undefined) ? false : bDelivery);

	function FillUAZipCodesCBF(sText) {
		var cboZipCode = getE("cbo" + ((bIsDelivery) ? "Delivery" : "") + "ZipCode");
		if (cboZipCode) {
			cboZipCode.options.length = 0;
			var aZC = sText.split("|");
	
			if (aZC.length > 2) {
				var eOpt = document.createElement("option");
				eOpt.value = "";
				eOpt.text = "-- zvolte --";
				cboZipCode.options.add(eOpt);
			}
	
			for (var i = 0; i < aZC.length - 1; i++) {
				var eOpt = document.createElement("option");
				eOpt.value = aZC[i];
				eOpt.text = aZC[i];
				cboZipCode.options.add(eOpt);
			}
		}
	}

	var cboCity = getE("cbo" + ((bIsDelivery) ? "Delivery" : "") + "City");
	var cboZipCode = getE("cbo" + ((bIsDelivery) ? "Delivery" : "") + "ZipCode");

	if (cboCity && cboZipCode) {
		if (cboCity.value == "") {
			cboZipCode.options.length = 0;
			var opt = document.createElement("option");
			opt.value = "";
			opt.text = "-- zvolte město --";
			cboZipCode.options.add(opt);
		}
		else {
			var ajax = new Ajax("/Back_UAregions.asp?a=getzc&cty=" + encodeURIComponent(cboCity.value) + "&l=", "get", FillUAZipCodesCBF);
			ajax.sendRQ("", false);
		}
	}

	return true;
}

function setGift(id)
{
	var nIdGift = null;
  
  for (var x=0; x<getF('FrmGifts').giftSel.length;x++){
      nIdGift = getF('FrmGifts').giftSel[x].value;
      if (getE('gift_'+nIdGift) != null) {
//        getE('gift_'+nIdGift).style.backgroundColor ='#ffffff';
      }          
    }

  InsertOrderCookie('OrderGiftId',id);  

//  getE('gift_' + id).style.backgroundColor = "#f5f5f5";  
  
  setGiftRow();
  
}

function setGiftInit()
{

  // Pokud neni gif zvole, vybereme prvni v poradi
  // ID darku i velikost je v cookies, proto vycucnem
  
  if (getF('FrmGifts') == undefined) {return;} 
  
  var nIdGift = 9999;
  var sGiftSize = "0";
  var nIdGiftWrk = 0; 
  
  if (ExtractOrderCookie('OrderGiftId') != '')
  {
    nIdGift = ExtractOrderCookie("OrderGiftId");
  } 

  if (ExtractOrderCookie('OrderGiftSize') != '')
  {
    sGiftSize = ExtractOrderCookie('OrderGiftSize');
  }   

  
  for (var x=0; x<getF('FrmGifts').giftSel.length;x++){
      nIdGiftWrk = getF('FrmGifts').giftSel[x].value;
      if (getE('gift_'+nIdGiftWrk) != null) {
        getE('gift_'+nIdGiftWrk).style.backgroundColor ='#ffffff';
      }
    }
    

  if (nIdGift != 9999)
  {
    // Oznacime zvoleny darek
//    getE('gift_' + nIdGift).style.backgroundColor = "#f5f5f5";  
   
   // Projdeme radio inputy a oznacime ten potrebny
     for (var x=0; x<getF('FrmGifts').giftSel.length;x++){
        if (getF('FrmGifts').giftSel[x].value == nIdGift)
        {
          getF('FrmGifts').giftSel[x].checked = true;
        }
      }
    
    if  (nIdGift !=0){
     // Projdeme barvy, pokud je zvolena tak preddefinujeme
      for (var x=0; x<getE('giftSizeColor_' + nIdGift).length;x++){
        if (getE('giftSizeColor_' + nIdGift)[x].value == sGiftSize)
        {
          getE('giftSizeColor_' + nIdGift)[x].selected = true;
        }
      }
      }
  } else 
  {
    // Neni zvolen zadny darek, oznacime prvni v poradi
    
     var nIdGift = getF('FrmGifts').giftSel[0].value;
//     getE('gift_' + nIdGift).style.backgroundColor = "#f5f5f5";  
     getF('FrmGifts').giftSel[0].checked = true;
    
  }
  
  setGiftRow();
  
  
}


function setGiftRow(){
  
  var sHtml  = "";
  var fGiftForm = getF('FrmGifts');
  
  
    for (var x=0; x<fGiftForm.giftSel.length;x++){
      if (fGiftForm.giftSel[x].checked) {
            giftIdSel =fGiftForm.giftSel[x].value;
        }
    }
  

  if (giftIdSel != 0){
  
   sSize = '-';
   if (getE('giftSizeColor_' + giftIdSel) != null) {
     if (getE('giftSizeColor_' + giftIdSel).options[getE('giftSizeColor_' + giftIdSel).selectedIndex].value != 0) {
      sSize = getE('giftSizeColor_' + giftIdSel).options[getE('giftSizeColor_' + giftIdSel).selectedIndex].text;
     }
   } else 
   {
    sSize = "";
   }
 
   sHtml = sHtml + '<td class="space p1"><img src='+ $("#gift_img_" +giftIdSel).val() +' /></td>';
   sHtml = sHtml + '<td class="name" colspan="3"><strong>Dárek - '+ $("#gift_name_" +giftIdSel).val() +'</strong><small>'+ sSize +' <span>|</span> v hodnotě '+ $("#gift_price_" +giftIdSel).val() +'</small></td>';
   sHtml = sHtml + '<td class="priceSum">0 </td>';
  
    $("#giftRow").html(sHtml);
    $("#giftRow").show();
  } else {
  
    $("#giftRow").hide();
  
  }
}


function ControlData1(){
	if(getF('FormReg').password.value == "") {alert("Zadejte heslo");getF('FormReg').password.focus();return false}
	if(getF('FormReg').passwordcheck.value == "") {alert("Pole Kontrola hesla se neshoduje s polem Heslo.");getF('FormReg').passwordcheck.focus();return false}
	if((getF('FormReg').password.value != getF('FormReg').passwordcheck.value)) {alert("Pole Kontrola hesla se neshoduje s polem Heslo.");getF('FormReg').passwordcheck.focus();return false}
  getE('FormReg').submit();
  return true;
}







function InsertCookies(strName,strData){
	var vyprs=new Date();
	vyprs.setDate(vyprs.getDate() - 365);
	document.cookie=strName+"="+strData+"; expires="+vyprs.toGMTString()+"; path=/;";
	vyprs.setDate(365 + 365 + vyprs.getDate());
	document.cookie=strName+"="+strData+"; expires="+vyprs.toGMTString()+"; path=/;";
}

function ExtractCookies(strName){
	var cookieList=document.cookie.split("; ");
	var cookieArray = new Array();
	var name = "#"
	for (var i=0; i < cookieList.length; i++){
		if(cookieList[i].indexOf(strName)>-1){
			if( cookieList[i].indexOf("=")>-1){name = cookieList[i].split("=");}
		}
	}
	if (name != "#"){
		return name[1];
	}else{
		return "none";
	}
}



$(document).ready(function() {


    // prihlaseni 
    
   $(".loEx1in #Logon_login").blur(function() {
     
     if ( $(".loEx1in #passInput").val() != "")
     {
        eval($(".loEx1in #passInput").focus());
     }  

   }); 

  $('.loEx1in #Logon_login').keyup(function() {
       if ( $(".loEx1in #passInput").val() != "")
       {
          eval($(".loEx1in #passInput").focus());
       }  
  });

   var count = 0;
    
   //1.krok 
    
    $('.bt_plus').click(function () {
        count = $(this).parent().children("input['Count']").val();
        count++;
        $(this).parent().children("input['Count']").val(count);
    });

    $('.bt_minus').click(function () {
        count = $(this).parent().children("input['Count']").val();
        if (count == 0 ) {return false;}
        
        count--;
        $(this).parent().children("input['Count']").val(count);
    });


    $('#snd23').click(function (){
       return step2();
    })

     
  try {
      $('.help').fancybox({
  				'width'				: '75%',
  				'height'			: '75%',
  				'autoScale'			: false,
  				'transitionIn'		: 'none',
  				'transitionOut'		: 'none',
  				'type'				: 'iframe'
  			});
        
      $('.js_help').fancybox({
  				'width'				: '75%',
  				'height'			: '75%',
  				'autoScale'			: false,
  				'transitionIn'		: 'none',
  				'transitionOut'		: 'none',
  				'type'				: 'iframe'
  			});

     }
    catch (e) {
    }

      
      
    
    
  // 2.krok
  
  $("input[name=reglog]").click(function(){
     if ($(this).val() == 'log')
     {
        $(".pass").show('Blind');
     } else
     {
      $(".pass").fadeOut();
     }
  });


  $("input[name$='email']").keypress(function() {
     $(".emailInfoAlert").hide();
  });


   $("#emailOrdStp2").blur(function() {
     
     InsertOrderCookie('email',$(this).val());   

   });

  $('#href_step3').click(function () {
    var sPass = $("#passInput").val();
    var sEmail = $("input[name='email']").val();
    
    if (sEmail == '' || sEmail == '@') {alert('Email není zadán.'); return false;}
  	if (EmailControl(sEmail)==false) {$("input[name='email']").focus();return false;}
  
    var ret = true;
  
    if ($("input[name=reglog]:checked").val() == 'reg'){

          //v pripadech kdy jiz kontrola emailu probehla
          if (ordStep3LogChecked) { return ret;}
           
   
           $.ajax({
                       type: "POST",
                       url: "/Back_OrderFunctions.asp",
                       cache: false,
                       async: false,
                       data: ({ email: sEmail, task: 'checkemail', inf_add: 'step3' }),
                       dataType: "html",
                       success: function (data) {
                          if (data == 0) {
                              $("#emailInfoAlertWithoutPass").hide();
                            } else {
                              $("#emailInfoAlertWithoutPass").show();
                              ordStep3LogChecked = true;
                              ret = false;
                            }
                       }
                   });
    
     return ret;
    
    }
    
    if (sPass == '' && ordStep3LogChecked == false) {alert('Heslo není zadáno.'); return false;}
    if (ordStep3LogChecked) 
    {
      InsertOrderCookie('password',"");   
      return true;
    }
    
    ret = true;
    $.ajax({
             type: "GET",
             url: "/Back_OrderFunctions.asp",
             cache: false,
             async: false,
             data: ({ Logon_login: sEmail, password: sPass, task: 'tryOrderLogin' }),
             dataType: "json",
             contentType: "application/json; charset=utf-8",
             success: function (data) {
                  var client = (typeof data.j) == 'string' ? eval('(' + data.j + ')') : data.j;
                  if (client[0].logged == 'false') 
                  {
                    alert('Neplatné přihlášení - špatné heslo.'); 
                    ret = false;
                    ordStep3LogChecked = true;
                    $("#passInput").val("");
                    $("#passInput").focus();
                  }
              }
     });
  
    InsertOrderCookie('password',sPass);   
    return ret;
    
   
   });

  $('#bto2log').click(function () {
    var sPass = $("#passInput").val();
    var sEmail = $("input[name='email']").val();
    
    if (sEmail == '' || sEmail == '@') {alert('Email není zadán.'); return false;}
  	if (EmailControl(sEmail)==false) {$("input[name='email']").focus();return false;}
  
    var ret = true;
    
    if ($("input[name=reglog]:checked").val() == 'reg'){
    
   
           $.ajax({
                       type: "POST",
                       url: "/Back_OrderFunctions.asp",
                       cache: false,
                       async: false,
                       data: ({ email: sEmail, task: 'checkemail', inf_add: 'step3' }),
                       dataType: "html",
                       success: function (data) {
                          if (data == 0) {
                              $("#emailInfoAlert").hide();
                            } else {
                              $("#emailInfoAlert").show();
                              $("input[name=reglog]").filter('[value=log]').click();
                              $("input[name$='password']").focus();
                               ret = false;
                            }
                       }
                   });
    
     return ret;
    
    }
    
    if (sPass == '') {alert('Heslo není zadáno.'); return false;}
    
    
    
    ret = true;
    
     $.ajax({
             type: "GET",
             url: "/Back_OrderFunctions.asp",
             cache: false,
             async: false,
             data: ({ Logon_login: sEmail, password: sPass, task: 'tryOrderLogin' }),
             dataType: "json",
             contentType: "application/json; charset=utf-8",
             success: function (data) {
                 var client = (typeof data.j) == 'string' ? eval('(' + data.j + ')') : data.j;
                  if (client[0].logged == 'false') {
                     alert('Neplatné přihlášení - špatné heslo.'); 
                     ret = false;
                     ordStep3LogChecked = true;
                     $("#passInput").val("");
                     $("#passInput").focus();
                     }
              }
     });
  
    InsertOrderCookie('password',sPass);   
    return ret;
    
   
   });

    
    $('#emailInfoAlertClose').click(function () {
         $("#emailInfoAlert").hide();
         $("input[name='password']").focus();
     });

    $('#emailInfoAlertCloseWithoutPass').click(function () {
         $("#emailInfoAlertWithoutPass").hide();
     });

 
    $('.loEx1_1').click(function () {
      var sEmail = $("input[name='email']").val();
      if (sEmail == '' || sEmail == '@') {alert('Email není zadán.'); return false;}

         $.ajax({
           type: "POST",
           url: "/lostpass.asp",
           cache: false,
           data: ({ email: sEmail}),
           dataType: "html",
           success: function (data) {
                if(data.indexOf('MessageNotOK') == -1)
                {
                  alert('Přihlašovací údaje byly úspěšně odeslány na Váš email.'); return false;
                } else {
                  alert('Litujeme, ale zadaný e-mail nepatří žádnému registrovanému uživateli.'); return false;
                }
           }
       });
    });


     $("input[name$='Email']").keypress(function() {
           $(".emailInfoAlert").hide();
       });


    //3.krok
    
     $('#fidelityUse').click(function () {
        
         $.ajax({
                   type: "GET",
                   url: "/Back_OrderFunctions.asp",
                   cache: false,
                   async: false,
                   data: ({task: 'usefidelity' }),
                   dataType: "html",
                   success: function (retPrice) {
                      if (retPrice != 0) {
                      
                        var nSumPrice = $("input[name='nPriceSum']").val();
                        nFidPrice = parseFloat(retPrice.replace(',','.'));
                        $("input[name='priceAdd']").val(nFidPrice);
                        if (nFidPrice > nSumPrice)
                        {
                          $("#rec_personal strong").html('- ' + nSumPrice + ' ');
                        } else {
                         $("#rec_personal strong").html('- ' + nFidPrice + ' ');
                          
                        }
                        
                        
                       
                       
                       
                        $("#rec_personal").show();
                        $(".recap_fidelityL").html('<img src="/img/bg_basket_add_info.gif" /> Sleva byla uplatněna.').removeClass('recap_fidelityL').addClass('recap_fidelity');
                        changeOrderDeliveryPrice();
                      } 
                    }
           });


     });
     
     
     
  try {
      $('.sim_info li a').fancybox({
  				'width'				: '75%',
  				'height'			: '75%',
  				'autoScale'			: false,
  				'transitionIn'		: 'none',
  				'transitionOut'		: 'none',
  				'type'				: 'iframe'
  			});
        
         
      $("a.zoom").fancybox({
    		'titleShow'     : false
    	});

     }
    catch (e) {
    }

          
    // Osobni odber UA - zmena
    
    $('#ooRegion').change(function() {
          $.ajax({
                   type: "GET",
                   url: "/Back_OrderFunctions.asp",
                   cache: false,
                   async: false,
                   data: ({task: 'ooUaChanged', val: $(this).val() }),
                   dataType: "html",
                   success: function (html) {
                      if (html != "") {
                        $("#ooCity").html(html);                       
                      } 
                    }
           });
        
    });   
          
    
    
    $(".delInfolnk").tipsy({live: true, html: true, fade:true, gravity: 'w'});
    $(".payInfolnk").tipsy({live: true, html: true, fade:true, gravity: 'e'});



    // Objednavka UA
    
     
    $('.newClient').click(function () {
      $('.ua_ord_left .navi').css('background-image','url(/img/bg_ua_ord_left.gif)');
      $('.regClientPart').hide();
      $('.newClientPart').show();
    });

    $('.regClient').click(function () {
      $('.ua_ord_left .navi').css('background-image','url(/img/bg_ua_ord_left_a.gif)');
      $('.regClientPart').show();
      $('.newClientPart').hide();
    });


    $("#ua_emailOrdStp2").keypress(function() {
       $(".ajaxMessage").hide();
    });
  
    $("input[name$='password']").keypress(function() {
       $(".ajaxMessage").hide();
    });

     $("#ua_emailOrdStp2").blur(function() {
       InsertOrderCookie('email',$(this).val());   
     });


  $('#ua_bto2log').click(function () {
    var sPass = $("#passInput").val();
    var sEmail = $("#ua_emailOrdStp2").val();
    
    if (sEmail == '' || sEmail == '@') {
      $("#ajaxMessage").html('Email není zadán.');
      $(".ajaxMessage").show();
      return false;
    }
    
  	if (EmailControlRegExp(sEmail, false)==false) {
      $("#ajaxMessage").html('Email není zadán.');
      $(".ajaxMessage").show();
      $("#ua_emailOrdStp2").focus();
      return false;
      }
  
    if (sPass == '') {
      
      $("#ajaxMessage").html('Heslo není zadáno.');
      $(".ajaxMessage").show();
      return false;
    }
    
    ret = true;
    
     $.ajax({
             type: "GET",
             url: "/Back_OrderFunctions.asp",
             cache: false,
             async: false,
             data: ({ Logon_login: sEmail, password: sPass, task: 'tryOrderLogin' }),
             dataType: "json",
             contentType: "application/json; charset=utf-8",
             success: function (data) {
                 var client = (typeof data.j) == 'string' ? eval('(' + data.j + ')') : data.j;
                  if (client[0].logged == 'false') {
                    $("#ajaxMessage").html('Neplatné přihlášení - špatné heslo.');
                    $(".ajaxMessage").show();
                    ret = false;
                   }
              }
     });
  
    InsertOrderCookie('password',sPass);   
    return ret;
   
   });

 
    $('#ua_lostPass').click(function () {
      var sEmail = $("#ua_emailOrdStp2").val();
      alert(sEmail);
      if (sEmail == '' || sEmail == '@') {
            $("#ajaxMessage").html("Email není zadán.");
            $(".ajaxMessage").show();
            return false;
     
        }

         $.ajax({
           type: "POST",
           url: "/lostpass.asp",
           cache: false,
           data: ({ email: sEmail}),
           dataType: "html",
           success: function (data) {
                if(data.indexOf('MessageNotOK') == -1)
                {
                    $("#ajaxMessage").html("Přihlašovací údaje byly úspěšně odeslány na Váš email.");
                    $(".ajaxMessage").show();
                    return false;
                } else {
                    $("#ajaxMessage").html("Litujeme, ale zadaný e-mail nepatří žádnému registrovanému uživateli.");
                    $(".ajaxMessage").show();
                    return false;
                }
           }
       });
    });
    
       //Akce 2+1 help
    $(".akce2plus1").tipsy({live: true, html: true, fade:true, gravity: 'w'});
   
    
    $('#SameAdressLink').click(function () {
      var SameAdress = $("input[name='SameAdress']").val();
      
      if (SameAdress == 1) {
        $("input[name='SameAdress']").val(0);
        $("#deliveryPart").hide();
      } else {
        $("input[name='SameAdress']").val(1);
        $("#deliveryPart").show();
     
      }
      
                
    });
    
    //send order UA
    
    $('#ua_send_order').click(function () {
    
      ControlDataOrderUserUa();
    
    });
    
});


var cookie_expire=new Date();
cookie_expire.setDate(cookie_expire.getDate() + 365);


function ExtractCookies_simple(strName){
	var cookieList=document.cookie.split("; ");
	var cookieArray = new Array();
	var name = "#"
	for (var i=0; i < cookieList.length; i++){
		if(cookieList[i].indexOf(strName+'=')==0){
			return cookieList[i].substr(cookieList[i].search('=')+1);
		}
	}
	return "";
}
function ExtractOrderCookie(strKey){ // vyuziva hlavniho klice USER
	var strKeysValues = ExtractCookies_simple('order');
	var aKeyValue, aOneKeyValue;
	if ((strKeysValues=="none")||(strKeysValues=="")) return "";
	aKeyValue = new Array();
	aOneKeyValue = new Array();
	aKeyValue = strKeysValues.split("&");
	for (var i = 0; i<aKeyValue.length; i++) {
		aOneKeyValue = aKeyValue[i].split("=");
		if (aOneKeyValue[0].toLowerCase()==strKey.toLowerCase()) { return unescape(decodeURI(aOneKeyValue[1])); }
	}
	return "";
}
function InsertOrderCookie(strKey, strValue){
	var strKeysValues = ExtractCookies_simple('order');
	var sTmp = '';
	var sDelimiter = '';
	var aKeyValue, aOneKeyValue;
	aKeyValue = new Array();
	aOneKeyValue = new Array();
	if ((strKeysValues=="none")||(strKeysValues=="")) {
		document.cookie = 'order' + "=" + strKey + "=" + encodeURI(strValue) + "; path=/;";
	} else if (("&"+strKeysValues.toLowerCase()).indexOf("&"+strKey.toLowerCase()+"=")==-1) {
		document.cookie = 'order' + "=" + strKeysValues + "&" + strKey + "=" + encodeURI(strValue) + "; path=/;";
    
	} else {
		aKeyValue = strKeysValues.split("&");
		for (var i = 0; i<aKeyValue.length; i++) {
			aOneKeyValue = aKeyValue[i].split("=");
			if (aOneKeyValue[0].toLowerCase()==strKey.toLowerCase()) aOneKeyValue[1] = encodeURI(strValue);
			sTmp += sDelimiter + aOneKeyValue[0] + "=" + aOneKeyValue[1];
			sDelimiter = "&";
		}
		document.cookie = 'order' + "=" + sTmp + "; expires=" + cookie_expire.toGMTString() + "; path=/; ";		
	}
}




