function getObject( Id )
{
    if ( document.getElementById )	return document.getElementById( Id );
    else if ( document.layers )	 return document.layers( Id );
    else if ( document.all )	 return document.all[ Id ];
    return false;
}

function setSelect(id,value){
	var i=0,end;
					    
	end = getObject(id).length;
	for (i;i<end;i++){	
	    if (getObject(id).options[i].value == value)
	    	getObject(id).selectedIndex=i;		    	
	}	
}

function copyFields(fromArray,toArray){
    for ( var i in fromArray ){
    	if (fromArray[i] == 'szam_megye' || fromArray[i] == 'szall_megye')
    		setSelect(toArray[i],getObject(fromArray[i]).value);
    	else
        	getObject(toArray[i]).value = getObject(fromArray[i]).value;
        //getObject(toArray[i]).style.backgroundColor='#eeeeee';
        //getObject('reg_form').toArray[i].disabled = true;
    }
}

function eraseFields(arr){
    for ( var i in arr ){
    	if (arr[i] == 'szam_megye' || arr[i] == 'szall_megye')
    		getObject(arr[i]).value.selectedIndex = 0;
    	else
        	getObject(arr[i]).value = "";
        //getObject(arr[i]).style.backgroundColor='#ffffff';
        //getObject('reg_form').arr[i].disabled = false;
    }
}







function doAjax(postData,inner,loading){
	$.ajax({
		type: "POST",
	   url: "ajax.php",
	   dataType: "json",
	   data: postData,
	   beforeSend: function(){
	   	   if (loading) $('#'+inner).html('<img alt="Loading" src="images/loading.gif" />');
	   	   else $('#'+inner).animate({opacity:0.9},500);
	   },
	   success: function(rData){
		   $('#'+inner).animate({opacity:1},500);
		   $('#'+inner).html(rData.output);		  
	   }
	 });
}


function ajax_vote(data,kid){
	$.ajax({
		   type: "POST",
		   url: "ajax.php",
		   dataType: "json",
		   data: data,
		   beforeSend: function(){
		   	   //$('#voteinner_'+kid).html('<img alt="Loading" src="images/loading.gif" />');
		   },
		   success: function(rData){
			   $('#voteinner_'+kid).html(rData.output);
			   setTimeout(function() {
			        $('#vote_status_'+kid).fadeOut('slow',void(0))
			   }, 3000);
		   }
		 });
}

/*

function setNotifierPos(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	$('#notifier_inner').css('top',windowHeight/2-$('#notifier_inner').height()/2+document.documentElement.scrollTop);
	$('#notifier_inner').css('left',windowWidth/2-$('#notifier_inner').width()/2); 
}
*/




function notify(html,posId){
	var windowWidth = document.documentElement.clientWidth;
	/*var windowHeight = document.documentElement.clientHeight;*/
	var _top = $('#'+posId).offset().top;
	var randomnumber=Math.floor(Math.random()*101)
	$('body').append('<div class="notifier_inner" id="notifier_'+posId+randomnumber+'">'+html+'</div>');
	
	$('#notifier_'+posId+randomnumber).css('top',_top-100);
	$('#notifier_'+posId+randomnumber).css('left',windowWidth/2-$('#notifier_'+posId+randomnumber).width()/2);
	
	$('#notifier_'+posId+randomnumber).fadeIn('slow',void(0));			   
	setTimeout(function() {
		//$('#notifier_'+posId).fadeOut('slow',void(0))
		$('#notifier_'+posId+randomnumber).remove();
	}, 3000);
	
}





function tooltipAlert(text,formElement){
	var pos = formElement.offset();
	var posParent = formElement.parent().offset();
	var element = $('<div class="tooltipAlert">'+text+'</div>').css('top',pos.top - posParent.top).css('left',pos.left - posParent.left +120);	
	element.appendTo(formElement.parent());
	element.fadeIn('slow',void(0));
	setTimeout(function(){
		element.fadeOut('slow',void(0));
	},3000);
}


function highlightInput(element,utotag){
	if (!utotag) utotag = "";
	element.hide();
	element.addClass('highlighted'+utotag);
	element.fadeIn('slow',void(0));
}

function removeInputHighlight(element,utotag){
	if (!utotag) utotag = "";
	element.removeClass('highlighted'+utotag);		
}





function hirlevelFeliratkozas(emailMezoId){
	$.ajax({
		   type: "POST",
		   url: "ajax.php",
		   dataType: "json",
		   data: "hirlevelFeliratkozas=1&email="+$('#'+emailMezoId).val(),
		   beforeSend: function(){				
		   	    //$('#'+inner).html('<img alt="Loading" src="images/loading.gif" />');
		   },
		   success: function(rData){
			   $('#'+emailMezoId).val('');
			   notify(rData.notify,emailMezoId);
		   }
		 });	
}

function hirlevelLeiratkozas(emailMezoId){
	$.ajax({
		   type: "POST",
		   url: "ajax.php",
		   dataType: "json",
		   data: "hirlevelLeiratkozas=1&email="+$('#'+emailMezoId).val(),
		   beforeSend: function(){				
		   	    //$('#'+inner).html('<img alt="Loading" src="images/loading.gif" />');
		   },
		   success: function(rData){
			   $('#'+emailMezoId).val('');
			   notify(rData.notify,emailMezoId);				
		   }
		 });	
}


function fadeLogin(){
	if ($('#loginDiv').css('display') == 'none')
		$('#loginDiv').fadeIn('slow',void(0));
	else
		$('#loginDiv').fadeOut('slow',void(0));
}



function number_format (number, decimals, dec_point, thousands_sep) {
    // Formats a number with grouped thousands  
    // 
    // version: 1109.2015
    // discuss at: http://phpjs.org/functions/number_format
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // +    revised by: Luke Smith (http://lucassmith.name)
    // +     bugfix by: Diogo Resende
    // +     bugfix by: Rival
    // +      input by: Kheang Hok Chin (http://www.distantia.ca/)
    // +   improved by: davook
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Jay Klehr
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Amir Habibi (http://www.residence-mixte.com/)
    // +     bugfix by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Theriault
    // +      input by: Amirouche
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');
    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'
    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);
    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');
    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'
    // *    example 10: number_format('1.20', 2);
    // *    returns 10: '1.20'
    // *    example 11: number_format('1.20', 4);
    // *    returns 11: '1.2000'
    // *    example 12: number_format('1.2000', 3);
    // *    returns 12: '1.200'
    // *    example 13: number_format('1 000,50', 2, '.', ' ');
    // *    returns 13: '100 050.00'
    // Strip all characters but numerical ones.
    number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
    var n = !isFinite(+number) ? 0 : +number,
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    return s.join(dec);
}




function refreshKwLeFields(kw){
	$('#kw_field').val( number_format(kw,2,'.','') );
	$('#le_field').val( number_format(kw*1.36,2,'.','') );
}


function checkElerhetoseg(){
	if ( $('#email_field').val() == '' && $('#tel_field').val() == '' ){
		alert('Kérjük, adja meg valamelyik elérhetőségét!');
		return false;
	}
		
	return true;
}


/*

var letters = new Array('Y','O','U',' ','N','E','E','D',' ','I','T',',',' ','W','E',' ','H','A','V','E',' ','I','T');
var maxLength = letters.length;					
var letters_i = 0;
					
function writeSlogen(letter){
	$('#letterHolder').append(letters[letters_i]);	
	letters_i++;
	setTimeout(function(){
		if (letters_i<maxLength) writeSlogen(letters[letters_i]);
		else letters_i = 0;
	},100);
}
*/




