var cancelStatus='FALSE';
var saveStatus='FALSE';
var isValidationApplicable='TRUE';
var isValidatingOtherField='FALSE';
var isValidatingWhichField='';
var isValidatingWhichFieldID='';
var validationColor='yellow';
var normalColor='white';

//Trim Function
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

// -- Blank Validation
//The third Field is not mandatory, but if one wants that the focus should go to any other field than cont
//Modified by Chirantan
function blankValidation(cont,msgField,strForceFocus){
	var i=0;
	var sText;
	sText=cont.value;
	sText = sText.replace(/^\s*|\s*$/g,"");
	if (sText == ""){
		alert(msgField + " cannot be blank !");
		if(eval(strForceFocus)){
			eval(strForceFocus+'.focus()');
		}else{
			cont.focus();
		}
		return false;
	}
	return true;
}

// -- Blank Validation combo box (Text)
function blankComboValidation(cont,msgField){
var i=0;
var sText;
sText=cont.options(cont.selectedIndex).text;
sText = sText.replace(/^\s*|\s*$/g,"");

if (sText == ""){
	alert(msgField + " cannot be blank !");
	cont.focus();
	return false;
}
return true;
}

// -- Blank Validation combo box (First Blank Select)
function blankComboIndex(cont,msgField){
	if (cont.selectedIndex == 0){
		alert("Please select " + msgField + " !");
		cont.focus();
		return false;
	}
	return true;
}


// -- Date Validation
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++){
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function isDateddmmyyyy(dtStr,msg){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(0,pos1)
	var strYear=dtStr.substring(pos2+1)
	
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		if(eval(msg)) alert(msg + ": The date format should be : dd/mm/yyyy");
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		if(eval(msg)) alert(msg + ": Please enter a valid month");
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		if(eval(msg)) alert(msg + ": Please enter a valid day");
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		if(eval(msg)) alert(msg + ": Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		if(eval(msg)) alert(msg + ": Please enter a valid date");
		return false
	}
return true
}
function doDateCheck(from, to,msgText) {
	if (Date.parse(from) <= Date.parse(to)) {
		return true;
	}
	else {
		if (from == "" || to == "") 
			alert("Both dates must be entered.");
		else 
			alert(msgText);
			return false;
	}
	return true;
}

function doDateCheck_ddmmyyyy(from, to,msgText) {
	//change the dd/mm/yyyy to mm/dd/yyyy
	//change from date in proper format
	var pos1=from.indexOf(dtCh)
	var pos2=from.indexOf(dtCh,pos1+1)
	
	var strMonthFrom=from.substring(pos1+1,pos2)
	var strDayFrom=from.substring(0,pos1)
	var strYearFrom=from.substring(pos2+1)
	
	//change from date in proper format
	pos1=to.indexOf(dtCh)
	pos2=to.indexOf(dtCh,pos1+1)
	
	var strMonthTo=to.substring(pos1+1,pos2)
	var strDayTo=to.substring(0,pos1)
	var strYearTo=to.substring(pos2+1)


	if (Date.parse(strMonthFrom+"/"+strDayFrom+"/"+strYearFrom) <= Date.parse(strMonthTo+"/"+strDayTo+"/"+strYearTo)) {
		return true;
	}
	else {
		if (from == "" || to == "") 
			alert("Both dates must be entered.");
		else{ 
			//if(eval(msgText)) 
			alert(msgText);
		}
		return false;
	}
	return true;
}

//E-mail validation
function checkEmail(emailAddr) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailAddr.value)){
		return (true)
	}
	alert("Invalid Email Address Format")
	//emailAddr.focus();
	return (false)
}

function isEmail(emailAddr) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailAddr)){
		return (true)
	}
	alert("Invalid Email Address Format")
	//emailAddr.focus();
	return (false)
}

function IsNumeric(s){
	var i,b;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9")) && (c != ".")) return false;
    }
    // All characters are numbers and ".".
    return true;
}

//Restrict maxlength of a TEXTAREA
//ErrorMessage="The maximum allowance of 40 characters has been reached."
function LimitMultiLineLength(obj)
{
	/*
	var iKey;
	var eAny_Event = window.event;
	iKey = eAny_Event.keyCode;
	var re 
	re = new RegExp("\r\n","g")  
	x = obj.value.replace(re,"").length ;
	if ((x >= obj.maxLength) && ((iKey > 33 && iKey < 255) || (iKey > 95 && iKey < 106)) && (iKey != 13))
	{
	if (obj.ErrorMessage )
	{
	alert(obj.ErrorMessage);
	}
	window.event.returnValue=false;      
	}
	*/
	//Modified by Sandeep Ghosh on 08 june 2006
	try{
		var x = obj.value.length;
		iKey = window.event.keyCode;
		
		//Modified by Chirantan
		if(iKey==13) return;
		
		if (x >= obj.maxLength){
			if (obj.ErrorMessage ){
				alert(obj.ErrorMessage);
			}
			window.event.returnValue=false;
		}
		
		if (window.event.type=='beforepaste'){
			var cbData = window.clipboardData.getData('Text');
			var re = new RegExp("\r\n","g");
			cbData=cbData.replace(re," ");
			re = new RegExp("\"","g");
			cbData=cbData.replace(re, " ");
			re = new RegExp("\'","g");
			cbData=cbData.replace(re, " "); 
			var b=window.clipboardData.setData('Text',cbData.substring(0,obj.maxLength-x));
			window.event.returnValue=false;
		}
	}catch(exception){
		
	}
}
function restrictToInteger(){
	var theObject;
	var objValue='';
	theObject=event.srcElement;
	objValue=theObject.value.toString();
	if (event.keyCode > 47 && event.keyCode < 58){
		if(event.keyCode==47){
			event.returnValue = false;
			return
		}
		event.returnValue = true;
	}else{
		event.returnValue = false;
	}
}

