Search This Blog

Monday, January 25, 2010

JSF FAQS

<b> 1) What does component mean and what are its types?</b>

Components in JSF are elements like text box, button, table etc. that are used to create user interfaces of JSF Applications. These are objects that manage interaction with a user. Components help developers to create UIs by assembling a number of components , associating them with object properties and event handlers. Would u like to repeat the same code again & again and waste time if u want to create many tables in hundreds of pages in your web application? Not at all. Once you create a component, it’s simple to drop that component onto any JSP. Components in JSF are of two types :

Simple Components like text box, button and
Compound Components like table, data grid etc.
A component containing many components inside it is called a compound component.

JSF allows you to create and use components of two types:

Standard UI Components:
JSF contains its basic set of  UI components like text box, check box, list boxe, button, label, radio button, table, panel etc. These are called standard components.

Custom UI Components:
Generally UI designers need some different , stylish components like fancy calendar, tabbed panes . These types of components are not standard JSF components. JSF provides this additional facility to let you create and use  your own set of reusable components. These components are called custom components.


<b>2) What is JSF (or JavaServer Faces)?</b>


A server side user interface component framework for Java™ technology-based web applications.JavaServer Faces (JSF) is an industry standard and a framework for building component-based user interfaces for web applications.

JSF contains an API for representing UI components and managing their state; handling events, server-side validation, and data conversion; defining page navigation; supporting internationalization and accessibility; and providing extensibility for all these features.


New to JSF ? Check JavaServer Faces (JSF) tutorial

<b>3) What are the advantages of JSF? </b>




The major benefits of JavaServer Faces technology are:

JavaServer Faces architecture makes it easy for the developers to use. In JavaServer Faces technology, user interfaces can be created easily with its built-in UI component library, which handles most of the complexities of user interface management.
Offers a clean separation between behavior and presentation.
Provides a rich architecture for managing component state, processing component data, validating user input, and handling events.
Robust event handling mechanism.
Events easily tied to server-side code.
Render kit support for different clients
Component-level control over statefulness
Highly 'pluggable' - components, view handler, etc
JSF also supports internationalization and accessibility
Offers multiple, standardized vendor implementations

<b>4. What are differences between struts and JSF?</b>




In a nutshell, Faces has the following advantages over Struts:

Eliminated the need for a Form Bean

Eliminated the need for a DTO Class

Allows the use of the same POJO on all Tiers because of the Backing Bean



The primary advantages of Struts as compared to JavaServer Faces technology are as follows:
Because Struts is a web application framework, it has a more sophisticated controller architecture than does JavaServer Faces technology. It is more sophisticated partly because the application developer can access the controller by creating an Action object that can integrate with the controller, whereas JavaServer Faces technology does not allow access to the controller. In addition, the Struts controller can do things like access control on each Action based on user roles. This functionality is not provided by JavaServer Faces technology.



Struts includes a powerful layout management framework, called Tiles, which allows you to create templates that you can reuse across multiple pages, thus enabling you to establish an overall look-and-feel for an application.

The Struts validation framework includes a larger set of standard validators, which automatically generate both server-side and client-side validation code based on a set of rules in a configuration file. You can also create custom validators and easily include them in your application by adding definitions of them in your configuration file.



The greatest advantage that JavaServer Faces technology has over Struts is its flexible, extensible UI component model, which includes:
A standard component API for specifying the state and behavior of a wide range of components, including simple components, such as input fields, and more complex components, such as scrollable data tables. Developers can also create their own components based on these APIs, and many third parties have already done so and have made their component libraries publicly available.

A separate rendering model that defines how to render the components in various ways. For example, a component used for selecting an item from a list can be rendered as a menu or a set of radio buttons.

An event and listener model that defines how to handle events generated by activating a component, such as what to do when a user clicks a button.

Conversion and validation models for converting and validating component data.

<b:if cond='data:post.hasJumpLink'>
<div class='jump-link'>
<a expr:href='data:post.url + "#more"'><data:post.jumpText/></a>
</div>
</b:if >

<b>5) What are the available implementations of JavaServer Faces?</b>

The main implementations of JavaServer Faces are:

Reference Implementation (RI) by Sun Microsystems.
Apache MyFaces is an open source JavaServer Faces (JSF) implementation or run-time.
ADF Faces is Oracle’s implementation for the JSF standard.


<b>6. What typical JSF application consists of?</b>


A typical JSF application consists of the following parts:

JavaBeans components for managing application state and behavior.
Event-driven development (via listeners as in traditional GUI development).
Pages that represent MVC-style views; pages reference view roots via the JSF component tree.


<b>7. What Is a JavaServer Faces Application?</b>

JavaServer Faces applications are just like any other Java web application. They run in a servlet container, and they typically contain the following:

JavaBeans components containing application-specific functionality and data.
Event listeners.
Pages, such as JSP pages.
Server-side helper classes, such as database access beans.
In addition to these items, a JavaServer Faces application also has:
A custom tag library for rendering UI components on a page.
A custom tag library for representing event handlers, validators, and other actions.
UI components represented as stateful objects on the server.
Backing beans, which define properties and functions for UI components.
Validators, converters, event listeners, and event handlers.
An application configuration resource file for configuring application resources.


<b>8. What is Managed Bean?</b>



JavaBean objects managed by a JSF implementation are called managed beans. A managed bean describes how a bean is created and managed. It has nothing to do with the bean's functionalities.


<b>9. What is Backing Bean?</b>

Backing beans are JavaBeans components associated with UI components used in a page. Backing-bean management separates the definition of UI component objects from objects that perform application-specific processing and hold data.

The backing bean defines properties and handling-logics associated with the UI components used on the page. Each backing-bean property is bound to either a component instance or its value. A backing bean also defines a set of methods that perform functions for the component, such as validating the component's data, handling events that the component fires and performing processing associated with navigation when the component activates.

<b>10. What are the differences between a Backing Bean and Managed Bean?</b>

Backing Beans are merely a convention, a subtype of JSF Managed Beans which have a very particular purpose. There is nothing special in a Backing Bean that makes it different from any other managed bean apart from its usage.

What makes a Backing Bean is the relationship it has with a JSF page; it acts as a place to put component references and Event code.


Backing Beans Managed Beans
A backing bean is any bean that is referenced by a form. A managed bean is a backing bean that has been registered with JSF (in faces-config.xml) and it automatically created (and optionally initialized) by JSF when it is needed.
The advantage of managed beans is that the JSF framework will automatically create these beans, optionally initialize them with parameters you specify in faces-config.xml,
Backing Beans should be defined only in the request scope The managed beans that are created by JSF can be stored within the request, session, or application scopes


Backing Beans should be defined in the request scope, exist in a one-to-one relationship with a particular page and hold all of the page specific event handling code.In a real-world scenario, several pages may need to share the same backing bean behind the scenes.A backing bean not only contains view data, but also behavior related to that data.
<b:if cond='data:post.hasJumpLink'>
<div class='jump-link'>
<a expr:href='data:post.url + "#more"'><data:post.jumpText/></a>
</div>
</b:if >


<b>11. What is view object?</b> 

A view object is a model object used specifically in the presentation tier. It contains the data that must display in the view layer and the logic to validate user input, handle events, and interact with the business-logic tier. The backing bean is the view object in a JSF-based application. Backing bean and view object are interchangeable terms.

What are The main tags in JSF?

JSF application typically uses JSP pages to represent views. JSF provides useful special tags to enhance these views. Each tag gives rise to an associated component. JSF (Sun Implementation) provides 43 tags in two standard JSF tag libraries:

JSF Core Tags Library.
JSF Html Tags Library.

<b>18. How do you declare the managed beans in the faces-config.xml file?</b>

The bean instance is configured in the faces-config.xml file:

<managed-bean>
<managed-bean-name>login</managed-bean-name>
<managed-bean-class>com.developersBookJsf.loginBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>


This means: Construct an object of the class com.developersBookJsf.loginBean, give it the name login, and keep it alive for the duration of the request.



<b>19. How to declare the Message Bundle in JSF?</b>



We can declare the message bundle in two ways:
(Let’s assume messages is the properties file)

1.  The simplest way is to include the following elements in faces-config.xml file:

<application>
<resource-bundle>
<base-name>messages</base-name>
<var>message</var>
</resource-bundle>
</application>

2.  Alternatively, you can add the f:loadBundle element to each JSF page that needs access to the bundle:
<blockquote><f:loadBundle baseName = “Jsf.messages” var=”message”/>

<b>20. How to declare the page navigation (navigation rules) in faces-config.xml file ?</b>

Navigation rules tells JSF implementation which page to send back to the browser after a form has been submitted. We can declare the page navigation as follows:



<naviagation-rule>
<from-view-id>/index.jsp</from-view-id>
<navigation-case>
<from-outcome>login</from-outcome>
<to-view-id>/welcome.jsp</to-view-id>
</navigation-case>
</naviagation-rule>

This declaration states that the login action navigates to /welcome.jsp, if it occurred inside /index.jsp.

Wednesday, January 20, 2010

Common javascript

/*
Common Javascript File
version 1.5
Author :none
*/

/**************** Functions **************************/

/*
* Agruments Type : N(id)
* Purpose : Makes components visible
* Author :none
* Description :
* You can pass any number of html field ids to it.
* All the html fields will get Appeared.
*/
function show(){
var argumentValues = show.arguments;
var argumentCount = show.arguments.length;
for ( i=0;i 57)){
e.cancelBubble = true;

if(!flag){
if (e.stopPropagation) e.stopPropagation();
e.preventDefault();
}
else
e.returnValue = false;
if(typeof errorId != "undefined" )
show(errorId);
return;
}
if(typeof errorId != "undefined" )
hide(errorId);
}

/*
* Agruments Type : id,fomrmat
* Purpose : Validate Date fomrmat
* Author :none
* Description :
* Function for validating Date, a utility function
*/
function validDateFormat(id,format){
ret = false;
if(id == null || format==null){
return false;
}
dateVal = document.getElementById(id).value;

if (dateVal !="" )
{
if ( format == "dd/mm/yyyy" )
re = /^\d{2}\/\d{2}\/\d{4}$/;
else
if ( format == "mm/yyyy" )
re = /^\d{1,2}\/\d{4}$/;
else
return ret;
if(dateVal.match(re) )
ret = true;
}

return ret;
}

/*
* Agruments Type : id,errorId,flag
* Purpose : Validate Date
* Author :none
* Description :
* Function for validating Date, a Client Side Validation
* Last flag is optional , only for when moth -00 is acceptable
*/
function validateDate(id,errorId,format,flag,flag00){
ret = false;
if(id == null || errorId == null || format==null){
hide(errorId);
return ret;
}

if( typeof flag00 == "undefined")
flag00 = false;

dateVal = document.getElementById(id).value;
if(dateVal == 'dd/mm/yyyy' ||dateVal == 'mm/yyyy'||dateVal == 'yyyy' ){
hide(errorId);
return false;
}
if (dateVal !="" )
{
if ( format == "dd/mm/yyyy" )
re = /^\d{2}\/\d{2}\/\d{4}$/;
else
if ( format == "mm/yyyy" )
re = /^\d{1,2}\/\d{4}$/;
else
if ( format == "yyyy" )
re = /^\d{4}$/;
else
return ret;
if(!dateVal.match(re) || !validDate(dateVal,format,flag00) )
{
show(errorId);
if(flag)
setFocus(id);
}
else
{
hide(errorId);
ret = true;
}
return ret;
}
else
{
hide(errorId);
return ret;
}
}

