//Copyright, 2000-2006, Libertas Technologies, LLC. All Rights Reserved.
//Last mods 20090112 - Todd Cooper - tcooper@libertastechnologies.com - www.libertastechnologies.com
//Common Javascript Functions
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
var xcor = 0;
var ycor = 0;

function confirm_delete(){
// Last mods 10.04.004 - tbankes@libertastechnologies.com
if(confirm('Are you sure you want to delete this record?'))
	return true;
else
	return false;
}

function formatPhone(strIDName) { 
// Last mods 031222 - tbankes@libertastechnologies.com
	var objPhone = document.getElementById(strIDName); 
	var digits = objPhone.value.replace(/[^0-9]/ig, ''); 
	if (!digits) { 
		return; 
	} 
	if (digits.length == 7) { 
		objPhone.value = digits.substring(0, 3) + '-' +  
		digits.substring(3, 7); 
	} else { 
		if (digits.length == 10) { 
			objPhone.value = '(' + digits.substring(0, 3) + ') ' +  
			digits.substring(3, 6) + '-' +  
			digits.substring(6, 10); 
		} else { 
			if (digits.length == 11) { 
				objPhone.value = digits.substring(0, 1) + ' (' + digits.substring(1, 4) + ') ' +  
				digits.substring(4, 7) + '-' +  
				digits.substring(7, 11); 
			} else { 
				objPhone.value = digits; 
			}
		} 
	}
} 

function deleterecord(strTable, strColumnName, strRecordID)	{
// Last mods 10.04.004 - tbankes@libertastechnologies.com
if(confirm('Are you sure you want to delete this record?'))	{
	var cQuery = getQueryVariable('c');
	var pQuery = getQueryVariable('p');
	var idQuery = getQueryVariable('id');
	location.href='./includes/deleterecord.aspx?table=' + strTable + '&col=' + strColumnName + '&delid=' + strRecordID + '&c=' + cQuery + '&p=' + pQuery + '&id=' + idQuery;
	return true;
	}
else	{
	return false;
	}
}

function printDocument(){
// Last mods 031222 - tbankes@libertastechnologies.com
	if (window.print){
		window.print() ;
	}else{
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
		WebBrowser1.ExecWB(6, 1);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
	}
}

function faxDocument(strRecordID)	{
// Last mods 031222 - tbankes@libertastechnologies.com
	var objDocID = document.getElementById('_ctl1_txtID');
	if(objDocID.value == '')	{
		if(confirm('You must save this record prior to creating a fax document.\n\nWould you like to save this record now?')){
			varobjQuicksave = document.getElementById('_ctl1_butQuickSave');
			varobjQuicksave.click();
		}
	}
	else	{
		varFaxWindow = NewWindow('./includes/printreferenceletter.aspx?rpt=referenceletter&id=' + strRecordID, '', '600', '400', 'yes');
	}
}

function printReferralQuestionaire(strRecordID, bolBlank)	{
// Last mods 031222 - tbankes@libertastechnologies.com
	var objDocID = document.getElementById('_ctl1_txtID');
	if(objDocID.value == '')	{
		if(confirm('You must save this record prior to creating a Referral Questionaire.\n\nWould you like to save this record now?')){
			varobjQuicksave = document.getElementById('_ctl1_butQuickSave');
			varobjQuicksave.click();
		}
	}
	else	{
	    if(bolBlank == true)
		    varDocWindow = NewWindow('./includes/printreferenceletter.aspx?rpt=referralquestionaireblank&id=' + strRecordID, '', '600', '400', 'yes');
		else
    		varDocWindow = NewWindow('./includes/printreferenceletter.aspx?rpt=referralquestionaire&id=' + strRecordID, '', '600', '400', 'yes');
	}
}