function restrictToNumeric(){
	var theObject;
	var objValue='';
	theObject=event.srcElement;
	objValue=theObject.value.toString();
	var dotPos=objValue.indexOf('.');
	if (event.keyCode==46 && dotPos > -1){
		event.returnValue = false;
		return
	}

	if (event.keyCode > 45 && event.keyCode < 58){
		if(event.keyCode==47){
			event.returnValue = false;
			return
		}
		event.returnValue = true;
	}else{
		event.returnValue = false;
	}
}

function restrictToNumericCode(){
	var theObject;
	var objValue='';
	theObject=event.srcElement;
	objValue=theObject.value.toString();
	var dotPos=-1;
	if (event.keyCode==46 && dotPos > -1){
		event.returnValue = false;
		return
	}

	if (event.keyCode > 45 && event.keyCode < 58){
		if(event.keyCode==47){
			event.returnValue = false;
			return
		}
		event.returnValue = true;
	}else{
		event.returnValue = false;
	}
}

function restrictToAlphaNumeric(){
	if(event.keyCode==47) return true; //Allow slash
	if ((event.keyCode > 32 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 97)) event.returnValue = false;
}

// This function takes only(0-9(48-57) && a-z(65-90) && A-Z(97-122))
function restrictToOnlyAlphaNumeric(){
	if ((event.keyCode > 32 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 97) || (event.keyCode > 122 && event.keyCode < 255)) event.returnValue = false;
}

function restrictToOnlyAlphaNumericDot(){
	if(event.keyCode==46) return true; //Allow dot
	if ((event.keyCode > 32 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 97) || (event.keyCode > 122 && event.keyCode < 255)) event.returnValue = false;
}

function enableDiasble(doc,strMode) {
	var input = doc.all.tags("INPUT");
	var select=doc.all.tags("SELECT");
	var textarea=doc.all.tags("TEXTAREA");
	var objLinks = doc.links;
	var linkDiv=doc.all.tags("DIV");
	var hiddenVisible='';
	
	var i=0;
	var bln=eval(strMode);
	if(bln==true) setValidationOff();
	else  setValidationOn();

	// For Text Box, Radio, Checkbox
	for (i=0; i<input.length; i++){
		if(input[i].type=="text"){
			input[i].readOnly=bln;
		}
	}
	for (i=0; i<input.length; i++){
		if(input[i].type=="radio" ){
			input[i].disabled=bln;
		}
	}
	for (i=0; i<input.length; i++){
		if(input[i].type=="checkbox" ){
			input[i].disabled=bln;
		}
	}
	// For Select
	for (i=0; i<select.length; i++){
		select[i].disabled=bln;
	}
	// For Text Area
	for (i=0; i<textarea.length; i++){
		textarea[i].disabled=bln;
	}
	// For link
	if (bln==true){
		hiddenVisible='hidden';
	}else{
		hiddenVisible='visible';
	}

	for (i=0; i<linkDiv.length; i++){
		if(linkDiv[i].id=="view" ){
			linkDiv[i].style.visibility=hiddenVisible;
		}
	}
	
	for(i=0;i<objLinks.length;i++){
		objLinks[i].disabled = bln;
		//link with onclick
		if(objLinks[i].onclick && bln){  
			objLinks[i].onclick = new Function("return false;" + objLinks[i].onclick.toString().getFuncBody());
		}
		//link without onclick
		else if(bln){  
		  objLinks[i].onclick = function(){return false;}
		}
		//remove return false with link without onclick
		else if(!bln && objLinks[i].onclick.toString().indexOf("function(){return false;}") != -1){            
		  objLinks[i].onclick = null;
		}
		//remove return false link with onclick
		else if(!bln && objLinks[i].onclick.toString().indexOf("return false;") != -1){  
		  strClick = objLinks[i].onclick.toString().getFuncBody().replace("return false;","")
		  objLinks[i].onclick = new Function(strClick);
		}
	}
}

