// JavaScript Document
function ValNum()
{
	if ( event.keyCode < 48 || event.keyCode > 57)
		event.returnValue = false;
	else
		event.returnValue = true;				
}	

function ValNum2()
{
	value = window.event.srcElement.value;
	if ( value < 1  )
	{
	    alert("So ngay phai lon hon 1");
	}
}


function checkpostad()
{
	if ( document.frmpostad.selsubcategory[document.frmpostad.selsubcategory.selectedIndex].value == "")
	{
		alert("Xin hay chon chuyen muc");
		document.frmpostad.selsubcategory.focus();
		return false;
	}

	if ( document.frmpostad.txtadtitle.value == "")
	{
		alert("Xin hay nhap tieu de");
		document.frmpostad.txtadtitle.focus();
		return false;
	}

	if ( document.frmpostad.selthoihan.value == "")
	{
		alert("Xin vui long nhap thoi han");
		document.frmpostad.selthoihan.focus();
		return false;
	}
	
	return true;
}

function checkpostbannerad()

{

	if ( document.frmpostad.txtbannerlink.value == "")

	{

		alert("Please your banner image link");

		document.frmpostad.txtbannerlink.focus();

		return false;

	}



	if ( document.frmpostad.txtwebsite.value == "")

	{

		alert("Please your website link");

		document.frmpostad.txtwebsite.focus();

		return false;

	}



	return true;

}


function checkupdatepass()
{
	if (document.frmcpassw.txtcurrpass.value == "" )
	{
		alert("Xin hay nhap password hien thoi");
		return false;
	}
	if (document.frmcpassw.txtnewpass.value != document.frmcpassw.txtretypenewpass.value)
	{
		alert("Password nhap lai khong dung");
		return false;
	}
	if ( document.frmcpassw.txtnewpass.value.length < 6 )
	{
		alert("Password phai co it nhat 6 ky tu");
		return false;
	}
	return true;
}

function checkpostweb()
{
	if (document.frmaddwebsite.txtwebname.value == "" )
	{
		alert("Xin hay nhap ten website");
		return false;
	}

	if (document.frmaddwebsite.txtwebaddress.value == "http://" )
	{
		alert("Xin hay nhap dia chi website");
		return false;
	}

	if ( document.frmaddwebsite.webtype[document.frmaddwebsite.webtype.selectedIndex].value == "")
	{
		alert("Xin chon loai web");
		return false;
	}

	return true;
}

function checkprofile()
{
	if ( document.frmprofile.txtfullname.value == "")
	{
		alert("Please enter full name");
		return false;
	}

	if ( document.frmprofile.txtemail.value == "")
	{
		alert("Please enter email address");
		return false;
	}

	if ( document.frmprofile.txtpassword.value != "")
	{
		if (confirm("Are you sure to cancel your account, you can't re-regisiter after cancelling your account?") == false)
			return false;
	}

	return true;
}


function doUpload() {
	if (document.formupload.userfile.value.length==0) {
		alert("Please enter path and file name");
		document.formupload.userfile.focus();
		return false;
	}

	var filename = document.formupload.userfile.value;	
	var dotpos;
	filename = filename.substring(filename.lastIndexOf("\\")+1,filename.length);
	dotpos=filename.lastIndexOf('.');
	ext=filename.substr(dotpos+1,3);
	ext=ext.toLowerCase();
	fname=filename.substr(0,dotpos);
	
	if(dotpos==-1||dotpos==0){
		alert("Your photo file must named with extension");
		return false;
	}
	
	if (ext!="")
		if ((ext!="jpg")){
			alert("We only accept file format of JPG. Please try again.");
			return false;
		}
	
	return true;
}

function checkinput()
{
	if ( document.frmcontact.txtname.value == "")
	{
		alert("Xin hay nhap ten nguoi gui");
		document.frmcontact.txtname.focus();
		return false;
	}

	if ( document.frmcontact.txtemail.value == "")
	{
		alert("Xin hay nhap email");
		document.frmcontact.txtemail.focus();
		return false;
	}
	if ( document.frmcontact.txtsubject.value == "")
	{
		alert("Xin hay nhap chu de");
		document.frmcontact.txtsubject.focus();
		return false;
	}
	if ( document.frmcontact.txtmessage.value == "")
	{
		alert("Xin hay nhap noi dung");
		document.frmcontact.txtmessage.focus();
		return false;
	}

	return true;
}

function checkInputSignup()
{
	if ( document.frmsignup.txtfullname.value == "")
	{
		alert("Xin vui long nhap ho ten");
		document.frmsignup.txtfullname.focus();
		return false;
	}

	if ( document.frmsignup.txtemail.value == "")
	{
		alert("Xin vui long nhap email");
		document.frmsignup.txtemail.focus();
		return false;
	}

	if ( document.frmsignup.txtconfirmemail.value == "")
	{
		alert("Xin vui long nhap lai email de xac nhan");
		document.frmsignup.txtconfirmemail.focus();
		return false;
	}

	if ( document.frmsignup.txtemail.value != document.frmsignup.txtconfirmemail.value )
	{
		alert("Email nhap lai phai giong voi email ban dau, xin kiem tra lai");
		document.frmsignup.txtconfirmemail.focus();
		return false;
	}

	if ( document.frmsignup.txtpassword.value == "")
	{
		alert("Xin vui long chon mat ma it nhat 6 ky tu");
		document.frmsignup.txtpassword.focus();
		return false;
	}

	if ( document.frmsignup.txtpassword.value.length < 6)
	{
		alert("Mat ma phai dai it nhat 6 ky tu");
		document.frmsignup.txtpassword.focus();
		return false;
	}

	if ( document.frmsignup.txtcpassword.value == "")
	{
		alert("Xin vui long nhap lai mat ma da xac nhan");
		document.frmsignup.txtcpassword.focus();
		return false;
	}
	
	if ( document.frmsignup.txtpassword.value != document.frmsignup.txtcpassword.value)
	{
		alert("Mat ma nhap lai khong khop voi mat ma da nhap, xin kiem tra lai");
		document.frmsignup.txtcpassword.focus();
		return false;
	}
	

	
	if ( document.frmsignup.chkagree.checked == false)
	{
		alert("Xin hay doc ky quy dinh va click vao box dong y");
		return false;
	}	
	
	return true;
}

function checkinputlogin()
{
	if ( document.frmsignin.txtemail.value == "")
	{
		alert("Please enter your email address");
		document.frmsignin.txtemail.focus();
		return false;	
	}
	
	if ( document.frmsignin.txtpassword.value == "")
	{
		alert("Please enter your password");
		document.frmsignin.txtpassword.focus();
		return false;	
	}
	
	return true;
}

function checkinputcontact()
{
	if ( document.frmcontact.txtname.value == "")
	{
		alert("Please enter your name");
		document.frmcontact.txtname.focus();
		return false;
	}

	if ( document.frmcontact.txtemail.value == "")
	{
		alert("Please enter your email");
		document.frmcontact.txtemail.focus();
		return false;
	}
	if ( document.frmcontact.txtsubject.value == "")
	{
		alert("Please enter subject");
		document.frmcontact.txtsubject.focus();
		return false;
	}
	if ( document.frmcontact.txtmessage.value == "")
	{
		alert("Please enter message");
		document.frmcontact.txtmessage.focus();
		return false;
	}

	return true;
}

function openWin(URL) 
{ 
	window.open(URL,null,"toolbar=no,width=400,height=300,status=no,scrollbars=yes,resize=no,menubars=no");	
}
