// functions to check for user input before posting data to the DB's

function checkContactusForm(formname){


if(document.forms[formname].first_name.value == ""){
alert("First Name is required to submit this form.");
} else if (document.forms[formname].last_name.value == ""){
alert("Last Name is required to submit this form.");
} else if (document.forms[formname].email.value == ""){
alert("An email address is required to submit this form.");
} else if (document.forms[formname].email.value.indexOf("@") == -1){
alert("A valid email address is required to submit this form.");
} else if (document.forms[formname].email.value.indexOf(".") == -1){
alert("A valid email address is required to submit this form.");
} else if (formname!="advancelist" && document.forms[formname].note_narrow.value == ""){
alert("A message in the comments field is required to submit this form.");
} else if (document.forms[formname].HIPPA.checked == false){
alert("Check the last checkbox in order to submit this form.");
} else {
if(formname == 'contactus'){
document.forms[formname].action = "savecontactus.php";
}else if (formname == 'resources'){
document.forms[formname].action = "saveresources.php";
}else if (formname == 'requestsamples'){
document.forms[formname].action = "saverequestsamples.php";
}else if (formname == 'sharestory'){
document.forms[formname].action = "savesharestory.php";
}else if (formname == 'advancelist'){
document.forms[formname].action = "saveadvancelist.php";
}
document.forms[formname].submit();
}

//savecontactus.php
}

function closefriendsbox(){

$('friendsevite').fade({ duration: .3});


}

function openfriendsbox(){

$('friendsevite').appear({ duration: .3});


}


function sendtofriend(){



if(document.sendtofriendform.fromname.value == ""){
alert("Your Name is required to submit the send to a friend form.");
}else if (document.sendtofriendform.fromemail.value == ""){
alert("Your email address is required to submit  the send to a friend form.");
} else if (document.sendtofriendform.fromemail.value.indexOf("@") == -1){
alert("Your email address is not valid and it is required to submit the send to a friend form.");
} else if (document.sendtofriendform.fromemail.value.indexOf(".") == -1){
alert("Your email address is not valid and it is required to submit the  send to a friend form.");
}else if (document.sendtofriendform.toemail.value == ""){
alert("Your email address of your friend is required to submit the send to a friend form.");
} else if (document.sendtofriendform.toemail.value.indexOf("@") == -1){
alert("Your email address of your friend is not valid and it is required to submit the send to a friend form.");
} else if (document.sendtofriendform.toemail.value.indexOf(".") == -1){
alert("Your email address of your friend is not valid and it is required to submit the  send to a friend form.");
}else if (document.sendtofriendform.HIPPA.checked == false){
alert("Please click on the checkbox to submit the send to a friend form.");
}else{

document.sendtofriendform.sharelink.value = document.location;

$('sendtofriendformid').request({
  onComplete: function(rqst){ 
  
   if(rqst.responseText.match(/^ERROR_RECAPTCHA:/)) {
 
      // HACK: Display the error message
      if(typeof Recaptcha.old_finish_reload === 'undefined') {
         Recaptcha.old_finish_reload = Recaptcha.finish_reload;
         Recaptcha.finish_reload = function(a, b, c, d) {
            Recaptcha.old_finish_reload(a, b, c, d);
            $('recaptcha_widget_div').removeClassName('recaptcha_nothad_incorrect_sol');
            $('recaptcha_widget_div').addClassName('recaptcha_had_incorrect_sol');
         };
      }

      Recaptcha.reload();
      
      return;
   }
   
  new Effect.Fade('friendsevite', { duration: .3});
  new Effect.Appear('msgsentdialog', { duration: 1, queue: 'end' });
  new Effect.Fade('msgsentdialog', { duration: 1, queue: 'end' });
  
  // reset the form
  document.sendtofriendform.reset();

  }
});

}

}


function showeasytouse(){

$('imagepop').appear({ duration: .3});


}

function hideeasytouse(){

$('imagepop').fade({ duration: .3});


}

function openInteractive() {
   
   var URL = "ig/index.php";

   day = new Date();
   id = day.getTime();
   eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=552,height=420');");

   return false;
}

function doconversion(namepage,docnum){

if (namepage == "prescribe"){
window.frames["googstuff"].location = "dlformConvTrack.php";

setTimeout("window.location='pdf/PrescriptionForm.pdf'",500);

}

if (namepage == "resource"){

switch (docnum)
{
case 1:
window.frames["googstuff"].location = "resourcesConvTrack.php";
setTimeout("window.location='pdf/patient_trifold_brochure.pdf'",500);
break;
case 2:
window.frames["googstuff"].location = "resourcesConvTrack.php";
setTimeout("window.location='pdf/I-PortSpecifications.pdf'",500);
break;
case 3:
window.frames["googstuff"].location = "resourcesConvTrack.php";
setTimeout("window.location='pdf/PrescriptionForm.pdf'",500);
break;
case 4:
window.frames["googstuff"].location = "resourcesConvTrack.php";
setTimeout("window.location='pdf/UserGuide.pdf'",500);
break;
case 5:
window.frames["googstuff"].location = "resourcesConvTrack.php";
setTimeout("window.location='pdf/how_to_use.pdf'",500);
break;
case 6:
window.frames["googstuff"].location = "resourcesConvTrack.php";
setTimeout("window.location='pdf/patientprofile.pdf'",500);
break;
case 7:
window.frames["googstuff"].location = "resourcesConvTrack.php";
setTimeout("window.location='pdf/hcp.pdf'",500);
break;

}

}

}


