//doctor_admin.js
//JavaScript  functions for 3D-Eye Home v2.0 for the patient page
//Created by: Patrick Chrobak for Eyemaginations
//Created: 12/3/2007

//function to track add a doctor

function add_package_to_cart(){
	document.getElementById("packages").value =1;
}

//function to track select all conditions overiew link
var count_all_cond=0;
function trackAllClickCond(){

	document.getElementById("tracker_all_cond").value =count_all_cond+1;
	count_all_cond++;
}

//function to track select none condition overview link
var count_none_cond=0;
function trackNoneClickCond(){

	document.getElementById("tracker_none_cond").value =count_none_cond+1;
	count_none_cond++;
}

//function to track select all surgical treatments link
var count_all_surg=0;
function trackAllClickSurg(){

	document.getElementById("tracker_all_surg").value =count_all_surg+1;
	count_all_surg++;
}

//function to track select non surgical treamtments link
var count_none_surg=0;
function trackNoneClickSurg(){

	document.getElementById("tracker_none_surg").value =count_none_surg+1;
	count_none_surg++;
}

//function to track select all optical solutions link
var count_all_opt=0;
function trackAllClickOpt(){

	document.getElementById("tracker_all_opt").value =count_all_opt+1;
	count_all_opt++;
}

//function to track select none optical solutions link
var count_none_opt=0;
function trackNoneClickOpt(){

	document.getElementById("tracker_none_opt").value =count_none_opt+1;
	count_none_opt++;
}

//function to track select all contact lense link
var count_all_con=0;
function trackAllClickCon(){

	document.getElementById("tracker_all_con").value =count_all_con+1;
	count_all_con++;
}

//function to track select none contact lense link
var count_none_con=0;
function trackNoneClickCon(){

	document.getElementById("tracker_none_con").value =count_none_con+1;
	count_none_con++;
}


//function to track add a doctor
var count_add_doctor=0;
function trackAddDoctor(){

	document.getElementById("tracker_add_doctor").value =count_add_doctor+1;
	count_add_doctor++;
}


//function to track add a doctor
var count_remove_doctor=0;
function trackRemoveDoctor(){

	document.getElementById("tracker_remove_doctor").value =count_remove_doctor+1;
	count_remove_doctor++;
}

// ADS needs a single checkall/none function for patient page
// this takes a common id in the input element and a bool
function checkAll(subtopic,yesno)
{
	var frm = document.patient;
	// get the form elements
	var el = frm.elements;
	// loop through the elements by subtopic id
	for(i=0; i<el.length; i++) {
		// and check if it is a checkbox and of the selected id
		if(el[i].type == "checkbox" && el[i].id == subtopic) {
			// if it is a checkbox and you submitted yes to the function
			el[i].checked = yesno;
		}
	}
}

//for check all button under Topic "
function checkAllConditions(obj)
{
var frm = document.patient
// get the form elements
var el = frm.elements
// loop through the elements...
for(i=0;i<19;i++) {
  // and check if it is a checkbox
  if(el[i].type == "checkbox" ) {
    // if it is a checkbox and you submitted yes to the function
    if(obj == "yes")
      // tick the box
      el[i].checked = true;
    else
      // otherwise untick the box
      el[i].checked = false;
    }
  }
}


//for check all button under topic Surgical
function checkAllSurgical(obj)
{
var frm = document.patient
// get the form elements
var el = frm.elements
// loop through the elements...
for(i=19;i<38;i++) {
  // and check if it is a checkbox
  if(el[i].type == "checkbox" ) {
    // if it is a checkbox and you submitted yes to the function
    if(obj == "yes")
      // tick the box
      el[i].checked = true;
    else
      // otherwise untick the box
      el[i].checked = false;
    }
  }
}


//for check all button under topic Optical
function checkAllOptical(obj)
{

var frm = document.patient
// get the form elements
var el = frm.elements
// loop through the elements...
for(i=38;i<47;i++) {
  // and check if it is a checkbox
  if(el[i].type == "checkbox" ) {
    // if it is a checkbox and you submitted yes to the function
    if(obj == "yes")
      // tick the box
      el[i].checked = true;
    else
      // otherwise untick the box
      el[i].checked = false;
    }
  }
}

//for check all button under topic Contact
function checkAllContact(obj)
{

var frm = document.patient
// get the form elements
var el = frm.elements
// loop through the elements...
for(i=47;i<51;i++) {
  // and check if it is a checkbox
  if(el[i].type == "checkbox" ) {
    // if it is a checkbox and you submitted yes to the function
    if(obj == "yes")
      // tick the box
      el[i].checked = true;
    else
      // otherwise untick the box
      el[i].checked = false;
    }
  }
}





//checks to make sure there is at aleast one subtopic selected
function ValidateArray()
{	
	
	var chks = document.getElementsByName('video[ ]');
	var hasChecked = false;
	for (var i = 0; i < chks.length; i++)
	{
	if (chks[i].checked)
	{
	hasChecked = true;
	break;
	}
	}
	if (!hasChecked)
	{
	alert("You must select at least one sub topic.");
	return false;
	}
	return true;
}



