// JavaScript Document


/*
 * START TIMER
© Live time, Date ( http://www.clubmiennam.com )
PHUOCMASTER Script
*/


var dayarray=new Array("Chủ nhật","Thứ hai","Thứ ba","Thứ tư","Thứ năm","Thứ sáu","Thứ bảy")
var montharray=new Array("tháng 1","tháng 2","tháng 3","tháng 4","tháng 5","tháng 6","tháng 7","tháng 8","tháng 9","tháng 10","tháng 11","tháng 12")

var getthedate = function(){
    var mydate=new Date()
    var year=mydate.getYear()
    if (year < 1000)    year+=1900

    var day=mydate.getDay()
    var month=mydate.getMonth()
    var daym=mydate.getDate()
    if (daym<10)    daym="0"+daym

    var hours=mydate.getHours()
    var minutes=mydate.getMinutes()
    var seconds=mydate.getSeconds()
    var dn="AM"
    if (hours>=12)  dn="PM"
    if (hours>12)   hours=hours-12
    if (hours==0)   hours=12
    if (minutes<=9) minutes="0"+minutes
    if (seconds<=9) seconds="0"+seconds
    //change font size here
    var cdate="<font color='#fedd01'>"+dayarray[day]+",</font> ngày "+daym+" "+montharray[month]+" năm "+year+"<b> "+hours+":"+minutes+":"+seconds+" "+dn+"</b>"

    if (document.all) document.all.clock.innerHTML=cdate
    else if (document.getElementById)
        document.getElementById("clock").innerHTML=cdate
    else document.write(cdate)
}



function goforit(){
    if (document.all||document.getElementById)
    setInterval("getthedate()",1000)
}
$(document).ready(function(){
   getthedate();
   goforit();
})

/**
 * END TIMER
 */




var isset=function(value){
    if(typeof value=="undefined" || value==null){
        return false
    }
    return true;
}

function open_window(link,w,h)
{
        var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes";
        newWin = window.open(link,'newWin',win);
}

function position_this_window(width, height)
{
    if(typeof(width)=='undefined' || width==null) width=795;
    var x = (screen.availWidth - width) / 2;
    window.resizeTo(width, screen.availHeight - height);
    window.moveTo(Math.floor(x),25);
}

var loadingButton = function(container){
    if(typeof container=="undefined" || container==null) container='icon_button';
    $('#' + container).attr('src','/static/images/web/loading.gif');
    
}

var closeSupport=function(){
    $('#supportContent').html('');
    $('#loadSupport').hide();
    $('a.closeChatWindow').hide();
}

var showCloseButton=function(){
    $('a.closeChatWindow').show();
}

var openSupport=function(nickname){
    closeSupport();
    var chatWindow='<object id="pingboxdat33vqz2xgŗ0" type="application/x-shockwave-flash" data="http://wgweb.msg.yahoo.com/badge/Pingbox.swf" width="340" height="420"><param name="movie" value="http://wgweb.msg.yahoo.com/badge/Pingbox.swf" /><param name="allowScriptAccess" value="always" /><param name="flashvars" value="wid=jTjpvBe2SmHRU_zH6KZTiIKdxymQTa8-" /><param name="wmode" value="transparent" /></object>';
    if(nickname=="thuydinh76"){
        chatWindow='<object id="pingboxefl9ap7nlmg0?" type="application/x-shockwave-flash" data="http://wgweb.msg.yahoo.com/badge/Pingbox.swf" width="340" height="420"><param name="movie" value="http://wgweb.msg.yahoo.com/badge/Pingbox.swf" /><param name="allowScriptAccess" value="always" /><param name="flashvars" value="wid=AYsxqF.vS3dx5ypzddsEGu1LWuw-" /><param name="wmode" value="transparent" /></object>';
    }
    $('#loadSupport').center();
    $('#supportContent').html(chatWindow);
    setTimeout('showCloseButton()',2500);
}

var gotoPage=function(url){
	window.location=url;
}

var setCurrent=function(idObj, idContent){
    $('#'+idObj+' option[value='+idContent+']').attr('selected',true);
}

var gotoPageAjax=function(url, divContainer){
	if(typeof divContainer=="undefined" || divContainer==null ) divContainer='Container';
	$('#'+divContainer).load(url);
}
var rand="";