function printFollowUpLetter(strRecordID)	{
// Last mods 031222 - tbankes@libertastechnologies.com
	var objDocID = document.getElementById('_ctl1_txtID');
	if(objDocID.value == '')	{
		if(confirm('You must save this record prior to creating a Followup Letter.\n\nWould you like to save this record now?')){
			varobjQuicksave = document.getElementById('_ctl1_butQuickSave');
			varobjQuicksave.click();
		}
	}
	else	{
		varDocWindow = NewWindow('./includes/printreferenceletter.aspx?rpt=referralfollowupletter&id=' + objDocID.value, '', '600', '400', 'yes');
	}
}

function printAllReferralForm(strRecordID)	{
// Last mods 031222 - tbankes@libertastechnologies.com
	var objDocID = document.getElementById('_ctl1_txtID');
	if(objDocID.value == '')	{
		if(confirm('You must save this record prior to creating a Referal Form Letters.\n\nWould you like to save this record now?')){
			varobjQuicksave = document.getElementById('_ctl1_butQuickSave');
			varobjQuicksave.click();
		}
	}
	else	{
		//varDocWindow = NewWindow('./includes/printreferenceletter.aspx?rpt=allreferralreport&id=' + objDocID.value, '', '600', '400', 'yes');
		location.href='main.aspx?c=lrisreport&report=allreferralreport&id=' + objDocID.value;
	}
}

function printMembershipDuesInvoices()	{
// Last mods 031222 - tbankes@libertastechnologies.com
	varDocWindow = NewWindow('./includes/printreferenceletter.aspx?rpt=indivdues', '', '600', '400', 'yes');
}

function printCrystalDocument()	{
// Last mods 031222 - tbankes@libertastechnologies.com
	var objTable = document.getElementById('header_table');
	var objTableSec = document.getElementById('member_menu_table');
	var objButtonFarm = document.getElementById('_ctl0_tblButtonFarm');
	objTable.style.display = 'none';
	objTableSec.style.display = 'none';
	objButtonFarm.style.display = 'none';
	printDocument();
	objTable.style.display = 'block';
	objTableSec.style.display = 'block';
	objButtonFarm.style.display = 'block';
}

function printCrystalLabels()	{
// Last mods 031222 - tbankes@libertastechnologies.com
	var objTable = document.getElementById('header_table');
	var objTableSec = document.getElementById('member_menu_table');
	var objButtonFarm = document.getElementById('_ctl0_tblButtonFarm');
	objTable.style.display = 'none';
	objTableSec.style.display = 'none';
	objButtonFarm.style.display = 'none';
	printDocument();
	//objTable.style.display = 'block';
	//objTableSec.style.display = 'block';
	//objButtonFarm.style.display = 'block';
	//history.go(-1);
	}

function printCrystalLabels3()	{
// Last mods 031222 - tbankes@libertastechnologies.com
//Currently not used
	if (document.getElementById != null) {
		var html = ''; 
		var printReadyElem = document.getElementById('_ctl0_divCrystalReport'); 
		if (printReadyElem != null) { 
			html += '<HTML><BODY>';
			html += printReadyElem.innerHTML;
			html += '</BODY></HTML>';
		}
		else { 
			alert("Could not find the printReady section in the HTML"); return; } 
		var printWin = window.open("","printSpecial"); 
		printWin.document.open(); 
		printWin.document.write(html); 
//		printWin.document.close(); 
//		printWin.print();
	}
}

function printCrystalDocument2(strPathParameters)	{
// Last mods 031222 - tbankes@libertastechnologies.com
//Currently not used
	varWindow = NewWindow('./printreportwrapper.aspx' + strPathParameters, '', '600', '400', 'yes');
}

function createRecord(strPage)	{
// Last mods 031222 - tbankes@libertastechnologies.com
	location.href='admin_index.aspx?c=' + strPage + '&p=detail&id=';
}

var win = null;
function NewWindow(mypage,myname,w,h,scroll){
// Last mods 031222 - tbankes@libertastechnologies.com
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
if(win.window.focus){win.window.focus();}
}

