sparoot="http://www.straine.com/";

function popUp(url) {
sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=675,height=525');
self.name = "mainWin";
}


function repclient(usr_id){
	window.location="repselect.aspx?usr_id="+usr_id;
}

function repsurvey(usr_id,survey_id){
	window.location="repselect.aspx?usr_id="+usr_id+"&survey_id="+survey_id;
}


function valNumBox( tform, curfield ) { 
 
    fieldName   = curfield; 
    fieldValue  = fieldName.value; 
    fieldLength = fieldName.value.length; 

    for( var i = 0; i < fieldLength; i++ ) { 
        var ch = fieldValue.substring( i, i + 1 ); 
        if (( ch < "0" ) || ( ch > "9" )) { 
            alert( "Please enter whole numbers only." ); 
				fieldName.value = "";
            fieldName.focus(); 
				break;
        } 
    } 
} 

function checknoempty(fld,mssg){
  if (fld.value.length < 1){
	  alert('Please enter '+mssg);
		fld.focus();
		return true;
	}
	if (fld.value == '0'){
//	  alert('Please enter '+mssg);
	  if (confirm('0 input for ' + mssg + '\nClick OK to continue, Cancel to reinput')){
		  return false;
		} else {
		  fld.focus();
		  return true;
		}
	}
}

function AnalysisWizard(){
  ok=true;
  if(document.login.username.value.length  < 1){
	  ok=false;
	  alert('Please enter an email address');
		document.login.username.focus();
	}
  if ((ok) && (document.login.password.value.length < 1)){
	  ok=false;
	  alert('Please enter a password,\nor click New User');
		document.login.password.focus();
	}
	if (ok){
    window.open(sparoot+'analysis/wizard.aspx?step=0&username='+document.login.username.value+'&password='+document.login.password.value+'&refcode='+document.login.refcode.value,'remote','top=10,left=10,width=770,height=580,scrollbars=yes,resizable=yes,status=no,menubar=no');
	}
}

function NewUser(){
  ok=true;
  if(document.login.username.value.length  < 1){
	  ok=false;
	  alert('Please enter an email address');
		document.login.username.focus();
	}
	if (ok){
    window.open(sparoot+'analysis/wizard.aspx?step=0&username='+document.login.username.value+'&password=NEW'+'&refcode='+document.login.refcode.value,'remote','top=10,left=10,width=770,height=550,scrollbars=yes,resizable=yes,status=no,menubar=no');
	}
}

function Password(){
  if(document.forgot.username.value.length  < 1){
	  ok=false;
	  alert('Please enter an email address or account id');
		document.forgot.username.focus();
	} else {
	  window.open(sparoot+'analysis/forgotpassword.aspx?emailaddy='+document.forgot.username.value,'remote','top=10,left=10,width=355,height=145,scrollbars=no,resizable=no,status=no,menubar=no');
	}
}

function Removeprac(id,num, first, last){
  if (confirm("Please Confirm: Delete "+first+" "+last+"? \n\nNOTE: Wait for window to refresh!")) {
	  window.open(sparoot+'analysis/practitioner.aspx?action=deletedentist&id='+id,'remote1','top=10,left=10,width=10,height=10,scrollbars=no,resizable=no,status=no,menubar=no');
	}
}

function Addprac(){
  ok=true;
	if (document.step1.prafirst_name.value.length < 1){
	  ok=false;
		alert('Please enter a practitioner first name');
		document.step1.prafirst_name.focus();
	}
	if ((ok) && (document.step1.pralast_name.value.length < 1)){
	  ok=false;
		alert('Please enter a practitioner last name');
		document.step1.pralast_name.focus();
	}
	if (ok){
//	  alert('Preparing to add practitioner, please press OK\n\nNOTE:This may take a little while, wait for window to refresh!');
    if (confirm("Please Confirm: Add "+document.step1.prafirst_name.value+" "+document.step1.pralast_name.value+"? \n\nNOTE: Wait for window to refresh!")) {
	    window.open(sparoot+'analysis/practitioner.aspx?action=addentist&user_id='+document.step1.user_id.value+'&pratype='+document.step1.pratype.value+'&prasalutation='+document.step1.prasalutation.value+'&prafirst_name='+document.step1.prafirst_name.value+'&pramiddle_init='+document.step1.pramiddle_init.value+'&pralast_name='+document.step1.pralast_name.value+'&usr_practice_name='+document.step1.usr_practice_name.value+'&usr_address='+document.step1.usr_address.value+'&usr_city='+document.step1.usr_city.value+'&usr_state='+document.step1.usr_state.value+'&usr_zip='+document.step1.usr_zip.value+'&usr_email='+document.step1.usr_email.value+'&usr_phone='+document.step1.usr_phone.value+'&usr_fax='+document.step1.usr_fax.value+'&usr_url='+document.step1.usr_url.value+'&usr_password='+document.step1.usr_password.value+'&usr_use_practice_name='+document.step1.usr_use_practice_name.value+'&usr_areacode='+document.step1.usr_areacode.value+'&usr_intraoralcams='+document.step1.usr_intraoralcams.value+'&usr_digiradiology='+document.step1.usr_digiradiology.value+'&usr_lasertechnology='+document.step1.usr_lasertechnology.value+'&usr_airabrasion='+document.step1.usr_airabrasion.value+'&usr_pracmgmt='+document.step1.usr_pracmgmt.value+'&usr_questionnum='+document.step1.usr_questionnum.value+'&usr_questionanswer='+document.step1.usr_questionanswer.value,'remote1','top=10,left=10,width=10,height=10,scrollbars=no,resizable=no,status=no,menubar=no');
    }			
	}
}

