
function submitPoll()
{
	for (i = 0; i < poll_form.length; i++)
		if (poll_form[i].checked)
		{
			window.open('poll.php?option='+poll_form[i].value, 'win1','width=500,height=230')
			return;
		}
	alert('B?n c?n ch?n m?t câu tr? l?i tr??c khi nh?n nút!');
}
function startList() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("navi");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
var errormsg="";
function checkEmail(email)
{
   var at1      =  email.indexOf("@");
   var at2      =  email.lastIndexOf("@");
   var dot     =  email.lastIndexOf(".");
   var space   =  email.indexOf(" ");
   if((at1!=-1)&&
      (at1!=0)&&
      (at2==at1)&&
      (dot!=-1)&&
      (dot>at1+1)&&
      (dot<email.length-1)&&
      (space==-1))
   {
      return true;
   }
   else
   {
      errormsg=errormsg+"- Email chua nhap hoac sai dinh dang.\n";
      return false;
   }
}
function checkEmail_en(email)
{
   var at1      =  email.indexOf("@");
   var at2      =  email.lastIndexOf("@");
   var dot     =  email.lastIndexOf(".");
   var space   =  email.indexOf(" ");
   if((at1!=-1)&&
      (at1!=0)&&
      (at2==at1)&&
      (dot!=-1)&&
      (dot>at1+1)&&
      (dot<email.length-1)&&
      (space==-1))
   {
      return true;
   }
   else
   {
      errormsg=errormsg+"- Invalid e-mail address.\n";
      return false;
   }
}
function checkDate(dd,mm,yyyy,name)
{
   result=true;
   if(!isNaN(yyyy)&&(yyyy!="")&&(yyyy<10000))
   {
      if( (mm=="02") && ((dd=="30")||(dd=="31")) )
         result=false;
      if( (mm=="02") && (dd=="29") && (yyyy%4>0) )
         result=false;
      if( ((mm=="04")||(mm=="06")||(mm=="09")||(mm=="11")) && (dd=="31") )
         result=false;
   }
   else
   {
      result=false;
   }
   if(result==false)
      errormsg=errormsg+"- "+name+" khong dung dinh dang.\n"
   return result;
}
function checkDate_en(dd,mm,yyyy,name)
{
   result=true;
   if(!isNaN(yyyy)&&(yyyy!="")&&(yyyy<10000))
   {
      if( (mm=="02") && ((dd=="30")||(dd=="31")) )
         result=false;
      if( (mm=="02") && (dd=="29") && (yyyy%4>0) )
         result=false;
      if( ((mm=="04")||(mm=="06")||(mm=="09")||(mm=="11")) && (dd=="31") )
         result=false;
   }
   else
   {
      result=false;
   }
   if(result==false)
      errormsg=errormsg+"- "+name+" invalid date.\n"
   return result;
}
function checkInterval(dstart,mstart,ystart,names,dend,mend,yend,namee)
{
   var re=true;
   re=checkDate(dstart,mstart,ystart,names)&&checkDate(dend,mend,yend,namee);
   if(re)
   {
      var yyyy=yend-ystart;
      if(yyyy>0)
	 		re=true;
      else if(yyyy==0)
      {
         var mm=mend-mstart;
         if(mm>0)
            re=true;
         else if(mm==0)
         {
            var dd=dend-dstart;
	    	if(dd>=0)
	       	re=true;
         else
            re=false;
         }
         else
	    		re=false;
      }
      else
         re=false;
   }
   if(re==false)
      errormsg=errormsg+"- Khoang thoi gian khong hop ly.\n";

   return re;
}
function checkInterval_en(dstart,mstart,ystart,names,dend,mend,yend,namee)
{
   var re=true;
   re=checkDate(dstart,mstart,ystart,names)&&checkDate(dend,mend,yend,namee);
   if(re)
   {
      var yyyy=yend-ystart;
      if(yyyy>0)
	 		re=true;
      else if(yyyy==0)
      {
         var mm=mend-mstart;
         if(mm>0)
            re=true;
         else if(mm==0)
         {
            var dd=dend-dstart;
	    	if(dd>=0)
	       	re=true;
         else
            re=false;
         }
         else
	    		re=false;
      }
      else
         re=false;
   }
   if(re==false)
      errormsg=errormsg+"- Invalid time.\n";

   return re;
}
function checkTextField(str,name)
{
	if(str=="")
	{
		errormsg=errormsg+"- "+name+" chua nhap thong tin.\n";
		return false;
	}
	else
		return true;
}
function checkTextField_en(str,name)
{
	if(str=="")
	{
		errormsg=errormsg+"- "+name+" cann't be empty.\n";
		return false;
	}
	else
		return true;
}

