var message="Function Disabled";
//for disabling right click action on a from
var oLastBtn=0;
	bIsMenu = false;
	//No RIGHT CLICK************************
	// ****************************
	if (window.Event) 
	document.captureEvents(Event.MOUSEUP); 
	function nocontextmenu()
	{ 
	event.cancelBubble = true 
	event.returnValue = false; 
	return false; 
	} 

	function norightclick(e) 
	{ 
	if (window.Event) 
	{ 
	if (e.which !=1) 
	return false; 
	} 
	else{//alert("aa"); //alert(event.button); 
	if (event.button !=1) 
	{ 
	event.cancelBubble = true 
	event.returnValue = false; 
	return false; 
	} }
	} 

	//remove the comments for the below 2 statements
	document.oncontextmenu = nocontextmenu; 
	document.onmousedown = norightclick; 

	//**************************************
	// ****************************
	// Block backspace onKeyDown************
	// ***************************


    	function onKeyDown() {
    		if ( (event.altKey) || ((event.keyCode == 8) && 
    				(event.srcElement.type != "text" &&
    				event.srcElement.type != "textarea" &&
    				event.srcElement.type != "password")) || 
    				((event.ctrlKey) && ((event.keyCode == 78) || (event.keyCode == 82)) ) ||
           			(event.keyCode == 116)|| (event.shiftKey && ((event.keyCode == 51) || 
				(event.keyCode == 53) || 
				(event.keyCode == 54) || (event.keyCode == 55) || 
				(event.keyCode == 188) || (event.keyCode == 190) || 
				(event.keyCode == 191) || (event.keyCode == 222))) || (event.keyCode == 192) || 
				((event.keyCode >=112) && (event.keyCode <=123)) ) {
        			event.keyCode = 0;
        			event.returnValue = false;
        		}
        	}

document.onkeydown = onKeyDown;
//To limit the maxlength of a textarea


//BugFix. This function uses field.select(). This causes the system to select both the fields, 
//the one that it is navigating from and the other that it is navigting to. This happens because
//this function (or validation of max length) is done in the OnBlur event.
function textAreaMaxLen(field,maxlength)
{
	if(field.value.length > parseInt(maxlength))
	{
		alert ("You can enter upto " + maxlength + " characters only...")
		//BugFix.b Deleted
		//field.select();
		//BugFix.e
		return false;
	}
	return true;
}

//For validating a field which is of money type
function MoneyValidation(msg,txtMoney)
{
	var txtVal;
	var varRoundValue;
	var nextval;
	var nextval1;
	var nextval2;
	var nextval3;
	var nextval4;
	var pos;
	var nextpos;
	txtVal = txtMoney.value;
	if(isNaN(txtVal))
	{
		alert(msg+ " must be numeric");
		txtMoney.select();
		txtMoney.focus();
		return false;
	}
	if(txtVal == "")
	{
		txtMoney.value='0.00'
		return
	}
	if(textTrim(txtVal)=="")
	{
		alert(msg+ " must be numeric");
		txtMoney.select();
		txtMoney.focus();
		return false;
	}
	txtVal = parseFloat(txtMoney.value);
	if(txtVal>922337203685477.5807)
	{
		alert("Value is too big");
		txtMoney.select();
		txtMoney.focus();
		return false;
	}
	txtMoney.value = parseFloat(txtMoney.value);
	txtVal = txtVal.toString();
	if(txtMoney.value==0)
	{
		txtMoney.value = "0.00"
		return
	}
	if(txtVal<0)
	{
		alert(msg+ " cannot be negative");
		txtMoney.select();
		txtMoney.focus();
		return false;
	}
	pos = (txtVal.toString()).indexOf(".");
	if(pos==-1)
	{
		txtMoney.value = txtMoney.value + ".00";
	}
	if(pos>-1)
	{
		nextval = txtVal.substring(parseInt(pos)+1);
		nextpos = (nextval.toString()).indexOf(".");
		if(nextpos>-1)
		{
			alert("Invalid Value");
			txtMoney.value = "";
			txtMoney.select();
			txtMoney.focus();
			return false;
		}
		nextval1 = txtVal.substring(parseInt(pos)+2);
		nextval2 = txtVal.substring(parseInt(pos)+3);
		if(txtVal.substring(parseInt(pos)+1)=="")
		{
			txtMoney.value = txtMoney.value + "00";
		}
		else if(nextval1=="")
		{
			txtMoney.value = txtMoney.value + "0";
		}
		else if(nextval2=="")
		{
		}
		else if(nextval2!="") 
		{
			alert("You cannot enter more then 2 decimal places");
			txtMoney.select();
			txtMoney.focus();
			return false;
		}
	}
}

