var arr_initValue = new Array();
var arr_text = new Array();
var arr_val = new Array();
var selIndex;
setformobject();

for(i=0;i<j_objform.elements.length;i++)
{
	arr_initValue[i] = j_objform.elements[i].value
	if (j_objform.elements[i].type == "checkbox")
		arr_initValue[i] = j_objform.elements[i].checked;
	

		//'''' Set the back color for the non editable fields
		if (j_objform.elements[i].readOnly || j_objform.elements[i].disabled)
			{
				j_objform.elements[i].className = "disabledcolor"
				j_objform.elements[i].tabIndex = "-1"
			}	
		//call function on keypress	
		
		if (j_objform.elements[i].type == "text" || j_objform.elements[i].type == "select-one")
			j_objform.elements[i].attachEvent('onkeydown',BodyF3function)	

		
		//TBC ADDED BY SHWETA ON 16April 2004
		if (j_objform.elements[i].type == "text")
			if (j_objform.elements[i].value == "1/1/1900" || j_objform.elements[i].value == "01/01/1900")
				j_objform.elements[i].value = ""

			
		
		
	//insert blank record 
	/*if (j_objform.elements[i].type == "select-one")
		{
			var foundblank = 0;
			for (k=0; k<window.document.all[j_objform.elements[i].id].length;k++ )
				{
					arr_text[k] = window.document.all[j_objform.elements[i].id].options[k].text;
					arr_val[k] = window.document.all[j_objform.elements[i].id].options[k].value;
					if (arr_text[k] =="")
						foundblank = 1;
					
					if (window.document.all[j_objform.elements[i].id].options[k].selected)
						selIndex = k;
				}	
				
			if (foundblank == 0)
				{
					//selIndex = selIndex+1;
					window.document.all[j_objform.elements[i].id].length = 0
					
					opttext = ""
					val = ""
					x=new Option(opttext,val,false,false);
					window.document.all[j_objform.elements[i].id].options[window.document.all[j_objform.elements[i].id].options.length] = x
					
					for(j=0;j<arr_text.length;j++)	
						{
							if (arr_text[j] !="")
								{
									x=new Option(arr_text[j],arr_val[j],false,false);
									window.document.all[j_objform.elements[i].id].options[window.document.all[j_objform.elements[i].id].options.length] = x
									if (selIndex == j)
										window.document.all[j_objform.elements[i].id].options[j+1].selected = true;
								}
						}
				}	
	}	
	*/	
	//set background color for required field
	
	if (j_objform.elements[i].type == "text" || j_objform.elements[i].type == "select-one" || j_objform.elements[i].type == "password")
		{
			if (j_objform.elements[i].className.toUpperCase().search("REQUIRED") != -1)
				j_objform.elements[i].className = "RequiredTextColor"
		}	
				
		
}

function ChangedValue()
{
	var arr_ChangeValue = new Array()
	for(i=0;i<j_objform.elements.length;i++)
	{
		if (j_objform.elements[i].type!="hidden" && j_objform.elements[i].id != 'cmbGridRecPerPage' && j_objform.elements[i].id != 'cmbpageno')
		{
			arr_ChangeValue[i] = j_objform.elements[i].value
			if (j_objform.elements[i].type == "checkbox")
				arr_ChangeValue[i] = j_objform.elements[i].checked
		
			if (arr_ChangeValue[i] != arr_initValue[i])
				return true;
		}
	}
	return false;
}	


function confirmsave()
{
	/*if(arr_initValue.length > 0)
	{
		if(ChangedValue() == true)
		{
			if(confirm(msg_data_mod) == true)
				return true;
		}//ChangedValue
	}//if(arr_initValue.length > 0)
	*/
	return false;	
}



//This function sets height and width of div and frame			
//objName = div/frame id
//sheight = optional default height (0.46)
//swidth = optional default width (0.75)
function setWidthHeight(objName,sheight,swidth)
{
	if(sheight !="")
		window.document.all[objName].style.height = sheight*screen.availHeight 
	else
		window.document.all[objName].style.height = 0.51*screen.availHeight 	
	
	if(swidth !="")
		window.document.all[objName].style.width=swidth*screen.availWidth			
	else
		window.document.all[objName].style.width=0.75*screen.availWidth				
	
}


