
function fnValidEntry(e,validationType)
{
var keynum;
var keychar;
var numcheck;
var bk;

var k = KeyCode;
keynum =k.translate_event(e).code;
/*if(window.event) // IE
	{
	keynum = e.keyCode;
	}
else if(e.which) // Netscape/Firefox/Opera
	{
	keynum = e.which;
	}*/
 keychar = String.fromCharCode(keynum);
 numcheck = /\d/;
 if(validationType=="Int")
 {

  if(!window.event) // IE
	{
		 if(keynum==46 || keynum==37 || keynum==38|| keynum==39|| keynum==40)
		  {
			return true;
		  }
	}

  if(keychar!='\b' && e.keyCode!=9)
  {
    return numcheck.test(keychar);
  }
  else
     return true
 }

 if(validationType=="Alpha")
   return !numcheck.test(keychar);


}

function fnValid(obj,validationType)
{
  try{
    var code=window.event ? obj.keyCode : obj.which

    if(code!=13)
    {
        if(validationType=="All")
          valChars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890' ,"

        if(validationType=="Int")
          valChars="1234567890"

        if(validationType=="Alpha")
          valChars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

        var isValid=false
        for(i=0;i<valChars.length;i++) {
          if(valChars.charAt(i) == String.fromCharCode(code))
          {
            obj.returnValue = true
            isValid=true
            break
          }
        }
        if(!isValid)
        obj.returnValue = false
    }
    else
    {
      obj.returnValue = false
    }
  }catch(e) {}
}




function fnShowWaitMessage(id,ShowHide)
{ //alert(ShowHide);
  //alert(id);
  if(global.getElementById(id))
  {
    fnDisableEnable(ShowHide)
    global.getElementById(id).style.display=(ShowHide ? "":"none")
  }
}

function fnDisableEnable(DisableEnable)
{ 

  if(DisableEnable)
  { //alert(DisableEnable)
    var dv  = document.createElement('div');
    dv.id="dvDisable"
    dv.className="disable"
    global.getElementsByTagName('body')[0].appendChild(dv)
     global.getElementsByTagName('body')[0].style.overflow="hidden"
    self.scroll(0,0)
  }
  else
  {
    global.getElementsByTagName('body')[0].style.overflow="auto"
    if(global.getElementById('dvDisable'))
    global.getElementsByTagName('body')[0].removeChild(global.getElementById('dvDisable'))
  }

}





function fnValidSearchChars(val)
{
  try{
      valChars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890?()* \',_-#@|:;/"
      var isValid=false
      var i =0
      var j=0
      var validstr=""
      for(i=0;i<val.length;i++) {
         for(j=0;j<valChars.length;j++) {
            if(val.charAt(i) == valChars.charAt(j))
            {
              validstr+=val.charAt(i)
              break
            }
         }
      }
      return validstr
  }catch(e) {
    return val
  }
}

function fnFormatCurrency(num)
{
  num = num.toString().replace(/\$|\,/g,'');
  if(isNaN(num))
  num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10)
  cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  num = num.substring(0,num.length-(4*i+3))+','+
  num.substring(num.length-(4*i+3));
  return (((sign)?'':'-') +  num + '.' + cents);
}

function Trim(STRING){
  STRING = LTrim(STRING);
  return RTrim(STRING);
}

function RTrim(STRING){
  while(STRING.charAt((STRING.length -1))==" "){
      STRING = STRING.substring(0,STRING.length-1);
  }
  return STRING;
}


function LTrim(STRING){
  while(STRING.charAt(0)==" "){
    STRING = STRING.replace(STRING.charAt(0),"");
  }
  return STRING;
}


function checkEmail(eMail) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(eMail)){
return (true)
}
return (false)
}




