
function ConfirmDelete(name)
{

	var checked = 0;
	var msg = "Are you sure you want to delete this " + name + "?";
	var msg2 = "Please select a " + name + " to delete."
	
	for(var i = 0; i < window.Form1.all.length; i++ )
	{ 
		if(window.Form1.all[i].type == "checkbox" && window.Form1.all[i].checked== true)
			if ((window.Form1.all[i].id != "chkAppPrinter") && (window.Form1.all[i].id != "chkPhysicalPrinter"))
				checked = 1;
	}
	
	if (checked == 1)
		if (window.confirm(msg) == true)
			return true;
		else
		{	//uncheck selected item(s)			
			for(var i = 0; i < window.Form1.all.length; i++ )
			{ 
			if(window.Form1.all[i].type == "checkbox")
				window.Form1.all[i].checked= false;
			}
			return false;
		}
	else
		window.alert(msg2);
		return false;
}

function ConfirmDeleteContact()
{
	return window.confirm("Are you sure you want to delete selected contact?");
}

function ResetContactList()
{
	document.forms[0].txtSearchDescription.value = "";
	document.forms[0].txtSearchEmailOrFax.value = "";
	document.forms[0].txtSearchShipper.value = "";
	document.forms[0].txtSearchLastName.value = "";
	document.forms[0].txtSearchFirstName.value = "";
	document.forms[0].dlOther.selectedIndex = 0;
	document.forms[0].rdShipper.checked = true;
}

function ResetContactListRDButtons(e)
{
	
	if (e.srcElement.id == "rdKM")
	{
		document.forms[0].dlOther.selectedIndex = 0;	
		document.forms[0].txtSearchShipper.value = "";
	}
	
	if (e.srcElement.id == "rdShipper")
	{
		document.forms[0].dlOther.selectedIndex = 0;	
	}
	
	if (e.srcElement.id == "rdOther")
	{
		document.forms[0].dlOther.selectedIndex = 0;	
		document.forms[0].txtSearchShipper.value = "";
	}
	
	if (e.srcElement.id == "dlOther")
	{
		if (document.forms[0].dlOther.selectedIndex != 0)
		{
		  document.forms[0].rdOther.checked = true;
		  document.forms[0].txtSearchShipper.value = "";
		} 
	}
	//exclude tab keydown event
	if (e.srcElement.id == "txtSearchShipper" && window.event.keyCode!= 9)
	{
		document.forms[0].rdShipper.checked = true;
		document.forms[0].dlOther.selectedIndex = 0;
	}
}

function CheckDuplicatedDestination(count)
{
	if (count > 0)
		return window.confirm("The destination already exists in the database, do you want to continue to update this record?");
	else
		return true;
	
}

function ConfirmCopy()

{
	var obj = document.forms[0].cboAppUser;
	var iIndex = obj.selectedIndex;
	

	if (iIndex > 0)
	{
		return confirm("The current user security profile will be replaced by the selected user profile. Are you sure you want to continue?");
	}	
}

function ConfirmExit()
{
	if (document.forms[0].txtIsDirty.value == "Y")
	{
		return confirm("Data has been changed but not saved yet. Are you sure you want to discard all changes?");
	}
}

function ConfirmDeleteAccess()
{

	var checked = 0;
	
	for(var i = 0; i < window.Form1.all.length; i++ )
	{ 
		if(window.Form1.all[i].type == "checkbox" && window.Form1.all[i].checked== true)
			checked = 1;
	}
	
	if (checked == 1)
		if (window.confirm("Are you sure you want to continue to delete?") == true)
			return true;
		else
		{	//uncheck selected item(s)			
			for(var i = 0; i < window.Form1.all.length; i++ )
			{ 
			if(window.Form1.all[i].type == "checkbox")
				window.Form1.all[i].checked= false;
			}
			return false;
		}
	else
		return false;
}

/****** IsDirty ******/	
function IsDirty()
	{
		document.forms[0].txtIsDirty.value = "Y"; 
	}


/***The following fuction is for ContactMaintenance.aspx which resets page elements 
	depending on what radio/text box that user made change to ***/