function WindowKeyDown() 
{
	
	//for company ID secreen only ++++++++++ window.location.href.search("COMPANYID")
	//if (!window.document.all["g_frmmain"] || window.location.href.search("COMPANYID") > 0 || window.location.href.search("BRW") >  0 )
	//	return false;
	
	var fAlt	= window.event.altKey;
	var fCtrl	= window.event.ctrlKey;
	var fShift	= window.event.shiftKey;
	var retVal
    var iKey  = window.event.keyCode;
    var g_NextControlName = "";
   
	if (window.event.ctrlKey)
		{
			retVal = "Ctrl" + iKey.toString();
		}	
		
		if (retVal == "Ctrl65" || retVal == "Ctrl97")
			{
				ShowMaintainFiles()
				return false;
			}	
			
    if ((window.event.keyCode >= 112) && (window.event.keyCode <= 123)) 
		{
			iKey = iKey-111;
			
			retVal = "F" + iKey.toString();
			if (retVal == "F3")
				{
					/*if (window.document.all["bodyid"].id == "bodyid" && event.srcElement.id == "")
						{
							browseclicked()
							window.event.returnValue = false;
							window.event.keyCode = retVal;			
							return false;
						}
					*/
					if (window.document.all[event.srcElement.id])
						if (window.document.all[event.srcElement.id].nextSibling)
							{
								g_NextControlName = window.document.all[event.srcElement.id].nextSibling.tagName
								searchlookup = window.document.all[event.srcElement.id].nextSibling.id
							}	
						
					if (g_NextControlName != "" && g_NextControlName != undefined && searchlookup.search("lookup") > 0)
						{
							g_NextControlName = g_NextControlName.toUpperCase()
							if (g_NextControlName.search("IMG") > -1)
								zoomclick(event.srcElement.id)
						}	
					else
						browseclicked()
						
					window.event.returnValue = false;
					window.event.keyCode = retVal;			
				}
			
		}
	else
		{
			window.event.returnValue = true	
			return false;
		}	
		
}
function BodyF3function()
{
	//Key Code
	//  114 -  F3   
	if (event.keyCode == 114)
		WindowKeyDown()
		
}


function OnBodyKeyDown()
{
	//Key Code
	//  114 -  F3   
	
	if (event.keyCode == 114 || event.keyCode == 17)
		WindowKeyDown()
		
		
}
//
function ShowMaintainFiles(cntid)
{
	//if security level is M/L then return
	//alert(window.parent.parent.frames[1].document.all["hd_securitylevel"].value.toUpperCase())
	if (window.parent.parent.frames[1])
		if (window.parent.parent.frames[1].document.all["hd_securitylevel"].value.toUpperCase() !="H")
			return false;
	
	if (arguments.length > 0)
		{
			cntid = cntid.toUpperCase()
			srcID = event.srcElement.id.toUpperCase()
			if (srcID == "G_BTNMAINTAIN")
				srcID = cntid
		}		
	else
		srcID = event.srcElement.id.toUpperCase()	
	//alert('srcID = ' + srcID)
	//Switch case is used for maintains files for all the pages
	
	if (srcID)
		{
		
			//Commodity Code PopUp
			if (srcID.search("_COMM") > 0)
				openDialog("../MasterFiles/commodity.aspx","560","390")
				
			//Location Popup OR RECEIVING Plant Code
			if (srcID.search("_LOC") > 0 || srcID.search("_RECVGPLANTCODE") > 0) 
				openDialog("../MasterFiles/LocationMaster.aspx","730","450")	
				
			//Owner Popup 
			if (srcID.search("_OWN") > 0 || srcID.search("_OWNERCODE") > 0) 
				openDialog("../MasterFiles/OwnerMaster.aspx","730","450")	
			
				
			//Unit of Measure Master	
			if (srcID.search("_UOM") > 0)
				openDialog("../MasterFiles/UOM.aspx","450","200")
				
			//Consignment Location Master	
			if (srcID.search("_CONS") > 0)
				openDialog("../MasterFiles/ConsignmentMaster.aspx","606","375")			
			
			//Contact Maintenance Master Screen
			if (srcID.search("_CUST") > 0)
				openDialog("../Contacts/ContactMaintenance.aspx","710","455")			
			
			//User Maintenance Master
			if (srcID.search("_USR") > 0 || srcID.search("_ORIGINATOR") > 0)
				openDialog("../MasterFiles/Users.aspx","500","320")
				
			//Commodity category Master
			if (srcID.search("_CATEGORY") > 0 || srcID.search("_ORIGINATOR") > 0)
				openDialog("../MasterFiles/CommodityCategory.aspx","500","180")	
				
			//Company Master
			if (srcID.search("_COMP") > 0 || srcID.search("_ORIGINATOR") > 0)
				openDialog("../MasterFiles/CompanyMaster.aspx","500","300")		
				
			//Division Master
			if (srcID.search("_DIV") > 0 || srcID.search("_ORIGINATOR") > 0)
				openDialog("../MasterFiles/Division.aspx","500","170")			

			//Freight Master Screen
			if (srcID.search("_PRONUMBER") > 0)
				openDialog("../MasterFiles/FreightInfo.aspx","630","355")			
				
		}		
		
}			