function checkPassword(p,namep,rp,namerp)
{
	if(p!=="")
	{
		if(p==rp)
	 		return true;
	 	else
		{
			errormsg=errormsg+"- "+namep+" khong giong voi "+namerp+".\n";
			return false;
		}
	}
	else
	{
		errormsg=errormsg+"- "+namep+" chua co thong tin.\n";
		return false;
	}

}
function checkPassword_en(p,namep,rp,namerp)
{
	if(p!=="")
	{
		if(p==rp)
	 		return true;
	 	else
		{
			errormsg=errormsg+"- "+namep+" not equal with "+namerp+".\n";
			return false;
		}
	}
	else
	{
		errormsg=errormsg+"- "+namep+" cann't be empty.\n";
		return false;
	}

}

function checkNewPassword_en(p,namep,rp,namerp)
{
	if(p==rp)
		return true;
	else
	{
		errormsg=errormsg+"- "+namep+" not equal with "+namerp+".\n";
		return false;
	}
}

function image_open(image_loc,img)
{
  HTML = "<html><style>body{margin:0px 0px 0px 0px}</style><body onBlur='top.close()'><img src='"+ image_loc +"' border=0 name=load_image onLoad='window.resizeTo(document.load_image.width+10,document.load_image.height+30);window.moveTo(parseInt(window.screen.availWidth)/2-parseInt(document.load_image.width+10)/2,parseInt(window.screen.availHeight)/2-parseInt(document.load_image.height+30)/2)'></body></html>";
  popupImage = window.open('','_blank','toolbar=no,scrollbars=no');
  popupImage.document.open();
  popupImage.document.write(HTML);
  popupImage.document.close();
  //obj_img = popupImage.document.getElementById(img);
 //obj_img.src= obj_img.src;
}
function checkIsIntNum(val,name)
{
	if((val!="")&&(!isNaN(val)) && val.indexOf(".")<0)
		return true;
	else
	{
		errormsg=errormsg+"- "+name+" khong phai la so nguyen.\n";
		return false;
	}
}
function checkIsIntNum_en(val,name)
{
	if((val!="")&&(!isNaN(val)) && val.indexOf(".")<0)
		return true;
	else
	{
		errormsg=errormsg+"- "+name+" is not an interger number.\n";
		return false;
	}
}
function checkChoice(val,name)
{
	if(val=="")
		errormsg=errormsg+"- "+name+" phai chon mot.\n";
}
function checkChoice_en(val,name)
{
	if(val=="")
		errormsg=errormsg+"- "+name+" must choose one.\n";
}

function checkIsNum(val,name)
{
	if((val!="")&&(!isNaN(val)))
		return true;
	else
	{
		errormsg=errormsg+"- "+name+" khong phai la mot so.\n";
	}
}
function checkIsNum_en(val,name)
{
	if((val!="")&&(!isNaN(val)))
		return true;
	else
	{
		errormsg=errormsg+"- "+name+" invalid number.\n";
	}

}
function checkAll()
{
	if(errormsg!="")
	{
		alert("---------------------------------------\nXIN KIEM TRA LAI THONG TIN !    \n---------------------------------------\n"+errormsg);
		errormsg="";
		return false;
	}
	else
		return true;
	errormsg="";
}
function checkAll_en()
{
	if(errormsg!="")
	{
		alert("---------------------------------------\nPLEASE CHECK FOLLOWING INFORMATIONS !    \n---------------------------------------\n"+errormsg);
		errormsg="";
		return false;
	}
	else
		return true;
	errormsg="";
}
function setCheckboxes(the_form, the_box, do_check)
{
    var elts      = (typeof(document.forms[the_form].elements[the_box]) != 'undefined')
                  ? document.forms[the_form].elements[the_box]
                  : document.forms[the_form].elements[the_box];
    var elts_cnt  = (typeof(elts.length) != 'undefined')
                  ? elts.length
                  : 0;

    if (elts_cnt) {
        for (var i = 0; i < elts_cnt; i++) {
            elts[i].checked = do_check;
        }
    } else {
        elts.checked = do_check;
    }
    return true;
}

