$().ready(function() {
	$('#modalDialog').jqm({ajax: '@href', trigger: 'a.modalTrigger'});	

  $('.bTip').bt({
    hoverIntentOpts: { interval: 0, timeout: 0 },
    padding: 15,
    spikeLength: 30,
    spikeGirth: 20,
    overlap: -3,
    cornerRadius: 10,
    fill: 'rgba(0, 0, 0, .8)',
    strokeWidth: 3,
    strokeStyle: '#fcac20',
    cssStyles: {color: '#FFF', fontWeight: 'bold'}
  });
  $('.bTipContent').bt({
    hoverIntentOpts: { interval: 0, timeout: 0 },
    contentSelector: "$('#content_'+$(this).attr('id')).html()",
    width: "auto",
    padding: 15,
    spikeLength: 30,
    spikeGirth: 20,
    overlap: -3,
    cornerRadius: 10,
    fill: 'rgba(0, 0, 0, .8)',
    strokeWidth: 3,
    strokeStyle: '#fcac20',
    cssStyles: {color: '#FFF', fontWeight: 'bold'}
  });
  $('.bTipAjax').bt({
    ajaxPath: ["'/showtipimage.php?ids='+$(this).attr('id')", 'div#content'],
    ajaxCache: false,
    ajaxLoading: "<img src='/pix/v2/spinner.gif' width='37' height='37'>",
    hoverIntentOpts: { interval: 0, timeout: 0 },
    width: "auto",
    padding: 15,
    spikeLength: 30,
    spikeGirth: 20,
    overlap: -3,
    cornerRadius: 10,
    fill: 'rgba(0, 0, 0, .8)',
    strokeWidth: 3,
    strokeStyle: '#fcac20',	
    cssStyles: {color: '#FFF', fontWeight: 'bold'}
  }); 
	
  // Social share
	$(".socialShare a").click(function(){	    		
		pageTracker._trackPageview('/virtual/socialshareclick/'+$(this).attr('id')+'/'+$(this).attr('href'));		
	});	
});

// Pic Delete
$('.deletePic').live('click',function(){
	var ok = confirm("Biztos törli a képet?");
	if(ok == true){
		$('#operationDiv').load('/operation.php?OP=deletePic&ad_id='+$('#ad_id_current').val()+'&adp_id='+$(this).attr('id'), function(){
			picUploadFormRefresh($('#ad_id_current').val(),$('#disableAttach').val());
		});
	}
	return false;
});
// Pic Upper
$('.upperPic').live('click',function(){	
	$('#operationDiv').load('/operation.php?OP=upperPic&ad_id='+$('#ad_id_current').val()+'&adp_id='+$(this).attr('id'), function(){
		picUploadFormRefresh($('#ad_id_current').val(),$('#disableAttach').val());
	});	
	return false;
});

// Pic Upload Refresh
function picUploadFormRefresh(ad_id,disableAttach){
	$('#uploadPicContainer').load('/uploadpicformelements.php?refresh=1&disableAttach='+disableAttach+'&ad_id='+ad_id, function(){});
}
// JAVA Uploader
$('#jumploaderToggle').live('click',function(){
	var idArray = $(this).val().split('-');
	if($(this).is(':checked') == true){
		$('#jumploaderContainer').load('jumploader/jumploader.php?flush=1&ad_id='+idArray[1]);
		picUploadFormRefresh(idArray[1],1);
	}else{
		$('#operation').attr('src','operation.php?OP=doTurnOffUploader&u_id='+idArray[0]);
		$('#jumploaderContainer').html('');
		picUploadFormRefresh(idArray[1],0);
	}
});

// Slideshow
var slideShowLoaded = 1;
var slideShowActive = 1;
$().ready(function() {
	if($('#adSearchHlContainer').length){
		$().everyTime(8000, 'adHlSlideshow', function() {
				if(slideShowLoaded == 1)
					refreshSearchHl();
		}, 10);		
	} 
});
function stopSearchHl(){
	if(slideShowActive == 1){
		$().stopTime('adHlSlideshow');
		slideShowActive = 0;
	}
}
function refreshSearchHl(){	
	slideShowLoaded = 0;
	$('#adSearchHlSpinner').show();
	$('#adSearchHlContainer').load('/operation.php?OP=doRefreshHl', function(){
		$('#adSearchHlSpinner').hide();
		slideShowLoaded = 1;
	});
}

$('.modalTrigger').live('click',function(){  
	$('.observerLoading').fadeIn('slow');
	$().ready(function() {		
		$('.observerLoading').hide();		
		$('.modalTrigger').click();
	});
	return false;
});