function ReSetAllOtherFields(e)
{

	//click on KM radio button, rest all text boxes and drop down list
	if (e.srcElement.id == "rdKM")
	{
		document.forms[0].dlOther.selectedIndex = 0;
		document.forms[0].txtShipper.value="";
		document.forms[0].txtNewOthers.value="";
	}
	
	//click on Shipper radio button 
	//exclude tab keydown event
	if (e.srcElement.id == "txtShipper" && window.event.keyCode!=9)
	{	
		document.forms[0].rdShipper.checked =true;
		document.forms[0].dlOther.selectedIndex = 0;
		document.forms[0].txtNewOthers.value="";
	}
	
	//click on Shipper radio button, rest other text boxes and drop down list
	if (e.srcElement.id == "rdShipper")
	{
		document.forms[0].dlOther.selectedIndex = 0;
		document.forms[0].txtNewOthers.value="";
	}

	//type on new others text box, rest other text boxes and drop down list
	//exclude tab keydown event
	if (e.srcElement.id == "txtNewOthers" && window.event.keyCode!=9)
	{
		document.forms[0].rdOther.checked =true;
		document.forms[0].dlOther.selectedIndex = 0;
		document.forms[0].txtShipper.value="";
	}	
	
	//select on dl other drop downlist rest all text boxes 
	if (e.srcElement.id == "dlOther")
	{
		document.forms[0].rdOther.checked =true;
		document.forms[0].txtNewOthers.value="";
		document.forms[0].txtShipper.value="";
	}	
	
	//click on Other radio button, rest all text boxes and drop down list
	if (e.srcElement == "rdOther")
	{
		//document.forms[0].rdOther.checked =true;
		document.forms[0].dlOther.selectedIndex = 0;
		document.forms[0].txtNewOthers.value="";
		document.forms[0].txtShipper.value="";		
	}
	//}	
}

//the following 3 functions are for resetting ContactDistribution.aspx search text boxes
function ResetContactDistribution()
{
	document.Form1.txtLocation.value = "";
	document.Form1.txtShipper.value = "";
	document.forms[0].dlReport.selectedIndex = 0;
	document.forms[0].dlFolder.selectedIndex = 0;
}

function ReSetContactDistributionDropDown(e)
{
	//reset folder dropdown list
	if (e.srcElement.id == "dlReport")
	{
		document.forms[0].dlFolder.selectedIndex = 0;
	}	
	
	//reset report dropdown list
	if (e.srcElement.id == "dlFolder")
	{
		document.forms[0].dlReport.selectedIndex = 0;
		document.Form1.txtLocation.value = "";
		document.Form1.txtShipper.value = "";
	}	

}

//make sure that either folder or report is selected for search on contactdistribution
function VerifyContactDistributionSelection()
{

	if (document.forms[0].dlFolder.selectedIndex == 0)
		{
			window.alert("A folder must be selected in order to perform the search operation.");
			return false;
		}
}

//confirm with user when creating a distribution for report to a shipper when the report does not belong to the shipper
//example: sending BPW Ticket to CHV destination
function ConfirmAddShipperDist(s, e)
{

	if (s != document.Form1.txtContactShipperCode.value && e.checked==true)
	{
		if (s != "EVERY")
		 return confirm("You are attempting to send Shipper " + s + "'s Report to Shipper " + document.Form1.txtContactShipperCode.value + "'s Destination. Continue??");
		else
		 return confirm("You are attempting to send " + s + " Shipper's Report to Shipper " + document.Form1.txtContactShipperCode.value + "'s Destination. Continue??");		 
	}
}

//Used in CustomerNotify.aspx 
//When different file is selected, populate txtFileName box with the file name
function GetFilePath()
{
	document.forms[0].txtFileName.value = document.forms[0].MyFile.value;
}

function CheckAll()
{
	
	for(var i = 0; i < chkList.all.length; i++)
	{
	
		if(chkList.all[i].type == "checkbox")
		{
			//if (chkList.all[i].id !="chkUndoAll")
			{
				chkList.all[i].checked = true;
			}	
		}
		
		//document.forms[0].chkUndoAll.checked=false;
	}
	document.forms[0].chkAll.checked=false;
	document.forms[0].chkUndoAll.checked=false;
}

function UnCheckAll()
{
	for(var i = 0; i < chkList.all.length; i++)
	{
		//if(chkList.all[i].type == "checkbox")
		{
			chkList.all[i].checked = false;
		}
	
	}
		document.forms[0].chkAll.checked=false;
		document.forms[0].chkUndoAll.checked=false;
		
}

function ConfirmListCheck()
{
	var listchecked = 0;
	
	for(var i = 0; i < chkList.all.length; i++)
	{
		if (chkList.all[i].checked == true)
			listchecked = 1;
	}
	
	if (listchecked == 1)
		return true;	
	else
		alert("Must select at least one Distribution Category.");
		return false;
}

function ResetShortMsg()
{
	if (document.forms[0].txtMsg.value != "")
		document.forms[0].txtMsg.value = "";
	
}

function ShowHelpInstruction()
{
	var windowParams = "height=345,width=350,left=550,top=260,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no";
			
	window.open("NoteCustHelp.aspx", "Instruction", windowParams);
}


