function validate_numeric(string) {
	var validFormatRegExp = /^\d*(\.\d+)?$/;
	var isValid = validFormatRegExp.test(string);
	return isValid;
}
function validate_alphanumericnospace(string) {
	var invalidCharactersRegExp = /[^a-z\d]/i;
	var isValid = !(invalidCharactersRegExp.test(string));
	return isValid;
}
function validate_email(email) {
	var validFormatRegExp = /^\w(\.?\w)*@\w(\.?[-\w])*\.[a-z]{2,4}$/i;
	var isValid = validFormatRegExp.test(email);
	return isValid;
}

function SubmitForm(frmName) {
	xacnhan=window.confirm('Are you sure to submit this form?');
	if (xacnhan) {
		frmName.act.value="send";
		frmName.submit();
	}
}
function ResetForm(frmName) {
	xacnhan=window.confirm('Are you sure to reset this form?');
	if (xacnhan) {
		frmName.act.value="";
		frmName.reset();
	}
}
function SubmitLogin(frmName) {
	if (frmName.username.value=="") {
		alert("Enter username!");
		frmName.username.focus();
	} else if (frmName.password.value=="") {
		alert("Enter password!");
		frmName.password.focus();
	} else {
		frmName.password.value=MD5(frmName.password.value);
		frmName.submit();
	}
}
function OpenConfirm(path, message) {
	xacnhan=confirm(message);
	if (xacnhan) {
		window.location.href=path;
	}
}
function ChangeImage(ID, img) {
	ID.src=img.src;
}
function CheckEmail(email) {
	if (email=='') {return false}
	if (email.indexOf('@')==-1) {return false}
	if (email.indexOf('.')==-1) {return false}
	var mark="<>?|:,[]~!#$%^&*()`'\\ /\"";
	for (i=0;i<mark.length;i++) {
		if (email.indexOf(mark.charAt(i))!=-1) {return false}
	}
	return true;
}
function SubmitUser(frmName) {
	if (frmName.username.value=="") {
		alert("Please enter Username!");
		frmName.username.focus();
	} else if (frmName.fullname.value=="") {
		alert("Please enter your fullname!");
		frmName.fullname.focus();
	} else if (frmName.email.value=="" || !CheckEmail(frmName.email.value)) {
		alert("Your email is invalid!");
		frmName.email.focus();
	} else {
		xacnhan=window.confirm('Are you sure to submit this form?');
		if (xacnhan) {
			frmName.act.value="send";
			frmName.submit();
		}
	}
}
function SubmitCart(frmName) {
	idproduct = frmName.elements("idpro[]");
	quantity = frmName.elements("quantity[]");
	kiemtra=true;
	if (idproduct.length>0) {
		for (i=0;i<idproduct.length;i++ ) {
			if (quantity[i].value=="" || !validate_numeric(quantity[i].value)) {
				kiemtra=false;
				alert("Quantity is invalid!");
				quantity[i].focus();
			}
		}
	}
	if (kiemtra) {
		xacnhan=window.confirm("Are you sure to submit this form?");
		if (xacnhan) {
			if (frmName.act.value=='paypal') {
				frmName.action="https://www.paypal.com/cgi-bin/webscr";
				frmName.target="_blank";
			}
			frmName.submit();
		}
	}
}
function SubmitOrder(frmName) {
	idproduct = frmName.elements("idpro[]");
	quantity = frmName.elements("quantity[]");
	kiemtra=true;
	if (idproduct.length>0) {
		for (i=0;i<idproduct.length;i++ ) {
			if (quantity[i].value=="" || !validate_numeric(quantity[i].value)) {
				kiemtra=false;
				alert("Quantity is invalid!");
				quantity[i].focus();
			}
		}
	}
	if (kiemtra) {
		if (frmName.first_name.value=="") {
			alert("Enter you first name!");
			frmName.first_name.focus();
		} else if (frmName.last_name.value=="") {
			alert("Enter you last name!");
			frmName.last_name.focus();
		} else if (frmName.email.value=="" || !CheckEmail(frmName.email.value)) {
			alert("Your email is invalid!");
			frmName.email.focus();
		} else if (frmName.address1.value=="") {
			alert("Enter you address!");
			frmName.address1.focus();
		} else if (frmName.country.value=="") {
			alert("Enter you country!");
			frmName.country.focus();
		} else if (frmName.city.value=="") {
			alert("Enter you city!");
			frmName.city.focus();
		} else if (frmName.tel.value=="") {
			alert("Enter you telephone number!");
			frmName.tel.focus();
		} else if (frmName.numberrandom.value=="") {
			alert("Please enter Security code like this picture!");
			frmName.numberrandom.focus();
		} else {
			xacnhan=window.confirm("Are you sure to submit this form?");
			if (xacnhan) {
				if (frmName.act.value=='paypal') {
					frmName.action="https://www.paypal.com/cgi-bin/webscr";
				}
				frmName.submit();
			}
		}
	}
}
function insertTag(beginTag,endTag) {
	var txtarea = document.frmPost.content;
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		text=caretPos.text;
		if (text=="") {
			text=prompt("Enter content to display:","");
		}
		caretPos.text= beginTag + text + endTag;
		txtarea.focus();
	} else {
		txtarea.value  += beginTag + endTag;
		txtarea.focus();
	}
}
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}
function copyClipboard() {
	var txtarea = document.frmPost.content;
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.execCommand('Copy');
	}
}
function pasteClipboard() {
	var txtarea = document.frmPost.content;
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.execCommand('Paste');
	}
}
function cutClipboard() {
	var txtarea = document.frmPost.content;
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.execCommand('Copy');
		caretPos.text='';
	}
}
function GetExt(filename) {
	vitriCham=filename.lastIndexOf(".")
	if (vitriCham==-1) {
		return "";
	} else {
		return filename.substring(vitriCham+1,filename.length);
	}
}
function SubmitPost(frmName) {
	ext=GetExt(frmName.image.value);
	ext=ext.toUpperCase();
	if (frmName.t.value=="") {
		alert("Category Identify is invalid! Please enter a number or zero number!");
		frmName.t.focus();
	} else if (frmName.title.value=="") {
		alert("Please enter Title!");
		frmName.title.focus();
	} else if (frmName.image.value!="" && (ext!="GIF" && ext!="JPG" && ext!="PNG")) {
		alert("Image filename is invalid! Please use GIF, JPG or PNG image.");
		frmName.image.focus();
	} else {
		xacnhan=window.confirm('Are you sure to submit this form?');
		if (xacnhan) {
			frmName.act.value="send";
			frmName.submit();
		}
	}
}
function SubmitAlbum(frmName) {
	ext=GetExt(frmName.image.value);
	ext=ext.toUpperCase();
	if (frmName.id.value=="" && frmName.image.value=="") {
		alert("Please choose an image!");
		frmName.image.focus();
	} else if (frmName.image.value!="" && (ext=="" || (ext!="GIF" && ext!="JPG" && ext!="PNG"))) {
		alert("Image filename is invalid! Please use GIF, JPG or PNG image.");
		frmName.image.focus();
	} else {
		xacnhan=window.confirm('Are you sure to submit this form?');
		if (xacnhan) {
			frmName.act.value="send";
			frmName.submit();
		}
	}
}
function SubmitVideo(frmName) {
	ext1=GetExt(frmName.image.value);
	ext1=ext1.toUpperCase();
	ext2=GetExt(frmName.video.value);
	ext2=ext2.toUpperCase();
	if (frmName.id.value=="" && frmName.link.value=="" && frmName.video.value=="") {
		alert("Please choose an video!");
		frmName.video.focus();
	} else if (frmName.video.value!="" && (ext2=="" || (ext2!="AVI" && ext2!="MPG" && ext2!="WMV"))) {
		alert("Video filename is invalid! Please use AVI, MPG or WMV video.");
		frmName.video.focus();
	} else if (frmName.id.value=="" && frmName.image.value=="") {
		alert("Please choose an image!");
		frmName.image.focus();
	} else if (frmName.image.value!="" && (ext1=="" || (ext1!="GIF" && ext1!="JPG" && ext1!="PNG"))) {
		alert("Image filename is invalid! Please use GIF, JPG or PNG image.");
		frmName.image.focus();
	} else {
		xacnhan=window.confirm('Are you sure to submit this form?');
		if (xacnhan) {
			frmName.act.value="send";
			frmName.submit();
		}
	}
}
function SubmitProduct(frmName) {
	ext=GetExt(frmName.image.value);
	ext=ext.toUpperCase();
	if (frmName.title.value=="") {
		alert("Please enter Title!");
		frmName.title.focus();
	} else if (frmName.image.value!="" && (ext=="" || (ext!="GIF" && ext!="JPG" && ext!="PNG"))) {
		alert("Image filename is invalid! Please use GIF, JPG or PNG image.");
		frmName.image.focus();
	} else {
		xacnhan=window.confirm('Are you sure to submit this form?');
		if (xacnhan) {
			frmName.act.value="send";
			frmName.submit();
		}
	}
}
function GetTitle(frmName) {
	temp=frmName.image.value;
	vitriCham=-1;
	if (temp!='') {	
		chuoi='';
		for (i=temp.length-1;i>=0;i--) {
			kytu=temp.charAt(i);
			if (kytu==".") vitriCham=i;
			if (kytu=="\\" || kytu=="/") break;
			if (kytu=="_") kytu=" ";
			chuoi=kytu+chuoi;
		}
		if (vitriCham!=-1) {
			vitriCham-=i+1;
			chuoi=chuoi.substring(0,vitriCham);
		}
		if (frmName.title.value=="") frmName.title.value=chuoi.substring(0,1).toUpperCase()+chuoi.substring(1,chuoi.length);
	}
}
function SubmitContact(frmName) {
	if (frmName.yourname.value=="") {
		alert("Please enter your name!");
		frmName.yourname.focus();
	} else if (frmName.email.value=="" || !CheckEmail(frmName.email.value)) {
		alert("Your email is invalid!");
		frmName.email.focus();
	} else if (frmName.content.value=="") {
		alert("Please enter your content!");
		frmName.content.focus();
	} else if (frmName.numberrandom.value=="") {
		alert("Please enter Security code like this picture!");
		frmName.numberrandom.focus();
	} else {
		xacnhan=window.confirm('Are you sure to submit this form?');
		if (xacnhan) {
			frmName.act.value="send";
			frmName.submit();
		}
	}
}
function OpenWin(path) {
	w=window.open(path,'','');
	w.focus();
}
function ShowImage(imagename,width,height) {
	vitriWidth=width+40;
	vitriHeight=height+40;
	vitriTop=(screen.availHeight-vitriHeight)/2;
	vitriLeft=(screen.availWidth-vitriWidth)/2;
	w=window.open('','','top='+vitriTop+', left='+vitriLeft+', width='+vitriWidth+', height='+vitriHeight+', scrollbars=1');
	w.document.writeln('<html><head><title>View image</title></head>');
	w.document.writeln('<body bgcolor=#000000 onDragstart="return false" onSelectstart="return false" onContextmenu="return false" style="border:0px" topmargin="20" leftmargin="20" rightmargin="20" bottommargin="20"><center>');
	w.document.writeln('<table width="100%" bgcolor="#CCCCCC" height="100%" border=0 cellpadding=20 cellspacing=1><tr><td bgcolor="#666666" align="center"><a href="java'+'script:window.close()" title="Close Window"><img src="'+imagename+'" border="1"></a></td></tr></table></center>');
	w.document.writeln('</body></html>');
	w.document.close();
	w.focus();
}
function ViewImage(id,width,height) {
	vitriWidth=width+40;
	vitriHeight=height+40;
	vitriTop=(screen.availHeight-vitriHeight)/2;
	vitriLeft=(screen.availWidth-vitriWidth)/2;
	w=window.open('./?m=post&f=viewimage&id='+id,'','top='+vitriTop+', left='+vitriLeft+', width='+vitriWidth+', height='+vitriHeight+', scrollbars=1');
	w.focus();
}
function ViewVideo(id,width,height) {
	vitriWidth=width+40;
	vitriHeight=height+40;
	vitriTop=(screen.availHeight-vitriHeight)/2;
	vitriLeft=(screen.availWidth-vitriWidth)/2;
	w=window.open('./?m=post&f=viewvideo&id='+id,'','top='+vitriTop+', left='+vitriLeft+', width='+vitriWidth+', height='+vitriHeight+', scrollbars=1');
	w.focus();
}
function SubmitComment(frmName) {
	if (frmName.author.value=="") {
		alert("Please enter your name!");
		frmName.author.focus();
	} else if (frmName.intro.value=="") {
		alert("Please enter your comment!");
		frmName.intro.focus();
	} else if (frmName.numberrandom.value=="") {
		alert("Please enter Security code like this picture!");
		frmName.numberrandom.focus();
	} else {
		xacnhan=window.confirm('Are you sure to submit this comment?');
		if (xacnhan) {
			frmName.act.value="send";
			frmName.submit();
		}
	}
}
function SubmitWeblink(frmName) {
	if (frmName.title.value=="") {
		alert("Please enter title!");
		frmName.title.focus();
	} else {
		xacnhan=window.confirm('Are you sure to submit this link?');
		if (xacnhan) {
			frmName.act.value="send";
			frmName.submit();
		}
	}
}
function SubmitBlock(frmName) {
	if (frmName.title.value=="") {
		alert("Please enter title!");
		frmName.title.focus();
	} else if (frmName.file.value=="") {
		alert("Please enter file (*.php)!");
		frmName.file.focus();
	} else {
		xacnhan=window.confirm('Are you sure to submit this block?');
		if (xacnhan) {
			frmName.act.value="send";
			frmName.submit();
		}
	}
}
function GoLink(frmName) {
	url= frmName.slcLink.options[frmName.slcLink.selectedIndex].value;
	if (url!="") {
		w=window.open(url);
		w.focus();
	}
}
function SubmitMail(frmName) {
	if (frmName.sendername.value=="") {
		alert("Please enter Sender's name!");
		frmName.sendername.focus();
	} else if (frmName.sendermail.value=="" || !CheckEmail(frmName.sendermail.value)) {
		alert("Sender's email is invalid!");
		frmName.sendermail.focus();
	} else if (frmName.receivname.value=="") {
		alert("Please enter Receipient's name!");
		frmName.receivname.focus();
	} else if (frmName.receivmail.value=="" || !CheckEmail(frmName.receivmail.value)) {
		alert("Receipient's email is invalid!");
		frmName.receivmail.focus();
	} else {
		xacnhan=window.confirm('Are you sure to submit this mail?');
		if (xacnhan) {
			frmName.act.value="send";
			frmName.submit();
		}
	}
}