// simpleModal START
$('.simpleModal').live('click',function (e) {
	e.preventDefault();
	var clickElement = $(this);
	$(document).ready(function(){
		// load the contact form using ajax				
		$.get(""+clickElement.attr('href'), function(data){				
			// create a modal dialog with the data
			$(data).modal({				
				close: true,
				overlayClose: true,
				overlayId: 'contact-overlay',
				containerId: 'contact-container',
				position: [100,'25%'],
				containerCss: {					
					width: 750,
					height: 550
				},
				onOpen: simpleModal.open,
				onClose: simpleModal.close
			});
		});
	});
});
$('.simpleModal2').live('click',function (e) {			
	e.preventDefault();
	var clickElement = $(this);
	$(document).ready(function(){
		// load the contact form using ajax		
		$.get(""+clickElement.attr('href'), function(data){				
			// create a modal dialog with the data
			$(data).modal({				
				close: true,
				overlayClose: true,
				overlayId: 'contact-overlay',
				containerId: 'contact-container',				
				position: [100,'35%'],
				containerCss: {					
					width: 425,
					height: 500					
				},
				onOpen: simpleModal.open,
				onClose: simpleModal.close
			});
		});
	});
});
var scrollTopPosition = 0;
var simpleModal = {	
	open: function (dialog) {
		scrollTopPosition = $(window).scrollTop();
		$.scrollTo(80,800); 
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
					
				});
			});
		});
	},
	close: function (dialog){
		$.scrollTo(scrollTopPosition,800);
		$.modal.close();
	}
};
function toggleHlCheckbox(id){
	var value = "";
	var valueHidden = 0;
	var smsID = 0;
	for(i=1;i<=3;i++){
		value = "false";		
		valueHidden = 0;
		if(i == id){
			value = "true";
			valueHidden = i;			
			smsID = i;
		}
		$('#checkboxHl'+i).attr({src:'/pix/v2/icon_check_'+value+'.png'});		
		$('#highlight'+i).val(valueHidden);		
	}
	$('#smsID').html(''+smsID);
	if($('#highlightTypeBox').is(":hidden")){
		$('#closeBox').hide();
		$('#highlightCatBox').slideUp("slow",function(){
			$('#highlightTypeBox').slideDown("slow");
		});				
	}
}
function toggleTCheckbox(id){
	var value = "";
	var valueHidden = "";
	for(i=1;i<=2;i++){
		$('#highlightType'+i+'Box').hide();
		value = "false";
		valueHidden = 0;
		if(i == id){
			value = "true";
			valueHidden = i;
			$('#highlightType'+i+'Box').fadeIn("slow");
		}
		$('#checkboxT'+i).attr({src:'/pix/v2/icon_check_'+value+'.png'});		
		$('#type'+i).val(valueHidden);		
	}	
}
function highlightDone(highlightDate){
	$('#iNev1').val(''); parent.$('#iEmail1').val('');
	$('#iNev2').val(''); parent.$('#iEmail2').val('');
	$('#iNev3').val(''); parent.$('#iEmail3').val('');
	$('#iNev4').val(''); parent.$('#iEmail4').val('');
	$('#highlightDate').html(highlightDate);
    $('#highlightDoneBox').slideDown('slow');
}
function changeHighlight(){
	for(i=1;i<=3;i++){
		$('#checkboxHl'+i).attr({src:'/pix/v2/icon_check_false.png'});		
	}
	for(i=1;i<=2;i++){
		$('#highlightType'+i+'Box').hide();
		$('#checkboxT'+i).attr({src:'/pix/v2/icon_check_false.png'});		
	}
	$('#highlightTypeBox').hide();
	$('#highlightDoneBox').hide();	
	$('#highlightCatBox').slideDown("slow");		
}
// simpleModal END

function replaceStatusSelect(ad_id,value){
	var ddlObj2=$("#status"+ad_id).finalselect({id:"ad_status"+ad_id,idNaked:''+ad_id,selectText:'Státusz',selectWidth:'120px',viewWidth:'140px',zIndex:100,selectImage:'/pix/v2/select.png'});
	ddlObj2.addItem('<img src="/pix/v2/icon_status1.gif"> <span class="thistext">Aktív</span>','1');
	ddlObj2.addItem('<img src="/pix/v2/icon_status0.gif"> <span class="thistext">Inaktív</span>','0');
	ddlObj2.addItem('<img src="/pix/v2/icon_status2.gif"> <span class="thistext">Értékesített</span>','2');
	ddlObj2.addItem('<img src="/pix/v2/icon_status3.gif"> <span class="thistext">Szüneteltetett</span>','3');
	var status = new Array('Inaktív','Aktív','Értékesített','Szüneteltetett');	
	if(status[value])
		ddlObj2.setDefaultItem(value,status[value]);	
}

// remove the registerOverlay call to disable the controlbar
    hs.registerOverlay(
        {
            thumbnailId: null,
            overlayId: 'controlbar',
            position: 'top right',
            hideOnMouseOut: true			
        }
    );