function fnValidateUserEntry(obj,arrField,arrEmail,ArrMatchFields)
{
  var isError=false
  var ID= (obj==null ? "" : obj.id)
  var i=0

    if(ID!="")
    {
        if(global.getElementById(ID).value.length==0)
        {
          if(global.getElementById('err'+ID))
            global.getElementById('err'+ID).style.display=""
            isError=true
        }
        else
        {
            if(global.getElementById('err'+ID))
              global.getElementById('err'+ID).style.display="none"

        }
    }
    else
    {
      for(i=0;i<arrField.length;i++)
      {
       ID=arrField[i]

         if(global.getElementById(ID).type=="text" || global.getElementById(ID).type=="textarea" || global.getElementById(ID).type=="password")
         {
           if(Trim(global.getElementById(ID).value).length==0)
           {
              if(global.getElementById('err'+ID))
                global.getElementById('err'+ID).style.display=""
              isError=true
           }
           else
           {
             if(global.getElementById('err'+ID))
               global.getElementById('err'+ID).style.display="none"
           }
         }

         if(global.getElementById(ID).type=="select-one")
         {
           if(Trim(global.getElementById(ID).options[global.getElementById(ID).selectedIndex].value)=="--")
           {
              if(global.getElementById('err'+ID))
              global.getElementById('err'+ID).style.display=""
              isError=true
           }
           else
           {
             if(global.getElementById('err'+ID))
               global.getElementById('err'+ID).style.display="none"
           }
         }

      }
    }

    if(!isError)
    {
//    arrEmail,arrOnlyInt,arrOnlyAlpha
      if(arrEmail!=null)
      {
        for(i=0;i<arrEmail.length;i++)
        {
          ID=arrEmail[i]
          if(checkEmail(Trim(global.getElementById(ID).value)))
          {
            if(global.getElementById('errValid'+ID))
            global.getElementById('errValid'+ID).style.display="none"
          }
          else
          {
           if(global.getElementById('errValid'+ID))
            global.getElementById('errValid'+ID).style.display=""
             isError=true
          }
        }
      }

      if((ArrMatchFields!=null) && !isError)
      {
        for(i=0;i<ArrMatchFields.length;i++)
        {
          ID=ArrMatchFields[i]
          if(Trim(global.getElementById(ID.split("_")[0]).value)==Trim(global.getElementById(ID.split("_")[1]).value))
          {
            if(global.getElementById('errMatch'+ID))
            global.getElementById('errMatch'+ID).style.display="none"
          }
          else
          {
            if(global.getElementById('errMatch'+ID))
            global.getElementById('errMatch'+ID).style.display=""
             isError=true
          }
        }
      }
    }

   return isError
}


function fnCompareDate(compDD1,compMM1,compYY1,compDD2,compMM2,compYY2)
{
  var JD1=0.000
  var JD2=0.000

  JD1 = (1461 * (compYY1 / 4)) + (153 * (compMM1 / 5)) + compDD1
  JD2 = (1461 * (compYY2 / 4)) + (153 * (compMM2 / 5)) + compDD2

   if(JD1 < JD2)
    return -1

   if(JD1 > JD2)
    return 1

   if(JD1==JD2)
    return 0
}


function MoveAway(evt)
{
/* if(ShowMoveMsg)
   evt.returnValue = "Dear user , You are moving away from Namastay.in. Continue?";*/
}



function fnClearMsg(arrMSGS)
{
      for(i=0;i<arrMSGS.length;i++)
      {
       ID=arrMSGS[i]
       if(global.getElementById(ID))
          global.getElementById(ID).style.display="none"
      }
}


function fnClearErrMsg(arrMSGS)
{
      for(i=0;i<arrMSGS.length;i++)
      {

       ID=arrMSGS[i]
       if(global.getElementById('err'+ID))
          global.getElementById('err'+ID).style.display="none"

       if(global.getElementById('errValid'+ID))
          global.getElementById('errValid'+ID).style.display="none"

       if(global.getElementById('errMatch'+ID))
          global.getElementById('errMatch'+ID).style.display="none"

      }
}




function fnResetValues(arrField)
{
  var isError=false
  var i=0

      for(i=0;i<arrField.length;i++)
      {
       ID=arrField[i]

         if(global.getElementById(ID).type=="text" || global.getElementById(ID).type=="textarea" || global.getElementById(ID).type=="password")
            global.getElementById(ID).value=""

         if(global.getElementById(ID).type=="select-one")
         global.getElementById(ID).selectedIndex=0
      }
}


//////////////////////////