function checkCheckboxes(the_form, the_box)
{
   var elts      = (typeof(document.forms[the_form].elements[the_box]) != 'undefined')
                  ? document.forms[the_form].elements[the_box]
                  : document.forms[the_form].elements[the_box];
   var elts_cnt  = (typeof(elts.length) != 'undefined')
                  ? elts.length
                  : 0;
	err=false;

	if (elts_cnt)
   {
		for (var i = 0; i < elts_cnt; i++)
		{
			if(elts[i].checked == true)
			{
				err=true;
				break;
			}
		}

	}
	else if(document.forms[the_form].elements[the_box].checked==true)
	{
		err=true;
	}

	return err;
}

function checkSelections(the_form, the_box)
{
   var elts      = (typeof(document.forms[the_form].elements[the_box]) != 'undefined')
                  ? document.forms[the_form].elements[the_box]
                  : document.forms[the_form].elements[the_box];
   var elts_cnt  = (typeof(elts.length) != 'undefined')
                  ? elts.length
                  : 0;
	err=false;

	if (elts_cnt)
   {
		for (var i = 0; i < elts_cnt; i++)
		{
			if(elts[i].selected == true)
			{
				err=true;
				break;
			}
		}

	}
	else if(document.forms[the_form].elements[the_box].selected==true)
	{
		err=true;
	}

	return err;
}

function checkZeroValue(the_form,the_box)
{

	var elts      = (typeof(document.forms[the_form].elements[the_box]) != 'undefined')
	                  ? document.forms[the_form].elements[the_box]
	                  : document.forms[the_form].elements[the_box];
	var elts_cnt  = (typeof(elts.length) != 'undefined')
						? elts.length
						: 0;
	err=false;

	if (elts_cnt)
	{
		for (var i = 0; i < elts_cnt; i++)
		{
			if(elts[i].value == "")
				elts[i].value = "0";
			if(elts[i].value != "0")
			{
				err=true;
				break;
			}
		}
	}
	else if(document.forms[the_form].elements[the_box].value!="")
	{
		err=true;
	}
	return err;
}
function CheckForm(){

	if(document.getElementById("regiter_for_company").checked== false && document.getElementById("regiter_for_individual").checked== false){

		alert("Choose register for option!");

		document.getElementById("regiter_for_company").focus();

		return false;

	}

	

	if(document.getElementById("course_kind_public").checked== false && document.getElementById("course_kind_in_house").checked== false && document.getElementById("course_kind_package").checked== false){

		alert("Choose course kind!");

		document.getElementById("regiter_for_company").focus();

		return false;

	}

	

	if(document.detail.course_name.value==""){

		alert("Choose course name!");

		document.detail.course_name.focus();

		return false;

	}



	if(document.detail.full_name.value==""){

		alert("Insert name!");

		document.detail.full_name.focus();

		return false;

	}

	

	if(document.detail.ocupation.value==""){

		alert("Insert occupation!");

		document.detail.ocupation.focus();

		return false;

	}

	

	if(document.detail.address.value==""){

		alert("Insert address!");

		document.detail.address.focus();

		return false;

	}

	

	if(document.detail.hand_phone.value==""){

		alert("Insert hand phone!");

		document.detail.hand_phone.focus();

		return false;

	}



	if(document.detail.email.value==""){

		alert("Insert email!");

		document.detail.email.focus();

		return false;

	}

	

	if(document.detail.email.value!=""){

		if(!CheckEmailFormat(document.detail.email.value)){

			window.alert("Email wrong. Re-insert it!");

			document.detail.email.focus();

			return false;

		}

	}	

	

	if(document.getElementById("regiter_for_company").checked){

		if(document.detail.company_name.value==""){

			alert("Insert company name!");

			document.detail.company_name.focus();

			return false;

		}

				

		if(document.detail.company_address.value==""){

			alert("Insert company address!");

			document.detail.company_address.focus();

			return false;

		}

		

		if(document.detail.company_telephone.value==""){

			alert("Insert company telephone!");

			document.detail.company_telephone.focus();

			return false;

		}

	

		if(document.detail.company_website.value==""){

			alert("Insert company wesbite!");

			document.detail.company_website.focus();

			return false;

		}

	}

	

	return true;

}