jQuery.fn.fadeToggle = function(speed, easing, callback) {
    return this.animate({opacity: 'toggle'}, speed, easing, callback);
};
function showSearcherLinks(mode){
		$('#szuresLink'+mode).next().fadeSliderToggle({speed:1000, easing : "swing"});		
}

hs.graphicsDir = 'highslide/graphics/';
hs.outlineType = 'rounded-white';
hs.showCredits = false;
hs.lang = {
	loadingText : 'Betöltés...',
	loadingTitle : 'Kattintson ide a betöltés megszakításához!',
	focusTitle : 'Kattintson ide a kép előtérbe helyezéséhez!',
	fullExpandTitle : 'Nagyítás az aktuális méretre',
	creditsText : '',
	creditsTitle : '',
	restoreTitle : 'Kattintson ide a kép bezárásához. Tartsa nyomva az egér bal gomját és húzza az egeret a mozgatáshoz. Használja a nyíl (<- ->) billentyűket az következő és előző képek megtekintéséhez.'
};

function showContactData(u_nev,u_id,ad_id){
  $('.contactLoading').fadeIn('slow');
  $(document).ready(function() {
    $('.contactDataShow').hide();
    $('.contactData').fadeIn('slow');
    $('.contactLoading').hide();
    pageTracker._trackPageview('/virtual/contactclick/'+u_id+'/'+ad_id+'/'+u_nev+'.html');
  });
}

function emailCheck(text) {
  if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(text))
    return (true);
  else
    return (false);
}

function numberOnly() {
        pressedButton=window.event.keyCode;
        if ((pressedButton==46) ||
                (pressedButton==39) ||
                (pressedButton==37) ||
                (pressedButton==9) ||
                (pressedButton==8) ||
                ((pressedButton>=96) && (pressedButton<=105)) ||
                ((pressedButton>=48) && (pressedButton<=57))) return true;
        else return false;
}

function addLocationEnableDisable(){
	if($('#o_id').val() == 1){
		$('#new_megye_link').hide();
		$('#new_tel_link').hide();
	}else{
		$('#new_megye_link').show();
		$('#new_tel_link').show();
	}
}
$('#o_id').ready(function() {
	addLocationEnableDisable();
});
function showHideLocation(type){
  if(type == 1){
    descript2('o_id');
    descript2('new_o_id');
    descript2('o_link');
    descript2('new_o_link');
	
	descript2('megye_id');
	descript2('new_megye_id');
	
	descript2('tel_id');
	descript2('new_tel_id');
	
	if($('#o_id').val() != 1){
		descript2('new_megye_link');
		descript2('new_tel_link');
	}
	
	$('#new_o_id').val('');
  }
  if(type == 2){
    descript2('new_o_link');

    descript2('megye_id');
    descript2('new_megye_id');
    descript2('megye_link');
    descript2('new_megye_link');

    descript2('tel_id');
    descript2('new_tel_id');
    descript2('new_tel_link');
	
	$('#new_megye_id').val('');
  }
  if(type == 3){
    descript2('new_o_link');

    descript2('new_megye_link');

    descript2('tel_id');
    descript2('new_tel_id');
    descript2('tel_link');
    descript2('new_tel_link');
	
	$('#new_tel_id').val('');
  }
}

function descript(id)
        {
        ne = document.getElementById(id);
        if(ne.style.display == 'none')
                {
                ne.style.display = 'block';				
                }
        else
                {
                ne.style.display = 'none';				
                }
        }
function descript2(id)
        {
        ne = document.getElementById(id);
        if(ne.style.display == 'none')
                {
                ne.style.display = 'inline';
                }
        else
                {
                ne.style.display = 'none';
                }
        }

function display(id)
        {
        var lang = new Array();
        lang[0] = "Hu";
        lang[1] = "En";
        lang[2] = "De";
        lang[3] = "Ro";

        for(i=0;i<=lang.length-1;i++)
                {
                ne = document.getElementById("text"+lang[i]);
                n2 = document.getElementById("button"+lang[i]);

                if(id == lang[i])
                        {
                        ne.style.display = 'block';
                        n2.style.backgroundColor = '#EEEEEE';
                        }
                else
                        {
                        ne.style.display = 'none';
                        n2.style.backgroundColor = '#FFFFFF';
                        }
                }
        return false;
        }

function formaz(szam) {
                                sz='';
                                for (i=0;i<szam.value.length;i++) {
                                        if (szam.value.charAt(i)!=' ') { sz+=szam.value.charAt(i); }
                                }
                                sz2='';
                                j=0;
                                for (i=sz.length;i>0;i--) {
                                        sz2=sz.charAt(i-1)+sz2;
                                        if (j==2 && i>1) {
                                        sz2=' '+sz2;
                                        j=-1;
                                        }
                                j++;
                                }
                                szam.value=sz2;
                                }