//To round a given value to 2digits
function roundValue(ValToRound)
{
	var txtVal = "";
	var varRoundValue = "";
	var nextval2 = "";
	var nextval3 = "";
	var nextval4 = "";
	var pos = "";
	
	txtVal = parseFloat(ValToRound);
	txtVal = txtVal.toString();
	pos = (txtVal.toString()).indexOf(".");
	if (parseInt(pos)== -1)
	{
		txtVal = txtVal + ".00";
		ValToRound = txtVal;
		return ValToRound.toString();	
	}
	else
	{
		nextval2 = txtVal.substring(parseInt(pos)+1);
		if(nextval2=="")
		{
			txtVal = txtVal + "00";
			ValToRound = txtVal;
			return ValToRound.toString();	
		}
		nextval3 = txtVal.substring(parseInt(pos)+2);
		if(nextval3=="")
		{
			txtVal = txtVal + "0";
			ValToRound = txtVal;
			return ValToRound.toString();	
		}
		nextval4 = txtVal.substring(parseInt(pos)+3);
		if(nextval4=="")
		{
			return ValToRound.toString();	
		}
		if(nextval4>4)
		{
			txtVal = txtVal.substring(0,parseInt(pos)+3);
			txtVal = parseFloat(txtVal) + parseFloat(0.01);
			ValToRound = txtVal;
			return ValToRound.toString();	
		}
		if(nextval4<4)
		{
			txtVal = txtVal.substring(0,parseInt(pos)+3);
			ValToRound = txtVal;
			return ValToRound.toString();	
		}
	}
}
//For validating a field which is of integer type
function IntValidation(msg,txtMoney)
{
	var txtVal;
	var pos;
	txtVal = txtMoney.value;
	if(isNaN(txtVal))
	{
		alert(msg+ " must be numeric");
		txtMoney.value = "";
		txtMoney.select();
		txtMoney.focus();
		return false;
	}
	if(txtVal<0)
	{
		alert(msg+ " cannot be negative");
		txtMoney.select();
		txtMoney.focus();
		return false;
	}
	pos = (txtVal.toString()).indexOf(".");
	if(pos>-1)
	{
		alert("Invalid Value");
		txtMoney.value="";
		txtMoney.focus();
		return false;
	}
}
//This function is used to trim a given value
function textTrim(mydata) 
{ 
	while(mydata.charAt(0)==" ") 
	{
		mydata=mydata.substring(1,mydata.length) 
	} 
	while(mydata.charAt(mydata.length-1)==" ") 
	{
		mydata=mydata.substring(0,mydata.length-1) 
	}
	return mydata;  
}

//For validating a field which is of money type and allows negative values
function NegativeMoneyValidation(msg,txtMoney)
{
	var txtVal;
	var varRoundValue;
	var nextval;
	var nextval1;
	var nextval2;
	var nextval3;
	var nextval4;
	var pos;
	var nextpos;
	txtVal = txtMoney.value;
	if(isNaN(txtVal))
	{
		alert(msg+ " must be numeric");
		txtMoney.select();
		txtMoney.focus();
		return false;
	}
	
	if(txtVal == "")
	{
		alert(msg + " Can not be Empty")
		return false;
	}
	
	if(textTrim(txtVal)=="")
	{
		alert(msg+ " must be numeric");
		txtMoney.select();
		txtMoney.focus();
		return false;
	}
	txtVal = parseFloat(txtMoney.value);
	if(txtVal>922337203685477.5807)
	{
		alert("Value is too big");
		txtMoney.select();
		txtMoney.focus();
		return false;
	}
	txtMoney.value = parseFloat(txtMoney.value);
	txtVal = txtVal.toString();
	if(txtMoney.value==0)
	{		
		txtMoney.value = "0.00"		
		return;
	}
	pos = (txtVal.toString()).indexOf(".");
	if(pos==-1)
	{
		txtMoney.value = txtMoney.value + ".00";
	}
	if(pos>-1)
	{
		nextval = txtVal.substring(parseInt(pos)+1);
		nextpos = (nextval.toString()).indexOf(".");
		if(nextpos>-1)
		{
			alert("Invalid Value");
			txtMoney.value = "";
			txtMoney.select();
			txtMoney.focus();
			return false;
		}
		if(txtVal.substring(parseInt(pos)+1)=="")
		{
			txtMoney.value = txtMoney.value + "00";			
		}
		nextval1 = txtVal.substring(parseInt(pos)+2);
		if(nextval1=="")
		{	
			txtMoney.value = txtMoney.value + "0";
			
		}
		nextval2 = txtVal.substring(parseInt(pos)+3);
		if(nextval2=="")
		{		
		}
		else
		{
			x = parseInt(txtVal.substring(parseInt(pos)+1))
			if(x==0)
			{				
			}
			else
			{
				alert("You cannot enter more then 2 decimal places");
				txtMoney.select();
				txtMoney.focus();
				return false;
			}
		}
	}
}



// ### Following is the code for opening frameless calender 

var windowW=190 // wide
var windowH=205 // high

// set the title of the page

var title =  "CALENDAR"

// set this to true if the popup should close
// upon leaving the launching page; else, false

var autoclose = true

// ============================
// do not edit below this line
// ============================

s = "width="+windowW+",height="+windowH;
var beIE = document.all?true:false

