/***********************************************
Preloader
************************************************/
$(document).ready(function(){
	$('#preloader').delay(350).fadeOut('slow'); 
	$('body').delay(350).css({'overflow-y':'visible'});
})
/***********************************************
// Force page to scroll to anchor (-40px)
************************************************/
$(document).ready(function() {
	setTimeout(function() {
		if(window.location.hash) {		
           var scrollPosition = $(window.location.hash).offset().top - 40;
            $('html, body').scrollTop(scrollPosition);
		}
	}, 100);
});

/***********************************************
Set top video / slider height
************************************************/
/*
function setMovieHeight(){
	newHeight=$('#video_top').width()/3.5;
	$('#video_top').css('height',newHeight);
}
$(document).ready(function(){setMovieHeight() });
$(window).on('resize', function(){ setMovieHeight() });
*/

/***********************************************
Tooltip
***********************************************

$(document).ready(function(){
    $('[data-toggle="tooltip"]').tooltip(); 
});

/***********************************************
	Scroll to top
************************************************/
$(document).ready(function(){
	$(window).scroll(function(){
		if ($(this).scrollTop() > 100) {
			if($(this).width()>975){ // hide sm
				$('#scrollToTop').fadeIn();
			}
		} else {
			$('#scrollToTop').fadeOut();
		}
	});

	$('#scrollToTop').click(function(){
		$('html, body').animate({scrollTop : 0},800);
		return false;
	});
});

/***********************************************
	Smooth scroll
************************************************/
var scroll = new SmoothScroll('a[href*="#"]', {
	speed: 500,
	speedAsDuration: true
});



/***********************************************
Send AJAX request to div
************************************************/
function sendToDiv(targetDiv,params,specialPhp) {
	//console.log(params);
	$("#"+targetDiv).html('<div class="loading"></div>');
	
	if(specialPhp)
		php = specialPhp;
	else
		php = targetDiv;

	var requestMain = $.ajax({
		async: true,
		cache:true,
		url: "content/"+php+".php",
		type: "POST",
		data: {sub:window.currensSub,params}
	});
	
	requestMain.done(function(msg) {
		$("#"+targetDiv).html(msg);
	}); 
};

/***********************************************
Show/Hide modal 
************************************************/
function showModal(modal,noScroll=null){
	$('#modal_dim').show();
	$('#'+modal).show();

	if(noScroll)
			$('html').css('overflow-y', 'hidden'); 
};

function hideModal(modal){ 
	$('html').css('overflow-y', 'auto');
	$('#'+modal).hide();
	$('#modal_dim').hide();
};


/***********************************************
Print Div
************************************************/
function printDiv(div,header)
{
    var mywindow = window.open('', 'PRINT', 'height=800,width=1024');

    mywindow.document.write('<html><head><title>' + header  + '</title>');
    mywindow.document.write('</head><body >');
    //mywindow.document.write('<h5>' + header  + '</h5>');
    mywindow.document.write($("#print").html());
    mywindow.document.write('</body></html>');

    mywindow.document.close(); // necessary for IE >= 10
    mywindow.focus(); // necessary for IE >= 10*/

    mywindow.print();
    mywindow.close();

    return true;
}


/***********************************************
CountDown timer (duration in seconds)
************************************************/
function startTimer(duration) {
    var timer = duration, minutes, seconds;
    window.timeinterval = setInterval(function () {
        minutes = parseInt(timer / 60, 10);
        seconds = parseInt(timer % 60, 10);

        minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;

        $("#timer").html(minutes + ":" + seconds);

        if (--timer < 0) {
			clearInterval(window.timeinterval);

        }
    }, 1000);
}

/***********************************************
check e-mail
************************************************/
function checkEmail(mail){
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail))
		return (true);
	else
	return (false);
}

/***********************************************
check phone
************************************************/
function checkPhone(phone)
{
	if (/^(\+{0,})(\d{0,})([(]{1}\d{1,3}[)]{0,}){0,}(\s?\d+|\+\d{2,3}\s{1}\d+|\d+){1}[\s|-]?\d+([\s|-]?\d+){1,2}(\s){0,}$/gm.test(phone))
		return true;
	else
		return false;
}