// JavaScript Document
var win_audio = null;
var isUploading = false;

function ConfirmDelete(name)
{
	if(confirm("Are you sure you want to delete '" + name + "' from the list?"))
	{
		return true;
	}
	
	return false;
}


function OpenAudioWindow(url)
{
	var parameters = "addressbar=no, statusbar=no, toolbar=no, scrollbars=yes,width=300,height=200";
	
	win = window.open(url, "Audio", parameters);
	
	if(win != null)
	{
		win.focus();
	}
	
	//return false;
}

function OpenAgreementWindow(url)
{
	var parameters = "addressbar=no, statusbar=no, toolbar=no, scrollbars=yes,width=350,height=250";
	
	win = window.open(url, "Agreement", parameters);
	
	if(win != null)
	{
		win.focus();
	}
	
	//return false;
}

function OpenCostPerHour(url)
{
	var parameters = "addressbar=no, statusbar=no, toolbar=no, scrollbars=yes,width=300,height=200";
	
	win = window.open(url, "Update", parameters);
	
	if(win != null)
	{
		win.focus();
	}
	
	//return false;
}

function OpenRemarks(url)
{
	var parameters = "addressbar=no, statusbar=no, toolbar=no, scrollbars=yes,width=350,height=280";
	
	win = window.open(url, "Remarks", parameters);
	
	if(win != null)
	{
		win.focus();
	}
	
	//return false;
}

function OpenPopupList(url)
{
	var parameters = "addressbar=no, statusbar=no, toolbar=no, scrollbars=auto,width=350,height=550";
	
	win = window.open(url, "RemarksList", parameters);
	
	if(win != null)
	{
		win.focus();
	}
	
	//return false;
}

function OpenPopupListWithSize(url, width, height)
{
	var parameters = "addressbar=no, statusbar=no, toolbar=no, scrollbars=auto,width=" + width + ",height=" + height;
	
	win = window.open(url, "PopupList", parameters);
	
	if(win != null)
	{
		win.focus();
	}
}

function BillingPhysicianDropdownChange()
{
	var combobox = document.getElementById('dropDownListPhysicians');
	var state = false;
	
	if(combobox != null && parseInt(combobox.value) == 0 )	
	{
		state = true;
	}
	
	document.getElementById('buttonSendBilling').disabled = state;
}

function SendBilling(totalAmount, physicianId)
{
	var combobox = document.getElementById('dropDownListPhysicians');
	var isFiltered = (physicianId == parseInt(combobox.value));
	
	if(!isFiltered)
	{
		alert("Unable to proceed, please press filter to refresh the data.");
		return;
	}
	
	else if(parseFloat(totalAmount) <= 0)
	{
		alert("Unable to proceed, total amount must be greater than zero.");
		return;
	}
	
	var parameters = "addressbar=no, statusbar=no, toolbar=no, scrollbars=yes,width=300,height=180";
	var url = "SendBilling.aspx?id=" + combobox.value +
			"&tamt=" + totalAmount;
			
	window.open(url, "Billing", parameters);
}

function CheckAllCheckbox()
{
	var frm = document.forms[0];
	var checkbox = frm.checkboxSelected;//document.getElementById('checkboxSelected');
	var checkState = (frm.buttonCheckAll.value.toLowerCase() == "check all");
	
	if(checkbox.value != null)
	{
		checkbox.checked = checkState;
	}
	
	else
	{
		for(i = 0; i < checkbox.length; i++)
		{
			checkbox[i].checked = checkState;
		}
	}
	
	if(checkState)
	{
		frm.buttonCheckAll.value = "Uncheck All";
		frm.buttonCheckAll2.value = "Uncheck All";
	}
	
	else
	{
		frm.buttonCheckAll.value = "Check All";
		frm.buttonCheckAll2.value = "Check All";
	}
}

function HasCheckedItem()
{
	var frm = document.forms[0];
	var checkbox = frm.checkboxSelected;// document.getElementById(checkboxName);
	
	if(checkbox.value != null)
	{
		return checkbox.checked;
	}
	
	else
	{
		for(i = 0; i < checkbox.length; i++)
		{
			if(checkbox[i].checked)
			{
				return true;
			}
		}
	}
	
	return false;
}

