// JavaScript Document
jQuery.noConflict();

/********** getElementById - IE fix ***********/
if (/msie/i.test (navigator.userAgent)) //only override IE
{
	document.nativeGetElementById = document.getElementById;
	document.getElementById = function(id)
	{
		var elem = document.nativeGetElementById(id);
		if(elem)
		{
			//make sure that it is a valid match on id
			if(elem.id == id)
			{
				return elem;
			}
			else
			{
				//otherwise find the correct element
				for(var i=1;i<document.all[id].length;i++)
				{
					if(document.all[id][i].id == id)
					{
						return document.all[id][i];
					}
				}
			}
		}
		return null;
	};
}
/********************************************/

function externalLinks() {
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++) {
    var anchor = anchors[i];
    if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
      anchor.target = "_blank";
  }
}

/*
*numbers only
*/
function isNumberKey(evt){
 var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode > 31 && (charCode < 48 || charCode > 57))
 return false;

 return true;
}

function operaCssFix(){
  if(jQuery.browser.opera){
    jQuery('.newsWrapper').css({'margin':'0 0 0 0px'});    
    jQuery('.actionWrapper').css({'margin':'0 0 0 0px'});    
  }
}


function onloadInit(){
  externalLinks(); 
  operaCssFix(); 
}

/********** moving background ***************/
/**
 * @author Alexander Farkas
 * v. 1.02
 */
(function(jQuery) {
 jQuery.extend(jQuery.fx.step,{
   backgroundPosition: function(fx) {
     if (fx.state === 0 && typeof fx.end == 'string') {
       var start = jQuery.curCSS(fx.elem,'backgroundPosition');
       start = toArray(start);
       fx.start = [start[0],start[2]];
       var end = toArray(fx.end);
       fx.end = [end[0],end[2]];
       fx.unit = [end[1],end[3]];
     }
     var nowPosX = [];
     nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
     nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
     fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
    
     function toArray(strg){
       strg = strg.replace(/left|top/g,'0px');
       strg = strg.replace(/right|bottom/g,'100%');
       strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
       var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
       return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
     }
   }
 });
})(jQuery);

// vertically center something in the viewport
(function(jQuery) {
  jQuery.fn.vCenter = function(options) {
    var pos = {
      sTop : function() {
        return window.pageYOffset
        || document.documentElement && document.documentElement.scrollTop
        ||  document.body.scrollTop;
      },
      wHeight : function() {
        return window.innerHeight
        || document.documentElement && document.documentElement.clientHeight
        || document.body.clientHeight;
      }
    };
    return this.each(function(index) {
      if (index == 0) {
        var $this = jQuery(this);
        var elHeight = $this.height();
        var elTop = pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2);
        $this.css({          
          top: elTop          
        });
      }
    });
  };
})(jQuery); // end plugin

  function showAjaxImage(){
    //ajax loading image show    
    jQuery('body').append('<div id="ajaxLoading"><img src="/site/img/ajaxLoading.gif" alt="Ajax Loader" /></div>');    
    var docWidth = jQuery(window).width();
    var docHeight = jQuery(window).height();
    jQuery('#ajaxLoading').css({ width: docWidth + 'px', height: docHeight + 'px' });    
    jQuery('#ajaxLoading').vCenter();    
    jQuery('#ajaxLoading img').css({left: (docWidth/2-55) + 'px', top: (parseInt(jQuery('#ajaxLoading').css('height'))/2-32)+'px'});                            
    jQuery(this).scroll(function(){
      jQuery('#ajaxLoading').vCenter();      
    });
    jQuery(window).resize(function(){      
      jQuery('#ajaxLoading').vCenter();            
    });
  } 
  
  function hideAjaxImage(){
    jQuery('#ajaxLoading').remove();
    jQuery('#ajaxLoading').css({display:'none'});  
    jQuery('#ajaxLoading img').remove();        
    jQuery('#ajaxLoading').remove();
    if(jQuery('#ajaxLoading').length>0)
      jQuery('#ajaxLoading').remove();    
  }