/*
* Agruments Type : N (id)
* Purpose : check for required/null for n no of fields
* Author :none
* Description :
* Function for required check, a Client Side Validation
*/
function requiredFields(){
var flag;
var argumentValues = requiredFields.arguments;
var argumentCount = requiredFields.arguments.length;
var i=0;
var j=-1;
flag = true;
while(i < (2 * (argumentCount/2) - 1) ) { var val = document.getElementById(argumentValues[i]).value ; if(val=='dd/mm/yyyy' || val=='mm/yyyy' || val == 'yyyy') val =''; if ( val == null || val == "" || val.replace(/^\s+|\s+$/g,"").length == 0 ) { show(argumentValues[i+1]); if(flag) j = i; flag = false; } else{ hide(argumentValues[i+1]); } i = i + 2; } if(j!=-1) setFocus(argumentValues[j]); return flag; } /* * Agruments Type : id,errorId,flag * Purpose : Validate Email * Author :none * Description : * Function for validating Email, a Client Side Validation* */ function validateEmail(id,errorId,flag){ var email = document.getElementById(id); var filter = /^([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+$/; if (email.value!="" &&!filter.test(email.value)) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,flag * Purpose : Validate Single Field Option * Author :none * Description : * Function for validating single character field, a Client Side Validation * here choice is string of valid options * eg. 'abc' , now only a or b or c is valid. */ function validateSingleFieldOption(id,errorId,choice,flag){ var item = document.getElementById(id); if ( item.value!="" && choice.indexOf(item.value)== -1) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,flag * Purpose : Validate Number (Integer) * Author :none * Description : * Function for validating Numeric Data, a Client Side Validation * eg. 10 , 123, 123 are valid * */ function validateNumber(id,errorId,flag){ var item = document.getElementById(id); if ( item.value!="" && !isNumeric(item.value)) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,flag * Purpose : Validate Number(Double) * Author :none * Description : * Function for validating Numeric Data, a Client Side Validation * eg. 10.1 , 123, 12.3 are valid * */ function validateDecimalNumber(id,errorId,flag){ var item = document.getElementById(id); if ( item.value!="" && !isDecimal(item.value)) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,funcId,flag * Purpose : Common Validation Function * Author :none * Description : * FuncId is business logic, this function will take care of error handling you just * need to pass your function id. * eg. * validateCommon('amtTxt','amtTxtErr1',isNumeric( 123 ),flag) * */ function validateCommon(id,errorId,funcId,flag){ var item = document.getElementById(id); if ( item.value!="" && ! funcId) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,len,flag * Purpose : lengh must be len * Author :none * Description : * length should be equal to len* * eg. * ret = validateExactLength('policyNoTxt','policyNoTxtErr1',9,ret) && ret; * */ function validateExactLength(id,errorId,len,flag){ var item = document.getElementById(id); if ( item.value!="" && item.value.length != len ) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,len,flag * Purpose : lengh must be minimum len * Author :none * Description : * length should be greater than equal to len* * eg. * ret = validateMinLength('policyNoTxt','policyNoTxtErr1',7,ret) && ret; * */ function validateMinLength(id,errorId,len,flag){ var item = document.getElementById(id); if ( item.value!="" && item.value.length < len ) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,len1,len2,flag * Purpose : Lenght in range of len1 and len2 * Author :none * Description : * Lenght should >= len1 and <= len2 * eg. * ret = validateLengthinRange('amtTxt','amtTxtErr0',3,6,ret) && ret; * */ function validateLengthinRange(id,errorId,len1,len2,flag){ var item = document.getElementById(id); if ( item.value!="" && ( item.value.length < len1 || item.value.length > len2) ) {
show(errorId);
if(flag)
setFocus(id);
return false;
}
else{
hide(errorId);
return true;
}
}

/*
* Agruments Type : String
* Purpose : checks whether String is numeric(integer) // not for client side js validation// Just a utility function
* Author :none
* Description :
* You can pass any string to it.
* It will check whether it is Numeric or not.
*/
function isNumeric(sText){
var filter = /^-{0}\d*\.{0}\d+$/;
return filter.test(sText);
}

/*
* Agruments Type : String
* Purpose : checks whether String is numeric(decimal) // not for client side js validation// Just a utility function
* Author :none
* Description :
* You can pass any string to it.
* It will check whether it is Numeric or not.
*/
function isDecimal(sText){
var filter = /^-{0}\d*\.{0,1}\d+$/;
return filter.test(sText);
}



/*
* Agruments Type : date ( value not id )
* Purpose : checks whether date is valid // not for client side js validation// Just a utility function
* Author :none
* Description :
* You can pass any date to it like dd/mm/yy or dd-mm-yyyy or dd.mm.yyyy
* It will check whether it is Numeric or not.
*/
function validDate(field,format,flag00){
var checkstr = "0123456789";
var DateValue = "";
var DateTemp = "";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;

if( typeof flag00 == "undefined")
flag00 = false;

err = 0;
DateValue = field;
/* Delete all chars except 0..9 */
for (i = 0; i < DateValue.length; i++) { if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
DateTemp = DateTemp + DateValue.substr(i,1);
}
}
DateValue = DateTemp;
/* Always change date to 8 digits - string*/

if (format == 'dd/mm/yyyy') {
err = 0;
}

if (format == 'mm/yyyy') {
err = 2;
}

if( format == 'yyyy') {
if( parseInt(DateValue,10)=='0')
return false;
else
return true;
}

/* year is wrong if year = 0000 */
year = DateValue.substr(4-err,4);
if (year == 0000) {
err = 20;
}
/* Validation of month*/
month = DateValue.substr(2-err,2);
if ((month < 1 && !flag00) || (month > 12)) {
err = 21;
}

if(err==0) {
/* Validation of day*/
day = DateValue.substr(0,2);
if (day < 1) { err = 22; } /* Validation leap-year / february / day */ if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) { leap = 1; } if ((month == 2) && (leap == 1) && (day > 29)) {
err = 23;
}
if ((month == 2) && (leap != 1) && (day > 28)) {
err = 24;
}
/* Validation of other months */

if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
err = 25;
}
if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
err = 26;
}
if (day == 00) {
err = 27;
}
}
/* if 00 ist entered , it is error*/
if ((month == 00) && (year == 0000)) {
err = 27;
}
/* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
if (err <= 2) { //DateField.value = day + seperator + month + seperator + year; return true; } /* Error-message if err != 0 */ else { return false; } } function viewPrint(){ var argumentValues = viewPrint.arguments; var argumentCount = viewPrint.arguments.length; var printPath; var url; //alert(argumentCount); if(argumentCount == 1){ //alert(argumentValues[0]); printPath = argumentValues[0]; url=contextPath + "/viewPrintFile.action?"+"printPath="+printPath+"&type=multiple"; window.open(url,'newWin1','status=no,\n\ resizable=yes,scrollbars=yes,dependent=yes,left=120,top=80,location=no'); }else if(argumentCount == 0){ printPath = document.getElementById("nextStepPath").value; url=contextPath + "/printAction.action?"+"printPath="+printPath; window.open(url,'newWin1','status=no,\n\ resizable=yes,scrollbars=yes,dependent=yes,left=120,top=80,location=no'); } return false; } // Author : None function edms(policyNumber){ url = contextPath+"/EdmsAction.action?"+"policyNumber="+policyNumber; window.open(url,'newWin1'); } // Author : None function silentPrint(printPath) { //alert("testing "); //alert('testing context path-----> '+appletUrl);
var servletPath = appletUrl;
//alert('print path -> '+printPath);
if(printPath != "" && servletPath != ""){
document.PrintApplet.printFile(printPath, servletPath);
}
//alert("done");
return true;
}

// Author : None
function deletePrintFile(printFilePath){
url=contextPath + "/deletePrintFile.action?"+"printPath="+printFilePath;
window.open(url,'newWin1','status=no,width=1,height=1,left=0,top=0');
}

/*
* Agruments Type : none
* Purpose : Opens a window, having result of your print file
* Author :none
* Description :
* wiill open a new window/popup for print file
*/

function displayPrintFile(){
// window.open('', 'newWin', 'width=750,height=600,status=no,resizable=no,scrollbars=no,dependent=yes,left=120,top=80');
// document.getElementById(formId).target = "newWin";
// document.getElementById(formId).action=actionName;
// document.getElementById(formId).submit();
var url=contextPath + "/jsp/common/printFile.html";
window.open(url,'newWin1','width=750,height=650,status=no,\n\
resizable=no,scrollbars=yes,dependent=yes,left=120,top=80,location=no');
return false;

}


/***********************NUMERICAL INPUT MASKING FUNCTIONS*****************************************/

/* Agruments Type : event.keyCode, this, mask
* Purpose : input masking
* Author :none
* Description :
* Last option is mask,
* it could ##-## or ##/##### or ##/##/#### etc
* eg.
* onKeyDown="javascript:return dFilter (event.keyCode, this, '##/##/####')"
*
*/
var dFilterStep;

function dFilterStrip (dFilterTemp, dFilterMask)
{
dFilterMask = replace(dFilterMask,'#','');
for (dFilterStep = 0; dFilterStep < dFilterMask.length++; dFilterStep++) { dFilterTemp = replace(dFilterTemp,dFilterMask.substring(dFilterStep,dFilterStep+1),''); } return dFilterTemp; } function dFilterMax (dFilterMask) { dFilterTemp = dFilterMask; for (dFilterStep = 0; dFilterStep < (dFilterMask.length+1); dFilterStep++) { if (dFilterMask.charAt(dFilterStep)!='#') { dFilterTemp = replace(dFilterTemp,dFilterMask.charAt(dFilterStep),''); } } return dFilterTemp.length; } function dFilter (key, textbox, dFilterMask) { dFilterNum = dFilterStrip(textbox.value, dFilterMask); if (key==9) { return true; } else if (key==8&&dFilterNum.length!=0) { dFilterNum = dFilterNum.substring(0,dFilterNum.length-1); } else if ( ((key>47&&key<58)||(key>95&&key<106)) && dFilterNum.length95&&key<106) key = parseInt(key) - 48; dFilterNum=dFilterNum+String.fromCharCode(key); } var dFilterFinal=''; for (dFilterStep = 0; dFilterStep < dFilterMask.length; dFilterStep++) { if (dFilterMask.charAt(dFilterStep)=='#') { if (dFilterNum.length!=0) { dFilterFinal = dFilterFinal + dFilterNum.charAt(0); dFilterNum = dFilterNum.substring(1,dFilterNum.length); } else { dFilterFinal = dFilterFinal + ""; } } else if (dFilterMask.charAt(dFilterStep)!='#') { dFilterFinal = dFilterFinal + dFilterMask.charAt(dFilterStep); } } textbox.value = dFilterFinal; return false; } function replace(fullString,text,by) { // Replaces text with by in string var strLength = fullString.length, txtLength = text.length; if ((strLength == 0) || (txtLength == 0)) return fullString; var i = fullString.indexOf(text); if ((!i) && (text != fullString.substring(0,txtLength))) return fullString; if (i == -1) return fullString; var newstr = fullString.substring(0,i) + by; if (i+txtLength < strLength) newstr += replace(fullString.substring(i+txtLength,strLength),text,by); return newstr; } /****************************END OF INPUT MASKING FUNCTIONS*******************************/ /* * Agruments Type : id ( id of datefield), format ( dd/mm/yyyy or mm/yyyy or yyyy ) * Purpose : check for current or back dates * Author :none * Description : * Today or back dates are valid :returns true * future dates are invalid : returs false * * validateCommon ('deathDtTxt','deathDtTxtErr2',notFutureDate('deathDtTxt','dd/mm/yyyy'),ret)&& ret; */ function notFutureDate(id,format){ var input = document.getElementById(id).value; if(input == '' || input == null) return true; var date1 = new Date(); var n = 0; if ( format == 'dd/mm/yyyy') n = 7; else if ( format == 'mm/yyyy') n =4; else if (format == 'yyyy') n = 1; if( n == 7){ var day = parseInt(input.substr(0,2),10); date1.setDate(day); } if ( n >= 4){
var month = parseInt(input.substr(n-4,2),10) -1;
date1.setMonth(month);
}
if ( n > 0){
var year = parseInt(input.substr(n-1,4),10);
date1.setYear(year);
}


if(date1 <= new Date() ) return true; else return false; } /* Agruments Type : id ( id of datefield), startDate, EndDate * Purpose : check for date is between or eqaul of startDate and EndDate * Author :none * Description : * dateInRange('id1','01/01/2009','31/12/2009') * for client side validate call : validateCommon('id','errorId',dateInRange('id1','01/01/2009','31/12/2009') * ,true) */ function dateInRange(id,startDate,endDate){ var input = document.getElementById(id).value; if(input == '' || input == null) return true; var date1 = new Date(); var date2 = new Date(); var date3 = new Date(); len1 = startDate.length; len2 = endDate.length; len3 = input.length; if( (len1 != len2) || (len2 != len3)) return false; var n = 0; if ( len1 == 10 ) n = 7; else if ( len1 == 7) n =4; else if (len1 == 4) n = 1; if( n == 7){ date1.setDate(parseInt(input.substr(0,2),10)); date2.setDate(parseInt(startDate.substr(0,2),10)); date3.setDate(parseInt(endDate.substr(0,2),10)); } if ( n >= 4){
date1.setMonth(parseInt(input.substr(n-4,2),10)-1);
date2.setMonth(parseInt(startDate.substr(n-4,2),10)-1);
date3.setMonth(parseInt(endDate.substr(n-4,2),10)-1);
}
if ( n > 0){
date1.setYear(parseInt(input.substr(n-1 ,4),10));
date2.setYear(parseInt(startDate.substr(n-1,4),10));
date3.setYear(parseInt(endDate.substr(n-1,4),10));
}

if( date1 >= date2 && date1 <= date3 ) return true; else return false; } /* Agruments Type : id * Purpose : returns the value of html component * Author :none * Description : * eg. this.value = getValueFromId('policyNoTxt'); * */ function getValueFromId(id){ return document.getElementById(id).value; } /* Agruments Type : id,val * Purpose : set the value of html component * Author :none * Description : * eg. setValueInId('policyNoTxt','111111111'); * setValueInId('policyNoTxt',12232323); * setValueInId('policyNoTxt',new Date());* * */ function setValueInId(id,val){ document.getElementById(id).value = val; } /* Agruments Type : id,id * Purpose : copy value of html component * Author :none * Description : * eg. copyValfromIdtoId('scrId','DesId'); * */ function copyValfromIdtoId(idScr,idDes){ document.getElementById(idDes).value = document.getElementById(idScr).value; } /* Agruments Type : id,id * Purpose : makes the single digit to double * Author :none * Description : * eg. makeDoubleDigit(5), will return '05' * */ function makeDoubleDigit(IntVal){ if( IntVal < 10 ) IntVal = '0'+IntVal; return IntVal; } /* Agruments Type : Date value * Purpose : convert Date value to 'dd/mm/yyyy' or 'mm/yyyy' or 'yyyy' format * Author :none * Description : * eg. dateToValue(new Date()) * Output: '01/01/2009' ( will return todays date in dd/mm/yyyy format) * dateToValue(new Date(),'dd/mm/yyyy') * Output: '01/01/2009' ( will return todays date in dd/mm/yyyy format) * dateToValue(new Date(),'mm/yyyy') * Output: '01/2009' ( will return todays date in mm/yyyy format) * dateToValue(new Date(),'yyyy') * Output: '2009' ( will return todays date in yyyy format) * */ function dateToValue(dateVar,format){ var dd = dateVar.getDate(); var mm = dateVar.getMonth()+1; var yy = dateVar.getFullYear(); var retVal; if (typeof format == "undefined") format = "dd/mm/yyyy"; if(format == 'dd/mm/yyyy') retVal = makeDoubleDigit(dd)+'/'+makeDoubleDigit(mm)+'/'+yy; if(format == 'mm/yyyy') retVal = makeDoubleDigit(mm)+'/'+yy; if(format == 'yyyy') retVal = yy; return retVal; } /* Agruments Type : string in 'dd/mm/yyyy' or 'mm/yyyy' or 'yyyy' format * Purpose : convert value from 'dd/mm/yyyy' or 'mm/yyyy' or 'yyyy' format to date value * Author :none * Description : * eg. valueToDate('01/01/2009') * valueToDate('01/2009') * valueToDate('2009') * */ function valueToDate(value){ var len = value.length; dateVar = new Date(); if(len >= 10)
dateVar.setDate(value.substr(0,2));
if(len >= 7)
dateVar.setMonth(value.substr(len - 7,2)-1);
if(len >=4 )
dateVar.setFullYear(value.substr(len -4,4));

return dateVar;
}

/* Agruments Type : string in 'dd/mm/yyyy' or 'mm/yyyy' or 'yyyy' format
* or
* Date value
*
* Purpose : removes '/' or add '/' from date
* Author :none
* Description :
* eg. formatDate()
* Output: 01012000
* formatDate('01/02/2009')
* Output: 01022009
* formatDate('01/02/2009',false)
* Output: 01022009
* formatDate('01022009',true)
* Output: 01/02/2009
*
*/
function formatDate(dateVar,flag){
if (typeof dateVar == "undefined")
dateVar = dateToValue(new Date());
else
if (typeof dateVar == "object")
dateVar = dateToValue(dateVar);
if (typeof flag == "undefined")
flag = false;

if(flag)
return dateVar.substr(0,2)+'/'+dateVar.substr(2,2)+'/'+dateVar.substr(4,4);
else
return dateVar.substr(0,2)+dateVar.substr(3,2)+dateVar.substr(6,4);
}

/* Agruments Type : date, date, number, boolean
* Purpose : calculate the date difference
* Author :none
* Description :
* eg. dateDifference('01/01/2009')
* Output: diffence of '01/01/2009' and today in days
* dateDifference('02/01/2009','01/01/2009')
* Output: diffence of '01/01/2009' and '01/01/2009' in days
* : 1
* dateDifference('02/01/2009','01/01/2009',0)
* Output: difference in days
* dateDifference('01/05/2009','01/01/2009',1)
* Output: difference in months
* : 4
* dateDifference('01/01/2010','01/01/2015',2)
* Output: difference in years
* : 5
*
* flag : 0 for days, 1 for months, 2 for years
*
* dateDifference('01/01/2010','01/01/2015',2,true)
* Output: will round the difference*
*
*/
function dateDifference(dateVar1,dateVar2,flag,n){
date1 = valueToDate(dateVar1);
if (typeof dateVar2 == "undefined")
date2 = new Date();
else
date2 = valueToDate(dateVar2);
diff = date1 - date2;
if (typeof flag == "undefined")
flag = 1;
else {
if(flag == 0)
flag = 1;
else
if(flag == 1)
flag = 30;
else
if(flag == 2)
flag = 360;
}
if(typeof n == "undefined")
n = false;
else
n = true;
if(n)
return Math.round(diff/(86400000 * flag ));
else
return diff/(86400000 * flag );
}

/* Agruments Type : string in 'dd/mm/yyyy' or 'mm/yyyy' or 'yyyy' format
* or
* Date value , number
*
* Purpose : add the days to date
* Author :none
* Description :
* eg. addDays() or addDays(new Date()) or addDays(new Date(),1)
* Output: will return date string of next day
* addDays('01/02/2009')
* Output: 02/02/2009
* addDays('01/02/2009',5)
* Output: 06/02/2009*
*/
function addDays(dateVar,dd){
var date1;
if (typeof dateVar == "undefined")
date1 = new Date();
else
if (typeof dateVar == "string")
date1 = valueToDate(dateVar);
else
date1 = dateVar;
if (typeof dd == "undefined")
dd = 1;
date1.setTime( date1.getTime() + dd * 24 * 60 * 60 * 1000);
return dateToValue(date1);
}

/* Purpose : Limit the length of object like textarea
* Author :none
* How to use : onkeypress="return imposeMaxLength(this, 100);"
*/
function imposeMaxLength(Object, MaxLen)
{
return (Object.value.length <= MaxLen -1); } /* Purpose : Date should not be past * */ function notPastDate(id,format){ var input = document.getElementById(id).value; if(input == '' || input == null) return true; var date1 = new Date(); var n = 0; if ( format == 'dd/mm/yyyy') n = 7; else if ( format == 'mm/yyyy') n =4; else if (format == 'yyyy') n = 1; if( n == 7){ var day = parseInt(input.substr(0,2),10); date1.setDate(day); } if ( n >= 4){
var month = parseInt(input.substr(n-4,2),10) -1;
date1.setMonth(month);
}
if ( n > 0){
var year = parseInt(input.substr(n-1,4),10);
date1.setYear(year);
}


if(date1 >= new Date() )
return true;
else
return false;

}

function printWithoutView(printFlag)
{
if(printFlag =="print")
{
window.print();
}

return true;
}

//
function printWithView(printFlag)
{
if(printFlag =="print")
{

var url=contextPath + "/jsp/common/printFile.html";
window.open(url,'1111','width=750,height=750,status=no,\n\
resizable=no,scrollbars=yes,dependent=yes,left=120,top=80,location=no');
}

return true;
}

//function loadStyleClasses(){
// nodes = document.body.getElementsByTagName("input");
// for(var i=0; i m ){
if(val==0)
document.getElementById(id).value = "0."
else
document.getElementById(id).value = Math.floor(val/10) + '.' + ( val - (Math.floor(val/10)*10) ) ;

}
}

if(document.getElementById(id).value.toString().indexOf('.') != -1) {
parts = document.getElementById(id).value.split('.');

if ( parts[1].length > n )
flag1 = true;

if ( parseInt(parts[0]) > (Math.pow(10,m) - 1)) {
document.getElementById(id).value = Math.floor(parseInt(parts[0],10)/10) + parseFloat(parts[1],10) * 0.1 ;
}

}
if(flag1)
document.getElementById(id).value = val.toFixed(n) ;
}

