﻿// JScript File
// <FileHeader>
// <FileName>Validations.js</FileName>
// <Description>
// It will hold data related to field validation
// </Description>
// <Author>Shrirang Desai</Author>
// <DateCreated date="20/06/2007"/>
// <RevisionHistory>
// <Revision date="" author="">
// Please add the revision history here.
// </Revision>
// </RevisionHistory>
// </FileHeader>


var form_dirty=false; 
var warn_onunload=true;

//<!--
// Ultimate client-side JavaScript client sniff. Version 3.03
// (C) Netscape Communications 1999-2001.  Permission granted to reuse and distribute.
// Revised 17 May 99 to add is_nav5up and is_ie5up (see below).
// Revised 20 Dec 00 to add is_gecko and change is_nav5up to is_nav6up
//                      also added support for IE5.5 Opera4&5 HotJava3 AOLTV
// Revised 22 Feb 01 to correct Javascript Detection for IE 5.x, Opera 4, 
//                      correct Opera 5 detection
//                      add support for winME and win2k
//                      synch with browser-type-oo.js
// Revised 26 Mar 01 to correct Opera detection
// Revised 02 Oct 01 to add IE6 detection

// Everything you always wanted to know about your JavaScript client
// but were afraid to ask. Creates "is_" variables indicating:
// (1) browser vendor:
//     is_nav, is_ie, is_opera, is_hotjava, is_webtv, is_TVNavigator, is_AOLTV
// (2) browser version number:
//     is_major (integer indicating major version number: 2, 3, 4 ...)
//     is_minor (float   indicating full  version number: 2.02, 3.01, 4.04 ...)
// (3) browser vendor AND major version number
//     is_nav2, is_nav3, is_nav4, is_nav4up, is_nav6, is_nav6up, is_gecko, is_ie3,
//     is_ie4, is_ie4up, is_ie5, is_ie5up, is_ie5_5, is_ie5_5up, is_ie6, is_ie6up, is_hotjava3, is_hotjava3up,
//     is_opera2, is_opera3, is_opera4, is_opera5, is_opera5up
// (4) JavaScript version number:
//     is_js (float indicating full JavaScript version number: 1, 1.1, 1.2 ...)
// (5) OS platform and version:
//     is_win, is_win16, is_win32, is_win31, is_win95, is_winnt, is_win98, is_winme, is_win2k
//     is_os2
//     is_mac, is_mac68k, is_macppc
//     is_unix
//     is_sun, is_sun4, is_sun5, is_suni86
//     is_irix, is_irix5, is_irix6
//     is_hpux, is_hpux9, is_hpux10
//     is_aix, is_aix1, is_aix2, is_aix3, is_aix4
//     is_linux, is_sco, is_unixware, is_mpras, is_reliant
//     is_dec, is_sinix, is_freebsd, is_bsd
//     is_vms
//
// See http://www.it97.de/JavaScript/JS_tutorial/bstat/navobj.html and
// http://www.it97.de/JavaScript/JS_tutorial/bstat/Browseraol.html
// for detailed lists of userAgent strings.
//
// Note: you don't want your Nav4 or IE4 code to "turn off" or
// stop working when new versions of browsers are released, so
// in conditional code forks, use is_ie5up ("IE 5.0 or greater") 
// is_opera5up ("Opera 5.0 or greater") instead of is_ie5 or is_opera5
// to check version in code which you want to work on future
// versions.
function Is()
{

    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    this.is_major = parseInt(navigator.appVersion);
    this.is_minor = parseFloat(navigator.appVersion);

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
    // If you want to allow spoofing, take out the tests for opera and webtv.
    this.is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    this.is_nav2 = (this.is_nav && (this.is_major == 2));
    this.is_nav3 = (this.is_nav && (this.is_major == 3));
    this.is_nav4 = (this.is_nav && (this.is_major == 4));
    this.is_nav4up = (this.is_nav && (this.is_major >= 4));
    this.is_navonly = (this.is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    this.is_nav6 = (this.is_nav && (this.is_major == 5));
    this.is_nav6up = (this.is_nav && (this.is_major >= 5));
    this.is_gecko = (agt.indexOf('gecko') != -1);


    this.is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    this.is_ie3    = (this.is_ie && (this.is_major < 4));
    this.is_ie4    = (this.is_ie && (this.is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    this.is_ie4up  = (this.is_ie && (this.is_major >= 4));
    this.is_ie5    = (this.is_ie && (this.is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    this.is_ie5_5  = (this.is_ie && (this.is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    this.is_ie5up  = (this.is_ie && !this.is_ie3 && !this.is_ie4);
    this.is_ie5_5up =(this.is_ie && !this.is_ie3 && !this.is_ie4 && !this.is_ie5);
    this.is_ie6    = (this.is_ie && (this.is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    this.is_ie6up  = (this.is_ie && !this.is_ie3 && !this.is_ie4 && !this.is_ie5 && !this.is_ie5_5);

    // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
    // or if this is the first browser window opened.  Thus the
    // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
    this.is_aol   = (agt.indexOf("aol") != -1);
    this.is_aol3  = (this.is_aol && this.is_ie3);
    this.is_aol4  = (this.is_aol && this.is_ie4);
    this.is_aol5  = (agt.indexOf("aol 5") != -1);
    this.is_aol6  = (agt.indexOf("aol 6") != -1);

    this.is_opera = (agt.indexOf("opera") != -1);
    this.is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    this.is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    this.is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    this.is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    this.is_opera5up = (this.is_opera && !this.is_opera2 && !this.is_opera3 && !is_opera4);

    this.is_webtv = (agt.indexOf("webtv") != -1); 

    this.is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
    this.is_AOLTV = this.is_TVNavigator;

    this.is_hotjava = (agt.indexOf("hotjava") != -1);
    this.is_hotjava3 = (this.is_hotjava && (this.is_major == 3));
    this.is_hotjava3up = (this.is_hotjava && (this.is_major >= 3));

    // *** JAVASCRIPT VERSION CHECK ***
    this.is_js;
    if (this.is_nav2 || this.is_ie3) this.is_js = 1.0;
    else if (this.is_nav3) this.is_js = 1.1;
    else if (this.is_opera5up) this.is_js = 1.3;
    else if (this.is_opera) this.is_js = 1.1;
    else if ((this.is_nav4 && (this.is_minor <= 4.05)) || this.is_ie4) this.is_js = 1.2;
    else if ((this.is_nav4 && (this.is_minor > 4.05)) || this.is_ie5) this.is_js = 1.3;
    else if (this.is_hotjava3up) this.is_js = 1.4;
    else if (this.is_nav6 || this.is_gecko) this.is_js = 1.5;
    // NOTE: In the future, update this code when newer versions of JS
    // are released. For now, we try to provide some upward compatibility
    // so that future versions of Nav and IE will show they are at
    // *least* JS 1.x capable. Always check for JS version compatibility
    // with > or >=.
    else if (this.is_nav6up) this.is_js = 1.5;
    // NOTE: ie5up on mac is 1.4
    else if (this.is_ie5up) this.is_js = 1.3

    // HACK: no idea for other browsers; always check for JS version with > or >=
    else this.is_js = 0.0;

    // *** PLATFORM ***
    this.is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
    //        Win32, so you can't distinguish between Win95 and WinNT.
    this.is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

    // is this a 16 bit compiled version?
    this.is_win16 = ((agt.indexOf("win16")!=-1) || 
               (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) || 
               (agt.indexOf("windows 16-bit")!=-1) );  

    this.is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
                    (agt.indexOf("windows 16-bit")!=-1));

    this.is_winme = ((agt.indexOf("win 9x 4.90")!=-1));
    this.is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));

    // NOTE: Reliable detection of Win98 may not be possible. It appears that:
    //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
    //       - On Mercury client, the 32-bit version will return "Win98", but
    //         the 16-bit version running on Win98 will still return "Win95".
    this.is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
    this.is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
    this.is_win32 = (this.is_win95 || this.is_winnt || this.is_win98 || 
                    ((this.is_major >= 4) && (navigator.platform == "Win32")) ||
                    (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

    this.is_os2   = ((agt.indexOf("os/2")!=-1) || 
                    (navigator.appVersion.indexOf("OS/2")!=-1) ||   
                    (agt.indexOf("ibm-webexplorer")!=-1));

    this.is_mac    = (agt.indexOf("mac")!=-1);
    // hack ie5 js version for mac
    if (this.is_mac && this.is_ie5up) this.is_js = 1.4;
    this.is_mac68k = (this.is_mac && ((agt.indexOf("68k")!=-1) || 
                               (agt.indexOf("68000")!=-1)));
    this.is_macppc = (this.is_mac && ((agt.indexOf("ppc")!=-1) || 
                                (agt.indexOf("powerpc")!=-1)));

    this.is_sun   = (agt.indexOf("sunos")!=-1);
    this.is_sun4  = (agt.indexOf("sunos 4")!=-1);
    this.is_sun5  = (agt.indexOf("sunos 5")!=-1);
    this.is_suni86= (this.is_sun && (agt.indexOf("i86")!=-1));
    this.is_irix  = (agt.indexOf("irix") !=-1);    // SGI
    this.is_irix5 = (agt.indexOf("irix 5") !=-1);
    this.is_irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1));
    this.is_hpux  = (agt.indexOf("hp-ux")!=-1);
    this.is_hpux9 = (this.is_hpux && (agt.indexOf("09.")!=-1));
    this.is_hpux10= (this.is_hpux && (agt.indexOf("10.")!=-1));
    this.is_aix   = (agt.indexOf("aix") !=-1);      // IBM
    this.is_aix1  = (agt.indexOf("aix 1") !=-1);    
    this.is_aix2  = (agt.indexOf("aix 2") !=-1);    
    this.is_aix3  = (agt.indexOf("aix 3") !=-1);    
    this.is_aix4  = (agt.indexOf("aix 4") !=-1);    
    this.is_linux = (agt.indexOf("inux")!=-1);
    this.is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
    this.is_unixware = (agt.indexOf("unix_system_v")!=-1); 
    this.is_mpras    = (agt.indexOf("ncr")!=-1); 
    this.is_reliant  = (agt.indexOf("reliantunix")!=-1);
    this.is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) || 
           (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) || 
           (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1)); 
    this.is_sinix = (agt.indexOf("sinix")!=-1);
    this.is_freebsd = (agt.indexOf("freebsd")!=-1);
    this.is_bsd = (agt.indexOf("bsd")!=-1);
    this.is_unix  = ((agt.indexOf("x11")!=-1) || this.is_sun || this.is_irix || this.is_hpux || 
                 this.is_sco ||this.is_unixware || this.is_mpras || this.is_reliant || 
                 this.is_dec || this.is_sinix || this.is_aix || this.is_linux || this.is_bsd || this.is_freebsd);

    this.is_vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));

//--> end hide JavaScript

}


function closeIt() 
{ 
    if((warn_onunload == true) && (form_dirty == true) ) 
    { 
        event.returnValue = 'Your changes will be lost. Do you want to continue?' 
    } 
    else 
    {
        form_dirty = false;
    }
}

/*** Will be used to throw server side exception on client side ***/
function serversideException(msg,severityType,exceptionType,source)
{
    var exceptionMsg = "";
    if (msg != "" && msg != null)
    {
        if (source != "" && source != null)
        {
            exceptionMsg = source + ":" 
        }
        
        if (exceptionType != "" && exceptionType != null)
        {
            exceptionMsg += "(Type:"+exceptionType+")\n"; 
        }
        
        //exceptionMsg += "Description: " + msg;
        exceptionMsg += " " + msg;
        
        errorMessageBox(exceptionMsg,severityType);
    }
}

/*** Will show message with critical,Informative and None indicator ***/
function errorMessageBox(msg, type)
{
    try {
      if ( type == "Information" ) {
        VBinfoMsg(msg)
      }
      else if ( ( type == "Error" ) || ( type == "Warning" )  || ( type == "Fatal" ))  {
         VBcritMsg(msg)
      }
      else {
         alert(msg)
      }
    } catch (e) {
        alert(msg)
    }
}

/*** Will validate text field ***/
function validateText(objText)		
{	
	
	var txtValue = objText.value;
	if (txtValue.length <= 0) 
	{
		objText.value = '';
		alert('Field cannot be kept empty');
		return false;
	}
	
	objText.value = (objText.value).replace(/'/,"");
	
	var invalidChars = new Array ('<','>');
	var index = 0;
	for (index=0;index < invalidChars.length; index ++)
	{
		if (txtValue.indexOf(invalidChars[index])>= 0)
		{ 
			alert('Entered text contains invalid characters');
			objText.value = '' ;
			return false;
		}	
	}
	
	return true;
}


/*** Will validate form text field ***/
function validatedForm()		
{	
    if (document.forms.length > 0) 
    {
        var field = document.forms[0];
        for (i = 0; i < field.length; i++) 
        {
            if ((field.elements[i].type == "text")) 
            {
                if ( field.elements[i].validate == "1" )
                {
                    if ( validateText(document.forms[0].elements[i]) == false)
                    {
                        document.forms[0].elements[i].focus();
                        return false;
                    }
                }
            }
      }
   }
   return true;
}

/*** Will focus of the form user name field ***/
function placeFocus() 
{
    if (document.forms.length > 0) 
    {
        var field = document.forms[0];
        for (i = 0; i < field.length; i++) 
        {
            if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) 
            {
                document.forms[0].elements[i].focus();
                break;
            }
      }
   }
}

/*** Delete confirmation message box ***/    
function ConfirmDelete(strMsg) 
{ 
    var msg = "Are you sure you want to delete this " + strMsg +" record?";
    try 
    {
        return VBconfirmMsg(msg);
    } 
    catch (e) 
    {
        return confirm(msg);
    }
}

/*** Save confirmation message box ***/    
function ConfirmMsg() 
{ 
   var msg = "Your changes will be lost. Do you want to continue?";
    try 
    {
        return VBconfirmMsg(msg);
    } 
    catch (e) 
    {
        return confirm(msg);
    }
}

/*** Delete confirmation message box ***/    
function ConfirmBox(strMsg) 
{ 
    try 
    {
        return VBconfirmMsg(strMsg);
    } 
    catch (e) 
    {
        return confirm(strMsg);
    }
}


/*** To check empty string ***/    
function IsEmpty(aTextField) 
{
    aTextField.value = trim(aTextField.value);
    
    if ((aTextField.value.length==0) || (aTextField.value==null)) 
    {
        return true;
    }
    else 
    { 
        return false; 
    }
}	

/****** To Check Max Length of a Multiline Text Box **************/
/********* Call onkeypress and onpaster*********************/
function textboxMultilineMaxNumber(txt,maxLen)
{
    try
    {
        if(txt.value.length > (maxLen-1)) 
        {
            return false
        }
    }
    catch(e)
    {}
}        

/****** To Check Max Length of a Multiline Text Box **************/
/********* Call onkeypress and onpaster*********************/
function restrictTextAreaMaxLen(txt,maxLen)
{
    try
    {
        if(txt.value.length > (maxLen-1)) 
        {
            txt.value = txt.value.substring(0,maxLen-1)
        }
    }
    catch(e)
    {}
} 

/*** To trim empty places ***/    
function trim(str)
{
    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}



/*** Will validate text field ***/
function validCharacters(objText)		
{	
    var txtValue = objText.value;
	if (txtValue.length <= 0) 
	{
		objText.value = '';
		return true;
	}
	
	var invalidChars = new Array (/</g,/>/g);
	var index = 0;
	for (index=0;index < invalidChars.length; index ++)
	{
		//if (txtValue.indexOf(invalidChars[index])>= 0)
		//{ 
			objText.value = (objText.value).replace(invalidChars[index],"");
		//}	
	}
	
	return true;
}


/**********************************************************************/
/*Function name :isDigit(theDigit) */ 
/*Usage of this function :test for an digit */ 
/*Input parameter required:thedata=string for test whether is digit */ 
/*Return value :if is digit,return true */ 
/* else return false */ 
/**********************************************************************/
function isDigit(theDigit) 
{ 
    var newDigit = 0;
	
    //theDigit: number or number with multiplier or comma separated number
    //Ex: 100 or 2.3K or 1,100
    var commaExist = theDigit.indexOf(','); 
    if (commaExist > 0)
    {
	    //Number maybe of type 200,000 or 2,001.23
	    var numVal = ExtractNumber(theDigit);
	    newDigit = numVal; 
    }
    if (commaExist ==  -1)
    {	
	    var multiplier = theDigit.charAt(theDigit.length - 1);
	    if (isAlpha(multiplier))
	    {
		    switch (multiplier)
		    {
			    case 't':
			    case 'T':
			    case 'k':
			    case 'K':
				    newDigit = theDigit.substring(0,theDigit.length-1) * 1000;
				    break;
					
			    case 'h':								
			    case 'H':
				    newDigit = theDigit.substring(0,theDigit.length-1) * 100;
				    break;
					
			    case 'm':
			    case 'M':
				    newDigit = theDigit.substring(0,theDigit.length-1) * 1000000;
				    break;
					
			    case 'b':
			    case 'B':
				    newDigit = theDigit.substring(0,theDigit.length-1) * 1000000000;
				    break;
				
			    default:
				    newDigit = 0;
				    break;
		    }
	    }
	    else {
		    //number without multiplier - with or without decimal digits
		    newDigit = theDigit; //no multiplier present
	    }
    }
	
    if (isNaN(newDigit))
	    return -1;
    else
    {
	    newDigit = newDigit + '';
	    var decimalPos = newDigit.indexOf('.'); 
	    Digit = new Number(newDigit);
	    if (decimalPos > 0)
	    { 
		    var decimalPlaces = 0;
		    var result = round(parseFloat(Digit), decimalPlaces);
		    return result;
	    }
	    else
		    return parseInt(Digit);				
    }
}

/*
* FormatNumber - Returns the number formatted with commas
*/
function FormatNumber(number)
{
    var nStr = number +  ' '; //number converted to a string
    var decimalPos = nStr.indexOf('.'); 
	
    if (decimalPos == -1)//no decimal digits present
    {
	    decimalPos = nStr.length - 1;
    }
    while (decimalPos > 0)
    {
	    decimalPos -= 3;
	    if (decimalPos <= 0) break;
	    nStr = nStr.substring(0,decimalPos) + ',' + nStr.substring(decimalPos, nStr.length);
    }
	
    nStr = (number < 0) ? '-' + nStr : nStr; //put '-' sign as prefix for negative numbers
    var numVal = ExtractNumber(nStr);

    // Trim the result
    var ch = nStr.substring(nStr.length-1, nStr.length);
    while (ch == " ") { // Check for spaces at the end of the string
	    nStr = nStr.substring(0, nStr.length-1);
	    ch = nStr.substring(nStr.length-1, nStr.length);
    }
	
    return (nStr);
}

/*
 * round - Returns the decimal number rounded to X decimal places 
 */
function round(number, X) 
{
    //X = (!X ? 2 : X); //default the number of decimal places to 2
    return Math.round(number*Math.pow(10,X)) / Math.pow(10,X);
}

/*
* ExtractNumber - Returns the actual number from a number format with commas
*/
function ExtractNumber(strNumber) 
{
    var decimalPos = strNumber.indexOf('.'); 
    if (decimalPos == -1)//no decimal digits present
	    retNum = parseInt((strNumber.split(",")).join('')); //for integers
    else
	    retNum = parseFloat((strNumber.split(",")).join('')); // for integers and decimals
    return retNum;
}

/*
 * isAlpha - Returns true for a vaild alphabet and false if otherwise
 * Input - ch : character
 */
function isAlpha(ch) 
{ 
    if(ch >= "a" && ch <= "z") return true; 
    if(ch >= "A" && ch <= "Z") return true;
    return false 
} 


function checkNumber(v) 
{ 
    var s = v.value;
	
    if (s == 0 || s.length <= 0) {
	    v.value = '';
	    return;
    }
	
    var newValue = isDigit(s);
    var strValue = FormatNumber(newValue);
    if (newValue > 0)
	    v.value = strValue; //newValue ;
    else
    {
	    v.value = '';  //do not move behide alert.
	    return false; 
    }
} 


function takeYear(theDate)
{
    x = theDate.getYear();
    var y = x % 100;
    y += (y < 38) ? 2000 : 1900;
    return y;
}

function leadingZero(nr)
{
    if (nr < 10) nr = "0" + nr;
    return nr;
}
function removeLeadingZero(nr)
{
    if (nr < 10) nr = nr.charAt(1);
    return nr;
}

    
    function checkDecimals(fieldName) 
    {
        var fieldValue;
        decallowed = 2;  // how many decimals are allowed?
        
        fieldValue = fieldName.value;
        
        if (isNaN(fieldValue) || fieldValue == "") 
        {
            alert("That does not appear to be a valid number.");
            fieldName.value='';
            fieldName.focus();
            return false;
        }
        else 
        {
            if (fieldValue.indexOf('.') == -1) 
            {
                if ( fieldValue.length > 2)
                {
                    alert ("Please enter value in 99.99 format only.");
                    return false;
                }
                else
                {
                    fieldValue += ".";
                }
            }
                    
            dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);

            if (dectext.length > decallowed)
            {
                alert ("Please enter a number with up to " + decallowed + " decimal places.");
                fieldName.value='';
                fieldName.focus();
                return false;
            }
            else 
            {
            }
        }
    }
    
/*** Session Expired Alert Message ***/    
function SessionExpired() 
{ 
    alert("Session has been expired, Please login again."); 
}    


 function getElementLeft(p_elm) 
 {
    var x = 0;
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    while (elm != null) {
      x+= elm.offsetLeft;
      elm = elm.offsetParent;
    }
    return parseInt(x);
}
function getElementHeight(p_elm)
{
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    return parseInt(elm.offsetHeight);
}
function getElementTop(p_elm) 
{
    var y = 0;
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    while (elm != null) {
      y+= elm.offsetTop;
      elm = elm.offsetParent;
    }
    return parseInt(y);
}
 
function getElementBottom(p_elm)
{
    return getElementTop(p_elm) + getElementHeight(p_elm);
}
//--------------------------------------------------------------------------------------------	
//-------------------------------------------------------------------
// disallowBlank(input_object[,message[,true]])
//   Checks a form field for a blank value. Optionally alerts if 
//   blank and focuses
//-------------------------------------------------------------------
function disallowBlank(obj){
	if (obj == null) {return false;} 
	var msg=(arguments.length>1)?arguments[1]:"";
	msg=replaceSubstring(msg,"&#39;","'");
	var dofocus=(arguments.length>2)?arguments[2]:true;
	if (isBlank(getInputValue(obj))){
		if(!isBlank(msg)){alert(msg);}
		if(dofocus){
			setFocus(obj);
			}
		return true;
		}
	return false;
	}

//-------------------------------------------------------------------
// disallowSpecialCharacters(input_object,[,message[,true,[special charcter string]]])
//   Checks whether the form field contains any of the special chracters
//	 return true if so else false 
//	 Limitation : Charater - is not allowed in special character string
//-------------------------------------------------------------------
function disallowSpecialCharacters(obj)
{
	if (obj == null) {return false;} 
	if (isBlank(getInputValue(obj))) {return false;}
	var msg=(arguments.length>1)?arguments[1]:"";
	msg=replaceSubstring(msg,"&#39;","'");
	var dofocus=(arguments.length>2)?arguments[2]:true;
	var spChars=(arguments.length>3)?arguments[3]:"[/*?+\"><|,\\\\]";
	if (hasSpecialCharacters(getInputValue(obj),spChars)) {
			if(!isBlank(msg)){alert(msg);}
		if(dofocus){
			setFocus(obj);
			}
		return true;
	}	
	return false;
}
//-------------------------------------------------------------------
// hasSpecialCharacters(string,special charcter string)
//   Checks whether the string contains any of the special chracters
//	 return true if so else false 
//-------------------------------------------------------------------
function hasSpecialCharacters(strValue,spChars)
{
		var r1 = new RegExp(spChars);
				
		return (r1.test(strValue));
}

//-------------------------------------------------------------------
// getInputValue(input_object)
//   Get the value of any form input field
//   Multiple-select fields are returned as comma-separated values
//   (Doesn't support input types: button,file,reset,submit)
//-------------------------------------------------------------------
function getInputValue(obj) {
	var use_default=(arguments.length>1)?arguments[1]:false;
	if (isArray(obj) && (typeof(obj.type)=="undefined")) {
		var values=new Array();
		for(var i=0;i<obj.length;i++){
			var v=getSingleInputValue(obj[i],use_default);
			if(v!=null){values[values.length]=v;}
			}
		return commifyArray(values);
		}
	return TrimAll(getSingleInputValue(obj,use_default));
	}

//-------------------------------------------------------------------
// isBlank(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
	}

