
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
//alert("Hi");
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function setVis(id, vis, displayNone) {
    if (id != '') {
        if (displayNone == undefined || (displayNone != true && displayNone != false)) {
            displayNone = true;
        }
	    obj = MM_findObj(id);
	    if (obj == undefined) {
	        return;
	    }
	    if(document.getElementById || document.all){//all the modern browsers
		    obj.style.visibility = vis ? "visible" : "hidden";
		    if (displayNone) {
		        obj.style.display = vis ? "block" : "none";
		    }
	    }
	    else if(document.layers){//this is NS4
		    obj.visibility = vis ? "show" : "hide";
		    if (displayNone) {
    		    obj.display = vis ? "block" : "hide";
            }
	    }  
	}
}

function getVis(id) {
	obj = MM_findObj(id);
	
	var vis = true;
	
	if(document.getElementById || document.all){//all the modern browsers
		if (obj.style.visibility == "hidden") {
		    vis = false;
		}
	}
	else if(document.layers){//this is NS4
		if (obj.visibility == "hide") {
		    vis = false;
		}
	}  
	return vis;
}

function toggleVis(id) {
	setVis(id, !getVis(id));
}

function footnotes(contID,noteID)
{
	var cont = document.getElementById(contID);
	var noteholder = document.getElementById(noteID);
	var spans = cont.getElementsByTagName("span");
	var notes = 0;
	
	for (i=0;i<spans.length;i++)
	{
		if (spans[i].className == "footnote")
		{
			notes++;
			noteholder.innerHTML += "<div class='footnote'><a name='note"+notes+"'></a>" + notes + ". " + spans[i].innerHTML + " <a href='#ftn"+notes+"' title='tr&#7903; l&#7841;i n&#7897;i dung'>&#8617;</a></div>";
			spans[i].innerHTML = "<a name='ftn"+notes+"' href='#note" + notes + "' title='xem footnote' class='footnote'>" + notes + "</a>";
		}
	}
	
	// hide button
	document.getElementById("btn").style.display = 'none';
	
}
	
function confirm_submit(msg){
	var agree=confirm(msg);
	if (agree){
		return true;
	}else{
		return false;
	}
}

function checknumber(x)
{
	var anum=/(^\d+$)|(^\d+\.\d+$)/;
	if (anum.test(x))
	{
		testresult=true;
	}
	else
	{
		testresult=false;
	}
	return (testresult)
}

function checkEmail(field) 
{ 
	var str = field.value; 
	var pattern = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/; 
	var flag = pattern.test(str); 
 	if(!flag) 
 	{ 
 	 	return false; 
 	} 
 return true; 
}

function check_url(field)
{
	var is_protocol_ok=field.value.indexOf('http://');
	if (is_protocol_ok==-1)
 	{ 
		return false;
 	}
	return true;
}

function isEmail(email)
{
	// Valid format: "a@b.cd"
	invalidChars = " /;,:";
	if (email=="")
	{
		return false;
	}
	for (var i=0; i<invalidChars.length; i++)
	{
		badChar=invalidChars.charAt(i);
		if (email.indexOf(badChar,0) > -1)
		{
			return false;
		}
	}
	atPos = email.indexOf("@",1);
	// there must be one "@" symbol
	if (atPos == -1)
	{
		return false;
	}
	if (email.indexOf("@", atPos+1)!=-1)
	{
		// and only one "@" symbol
		return false;
	}
		periodPos = email.indexOf(".",atPos)
	if (periodPos == -1)
	{
		// and at least one "." after the "@"
		return false;
	}
	if (atPos+2>periodPos)
	{
		// and at least one character between "@" and "."
		return false;
	}
	if (periodPos+3>email.length)
	{
		return false;
	}
	return true;
}