function updateParentPage()	{
// Last mods 031222 - tbankes@libertastechnologies.com
//parent.opener.document.getElementById("_ctl1_btnDoPostBack").click();
	parent.opener.location.href=parent.opener.document.URL;
	self.close();
}
function openDynamicDialog(intWidth, intHeight, bolCenter, strHeader, strContent)  {
// Last mods 031222 - tbankes@libertastechnologies.com
    var LeftPosition;
    var TopPosition;
    if(bolCenter)   {
        LeftPosition = (screen.width) ? (screen.width-intWidth)/2 : 0;
        TopPosition = (screen.height) ? (screen.height-intHeight)/2 : 0;
    }
    else    {
        LeftPosition = 800/2 - (intWidth/2);
        TopPosition = 768/2 - (intHeight/2) - 100;
    }
    var layer;
    if(ns4) {	
        layer = document.getElementById('dynamiccontent');
    }
    else    {
        layer = document.all['dynamiccontent'];
    }
    var strWindowContent;
    strWindowContent = '<div style="DISPLAY: inline; Z-INDEX: 100; LEFT: ' + LeftPosition+ 'px; VERTICAL-ALIGN: top; WIDTH: ' + intWidth + 'px; POSITION: absolute; TOP: ' + TopPosition + 'px; HEIGHT: ' + intHeight + 'px; BACKGROUND-COLOR: #efefef; border: solid 1px #003366; TEXT-ALIGN: left;"><table cellpadding=0 cellspacing=0 border=0 width=100%><tr><td height=20 width=' + intWidth + ' class=dynamicdialogheader>' + strHeader + '</td></tr><tr><td><div id=dynamiccontentbody class=dynamicdialogtext>' + strContent + '</div></td></tr></table></div>';
	if(ns4) {	
	layer.document.open();
	layer.document.write(strWindowContent); //write content to layer
	layer.document.close();
	layer.visibility="visible";	//change visibility to visible
	}
	else {		     
	layer.innerHTML = strWindowContent;  //write content to layer\
	//layer.style.visibility="visible";	//change visibility to visible
    }
}

function openFollowUpRangeDialog(intWidth, intHeight, bolCenter, intType)   {
// Last mods 031222 - tbankes@libertastechnologies.com
// intType = 1 for standard report, 2 = labels
    var strHeader = 'Print Follow Up Letters By ID';
    var strContent;
    strContent = '<table cellpadding=0 cellspacing=0 border=0 width=100% class=dynamicdialogtext><tr><td colspan=2>Enter the range of Referral IDs to generate referral reports for...<br/><br/></td></tr>' +
    '<tr><td>Starting with ID:</td><td><input type=text name=LRISstartid id=LRISstartid size=10 class=formField></td></tr><tr><td>End with ID:</td><td><input type=text name=LRISendid id=LRISendid size=10 class=formField></td></tr><tr><td align=center colspan=2><br/><input type=button class=button value=Submit title=butLRISRange name=butLRISRange id=butLRISRange onclick=\"launchLRISRangeReport(' + intType + ');\" style=\"width:100px;\"></td></tr></table>'
    openDynamicDialog(intWidth, intHeight, bolCenter, strHeader, strContent);
}

function launchLRISRangeReport(intType)   {
// Last mods 031222 - tbankes@libertastechnologies.com
// intType = 1 for standard report, 2 = labels
    var startID = document.forms[0].LRISstartid.value;
    var endID = document.forms[0].LRISendid.value;
    if(ns4) {	
        layer = document.getElementById('dynamiccontentbody');
    }
    else    {
        layer = document.all['dynamiccontentbody'];
    }
    layer.innerHTML = '<br/><br/><br/><div style=\"width:100%; text-align: center;\">One moment, building report...</div>';
    if(intType == 2) {
        location.href='main.aspx?c=labelreports&report=labelsreferralfollowupletterbyrange&startid=' + startID + '&endid=' + endID;
    }
    else    {
        location.href='main.aspx?c=reports&report=referralfollowupletterbyrange&startid=' + startID + '&endid=' + endID;
    }
}

function openUploadWindow(strTable, strRecordID)	{
// Last mods 031222 - tbankes@libertastechnologies.com{
	varWindow = NewWindow('includes/fileupload.aspx?table=' + strTable + '&id=' + strRecordID, '', '525', '222', 'no');
}