//-------------------------------------------------------------------
// replaceSubstring(value)
//   Returns string with replaced sub string by the replacement
//-------------------------------------------------------------------
function replaceSubstring(inputString, fromString, toString) {
	// Goes through the inputString and replaces every occurrence of fromString with toString
	var temp = inputString;
	if (fromString == "") {
		return inputString;
	}
	if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
		while (temp.indexOf(fromString) != -1) {
			var toTheLeft = temp.substring(0, temp.indexOf(fromString));
			var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
			temp = toTheLeft + toString + toTheRight;
		}
	} else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
		var midStrings = new Array("~", "`", "_", "^", "#");
		var midStringLen = 1;
		var midString = "";
		// Find a string that doesn't exist in the inputString to be used
		// as an "inbetween" string
		while (midString == "") {
			for (var i=0; i < midStrings.length; i++) {
				var tempMidString = "";
				for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
				if (fromString.indexOf(tempMidString) == -1) {
				midString = tempMidString;
				i = midStrings.length + 1;
				}
			}
		} // Keep on going until we build an "inbetween" string that doesn't exist
		// Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
		while (temp.indexOf(fromString) != -1) {
			var toTheLeft = temp.substring(0, temp.indexOf(fromString));
			var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
			temp = toTheLeft + midString + toTheRight;
		}
		// Next, replace the "inbetween" string with the "toString"
		while (temp.indexOf(midString) != -1) {
			var toTheLeft = temp.substring(0, temp.indexOf(midString));
			var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
			temp = toTheLeft + toString + toTheRight;
		}
	} // Ends the check to see if the string being replaced is part of the replacement string or not
	return temp; // Send the updated string back to the user
	} // Ends the "replaceSubstring" function
	

