
var gizmo;
 
var day = new Array("Sun", "Mon",	"Tue", "Wed", "Thu",	"Fri",	"Sat");
var mon = new Array("December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November");
var de = new Array("st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th", "st");

function stopClock(){
  clearTimeout(gizmo);
}
 
function yourClock(){
  var nd = new Date();
  var h, m;
  var s;
  var time = " ";
  h = nd.getHours();
  m = nd.getMinutes();
  s = nd.getSeconds();
	dn = day[nd.getDay()];
	d = nd.getDate();
	deo = nd.getDate();
	d = (d < 10)?"0"+d:d;
	mo = mon[nd.getMonth()];
	y = nd.getFullYear();
  if (h <= 9) h = "0" + h;
  if (m <= 9) m = "0" + m;
  if (s <= 9) s = "0" + s;
	var don="AM"
	if (h>=12){don = "PM"}
	if (h>12){h -= 12}
  time += h + ":" + m + ":" + s + " " + don+ " | " + dn + ", " + mo + " " + d + "<SUP>" + de[deo] + "</SUP>" + ", " + y; 
  document.getElementById("dateTime").innerHTML = time;
  gizmo = setTimeout("yourClock()", 1000);
}

function ShowDiv(i,s, name){
	for(j=1;j<=s;j++){
		if(j==i){
			if(document.getElementById(name+i).style.display=="")
				document.getElementById(name+i).style.display="none";
			else
				document.getElementById(name+i).style.display="";			
		}else{
			document.getElementById(name+j).style.display="none";
		}
	}
}

function ShowDiv2(i,s, name){
	for(j=1;j<=s;j++){
		if(j==i){
			if(document.getElementById(name+i).style.display=="")
				document.getElementById(name+i).style.display="none";
			else
				document.getElementById(name+j).style.display="";			
		}else{
			document.getElementById(name+j).style.display="none";
		}
	}
	
}

function ShowAnswer(i,s){
	for(j=1;j<=s;j++){
		if(j==i){
			if(document.getElementById("row"+i).style.display=="")
				document.getElementById("row"+i).style.display="none";
			else
				document.getElementById("row"+i).style.display="";			
		}else{
			document.getElementById("row"+j).style.display="none";
		}
	}
}

function upImg(qStr)
{
	width=500;
	height=250;
	//----------------------------------
	Url="/upload/upload.php"+qStr;
	//----------------------------------
	window.open(Url,"","toolbar=no,scrollbar=no,status=no,resizable=no,width=" + width + ",height=" + height + ",top="
							+ ((window.screen.availHeight - height)/2) +",left=" + ((window.screen.availWidth - width)/2));
}

function openURL(strURL, w, h)
{
	width=w;
	height=h;
	window.open(strURL,"","toolbar=no,scrollbar=no,status=no,resizable=no,width=" + width + ",height=" + height + ",top="
							+ ((window.screen.availHeight - height)/2) +",left=" + ((window.screen.availWidth - width)/2));
}

function openWindowWithScroll(f, w ,h)
{
	width=w;
	height=h;
	//----------------------------------
	Url=f;	
	//----------------------------------
	window.open(Url,"","toolbar=no,scrollbars=yes,status=yes,resizable=no ,width=" + width + ",height=" + height + ",top="
							+ ((window.screen.availHeight - height)/2) +",left=" + ((window.screen.availWidth - width)/2));
}

function showPreview()

{
if (document.all.txtHinhAnh.value != "")
	document.all.PREVIEWPIC.src=document.all.txtHinhAnh.value ;

else
	document.all.PREVIEWPIC.src='/images/preview.jpg';
}

function enableIt(){
	var obj = document.getElementById("cmdsurvey");
	if(obj.disabled == true){
		obj.disabled = false;
		obj.className = "cmdSelect";
	}
}

function goNow(){
	var str;
	str = document.getElementById("fastLink").value;
	if(str.length > 0){
		window.open(str);
	}
}

var h, w;

function getImgSize(imgSrc)
{
var newImg = new Image();
newImg.src = imgSrc;
h = newImg.height;
w = newImg.width;
}

function openPic(sPicURL){
	getImgSize(sPicURL);
	//alert(h + "---" + w);
	window.open("/realImage.htm?"+sPicURL+"", "", "toolbar=no,scrollbar=no,status=no,resizable=no,HEIGHT="+h+",WIDTH="+w+",TOP="
							+ ((window.screen.availHeight - h)/2) +",LEFT=" + ((window.screen.availWidth - w)/2));
}

function isEmail(s)
{
if(s=="")
	return false;
if(s.indexOf(" ")>0)
	return false;
if(s.indexOf("@")==-1)
	return false;
var i=1;
var slen=s.length;
if(s.indexOf(".")==-1 || s.indexOf(".")==s.length-1)
	return false;
if(s.indexOf("..")!=-1)
	return false;
if(s.indexOf("@")!=s.lastIndexOf("@"))
	return false;
var str="abcdefghijklmnopqrstuvwxyz1234567890@-._ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for(var j=0;j<s.length;j++)
	if(str.indexOf(s.charAt(j))==-1)
		return false;
return true;
}

function checkContact(){
	if(document.getElementById("txthoten").value == ""){
		alert("Ban chua nhap thong tin ho va ten!");
		document.getElementById("txthoten").focus();
		return false;
	}
	if(!isEmail(document.getElementById("txtemail").value)){
		alert("Dia chi email khong hop le!");
		document.getElementById("txtemail").focus();
		return false;
	}
	if(document.getElementById("txtnoidung").value == ""){
		alert("Chua co noi dung lien he!");
		document.getElementById("txtnoidung").focus();
		return false;
	}
	return true;
}

function checkQuery(){
	if(document.getElementById("selCatalogue").value == ""){
		alert("Ban chua chon danh muc cau hoi tu van!");
		document.getElementById("selCatalogue").focus();
		return false;
	}
	if(document.getElementById("txtContent").value == ""){
		alert("Chua co noi dung cau hoi!");
		document.getElementById("txtContent").focus();
		return false;
	}
	return true;
}

function checkSearch(){
	if(document.frm_Search.keyWord.value == ""){
		alert("Ban chua nhap tu khoa!");
		document.frm_Search.keyWord.focus();
		return false;
	}
	return true;
}

function enableIt(){
	var obj = document.getElementById("cmdsurvey");
	if(obj.disabled == true){
		obj.disabled = false;
		//obj.className = "cmdSelect";
	}
}

