
function checkSearch(MyForm) 
{
	var keyword=trimstring(MyForm.keyword.value);
	if (keyword=="") 
	{ 
		alert("Vui long nhap thong tin de tim kiem"); 
		MyForm.keyword.focus();
		return false; 
	}
	if ((keyword.search("scrip")>=0)||(keyword.search("objec")>=0)||(keyword.search("apple")>=0)||(keyword.search("embe")>=0))
	{
		alert("Thong tin tim kiem khong hop le.");
		MyForm.keyword.focus();
		return false; 
	}
	return true;
}

function checkSearchEN(MyForm) 
{
	var keyword=trimstring(MyForm.keyword.value);
	if (keyword=="") 
	{ 
		alert("Please input your keyword"); 
		MyForm.keyword.focus();
		return false; 
	}
	if ((keyword.search("scrip")>=0)||(keyword.search("objec")>=0)||(keyword.search("apple")>=0)||(keyword.search("embe")>=0))
	{
		alert("Your keyword is not valid.");
		MyForm.keyword.focus();
		return false; 
	}
	return true;
}

function checkSearch_Detail(MyForm) 
{
	var keyword=trimstring(MyForm.keyword.value);
	
	if ((keyword.search("scrip")>=0)||(keyword.search("objec")>=0)||(keyword.search("apple")>=0)||(keyword.search("embe")>=0))
	{
		alert("Thong tin tim kiem khong hop le.");
		MyForm.keyword.focus();
		return false; 
	}
	return true;
}

function doMouseOverMenuLevel2(item)
{
	for(i=0;i<item.children.length;i++) 
	{
		item.children(i).style.cursor='hand'; 
		item.children(i).style.backgroundColor='#FCF8D4'
	}
}
	
function doMouseOutMenuLevel2(item,strBgcolor)
{
	for(i=0;i<item.children.length;i++) 
		item.children(i).style.backgroundColor=strBgcolor
}
	
function doMouseClick(item)
{
	item.firstChild.firstChild.click();
}

function checkFeedbackForm(frmForm)
{
	var fullname;
	var content;
	fullname=trimstring(frmForm.fullname.value);
	if (fullname=="") {
		alert("Vui long nhap ho ten.");
		frmForm.fullname.focus();
		return false;
	}
	if ((fullname.search("scrip")>=0)||(fullname.search("objec")>=0)||(fullname.search("apple")>=0)||(fullname.search("embe")>=0))
	{
		alert("Ho ten khong hop le.");
		frmForm.fullname.focus();
		return false; 
	}
	content=trimstring(frmForm.content.value);
	if (content=="") {
		alert("Vui long nhap noi dung.");
		frmForm.content.focus();
		return false;
	}
	if ((content.search("scrip")>=0)||(content.search("objec")>=0)||(content.search("apple")>=0)||(content.search("embe")>=0))
	{
		alert("Noi dung khong hop le.");
		frmForm.content.focus();
		return false; 
	}
		
	return true;
}

function checkFeedbackFormEN(frmForm)
{
	var fullname;
	var content;
	fullname=trimstring(frmForm.fullname.value);
	if (fullname=="") {
		alert("Please input your fullname.");
		frmForm.fullname.focus();
		return false;
	}
	if ((fullname.search("scrip")>=0)||(fullname.search("objec")>=0)||(fullname.search("apple")>=0)||(fullname.search("embe")>=0))
	{
		alert("Your fullname is not valid.");
		frmForm.fullname.focus();
		return false; 
	}
	content=trimstring(frmForm.content.value);
	if (content=="") {
		alert("Please input your content.");
		frmForm.content.focus();
		return false;
	}
	if ((content.search("scrip")>=0)||(content.search("objec")>=0)||(content.search("apple")>=0)||(content.search("embe")>=0))
	{
		alert("Your content is not valid.");
		frmForm.content.focus();
		return false; 
	}
		
	return true;
}

function Submit_onclick(MyForm)
{ 
	var txtfullname_sender=trimstring(MyForm.fullname_sender.value);
	var txtemail_sender=trimfullstring(MyForm.email_sender.value); 
	var txtfullname_receiver=trimstring(MyForm.fullname_receiver.value); 
	var txtemail_receiver=trimfullstring(MyForm.email_receiver.value); 
	if (txtfullname_sender=="") 
	{ 
		alert ("Vui long cung cap ho ten nguoi gui."); 
		MyForm.fullname_sender.value="";
		MyForm.fullname_sender.focus();
		return false; 
	}
	if (txtemail_sender=="") 
	{ 
		alert ("Vui long cung cap email cua nguoi gui."); 
		MyForm.email_sender.value="";
		MyForm.email_sender.focus(); 
		return false; 
	} 
	if (!isEmail(txtemail_sender))
	{ 
		alert ("Email cua nguoi gui khong hop le."); 
		MyForm.email_sender.focus(); 
		return false; 
	} 
	if (txtfullname_receiver=="") 
	{ 
		alert ("Vui long cung cap ho ten nguoi nhan."); 
		MyForm.fullname_receiver.value="";
		MyForm.fullname_receiver.focus(); 
		return false; 
	} 
	if (txtemail_receiver=="") 
	{ 
		alert ("Vui long cung cap email cua nguoi nhan."); 
		MyForm.email_receiver.value="";
		MyForm.email_receiver.focus(); 
		return false; 
	} 
	if (!isEmail(txtemail_receiver))
	{  
		alert ("Email cua nguoi nhan khong hop le."); 
		MyForm.email_receiver.focus(); 
		return false; 
	} 
	return true; 
} 

function doVote()
{
	alert("Chan thanh cam on ban da quan tam");
	//window.document.frmVoteDetail.action="vote_detail.aspx?action=1";
	//window.document.frmVoteDetail.submit();
	window.close();
	return true;
}