//-------------------------------------------------------------------
// setFocus(obj[,showSelected])
//   set focus to the control
//-------------------------------------------------------------------
function setFocus(obj){
	var showSelected=(arguments.length>1)?arguments[1]:false;	
	if (obj == null) {return;} 
	if (obj.disabled == true) {return;}
	if (isArray(obj) && (typeof(obj.type)=="undefined")) {obj=obj[0];}
	if (obj.type=="hidden") {return;}
	if (showSelected ==true) {
	if(obj.type=="text"||obj.type=="textarea"||obj.type=="password") { obj.select(); }
	}
	obj.focus();
}
//-------------------------------------------------------------------
// isArray(obj)
// Returns true if the object is an array, else false
//-------------------------------------------------------------------
function isArray(obj){return(typeof(obj.length)=="undefined")?false:true;}
//-------------------------------------------------------------------
// getSingleInputValue(input_object,use_default)
//   Utility function used by others
//-------------------------------------------------------------------
function getSingleInputValue(obj,use_default) {
	switch(obj.type){
		case 'radio': case 'checkbox': return(((use_default)?obj.defaultChecked:obj.checked)?obj.value:null);
		case 'text': case 'file': case 'hidden': case 'textarea': case 'Textbox': return(use_default)?obj.defaultValue:obj.value;
		case 'password': return((use_default)?null:obj.value);
		case 'select-one':
			if (obj.options==null) { return null; }
			if(use_default){
				var o=obj.options;
				for(var i=0;i<o.length;i++){if(o[i].defaultSelected){return o[i].value;}}
				return o[0].value;
				}
			if (obj.selectedIndex<0){return null;}
			return(obj.options.length>0)?obj.options[obj.selectedIndex].value:null;
		case 'select-multiple': 
			if (obj.options==null) { return null; }
			var values=new Array();
			for(var i=0;i<obj.options.length;i++) {
				if((use_default&&obj.options[i].defaultSelected)||(!use_default&&obj.options[i].selected)) {
					values[values.length]=obj.options[i].value;
					}
				}
			return (values.length==0)?null:commifyArray(values);
		}
	alert("FATAL ERROR: Field type "+obj.type+" is not supported for this function");
	return null;
	}
//-------------------------------------------------------------------
// Trim functions
//   Returns string with whitespace trimmed
//-------------------------------------------------------------------
function LTrim(str){
	if (str==null){return null;}
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
	}
function RTrim(str){
	if (str==null){return null;}
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
	}
function Trim(str){return LTrim(RTrim(str));}
function LTrimAll(str) {
	if (str==null){return str;}
	for (var i=0; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i++);
	return str.substring(i,str.length);
	}
function RTrimAll(str) {
	if (str==null){return str;}
	for (var i=str.length-1; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i--);
	return str.substring(0,i+1);
	}
function TrimAll(str) {
	return LTrimAll(RTrimAll(str));
	}

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