function submitUpload(curForm)	{
// Last mods 031222 - tbankes@libertastechnologies.com
	if(curForm.MyFile.value == '')	{
	//User has not selected a file using the upload control
		alert('You must first select a file using the \"Browse...\" button prior to clicking the \"Upload File\" button.');
		return false;
	}
	strFileName = curForm.MyFile.value;
	intCharIndex = strFileName.indexOf("#");
	intCharIndex = intCharIndex + strFileName.indexOf("&");
	intCharIndex = intCharIndex + strFileName.indexOf("/");
	if(intCharIndex>0)	{
		alert('You can not upload a file whose file name contains one or more of the following characters: #  &  /\n\nPlease rename the file prior to uploading it to the server.');
		return false;
	}
	curForm.statusbardisplay.value='Please wait, the file is being uploaded to the server...';
	bar1.showBar();
	bar1.togglePause();
	curForm.Submit1.value = 'Saving...';
	curForm.Submit1.disabled = true;
	curForm.submit();
}

function openReferralSubjectWindow(strRecordID)	{
// Last mods 031222 - tbankes@libertastechnologies.com
	var objDocID = document.getElementById('_ctl1_txtID');
	if(objDocID.value == '')	{
		if(confirm('You must save this member profile prior to adding referral subjects.\n\nWould you like to save this member profile now?')){
			varobjQuicksave = document.getElementById('_ctl1_butQuickSave');
			varobjQuicksave.click();
		}
	}
	varWindow = NewWindow('member/referralsubject.aspx?id=' + strRecordID, '', '570', '222', 'no');
}

function openArbitrationAttorneyWindow(strRecordID)	{
// Last mods 031222 - tbankes@libertastechnologies.com
	varWindow = NewWindow('member/arbitrationattorneyinformation.aspx?id=' + strRecordID, '', '570', '222', 'no');
}

function changeto(intMenuOption)	{
// Last mods 031222 - tbankes@libertastechnologies.com
	var strID = 'menutable' + eval(intMenuOption);
	identity=document.getElementById(strID);
	identity.className='membermenuhot';
}

function changeback(intMenuOption){
// Last mods 031222 - tbankes@libertastechnologies.com
	var strID = 'menutable' + eval(intMenuOption);
	identity=document.getElementById(strID);
	identity.className='membermenuselected';
}