function submitVote(intVote_id)
{
	var strItemList;
	window.document.frmWebsite.VoteItem.value = '';
	for (i=0; i < frmWebsite.elements.length - 1; i++)
	{
		if (frmWebsite.elements[i].checked)
			window.document.frmWebsite.VoteItem.value=window.document.frmWebsite.VoteItem.value + ',' + frmWebsite.elements[i].value;
	}
	openpage_noresize('../vn/vote_detail.aspx?vote_id=' + intVote_id + '&action=1' + '&itemlist=' + window.document.frmWebsite.VoteItem.value ,'itemvote','520','310');
}
//image viewer
function ImageExpander(oThumb, sImgSrc)
{
	// store thumbnail image and overwrite its onclick handler.
	this.oThumb = oThumb;
	this.oThumb.expander = this;
	this.oThumb.onclick = function() { this.expander.expand(); }
	
	// record original size
	this.smallWidth = oThumb.offsetWidth;
	this.smallHeight = oThumb.offsetHeight;	

	this.bExpand = true;
	this.bTicks = false;
	
	// self organized list
	if ( !window.aImageExpanders )
	{
		window.aImageExpanders = new Array();
	}
	window.aImageExpanders.push(this);

	// create the full sized image.
	this.oImg = new Image();
	this.oImg.expander = this;
	this.oImg.onload = function(){this.expander.onload();}
	this.oImg.src = sImgSrc;
}

ImageExpander.prototype.onload = function()
{
	this.oDiv = document.createElement("div");
	document.body.appendChild(this.oDiv);
	this.oDiv.appendChild(this.oImg);
	this.oDiv.style.position = "absolute";
	this.oDiv.style.zIndex = 1000;
	this.oDiv.expander = this;
	this.oDiv.onclick = function() {this.expander.toggle();};
	this.oImg.title = "Click to reduce.";
	this.bigWidth = this.oImg.width;
	this.bigHeight = this.oImg.height;
	
	if ( this.bExpand )
	{
		this.expand();
	}
	else
	{
		this.oDiv.style.visibility = "hidden";
		this.oImg.style.visibility = "hidden";
	}
}
ImageExpander.prototype.toggle = function()
{
	this.bExpand = !this.bExpand;
	if ( this.bExpand )
	{
		for ( var i in window.aImageExpanders )
			if ( window.aImageExpanders[i] !== this )
				window.aImageExpanders[i].reduce();
	}
}
ImageExpander.prototype.expand = function()
{
	// set direction of expansion.
	this.bExpand = true;

	// set all other images to reduce
	for ( var i in window.aImageExpanders )
		if ( window.aImageExpanders[i] !== this )
			window.aImageExpanders[i].reduce();

	// if not loaded, don't continue just yet
	if ( !this.oDiv ) return;
	
	// hide the thumbnail
	this.oThumb.style.visibility = "hidden";
	
	// calculate initial dimensions
	this.x = this.oThumb.offsetLeft;
	this.y = this.oThumb.offsetTop;
	this.w = this.oThumb.clientWidth;
	this.h = this.oThumb.clientHeight;
	
	this.oDiv.style.left = this.x + "px";
	this.oDiv.style.top = this.y + "px";
	this.oImg.style.width = this.w + "px";
	this.oImg.style.height = this.h + "px";
	this.oDiv.style.visibility = "visible";
	this.oImg.style.visibility = "visible";
	
	// start the animation engine.
	if ( !this.bTicks )
	{
		this.bTicks = true;
		var pThis = this;
		window.setTimeout(function(){pThis.tick();},25);	
	}
}
ImageExpander.prototype.reduce = function()
{
	// set direction of expansion.
	this.bExpand = false;
}
ImageExpander.prototype.tick = function()
{
	// calculate screen dimensions
	var cw = document.body.clientWidth;
	var ch = document.body.clientHeight;
	var cx = document.body.scrollLeft + cw / 2;
	var cy = document.body.scrollTop + ch / 2;

	// calculate target
	var tw,th,tx,ty;
	if ( this.bExpand )
	{
		tw = this.bigWidth;
		th = this.bigHeight;
		if ( tw > cw )
		{
			th *= cw / tw;
			tw = cw;
		}	
		if ( th > ch )
		{
			tw *= ch / th;
			th = ch;
		}
		tx = cx - tw / 2;
		ty = cy - th / 2; 
	}
	else
	{
		tw = this.smallWidth;
		th = this.smallHeight;
		tx = this.oThumb.offsetLeft;
		ty = this.oThumb.offsetTop;
	}	
	// move 5% closer to target
	var nHit = 0;
	var fMove = function(n,tn) 
	{
		var dn = tn - n;
		if ( Math.abs(dn) < 3 )
		{
			nHit++;
			return tn;
		}
		else
		{
			return n + dn / 10;
		}
	}
	this.x = fMove(this.x, tx);
	this.y = fMove(this.y, ty);
	this.w = fMove(this.w, tw);
	this.h = fMove(this.h, th);
	
	this.oDiv.style.left = this.x + "px";
	this.oDiv.style.top = this.y + "px";
	this.oImg.style.width = this.w + "px";
	this.oImg.style.height = this.h + "px";

	// if reducing and size/position is a match, stop the tick	
	if ( !this.bExpand && (nHit == 4) )
	{
		this.oImg.style.visibility = "hidden";
		this.oDiv.style.visibility = "hidden";
		this.oThumb.style.visibility = "visible";

		this.bTicks = false;
	}
	
	if ( this.bTicks )
	{
		var pThis = this;
		window.setTimeout(function(){pThis.tick();},25);
	}
}