//search
function goclicked(fwhere)
{
	var searchcriteria = false;
	var popupcom = false;
	setformobject()
	//event.srcElement.disabled = true;
	for(i=0;i<j_objform.elements.length-1;i++)
	{
		if (j_objform.elements[i].type == "text" || j_objform.elements[i].type == "select-one")
			if (j_objform.elements[i].value != "")
				searchcriteria = true	
	}
	
	
	if (fwhere != 'all' && searchcriteria == true)
		j_objform.g_hd_submitmode.value = "searchcriteria";
	else
		{
			j_objform.g_hd_filter.value = ""		
			for(i=0;i<j_objform.elements.length-1;i++)
				{
					
					if (j_objform.elements[i].type == "text" || j_objform.elements[i].type == "select-one")
						j_objform.elements[i].value = ""
				}
			if (j_objform.g_hd_submitmode.value == "clear")
				j_objform.g_hd_pagesize.value = "10"
			else
				{
					if (searchcriteria == false)
						j_objform.g_hd_pagesize.value = "10"		
					else	
						{
							j_objform.g_hd_submitmode.value = "";	
							j_objform.g_hd_pagesize.value = "All"	
						}	
				}	
		}	
		
	j_objform.submit();
}

function ClearSearch()
{
	for(i=0;i<j_objform.elements.length-1;i++)
	{
		if (j_objform.elements[i].type == "text")
			j_objform.elements[i].value = ""
		if (j_objform.elements[i].type == "select-one")	
			j_objform.elements[i].value = -1
	}
	j_objform.g_hd_submitmode.value	 = "clear"
		
}


if(j_objform.g_hd_submitmode)
	if (j_objform.g_hd_submitmode.value == "searchcriteria")
		window.document.all["imgadd"].style.display = ""
		
// show the message	

if (window.document.all["g_lbl_error"])
	{
			if (window.document.all["g_lbl_error"].innerText !="")
				{
					
					window.document.all["g_lbl_error"].style.display = "none"
					alert(window.document.all["g_lbl_error"].innerText)
					if (window.document.all["g_lbl_error"].innerText.toUpperCase().search("ACCESS TO THIS OPTION") > 0)
						window.location.href = "../Inventory/UsedComEqp.aspx"
				}	
	}	



//help
var hlpfromwhere
function showContextHelp()
{
	url = "../common/irshelp.aspx?fromwhere="+hlpfromwhere
	window.showHelp(url)
}

function showNoHelp()
{
	window.showHelp("../common/nohelp.htm");
}

function fnOnHelp()
{
	if (event)
		window.event.returnValue = false
	showContextHelp()
}