(function() {
/*
* Library to normalize key codes across browsers. This works with keydown
* events; keypress events are not fired for all keys, and the codes are
* different for them. It returns an object with the following fields:
* { int code, bool shift, bool alt, bool ctrl }. The normalized keycodes
* obey the following rules:
*
* For alphabetic characters, the ASCII code of the uppercase version
*
* For codes that are identical across all browsers (this includes all
* modifiers, esc, delete, arrows, etc.), the common keycode
*
* For numeric keypad keys, the value returned by numkey().
* (Usually 96 + the number)
*
* For symbols, the ASCII code of the character that appears when shift
* is not held down, EXCEPT for '" => 222 (conflicts with right-arrow/pagedown),
* .> => 190 (conflicts with Delete) and `~ => 126 (conflicts with Num0).
*
* Basic usage:
* document.onkeydown = function(e) {
* do_something_with(KeyCode.translateEvent(e)
* };
*
* The naming conventions for functions use 'code' to represent an integer
* keycode, 'key' to represent a key description (specified above), and 'e'
* to represent an event object.
*
* There's also functionality to track and detect which keys are currently
* being held down: install 'key_up' and 'key_down' on their respective event
* handlers, and then check with 'is_down'.
*
* @fileoverview
* @author Jonathan Tang
* @version 0.9
* @license BSD
*/
 
/*
Copyright (c) 2008 Jonathan Tang
All rights reserved.
 
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
 
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
var modifiers = ['ctrl', 'alt', 'shift'],
    KEY_MAP = {},
    shifted_symbols = {
        58: 59, // : -> ;
        43: 61, // = -> +
        60: 44, // < -> ,
        95: 45, // _ -> -
        62: 46, // > -> .
        63: 47, // ? -> /
        96: 192, // ` -> ~
        124: 92, // | -> \
        39: 222, // ' -> 222
        34: 222, // " -> 222
        33: 49, // ! -> 1
        64: 50, // @ -> 2
        35: 51, // # -> 3
        36: 52, // $ -> 4
        37: 53, // % -> 5
        94: 54, // ^ -> 6
        38: 55, // & -> 7
        42: 56, // * -> 8
        40: 57, // ( -> 9
        41: 58, // ) -> 0
        123: 91, // { -> [
        125: 93 // } -> ]
    };
 
function isLower(ascii) {
    return ascii >= 97 && ascii <= 122;
};
function capitalize(str) {
    return str.substr(0,1).toUpperCase() + str.substr(1).toLowerCase();
};
 
var is_gecko = navigator.userAgent.indexOf('Gecko') != -1,
    is_ie = navigator.userAgent.indexOf('MSIE') != -1,
    is_windows = navigator.platform.indexOf('Win') != -1,
    is_opera = window.opera && window.opera.version() < 9.5,
    is_konqueror = navigator.vendor && navigator.vendor.indexOf('KDE') != -1,
    is_icab = navigator.vendor && navigator.vendor.indexOf('iCab') != -1;
 
var GECKO_IE_KEYMAP = {
    186: 59, // ;: in IE
    187: 61, // =+ in IE
    188: 44, // ,<
    109: 95, // -_ in Mozilla
    107: 61, // =+ in Mozilla
    189: 95, // -_ in IE
    190: 62, // .>
    191: 47, // /?
    192: 126, // `~
    219: 91, // {[
    220: 92, // \|
    221: 93 // }]
};
 
var OPERA_KEYMAP = {};
 
// Browser detection taken from quirksmode.org
if(is_opera && is_windows) {
    KEY_MAP = OPERA_KEYMAP;
} else if(is_opera || is_konqueror || is_icab) {
    var unshift = [33, 64, 35, 36, 37, 94, 38, 42, 40, 41,
                   58, 43, 60, 95, 62, 63, 124, 34];
    KEY_MAP = OPERA_KEYMAP;
    for(var i = 0; i < unshift.length; ++i) {
        KEY_MAP[unshift[i]] = shifted_symbols[unshift[i]];
    }
} else {
    // IE and Gecko are close enough that we can use the same map for both,
    // and the rest of the world (eg. Opera 9.50) seems to be standardizing
    // on them
    KEY_MAP = GECKO_IE_KEYMAP;
}
 
if(is_konqueror) {
    KEY_MAP[0] = 45;
    KEY_MAP[127] = 46;
    KEY_MAP[45] = 95;
}
 
var key_names = {
    32: 'SPACE',
    13: 'ENTER',
    9: 'TAB',
    8: 'BACKSPACE',
    16: 'SHIFT',
    17: 'CTRL',
    18: 'ALT',
    20: 'CAPS_LOCK',
    144: 'NUM_LOCK',
    145: 'SCROLL_LOCK',
    37: 'LEFT',
    38: 'UP',
    39: 'RIGHT',
    40: 'DOWN',
    33: 'PAGE_UP',
    34: 'PAGE_DOWN',
    36: 'HOME',
    35: 'END',
    45: 'INSERT',
    46: 'DELETE',
    27: 'ESCAPE',
    19: 'PAUSE',
    222: "'"
};
function fn_name(code) {
    if(code >= 112 && code <= 123) return 'F' + (code - 111);
    return false;
};
function num_name(code) {
    if(code >= 96 && code < 106) return 'Num' + (code - 96);
    switch(code) {
        case 106: return 'Num*';
        case 111: return 'Num/';
        case 110: return 'Num.';
        default: return false;
    }
};
 
var current_keys = {
    codes: {},
    ctrl: false,
    alt: false,
    shift: false
};
 
function update_current_modifiers(key) {
    current_keys.ctrl = key.ctrl;
    current_keys.alt = key.alt;
    current_keys.shift = key.shift;
};
 
function same_modifiers(key1, key2) {
    return key1.ctrl === key2.ctrl
        && key1.alt === key2.alt
        && key1.shift === key2.shift;
};
 
if(typeof window.KeyCode != "undefined") {
    var _KeyCode = window.KeyCode;
}
 
var KeyCode = window.KeyCode = {
    no_conflict: function() {
        window.KeyCode = _KeyCode;
        return KeyCode;
    },
 
    /** Generates a function key code from a number between 1 and 12 */
    fkey: function(num) { return 111 + num; },
 
    /**
* Generates a numeric keypad code from a number between 0 and 9.
* Also works for (some) arithmetic operators. The mappings are:
*
* *: 106, /: 111, .: 110
*
* + and - are not supported because the keycodes generated by Mozilla
* conflict with the non-keypad codes. The same applies to all the
* arithmetic keypad keys on Konqueror and early Opera.
*/
    numkey: function(num) {
        switch(num) {
            case '*': return 106;
            case '/': return 111;
            case '.': return 110;
            default: return 96 + num;
        }
    },
 
    /** Generates a key code from the ASCII code of (the first character of) a
* string.
*/
    key: function(str) {
        var c = str.charCodeAt(0);
        if(isLower(c)) return c - 32;
        return shifted_symbols[c] || c;
    },
 
    /** Checks if two key objects are equal. */
    key_equals: function(key1, key2) {
        return key1.code == key2.code && same_modifiers(key1, key2);
    },
 
    /** Translates a keycode to its normalized value. */
    translate_key_code: function(code) {
        return KEY_MAP[code] || code;
    },
 
    /** Translates a keyDown event to a normalized key event object. The
* object has the following fields:
* { int code; boolean shift, boolean alt, boolean ctrl }
*/
    translate_event: function(e) {
        e = e || window.event;
        var code = e.which || e.keyCode;
        return {
            code: KeyCode.translate_key_code(code),
            shift: e.shiftKey,
            alt: e.altKey,
            ctrl: e.ctrlKey
        };
    },
 
    /**
* Keydown event listener to update internal state of which keys are
* currently pressed.
*/
    key_down: function(e) {
        var key = KeyCode.translate_event(e);
        current_keys.codes[key.code] = key.code;
        update_current_modifiers(key);
    },
 
    /**
* Keyup event listener to update internal state.
*/
    key_up: function(e) {
        var key = KeyCode.translate_event(e);
        delete current_keys.codes[key.code];
        update_current_modifiers(key);
    },
 
    /**
* Returns true if the key spec (as returned by translate_event) is
* currently held down.
*/
    is_down: function(key) {
        var code = key.code;
        if(code == KeyCode.CTRL) return current_keys.ctrl;
        if(code == KeyCode.ALT) return current_keys.alt;
        if(code == KeyCode.SHIFT) return current_keys.shift;
 
        return current_keys.codes[code] !== undefined
            && same_modifiers(key, current_keys);
    },
 
    /** Returns a string representation of a key event suitable for the
* shortcut.js or JQuery HotKeys plugins. Also makes a decent UI display.
*/
    hot_key: function(key) {
        var pieces = [];
        for(var i = 0; i < modifiers.length; ++i) {
            var modifier = modifiers[i];
            if(key[modifier] && modifier.toUpperCase() != key_names[key.code]) {
                pieces.push(capitalize(modifier));
            }
        }
 
        var c = key.code;
        var key_name = key_names[c] || fn_name(c) || num_name(c) || String.fromCharCode(c);
        pieces.push(capitalize(key_name))
        return pieces.join('+');
    }
};
 
// Add key constants
for(var code in key_names) {
    KeyCode[key_names[code]] = code;
}
})();


