
function getDateClient(para) {
	var d = new Date();
	var y = parseInt(d.getYear());
	y %= 100;
	if (y < 10) y = "0" + y;
	if (para == "en") {
		var weekday 	= ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
		var monthday 	= ['January','February','March','April','May','June','July','August','September','October','November','December'];
		document.getElementById("spnDate").innerHTML = "<b>" + weekday[d.getDay()] + "</b>,&nbsp;" + monthday[d.getMonth()] + "&nbsp;" + d.getDate() + ",&nbsp;" + "20" + y;
	} else {
		var weekday 	= ['Ch&#7911; nh&#7853;t','Th&#7913; hai','Th&#7913; ba','Th&#7913; t&#432;','Th&#7913; n&#259;m','Th&#7913; s&aacute;u','Th&#7913; b&#7843;y'];
		var monthday 	= ['01','02','03','04','05','06','07','08','09','10','11','12'];
		document.getElementById("spnDate").innerHTML = "<b>" + weekday[d.getDay()] + "</b>,&nbsp;ng&agrave;y&nbsp;" + d.getDate() + "/"  + monthday[d.getMonth()] + "/" + "20" + y;
	}
}

function showImage(url) {
	var img = new Image();
	img.src = url;
	w = img.width;
	h = img.height;
	t=(screen.availHeight - h)/2;
	l=(screen.availWidth - w)/2;
	window.open(url,"","width=" + (w + 20)+ "px,height=" + (h + 20)+ ",top=" + t +"px,left=" + l + "px,resizable=0,status=0,scrollbars=yes");
}
function is_email(email)
{	
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email))	
		return false;
	else
		return true;	
}

function CompDate(strDate1,strDate2){
		var m1, d1, y1;
		var m2, d2, y2;
		var s, pos1, pos2;
		var s = strDate1, s1 = strDate2;
		if (s.length == 0 || s1.length == 0) return true;

		pos1 = s.indexOf("/",0);
		pos2 = s.indexOf("/",pos1+1);
		m1 = parseInt(s.substr(0,pos1),10);
		d1 = parseInt(s.substr(pos1+1,pos2-pos1-1),10);
		y1 = parseInt(s.substr(pos2+1,s.length-pos2),10);
		
		pos1 = s1.indexOf("/",0);
		pos2 = s1.indexOf("/",pos1+1);
		m2 = parseInt(s1.substr(0,pos1),10);
		d2 = parseInt(s1.substr(pos1+1,pos2-pos1-1),10);
		y2 = parseInt(s1.substr(pos2+1,s1.length-pos2),10);
		
		var d1 = new Date(y1,m1,d1);
		var d2 = new Date(y2,m2,d2);
		if (d1 > d2 || d1 == d2) 
			return true;
		else
			return false;
}
function download(id,tbl){
	window.open("download.php?id="+id+"&tbl="+tbl);
}
function isNumber(textNum)
{
	var re = /^[0-9]{1,5}$/;	
	sNum = document.getElementById(textNum).value;
	if (!re.test(sNum) ){
		alert("Vui long nhap vao kieu so !");		
		$("#"+textNum).focus();
		return false;
	}
}
function text_num(id){
	var re = /^[0-9]{1,2}$/;	
	sNum = document.getElementById(id).value;
	if (!re.test(sNum) ){			
		$("#"+id).val("0");
		return false;
	}
}
function dl(type){
		window.open("download.php?type="+type);
}
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){		
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){		
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){		
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){		
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){		
		return false
	}
return true
}

function show_image(img){
	$('#img_banner').attr('src',img);
}
