/**
 * @author Andrius Jukna <endris.j[at]gmail.com>
 * @license: feel free to use it, but keep this credits!	
 */

var patternNumber		= /^([0-9])+$/;
var patternPhone		= /^\+?([0-9\-\s])+$/;
var patternPhoneE		= /^\+?([0-9\-\s])*$/;
var patternPhoneStrong	= /^\+([0-9]{11})+$/;
var patternName			= /^([a-zA-ZąĄčČęĘėĖįĮšŠųŲūŪžŽ_\.\-\s])+$/;
var patternNameE		= /^([a-zA-ZąĄčČęĘėĖįĮšŠųŲūŪžŽ_\.\-\s])*$/;
var patternUsername		= /^.+$/;
var patternEmail 		= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var patternEmailE		= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})*$/;
var patternPassword	= /^.+$/;


$(document).ready(function() {	
	if(typeof markErrors == 'function') markErrors();
	if(typeof callThenLoaded_Login == 'function') callThenLoaded_Login();
	if(typeof callThenLoaded_ClosedZoneMenu == 'function') callThenLoaded_ClosedZoneMenu();
	if(typeof callThenLoaded_CtrlSpecific == 'function') callThenLoaded_CtrlSpecific();
	
	$('.btnCircle').bind('mouseover', function(){
	   $(this).attr('src', btnCircleSelUrl);
	});
	$('.btnCircle').bind('mouseout', function(){
	   $(this).attr('src', btnCircleUrl);
	});
});

function checkElement(id, pattern) {
	var item = $('#'+id);
	item.removeClass('error');
	if(!isValidByPattern(item.val(), pattern)) {
        item.focus();
        item.addClass('error');
        return false;
    }
    return true;
}

function isValidByPattern(value, pattern) {
    value = value.replace(/^\s+/, '');
    value = value.replace(/\s+$/, '');
    if(pattern.test(value))
        return true;
    return false;
}
function isNotEmpty(value) {
    value = value.replace(/^\s+/, '');
    value = value.replace(/\s+$/, '');
    if(value && value != "undefined")
        return true;
    return false;
}

function removeBlock(id, preview_id) {
    $('#'+id).remove();
    $('#'+preview_id).remove();
    return false;
};

function inc(filename)
{
	var head = document.getElementsByTagName('head').item(0);
	script = document.createElement('script');
	script.src = filename;
	script.type = 'text/javascript';
	head.appendChild(script)
}


/* CHAT POPUP */
function createPopup(url, window_name, height, width) {
	window.open(
            url,
            window_name,
            'channelmode=no,directories=no,fullscreen=no,height='+height+',left=100,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=yes,toolbar=no,top=50,width='+width
        );
    
    
    return false;
}
/* END. chat popup */

/* SMOOTH SCROLL */

jQuery.fn.extend({
  scrollTo : function(speed, easing, leaveSpace) {
    return this.each(function() {
      var targetOffset = $(this).offset().top - leaveSpace;
      $('html,body').animate({scrollTop: targetOffset}, speed, easing);
    });
  }
});
/* END. smooth scroll */