function SubmitRecruitment(frmName) {
	var day=frmName.day.options[frmName.day.selectedIndex].value;
	var month=frmName.month.options[frmName.month.selectedIndex].value;
	var year=frmName.year.options[frmName.year.selectedIndex].value;

	if (frmName.yourname.value=="") {
		alert("Please enter your Fullname!");
		frmName.yourname.focus();
	} else if (frmName.email.value=="" || !CheckEmail(frmName.email.value)) {
		alert("Your email is invalid!");
		frmName.email.focus();
	} else if (day=="") {
		alert("Please enter day of your birthday!");
		frmName.day.focus();
	} else if (month=="") {
		alert("Please enter month of your birthday!");
		frmName.month.focus();
	} else if ((month==2 && day>28) || ((month==4 || month==6 || month==9 || month==11) && day>30)) {
		alert("Your birthday is invalid. Check again!");
		frmName.day.focus();
	} else if (year=="") {
		alert("Please enter year of your birthday!");
		frmName.year.focus();
	} else if (frmName.sex.value=="") {
		alert("Please enter your sex (male or female)!");
		frmName.sex.focus();
	} else if (frmName.address.value=="") {
		alert("Please enter your address or location!");
		frmName.address.focus();
	} else if (frmName.education.value=="") {
		alert("Please enter your education!");
		frmName.education.focus();
	} else if (frmName.speciality.value=="") {
		alert("Please enter your Speciality!");
		frmName.speciality.focus();
	} else if (frmName.university.value=="") {
		alert("Please enter your University!");
		frmName.university.focus();
	} else {
		xacnhan=window.confirm('Are you sure to submit this form?');
		if (xacnhan) {
			frmName.act.value="send";
			frmName.submit();
		}
	}
}
function ViewPost(id,width,height) {
	vitriWidth=width+40;
	vitriHeight=height+40;
	vitriTop=(screen.availHeight-vitriHeight)/2;
	vitriLeft=(screen.availWidth-vitriWidth)/2;
	w=window.open('./?m=post&f=viewpost&id='+id,'','top='+vitriTop+', left='+vitriLeft+', width='+vitriWidth+', height='+vitriHeight+', scrollbars=1, resizable=1, menubar=1');
	w.focus();
}
function EmailPost(id,width,height) {
	vitriWidth=width+40;
	vitriHeight=height+40;
	vitriTop=(screen.availHeight-vitriHeight)/2;
	vitriLeft=(screen.availWidth-vitriWidth)/2;
	w=window.open('./?m=post&f=emailpost&id='+id,'','top='+vitriTop+', left='+vitriLeft+', width='+vitriWidth+', height='+vitriHeight+', scrollbars=1, resizable=1');
	w.focus();
}
function PlayMusic(music) {
	width=320;
	height=300;
	music=unescape(music);
	vitriWidth=width;
	vitriHeight=height;
	vitriTop=(screen.availHeight-vitriHeight)/2;
	vitriLeft=(screen.availWidth-vitriWidth)/2;
	w=window.open('','Music','top='+vitriTop+', left='+vitriLeft+', width='+vitriWidth+', height='+vitriHeight);
	w.document.writeln('<html><head><title>Play Music</title></head>');
	w.document.writeln('<body bgcolor=#000000 onDragstart="return false" onSelectstart="return false" onContextmenu="return false" style="border:0px" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" scroll="no"><center>');
	w.document.writeln('<table width="100%" height="100%" bgcolor="#CCCCCC" border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#666666" align="center">');
	w.document.writeln('<object width="100%" height="' + height + '" classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,0,0" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">');
	w.document.writeln('<param name=filename value="' + music + '">');
	w.document.writeln('<param name=autostart value="1">');
	w.document.writeln('<param name="showstatusbar" value="1">');
	w.document.writeln('<param name="loop" value="true">');
	w.document.writeln('<param name="EnableContextMenu" value="true">');
	w.document.writeln('<embed src="' + music + '" width="100%" height="' + height + '" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows95/downloads/contents/wurecommended/s_wufeatured/mediaplayer/default.asp" showstatusbar="1" autostart=true EnableContextMenu=true loop=true></embed>');
	w.document.writeln('</object>');
	w.document.writeln('</td></tr></table></center>');
	w.document.writeln('</body></html>');
	w.document.close();
	w.focus();
}