function addbookmark()
{
bookmarkurl="http://www.telecommuting21.com"
bookmarktitle="Telecummuting21.com"
if (document.all)
window.external.AddFavorite(bookmarkurl,bookmarktitle)
}

function Print()
{
         document.getElementById("header").style.display = "none";
         document.getElementById("footer").style.display = "none";
         document.getElementById("left").style.display = "none";
         document.getElementById("menubody").style.display = "none";
         window.print();

         document.getElementById("header").style.display = "";
         document.getElementById("footer").style.display = "";
         document.getElementById("menubody").style.display = "";
         document.getElementById("left").style.display = "";
}

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+"- Your Email ?\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 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+"- Ngay het han so voi hien tai khong hop ly.\n";

   return re;
}
function checkTextField(str,name)
{
        if(str=="")
        {
                errormsg=errormsg+"- "+name+" ?\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 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 checkChoice(val,name)
{
        if(val=="")
                errormsg=errormsg+"- "+name+" phai chon mot.\n";
}

function checkIsNum(val,name)
{
        if((val!="")&&(!isNaN(val)))
                return true;
        else
        {
                errormsg=errormsg+"- "+name+" khong phai la mot so.\n";
        }

}
function checkAll()
{
        if(errormsg!="")
        {
                alert("---------------------------------------\nVERIFY YOUR INFORMATION, PLEASE !    \n---------------------------------------\n"+errormsg);
                errormsg="";
                return false;
        }
        else
                return true;
        errormsg="";
}

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)'></body></html>";
  popupImage = window.open('','_blank','toolbar=no,scrollbars=no');
  popupImage.document.open();
  popupImage.document.write(HTML);
  popupImage.document.close();
}

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 doLogin()
{
        if(document.tflogin.uvntd[0].checked)
                document.tflogin.action="login.php?hed=ungvien.php?item=3";
        else if(document.tflogin.uvntd[1].checked)
                document.tflogin.action="company_check.php?hed=ntdung.php?item=2";
        else
                errormsg="- You are a telecommuter or a company ?\n";

        checkEmail(document.tflogin.email.value);
        checkTextField(document.tflogin.password.value,"Your Password");
        if(checkAll())
        {
                document.tflogin.submit();
                return true;
        }
}

function doSignup()
{
        if(document.tfsignup.uvntd[0].checked)
                document.tfsignup.action="ungvien.php?item=13";
        else if(document.tfsignup.uvntd[1].checked)
                document.tfsignup.action="ntdung.php?item=10&state=new";
        else
                errormsg="- You are a telecommuter or a company ?\n";

        checkEmail(document.tfsignup.email.value);
        checkTextField(document.tfsignup.name.value,"Your Name");
        if(checkAll())
                document.tfsignup.submit();
}

function doForgot()
{
        if(document.tflogin.uvntd[0].checked)
                window.location="../member/candidate_forgot.php?tab=2&uvntd="+document.tflogin.uvntd.value;
        else if(document.tflogin.uvntd[1].checked)
                window.location="../member/company_forgot.php?tab=2&uvntd="+document.tflogin.uvntd.value;
        else
                alert("- You are a telecommuter or a company ?");
}
function doChangeLogin()
{
                 if(document.tflogin.uvntd[0].checked)
                 {
                        document.all.f0.innerHTML="<font color=\"#ff5500\">Telecommuter</font>";
                        document.all.f1.innerHTML="Company";
                 }
                 if(document.tflogin.uvntd[1].checked)
                 {
                        document.all.f0.innerHTML="Telecommuter";
                        document.all.f1.innerHTML="<font color=\"#ff5500\">Company</font>";
                 }
}
function matkhau()
{
        if(document.tflogin.uvntd[0].checked)
                document.tflogin.action="login.php?hed=ungvien.php?item=3";
        else if(document.tflogin.uvntd[1].checked)
                document.tflogin.action="company_check.php?hed=ntdung.php?item=2";
        else
                errormsg="- You are a telecommuter or a company ?\n";
        return true;
}
function doChangeSignUp()
{
                 if(document.tfsignup.uvntd[0].checked)
                 {
                        document.all.s0.innerHTML="<font color=\"#ff5500\">Telecommuter</font>";
                        document.all.s1.innerHTML="Company";
                 }
                 if(document.tfsignup.uvntd[1].checked)
                 {
                        document.all.s0.innerHTML="Telecommuter";
                        document.all.s1.innerHTML="<font color=\"#ff5500\">Company</font>";
                 }
}

function check_password()
{
         if( document.tf.password.value=="" )
         {
            alert("Mauvaise Mot de Passe!") ;
            tf.password.focus();
            return false ;
         }
         if( document.tf.repassword.value=="" )
         {
            alert("Confirm your password, please!") ;
            tf.repassword.focus();
            return false ;
         }
         if( document.tf.password.value != document.tf.repassword.value )
         {
            alert("Les deux Mots de Passe ne sont pas identiques") ;
            tf.repassword.value = "" ;
            tf.repassword.focus();
            return false ;
         }
         return true ;
}
function TestEmail()
{
         if( document.ef.email.value=="" )
         {
            alert("Your Email, please!") ;
            ef.email.focus();
            return false ;
         }
}