jQuery(document).ready(function(){

//----------vseobecne graficke a funkcne handlery-----------------------
  //-----------zmena classy buttonu-------------------
  jQuery('input.button')
    .mouseover(function(){
      jQuery(this).attr('className', 'buttonHover');
    })
    .mouseout(function(){
      jQuery(this).attr('className', 'button');
    });

  //---------handlery pre mouseover poloziek-------------
  jQuery('div#kosik table.kosik tr.mouseover')
  .live('mouseover',function(){
      jQuery(this).stop().animate({backgroundColor: mouseOverColor}, mouseOverTime);
      if(jQuery(this).children('td').children('input:radio').length > 0){
        jQuery(this).css('cursor', 'pointer');
      }
    });
  jQuery('div#kosik table.kosik tr.mouseover')
    .live('mouseout',function(){
      jQuery(this).stop().animate({backgroundColor: mouseOutColor}, mouseOutTime);
    });

  //DIC a IC DPH - handler kvoli validovaniu
  jQuery('#idpoDic').keyup(function(){
    if(jQuery(this).length>0){
      jQuery('#idpoIcDph').focus();
      jQuery(this).focus();
    }
  });
  jQuery('#idpoIcDph').keyup(function(){
    if(jQuery(this).length>0){
      jQuery('#idpoDic').focus();
      jQuery(this).focus();
    }
  });

  //only numbers to input (item count)
  jQuery('.kosikCountInput').keypress(function(evt){
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57 || jQuery(this).val().length >=3))
      return false;
    return evt;
  });
//filters
  jQuery(function($) {
    jQuery.fn.reverse = function() {
        return this.pushStack(this.get().reverse(), arguments);
    };
    jQuery.each( ['prev', 'next'], function(unusedIndex, name) {
        jQuery.fn[ name + 'ALL' ] = function(matchExpr) {
            var $all = jQuery('body').find('*').andSelf();
            $all = (name == 'prev')
                 ? $all.slice(0, $all.index(this)).reverse()
                 : $all.slice($all.index(this) + 1)
            ;
            if (matchExpr) $all = $all.filter(matchExpr);
            return $all;
        };
    });
  });
  jQuery('#filter_form select').change(function(){
	  jQuery(".productLiner").hide();
	  jQuery(".basicFilter").hide();
	  jQuery(".pleaseFillFilter").show();
	  if(jQuery(this).parent().nextALL('fieldset').children('select').length != 0) {
			jQuery(this).parent().nextALL('fieldset').children('select').attr('disabled','disabled');
			jQuery(this).parent().nextALL('fieldset').children('select').removeOption(/./);
	  }

	  var name = jQuery(this).attr("name");
	  if (name == "f4") {
		jQuery('#filter_form').submit();
	  }
	  else {
		  var nextOne = jQuery(this).parent().next('fieldset').children('select');
		  jQuery(nextOne).removeAttr("disabled");
		  
		  last = 0
		  params = {"category-id" : category_id};
		  jQuery(this).parent().prevALL('fieldset').children('select').reverse().each(function(index, element){
			  last = index+1;
			  params["f" + last] = jQuery(element).val();
		  });
		  last++;
		  params["f" + last] = jQuery(this).val();

		  //console.log(params);
		  jQuery.ajax({
			url: "/products/reload-filter",
			dataType: "json",
			data: params,
			beforeSend: function() {
        showAjaxImage();
        jQuery('#ajaxLoading').animate({
          opacity:'0.8'                  
        },500);
			    //console.log("before");
			},
			success: function(data){
				jQuery(nextOne).removeOption();
				jQuery.each(data, function(i, item) {
                    jQuery(nextOne).addOption(item.id, item.name);
                });
				jQuery(nextOne).val(0);
			},
			complete: function() {
			 jQuery('#ajaxLoading').animate({
          opacity:'0'                  
        },500,function(){
          hideAjaxImage(); 
        }); 
				//console.log("after");
			}
		  });
	  }
    
  });
  jQuery("#base_filter_form select").change(function(){
	  jQuery('#base_filter_form').submit();
  });
  jQuery("#base_filter_form input[type='checkbox']").click(function(){
	  jQuery('#base_filter_form').submit();
  });

//prod detail
  if(jQuery('#idBuyButton').length == 0){  
    jQuery('#buyForm fieldset').children('label:last').animate(
      {fontSize: '18px',
      lineHeight: '22px',
      color: '#DF5D14'},1000
    );
  } 
     
  jQuery('#buyForm fieldset').children('select:last').focus(function(){            
    jQuery(this).prev('label').animate(
      {fontSize: '10px',
      lineHeight: '15px',
      color: '#4B4B4B'},1500
    );
  });
  jQuery('#buyForm select').change(function(){        
    if(jQuery(this).nextALL('select').length != 0)         
      jQuery(this).nextALL('select').attr('disabled','disabled');         
    jQuery(this).parent().parent('form').submit();          
  });

//login form 
  jQuery('#login_uzivatel')
    .focus(function(){
      if(jQuery(this).val()=='login'){
        jQuery(this).val('');
      }
    })
    .blur(function(){
      if(jQuery(this).val()==''){
        jQuery(this).val('login');
      }
    });
  jQuery('#login_heslo')
    .focus(function(){
      jQuery(this).val('');
    })
    .blur(function(){
      if(jQuery(this).val()==''){
        jQuery(this).val('heslo');
      }
    });
  jQuery('#login_submit')
    .mouseover(function(){
      jQuery(this).css({'fontWeight':'bold'});
    })
    .mouseout(function(){
      jQuery(this).css({'fontWeight':'normal'});
    });
    