/*
* eg. onkeyup="onlyDouble('check1',5,2)" onKeyPress= "onlyDoubleSupporter(event,'check1')" maxlength="8"
*/
function onlyDoubleSupporter(e,id,errorId){
var flag = false;

if (e.keyCode) {
code = e.keyCode; flag = true;
}
else if (e.which) code = e.which;

var char1 = String.fromCharCode(code);

if(code!=8 && code!=13 && !( code==118 && e.ctrlKey) && !( code==99 && e.ctrlKey))
if ( (( (code < 48) || (code > 57)) && char1!='.' ) || ( char1 == '.' && document.getElementById(id).value.toString().indexOf('.')!=-1) ){
e.cancelBubble = true;

if(!flag){
if (e.stopPropagation) e.stopPropagation();
e.preventDefault();
}
else
e.returnValue = false;
if(typeof errorId != "undefined" )
show(errorId);
return;
}

if(typeof errorId != "undefined" )
hide(errorId);
}

/* Agruments Type : fromId,toId,errorId,flag
* Purpose : From Date Should not be greater than To Date
* Author :none
* Description :
* eg. fromDateValidate('fromDateTxt','toDateTxt','fromDateTxtErr2',ret );
*/

function fromDateValidate(fromId,toId,errorId,flag){
return validateCommon(fromId,errorId ,valueToDate(getValueFromId(fromId)) <= valueToDate(getValueFromId(toId)),flag ); } /* Agruments Type : id,errId,val,ret * Purpose : if value of field is val then show error * Author :none * Description : * eg. ret = invalidValue('policyNoTxt','policyNoTxtErr3',0,ret) */ function invalidValue(id,errId,val,ret){ return validateCommon(id,errId,parseInt(document.getElementById(id).value,10) != val,ret); } //// Block Backspace / F5 / Control+N if (typeof window.event == 'undefined'){ document.onkeydown = function(e){ try{ var test_var=e.target.nodeName.toUpperCase(); if (e.target.type) var test_type=e.target.type.toUpperCase(); if (e.keyCode == 116 || (e.keyCode == 78 && e.ctrlKey) ){ e.preventDefault(); } else if ((test_var == 'INPUT' && test_type == 'TEXT') || test_var == 'TEXTAREA'){ return e.keyCode; }else if (e.keyCode == 8){ e.preventDefault(); } } catch(err){} } }else{ document.onkeydown = function(){ var test_var=event.srcElement.tagName.toUpperCase(); if (event.srcElement.type) var test_type=event.srcElement.type.toUpperCase(); if (event.keyCode == 116 || (event.keyCode == 78 && event.ctrlKey) ){ event.returnValue=false; event.keyCode = 0; } else if ((test_var == 'INPUT' && test_type == 'TEXT') || test_var == 'TEXTAREA'){ return; }else if (event.keyCode == 8){ event.returnValue=false; event.keyCode = 0; } } } /////// END OF Block Backspace / F5 / Control+N /* Agruments Type : NONE * Purpose : Handles multiple submit * Author :none * */ function beforeSubmit(){ //show('boxWait'); document.body.style.cursor = "wait"; nodes = document.getElementsByTagName('input'); for(i=0;i= len && cursorPos==len) && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0,len);
input.form[(getIndex(input)+1) % input.form.length].focus();
return true;
}else{
return false;
}