function reload(bolIsAdmin, strURLTarget)	{
// Last mods 031222 - tbankes@libertastechnologies.com
	var varLocation = window.location.toString();
	var intLocation = varLocation.indexOf('admin');
	if(intLocation != -1)
		location.href = '../' + strURLTarget;
	else
		location.href = strURLTarget;
}
function searchbyMemberID()	{
// Last mods 11.21.004 - tbankes@libertastechnologies.com
	var fldMemberID = document.getElementById('_ctl0_MemberID').value;
	if(fldMemberID=='')	{
		alert('Please enter a Member ID prior to attempting to search by Member ID.');
		return false;
	}
	else	{
		return true;
	}
}
function searchbyMemberName()	{
// Last mods 11.21.004 - tbankes@libertastechnologies.com
	var fldMemberName = document.getElementById('_ctl0_MemberLastName').value;
	if(fldMemberName=='')	{
		alert('Please enter a last name to search for prior to attempting to search by Member Name');
		return false;
	}
	else	{
		return true;
	}
}
function searchbyMemberFirstName()	{
// Last mods 20071004 - tbankes@libertastechnologies.com
	var fldMemberName = document.getElementById('_ctl0_MemberFirstName').value;
	if(fldMemberName=='')	{
		alert('Please enter a last name to search for prior to attempting to search by Member Name');
		return false;
	}
	else	{
		return true;
	}
}
function searchbyMemberInfo()	{
// Last mods 11.21.004 - tbankes@libertastechnologies.com
	var fldMemberID = document.getElementById('_ctl0_MemberInfo').value;
	if(fldMemberID=='')	{
		alert('Please enter text to search for prior to attempting to search by Member Info.');
		return false;
	}
	else	{
		return true;
	}
}
function searchbyReferralID()	{
// Last mods 11.21.004 - tbankes@libertastechnologies.com
	var fldReferral = document.getElementById('_ctl0_ReferralID').value;
	if(fldReferral=='')	{
		alert('Please enter a Referral ID prior to attempting to search by Referral ID.');
		return false;
	}
	else	{
		return true;
	}
}
function searchbyReferralName()	{
// Last mods 11.21.004 - tbankes@libertastechnologies.com
	var fldReferral = document.getElementById('_ctl0_ReferralName').value;
	if(fldReferral=='')	{
		alert('Please enter a last name to search for prior to attempting to search by Referral Name');
		return false;
	}
	else	{
		return true;
	}
}
function searchbyReferralInfo()	{
// Last mods 11.21.004 - tbankes@libertastechnologies.com
	var fldReferral = document.getElementById('_ctl0_ReferralInfo').value;
	if(fldReferral=='')	{
		alert('Please enter text to search for prior to attempting to search by Referral Info.');
		return false;
	}
	else	{
		return true;
	}
}
function searchbyArbitrationName()	{
// Last mods 11.21.004 - tbankes@libertastechnologies.com
	var fldArbitrationSearch = document.getElementById('_ctl0_ArbitrationName').value;
	if(fldArbitrationSearch=='')	{
		alert('Please enter a Case name prior to attempting to search.');
		return false;
	}
	else	{
		return true;
	}
}
function searchbyArbitrationID()	{
// Last mods 11.21.004 - tbankes@libertastechnologies.com
	var fldArbitrationSearch = document.getElementById('_ctl0_ArbitrationID').value;
	if(fldArbitrationSearch=='')	{
		alert('Please enter a Case ID prior to attempting to search.');
		return false;
	}
	else	{
		return true;
	}
}
function searchbyArbitration()	{
// Last mods 11.21.004 - tbankes@libertastechnologies.com
	var fldArbitrationSearch = document.getElementById('_ctl0_ArbitrationInfo').value;
	if(fldArbitrationSearch=='')	{
		alert('Please enter text to search for prior to attempting to search by Arbitration Info.');
		return false;
	}
	else	{
		return true;
	}
}
function searchbyDirectoryID()	{
// Last mods 5.1.2005 - tbankes@libertastechnologies.com
	var fldMemberID = document.getElementById('_ctl0_MemberID').value;
	if(fldMemberID=='')	{
		alert('Please enter a Member ID prior to attempting to search by Directory ID.');
		return false;
	}
	else	{
		return true;
	}
}
function searchbyDirectoryName()	{
// Last mods 5.1.2005 - tbankes@libertastechnologies.com
	var fldMemberName = document.getElementById('_ctl0_MemberLastName').value;
	if(fldMemberName=='')	{
		alert('Please enter a last name to search for prior to attempting to search by Directory Name');
		return false;
	}
	else	{
		return true;
	}
}
function searchbyDirectoryInfo()	{
// Last mods 5.1.2005 - tbankes@libertastechnologies.com
	var fldMemberID = document.getElementById('_ctl0_MemberInfo').value;
	if(fldMemberID=='')	{
		alert('Please enter text to search for prior to attempting to search by Directory Info.');
		return false;
	}
	else	{
		return true;
	}
}
function displayNewWindow(objDivName, objDefaultFieldName)	{
// Last mods 090112 - tcooper@libertastechnologies.com
	var objDocID = document.getElementById('_ctl1_txtID');
	if(objDocID.value == '')	{
		if(confirm('You must save this record prior to adding this information.\n\nWould you like to save this record now?')){
			varobjQuicksave = document.getElementById('_ctl1_butQuickSave');
			varobjQuicksave.click();
		}
	}
	else	{
		var divTable = document.getElementById(objDivName); 
 		var objTableField = document.getElementById('fld' + objDivName);
		divTable.style.display = 'block';
		divTable.style.left=(document.body.clientWidth/2) - (divTable.offsetWidth/2);
		divTable.style.top=ycor - (divTable.offsetHeight/2) + 25;
		if(objDefaultFieldName)	{
		    // jtc 1/12/2009 added "if" around the following stmt:
		    if (objTableField){objTableField.focus();}
			var objDefaultField = document.getElementById(objDefaultFieldName);	
			objDefaultField.focus();
		}
	}
}//displayNewWindow
function checkForNewUserWhichWouldRequireSave()	{
// Last mods 090120 - tcooper@libertastechnologies.com
	var objDocID = document.getElementById('_ctl1_txtID');
	if(objDocID.value == '')	{
		if(confirm('You must save this record prior to adding this information.\n\nWould you like to save this record now?')){
			varobjQuicksave = document.getElementById('_ctl1_butQuickSave');
			varobjQuicksave.click();
		}
		return false;
	}
	return true;
}//checkForNewUserWhichWouldRequireSave
function cancelNewWindow(objDivName)	{
// Last mods 031222 - tbankes@libertastechnologies.com
	var divTable = document.getElementById(objDivName); 
	divTable.style.display = 'none';
}
function init() {
// Last mods 031222 - tbankes@libertastechnologies.com
	if (ns4) {document.captureEvents(Event.MOUSEMOVE);}
	document.onmousemove=mousemove;
}
function mousemove(e) {
// Last mods 031222 - tbankes@libertastechnologies.com
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		xcor = e.pageX;
		ycor = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		xcor = e.clientX + document.body.scrollLeft;
		ycor = e.clientY + document.body.scrollTop;
	}
