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 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 {
		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 {
		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 GoLink(frmName) {
	url= frmName.slcLink.options[frmName.slcLink.selectedIndex].value;
	if (url!="") {
		w=window.open(url);
		w.focus();
	}
}
function SubmitOrder(frmName) {
	if (frmName.count.value=="" || isNaN(frmName.count.value)) {
		alert("Quantity of product is invalid! Enter a number!");
		frmName.count.focus();
	} else if (frmName.yourname.value=="") {
		alert("Please enter your name!");
		frmName.yourname.focus();
	} else if (frmName.address.value=="") {
		alert("Please enter your address!");
		frmName.address.focus();
	} else if (frmName.email.value=="" || !CheckEmail(frmName.email.value)) {
		alert("Please enter your email!");
		frmName.email.focus();
	} else if (frmName.tel3.value=="" || isNaN(frmName.tel3.value)) {
		alert("Your telephone is invalid! Enter your telephone number!");
		frmName.tel3.focus();
	} else {
		total=(frmName.count.value*frmName.price.value)
		frmName.content.value="Order product "+frmName.title.value+" (ProductID="+frmName.idproduct.value+"):"
			+"\nCount: "+frmName.count.value
			+"\nPrice: "+frmName.currency.value+frmName.price.value
			+"\n---------------------------"
			+"\nTotal: "+frmName.currency.value+total
			+"\nLink: "+frmName.domain.value+"/?m=post&f=post&id="+frmName.id.value+"&idproduct="+frmName.idproduct.value;
		xacnhan=window.confirm('Are you sure to buy this product?');
		if (xacnhan) {
			frmName.act.value="buy";
			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();
		}
	}
}