function step1ok(repid){
  if(hasPractitioners == false){
	  alert('Please add at least one practitioner');
		return false;
	}
//  if(document.step1.usr_digiradiology.value == '0'){
//	  alert('Please indicated wether you own digital radiography technology');
//		step1.usr_digiradiology.focus();
//		return false;
//	}
//  if(document.step1.usr_lasertechnology.value == '0'){
//	  alert('Please indicated wether you own digital laser technology');
//		step1.usr_lasertechnology.focus();
//		return false;
//	}
//  if(document.step1.usr_airabrasion.value == '0'){
//	  alert('Please indicated wether you own air abrasion technology');
//		step1.usr_airabrasion.focus();
//		return false;
//	}
//  if (checknoempty(document.step1.usr_email,'Email Address')){
//		return false;
//	} 
//	else if ((repid == '-1') && (checknoempty(document.step1.usr_password,'Password'))){
//	  return false;
//	}
//	else if (checknoempty(document.step1.usr_practice_name,'Practice Name')){
	if (checknoempty(document.step1.usr_practice_name,'Practice Name')){
	  return false;
	}
	else if (checknoempty(document.step1.usr_city,'City')){
	  return false;
	}
	else if (checknoempty(document.step1.usr_zip,'Zip Code')){
	  return false;
	}
	else if (checknoempty(document.step1.usr_areacode,'Area Code')){
	  return false;
	}
	else if (checknoempty(document.step1.usr_phone,'Phone Number')){
	  return false;
	}
//	else if ((repid == '-1') && (document.step1.usr_questionnum.value == '-1')){
//	  alert('Please Select a Password Reminder Question');
//	  return false;
//	}
//	else if ((repid == '-1') && (checknoempty(document.step1.usr_questionanswer,'Password Reminder Answer'))){
//	  return false;
//	}

	return true
}


function step2ok(){
	pctmaint = document.step2.patients_of_record.value * (parseInt(document.step2.pct_periodontal.value)/100);

	if (checknoempty(document.step2.patients_of_record,'Patients of Record')){
	  return false;
	}
	else if (checknoempty(document.step2.operatories,'Operatories')){
	  return false;
	}
	else if (checknoempty(document.step2.hygiene_appts,'Hygiene Appointments')){
	  return false;
	}
	else if (checknoempty(document.step2.est_patients_6,'Estimated Patients')){
	  return false;
	}
	else if (checknoempty(document.step2.pct_periodontal,'Percent Periodontal Maintenance')){
	  return false;
	}
	else if (checknoempty(document.step2.ar_last_month,'Accounts Recievable Balance - Last Month')){
	  return false;
	}
	else if (checknoempty(document.step2.ytd_prod_last_month,'Year to Date Prodcution - Last Month')){
	  return false;
	}
	else if (checknoempty(document.step2.mo_prod_last_month,'Monthly Production - Last Month')){
	  return false;
	}
	else if ((document.step2.is_owner.checked == false) && (checknoempty(document.step2.authorized_name,'Authorized Name'))){
	  return false;
	}
	else if (parseInt(document.step2.est_patients_6.value) > parseInt(document.step2.patients_of_record.value)){
	  if (confirm('Estimated Patients exceeds Patients of Record\nClick OK to proceed, Cancel to re-input')){
		} else {
		document.step2.est_patients_6.focus();
	  return false;
		}
	}
	else if (parseInt(document.step2.est_patients_6.value) > (parseInt(document.step2.hygiene_appts.value) * 24)){
	  if (confirm('Estimated Patients exceeds 24 * Hygiene Appts\nClick OK to proceed, Cancel to re-input')){
		} else {
		document.step2.est_patients_6.focus();
	  return false;
		}
	}
	else if (pctmaint > (parseInt(document.step2.hygiene_appts.value) * 24)){
	  if (confirm('% Periodontal Maint exceeds 24 * Hygiene Appts\nClick OK to proceed, Cancel to re-input')){
		} else {
		document.step2.pct_periodontal.focus();
	  return false;
		}
	}
/*	else if ( parseInt(document.step2.mo_prod_last_month.value) > ( parseInt(document.step2.ytd_prod_last_month.value) / parseInt(document.step2.smonth.value) ) ){
	  if (confirm('Monthly Production exceeds YTD Production / Month Ended\nClick OK to proceed, Cancel to re-input')){
		} else {
		document.step2.mo_prod_last_month.focus();
	  return false;
		}
	}*/
	
  return true;
}