function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length) if(arr[index] == ele){ //alert("arr[index]-"+arr[index]); found = true; }else{ //alert("arr[index]-"+arr[index]); index++; } return found; } function getIndex(input) { var index = -1, i = 0, found = false; while (i < input.form.length && index == -1) if (input.form[i] == input)index = i; else i++; return index; } return true; } function getCursorPosition(input) { // HERE txt is the text field name var obj=input.value; var CurPos = 0; //FOR IE if (document.selection) { input.focus(); var Sel = document.selection.createRange(); Sel.moveStart ('character', -input.value.length); CurPos = Sel.text.length; } // For Firefox //else if (input.selectionStart input.selectionStart == '0') else if (typeof input.selectionStart != 'undefined') CurPos = input.selectionStart; return CurPos; } function selectAutoJumb(input){ input.form[(getCurrentIndex(input)+1) % input.form.length].focus(); function getCurrentIndex(input) { var index = -1, i = 0, found = false; while (i < input.form.length && index == -1) if (input.form[i] == input)index = i; else i++; return index; } } // End of file // Revisions Number - Author // 1.5 -none /* Common Javascript File version 1.5 Author :none */ /**************** Functions **************************/ /* * Agruments Type : N(id) * Purpose : Makes components visible * Author :none * Description : * You can pass any number of html field ids to it. * All the html fields will get Appeared. */ function show(){ var argumentValues = show.arguments; var argumentCount = show.arguments.length; for ( i=0;i 57)){
e.cancelBubble = true;

if(!flag){
if (e.stopPropagation) e.stopPropagation();
e.preventDefault();
}
else
e.returnValue = false;
if(typeof errorId != "undefined" )
show(errorId);
return;
}
if(typeof errorId != "undefined" )
hide(errorId);
}

/*
* Agruments Type : id,fomrmat
* Purpose : Validate Date fomrmat
* Author :none
* Description :
* Function for validating Date, a utility function
*/
function validDateFormat(id,format){
ret = false;
if(id == null || format==null){
return false;
}
dateVal = document.getElementById(id).value;

if (dateVal !="" )
{
if ( format == "dd/mm/yyyy" )
re = /^\d{2}\/\d{2}\/\d{4}$/;
else
if ( format == "mm/yyyy" )
re = /^\d{1,2}\/\d{4}$/;
else
return ret;
if(dateVal.match(re) )
ret = true;
}

return ret;
}

/*
* Agruments Type : id,errorId,flag
* Purpose : Validate Date
* Author :none
* Description :
* Function for validating Date, a Client Side Validation
* Last flag is optional , only for when moth -00 is acceptable
*/
function validateDate(id,errorId,format,flag,flag00){
ret = false;
if(id == null || errorId == null || format==null){
hide(errorId);
return ret;
}

if( typeof flag00 == "undefined")
flag00 = false;

dateVal = document.getElementById(id).value;
if(dateVal == 'dd/mm/yyyy' ||dateVal == 'mm/yyyy'||dateVal == 'yyyy' ){
hide(errorId);
return false;
}
if (dateVal !="" )
{
if ( format == "dd/mm/yyyy" )
re = /^\d{2}\/\d{2}\/\d{4}$/;
else
if ( format == "mm/yyyy" )
re = /^\d{1,2}\/\d{4}$/;
else
if ( format == "yyyy" )
re = /^\d{4}$/;
else
return ret;
if(!dateVal.match(re) || !validDate(dateVal,format,flag00) )
{
show(errorId);
if(flag)
setFocus(id);
}
else
{
hide(errorId);
ret = true;
}
return ret;
}
else
{
hide(errorId);
return ret;
}
}