function enableTab(){
	var objLinks = document.links;
	var hiddenVisible='';
	var strMode='false';
	var i=0;
	var bln=eval(strMode);
	if(bln==true) setValidationOff();
	else  setValidationOn();


	for(i=0;i<objLinks.length;i++){
		if(objLinks[i].TAB=='TRUE'){
			objLinks[i].disabled = bln;
			//link with onclick
			if(objLinks[i].onclick && bln){  
				objLinks[i].onclick = new Function("return false;" + objLinks[i].onclick.toString().getFuncBody());
			}
			//link without onclick
			else if(bln){  
			  objLinks[i].onclick = function(){return false;}
			}
			//remove return false with link without onclick
			else if(!bln && objLinks[i].onclick.toString().indexOf("function(){return false;}") != -1){            
			  objLinks[i].onclick = null;
			}
			//remove return false link with onclick
			else if(!bln && objLinks[i].onclick.toString().indexOf("return false;") != -1){  
			  strClick = objLinks[i].onclick.toString().getFuncBody().replace("return false;","")
			  objLinks[i].onclick = new Function(strClick);
			}
		}
	}
}
String.prototype.getFuncBody = function(){ 
  var str=this.toString(); 
  str=str.replace(/[^{]+{/,"");
  str=str.substring(0,str.length-1);   
  str = str.replace(/\n/gi,"");
  if(!str.match(/\(.*\)/gi))str += ")";
  return str; 
}

//This function will restrict user to input single quote and double quote
function restrictSingleQuote(doc) {
	var input = doc.all.tags("INPUT");
	var textarea=doc.all.tags("TEXTAREA");
	var select=doc.all.tags("SELECT");

	formatAllBoxes(doc);

	var i=0;
	// For Text Box
	for (i=0; i<input.length; i++){
		if(input[i].type=="text"){
			//Checks if any onkeypress event function already exists
			if (input[i].onkeypress){
				//Without the above check the code will return errors
				//since the input[i].onkeypress does not exist
				if(trim(input[i].onkeypress.toString().getFuncBody()).substring(trim(input[i].onkeypress.toString().getFuncBody()).length-1,trim(input[i].onkeypress.toString().getFuncBody()).length)==';'){
					//Checks to see if a ; is to be appended
					input[i].onkeypress=new Function(input[i].onkeypress.toString().getFuncBody()+'fnRestrict(event)');
				}else{
					input[i].onkeypress=new Function(input[i].onkeypress.toString().getFuncBody()+';fnRestrict(event)');
				}
			}else{
				input[i].onkeypress=function () {fnRestrict(event)};
			}
		}
	}
	// For Text Area
	for (i=0; i<textarea.length; i++){
			//Checks if any onkeypress event function already exists
			if (textarea[i].onkeypress){
				//Without the above check the code will return errors
				//since the input[i].onkeypress does not exist
				if(trim(textarea[i].onkeypress.toString().getFuncBody()).substring(trim(textarea[i].onkeypress.toString().getFuncBody()).length-1,trim(textarea[i].onkeypress.toString().getFuncBody()).length)==';'){
					//Checks to see if a ; is to be appended
					textarea[i].onkeypress=new Function(textarea[i].onkeypress.toString().getFuncBody()+'fnRestrict(event)');
				}else{
					textarea[i].onkeypress=new Function(textarea[i].onkeypress.toString().getFuncBody()+';fnRestrict(event)');
				}
			}else{
				textarea[i].onkeypress=function () {fnRestrict(event)};
			}
	}
	
	//This is added by Chirantan
	//Not required for restriction of single quotes
	//But for calling checkFieldLevelValidation
	//to lessen the burden on developers.
	fieldLevelValidation(doc);
}

function getCaretPosition(elm) {
	if (typeof elm.selectionStart != "undefined"){
		return elm.selectionStart;
	}else if (document.selection){
		return Math.abs(document.selection.createRange().moveStart("character",-1000000));
	}
}
function fnRestrict(e){
	var theObject;
	theObject=e.srcElement;
	if(theObject.type=='text'){
		if (getCaretPosition(theObject) == 0 && e.keyCode == 32){
			e.returnValue = false;
		}
	}else if(theObject.type=='textarea'){
		if (getCaretPosition(theObject) == 3 && e.keyCode == 32){
			e.returnValue = false;
		}
	}
	if (e.keyCode == 34 || e.keyCode == 39 ) e.returnValue = false;
}

//For navigation with enter key
function gotoNextField(whichEvent,whichForm,nextFieldName){
	if (whichEvent.keyCode==13){
		whichEvent.returnValue = false;
		setFieldFocus(whichForm,nextFieldName);
	}
}
//This is a separate function since it may be called with an associated event
function setFieldFocus(formName,fieldName){
	var isLinkPerhaps='FALSE';

	if (fieldName!='none'){
		//Try-catch is needed since if the element to be focussed is not enabled
		//Javascript will return with errors.
		try{
			//These ifs may look as if they are not needed
			//but may be needed if client changes specifications
			if(eval('document.'+formName+'.'+fieldName+'.type')=='text'){
					//eval('document.'+formName+'.'+fieldName+'.select()');
					eval('document.'+formName+'.'+fieldName+'.focus()');
			}
			if(eval('document.'+formName+'.'+fieldName+'.type')=='textarea'){
					//eval('document.'+formName+'.'+fieldName+'.select()');
					eval('document.'+formName+'.'+fieldName+'.focus()');
			}
			if(eval('document.'+formName+'.'+fieldName+'.type')=='checkbox'){
					eval('document.'+formName+'.'+fieldName+'.select()');
					eval('document.'+formName+'.'+fieldName+'.focus()');
			}
			if(eval('document.'+formName+'.'+fieldName+'.type')=='select-one'){
					eval('document.'+formName+'.'+fieldName+'.focus()');
			}
			if(eval('document.'+formName+'.'+fieldName+'.type')=='checkbox'){
					eval('document.'+formName+'.'+fieldName+'.focus()');	
			}
			if(eval('document.'+formName+'.'+fieldName+'.type')=='button'){
					eval('document.'+formName+'.'+fieldName+'.focus()');
			}
			if(eval('document.'+formName+'.'+fieldName+'.type')=='submit'){
					eval('document.'+formName+'.'+fieldName+'.focus()');
			}
		}catch(exception){
			isLinkPerhaps='TRUE';
		}
	}
	//If caught in exception try for any anchor id, or some other id
	if(isLinkPerhaps=='TRUE'){
		try{
			if(eval(fieldName+'.disabled')==false) eval(fieldName+'.focus()');
		}catch(exception){}
	}
}

function isFieldLevelValidationOn(){
	if(isValidatingOtherField=='TRUE') return true;
	return false;
}

//No comments are needed as the functionalities are as restrictSingleQuote()
//only that they are applied on 'onblur' event and used also for 'select'
function fieldLevelValidation(doc){
	var input = doc.all.tags("INPUT");
	var textarea=doc.all.tags("TEXTAREA");
	var select=doc.all.tags("SELECT");
	var objLinks = doc.links;
	var form=doc.all.tags("FORM");
	
	var i;
	for (i=0; i<input.length; i++){
		if(input[i].type=="text"){
			if (input[i].onblur){
				if(trim(input[i].onblur.toString().getFuncBody()).substring(trim(input[i].onblur.toString().getFuncBody()).length-1,trim(input[i].onblur.toString().getFuncBody()).length)==';'){
					input[i].onblur=new Function(input[i].onblur.toString().getFuncBody()+'checkFieldLevelValidation(event)');
				}else{
					input[i].onblur=new Function(input[i].onblur.toString().getFuncBody()+';checkFieldLevelValidation(event)');
				}
			}else{
				input[i].onblur=function () {checkFieldLevelValidation(event)};
			}
		}
	}
	for (i=0; i<textarea.length; i++){
		if (textarea[i].onblur){
			if(trim(textarea[i].onblur.toString().getFuncBody()).substring(trim(textarea[i].onblur.toString().getFuncBody()).length-1,trim(textarea[i].onblur.toString().getFuncBody()).length)==';'){
				textarea[i].onblur=new Function(textarea[i].onblur.toString().getFuncBody()+'checkFieldLevelValidation(event)');
			}else{
				textarea[i].onblur=new Function(textarea[i].onblur.toString().getFuncBody()+';checkFieldLevelValidation(event)');
			}
		}else{
			textarea[i].onblur=function () {checkFieldLevelValidation(event)};
		}
	}
	for (i=0; i<select.length; i++){
		if (select[i].onblur){
			if(trim(select[i].onblur.toString().getFuncBody()).substring(trim(select[i].onblur.toString().getFuncBody()).length-1,trim(select[i].onblur.toString().getFuncBody()).length)==';'){
				select[i].onblur=new Function(select[i].onblur.toString().getFuncBody()+'checkFieldLevelValidation(event)');
			}else{
				select[i].onblur=new Function(select[i].onblur.toString().getFuncBody()+';checkFieldLevelValidation(event)');
			}
		}else{
			select[i].onblur=function () {checkFieldLevelValidation(event)};
		}
	}
	//The links should not pop up window if validation is going on
	for(i=0;i<objLinks.length;i++){
		if(objLinks[i].onclick){  
			objLinks[i].onclick = new Function('if(isFieldLevelValidationOn()) return;' + objLinks[i].onclick.toString().getFuncBody());
		}else{
		  objLinks[i].onclick = function(){if(isFieldLevelValidationOn()) return;}
		}
	}
	
	//Add code for the special functionalities of the Cancel and Print buttons
	for (i=0; i<form.length; i++){
		if(eval('doc.'+form[i].name+'.btnCancel')){
			//Found a valid cancel button
			var theObj=eval('doc.'+form[i].name+'.btnCancel');
			theObj.onbeforeactivate=function(){setCancelStatus()};
			//(onbeforeactivate is fired just before the element is activated)
		}
		if(eval('doc.'+form[i].name+'.btnSave')){
			//Found a valid save button
			var theObj=eval('doc.'+form[i].name+'.btnSave');
			theObj.onbeforeactivate=function(){setSaveStatus()};
			//(onbeforeactivate is fired just before the element is activated)
		}
		if(eval('doc.'+form[i].name+'.btnNew')){
			//Found a valid print button
			var theObj=eval('doc.'+form[i].name+'.btnNew');
			if(theObj.onclick){
				theObj.onclick = new Function('setValidationOn();' + theObj.onclick.toString().getFuncBody());
			}else{
				theObj.onclick = function(){setValidationOn()}
			}
		}
		if(eval('doc.'+form[i].name+'.btnEdit')){
			//Found a valid print button
			var theObj=eval('doc.'+form[i].name+'.btnEdit');
			if(theObj.onclick){
				theObj.onclick = new Function('setValidationOn();' + theObj.onclick.toString().getFuncBody());
			}else{
				theObj.onclick = function(){setValidationOn()}
			}
		}
	}
}

function setCancelStatus(){
	cancelStatus='TRUE';
}
function setSaveStatus(){
	saveStatus='TRUE';
}
function setValidationOn(){
	isValidationApplicable='TRUE';
}
function setValidationOff(){
	isValidationApplicable='FALSE';
}

//This checks for field level validation as specified
function checkFieldLevelValidation(whichEvent){
	var theObject=whichEvent.srcElement;
	var objectType=whichEvent.srcElement.type;
	
	if(isValidationApplicable=='FALSE') return;
	
	//First is that check whether cancel or print buttons were clicked
	//else the rest of the validations or omit all validations and allow
	//user to do what he feels.
	if(cancelStatus=='TRUE') return;
	//if(saveStatus=='TRUE') return;
	
	//priority check for allItems=doc.all if .name matches with any of these then!!
	//out.write("window.opener.document."+ownerFormName+"."+arrTextBox[j]+".fireEvent(\"onchange\");\n");
	//PROBLEM: I can loop for all items, but what about those in two columns
	
	//Explicitly kept so that the loop does not enter into cyclic order with more than two fields
	if(isValidatingOtherField=='TRUE'){
		if(theObject.name!=isValidatingWhichField)
			return;
	}
	
	if(theObject.id){
		if(trim(theObject.id.toUpperCase())=='M'){
			//Marked as Mandatory
			if(theObject.type=='select-one'){
				if(theObject.selectedIndex==0){
					whenNotValid(theObject,'FALSE');
				}else{
					//Value Ok, do nothing, even then reset the bg color
					whenNotValid(theObject,'TRUE');
				}
			}else{
				if(trim(theObject.value)==''){
					whenNotValid(theObject,'FALSE');
				}else{
					//Value Ok, do nothing, even then reset the bg color
					whenNotValid(theObject,'TRUE');
				}
			}
		}else{
			//No marking, if needed one may call explicitFieldLevelValidation()
		}
		//For those that should be greater than a particular no.
		if(theObject.id.toUpperCase().substring(0,5)=='M:GT:'){
			if(theObject.type=='select-one'){
			}else{
				if(!((theObject.value-0)>(theObject.id.toUpperCase().substring(5)-0))){
					whenNotValid(theObject,'FALSE');
				}else{
					//Value Ok, do nothing, even then reset the bg color
					whenNotValid(theObject,'TRUE');
				}
			}
		}else{
			//No marking, if needed one may call explicitFieldLevelValidation()
		}
		//For those that should be less than a particular no.
		if(theObject.id.toUpperCase().substring(0,5)=='M:LT:'){
			if(theObject.type=='select-one'){
			}else{
				if(!((theObject.value-0)<(theObject.id.toUpperCase().substring(5)-0))){
					whenNotValid(theObject,'FALSE');
				}else{
					//Value Ok, do nothing, even then reset the bg color
					whenNotValid(theObject,'TRUE');
				}
			}
		}else{
			//No marking, if needed one may call explicitFieldLevelValidation()
		}
		//For those that should be equal than a particular no.
		if(theObject.id.toUpperCase().substring(0,5)=='M:EQ:'){
			if(theObject.type=='select-one'){
			}else{
				if(!((theObject.value-0)==(theObject.id.toUpperCase().substring(5)-0))){
					whenNotValid(theObject,'FALSE');
				}else{
					//Value Ok, do nothing, even then reset the bg color
					whenNotValid(theObject,'TRUE');
				}
			}
		}else{
			//No marking, if needed one may call explicitFieldLevelValidation()
		}
		if(theObject.id.toUpperCase().substring(0,7)=='M:DATE:'){
			if(theObject.type=='select-one'){
			}else{
				if(!isDateddmmyyyy(theObject.value)){
					whenNotValid(theObject,'FALSE');
				}else{
					//Value Ok, do nothing, even then reset the bg color
					whenNotValid(theObject,'TRUE');
				}
			}
		}else{
			//No marking, if needed one may call explicitFieldLevelValidation()
		}
	}else{
		//Not even an id., assume no marking
		//If needed one may call explicitFieldLevelValidation()
	}
}

//The DHTML details may call this function for explicit validation
//id values etc are not even refered to
//This function is introduced since sabir is using id attributes for detail handling
function explicitFieldLevelValidation(whichEvent,strCond){
	var theObject=whichEvent.srcElement;
	var objectType=whichEvent.srcElement.type;
	
	if(isValidationApplicable=='FALSE') return;

	//First is that check whether cancel or print buttons were clicked
	//else the rest of the validations or omit all validations and allow
	//user to do what he feels.
	if(cancelStatus=='TRUE') return;
	//if(saveStatus=='TRUE') return;
	
	//Explicitly kept so that the loop does not enter into cyclic order with more than two fields
	if(isValidatingOtherField=='TRUE'){
		if(theObject.id){
			if(theObject.name!=isValidatingWhichField&&theObject.id!=isValidatingWhichFieldID) return;
		}else{
			if(theObject.name!=isValidatingWhichField) return;
		}
	}

	//priority check for allItems=doc.all if .name matches with any of these then!!

	if(theObject.type=='select-one'){
		if(theObject.selectedIndex == 0){
			whenNotValid(theObject,'FALSE');
		}else{
			//Value Ok, do nothing, even then reset the bg color
			whenNotValid(theObject,'TRUE');
		}
	}else{
		if(trim(theObject.value)==''){
			whenNotValid(theObject,'FALSE');
		}else{
			//Value Ok, do nothing, even then reset the bg color
			whenNotValid(theObject,'TRUE');
		}
	}
	
	if(!eval(strCond)) return;
	if(strCond==''){
		return;
	}else{
		//For those that should be greater than a particular no.
		if(strCond.toUpperCase().substring(0,5)=='M:GT:'){
			if(theObject.type=='select-one'){
			}else{
				if(!((theObject.value-0)>(strCond.toUpperCase().substring(5)-0))){
					whenNotValid(theObject,'FALSE');
				}else{
					//Value Ok, do nothing, even then reset the bg color
					whenNotValid(theObject,'TRUE');
				}
			}
		}else{
			//No marking, if needed one may call explicitFieldLevelValidation()
		}
		//For those that should be less than a particular no.
		if(strCond.toUpperCase().substring(0,5)=='M:LT:'){
			if(theObject.type=='select-one'){
			}else{
				if(!((theObject.value-0)<(strCond.toUpperCase().substring(5)-0))){
					whenNotValid(theObject,'FALSE');
				}else{
					//Value Ok, do nothing, even then reset the bg color
					whenNotValid(theObject,'TRUE');
				}
			}
		}else{
			//No marking, if needed one may call explicitFieldLevelValidation()
		}
		//For those that should be equal than a particular no.
		if(strCond.toUpperCase().substring(0,5)=='M:EQ:'){
			if(theObject.type=='select-one'){
			}else{
				if(!((theObject.value-0)==(strCond.toUpperCase().substring(5)-0))){
					whenNotValid(theObject,'FALSE');
				}else{
					//Value Ok, do nothing, even then reset the bg color
					whenNotValid(theObject,'TRUE');
				}
			}
		}else{
			//No marking, if needed one may call explicitFieldLevelValidation()
		}
		if(strCond.toUpperCase().substring(0,7)=='M:DATE:'){
			if(theObject.type=='select-one'){
			}else{
				if(!isDateddmmyyyy(theObject.value)){
					whenNotValid(theObject,'FALSE');
				}else{
					//Value Ok, do nothing, even then reset the bg color
					whenNotValid(theObject,'TRUE');
				}
			}
		}else{
			//No marking, if needed one may call explicitFieldLevelValidation()
		}
	}
}

function whenNotValid(theObject,isValidValue){
	//var propertyBorder=theObject.style.border;
	//var propertyBorderColor=theObject.style.borderColor;
	//var propertyBorderWidth=theObject.style.borderWidth;
	try{
		if(theObject.readOnly==true || theObject.disabled==true){
			isValidatingOtherField='FALSE';
			isValidatingWhichField='';
			isValidatingWhichFieldID='';
			return;
		}
		if(isValidValue=='FALSE'){
			//Mark that this is the field that is being currently validated
			isValidatingOtherField='TRUE';
			isValidatingWhichField=theObject.name;
			isValidatingWhichFieldID=theObject.id;
			
			theObject.style.backgroundColor=validationColor;
			//Other style property should be as they were
			theObject.style.fontFamily='Arial, Helvetica, sans-serif';
			theObject.style.fontSize='11px';
			theObject.style.lineHeight='normal';
			theObject.style.fontWeight='normal';
			theObject.style.borderStyle='solid';
			theObject.style.borderWidth='1pt';
			theObject.style.borderColor='lightsteelblue';
			theObject.focus();
		}else{
			//Unmark that this field is validated for correct input
			if(theObject.name==isValidatingWhichField){
				isValidatingOtherField='FALSE';
				isValidatingWhichField='';
				isValidatingWhichFieldID='';
			}
			theObject.style.backgroundColor=normalColor;
			theObject.style.fontFamily='Arial, Helvetica, sans-serif';
			theObject.style.fontSize='11px';
			theObject.style.lineHeight='normal';
			theObject.style.fontWeight='normal';
			theObject.style.borderStyle='solid';
			theObject.style.borderWidth='1pt';
			theObject.style.borderColor='lightsteelblue';
		}
	}catch(exception){
		isValidatingOtherField='FALSE';
		isValidatingWhichField='';
		isValidatingWhichFieldID='';
	}
}

function formatAllBoxes(doc){
	var input = doc.all.tags("INPUT");
	var textarea=doc.all.tags("TEXTAREA");
	var select=doc.all.tags("SELECT");
	
	var propertyBorder;
	var propertyBorderColor;
	var propertyBorderWidth;
	
	var i;
	for (i=0; i<input.length; i++){
		try{
			//If it is a button or message display area, do not apply changes
			if(input[i].type=='button') {}else{
				if(input[i].type=='submit') {}else{
					if(input[i].type=='checkbox') {}else{
						if(input[i].type=='radio') {}else{
							if(input[i].name=='message' || input[i].id.toUpperCase()=='CAPTION') {}else{
			
								//propertyBorder=input[i].style.border;
								//propertyBorderColor=input[i].style.borderColor;
								//propertyBorderWidth=input[i].style.borderWidth;
				
								//This check is required for - if this function is called 
								//when a field level validation is in process
								if(input[i].style.backgroundColor==validationColor){
									input[i].style.backgroundColor=validationColor;				
								}else{
									input[i].style.backgroundColor=normalColor;
								}
				
								input[i].style.fontFamily='Arial, Helvetica, sans-serif';
								input[i].style.fontSize='11px';
								input[i].style.lineHeight='normal';
								input[i].style.fontWeight='normal';
								//input[i].style.border=propertyBorder;
								input[i].style.borderStyle='solid';
								input[i].style.borderWidth='1pt';
								input[i].style.borderColor='lightsteelblue';
							}
						}
					}
				}
			}
		}catch(exception){}
	}
	for (i=0; i<textarea.length; i++){
		try{
			//propertyBorder=textarea[i].style.border;
			//propertyBorderColor=textarea[i].style.borderColor;
			//propertyBorderWidth=textarea[i].style.borderWidth;
		
			//This check is required for - if this function is called 
			//when a field level validation is in process
			if(textarea[i].style.backgroundColor==validationColor){
				textarea[i].style.backgroundColor=validationColor;				
			}else{
				textarea[i].style.backgroundColor=normalColor;
			}
			
			textarea[i].style.fontFamily='Arial, Helvetica, sans-serif';
			textarea[i].style.fontSize='11px';
			textarea[i].style.lineHeight='normal';
			textarea[i].style.fontWeight='normal';
			//textarea[i].style.border=propertyBorder;
			textarea[i].style.borderStyle='solid';
			textarea[i].style.borderWidth='1pt';
			textarea[i].style.borderColor='lightsteelblue';
		}catch(exception){}
	}
	for (i=0; i<select.length; i++){
		try{
			//propertyBorder=select[i].style.border;
			//propertyBorderColor=select[i].style.borderColor;
			//propertyBorderWidth=select[i].style.borderWidth;
			
			//This check is required for - if this function is called 
			//when a field level validation is in process
			if(select[i].style.backgroundColor==validationColor){
				select[i].style.backgroundColor=validationColor;
			}else{
				select[i].style.backgroundColor=normalColor;
			}
			
			select[i].style.fontFamily='Arial, Helvetica, sans-serif';
			select[i].style.fontSize='11px';
			select[i].style.lineHeight='normal';
			select[i].style.fontWeight='normal';
			//select[i].style.border=propertyBorder;
			select[i].style.borderStyle='solid';
			select[i].style.borderWidth='1pt';
			select[i].style.borderColor='lightsteelblue';
		}catch(exception){}
	}
}

function informJSofNewElement(){

}

function formatDynamicBoxes(doc,whichName,whichProperty){
	var theObj;
	try{
		if(whichProperty.toUpperCase()=='ID')
			theObj=doc.getElementsById(whichName);
		if(whichProperty.toUpperCase()=='NAME')
			theObj=doc.getElementsByName(whichName);
		
		var propertyBorder;
		var propertyBorderColor;
		var propertyBorderWidth;
		var i;
		for(i=0;i<theObj.length;i++){
			//propertyBorder=theObj[i].style.border;
			//propertyBorderColor=theObj[i].style.borderColor;
			//propertyBorderWidth=theObj[i].style.borderWidth;
				
			//This check is required for - if this function is called
			//when a field level validation is in process
			if(theObj[i].name=='message' || theObj[i].id.toUpperCase()=='CAPTION') {
				//nothing to do
			}else{
				if(theObj[i].style.backgroundColor==validationColor){
					theObj[i].style.backgroundColor=validationColor;
				}else{
					theObj[i].style.backgroundColor=normalColor;
				}
				
				theObj[i].style.fontFamily='Arial, Helvetica, sans-serif';
				theObj[i].style.fontSize='11px';
				theObj[i].style.lineHeight='normal';
				theObj[i].style.fontWeight='normal';
				//theObj[i].style.border=propertyBorder;
				theObj[i].style.borderStyle='solid';
				theObj[i].style.borderWidth='1pt';
				theObj[i].style.borderColor='lightsteelblue';
			}
		}
	}catch(exception){}
}
//-------------------------------------------------------------------------------------------------------------------
function isAlien(a) {
   return isObject(a) && typeof a.constructor != 'function';
}
function isArray(a) {
    return isObject(a) && a.constructor == Array;
}
function isBoolean(a) {
    return typeof a == 'boolean';
}
function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}
function isFunction(a) {
    return typeof a == 'function';
}
function isNull(a) {
    return typeof a == 'object' && !a;
}
function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
function isString(a) {
    return typeof a == 'string';
}
function isUndefined(a) {
    return typeof a == 'undefined';
} 
//-------------------------------------------------------------------------------------------------------------------
//-----------------------------------------------Changed by Chirantan: START
function doRoundOf(theNumber,numDigits){
	var startNow=false;
	var beforePoint=''
	var afterPoint='';
	var i;
	var c;

	//Initializing before and after the decimal point
	theNumber=theNumber+'';
    for(i=0;i<theNumber.length;i++){
        c=theNumber.charAt(i);
        if(startNow==true){
        	afterPoint=afterPoint+''+c;
        }
        if(c==".") startNow=true;
        if(startNow==false){
        	beforePoint=beforePoint+''+c;
        }
    }

	//Returning the values
	if(beforePoint=='') beforePoint='0';
	if(numDigits==0) return beforePoint;
    if(afterPoint.length==numDigits) return beforePoint+'.'+afterPoint;
    if(afterPoint.length<numDigits){
	    for(i=0;i<numDigits;i++){
	    	afterPoint=afterPoint+'0';
	    	if(afterPoint.length==numDigits) return beforePoint+'.'+afterPoint;
	    }
    }
    if(afterPoint.length>numDigits){
    	c=afterPoint.charAt(numDigits-1);
    	if(afterPoint.charAt(numDigits)>='5'){
			afterPoint=afterPoint.substring(0,numDigits-1);
			c=(c-0)+1;
			afterPoint=afterPoint+''+c;
    	}
    	if(afterPoint.charAt(numDigits)<'5'){
    		afterPoint=afterPoint.substring(0,numDigits);
    	}
    	return beforePoint+'.'+afterPoint;
    }
}

function formatAmount(e,theCharacter,countDigits,digitsAfterPoint){
	//Assumes that restrictToNumeric is called on keypress
	var theObject=e.srcElement;
	var theAmount=theObject.value;
	var theLength=theAmount.length;
	var afterPoint='';
	var beforePoint='';
	var startNow=false;
	var structureBeforePoint='';
	var counter;
	
	var i;
    for(i=0;i<theLength;i++){
        c=theAmount.charAt(i);
        if(startNow==true){
       		afterPoint=afterPoint+''+c;
        }
        if(c==".") startNow=true;
		//unformat the number
        if(startNow==false){
			if(c==theCharacter){
			}else{
        		beforePoint=beforePoint+''+c;
			}
        }
    }
	
	//formatting the digits before point
	theLength=beforePoint.length;
	counter=0;
	if(theLength>(countDigits-0)){
		for(i=beforePoint.length-1;i>=0;i--){
			c=beforePoint.charAt(i);
			structureBeforePoint=c+''+structureBeforePoint;
			counter++;
			if(counter==(countDigits-0)){
				counter=0;
				structureBeforePoint=theCharacter+structureBeforePoint;
			}
		}
		if(structureBeforePoint.charAt(0)==','){
			beforePoint=structureBeforePoint.substring(1);
		}else{
			beforePoint=structureBeforePoint;
		}
	}
	
	//formatting for more digits after decimals
	theLength=afterPoint.length;
	if(theLength>digitsAfterPoint){
		afterPoint=afterPoint.substring(0,digitsAfterPoint);
	}
	
	if(theLength>0){
		theObject.value=beforePoint+'.'+afterPoint;
	}else{
		if(theAmount.length>beforePoint.length){ //this means rascal ta khali point tipechilo
			theObject.value=beforePoint+'.';
		}else{
			theObject.value=beforePoint;
		}
	}
    return true;
}

function formattedAmountToAmount(theAmount,theCharacter,countDigits,digitsAfterPoint){
	//Assumes that restrictToNumeric is called on keypress
	var theLength=theAmount.length;
	var afterPoint='';
	var beforePoint='';
	var startNow=false;
	var structureBeforePoint='';
	var counter;
	var decimalFlag='NO';
	
	var i;
    for(i=0;i<theLength;i++){
        c=theAmount.charAt(i);
        if(startNow==true){
       		afterPoint=afterPoint+''+c;
        }
        if(c=="."){
        	decimalFlag='YES';
        	startNow=true;
        }
		//unformat the number
        if(startNow==false){
			if(c==theCharacter){
			}else{
        		beforePoint=beforePoint+''+c;
			}
        }
    }
	
	//formatting for more digits after decimals
	theLength=afterPoint.length;
	if(theLength>digitsAfterPoint){
		afterPoint=afterPoint.substring(0,digitsAfterPoint);
	}
	
	if(theLength>0){
		return (beforePoint+'.'+afterPoint);
	}else{
		if(decimalFlag=='YES'){ //this means rascal ta khali point tipechilo
			return (beforePoint+'.');
		}else{
			return (beforePoint);
		}
	}
}

function amountToFormattedAmount(theAmount,theCharacter,countDigits,digitsAfterPoint){
	//Assumes that restrictToNumeric is called on keypress
	var theLength=theAmount.length;
	var afterPoint='';
	var beforePoint='';
	var startNow=false;
	var structureBeforePoint='';
	var counter;
	var decimalFlag='NO';
	
	var i;
    for(i=0;i<theLength;i++){
        c=theAmount.charAt(i);
        if(startNow==true){
       		afterPoint=afterPoint+''+c;
        }
        if(c=="."){
        	decimalFlag='YES';
        	startNow=true;
        }
		//unformat the number
        if(startNow==false){
			if(c==theCharacter){
			}else{
        		beforePoint=beforePoint+''+c;
			}
        }
    }
	
	//formatting the digits before point
	theLength=beforePoint.length;
	counter=0;
	if(theLength>(countDigits-0)){
		for(i=beforePoint.length-1;i>=0;i--){
			c=beforePoint.charAt(i);
			structureBeforePoint=c+''+structureBeforePoint;
			counter++;
			if(counter==(countDigits-0)){
				counter=0;
				structureBeforePoint=theCharacter+structureBeforePoint;
			}
		}
		if(structureBeforePoint.charAt(0)==','){
			beforePoint=structureBeforePoint.substring(1);
		}else{
			beforePoint=structureBeforePoint;
		}
	}
	
	if((digitsAfterPoint-0)==0){//Decimal not required
		return (beforePoint);
	}else{
		if(decimalFlag=='YES'){//Decimal more than required
			afterPoint=afterPoint.substring(0,digitsAfterPoint);
			return (beforePoint+'.'+afterPoint);
		}else{
			if(afterPoint.length==(digitsAfterPoint-0)){//Decimal equal to that required
				return (beforePoint+'.'+afterPoint);
			}else{
			    for(i=0;i<(digitsAfterPoint-0);i++){
			    	afterPoint=afterPoint+'0';
			    	if(afterPoint.length==(digitsAfterPoint-0)) return (beforePoint+'.'+afterPoint);
			    }
			}
		}
	}
}
//-----------------------------------------------Changed by Chirantan: END

//----------------- Added by Sandeep Date Add function : START :--------------------------
function DateAdd(dt,num,dmy){
	//change the dd/mm/yyyy to mm/dd/yyyy
	//change date in proper format
	num=num-0;
	//dmy:	'D' = Day
	//		'M' = Month
	//		'Y' = Year
	var pos1=dt.indexOf(dtCh)
	var pos2=dt.indexOf(dtCh,pos1+1)
	
	var strMonth=dt.substring(pos1+1,pos2)
	var strDay=dt.substring(0,pos1)
	var strYear=dt.substring(pos2+1)
	
	myDate = new Date(strMonth+"/"+strDay+"/"+strYear);
	var lastDateOfCurrentMonthYear=getLastDateOfTheMonthYear(myDate);
	
	if(dmy.toUpperCase()=='Y'){
		if(strDay==lastDateOfCurrentMonthYear){
			strDay=getLastDateOfTheMonthYear(new Date(strMonth+"/01/"+eval(strYear-0+num)));
			strYear=eval(strYear-0+num);
			strMonth=strMonth-0;
		}else{
			myDate.setFullYear(myDate.getFullYear()+num);
			strMonth=myDate.getMonth();
			strDay=myDate.getDate();
			strMonth=strMonth-0+1;
			strYear=myDate.getFullYear();
		}
	}else if(dmy.toUpperCase()=='M'){
		if(strDay==lastDateOfCurrentMonthYear ||
			strMonth==12 && strDay==30 && Math.round((((strMonth-0+num)/12)-Math.floor((strMonth-0+num)/12))*12)==2){
			
			strYear=strYear-0+Math.floor((strMonth-0+num)/12);
			strMonth=Math.round((((strMonth-0+num)/12)-Math.floor((strMonth-0+num)/12))*12);
			strDay=getLastDateOfTheMonthYear(new Date(strMonth+"/01/"+strYear));
		}else{
			myDate.setMonth(myDate.getMonth() + num);
			strDay=myDate.getDate();
			strMonth=myDate.getMonth();
			strYear=myDate.getFullYear();
			strMonth=strMonth-0+1;
		}
	}else if(dmy.toUpperCase()=='D'){
		myDate.setDate(myDate.getDate() + num);
		strDay=myDate.getDate();
		strMonth=myDate.getMonth();
		strYear=myDate.getFullYear();
		strMonth=strMonth-0+1;
	}
	
	
	if(strDay < 10) strDay="0"+strDay;
	if(strMonth < 10) strMonth="0"+strMonth;
	
	
	return strDay+"/"+strMonth+"/"+strYear;
	
}

function getLastDateOfTheMonthYear(theDate){
	// create a varible to specify what the
	// last day for the current month is
	var theday = 0;
	var month_num=theDate.getMonth();
	var right_year=theDate.getFullYear();
	var endofmonth=0;
	
	if (month_num == 0 || month_num == 2 || month_num == 4 || 
		month_num == 6 || month_num == 7 || month_num == 9 || 
		month_num == 11){ 
		
		endofmonth=31;
	}
	if (month_num == 3 || month_num == 5 || month_num == 8 || 
		month_num == 10){ 
	
		endofmonth=30;
	}

	if (month_num == 1){ 
		// This will check for a leap year
		// If the year is evenly divisible by four
		// or in the case of a new century evenly divisible
		// by 400 then the end of the February month should be the 29th

		right_year_divided=right_year/4;
		right_year_divided_string= new String(right_year_divided);
		var is_decimal = right_year_divided_string.indexOf('.');
	
		if (is_decimal != -1){ 
			endofmonth=28; 
		}else{ 
			endofmonth=29; 
		}

		right_year_string= new String(right_year);
		var the_century=new String(right_year_string.charAt(2)) 
		the_century= the_century + new String(right_year_string.charAt(3));
	
		if (the_century == "00"){ 
			right_year_divided=right_year/400;
			right_year_divided_string= new String(right_year_divided);
			var is_decimal = right_year_divided_string.indexOf('.');
			
			if (is_decimal != -1){
				endofmonth=28;
			}else{
				endofmonth=29;
			}
		}
	}
	return endofmonth;
}
//----------------- Added by Sandeep--------------------------

//added by sherab 
function SubmitMail(mode){
	if(mode=='n')
		{
		 window.open("http://mail.rma.org.bt/webmail/src/login.php","pop","");
		 }
	else
		{
		window.open("http://mail.rma.org.bt:2000/","pop","");
		}
 }