function setdate(){
  document.step2.data_date.value = document.step2.smonth.value + '/01/' + document.step2.syear.value;
}


function changeCase(frmObj){
  var index;
  var tmpStr;
  var tmpChar;
  var preString;
  var postString;
  var strlen;
  tmpStr = frmObj.value;
  strLen = tmpStr.length;
  if (strLen > 0)  {
	  for (index = 0; index < strLen; index++)  {
		  if (index == 0)  {
		    tmpChar = tmpStr.substring(0,1).toUpperCase();
		    postString = tmpStr.substring(1,strLen);
		    tmpStr = tmpChar + postString; 
	    }
		  else {
			  tmpChar = tmpStr.substring(index, index+1).toUpperCase();
				preString = tmpStr.substring(0, index);
				postString = tmpStr.substring(index+1,strLen);
				tmpStr = preString + tmpChar + postString;
		  }
    }
  }
  frmObj.value = tmpStr;
}

function changeInitCase(frmObj) {
  var index;
  var tmpStr;
  var tmpChar;
  var preString;
  var postString;
  var strlen;
  tmpStr = frmObj.value;
  strLen = tmpStr.length;
  if (strLen > 0)  {
	  for (index = 0; index < strLen; index++)  {
		  if (index == 0)  {
		    tmpChar = tmpStr.substring(0,1).toUpperCase();
		    postString = tmpStr.substring(1,strLen);
		    tmpStr = tmpChar + postString; 
	    }
		  else {
			  tmpChar = tmpStr.substring(index, index+1);
			  if (tmpChar == " " && index < (strLen-1))  {
				  tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
				  preString = tmpStr.substring(0, index+1);
				  postString = tmpStr.substring(index+2,strLen);
				  tmpStr = preString + tmpChar + postString;
		    }
		  }
    }
  }
  frmObj.value = tmpStr;
}

function consultation(){
  document.msgfrm.msg.value = '           Please wait, submitting information.'
	c1 = 'usr_choice1_date='+document.form.usr_choice1_date.value+'&usr_choice1_time='+document.form.usr_choice1_time.value+'&usr_choice1_ampm='+document.form.usr_choice1_ampm.value+'&usr_choice1_timezone='+document.form.usr_choice1_timezone.value
	c2 = 'usr_choice2_date='+document.form.usr_choice2_date.value+'&usr_choice2_time='+document.form.usr_choice2_time.value+'&usr_choice2_ampm='+document.form.usr_choice2_ampm.value+'&usr_choice2_timezone='+document.form.usr_choice2_timezone.value
	c3 = 'usr_choice3_date='+document.form.usr_choice3_date.value+'&usr_choice3_time='+document.form.usr_choice3_time.value+'&usr_choice3_ampm='+document.form.usr_choice3_ampm.value+'&usr_choice3_timezone='+document.form.usr_choice3_timezone.value
	c4 = 'oldusr_choice1_date='+document.form.oldusr_choice1_date.value+'&oldusr_choice1_time='+document.form.oldusr_choice1_time.value+'&oldusr_choice1_ampm='+document.form.oldusr_choice1_ampm.value+'&oldusr_choice1_timezone='+document.form.oldusr_choice1_timezone.value
	c5 = 'oldusr_choice2_date='+document.form.oldusr_choice2_date.value+'&oldusr_choice2_time='+document.form.oldusr_choice2_time.value+'&oldusr_choice2_ampm='+document.form.oldusr_choice2_ampm.value+'&oldusr_choice2_timezone='+document.form.oldusr_choice2_timezone.value
	c6 = 'oldusr_choice3_date='+document.form.oldusr_choice3_date.value+'&oldusr_choice3_time='+document.form.oldusr_choice3_time.value+'&oldusr_choice3_ampm='+document.form.oldusr_choice3_ampm.value+'&oldusr_choice3_timezone='+document.form.oldusr_choice3_timezone.value
  window.open(sparoot+'analysis/conference.aspx?'+c1+'&'+c2+'&'+c3+'&'+c4+'&'+c5+'&'+c6,'remote1','top=10,left=10,width=10,height=10,scrollbars=no,resizable=no,status=no,menubam=no');
}

  function checkreq(formobj){
	  oktogo=true
		fieldlist=''
	  for(var i = 0; i < formobj.elements.length; i++) {
      //reset fields just in case they were flagged before
      if ((formobj.elements[i].className == 'inputdataRERR') ||(formobj.elements[i].className == 'inputdataR')){
		     formobj.elements[i].className='inputdataR'
			}
			//now checkem danno
      if (((formobj.elements[i].className == 'inputdataRERR') ||(formobj.elements[i].className == 'inputdataR')) && (formobj.elements[i].value == '')){
		     formobj.elements[i].className='inputdataRERR'
				 oktogo=false
			}
		}
		if (oktogo == false){
		  alert('Required fields are blank (highlighted in red).\nPlease fill in the required fields and resubmit')
		}
		return oktogo
	}