function OpenCalender(fld_name){
	var urlPop = "Calendar.asp" + "?fld_name=" + fld_name
	if(beIE)
	{
		

		NFW=window.open(urlPop,"popWindow","scrollbars=no,"+s)
		//NFW.blur()
		window.focus() 
		//NFW.resizeTo(windowW,windowH)
		NFW.moveTo(windowX,windowY)

	/*	NFW = window.open("","popFrameless","fullscreen,"+s)     
		//NFW.blur()
		window.focus()       
		NFW.resizeTo(windowW,windowH)
		NFW.moveTo(windowX,windowY)
		var frameString=""+
					"<html>"+
					"<head>"+
					"<title>"+title+"</title>"+
					"</head>"+
					"<frameset rows='*,0' framespacing=0 border=0 frameborder=0>"+
					"<frame name='top' src='"+urlPop+"' scrolling='no'>"+
					"<frame name='bottom' src='about:blank' scrolling='no'>"+
					"</frameset>"+
					"</html>"
		NFW.document.open();
		NFW.document.write(frameString)
		NFW.document.close() */
	}else {
		NFW=window.open(urlPop,"popFrameless","scrollbars,"+s)
		//NFW.blur()
		window.focus() 
		NFW.resizeTo(windowW,windowH)
		NFW.moveTo(windowX,windowY)
	}   
	NFW.focus()   
	if (autoclose){
    window.onunload = function(){NFW.close()}
  }
}





//### following function is used to build the field name when fields are in array

/*	function rtn_index(i)
	{
		var count=frmSaleMast.count.value
		if (count>1)
		{
			index= "[" + i + "]"
		}else
		{
			index=""
		}
		return index
	} */

//## following function is used to change the date format from dd/mm/yyyy to mm/dd/yyyy 

	function FormatDate(varDate)
	{
		pos = varDate.indexOf("/");
		varDay = varDate.substring(0,pos);
		pos1 = varDate.lastIndexOf("/");
		varMonth = varDate.substring(pos+1,pos1);
		varYear = varDate.substring(pos1+1);
		varNewDate = varMonth+"/"+varDay+"/"+varYear

		return varNewDate
	}
	
//## Following function is used to for keeping child window always on top of parent (No minimise)
//## Calling event onFocus="Focus_editWindow();" onactivate="Focus_editWindow();" onunload="window_onunload();"
var editWindow = null
var WaitDialog = null
var editWindow_1 = null
function Focus_editWindow()
{
	if (editWindow_1 && !editWindow_1.closed) 
	{
		editWindow_1.focus(); 
	}
	if (editWindow && !editWindow.closed) 
	{
		editWindow.focus(); 
	}
	if(top.menu)
	{
		if(top("menu").WaitDialog && !top("menu").WaitDialog.closed)
		{
			top("menu").WaitDialog.focus(); 
		}
	}
}

//## Following function closes the child window if parent window is closed
//## Calling  onunload="window_onunload();"

function window_onunload()
{
	if(editWindow_1 && !editWindow_1.closed) 
	{
		editWindow_1.close();
	}
	if(editWindow && !editWindow.closed) 
	{
		editWindow.close();
	}
	if(top.menu)
	{
		if(top("menu").WaitDialog && !top("menu").WaitDialog.closed)
		{
			top("menu").WaitDialog.close()
		}
	}
}

//## Following function is used to close a Wait Dialog window while background form has finished processing
//## fucntion call - onload
function closeWaitDialog()
{
	if(top("menu").WaitDialog && !top("menu").WaitDialog.closed)
	{
		top("menu").WaitDialog.close()
	}
}

//## Following function is used to remove the leading or trailing space from a string

function textTrim(mydata) 
{ 
	while(mydata.charAt(0)==" ") 
	{
		mydata=mydata.substring(1,mydata.length) 
	} 
	while(mydata.charAt(mydata.length-1)==" ") 
	{
		mydata=mydata.substring(0,mydata.length-1) 
	}
	return mydata;
	event.cancelBubble = true
}


/*function OpenCalender(objInput)

{
	var strReturn = "" 
	
	var objCtrl = eval("document.forms[0]." + objInput) ;
	strReturn =  window.showModelDialog( "./Calendar.asp?fld_name="+ objInput , " ", "dialogHeight: 231px; dialogWidth:214px; center: Yes; help: No; resizable: No; status: No; border: 0");
	
	
	if( (strReturn != "") && (strReturn != undefined) )
	{
		objCtrl.value = strReturn ;
		
		if( objCtrl.disabled == false )
		objCtrl.focus();
	}	

}*/

//E00126.B this function returns the report name as current date time string
function rtn_report_name()
{
	var dt = new Date()
	rpt_name = dt.getDate() + "" + (parseInt(dt.getMonth()) + 1) + "" + dt.getFullYear() + "" + dt.toLocaleTimeString()
	rpt_name = rpt_name.replace(" ","")
	rpt_name = rpt_name.replace(":","")
	rpt_name = rpt_name.replace(":","")
	return rpt_name
}
//E00126.E

//E00131.B
function chkChar(FldName, FldText)
{
	val=FldName.value
	if(val.indexOf(",") != -1)
	{
		alert("The character comma (,) is not allowed in " + FldText + ".")
		FldName.focus();
		return false;
	}		
}
//E00131.E