/*
* Agruments Type : N (id)
* Purpose : check for required/null for n no of fields
* Author :none
* Description :
* Function for required check, a Client Side Validation
*/
function requiredFields(){
var flag;
var argumentValues = requiredFields.arguments;
var argumentCount = requiredFields.arguments.length;
var i=0;
var j=-1;
flag = true;
while(i < (2 * (argumentCount/2) - 1) ) { var val = document.getElementById(argumentValues[i]).value ; if(val=='dd/mm/yyyy' || val=='mm/yyyy' || val == 'yyyy') val =''; if ( val == null || val == "" || val.replace(/^\s+|\s+$/g,"").length == 0 ) { show(argumentValues[i+1]); if(flag) j = i; flag = false; } else{ hide(argumentValues[i+1]); } i = i + 2; } if(j!=-1) setFocus(argumentValues[j]); return flag; } /* * Agruments Type : id,errorId,flag * Purpose : Validate Email * Author :none * Description : * Function for validating Email, a Client Side Validation* */ function validateEmail(id,errorId,flag){ var email = document.getElementById(id); var filter = /^([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+$/; if (email.value!="" &&!filter.test(email.value)) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,flag * Purpose : Validate Single Field Option * Author :none * Description : * Function for validating single character field, a Client Side Validation * here choice is string of valid options * eg. 'abc' , now only a or b or c is valid. */ function validateSingleFieldOption(id,errorId,choice,flag){ var item = document.getElementById(id); if ( item.value!="" && choice.indexOf(item.value)== -1) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,flag * Purpose : Validate Number (Integer) * Author :none * Description : * Function for validating Numeric Data, a Client Side Validation * eg. 10 , 123, 123 are valid * */ function validateNumber(id,errorId,flag){ var item = document.getElementById(id); if ( item.value!="" && !isNumeric(item.value)) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,flag * Purpose : Validate Number(Double) * Author :none * Description : * Function for validating Numeric Data, a Client Side Validation * eg. 10.1 , 123, 12.3 are valid * */ function validateDecimalNumber(id,errorId,flag){ var item = document.getElementById(id); if ( item.value!="" && !isDecimal(item.value)) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,funcId,flag * Purpose : Common Validation Function * Author :none * Description : * FuncId is business logic, this function will take care of error handling you just * need to pass your function id. * eg. * validateCommon('amtTxt','amtTxtErr1',isNumeric( 123 ),flag) * */ function validateCommon(id,errorId,funcId,flag){ var item = document.getElementById(id); if ( item.value!="" && ! funcId) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,len,flag * Purpose : lengh must be len * Author :none * Description : * length should be equal to len* * eg. * ret = validateExactLength('policyNoTxt','policyNoTxtErr1',9,ret) && ret; * */ function validateExactLength(id,errorId,len,flag){ var item = document.getElementById(id); if ( item.value!="" && item.value.length != len ) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,len,flag * Purpose : lengh must be minimum len * Author :none * Description : * length should be greater than equal to len* * eg. * ret = validateMinLength('policyNoTxt','policyNoTxtErr1',7,ret) && ret; * */ function validateMinLength(id,errorId,len,flag){ var item = document.getElementById(id); if ( item.value!="" && item.value.length < len ) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,len1,len2,flag * Purpose : Lenght in range of len1 and len2 * Author :none * Description : * Lenght should >= len1 and <= len2 * eg. * ret = validateLengthinRange('amtTxt','amtTxtErr0',3,6,ret) && ret; * */ function validateLengthinRange(id,errorId,len1,len2,flag){ var item = document.getElementById(id); if ( item.value!="" && ( item.value.length < len1 || item.value.length > len2) ) {
show(errorId);
if(flag)
setFocus(id);
return false;
}
else{
hide(errorId);
return true;
}
}

/*
* Agruments Type : String
* Purpose : checks whether String is numeric(integer) // not for client side js validation// Just a utility function
* Author :none
* Description :
* You can pass any string to it.
* It will check whether it is Numeric or not.
*/
function isNumeric(sText){
var filter = /^-{0}\d*\.{0}\d+$/;
return filter.test(sText);
}

/*
* Agruments Type : String
* Purpose : checks whether String is numeric(decimal) // not for client side js validation// Just a utility function
* Author :none
* Description :
* You can pass any string to it.
* It will check whether it is Numeric or not.
*/
function isDecimal(sText){
var filter = /^-{0}\d*\.{0,1}\d+$/;
return filter.test(sText);
}



/*
* Agruments Type : date ( value not id )
* Purpose : checks whether date is valid // not for client side js validation// Just a utility function
* Author :none
* Description :
* You can pass any date to it like dd/mm/yy or dd-mm-yyyy or dd.mm.yyyy
* It will check whether it is Numeric or not.
*/
function validDate(field,format,flag00){
var checkstr = "0123456789";
var DateValue = "";
var DateTemp = "";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;

if( typeof flag00 == "undefined")
flag00 = false;

err = 0;
DateValue = field;
/* Delete all chars except 0..9 */
for (i = 0; i < DateValue.length; i++) { if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
DateTemp = DateTemp + DateValue.substr(i,1);
}
}
DateValue = DateTemp;
/* Always change date to 8 digits - string*/

if (format == 'dd/mm/yyyy') {
err = 0;
}

if (format == 'mm/yyyy') {
err = 2;
}

if( format == 'yyyy') {
if( parseInt(DateValue,10)=='0')
return false;
else
return true;
}

/* year is wrong if year = 0000 */
year = DateValue.substr(4-err,4);
if (year == 0000) {
err = 20;
}
/* Validation of month*/
month = DateValue.substr(2-err,2);
if ((month < 1 && !flag00) || (month > 12)) {
err = 21;
}

if(err==0) {
/* Validation of day*/
day = DateValue.substr(0,2);
if (day < 1) { err = 22; } /* Validation leap-year / february / day */ if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) { leap = 1; } if ((month == 2) && (leap == 1) && (day > 29)) {
err = 23;
}
if ((month == 2) && (leap != 1) && (day > 28)) {
err = 24;
}
/* Validation of other months */

if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
err = 25;
}
if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
err = 26;
}
if (day == 00) {
err = 27;
}
}
/* if 00 ist entered , it is error*/
if ((month == 00) && (year == 0000)) {
err = 27;
}
/* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
if (err <= 2) { //DateField.value = day + seperator + month + seperator + year; return true; } /* Error-message if err != 0 */ else { return false; } } function viewPrint(){ var argumentValues = viewPrint.arguments; var argumentCount = viewPrint.arguments.length; var printPath; var url; //alert(argumentCount); if(argumentCount == 1){ //alert(argumentValues[0]); printPath = argumentValues[0]; url=contextPath + "/viewPrintFile.action?"+"printPath="+printPath+"&type=multiple"; window.open(url,'newWin1','status=no,\n\ resizable=yes,scrollbars=yes,dependent=yes,left=120,top=80,location=no'); }else if(argumentCount == 0){ printPath = document.getElementById("nextStepPath").value; url=contextPath + "/printAction.action?"+"printPath="+printPath; window.open(url,'newWin1','status=no,\n\ resizable=yes,scrollbars=yes,dependent=yes,left=120,top=80,location=no'); } return false; } // Author : None function edms(policyNumber){ url = contextPath+"/EdmsAction.action?"+"policyNumber="+policyNumber; window.open(url,'newWin1'); } // Author : None function silentPrint(printPath) { //alert("testing "); //alert('testing context path-----> '+appletUrl);
var servletPath = appletUrl;
//alert('print path -> '+printPath);
if(printPath != "" && servletPath != ""){
document.PrintApplet.printFile(printPath, servletPath);
}
//alert("done");
return true;
}

// Author : None
function deletePrintFile(printFilePath){
url=contextPath + "/deletePrintFile.action?"+"printPath="+printFilePath;
window.open(url,'newWin1','status=no,width=1,height=1,left=0,top=0');
}

/*
* Agruments Type : none
* Purpose : Opens a window, having result of your print file
* Author :none
* Description :
* wiill open a new window/popup for print file
*/

function displayPrintFile(){
// window.open('', 'newWin', 'width=750,height=600,status=no,resizable=no,scrollbars=no,dependent=yes,left=120,top=80');
// document.getElementById(formId).target = "newWin";
// document.getElementById(formId).action=actionName;
// document.getElementById(formId).submit();
var url=contextPath + "/jsp/common/printFile.html";
window.open(url,'newWin1','width=750,height=650,status=no,\n\
resizable=no,scrollbars=yes,dependent=yes,left=120,top=80,location=no');
return false;

}


/***********************NUMERICAL INPUT MASKING FUNCTIONS*****************************************/

/* Agruments Type : event.keyCode, this, mask
* Purpose : input masking
* Author :none
* Description :
* Last option is mask,
* it could ##-## or ##/##### or ##/##/#### etc
* eg.
* onKeyDown="javascript:return dFilter (event.keyCode, this, '##/##/####')"
*
*/
var dFilterStep;

function dFilterStrip (dFilterTemp, dFilterMask)
{
dFilterMask = replace(dFilterMask,'#','');
for (dFilterStep = 0; dFilterStep < dFilterMask.length++; dFilterStep++) { dFilterTemp = replace(dFilterTemp,dFilterMask.substring(dFilterStep,dFilterStep+1),''); } return dFilterTemp; } function dFilterMax (dFilterMask) { dFilterTemp = dFilterMask; for (dFilterStep = 0; dFilterStep < (dFilterMask.length+1); dFilterStep++) { if (dFilterMask.charAt(dFilterStep)!='#') { dFilterTemp = replace(dFilterTemp,dFilterMask.charAt(dFilterStep),''); } } return dFilterTemp.length; } function dFilter (key, textbox, dFilterMask) { dFilterNum = dFilterStrip(textbox.value, dFilterMask); if (key==9) { return true; } else if (key==8&&dFilterNum.length!=0) { dFilterNum = dFilterNum.substring(0,dFilterNum.length-1); } else if ( ((key>47&&key<58)||(key>95&&key<106)) && dFilterNum.length95&&key<106) key = parseInt(key) - 48; dFilterNum=dFilterNum+String.fromCharCode(key); } var dFilterFinal=''; for (dFilterStep = 0; dFilterStep < dFilterMask.length; dFilterStep++) { if (dFilterMask.charAt(dFilterStep)=='#') { if (dFilterNum.length!=0) { dFilterFinal = dFilterFinal + dFilterNum.charAt(0); dFilterNum = dFilterNum.substring(1,dFilterNum.length); } else { dFilterFinal = dFilterFinal + ""; } } else if (dFilterMask.charAt(dFilterStep)!='#') { dFilterFinal = dFilterFinal + dFilterMask.charAt(dFilterStep); } } textbox.value = dFilterFinal; return false; } function replace(fullString,text,by) { // Replaces text with by in string var strLength = fullString.length, txtLength = text.length; if ((strLength == 0) || (txtLength == 0)) return fullString; var i = fullString.indexOf(text); if ((!i) && (text != fullString.substring(0,txtLength))) return fullString; if (i == -1) return fullString; var newstr = fullString.substring(0,i) + by; if (i+txtLength < strLength) newstr += replace(fullString.substring(i+txtLength,strLength),text,by); return newstr; } /****************************END OF INPUT MASKING FUNCTIONS*******************************/ /* * Agruments Type : id ( id of datefield), format ( dd/mm/yyyy or mm/yyyy or yyyy ) * Purpose : check for current or back dates * Author :none * Description : * Today or back dates are valid :returns true * future dates are invalid : returs false * * validateCommon ('deathDtTxt','deathDtTxtErr2',notFutureDate('deathDtTxt','dd/mm/yyyy'),ret)&& ret; */ function notFutureDate(id,format){ var input = document.getElementById(id).value; if(input == '' || input == null) return true; var date1 = new Date(); var n = 0; if ( format == 'dd/mm/yyyy') n = 7; else if ( format == 'mm/yyyy') n =4; else if (format == 'yyyy') n = 1; if( n == 7){ var day = parseInt(input.substr(0,2),10); date1.setDate(day); } if ( n >= 4){
var month = parseInt(input.substr(n-4,2),10) -1;
date1.setMonth(month);
}
if ( n > 0){
var year = parseInt(input.substr(n-1,4),10);
date1.setYear(year);
}


if(date1 <= new Date() ) return true; else return false; } /* Agruments Type : id ( id of datefield), startDate, EndDate * Purpose : check for date is between or eqaul of startDate and EndDate * Author :none * Description : * dateInRange('id1','01/01/2009','31/12/2009') * for client side validate call : validateCommon('id','errorId',dateInRange('id1','01/01/2009','31/12/2009') * ,true) */ function dateInRange(id,startDate,endDate){ var input = document.getElementById(id).value; if(input == '' || input == null) return true; var date1 = new Date(); var date2 = new Date(); var date3 = new Date(); len1 = startDate.length; len2 = endDate.length; len3 = input.length; if( (len1 != len2) || (len2 != len3)) return false; var n = 0; if ( len1 == 10 ) n = 7; else if ( len1 == 7) n =4; else if (len1 == 4) n = 1; if( n == 7){ date1.setDate(parseInt(input.substr(0,2),10)); date2.setDate(parseInt(startDate.substr(0,2),10)); date3.setDate(parseInt(endDate.substr(0,2),10)); } if ( n >= 4){
date1.setMonth(parseInt(input.substr(n-4,2),10)-1);
date2.setMonth(parseInt(startDate.substr(n-4,2),10)-1);
date3.setMonth(parseInt(endDate.substr(n-4,2),10)-1);
}
if ( n > 0){
date1.setYear(parseInt(input.substr(n-1 ,4),10));
date2.setYear(parseInt(startDate.substr(n-1,4),10));
date3.setYear(parseInt(endDate.substr(n-1,4),10));
}

if( date1 >= date2 && date1 <= date3 ) return true; else return false; } /* Agruments Type : id * Purpose : returns the value of html component * Author :none * Description : * eg. this.value = getValueFromId('policyNoTxt'); * */ function getValueFromId(id){ return document.getElementById(id).value; } /* Agruments Type : id,val * Purpose : set the value of html component * Author :none * Description : * eg. setValueInId('policyNoTxt','111111111'); * setValueInId('policyNoTxt',12232323); * setValueInId('policyNoTxt',new Date());* * */ function setValueInId(id,val){ document.getElementById(id).value = val; } /* Agruments Type : id,id * Purpose : copy value of html component * Author :none * Description : * eg. copyValfromIdtoId('scrId','DesId'); * */ function copyValfromIdtoId(idScr,idDes){ document.getElementById(idDes).value = document.getElementById(idScr).value; } /* Agruments Type : id,id * Purpose : makes the single digit to double * Author :none * Description : * eg. makeDoubleDigit(5), will return '05' * */ function makeDoubleDigit(IntVal){ if( IntVal < 10 ) IntVal = '0'+IntVal; return IntVal; } /* Agruments Type : Date value * Purpose : convert Date value to 'dd/mm/yyyy' or 'mm/yyyy' or 'yyyy' format * Author :none * Description : * eg. dateToValue(new Date()) * Output: '01/01/2009' ( will return todays date in dd/mm/yyyy format) * dateToValue(new Date(),'dd/mm/yyyy') * Output: '01/01/2009' ( will return todays date in dd/mm/yyyy format) * dateToValue(new Date(),'mm/yyyy') * Output: '01/2009' ( will return todays date in mm/yyyy format) * dateToValue(new Date(),'yyyy') * Output: '2009' ( will return todays date in yyyy format) * */ function dateToValue(dateVar,format){ var dd = dateVar.getDate(); var mm = dateVar.getMonth()+1; var yy = dateVar.getFullYear(); var retVal; if (typeof format == "undefined") format = "dd/mm/yyyy"; if(format == 'dd/mm/yyyy') retVal = makeDoubleDigit(dd)+'/'+makeDoubleDigit(mm)+'/'+yy; if(format == 'mm/yyyy') retVal = makeDoubleDigit(mm)+'/'+yy; if(format == 'yyyy') retVal = yy; return retVal; } /* Agruments Type : string in 'dd/mm/yyyy' or 'mm/yyyy' or 'yyyy' format * Purpose : convert value from 'dd/mm/yyyy' or 'mm/yyyy' or 'yyyy' format to date value * Author :none * Description : * eg. valueToDate('01/01/2009') * valueToDate('01/2009') * valueToDate('2009') * */ function valueToDate(value){ var len = value.length; dateVar = new Date(); if(len >= 10)
dateVar.setDate(value.substr(0,2));
if(len >= 7)
dateVar.setMonth(value.substr(len - 7,2)-1);
if(len >=4 )
dateVar.setFullYear(value.substr(len -4,4));

return dateVar;
}

/* Agruments Type : string in 'dd/mm/yyyy' or 'mm/yyyy' or 'yyyy' format
* or
* Date value
*
* Purpose : removes '/' or add '/' from date
* Author :none
* Description :
* eg. formatDate()
* Output: 01012000
* formatDate('01/02/2009')
* Output: 01022009
* formatDate('01/02/2009',false)
* Output: 01022009
* formatDate('01022009',true)
* Output: 01/02/2009
*
*/
function formatDate(dateVar,flag){
if (typeof dateVar == "undefined")
dateVar = dateToValue(new Date());
else
if (typeof dateVar == "object")
dateVar = dateToValue(dateVar);
if (typeof flag == "undefined")
flag = false;

if(flag)
return dateVar.substr(0,2)+'/'+dateVar.substr(2,2)+'/'+dateVar.substr(4,4);
else
return dateVar.substr(0,2)+dateVar.substr(3,2)+dateVar.substr(6,4);
}

/* Agruments Type : date, date, number, boolean
* Purpose : calculate the date difference
* Author :none
* Description :
* eg. dateDifference('01/01/2009')
* Output: diffence of '01/01/2009' and today in days
* dateDifference('02/01/2009','01/01/2009')
* Output: diffence of '01/01/2009' and '01/01/2009' in days
* : 1
* dateDifference('02/01/2009','01/01/2009',0)
* Output: difference in days
* dateDifference('01/05/2009','01/01/2009',1)
* Output: difference in months
* : 4
* dateDifference('01/01/2010','01/01/2015',2)
* Output: difference in years
* : 5
*
* flag : 0 for days, 1 for months, 2 for years
*
* dateDifference('01/01/2010','01/01/2015',2,true)
* Output: will round the difference*
*
*/
function dateDifference(dateVar1,dateVar2,flag,n){
date1 = valueToDate(dateVar1);
if (typeof dateVar2 == "undefined")
date2 = new Date();
else
date2 = valueToDate(dateVar2);
diff = date1 - date2;
if (typeof flag == "undefined")
flag = 1;
else {
if(flag == 0)
flag = 1;
else
if(flag == 1)
flag = 30;
else
if(flag == 2)
flag = 360;
}
if(typeof n == "undefined")
n = false;
else
n = true;
if(n)
return Math.round(diff/(86400000 * flag ));
else
return diff/(86400000 * flag );
}

/* Agruments Type : string in 'dd/mm/yyyy' or 'mm/yyyy' or 'yyyy' format
* or
* Date value , number
*
* Purpose : add the days to date
* Author :none
* Description :
* eg. addDays() or addDays(new Date()) or addDays(new Date(),1)
* Output: will return date string of next day
* addDays('01/02/2009')
* Output: 02/02/2009
* addDays('01/02/2009',5)
* Output: 06/02/2009*
*/
function addDays(dateVar,dd){
var date1;
if (typeof dateVar == "undefined")
date1 = new Date();
else
if (typeof dateVar == "string")
date1 = valueToDate(dateVar);
else
date1 = dateVar;
if (typeof dd == "undefined")
dd = 1;
date1.setTime( date1.getTime() + dd * 24 * 60 * 60 * 1000);
return dateToValue(date1);
}

/* Purpose : Limit the length of object like textarea
* Author :none
* How to use : onkeypress="return imposeMaxLength(this, 100);"
*/
function imposeMaxLength(Object, MaxLen)
{
return (Object.value.length <= MaxLen -1); } /* Purpose : Date should not be past * */ function notPastDate(id,format){ var input = document.getElementById(id).value; if(input == '' || input == null) return true; var date1 = new Date(); var n = 0; if ( format == 'dd/mm/yyyy') n = 7; else if ( format == 'mm/yyyy') n =4; else if (format == 'yyyy') n = 1; if( n == 7){ var day = parseInt(input.substr(0,2),10); date1.setDate(day); } if ( n >= 4){
var month = parseInt(input.substr(n-4,2),10) -1;
date1.setMonth(month);
}
if ( n > 0){
var year = parseInt(input.substr(n-1,4),10);
date1.setYear(year);
}


if(date1 >= new Date() )
return true;
else
return false;

}

function printWithoutView(printFlag)
{
if(printFlag =="print")
{
window.print();
}

return true;
}

//
function printWithView(printFlag)
{
if(printFlag =="print")
{

var url=contextPath + "/jsp/common/printFile.html";
window.open(url,'1111','width=750,height=750,status=no,\n\
resizable=no,scrollbars=yes,dependent=yes,left=120,top=80,location=no');
}

return true;
}

//function loadStyleClasses(){
// nodes = document.body.getElementsByTagName("input");
// for(var i=0; i m ){
if(val==0)
document.getElementById(id).value = "0."
else
document.getElementById(id).value = Math.floor(val/10) + '.' + ( val - (Math.floor(val/10)*10) ) ;

}
}

if(document.getElementById(id).value.toString().indexOf('.') != -1) {
parts = document.getElementById(id).value.split('.');

if ( parts[1].length > n )
flag1 = true;

if ( parseInt(parts[0]) > (Math.pow(10,m) - 1)) {
document.getElementById(id).value = Math.floor(parseInt(parts[0],10)/10) + parseFloat(parts[1],10) * 0.1 ;
}

}
if(flag1)
document.getElementById(id).value = val.toFixed(n) ;
}