//search form
  jQuery('#search_input')
    .focus(function(){
      jQuery(this).css({'background':'transparent url("/site/img/searchInputBgHover.png") no-repeat 0 0'});
      if(jQuery(this).val()=='Hľadať ...'){
        jQuery(this).val('');
      }
    })
    .blur(function(){
      jQuery(this).css({'background':'none'});
      if(jQuery(this).val()==''){
        jQuery(this).val('Hľadať ...');
      }
    });
  jQuery('#search_submit')
    .mouseover(function(){
      jQuery(this).css({'background':'transparent url("/site/img/searchSubmitBgHover.png") no-repeat 0 0'});
    })
    .mouseout(function(){
      jQuery(this).css({'background':'none'});
    });

//buy form  
  jQuery('.buySubmit')
    .mouseover(function(){
      jQuery(this).css({'background':'transparent url("/site/img/buyButtonHover.png") no-repeat 0 0'});
    })
    .mouseout(function(){
      jQuery(this).css({'background':'transparent url("/site/img/buyButton.png") no-repeat 0 0'});
    })
//top menu background position
  jQuery(".topMenuBanner li a")
  	.css( {backgroundPosition: "0 -53px"} )
  	.mouseover(function(){	  
  		jQuery(this).animate(
  			{backgroundPosition:"(0 0)"}, 
  			{queue:false, duration:600});     
  		})
  	.mouseout(function(){
  		jQuery(this).stop().animate(
  			{backgroundPosition: "(0 -53px)"}, 
  			{queue:false, duration:300});
    });
        
//left menu background position
  jQuery(".leftMenu li a")
  	.css( {backgroundPosition: "-220px 0"} )
  	.mouseover(function(){	  
  		jQuery(this).animate(
  			{backgroundPosition:"(0 0)"}, 
  			{queue:false, duration:400});     
  		})
  	.mouseout(function(){
  		jQuery(this).stop().animate(
  			{backgroundPosition: "(-220px 0)"}, 
  			{queue:false, duration:200});
    });
  
if(!jQuery.browser.msie || (jQuery.browser.msie && jQuery.browser.version!='6.0')){
//right menu hovers
//name convention: 
//brand+.+extension
//brand+Hover+.+extension
  jQuery('.brand a')
    .mouseover(function(){
      var tempLink = jQuery(this).children('img').attr('src');
      var ext = tempLink.substr(tempLink.length-4,tempLink.length);
      var link = tempLink.substr(0,tempLink.length-4);
      jQuery(this).children('img').attr('src',link+'_hover'+ext);
    })
    .mouseout(function(){
      var link = jQuery(this).children('img').attr('src');
      var ext = link.substr(link.length-4,link.length);
      link = link.substr(0,link.length-10);
      jQuery(this).children('img').attr('src',link+''+ext);
    });
}

if(!jQuery.browser.msie || (jQuery.browser.msie && jQuery.browser.version!='7.0' && jQuery.browser.version!='6.0')){
  var ie67 = false;
}else{
  var ie67 = true;
}
if(!ie67){
//round corners
  jQuery('.rounded').corner('3px');
}
//category events
  jQuery('.categoryWrapper')
    .mouseover(function(){      
      jQuery(this).stop().animate({
        backgroundColor:'#373737'
      },300, function(){
        if(!ie67){
          jQuery(this).children('div').each(function(){
            jQuery(this).remove();
          });
          jQuery(this).corner('3px');
        }
      });
    })
    .mouseout(function(){
      jQuery(this).stop().animate({
        backgroundColor:'#656565'
      },300, function(){
        if(!ie67){
          jQuery(this).children('div').each(function(){
            jQuery(this).remove();
          });
          jQuery(this).corner('3px');
        }
      });      
    });