//	status="x= "+xcor+", y= "+ycor;
}
function iPrint(ptarget) { 
// Last mods 031222 - tbankes@libertastechnologies.com
	ptarget.focus(); 
	ptarget.print(); 
} 
function getQueryVariable(variable) {
// Last mods 031222 - tbankes@libertastechnologies.com
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  alert('Query Variable: ' + variable + ' not found');
}
var dom = document.getElementById;
var iex = document.all;
var ns4 = document.layers;
function addEvent(event,method){
  this["on"+event] = method;
  if(ns4) this.captureEvents(Event[event.toUpperCase()]);
}
function removeEvent(event){
// Last mods 031222 - tbankes@libertastechnologies.com
  this["on"+event] = null;
  if(ns4) this.releaseEvents(Event[event.toUpperCase()]);
}
function getElement(name){
// Last mods 031222 - tbankes@libertastechnologies.com
  if(dom) var el = document.getElementById(name);
  else if(iex) var el = document.all[name];
  else if(ns4) var el = getLayer(name);
  el.css = ns4 ? el : el.style;
  el.getLeft = function(){return parseInt(el.css.left) || 0};
  el.getTop = function(){return parseInt(el.css.top) || 0};
  el.setLeft = function(x){el.css.left = ns4 ? x : x+"px"};
  el.setTop = function(y){el.css.top = ns4 ? y : y+"px"};
  el.moveBy = function(x,y){el.setLeft(el.getLeft()+x);el.setTop(el.getTop()+y)};
  el.moveTo = function(x,y){el.setLeft(x);el.setTop(y)};
  el.getWidth = function(){return ns4 ? el.document.width : el.offsetWidth};
  el.getHeight = function(){return ns4 ? el.document.height : el.offsetHeight};
  el.hideVis = function(){el.css.visibility = "hidden"};
  el.showVis = function(){el.css.visibility = "visible"};
  el.addEvent = addEvent;
  el.removeEvent = removeEvent;
  return el;
}
function getLayer(name, root){
// Last mods 031222 - tbankes@libertastechnologies.com
  var i, layer, found = null;
  if(!root) root = window;
  for(i = 0; i < root.document.layers.length; i++){
    layer = root.document.layers[i];
    if(layer.id == name) return layer;
    if(layer.document.layers.length) found = getLayer(name,layer);
    if(found) return found;
  }
  return null;
}