/*
* eg. onkeyup="onlyDouble('check1',5,2)" onKeyPress= "onlyDoubleSupporter(event,'check1')" maxlength="8"
*/
function onlyDoubleSupporter(e,id,errorId){
var flag = false;

if (e.keyCode) {
code = e.keyCode; flag = true;
}
else if (e.which) code = e.which;

var char1 = String.fromCharCode(code);

if(code!=8 && code!=13 && !( code==118 && e.ctrlKey) && !( code==99 && e.ctrlKey))
if ( (( (code < 48) || (code > 57)) && char1!='.' ) || ( char1 == '.' && document.getElementById(id).value.toString().indexOf('.')!=-1) ){
e.cancelBubble = true;

if(!flag){
if (e.stopPropagation) e.stopPropagation();
e.preventDefault();
}
else
e.returnValue = false;
if(typeof errorId != "undefined" )
show(errorId);
return;
}

if(typeof errorId != "undefined" )
hide(errorId);
}

/* Agruments Type : fromId,toId,errorId,flag
* Purpose : From Date Should not be greater than To Date
* Author :none
* Description :
* eg. fromDateValidate('fromDateTxt','toDateTxt','fromDateTxtErr2',ret );
*/

function fromDateValidate(fromId,toId,errorId,flag){
return validateCommon(fromId,errorId ,valueToDate(getValueFromId(fromId)) <= valueToDate(getValueFromId(toId)),flag ); } /* Agruments Type : id,errId,val,ret * Purpose : if value of field is val then show error * Author :none * Description : * eg. ret = invalidValue('policyNoTxt','policyNoTxtErr3',0,ret) */ function invalidValue(id,errId,val,ret){ return validateCommon(id,errId,parseInt(document.getElementById(id).value,10) != val,ret); } //// Block Backspace / F5 / Control+N if (typeof window.event == 'undefined'){ document.onkeydown = function(e){ try{ var test_var=e.target.nodeName.toUpperCase(); if (e.target.type) var test_type=e.target.type.toUpperCase(); if (e.keyCode == 116 || (e.keyCode == 78 && e.ctrlKey) ){ e.preventDefault(); } else if ((test_var == 'INPUT' && test_type == 'TEXT') || test_var == 'TEXTAREA'){ return e.keyCode; }else if (e.keyCode == 8){ e.preventDefault(); } } catch(err){} } }else{ document.onkeydown = function(){ var test_var=event.srcElement.tagName.toUpperCase(); if (event.srcElement.type) var test_type=event.srcElement.type.toUpperCase(); if (event.keyCode == 116 || (event.keyCode == 78 && event.ctrlKey) ){ event.returnValue=false; event.keyCode = 0; } else if ((test_var == 'INPUT' && test_type == 'TEXT') || test_var == 'TEXTAREA'){ return; }else if (event.keyCode == 8){ event.returnValue=false; event.keyCode = 0; } } } /////// END OF Block Backspace / F5 / Control+N /* Agruments Type : NONE * Purpose : Handles multiple submit * Author :none * */ function beforeSubmit(){ //show('boxWait'); document.body.style.cursor = "wait"; nodes = document.getElementsByTagName('input'); for(i=0;i= len && cursorPos==len) && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0,len);
input.form[(getIndex(input)+1) % input.form.length].focus();
return true;
}else{
return false;
}

function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length) if(arr[index] == ele){ //alert("arr[index]-"+arr[index]); found = true; }else{ //alert("arr[index]-"+arr[index]); index++; } return found; } function getIndex(input) { var index = -1, i = 0, found = false; while (i < input.form.length && index == -1) if (input.form[i] == input)index = i; else i++; return index; } return true; } function getCursorPosition(input) { // HERE txt is the text field name var obj=input.value; var CurPos = 0; //FOR IE if (document.selection) { input.focus(); var Sel = document.selection.createRange(); Sel.moveStart ('character', -input.value.length); CurPos = Sel.text.length; } // For Firefox //else if (input.selectionStart input.selectionStart == '0') else if (typeof input.selectionStart != 'undefined') CurPos = input.selectionStart; return CurPos; } function selectAutoJumb(input){ input.form[(getCurrentIndex(input)+1) % input.form.length].focus(); function getCurrentIndex(input) { var index = -1, i = 0, found = false; while (i < input.form.length && index == -1) if (input.form[i] == input)index = i; else i++; return index; } } // End of file // Revisions Number - Author // 1.5 -none /* Common Javascript File version 1.5 Author :none */ /**************** Functions **************************/ /* * Agruments Type : N(id) * Purpose : Makes components visible * Author :none * Description : * You can pass any number of html field ids to it. * All the html fields will get Appeared. */ function show(){ var argumentValues = show.arguments; var argumentCount = show.arguments.length; for ( i=0;i 57)){
e.cancelBubble = true;

if(!flag){
if (e.stopPropagation) e.stopPropagation();
e.preventDefault();
}
else
e.returnValue = false;
if(typeof errorId != "undefined" )
show(errorId);
return;
}
if(typeof errorId != "undefined" )
hide(errorId);
}

/*
* Agruments Type : id,fomrmat
* Purpose : Validate Date fomrmat
* Author :none
* Description :
* Function for validating Date, a utility function
*/
function validDateFormat(id,format){
ret = false;
if(id == null || format==null){
return false;
}
dateVal = document.getElementById(id).value;

if (dateVal !="" )
{
if ( format == "dd/mm/yyyy" )
re = /^\d{2}\/\d{2}\/\d{4}$/;
else
if ( format == "mm/yyyy" )
re = /^\d{1,2}\/\d{4}$/;
else
return ret;
if(dateVal.match(re) )
ret = true;
}

return ret;
}

/*
* Agruments Type : id,errorId,flag
* Purpose : Validate Date
* Author :none
* Description :
* Function for validating Date, a Client Side Validation
* Last flag is optional , only for when moth -00 is acceptable
*/
function validateDate(id,errorId,format,flag,flag00){
ret = false;
if(id == null || errorId == null || format==null){
hide(errorId);
return ret;
}

if( typeof flag00 == "undefined")
flag00 = false;

dateVal = document.getElementById(id).value;
if(dateVal == 'dd/mm/yyyy' ||dateVal == 'mm/yyyy'||dateVal == 'yyyy' ){
hide(errorId);
return false;
}
if (dateVal !="" )
{
if ( format == "dd/mm/yyyy" )
re = /^\d{2}\/\d{2}\/\d{4}$/;
else
if ( format == "mm/yyyy" )
re = /^\d{1,2}\/\d{4}$/;
else
if ( format == "yyyy" )
re = /^\d{4}$/;
else
return ret;
if(!dateVal.match(re) || !validDate(dateVal,format,flag00) )
{
show(errorId);
if(flag)
setFocus(id);
}
else
{
hide(errorId);
ret = true;
}
return ret;
}
else
{
hide(errorId);
return ret;
}
}