function getProductClicked1(){

	document.getElementById("products_id").value=document.getElementById("package1").value;
	return true;
}

function getProductClicked2(){

	document.getElementById("products_id").value=document.getElementById("package2").value;
	return true;
}

function getProductClicked3(){

	document.getElementById("products_id").value=document.getElementById("package3").value;
	return true;
}



//Validate regisration page
function ValidateForm(){
	var FormComplete = true;
	var InvalidInfo = "The following information you have entered is not valid:\n\n";
	var ThereIsInvalidInfo = false;
	var ThereIsMissingInfo = false;
	var frm = document.forms.register;
	//Check for a user name:
	
	if (frm.username.value == "")
	{
		FormComplete = false;
		RequiredInfo= "username cannot be blank";
		ThereIsMissingInfo = true;
	}
	
	if (frm.password.value == "")
	{
		FormComplete = false;
		RequiredInfo= "password cannot be blank";
		ThereIsMissingInfo = true;
	}
	

	if (frm.practice_name.value == "")
	{
		FormComplete = false;
		RequiredInfo= "Practice name cannot be blank";
		ThereIsMissingInfo = true;
	}
	if (frm.salutation.value == "")
	{
		FormComplete = false;
		RequiredInfo= "Salutation cannot be blank";
		ThereIsMissingInfo = true;
	}
	if (frm.doctor_firstname.value == "")
	{
		FormComplete = false;
		RequiredInfo= "Doctor first name cannot be blank";
		ThereIsMissingInfo = true;
	}
	if (frm.doctor_lastname.value == "")
	{
		FormComplete = false;
		RequiredInfo= "Doctor last name cannot be blank";
		ThereIsMissingInfo = true;
	}
	if (frm.street_address.value == "")
	{
		FormComplete = false;
		RequiredInfo= "Address cannot be blank";
		ThereIsMissingInfo = true;
	}
	if (frm.city.value == "")
	{
		FormComplete = false;
		RequiredInfo= "City cannot be blank";
		ThereIsMissingInfo = true;
	}
	if (frm.state.value == "")
	{
		FormComplete = false;
		RequiredInfo= "State cannot be blank";
		ThereIsMissingInfo = true;
	}
	if (frm.zip.value == "")
	{
		FormComplete = false;
		RequiredInfo= "Zip code cannot be blank";
		ThereIsMissingInfo = true;
	}
	if (frm.email.value == "")
	{
		FormComplete = false;
		RequiredInfo= "Email cannot be blank";
		ThereIsMissingInfo = true;
	}
	if (frm.eula_agree.checked == false)
	{
		FormComplete = false;
		RequiredInfo= "You must agree to the EULA";
		ThereIsMissingInfo = true;
	}
	if (frm.password.value != frm.password_verify.value)
	{
		FormComplete = false;
		RequiredInfo= "Passwords do not match";
		ThereIsMissingInfo = true;
	}
	
	if (FormComplete){
		return true;
	}else{
		if(ThereIsInvalidInfo && ThereIsMissingInfo){
			alert(RequiredInfo + "\n" + InvalidInfo)
		}else if(ThereIsMissingInfo){
			alert(RequiredInfo);
		}else if(ThereIsInvalidInfo){
			alert(InvalidInfo);
		}
		return false;
	}
}

function ValidateOrderDiscs(){
	var FormComplete = true;
	var InvalidInfo = "The following information you have entered is not valid:\n\n";
	var ThereIsInvalidInfo = false;
	var ThereIsMissingInfo = false;
	var frm = document.forms.orderDiscs;
	//Check for a user name:
	
	// ADS we are using practice_id now not password
	//if (frm.password.value == "")
	//{
	//	FormComplete = false;
	//	RequiredInfo= "password cannot be blank";
	//	ThereIsMissingInfo = true;
	//}

	 if ( ( frm.packages[0].checked == false )
    && ( frm.packages[1].checked == false )
     && ( frm.packages[2].checked == false ))
    {
       FormComplete = false;
		RequiredInfo= "You Must select a Disc Package";
		ThereIsMissingInfo = true;
    }
    
	if (FormComplete){
		return true;
	
	}else{
		if(ThereIsInvalidInfo && ThereIsMissingInfo){
			alert(RequiredInfo + "\n" + InvalidInfo)
		}else if(ThereIsMissingInfo){
			alert(RequiredInfo);
		}else if(ThereIsInvalidInfo){
			alert(InvalidInfo);
		}
		return false;
	}
	
	
}

function CheckNewAccount(){
	var FormComplete = true;
	var InvalidInfo = "The following information you have entered is not valid:\n\n";
	var ThereIsInvalidInfo = false;
	var ThereIsMissingInfo = false;
	var frm = document.forms.accountinfo;
	//Check for a user name:
	
	if (frm.practice_name.value == "")
	{
		FormComplete = false;
		RequiredInfo= "password cannot be blank";
		ThereIsMissingInfo = true;
	}

	
	if (FormComplete){
		return true;
	
	}else{
		if(ThereIsInvalidInfo && ThereIsMissingInfo){
			alert(RequiredInfo + "\n" + InvalidInfo)
		}else if(ThereIsMissingInfo){
			alert(RequiredInfo);
		}else if(ThereIsInvalidInfo){
			alert(InvalidInfo);
		}
		return false;
	}
}

