﻿
//két objektumot összehasonlító fn
(function($){
    $.fn.equals = function(compareTo){
        if (!compareTo || !compareTo.length || this.length != compareTo.length) {
            return false;
        }
        for (var i = 0; i < this.length; i++) {
            if (this[i] !== compareTo[i]) {
                return false;
            }
        }
        return true;
    }

})(jQuery);


function updateOptionItems(){
    var sels = $('.eszkozalapRow select');
    var selectedOptions = [];
    sels.each(function(i){       
        if ($.inArray($(this).val(), selectedOptions) != -1) {
            selectedOptions[i] = $(this).find('option:selected').removeAttr('selected').siblings(':not(:disabled)').eq(0).attr('selected','selected').val(); 
        }
        else selectedOptions[i] = $(this).val();
    });
    sels.each(function(i){
        var s = $(this);
        s.find('option').each(function(){
            var v = $(this).val();
            
            if ($.inArray(v, selectedOptions) == -1 || (s.val() == v)) {
                $(this).attr('disabled', 0);
                s.prev().find('li[id=' + v + ']').css({
                    display: 'block'
                });
            }
            else 
                if (s.val() != v) {
                    $(this).attr('disabled', 'disabled');
                    s.prev().find('li[id=' + v + ']').css({
                        display: 'none'
                    });
                }
        });
    });
}