/*
* Agruments Type : N (id)
* Purpose : check for required/null for n no of fields
* Author :none
* Description :
* Function for required check, a Client Side Validation
*/
function requiredFields(){
var flag;
var argumentValues = requiredFields.arguments;
var argumentCount = requiredFields.arguments.length;
var i=0;
var j=-1;
flag = true;
while(i < (2 * (argumentCount/2) - 1) ) { var val = document.getElementById(argumentValues[i]).value ; if(val=='dd/mm/yyyy' || val=='mm/yyyy' || val == 'yyyy') val =''; if ( val == null || val == "" || val.replace(/^\s+|\s+$/g,"").length == 0 ) { show(argumentValues[i+1]); if(flag) j = i; flag = false; } else{ hide(argumentValues[i+1]); } i = i + 2; } if(j!=-1) setFocus(argumentValues[j]); return flag; } /* * Agruments Type : id,errorId,flag * Purpose : Validate Email * Author :none * Description : * Function for validating Email, a Client Side Validation* */ function validateEmail(id,errorId,flag){ var email = document.getElementById(id); var filter = /^([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+$/; if (email.value!="" &&!filter.test(email.value)) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,flag * Purpose : Validate Single Field Option * Author :none * Description : * Function for validating single character field, a Client Side Validation * here choice is string of valid options * eg. 'abc' , now only a or b or c is valid. */ function validateSingleFieldOption(id,errorId,choice,flag){ var item = document.getElementById(id); if ( item.value!="" && choice.indexOf(item.value)== -1) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,flag * Purpose : Validate Number (Integer) * Author :none * Description : * Function for validating Numeric Data, a Client Side Validation * eg. 10 , 123, 123 are valid * */ function validateNumber(id,errorId,flag){ var item = document.getElementById(id); if ( item.value!="" && !isNumeric(item.value)) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,flag * Purpose : Validate Number(Double) * Author :none * Description : * Function for validating Numeric Data, a Client Side Validation * eg. 10.1 , 123, 12.3 are valid * */ function validateDecimalNumber(id,errorId,flag){ var item = document.getElementById(id); if ( item.value!="" && !isDecimal(item.value)) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,funcId,flag * Purpose : Common Validation Function * Author :none * Description : * FuncId is business logic, this function will take care of error handling you just * need to pass your function id. * eg. * validateCommon('amtTxt','amtTxtErr1',isNumeric( 123 ),flag) * */ function validateCommon(id,errorId,funcId,flag){ var item = document.getElementById(id); if ( item.value!="" && ! funcId) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,len,flag * Purpose : lengh must be len * Author :none * Description : * length should be equal to len* * eg. * ret = validateExactLength('policyNoTxt','policyNoTxtErr1',9,ret) && ret; * */ function validateExactLength(id,errorId,len,flag){ var item = document.getElementById(id); if ( item.value!="" && item.value.length != len ) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,len,flag * Purpose : lengh must be minimum len * Author :none * Description : * length should be greater than equal to len* * eg. * ret = validateMinLength('policyNoTxt','policyNoTxtErr1',7,ret) && ret; * */ function validateMinLength(id,errorId,len,flag){ var item = document.getElementById(id); if ( item.value!="" && item.value.length < len ) { show(errorId); if(flag) setFocus(id); return false; } else{ hide(errorId); return true; } } /* * Agruments Type : id,errorId,len1,len2,flag * Purpose : Lenght in range of len1 and len2 * Author :none * Description : * Lenght should >= len1 and <= len2 * eg. * ret = validateLengthinRange('amtTxt','amtTxtErr0',3,6,ret) && ret; * */ function validateLengthinRange(id,errorId,len1,len2,flag){ var item = document.getElementById(id); if ( item.value!="" && ( item.value.length < len1 || item.value.length > len2) ) {
show(errorId);
if(flag)
setFocus(id);
return false;
}
else{
hide(errorId);
return true;
}
}

/*
* Agruments Type : String
* Purpose : checks whether String is numeric(integer) // not for client side js validation// Just a utility function
* Author :none
* Description :
* You can pass any string to it.
* It will check whether it is Numeric or not.
*/
function isNumeric(sText){
var filter = /^-{0}\d*\.{0}\d+$/;
return filter.test(sText);
}

/*
* Agruments Type : String
* Purpose : checks whether String is numeric(decimal) // not for client side js validation// Just a utility function
* Author :none
* Description :
* You can pass any string to it.
* It will check whether it is Numeric or not.
*/
function isDecimal(sText){
var filter = /^-{0}\d*\.{0,1}\d+$/;
return filter.test(sText);
}



/*
* Agruments Type : date ( value not id )
* Purpose : checks whether date is valid // not for client side js validation// Just a utility function
* Author :none
* Description :
* You can pass any date to it like dd/mm/yy or dd-mm-yyyy or dd.mm.yyyy
* It will check whether it is Numeric or not.
*/
function validDate(field,format,flag00){
var checkstr = "0123456789";
var DateValue = "";
var DateTemp = "";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;

if( typeof flag00 == "undefined")
flag00 = false;

err = 0;
DateValue = field;
/* Delete all chars except 0..9 */
for (i = 0; i < DateValue.length; i++) { if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
DateTemp = DateTemp + DateValue.substr(i,1);
}
}
DateValue = DateTemp;
/* Always change date to 8 digits - string*/

if (format == 'dd/mm/yyyy') {
err = 0;
}

if (format == 'mm/yyyy') {
err = 2;
}

if( format == 'yyyy') {
if( parseInt(DateValue,10)=='0')
return false;
else
return true;
}

/* year is wrong if year = 0000 */
year = DateValue.substr(4-err,4);
if (year == 0000) {
err = 20;
}
/* Validation of month*/
month = DateValue.substr(2-err,2);
if ((month < 1 && !flag00) || (month > 12)) {
err = 21;
}

if(err==0) {
/* Validation of day*/
day = DateValue.substr(0,2);
if (day < 1) { err = 22; } /* Validation leap-year / february / day */ if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) { leap = 1; } if ((month == 2) && (leap == 1) && (day > 29)) {
err = 23;
}
if ((month == 2) && (leap != 1) && (day > 28)) {
err = 24;
}
/* Validation of other months */

if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
err = 25;
}
if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
err = 26;
}
if (day == 00) {
err = 27;
}
}
/* if 00 ist entered , it is error*/
if ((month == 00) && (year == 0000)) {
err = 27;
}
/* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
if (err <= 2) { //DateField.value = day + seperator + month + seperator + year; return true; } /* Error-message if err != 0 */ else { return false; } } function viewPrint(){ var argumentValues = viewPrint.arguments; var argumentCount = viewPrint.arguments.length; var printPath; var url; //alert(argumentCount); if(argumentCount == 1){ //alert(argumentValues[0]); printPath = argumentValues[0]; url=contextPath + "/viewPrintFile.action?"+"printPath="+printPath+"&type=multiple"; window.open(url,'newWin1','status=no,\n\ resizable=yes,scrollbars=yes,dependent=yes,left=120,top=80,location=no'); }else if(argumentCount == 0){ printPath = document.getElementById("nextStepPath").value; url=contextPath + "/printAction.action?"+"printPath="+printPath; window.open(url,'newWin1','status=no,\n\ resizable=yes,scrollbars=yes,dependent=yes,left=120,top=80,location=no'); } return false; } // Author : None function edms(policyNumber){ url = contextPath+"/EdmsAction.action?"+"policyNumber="+policyNumber; window.open(url,'newWin1'); } // Author : None function silentPrint(printPath) { //alert("testing "); //alert('testing context path-----> '+appletUrl);
var servletPath = appletUrl;
//alert('print path -> '+printPath);
if(printPath != "" && servletPath != ""){
document.PrintApplet.printFile(printPath, servletPath);
}
//alert("done");
return true;
}

// Author : None
function deletePrintFile(printFilePath){
url=contextPath + "/deletePrintFile.action?"+"printPath="+printFilePath;
window.open(url,'newWin1','status=no,width=1,height=1,left=0,top=0');
}

/*
* Agruments Type : none
* Purpose : Opens a window, having result of your print file
* Author :none
* Description :
* wiill open a new window/popup for print file
*/

function displayPrintFile(){
// window.open('', 'newWin', 'width=750,height=600,status=no,resizable=no,scrollbars=no,dependent=yes,left=120,top=80');
// document.getElementById(formId).target = "newWin";
// document.getElementById(formId).action=actionName;
// document.getElementById(formId).submit();
var url=contextPath + "/jsp/common/printFile.html";
window.open(url,'newWin1','width=750,height=650,status=no,\n\
resizable=no,scrollbars=yes,dependent=yes,left=120,top=80,location=no');
return false;

}


/***********************NUMERICAL INPUT MASKING FUNCTIONS*****************************************/

/* Agruments Type : event.keyCode, this, mask
* Purpose : input masking
* Author :none
* Description :
* Last option is mask,
* it could ##-## or ##/##### or ##/##/#### etc
* eg.
* onKeyDown="javascript:return dFilter (event.keyCode, this, '##/##/####')"
*
*/
var dFilterStep;

function dFilterStrip (dFilterTemp, dFilterMask)
{
dFilterMask = replace(dFilterMask,'#','');
for (dFilterStep = 0; dFilterStep < dFilterMask.length++; dFilterStep++) { dFilterTemp = replace(dFilterTemp,dFilterMask.substring(dFilterStep,dFilterStep+1),''); } return dFilterTemp; } function dFilterMax (dFilterMask) { dFilterTemp = dFilterMask; for (dFilterStep = 0; dFilterStep < (dFilterMask.length+1); dFilterStep++) { if (dFilterMask.charAt(dFilterStep)!='#') { dFilterTemp = replace(dFilterTemp,dFilterMask.charAt(dFilterStep),''); } } return dFilterTemp.length; } function dFilter (key, textbox, dFilterMask) { dFilterNum = dFilterStrip(textbox.value, dFilterMask); if (key==9) { return true; } else if (key==8&&dFilterNum.length!=0) { dFilterNum = dFilterNum.substring(0,dFilterNum.length-1); } else if ( ((key>47&&key<58)||(key>95&&key<106)) && dFilterNum.length95&&key<106) key = parseInt(key) - 48; dFilterNum=dFilterNum+String.fromCharCode(key); } var dFilterFinal=''; for (dFilterStep = 0; dFilterStep < dFilterMask.length; dFilterStep++) { if (dFilterMask.charAt(dFilterStep)=='#') { if (dFilterNum.length!=0) { dFilterFinal = dFilterFinal + dFilterNum.charAt(0); dFilterNum = dFilterNum.substring(1,dFilterNum.length); } else { dFilterFinal = dFilterFinal + ""; } } else if (dFilterMask.charAt(dFilterStep)!='#') { dFilterFinal = dFilterFinal + dFilterMask.charAt(dFilterStep); } } textbox.value = dFilterFinal; return false; } function replace(fullString,text,by) { // Replaces text with by in string var strLength = fullString.length, txtLength = text.length; if ((strLength == 0) || (txtLength == 0)) return fullString; var i = fullString.indexOf(text); if ((!i) && (text != fullString.substring(0,txtLength))) return fullString; if (i == -1) return fullString; var newstr = fullString.substring(0,i) + by; if (i+txtLength < strLength) newstr += replace(fullString.substring(i+txtLength,strLength),text,by); return newstr; } /****************************END OF INPUT MASKING FUNCTIONS*******************************/ /* * Agruments Type : id ( id of datefield), format ( dd/mm/yyyy or mm/yyyy or yyyy ) * Purpose : check for current or back dates * Author :none * Description : * Today or back dates are valid :returns true * future dates are invalid : returs false * * validateCommon ('deathDtTxt','deathDtTxtErr2',notFutureDate('deathDtTxt','dd/mm/yyyy'),ret)&& ret; */ function notFutureDate(id,format){ var input = document.getElementById(id).value; if(input == '' || input == null) return true; var date1 = new Date(); var n = 0; if ( format == 'dd/mm/yyyy') n = 7; else if ( format == 'mm/yyyy') n =4; else if (format == 'yyyy') n = 1; if( n == 7){ var day = parseInt(input.substr(0,2),10); date1.setDate(day); } if ( n >= 4){
var month = parseInt(input.substr(n-4,2),10) -1;
date1.setMonth(month);
}
if ( n > 0){
var year = parseInt(input.substr(n-1,4),10);
date1.setYear(year);
}


if(date1 <= new Date() ) return true; else return false; } /* Agruments Type : id ( id of datefield), startDate, EndDate * Purpose : check for date is between or eqaul of startDate and EndDate * Author :none * Description : * dateInRange('id1','01/01/2009','31/12/2009') * for client side validate call : validateCommon('id','errorId',dateInRange('id1','01/01/2009','31/12/2009') * ,true) */ function dateInRange(id,startDate,endDate){ var input = document.getElementById(id).value; if(input == '' || input == null) return true; var date1 = new Date(); var date2 = new Date(); var date3 = new Date(); len1 = startDate.length; len2 = endDate.length; len3 = input.length; if( (len1 != len2) || (len2 != len3)) return false; var n = 0; if ( len1 == 10 ) n = 7; else if ( len1 == 7) n =4; else if (len1 == 4) n = 1; if( n == 7){ date1.setDate(parseInt(input.substr(0,2),10)); date2.setDate(parseInt(startDate.substr(0,2),10)); date3.setDate(parseInt(endDate.substr(0,2),10)); } if ( n >= 4){
date1.setMonth(parseInt(input.substr(n-4,2),10)-1);
date2.setMonth(parseInt(startDate.substr(n-4,2),10)-1);
date3.setMonth(parseInt(endDate.substr(n-4,2),10)-1);
}
if ( n > 0){
date1.setYear(parseInt(input.substr(n-1 ,4),10));
date2.setYear(parseInt(startDate.substr(n-1,4),10));
date3.setYear(parseInt(endDate.substr(n-1,4),10));
}

if( date1 >= date2 && date1 <= date3 ) return true; else return false; } /* Agruments Type : id * Purpose : returns the value of html component * Author :none * Description : * eg. this.value = getValueFromId('policyNoTxt'); * */ function getValueFromId(id){ return document.getElementById(id).value; } /* Agruments Type : id,val * Purpose : set the value of html component * Author :none * Description : * eg. setValueInId('policyNoTxt','111111111'); * setValueInId('policyNoTxt',12232323); * setValueInId('policyNoTxt',new Date());* * */ function setValueInId(id,val){ document.getElementById(id).value = val; } /* Agruments Type : id,id * Purpose : copy value of html component * Author :none * Description : * eg. copyValfromIdtoId('scrId','DesId'); * */ function copyValfromIdtoId(idScr,idDes){ document.getElementById(idDes).value = document.getElementById(idScr).value; } /* Agruments Type : id,id * Purpose : makes the single digit to double * Author :none * Description : * eg. makeDoubleDigit(5), will return '05' * */ function makeDoubleDigit(IntVal){ if( IntVal < 10 ) IntVal = '0'+IntVal; return IntVal; } /* Agruments Type : Date value * Purpose : convert Date value to 'dd/mm/yyyy' or 'mm/yyyy' or 'yyyy' format * Author :none * Description : * eg. dateToValue(new Date()) * Output: '01/01/2009' ( will return todays date in dd/mm/yyyy format) * dateToValue(new Date(),'dd/mm/yyyy') * Output: '01/01/2009' ( will return todays date in dd/mm/yyyy format) * dateToValue(new Date(),'mm/yyyy') * Output: '01/2009' ( will return todays date in mm/yyyy format) * dateToValue(new Date(),'yyyy') * Output: '2009' ( will return todays date in yyyy format) * */ function dateToValue(dateVar,format){ var dd = dateVar.getDate(); var mm = dateVar.getMonth()+1; var yy = dateVar.getFullYear(); var retVal; if (typeof format == "undefined") format = "dd/mm/yyyy"; if(format == 'dd/mm/yyyy') retVal = makeDoubleDigit(dd)+'/'+makeDoubleDigit(mm)+'/'+yy; if(format == 'mm/yyyy') retVal = makeDoubleDigit(mm)+'/'+yy; if(format == 'yyyy') retVal = yy; return retVal; } /* Agruments Type : string in 'dd/mm/yyyy' or 'mm/yyyy' or 'yyyy' format * Purpose : convert value from 'dd/mm/yyyy' or 'mm/yyyy' or 'yyyy' format to date value * Author :none * Description : * eg. valueToDate('01/01/2009') * valueToDate('01/2009') * valueToDate('2009') * */ function valueToDate(value){ var len = value.length; dateVar = new Date(); if(len >= 10)
dateVar.setDate(value.substr(0,2));
if(len >= 7)
dateVar.setMonth(value.substr(len - 7,2)-1);
if(len >=4 )
dateVar.setFullYear(value.substr(len -4,4));

return dateVar;
}

/* Agruments Type : string in 'dd/mm/yyyy' or 'mm/yyyy' or 'yyyy' format
* or
* Date value
*
* Purpose : removes '/' or add '/' from date
* Author :none
* Description :
* eg. formatDate()
* Output: 01012000
* formatDate('01/02/2009')
* Output: 01022009
* formatDate('01/02/2009',false)
* Output: 01022009
* formatDate('01022009',true)
* Output: 01/02/2009
*
*/
function formatDate(dateVar,flag){
if (typeof dateVar == "undefined")
dateVar = dateToValue(new Date());
else
if (typeof dateVar == "object")
dateVar = dateToValue(dateVar);
if (typeof flag == "undefined")
flag = false;

if(flag)
return dateVar.substr(0,2)+'/'+dateVar.substr(2,2)+'/'+dateVar.substr(4,4);
else
return dateVar.substr(0,2)+dateVar.substr(3,2)+dateVar.substr(6,4);
}

/* Agruments Type : date, date, number, boolean
* Purpose : calculate the date difference
* Author :none
* Description :
* eg. dateDifference('01/01/2009')
* Output: diffence of '01/01/2009' and today in days
* dateDifference('02/01/2009','01/01/2009')
* Output: diffence of '01/01/2009' and '01/01/2009' in days
* : 1
* dateDifference('02/01/2009','01/01/2009',0)
* Output: difference in days
* dateDifference('01/05/2009','01/01/2009',1)
* Output: difference in months
* : 4
* dateDifference('01/01/2010','01/01/2015',2)
* Output: difference in years
* : 5
*
* flag : 0 for days, 1 for months, 2 for years
*
* dateDifference('01/01/2010','01/01/2015',2,true)
* Output: will round the difference*
*
*/
function dateDifference(dateVar1,dateVar2,flag,n){
date1 = valueToDate(dateVar1);
if (typeof dateVar2 == "undefined")
date2 = new Date();
else
date2 = valueToDate(dateVar2);
diff = date1 - date2;
if (typeof flag == "undefined")
flag = 1;
else {
if(flag == 0)
flag = 1;
else
if(flag == 1)
flag = 30;
else
if(flag == 2)
flag = 360;
}
if(typeof n == "undefined")
n = false;
else
n = true;
if(n)
return Math.round(diff/(86400000 * flag ));
else
return diff/(86400000 * flag );
}

/* Agruments Type : string in 'dd/mm/yyyy' or 'mm/yyyy' or 'yyyy' format
* or
* Date value , number
*
* Purpose : add the days to date
* Author :none
* Description :
* eg. addDays() or addDays(new Date()) or addDays(new Date(),1)
* Output: will return date string of next day
* addDays('01/02/2009')
* Output: 02/02/2009
* addDays('01/02/2009',5)
* Output: 06/02/2009*
*/
function addDays(dateVar,dd){
var date1;
if (typeof dateVar == "undefined")
date1 = new Date();
else
if (typeof dateVar == "string")
date1 = valueToDate(dateVar);
else
date1 = dateVar;
if (typeof dd == "undefined")
dd = 1;
date1.setTime( date1.getTime() + dd * 24 * 60 * 60 * 1000);
return dateToValue(date1);
}

/* Purpose : Limit the length of object like textarea
* Author :none
* How to use : onkeypress="return imposeMaxLength(this, 100);"
*/
function imposeMaxLength(Object, MaxLen)
{
return (Object.value.length <= MaxLen -1); } /* Purpose : Date should not be past * */ function notPastDate(id,format){ var input = document.getElementById(id).value; if(input == '' || input == null) return true; var date1 = new Date(); var n = 0; if ( format == 'dd/mm/yyyy') n = 7; else if ( format == 'mm/yyyy') n =4; else if (format == 'yyyy') n = 1; if( n == 7){ var day = parseInt(input.substr(0,2),10); date1.setDate(day); } if ( n >= 4){
var month = parseInt(input.substr(n-4,2),10) -1;
date1.setMonth(month);
}
if ( n > 0){
var year = parseInt(input.substr(n-1,4),10);
date1.setYear(year);
}


if(date1 >= new Date() )
return true;
else
return false;

}

function printWithoutView(printFlag)
{
if(printFlag =="print")
{
window.print();
}

return true;
}

//
function printWithView(printFlag)
{
if(printFlag =="print")
{

var url=contextPath + "/jsp/common/printFile.html";
window.open(url,'1111','width=750,height=750,status=no,\n\
resizable=no,scrollbars=yes,dependent=yes,left=120,top=80,location=no');
}

return true;
}

//function loadStyleClasses(){
// nodes = document.body.getElementsByTagName("input");
// for(var i=0; i m ){
if(val==0)
document.getElementById(id).value = "0."
else
document.getElementById(id).value = Math.floor(val/10) + '.' + ( val - (Math.floor(val/10)*10) ) ;

}
}

