/* JavaScript Document*/
(function(jQuery) {
	jQuery.fn.clickoutside = function(callback) {
		var outside = 1, self = $(this);
		self.cb = callback;
		this.click(function() { 
			outside = 0; 
		}); 
		$(document).click(function(event){
			if(event.button == 0)
			{
				outside && self.cb();
				outside = 1;
			}
		});
		return $(this);
	}
})(jQuery);


$(function(){
			   
    $('textarea').each(function(){
        $(this).val($(this).context.defaultValue);
    });
	
    $('textarea').focus(function(){
        $(this).css('color', '#333');
    }).blur(function(){
        if ($(this).val() == $(this).context.defaultValue){
            $(this).css('color', '#838383');
        }
    });
	
    $('textarea').focus(function(){
        $(this).addClass('sffocus');
    }).blur(function(){
        $(this).removeClass('sffocus');
    });
	
    $('.highlight-border textarea.general').focus(function(){
        $(this).addClass('sffocus');
    }).blur(function(){
        $(this).removeClass('sffocus');
    });
	
    $('input:text').focus(function(){
        $(this).css('color', '#333');
    }).blur(function(){
        if ($(this).val() == $(this).context.defaultValue){
            $(this).css('color', '#838383');
        }
    });
	
    $('input:password').focus(function(){
        $(this).css('color', '#333');
    }).blur(function(){
        if ($(this).val() == $(this).context.defaultValue){
            $(this).css('color', '#838383');
        }
    });
	
    $('input:text').focus(function(){
        $(this).addClass('sffocus');
    }).blur(function(){
        $(this).removeClass('sffocus');
    });
	
    $('input:password').focus(function(){
        $(this).addClass('sffocus');
    }).blur(function(){
        $(this).removeClass('sffocus');
    });
	
    $('.search input.search-field').focus(function(){
        $(this).addClass('sffocus');
    }).blur(function(){
        $(this).removeClass('sffocus');
    });
		   
    $('#top_page .mynaviga li.tk a').click(function(){
        $(this).next().slideToggle(0, function(){
            if($(this).is(':hidden'))
            {
                $(this).prev().removeClass('active');
            }
            else
            {
                $(this).prev().addClass('active');
            }
	   
        });
	  
    })
    jQuery('#top_page .mynaviga li.tk a').clickoutside(function(){
        if($(this).next().css('display') == 'block'){
            $(this).removeClass('active');
            $(this).next().hide();
        }
    })
	
    $(window).resize(function(){
        if ($.browser.msie && $.browser.version.substr(0,1)<7){
            var root = document.documentElement;
            if(root.scrollWidth < 980){
                $('#ionetaskbar').css({
                    'bottom':'17px'
                });
            }
            else
            {
                $('#ionetaskbar').css({
                    'bottom':'0'
                });
            }
        }
    })
	
    $(".title").hover(function(){
        $(this).addClass("title-hover");
    },function(){
        $(this).removeClass("title-hover");
    })
})
/*Function to show tooltip*/

/**
** ham cat bo ky tu dac biet
**/
function StripSpecialChar(str, bool)
{
    str = str.replace(/<\?php/g, '');
    str = str.replace(/<\?/g, '');
    str = str.replace(/\?>/g, '');
	
    str = str.replace(/<script>/g, '');
    str = str.replace(/<script/g, '');
    str = str.replace(/<\/script>/g, '');
	
    if ( bool == 1 )
    {
        str = str.replace(/([\`\~\!\#\$\%\^\&\*\(\)\{\}\,\?\:\;\/\\\[\]\+\=\|\<\>\'\"])/gi, "");
    }
    else
    {
        str = str.replace(/([\`\~\!\@\#\$\%\^\&\*\(\)\{\}\.\,\?\:\;\/\\\[\]\-\_\+\=\|\<\>\'\"])/gi, "");
        str = $.trim(str);
    }
	
    return str;
}

function validWebsite(website) {
    website = $.trim(website);
    if(website.indexOf(' ') > 0){
        return false;
    }
	 
    if ( website.indexOf('http://') >= 0 ) {
        if(website.lastIndexOf('://') > 4){
            return false;
        }
    }
	
    if ( website.indexOf('https://') >= 0 ) {
        if(website.lastIndexOf('://') > 5){
            return false;
        }
    }
	
    if(website.indexOf('http://') == -1 && website.indexOf('https://') == -1) {
        website = 'http://' + website;
    }
	 
    var e = /(http|https):\/\/[\w{0,][A-Za-z0-9\.-]{3,}\.[A-Za-z]{2,}[\/\?]{0,}/;
    if(website.match(e) == null){
        return false;
    }

    return true;
}

function sendEmailActiveCode(userid) {
    
    $.ajax({
        type:'POST',
        url: domain+'/system/register/sendemailactivecode',
        data:({
            userid: userid
        }),
        dataType:'json',
        success:function(response){
            if (!response.error) {
                $("#inform #inform-main").html('Yêu cầu kích hoạt tài khoản đã được gửi về email của bạn. Nếu không thấy, bạn hãy kiểm tra mục thư rác.');
            }
        }
    });
}

function strip_tags (input, allowed) {
    allowed = (((allowed || "") + "")
        .toLowerCase()
        .match(/<[a-z][a-z0-9]*>/g) || [])
    .join('');
    var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
    commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
    return input.replace(commentsAndPhpTags, '').replace(tags, function($0, $1){
        return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
    });
}
<!--view more top menu-->
$('#hasmore').toggle(
	function(){
		$('#subtop').slideDown(300);
		$(this).addClass('over');
		$(this).parent().addClass('start');
	},
	function(){
		$('#subtop').slideUp(300);
		$(this).removeClass('over');
		$(this).parent().removeClass('start');
	}
);