// --- for FormFiller module ---
function pageSubmit() {
    var inactiveButton = document.getElementById("inactiveButton");
    var activeButton = document.getElementById("activeButton");
    inactiveButton.style.display = "block";
    activeButton.style.display = "none";
}

    var intervalId=null;
    var timeoutId=null;
	promoStep=0;
	promoNum=0;
	promoWidth=625;
	start = true;

	$(document).ready(function() {
        
       /* rightContent z-index */ 
       /* 
       $('#rightContent, td.adminError').mouseover(function(){
           $('#rightContent').css({
               'position': 'relative',
               'z-index': 100
           });
           $('td.adminError').css({
               'visibility': 'hidden'
           })
       }).mouseout(function(){
           $('#rightContent').css({
               'position': 'static',
               'z-index': 0
           });
           $('td.adminError').css({
               'visibility': 'visible'
           })
       })
        */
        
        
        /* tooltip */
       
       $('.tooltipped').tooltip({ 
            delay: 0, 
            showURL: false,
            track: true,
            extraClass: "jsTooltip"
        });

	    /* promobox slide start */

         if ($('.promoBox').length > 0) {
                      
             promoNum = $('.promoItems').length;
             
             $('.promoBoxMove').css('width', (promoNum * promoWidth) + 'px');
             
             $('.promoStepBtn').click(function(){
                 promoStep = (this.id).substring(1, 2) - 1;
                 promoMove();
                 if (promoStep == 0) {
                     $('#n1').addClass('menuContActiveFirst');
                 }
                 if (intervalId !== null) {
                     //alert('i')
                     clearInterval(intervalId);
                 }
                 if (clearInterval !== null) {
                     //alert('j')
                     clearTimeout(timeoutId);
                 }
             // nem indul el újra timeoutId = setTimeout("promoAutoMoveStart()", 2000);
            });
            
        }

	    /* js dropdown start */

	    if($('.dropDownList_1').length)$ ('.dropDownList_1').customSelect({ scrollbarW: 15 });
	    if($('.dropDownList_2').length)$ ('.dropDownList_2').customSelect({ classAttr: 'otherCustomSelect', scrollbarW: 15 });
	    if($('.dropDownList_3').length)$ ('.dropDownList_3').customSelect({ classAttr: 'otherCustomSelect otherCustomSelect2', scrollbarW: 15 });
  	    if($('.dropDownList_4').length)$ ('.dropDownList_4').customSelect({ classAttr: 'otherCustomSelect otherCustomSelect3', scrollbarW: 15 });
        if($('.dropDownList_5').length)$ ('.dropDownList_5').customSelect({ classAttr: 'otherCustomSelect otherCustomSelect4', scrollbarW: 15 });
        if($('.dropDownList_6').length)$ ('.dropDownList_6').customSelect({ classAttr: 'otherCustomSelect otherCustomSelect5', scrollbarW: 15 });
        if($('.dropDownList_9').length)$ ('.dropDownList_9').customSelect({ classAttr: 'otherCustomSelect otherCustomSelect9', scrollbarW: 15 });        

	    $('.fontSizeUp').click(function() {
	        changeFontSize('up');
	    });

	    $('.fontSizeDown').click(function() {
	        changeFontSize('down');
	    });

	    $('.printPageIco').click(function() {
	        window.print();
	    });

	    var $textsToResize = $('#pContent').find('*').contents().filter(function() {
	        return (this.nodeName == '#text' && this.nodeValue != null)
	    }).parent();

	    function changeFontSize(size) {
	        var fs, lh;
	        if (size == 'up') {
	            $textsToResize.each(function() {
	                fs = parseInt($(this).css('font-size'));
	                lh = parseInt($(this).css('line-height'));
                    if(!lh)lh=fs+3;
	                $(this).css({
	                    'font-size': (fs + 3) + 'px',
	                    'line-height': (lh + 3) + 'px'
	                });
	            });
	        }
	        else {
	            $textsToResize.each(function() {
	                fs = parseInt($(this).css('font-size'));
	                lh = parseInt($(this).css('line-height'));
                    if(!lh)lh=fs+3;
	                $(this).css({
	                    'font-size': (fs - 3) + 'px',
	                    'line-height': (lh - 3) + 'px'
	                });
	            });
	        }
	    };

	    
	    /* js dropdown end */
	    
		
		$('.formSteps .active, .formSteps .following').click(function(e){
            e.preventDefault();
            e.stopPropagation();
		});

        if($.browser.msie && $.browser.version==6){
            //alert(virtualPath);
            $('table.formSteps td a var').attr('style','background-image:none;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+virtualPath+'/Modules/Images/bg_formStepsBtnBlue.png'+'", sizingMethod="crop");');
            $('table.formSteps td a.active var').attr('style','background-image:none;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+virtualPath+'/Modules/Images/bg_formStepsBtnRed.png'+'", sizingMethod="crop");');
            $('table.formSteps td a.following var').attr('style','background-image:none;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+virtualPath+'/Modules/Images/bg_formStepsBtnGrey.png'+'", sizingMethod="crop");');
            $('table.formSteps td a em').attr('style','background-image:none;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+virtualPath+'/Modules/Images/bg_formStepsArrow.png'+'", sizingMethod="crop");');
            $('.sendPageEmailBottom').attr('style','background-image:none;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+virtualPath+'/Modules/Images/bg_send_email_bottom.png'+'", sizingMethod="crop");');
            $('.sendPageEmailTop').attr('style','background-image:none;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+virtualPath+'/Modules/Images/bg_send_email_top.png'+'", sizingMethod="crop");');
        }

	});

	function bindDropdownList() {	   
	    $('.dropDownList_2').customSelect({ classAttr: 'otherCustomSelect', scrollbarW: 15 });
	};    

	function promoMove(){

		$('.promoStepBtn').removeClass('menuContActive');
		$('.promoStepBtn').removeClass('menuContActiveFirst');

		if(promoStep != promoNum) {

			$('#n'+(promoStep+1)).addClass('menuContActive');

			$('.promoBoxMove').animate({
				left: 0-promoStep*promoWidth + 'px'
			}, 2000, 'easeInOutQuart');

		} else {
			promoStep = 0;
			$('.promoBoxMove').hide();
			$('.promoBoxMove').css('left','0px');
			$('.promoBoxMove').fadeIn();
			$('#n1').addClass('menuContActiveFirst');
		}        

		return false;

	}

	function promoAutoMove(){

		if(promoStep<=(promoNum-1)){
			promoStep++;
		}else{
			promoStep--;
		}

		if(promoStep==0){
			promoStep++;
		}

		promoMove();

	};   

	function promoAutoMoveStart(){
		intervalId=setInterval("promoAutoMove()", 7000);
	}

    window.onload = function(){         
        if ($('.promoBox').length>0) {            
            intervalId = setInterval("promoAutoMove()", 7000);
            //timeoutId = setTimeout("promoAutoMoveStart()", 4000);
        }        
    }
    
	/* promobox slide end */
    
    /* map selector */
    
        
        
    function mapRollover(flag, region) {
        
        placeName='Nincs meghatározva';
        switch (region) {
    	    case 'gyor_moson_sopron':
            placeName='Győr-Moson-Sopron';
    		newimage = '/Modules/Images/pic_map-of-hungary-m1.gif';
    		break;
    	case 'vas':
            placeName='Vas';
            newimage = '/Modules/Images/pic_map-of-hungary-m2.gif';
    		break;
    	case 'zala':
            placeName='Zala';
            newimage = '/Modules/Images/pic_map-of-hungary-m3.gif';
    		break;
    	case 'veszprem':
    	    placeName='Veszprém';
    	    newimage = '/Modules/Images/pic_map-of-hungary-m4.gif';
    		break;
    	case 'komarom_esztergom':
    		placeName='Komárom-Esztergom';
    		newimage = '/Modules/Images/pic_map-of-hungary-m6.gif';
    		break;
    	case 'fejer':
    	    placeName='Fejér';
    	    newimage = '/Modules/Images/pic_map-of-hungary-m7.gif';
    		break;
    	case 'pest':
    	    placeName='Pest';
    	    newimage = '/Modules/Images/pic_map-of-hungary-m8.gif';
    		break;
    	case 'nograd':
    		placeName='Nógrád';
    		newimage = '/Modules/Images/pic_map-of-hungary-m9.gif';
    		break;
    	case 'borsod_abauj_zemplen':
    		placeName='Borsod-Abaúj-Zemplén';
    		newimage = '/Modules/Images/pic_map-of-hungary-m10.gif';
    		break;
    	case 'szabolcs_szatmar_bereg':
    	    placeName='Szabolcs-Szatmár-Bereg';
    	    newimage = '/Modules/Images/pic_map-of-hungary-m11.gif';
    		break;
    	case 'hajdu_bihar':
            placeName='Hajdú-Bihar';
            newimage = '/Modules/Images/pic_map-of-hungary-m12.gif';
    		break;
    	case 'heves':
    		placeName='Heves';
    		newimage = '/Modules/Images/pic_map-of-hungary-m13.gif';
    		break;
    	case 'jasz_nagykun_szolnok':
    	    placeName='Jász-Nagykun-Szolnok';
    	    newimage = '/Modules/Images/pic_map-of-hungary-m14.gif';
    		break;
    	case 'bekes':
    	    placeName='Békés';
    	    newimage = '/Modules/Images/pic_map-of-hungary-m15.gif';
    		break;
    	case 'budapest':
    	    placeName='Budapest';
    	    newimage = '/Modules/Images/pic_map-of-hungary-m16.gif';
    		break;
    	case 'csongrad':
    	    placeName='Csongrád';
    	    newimage = '/Modules/Images/pic_map-of-hungary-m17.gif';
    		break;
    	case 'bacs_kiskun':
    	    placeName='Bács-Kiskun';
    	    newimage = '/Modules/Images/pic_map-of-hungary-m18.gif';
    		break;
    	case 'baranya':
    	    placeName='Baranya';
    	    newimage = '/Modules/Images/pic_map-of-hungary-m19.gif';
    		break;
    	case 'tolna':
    	    placeName='Tolna';
    	    newimage = '/Modules/Images/pic_map-of-hungary-m20.gif';
    		break;    
    	case 'somogy':
    	    placeName='Somogy';
    	    newimage = '/Modules/Images/pic_map-of-hungary-m21.gif';
    		break;
    	}
    
    	$('#ctl00_ctl00_BodyContent_MainContent_pic_mapOfHungary').attr('src', virtualPath + newimage);    

        //$('.maptest').html(flag+' - '+placeName);
    
       // name display with jquery 
	   if (flag == 0) {
           $('.mapMap').mousemove(function(e){
           
               var mouseX = e.pageX;
               var mouseY = e.pageY;
               
               $('.mapPlaceName').html(placeName);
               $('.mapPlaceName').css('display', 'block');
               $('.mapPlaceName').css('top', (mouseY +5) + 'px');
               $('.mapPlaceName').css('left', (mouseX +5) + 'px');
               
           });
       }
    }    
    
   
    function mapRollout() {
    	var s = document.getElementById("ctl00_ctl00_BodyContent_MainContent_counties");
    	var regio = s.options[s.selectedIndex].value;
    	if(regio != 'osszes'){
    		mapRollover(1,s.options[s.selectedIndex].value);
    	} else {
    	$('#ctl00_ctl00_BodyContent_MainContent_pic_mapOfHungary').attr('src', virtualPath + '/Modules/Images/pic_map-of-hungary.gif');
    	}
    
        $('.mapMap').mousemove(function(e){
	        $('.mapPlaceName').css('display', 'none');          
        });
    }
    
    
    /* map selector end */

    function showErrorOnZipCodeInvalid(containerSpan, zipCodeControlRowId, errorImageId, errorMessageId, cityNameId, errorMessage) {
        var container = document.getElementById(containerSpan);          
        if (container != null)
        {
            var cityName = document.getElementById(cityNameId);   
            if ((cityName != null) && (trim(cityName.innerHTML) == "")) {
                if (navigator.appName == "Microsoft Internet Explorer") {
                    document.getElementById(zipCodeControlRowId).className = "backgroundError";
                } else {
                    document.getElementById(zipCodeControlRowId).setAttribute("class", "backgroundError");
                }                   
                document.getElementById(errorImageId).style.display = "block";               
                document.getElementById(errorMessageId).style.display = "block";               
                var errorMessageSpan = document.getElementById(errorMessageId);                              
                errorMessageSpan.innerHTML = errorMessage;
            } else {
                if (navigator.appName == "Microsoft Internet Explorer") {
                    document.getElementById(zipCodeControlRowId).className = "";
                } else {
                    document.getElementById(zipCodeControlRowId).setAttribute("class", "");
                }
                document.getElementById(errorImageId).style.display = "none";              
                document.getElementById(errorMessageId).style.display = "none";
                var errorMessageSpan = document.getElementById(errorMessageId);              
                errorMessageSpan.innerHTML = "";
            }
        }
    }

    function trim(str) { return str.replace(/^\s+|\s+$/g, ""); };

    var zipcodeControlIds = new Array();

    function PostBackZipCode(evt, sourceControl, targetControlId, maxLength, isNumnerRequired) {        
        if ($.inArray(targetControlId, zipcodeControlIds) == -1) {
            if ((trim(sourceControl.value).length == maxLength) && (!isNumnerRequired || isNumberKey(evt))) {
                targetControl = document.getElementById(targetControlId);
                zipcodeControlIds.push(targetControlId);
                targetControl.onchange();
            }
        }
    }
    
    function HideCity(evt, controlId, buttonId) {      
        if (isNumberKey(evt) || isDelete(evt)) {
            zipcodeControlIds = $.grep(zipcodeControlIds, function(value) {
                return value != buttonId;
            });

            var cityNameSpan = document.getElementById(controlId).getElementsByTagName('span');
            if (cityNameSpan[0]) {                
                cityNameSpan[0].innerHTML = "";
            }
        }
    }

    function isNumberKey(evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode
        if ((charCode >= 48 && charCode <= 57) || (charCode >= 96 && charCode <= 105))
            return true;
        return false;
    }

    function isDelete(evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode != 8 && charCode != 46)
            return false;
        return true;
    }


    function BanSetFocusWhenNeeded(evt, controlFrom, controlToId, maxLength) {
        var expression = ((controlFrom.value.length == maxLength)
                         && (doGetCaretPosition(controlFrom) == maxLength)
                         && (isNumberKey(evt)));
        controlToFocus = document.getElementById(controlToId);
        SetFocusWhen(controlToFocus, expression)
    }

    function SetFocusWhen(controlToFocus, expression) {
        if (expression) {
            controlToFocus.focus();
        }
    }

function doGetCaretPosition (ctrl) {
var CaretPos = 0;
// IE Support
if (document.selection) {
ctrl.focus ();
var Sel = document.selection.createRange ();
Sel.moveStart ('character', -ctrl.value.length);
CaretPos = Sel.text.length;
}
// Firefox support
else if (ctrl.selectionStart || ctrl.selectionStart == '0'){
CaretPos = ctrl.selectionStart;
}
return (CaretPos);
}

function setCaretPosition(ctrl, pos)
{

if(ctrl.setSelectionRange)
{
ctrl.focus();
ctrl.setSelectionRange(pos,pos);
}
else if (ctrl.createTextRange) {
var range = ctrl.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
}