//thumb effects
  jQuery("ul.thumb li").hover(function() {
  	jQuery(this).css({'z-index' : '10'}); /*Add a higher z-index value so this image stays on top*/ 
  	jQuery(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
  		.animate({
  			marginTop: '-70px', /* The next 4 lines will vertically align this image */ 
  			marginLeft: '-64px',
  			top: '50%',
  			left: '50%',
  			width: '120px', /* Set new width */
  			height: '130px' /* Set new height */  			  			
  		}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */
  
  	} , function() {
  	jQuery(this).css({'z-index' : '0'}); /* Set z-index back to 0 */
  	jQuery(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
  		.animate({
  			marginTop: '0', /* Set alignment back to default */
  			marginLeft: '0',
  			top: '0',
  			left: '0',
  			width: '93px', /* Set width back to default */
  			height: '105px' /* Set height back to default */  			  			
  		}, 400);
  });
   jQuery("ul.thumb li a").click(function() {  
     var mainImage = jQuery(this).attr("href"); //Find Image Name
     jQuery("#main_view img").attr({src: mainImage});
     return false;
   }); 

//registration form
  jQuery('input[name=cbUserType]').click(function(){
    if(myValidation!= null){
      myValidation.resetForm();
      myValidation = null;      
    }   
    if(jQuery(this).val() == 1){    
      jQuery('#tabFirma').animate({
        height: "hide"                
      },300, function(){        
        jQuery('#tabOsoba').animate({
          height: "show" 
        },2500);      
      });      
    }else{
      jQuery('#tabOsoba').animate({
        height: "hide"                    
      },300, function(){        
        jQuery('#tabFirma').animate({
          height: "show" 
        },2500);
      });
    }         
  });
  jQuery('#idpoDic').keyup(function(){
    if(jQuery(this).length>0){
      jQuery('#idpoIcDph').focus();
      jQuery(this).focus();
    }
  });
  jQuery('#idpoIcDph').keyup(function(){
    if(jQuery(this).length>0){
      jQuery('#idpoDic').focus();
      jQuery(this).focus();
    }
  });
  if(jQuery('#sendReg').length>0){    
    jQuery('#tabFirma').css('display','none');
  }
  
  if(jQuery('#sendReg').length>0){    
    if(jQuery('input[name=cbUserType]:checked').val()==1){//FO zakaznik                    
      myValidation = jQuery("#regForm").validate({ 
      rules: {           
          chbSuhlas: "required",
          foNameOsoba: {
            required: true,
            minlength: 2,
            number: false
          },
          foSurname: {
            required: true,
            minlength: 2,
            number: false
          },
          foPhone:{
            digits: true,
            minlength: 10            
          },
          foEmail:{
            required: true,
            email: true
          },
          foStreet:{
            required: true
          },
          foCity:{
            required: true
          },
          foZip_code:{
            required: true                
          },
          foState:{
            required: true                
          },
          foStreet2:{
            required: true
          },
          foCity2:{
            required: true
          },
          foZip_code2:{
            required: true                
          },
          foState2:{
            required: true                
          },
          tbLoginAdd: {    
            required: true,                
            minlength: 2/*, 
            remote: {
              url: "check-email.php",//volanie cez ajax ci uz taky login neexistuje
              type: "post",
              data: {//takto sa daju posielat dalsie data do ajaxu cez post/get
                username: function() {
                  return $("#username").val();
                }
              }
            }*/
          }, 
          tbPasswordAdd: {
            required: true,                    
            minlength: 6 
          },
          tbPasswordAddOverenie: {
            required: true,                    
            minlength: 6,
            equalTo: "#idtbPasswordAdd"
          }
           
      }, 
      messages: {   
          chbSuhlas: {
            required: aErrorMsg['chbSuhlas']['required'][lang]
          }, 
          foNameOsoba: {
            required: aErrorMsg['foNameOsoba']['required'][lang],
            minlength: jQuery.format(aErrorMsg['foNameOsoba']['minlength'][lang]),
            number: aErrorMsg['foNameOsoba']['number'][lang]
          },
          foSurname: {
            required: aErrorMsg['foSurname']['required'][lang],
            minlength: jQuery.format(aErrorMsg['foSurname']['minlength'][lang]),
            number: aErrorMsg['foSurname']['number'][lang]
          },
          foPhone:{
            minlength: jQuery.format(aErrorMsg['foPhone']['minlength'][lang]),
            digits: aErrorMsg['foPhone']['digits'][lang]
          },
          foEmail:{
            required: aErrorMsg['foEmail']['required'][lang],
            email: aErrorMsg['foEmail']['email'][lang]
          },
          foStreet:{
            required: aErrorMsg['foStreet']['required'][lang]
          },
          foCity:{
            required: aErrorMsg['foCity']['required'][lang]
          },
          foZip_code:{
            required: aErrorMsg['foZip_code']['required'][lang]                
          },
          foState:{
            required: aErrorMsg['foState']['required'][lang]                
          },
          foStreet2:{
            required: aErrorMsg['foStreet2']['required'][lang]
          },
          foCity2:{
            required: aErrorMsg['foCity2']['required'][lang]
          },
          foZip_code2:{
            required: aErrorMsg['foZip_code2']['required'][lang]                
          },
          foState2:{
            required: aErrorMsg['foState2']['required'][lang]                
          },
          tbLoginAdd: { 
            required: aErrorMsg['tbLoginAdd']['required'][lang],                   
            minlength: jQuery.format(aErrorMsg['tbLoginAdd']['minlength'][lang])/*, 
            remote: aErrorMsg['tbLoginAdd']['remote'][lang]
            }*/
          }, 
          tbPasswordAdd: {
            required: aErrorMsg['tbPasswordAdd']['required'][lang],                    
            minlength: jQuery.format(aErrorMsg['tbPasswordAdd']['minlength'][lang])
          },
          tbPasswordAddOverenie: {
            required: aErrorMsg['tbPasswordAddOverenie']['required'][lang],
            minlength: jQuery.format(aErrorMsg['tbPasswordAddOverenie']['minlength'][lang]),
            equalTo: aErrorMsg['tbPasswordAddOverenie']['equalTo'][lang]
          }      
          
      }, 
      errorElement: "label",
      errorClass: "errorLabel",
      // the errorPlacement has to take the table layout into account 
      errorPlacement: function(error, element) {             
          if ( element.is(":radio") ) 
              error.appendTo( element.parent('td').parent('tr').next('tr').children('td') ); 
          else if ( element.is(":checkbox") ) 
              error.appendTo( element.parent('td').parent('tr').next('tr').children('td') ); 
          else                  
              error.appendTo( element.parent('td').parent('tr').next('tr').children('td')[1] );                                         
      },         
      // set this class to error-labels to indicate valid fields 
      success: function(label) { 
          // set   as text for IE
          if ( label.parent().parent().next().children().is(":radio") ) 
              ; 
          else if ( label.prev('input').is(":checkbox") ) 
              ; 
          else 
              ;
                           
          label.html(" ").addClass("checked"); 
      }                     
    });
    }else{//PO zakaznik
      myValidation = jQuery("#regForm").validate({ 
      rules: {         
          chbSuhlas: "required",
          poPravnaForma: {
            required: true                
          },
          poName: {
            required: true,
            minlength: 2
          },
          poWebAdresa: {
            url: true
          },
          poContactPerson: {
            minlength: 2
          },                             
          poPhone:{
            digits: true,
            minlength: 10            
          },
          poEmail:{
            required: true,
            email: true
          },
          poIco: {
            required: true,
            rangelength: [8, 8],
            digits: true
          },
          poDic: {
            required: "poIcDph:blank",
            rangelength: [10, 10],
            digits: true
          },
          poIcDph: {
            required: "poDic:blank",
            rangelength: [12, 12]
          },
          poStreet:{
            required: true
          },
          poCity:{
            required: true
          },
          poZip_code:{
            required: true                
          },
          poState:{
            required: true                
          },
          poStreet2:{
            required: true
          },
          poCity2:{
            required: true
          },
          poZip_code2:{
            required: true                
          },
          poState2:{
            required: true                
          },
          tbLoginAdd: {   
            required: true,                 
            minlength: 2/*, 
            remote: {
              url: "check-email.php",//volanie cez ajax ci uz taky login neexistuje
              type: "post",
              data: {//takto sa daju posielat dalsie data do ajaxu cez post/get
                username: function() {
                  return $("#username").val();
                }
              }
            }*/
          }, 
          tbPasswordAdd: {
            required: true,                    
            minlength: 6 
          },
          tbPasswordAddOverenie: {
            required: true,                    
            minlength: 6,
            equalTo: "#idtbPasswordAdd" 
          }
           
        }, 
        messages: {           
            chbSuhlas: {
              required: aErrorMsg['chbSuhlas']['required'][lang]
            }, 
            poPravnaForma: {
              required: aErrorMsg['poPravnaForma']['required'][lang]                
            },
            poName: {
              required: aErrorMsg['poName']['required'][lang],
              minlength: jQuery.format(aErrorMsg['poName']['minlength'][lang])
            },
            poWebAdresa: {
              url: aErrorMsg['poWebAdresa']['url'][lang]
            },
            poContactPerson: {
              minlength: jQuery.format(aErrorMsg['poContactPerson']['minlength'][lang])
            },         
            poPhone:{
              minlength: jQuery.format(aErrorMsg['poPhone']['minlength'][lang]),
              digits: aErrorMsg['poPhone']['digits'][lang]
            },
            poEmail:{
              required: aErrorMsg['poEmail']['required'][lang],
              email: aErrorMsg['poEmail']['email'][lang]
            },
            poIco: {
              required: aErrorMsg['poIco']['required'][lang],
              rangelength: jQuery.format(aErrorMsg['poIco']['rangelength'][lang]),
              digits: aErrorMsg['poIco']['digits'][lang]
            },
            poDic: {
              required: aErrorMsg['poDic']['required'][lang],
              rangelength: jQuery.format(aErrorMsg['poDic']['rangelength'][lang]),
              digits: aErrorMsg['poDic']['digits'][lang]
            },
            poIcDph: {
              required: aErrorMsg['poIcDph']['required'][lang],
              rangelength: jQuery.format(aErrorMsg['poIcDph']['rangelength'][lang])
            },
            poStreet:{
              required: aErrorMsg['poStreet']['required'][lang]
            },
            poCity:{
              required: aErrorMsg['poCity']['required'][lang]
            },
            poZip_code:{
              required: aErrorMsg['poZip_code']['required'][lang]                
            },
            poState:{
              required: aErrorMsg['poState']['required'][lang]                
            },
            poStreet2:{
              required: aErrorMsg['poStreet2']['required'][lang]
            },
            poCity2:{
              required: aErrorMsg['poCity2']['required'][lang]
            },
            poZip_code2:{
              required: aErrorMsg['poZip_code2']['required'][lang]                
            },
            poState2:{
              required: aErrorMsg['poState2']['required'][lang]                
            },
            tbLoginAdd: {  
              required: aErrorMsg['tbLoginAdd']['required'][lang],                  
              minlength: jQuery.format(aErrorMsg['tbLoginAdd']['minlength'][lang])/*, 
              remote: aErrorMsg['tbLoginAdd']['remote'][lang]
              }*/
            }, 
            tbPasswordAdd: {
              required: aErrorMsg['tbPasswordAdd']['required'][lang],                    
              minlength: jQuery.format(aErrorMsg['tbPasswordAdd']['minlength'][lang])
            },
            tbPasswordAddOverenie: { 
              required: aErrorMsg['tbPasswordAddOverenie']['required'][lang],
              minlength: jQuery.format(aErrorMsg['tbPasswordAddOverenie']['minlength'][lang]),
              equalTo: aErrorMsg['tbPasswordAddOverenie']['equalTo'][lang]
            }      
            
        }, 
        errorElement: "label",
        errorClass: "errorLabel",
        // the errorPlacement has to take the table layout into account 
        errorPlacement: function(error, element) {             
            if ( element.is(":radio") ) 
                error.appendTo( element.parent('td').parent('tr').next('tr').children('td') ); 
            else if ( element.is(":checkbox") ) 
                error.appendTo( element.parent('td').parent('tr').next('tr').children('td') );
            else{                  
                error.appendTo( element.parent('td').parent('tr').next('tr').children('td')[1] );              
            }                   
        },             
        // set this class to error-labels to indicate valid fields 
        success: function(label) { 
            // set   as text for IE
            if ( label.parent().parent().next().children().is(":radio") ) 
                ; 
            else if ( label.prev('input').is(":checkbox") ) 
                ; 
            else 
                ;
                             
            label.html(" ").addClass("checked"); 
        }                     
      });
      }
        
    }  
    
    if(jQuery('#sendChangeData').length>0){    
      if(jQuery('input[name=cbUserType]:checked').val()==1){//FO zakaznik                    
        myValidation = jQuery("#regForm").validate({ 
        rules: {                       
            foNameOsoba: {
              required: true,
              minlength: 2,
              number: false
            },
            foSurname: {
              required: true,
              minlength: 2,
              number: false
            },
            foPhone:{
              digits: true,
              minlength: 10            
            },
            foEmail:{
              required: true,
              email: true
            },
            foStreet:{
              required: true
            },
            foCity:{
              required: true
            },
            foZip_code:{
              required: true                
            },
            foState:{
              required: true                
            },
            foStreet2:{
              required: true
            },
            foCity2:{
              required: true
            },
            foZip_code2:{
              required: true                
            },
            foState2:{
              required: true                
            },
            tbLoginAdd: {    
              required: true,                
              minlength: 2/*, 
              remote: {
                url: "check-email.php",//volanie cez ajax ci uz taky login neexistuje
                type: "post",
                data: {//takto sa daju posielat dalsie data do ajaxu cez post/get
                  username: function() {
                    return $("#username").val();
                  }
                }
              }*/
            }, 
            tbPasswordAdd: {                                  
              minlength: 6 
            },
            tbPasswordAddOverenie: {
              required: '#idtbPasswordAdd:filled',                    
              minlength: 6,
              equalTo: "#idtbPasswordAdd"
            }
             
        }, 
        messages: {                
            foNameOsoba: {
              required: aErrorMsg['foNameOsoba']['required'][lang],
              minlength: jQuery.format(aErrorMsg['foNameOsoba']['minlength'][lang]),
              number: aErrorMsg['foNameOsoba']['number'][lang]
            },
            foSurname: {
              required: aErrorMsg['foSurname']['required'][lang],
              minlength: jQuery.format(aErrorMsg['foSurname']['minlength'][lang]),
              number: aErrorMsg['foSurname']['number'][lang]
            },
            foPhone:{
              minlength: jQuery.format(aErrorMsg['foPhone']['minlength'][lang]),
              digits: aErrorMsg['foPhone']['digits'][lang]
            },
            foEmail:{
              required: aErrorMsg['foEmail']['required'][lang],
              email: aErrorMsg['foEmail']['email'][lang]
            },
            foStreet:{
              required: aErrorMsg['foStreet']['required'][lang]
            },
            foCity:{
              required: aErrorMsg['foCity']['required'][lang]
            },
            foZip_code:{
              required: aErrorMsg['foZip_code']['required'][lang]                
            },
            foState:{
              required: aErrorMsg['foState']['required'][lang]                
            },
            foStreet2:{
              required: aErrorMsg['foStreet2']['required'][lang]
            },
            foCity2:{
              required: aErrorMsg['foCity2']['required'][lang]
            },
            foZip_code2:{
              required: aErrorMsg['foZip_code2']['required'][lang]                
            },
            foState2:{
              required: aErrorMsg['foState2']['required'][lang]                
            },
            tbLoginAdd: { 
              required: aErrorMsg['tbLoginAdd']['required'][lang],                   
              minlength: jQuery.format(aErrorMsg['tbLoginAdd']['minlength'][lang])/*, 
              remote: aErrorMsg['tbLoginAdd']['remote'][lang]
              }*/
            }, 
            tbPasswordAdd: {                                  
              minlength: jQuery.format(aErrorMsg['tbPasswordAdd']['minlength'][lang])
            },
            tbPasswordAddOverenie: {
              required: aErrorMsg['tbPasswordAddOverenie']['required'][lang],
              minlength: jQuery.format(aErrorMsg['tbPasswordAddOverenie']['minlength'][lang]),
              equalTo: aErrorMsg['tbPasswordAddOverenie']['equalTo'][lang]
            }      
            
        }, 
        errorElement: "label",
        errorClass: "errorLabel",
        // the errorPlacement has to take the table layout into account 
        errorPlacement: function(error, element) {             
            if ( element.is(":radio") ) 
                error.appendTo( element.parent('td').parent('tr').next('tr').children('td') ); 
            else if ( element.is(":checkbox") ) 
                error.appendTo( element.parent('td').parent('tr').next('tr').children('td') ); 
            else                  
                error.appendTo( element.parent('td').parent('tr').next('tr').children('td')[1] );                                         
        },         
        // set this class to error-labels to indicate valid fields 
        success: function(label) { 
            // set   as text for IE
            if ( label.parent().parent().next().children().is(":radio") ) 
                ; 
            else if ( label.prev('input').is(":checkbox") ) 
                ; 
            else 
                ;
                             
            label.html(" ").addClass("checked"); 
        }                     
      });
      }else{//PO zakaznik
        myValidation = jQuery("#regForm").validate({ 
        rules: {                     
            poPravnaForma: {
              required: true                
            },
            poName: {
              required: true,
              minlength: 2
            },
            poWebAdresa: {
              url: true
            },
            poContactPerson: {
              minlength: 2
            },                             
            poPhone:{
              digits: true,
              minlength: 10            
            },
            poEmail:{
              required: true,
              email: true
            },
            poIco: {
              required: true,
              rangelength: [8, 8],
              digits: true
            },
            poDic: {
              required: "poIcDph:blank",
              rangelength: [10, 10],
              digits: true
            },
            poIcDph: {
              required: "poDic:blank",
              rangelength: [12, 12]
            },
            poStreet:{
              required: true
            },
            poCity:{
              required: true
            },
            poZip_code:{
              required: true                
            },
            poState:{
              required: true                
            },
            poStreet2:{
              required: true
            },
            poCity2:{
              required: true
            },
            poZip_code2:{
              required: true                
            },
            poState2:{
              required: true                
            },
            tbLoginAdd: {   
              required: true,                 
              minlength: 2/*, 
              remote: {
                url: "check-email.php",//volanie cez ajax ci uz taky login neexistuje
                type: "post",
                data: {//takto sa daju posielat dalsie data do ajaxu cez post/get
                  username: function() {
                    return $("#username").val();
                  }
                }
              }*/
            }, 
            tbPasswordAdd: {                                 
              minlength: 6 
            },
            tbPasswordAddOverenie: {
              required: '#idtbPasswordAdd:filled',                    
              minlength: 6,
              equalTo: "#idtbPasswordAdd" 
            }
             
        }, 
        messages: {                       
            poPravnaForma: {
              required: aErrorMsg['poPravnaForma']['required'][lang]                
            },
            poName: {
              required: aErrorMsg['poName']['required'][lang],
              minlength: jQuery.format(aErrorMsg['poName']['minlength'][lang])
            },
            poWebAdresa: {
              url: aErrorMsg['poWebAdresa']['url'][lang]
            },
            poContactPerson: {
              minlength: jQuery.format(aErrorMsg['poContactPerson']['minlength'][lang])
            },         
            poPhone:{
              minlength: jQuery.format(aErrorMsg['poPhone']['minlength'][lang]),
              digits: aErrorMsg['poPhone']['digits'][lang]
            },
            poEmail:{
              required: aErrorMsg['poEmail']['required'][lang],
              email: aErrorMsg['poEmail']['email'][lang]
            },
            poIco: {
              required: aErrorMsg['poIco']['required'][lang],
              rangelength: jQuery.format(aErrorMsg['poIco']['rangelength'][lang]),
              digits: aErrorMsg['poIco']['digits'][lang]
            },
            poDic: {
              required: aErrorMsg['poDic']['required'][lang],
              rangelength: jQuery.format(aErrorMsg['poDic']['rangelength'][lang]),
              digits: aErrorMsg['poDic']['digits'][lang]
            },
            poIcDph: {
              required: aErrorMsg['poIcDph']['required'][lang],
              rangelength: jQuery.format(aErrorMsg['poIcDph']['rangelength'][lang])
            },
            poStreet:{
              required: aErrorMsg['poStreet']['required'][lang]
            },
            poCity:{
              required: aErrorMsg['poCity']['required'][lang]
            },
            poZip_code:{
              required: aErrorMsg['poZip_code']['required'][lang]                
            },
            poState:{
              required: aErrorMsg['poState']['required'][lang]                
            },
            poStreet2:{
              required: aErrorMsg['poStreet2']['required'][lang]
            },
            poCity2:{
              required: aErrorMsg['poCity2']['required'][lang]
            },
            poZip_code2:{
              required: aErrorMsg['poZip_code2']['required'][lang]                
            },
            poState2:{
              required: aErrorMsg['poState2']['required'][lang]                
            },
            tbLoginAdd: {  
              required: aErrorMsg['tbLoginAdd']['required'][lang],                  
              minlength: jQuery.format(aErrorMsg['tbLoginAdd']['minlength'][lang])/*, 
              remote: aErrorMsg['tbLoginAdd']['remote'][lang]
              }*/
            }, 
            tbPasswordAdd: {                                  
              minlength: jQuery.format(aErrorMsg['tbPasswordAdd']['minlength'][lang])
            },
            tbPasswordAddOverenie: { 
              required: aErrorMsg['tbPasswordAddOverenie']['required'][lang],
              minlength: jQuery.format(aErrorMsg['tbPasswordAddOverenie']['minlength'][lang]),
              equalTo: aErrorMsg['tbPasswordAddOverenie']['equalTo'][lang]
            }      
            
        }, 
        errorElement: "label",
        errorClass: "errorLabel",
        // the errorPlacement has to take the table layout into account 
        errorPlacement: function(error, element) {             
            if ( element.is(":radio") ) 
                error.appendTo( element.parent('td').parent('tr').next('tr').children('td') ); 
            else if ( element.is(":checkbox") ) 
                error.appendTo( element.parent('td').parent('tr').next('tr').children('td') );
            else{                  
                error.appendTo( element.parent('td').parent('tr').next('tr').children('td')[1] );              
            }                   
        },             
        // set this class to error-labels to indicate valid fields 
        success: function(label) { 
            // set   as text for IE
            if ( label.parent().parent().next().children().is(":radio") ) 
                ; 
            else if ( label.prev('input').is(":checkbox") ) 
                ; 
            else 
                ;
                             
            label.html(" ").addClass("checked"); 
        }                     
      });
      }
        
    }     
    
  onloadInit();
});


//functions for registration
	function copyAddrFo() {
  		jQuery('#idfoStreet2').val(jQuery('#idfoStreet').val());
  		jQuery('#idfoStreet2').focus();
  		jQuery('#idfoCity2').val(jQuery('#idfoCity').val());
  		jQuery('#idfoCity2').focus();
  		jQuery('#idfoZip_code2').val(jQuery('#idfoZip_code').val());
  		jQuery('#idfoZip_code2').focus();
  		jQuery('#idfoState2').val(jQuery('#idfoState').val());
  		jQuery('#idfoState2').focus();
  		jQuery('#idfoState2').blur();
	}
	function copyAddrPo() {
  		jQuery('#idpoStreet2').val(jQuery('#idpoStreet').val());
  		jQuery('#idpoStreet2').focus();
  		jQuery('#idpoCity2').val(jQuery('#idpoCity').val());
  		jQuery('#idpoCity2').focus();
  		jQuery('#idpoZip_code2').val(jQuery('#idpoZip_code').val());
  		jQuery('#idpoZip_code2').focus();
  		jQuery('#idpoState2').val(jQuery('#idpoState').val());
  		jQuery('#idpoState2').focus();
  		jQuery('#idpoState2').blur();
	}
