var reEmail=/^.+\@.+\..+$/

//**********************************************************************************************************************
var ElementObjectsCache=new Object();
function GetE(objID){
  if (!ElementObjectsCache[objID]) ElementObjectsCache[objID]=document.getElementById(objID);    
  return ElementObjectsCache[objID];
}

function checkname(name,ln){
  var sw=0;
  carray=name.split(" ");
  sw=0;
  for(i=0;i<carray.length;i++)
    if (carray[i].length!=0)
      sw+=carray[i].length;
  if (sw<ln){
    return false;
  }else{
    return true;
  }
}

//*************************************************************************************************************************
function check_passwd(aid){
  form=document.forms.mainform;
  if (aid!=0 && checkname(form.passwd.value,1) && !checkname(form.oldpasswd.value,3)){
    alert('Please enter your old password');
    form.oldpasswd.focus();
    return false;
  }
  if (aid==0 && !checkname(form.passwd.value,3)){
    alert('Please enter your password');
    form.passwd.focus();
    return false;
  }
  if (form.passwd.value!=form.repasswd.value){
    alert('Passwords not matching');
    form.passwd.focus();
    return false;
  }
  return true;
}


//******************************************************************************************************************************
function checkform(){
  form=document.forms.mainform;
  if (!checkname(form.f_name.value,3)){
    alert('Please, enter your name !');
    form.f_name.focus();
  }else if(!reEmail.test(form.f_email.value)){
    alert('Invalid email address');
    form.f_email.focus();
  }else if (!checkname(form.f_tel.value,3)){
    alert('Enter telephone number');
    form.f_tel.focus();
  }else if (!checkname(form.f_comment.value,3)){
    alert('Enter comment');
    form.f_comment.focus();
  }else{
    form.action.value="Send";
    form.submit();
  }
}
//*************************************************************************************************************************
function check_client(action,aid){
  form=document.forms.mainform;
  if (!checkname(form.title.value,1)){
    alert('Please, enter your title');
    form.title.focus();
  }else if (!checkname(form.firstname.value,3)){
    alert('Please, enter your first name');
    form.firstname.focus();
  }else if (!checkname(form.surname.value,3)){
    alert('Please, enter your surname');
    form.surname.focus();
  }else if (!checkname(form.tel.value,3)){
    alert('Please, enter your telephone number');
    form.tel.focus();
  }else if(!reEmail.test(form.email.value)){
    alert('Invalid email address');
    form.email.focus();
  }else if (!check_passwd(aid)){
    return false;
  }else if (!checkname(form.duedate.value,10)){
    alert('Invalid due date');
    form.duedate.focus();
  }else{
    form.action.value='ClientSave';
    form.submit();
  }
}

//*************************************************************************************************************************
function openduedatecalendar(fieldname){
  form=document.forms.mainform;
  eval('sdate=form["'+fieldname+'"].value');
  open('calendar.php?fieldname='+fieldname+'&sdatestr='+sdate,'duedate','status=no,menubar=no,resizable=no,scrollbars=AUTO,width=200,height=180');
}

//*************************************************************************************************************************
function cancel_book(){
  form=document.forms.mainform;
  if (form.accord.checked && confirm('Are you sure you want to cancel this appointment?')){
    form.action.value='ClientCancelBookConfirm';
    form.submit();
  }
}

//*************************************************************************************************************************
function timechecked(){
  form=document.forms.mainform;
  result=false;
  if (form.book_time.length>0){
    if (form.book_time) for (i=0;i<form.book_time.length;i++) if (form.book_time[i].checked) result=true;
  }else{
    result=form.book_time.checked;
  }
  return result;
}


//*************************************************************************************************************************
function check_book_date(action){
  form=document.forms.mainform;
  if (form.sdatestr.value==''){
    alert('Please, select a date');
  }else if(!timechecked()){
    alert('Please, select a valid time');
  }else if (document.getElementById('TermsOk').checked==false){
    alert('Please read and agree to the Terms & Conditions');
  }else{
    form.action.value='ClientBookAppSave';
    form.submit();
  }
}

function check_forg_passw(){
  form=document.forms.mainform;
  if(!reEmail.test(form.email.value)){
    alert('Invalid email address');
    form.email.focus();
  }else{
    form.action.value='SendPWD';
    form.submit();
  }
}
//*************************************************************************************************************************
function OpenVideo(videoid){
  X=400;
  Y=300;
  windowprops = "top="+(screen.height-Y)/2+",left="+(screen.width-X)/2+",status=no,scrollbars=no,directories=no,location=no,toolbar=no,resizable=no,menubar=no,width="+X+",height="+Y;
  window.open("video.php?videoid="+videoid,"VIDEO",windowprops);
}

//*************************************************************************************************************************
function OpenTerms(){
  X=500;
  Y=400;
  windowprops = "top="+(screen.height-Y)/2+",left="+(screen.width-X)/2+",status=no,scrollbars=no,directories=no,location=no,toolbar=no,resizable=no,menubar=no,width="+X+",height="+Y;
  window.open("terms.php","Babyvision - Terms And Conditions",windowprops);
}