var dataInvalid=function(self, errorText, showAlert, val, parentTrack, errImage, style){
	if(typeof errImage=="undefined" || errImage==null ) errImage='<img src="/static/images/web/attention.png">';
	
	errImage=errImage + '&nbsp;';
	if(parentTrack==null || typeof parentTrack=="undefined") parentTrack='div[class=formElement]';
	if(showAlert==null || typeof showAlert=="undefined") showAlert=false;
	if(showAlert){
		alert(errorText)
		self.select();
		//self.focus();
	}
	if(val!=null && typeof val!="undefined") {
		if(self.attr('type')!='radio' || val!=0)
			self.val(val);
	}
	$('div[class=instruction]').hide();
	var dataChecker=callDataChecker(self, parentTrack);
	dataChecker.html(errImage+errorText);
	if(typeof style!="undefined" && style!=null ) {
		//alert('height:'+height+'px')
		dataChecker.attr('style', style);
	}
	dataChecker.fadeIn('slow');
}

var hasSpecialChars=function(orgString){
	if (orgString.match("^[a-z0-9'\s]{1,50}$")) {
	   return 0;
	}	
	return 1;
}

var outlineEffect=function(self){
	var formElement=self.parents('div[class=formElement]');
	$('div[class=input focus]').removeClass('focus');
	$('div[class=instruction]').hide();
	formElement.find('div[class=input]').addClass('focus');
	if(formElement.find('div[class=instruction]').html()!=""){
		formElement.find('div[class=instruction]').fadeIn('slow');
		formElement.find('div[class=dataChecker]').hide();
	}
}

var callDataChecker=function(self, parentTrack){
	return self.parents(parentTrack).find('div[class=dataChecker]');
}


var isValidEmail=function(email){
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(email);
}

var checkValid=function(self, url, errorText, data, parentTrack, errImage){
	if(errImage==null || typeof errImage=="undefined") errImage='<img src="/static/images/web/attention.png"> &nbsp; ';
	if(parentTrack==null || typeof parentTrack=="undefined") parentTrack='div[class=formElement]';
	var inputValue=self.val();
	if(inputValue!='') {
		$('div[class=instruction]').hide();
		callDataChecker(self, parentTrack).show();
		callDataChecker(self, parentTrack).html("<img src='/static/images/web/loading.gif'>");
		
		callDataChecker(self, parentTrack).load(url, data,
			function(respondText){
				
				if(respondText==1){
					callDataChecker(self, parentTrack).html("<img src='/static/images/web/tick.png'>");
					
				}else if(typeof errorText[respondText]=='undefined'){
						callDataChecker(self, parentTrack).html('');
				}else{
					callDataChecker(self, parentTrack).html(errImage+errorText[respondText]);
				}
		});
	}else{
		callDataChecker(self, parentTrack).html('');
		callDataChecker(self, parentTrack).hide();
	}	
}

var showValidateImage=function(len){
	if(len==null || typeof len=="undefined") len=4;
	var url="/user/libs/randomstring/";
	$('#validateContainer').html("<img src='/static/images/web/loading.gif' style='padding-top:21px'>");
	$('#validateContainer').load(url,'',function(response){
		rand=response;
		$(this).html('<img src="/ValidateImage.php?v='+rand+'&length='+len+'">');
	});	
}

jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("display","block");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() - 70 + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}


jQuery.fn.progress = function () {
    this.css("position","absolute");
    this.css("display","block");
    this.css("background","url(/static/images/web/page_loading.gif) no-repeat");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}


jQuery.fn.offProgress = function () {
    this.css("display","none");
    this.css("background","");
    return this;
}

var loadFocus=function(){
	$('input, select, textarea').focus(function(){	
		outlineEffect($(this));							  
	})

	$('button').focus(function(){	
		outlineEffect($(this));							  
	})
	
	$('#validateContainer').click(function(){
		showValidateImage();
		return false;
	})
}

var loadMarquee=function(){

        $('div.message marquee').marquee('pointer').mouseover(function () {
            $(this).trigger('stop');
        }).mouseout(function () {
            $(this).trigger('start');
        }).mousemove(function (event) {
            if ($(this).data('drag') == true) {
                this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
            }
        }).mousedown(function (event) {
            $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
        }).mouseup(function () {
            $(this).data('drag', false);
        });
}

$(document).ready(function(){

	loadFocus();
        loadMarquee();
	$('div[class=instruction]').unbind('click');
	

 })