function showsignup(){
$('forgotform').fade({ duration: .3});
windowshown = 0;
$('signuptxt').setStyle({
display: 'none'
});
$("errormessage").update();
$("errormsglogin").update();
$('signuptxtbox').appear({ duration: .3});

}

function hidewindow(){
$('signuptxtbox').fade({ duration: .3});
$('signuptxt').setStyle({
display: 'block'
});
}

function setusertype(lblidx){
label = document.createlearner.jtitle.options[lblidx].value;

switch(label)
{
case "caretaker":
document.createlearner.type.value = "patient";
break;
case "patient":
document.createlearner.type.value = "patient";
break;
case "doctor":
document.createlearner.type.value = "hcp";
break;
case "educator":
document.createlearner.type.value = "hcp";
break;
case "nurse":
document.createlearner.type.value = "hcp";
break;
default:

}

}

function createStudent(){

if(makesurecreateestudent()){

$('createlearner').request({
  onComplete: function(response){ 
  hidewindow();
  if(response.responseText.indexOf("success") != -1){
  // we need to add a cookie that states we login
  document.cookie="logged=1";
 fromajax = response.responseText;
 ajArray = new Array();
 ajArray = fromajax.split(" ");
 document.cookie="typ="+ajArray[1];
   // enter the reg view by reloading.
   document.createlearner.reset();
  // window.location.href = "e-detail.php";
   window.location.reload(true);
  }else if(response.responseText.indexOf("dupuser") != -1){
  
  $("errormessage").update("Your email has been registered before, if you forgot your password click on the 'Forgot password' link to get it via email.");
  $("errormessage").setStyle({
  color: 'red'
  });
  
 }

  }
});

}
}

function loginStudent(){

if(document.dologinform.email.value == "" || document.dologinform.password.value == ""){
 $("errormsglogin").update("Your username (email) or password was left empty.");

}else if(document.dologinform.email.value.indexOf("@") == -1 || document.dologinform.email.value.indexOf(".") == -1 || document.dologinform.email.value.indexOf("=") != -1 || document.dologinform.email.value.indexOf("'") != -1 ||
document.dologinform.email.value.indexOf("\"") != -1){

$("errormsglogin").update("Your username is not valid, please enter it again.");

}else{

$('dologinform').request({
  onComplete: function(responselogin){ 
  if(responselogin.responseText.indexOf("oklogin") != -1){
  
  // we need to add a cookie that states we login
  document.cookie="logged=1";
 fromajax = responselogin.responseText;
 ajArray = new Array();
 ajArray = fromajax.split(" ");
 document.cookie="typ="+ajArray[1];
   // enter the reg view by reloading.
 window.location.reload(true);
  
  }else if(responselogin.responseText.indexOf("error") != -1){
  
  $("errormsglogin").update("Your username (email) or password did not match our records.");
  
  }
  
  }
  
  })
  
  }
  

}

function reseterror(){

 $("errormsglogin").update();
 $("errormessage").update();

}

function makesurecreateestudent(){

if(document.createlearner.email.value == "" || document.createlearner.emailconf.value == "" || document.createlearner.password.value == "" || document.createlearner.firstname.value == "" || document.createlearner.lastname.value == "" || document.createlearner.jtitle.selectedIndex == 0){

$("reqlabel").update("Make sure all fields are entered.");
$("reqlabel").setStyle({
  color: 'red'
  });
  return false;

}else if(document.createlearner.email.value.indexOf("@") == -1 || document.createlearner.email.value.indexOf(".") == -1 || document.createlearner.email.value.indexOf("=") != -1 || document.createlearner.email.value.indexOf("'") != -1 ||
document.createlearner.email.value.indexOf("\"") != -1){
$("reqlabel").update("Make sure you enter a valid email.");
$("reqlabel").setStyle({
  color: 'red'
  });
 return false;
}else if(document.createlearner.email.value != document.createlearner.emailconf.value){

$("reqlabel").update("emails do not match.");
$("reqlabel").setStyle({
  color: 'red'
  });
  
  return false;
}else{
  return true;
}
 

}

windowshown = 0;
function showforgotpassform(){
if(windowshown == 0){
hidewindow();
Effect.SlideDown('forgotform', { duration: .5});
windowshown = 1;
$("textforgot").update("Enter your registered email address and we will send you the password to that address:");
$("textforgot").setStyle({
  color: '#666666'
  });
}else{
$('forgotform').fade({ duration: .3});
windowshown = 0;
}
}

function forgotpasswarn(){

$("textforgot").update("Enter your registered email address and we will send you the password to that address:");
$("textforgot").setStyle({
  color: '#666666'
  });
  
if(document.forgotpass.email.value == ""){
  
   $("textforgot").update("email field cannot be empty.");
  $("textforgot").setStyle({
  color: 'red'
  });
  
  }else{

$('forgotpassinner').request({
  onComplete: function(responseforgot){ 
  if(responseforgot.responseText.indexOf("oksent") != -1){
  
  $("textforgot").update("Your password has been sent! please check your email's inbox.");
  $("textforgot").setStyle({
  color: '#339900'
  });
  
  }else if(responseforgot.responseText.indexOf("error") != -1){
  
  $("textforgot").update("Your username (email) did not match our records.");
  $("textforgot").setStyle({
  color: 'red'
  });
  }
  
  }
  
  })
  }

}