function popup(URI,pageTitle,width,height)
{
   window.open(URI,pageTitle,"scrollbars=1,width="+width+",height="+height);
}


//Validate regisration page
function ValidateFormBypass(){
	var FormComplete = true;
	var InvalidInfo = "The following information you have entered is not valid:\n\n";
	var ThereIsInvalidInfo = false;
	var ThereIsMissingInfo = false;
	var frm = document.forms.bypass;
	//Check for a user name:
	
	if (frm.username.value == "")
	{
		FormComplete = false;
		RequiredInfo= "password cannot be blank";
		ThereIsMissingInfo = true;
	}

	if (frm.password.value == "")
	{
		FormComplete = false;
		RequiredInfo= "password cannot be blank";
		ThereIsMissingInfo = true;
	}
	

	if (frm.practice_name.value == "")
	{
		FormComplete = false;
		RequiredInfo= "Practice name cannot be blank";
		ThereIsMissingInfo = true;
	}
	if (frm.salutation.value == "")
	{
		FormComplete = false;
		RequiredInfo= "Salutation cannot be blank";
		ThereIsMissingInfo = true;
	}
	if (frm.doctor_firstname.value == "")
	{
		FormComplete = false;
		RequiredInfo= "Doctor first name cannot be blank";
		ThereIsMissingInfo = true;
	}
	if (frm.doctor_lastname.value == "")
	{
		FormComplete = false;
		RequiredInfo= "Doctor last name cannot be blank";
		ThereIsMissingInfo = true;
	}
	if (frm.street_address.value == "")
	{
		FormComplete = false;
		RequiredInfo= "Address cannot be blank";
		ThereIsMissingInfo = true;
	}
	if (frm.city.value == "")
	{
		FormComplete = false;
		RequiredInfo= "City cannot be blank";
		ThereIsMissingInfo = true;
	}
	if (frm.state.value == "")
	{
		FormComplete = false;
		RequiredInfo= "State cannot be blank";
		ThereIsMissingInfo = true;
	}
	if (frm.zip.value == "")
	{
		FormComplete = false;
		RequiredInfo= "Zip code cannot be blank";
		ThereIsMissingInfo = true;
	}
	if (frm.email.value == "")
	{
		FormComplete = false;
		RequiredInfo= "Email cannot be blank";
		ThereIsMissingInfo = true;
	}

	if (frm.password.value != frm.password_verify.value)
	{
		FormComplete = false;
		RequiredInfo= "Passwords do not match";
		ThereIsMissingInfo = true;
	}
	if (FormComplete){
		return true;
	}else{
		if(ThereIsInvalidInfo && ThereIsMissingInfo){
			alert(RequiredInfo + "\n" + InvalidInfo)
		}else if(ThereIsMissingInfo){
			alert(RequiredInfo);
		}else if(ThereIsInvalidInfo){
			alert(InvalidInfo);
		}
		return false;
	}
}


//Validate regisration page
function EditAccountInfo(){
	var FormComplete = true;
	var InvalidInfo = "The following information you have entered is not valid:\n\n";
	var ThereIsInvalidInfo = false;
	var ThereIsMissingInfo = false;
	var frm = document.forms.EditAccount;
	//Check for a user name:
	
	if (frm.practice_name.value == "")
	{
		FormComplete = false;
		RequiredInfo= "Practice Name cannot be blank";
		ThereIsMissingInfo = true;
	}
	
	if (frm.email.value == "")
	{
		FormComplete = false;
		RequiredInfo= "Email Address Cannot be blank";
		ThereIsMissingInfo = true;
	}
	
	if (FormComplete){
		return true;
	}else{
		if(ThereIsInvalidInfo && ThereIsMissingInfo){
			alert(RequiredInfo + "\n" + InvalidInfo)
		}else if(ThereIsMissingInfo){
			alert(RequiredInfo);
		}else if(ThereIsInvalidInfo){
			alert(InvalidInfo);
		}
		return false;
	}
}
//Validate practice page
function EditPracticeInfo(){
	var FormComplete = true;
	var InvalidInfo = "The following information you have entered is not valid:\n\n";
	var ThereIsInvalidInfo = false;
	var ThereIsMissingInfo = false;
	var frm = document.forms.EditAccount;
	//Check for a user name:
	
	if (frm.display_practice.value == "")
	{
		FormComplete = false;
		RequiredInfo= "Practice Name cannot be blank";
		ThereIsMissingInfo = true;
	}
	
	if (frm.display_email.value == "")
	{
		FormComplete = false;
		RequiredInfo= "Email Address Cannot be blank";
		ThereIsMissingInfo = true;
	}
	
	if (FormComplete){
		return true;
	}else{
		if(ThereIsInvalidInfo && ThereIsMissingInfo){
			alert(RequiredInfo + "\n" + InvalidInfo)
		}else if(ThereIsMissingInfo){
			alert(RequiredInfo);
		}else if(ThereIsInvalidInfo){
			alert(InvalidInfo);
		}
		return false;
	}
}