function HasInValidAssignedUserValue()
{
	var frm = document.forms[0];
	var checkbox = frm.checkboxSelected;//document.getElementById(checkboxName);
	var dropDown = frm.selectUsers;//document.getElementById(dropDownname);
	
	if(checkbox.value != null)
	{
		if(checkbox.checked)
		{
			if(dropDown.value == '')
			{
				alert('Unable to proceed, please select valid assigned user.');
				dropDown.focus();
				return true;
			}
			
			return false;
		}
	}
	
	else
	{
		for(i = 0; i < checkbox.length; i++)
		{
			if(checkbox[i].checked)
			{
				if(dropDown[i].value == '')
				{
					alert('Unable to proceed, please select valid assigned user.');
					dropDown[i].focus();
					return true;
				}
			}
		}
	}
	
	return false;
}

function RegularExpression(value, expression)
{
	if(expression.test(value)) return true;

	return false;
}

function IsNumericRequired(value)
{
	return RegularExpression(value, /^[0-9]+$/);	
}

function IsValidTranscriptionIdFormat(value)
{
	return value.length >= 8 && RegularExpression(value, /^[awAW][0-9]+$/);	
}

function AutoFilterClickButtonHandler(obj, e, buttonName)
{
	var key;
	var isCtrl = false;
	var keychar;
	
	if(window.event) 
	{
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	
	else if(e.which) 
	{
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for enter
	if (key == 13 )// || isCtrl)
	{
		button = document.getElementById(buttonName);

		if(button != null)
		{
			button.click();
		}
		
		return true;
	}
}

function Trim(str) 
{
  while (str.charAt(str.length - 1)==" ")
    str = str.substring(0, str.length - 1);

  while (str.charAt(0)==" ")
    str = str.substring(1, str.length);

  return str;
}

function SelectStep(stepNumber, selectedColor, unSelectedColor)
{
	//alert(stepNumber);
	for(i = 1; i <= 15; i++)
	{
		var ctrl = document.getElementById("step" + i);
		
		//alert(ctrl == null);
		
		if(ctrl != null)
		{
			
			if(i == stepNumber)
			{
				var ctrl2 = document.getElementById("step" + stepNumber);
				
				//alert(ctrl2 == null);
				//ctrl2.style = "background-color: " + selectedColor;
				
				if(ctrl2 != null)
				{
					//alert(selectedColor);
					ctrl2.style.backgroundColor = selectedColor;
				}
			}
			
			else
			{
				//alert(unSelectedColor);
			  	ctrl.style.backgroundColor = unSelectedColor;
			}
		}
	}
}

function RowHilights(ctrlid, checked, defaultcolor)
{
	var highlightColor = "#99CCFF"; //-- highlight color
   	var ctrl = document.getElementById(ctrlid);
   
   	if(ctrl == null)
   	{
		return;
	}
	
   	if(checked)
   	{
		ctrl.style.backgroundColor = highlightColor;
		return;
   	}
	
	ctrl.style.backgroundColor = defaultcolor;
}

function InitializeDownloadItems(ctrlId, hiddenCtrlId)
{
	var frm = document.forms[0];
	var ctrl = frm.checkboxBatch;//document.getElementById(ctrlId);
	var ctrlHidden = document.getElementById(hiddenCtrlId);
	var itemIds = "";
	
	if(ctrl.value != null)
	{
		if(!ctrl.checked)
		{
			alert("Unable to proceed no item(s) selected.");
			return false;
		}
		
		itemIds = ctrl.value;
		ctrlHidden.value = itemIds;
		return true;
	}
	
	//-- array checkbox
	for(i = 0; i < ctrl.length; i++)
	{
		if(ctrl[i].checked)
		{
			if(itemIds.length > 0)
			{
				itemIds = itemIds + ",";
			}
			
			itemIds = itemIds + ctrl[i].value;
		}
	}
	
	if(itemIds.length == 0)
	{
		alert("Unable to proceed no item(s) selected.");
		return false;
	}
	
	ctrlHidden.value = itemIds;
	//alert(ctrlHidden.value);
	return true;
}

function DownloadSelectedItem(ctrlId, hiddenCtrlId)
{
	if(!InitializeDownloadItems(ctrlId, hiddenCtrlId))
	{
		return false;
	}
	
	var url = "BatchDownload.aspx?bdt=" + document.getElementById(hiddenCtrlId).value;
	
	window.location = url;	
	return true;
}