if(document.getElementById(id).value.toString().indexOf('.') != -1) {
parts = document.getElementById(id).value.split('.');

if ( parts[1].length > n )
flag1 = true;

if ( parseInt(parts[0]) > (Math.pow(10,m) - 1)) {
document.getElementById(id).value = Math.floor(parseInt(parts[0],10)/10) + parseFloat(parts[1],10) * 0.1 ;
}

}
if(flag1)
document.getElementById(id).value = val.toFixed(n) ;
}

/*
* eg. onkeyup="onlyDouble('check1',5,2)" onKeyPress= "onlyDoubleSupporter(event,'check1')" maxlength="8"
*/
function onlyDoubleSupporter(e,id,errorId){
var flag = false;

if (e.keyCode) {
code = e.keyCode; flag = true;
}
else if (e.which) code = e.which;

var char1 = String.fromCharCode(code);

if(code!=8 && code!=13 && !( code==118 && e.ctrlKey) && !( code==99 && e.ctrlKey))
if ( (( (code < 48) || (code > 57)) && char1!='.' ) || ( char1 == '.' && document.getElementById(id).value.toString().indexOf('.')!=-1) ){
e.cancelBubble = true;

if(!flag){
if (e.stopPropagation) e.stopPropagation();
e.preventDefault();
}
else
e.returnValue = false;
if(typeof errorId != "undefined" )
show(errorId);
return;
}

if(typeof errorId != "undefined" )
hide(errorId);
}

/* Agruments Type : fromId,toId,errorId,flag
* Purpose : From Date Should not be greater than To Date
* Author :none
* Description :
* eg. fromDateValidate('fromDateTxt','toDateTxt','fromDateTxtErr2',ret );
*/

function fromDateValidate(fromId,toId,errorId,flag){
return validateCommon(fromId,errorId ,valueToDate(getValueFromId(fromId)) <= valueToDate(getValueFromId(toId)),flag ); } /* Agruments Type : id,errId,val,ret * Purpose : if value of field is val then show error * Author :none * Description : * eg. ret = invalidValue('policyNoTxt','policyNoTxtErr3',0,ret) */ function invalidValue(id,errId,val,ret){ return validateCommon(id,errId,parseInt(document.getElementById(id).value,10) != val,ret); } //// Block Backspace / F5 / Control+N if (typeof window.event == 'undefined'){ document.onkeydown = function(e){ try{ var test_var=e.target.nodeName.toUpperCase(); if (e.target.type) var test_type=e.target.type.toUpperCase(); if (e.keyCode == 116 || (e.keyCode == 78 && e.ctrlKey) ){ e.preventDefault(); } else if ((test_var == 'INPUT' && test_type == 'TEXT') || test_var == 'TEXTAREA'){ return e.keyCode; }else if (e.keyCode == 8){ e.preventDefault(); } } catch(err){} } }else{ document.onkeydown = function(){ var test_var=event.srcElement.tagName.toUpperCase(); if (event.srcElement.type) var test_type=event.srcElement.type.toUpperCase(); if (event.keyCode == 116 || (event.keyCode == 78 && event.ctrlKey) ){ event.returnValue=false; event.keyCode = 0; } else if ((test_var == 'INPUT' && test_type == 'TEXT') || test_var == 'TEXTAREA'){ return; }else if (event.keyCode == 8){ event.returnValue=false; event.keyCode = 0; } } } /////// END OF Block Backspace / F5 / Control+N /* Agruments Type : NONE * Purpose : Handles multiple submit * Author :none * */ function beforeSubmit(){ //show('boxWait'); document.body.style.cursor = "wait"; nodes = document.getElementsByTagName('input'); for(i=0;i= len && cursorPos==len) && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0,len);
input.form[(getIndex(input)+1) % input.form.length].focus();
return true;
}else{
return false;
}

function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele){
//alert("arr[index]-"+arr[index]);
found = true;
}else{
//alert("arr[index]-"+arr[index]);
index++;
}
return found;
}

function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}

function getCursorPosition(input)
{
// HERE txt is the text field name
var obj=input.value;
var CurPos = 0;

//FOR IE
if (document.selection)
{
input.focus();
var Sel = document.selection.createRange();
Sel.moveStart ('character', -input.value.length);
CurPos = Sel.text.length;
}

// For Firefox
//else if (input.selectionStart input.selectionStart == '0')
else if (typeof input.selectionStart != 'undefined')
CurPos = input.selectionStart;
return CurPos;
}


function selectAutoJumb(input){
input.form[(getCurrentIndex(input)+1) % input.form.length].focus();

function getCurrentIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
}



// End of file
// Revisions Number - Author
// 1.5 -none