
//
// based in part on 
// http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
// The Ultimate JavaScript Client Sniffer
// and Andy King's object detection sniffer
//

// convert all characters to lowercase to simplify testing
var agt = navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();

// *** BROWSER VERSION ***

var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);

var is_opera = (agt.indexOf("opera") != -1);
var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
var is_opera6 = (agt.indexOf("opera 6") != -1 || agt.indexOf("opera/6") != -1);                     // 020128- abk
var is_opera7 = (agt.indexOf("opera 7") != -1 || agt.indexOf("opera/7") != -1);                     // 021205- dmr
var is_opera8 = (agt.indexOf("opera 8") != -1 || agt.indexOf("opera/8") != -1);                     // 09-19-2006 jonw 
var is_opera9 = (agt.indexOf("opera 9") != -1 || agt.indexOf("opera/9") != -1);                     // 09-19-2006 jonw

var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);
var is_opera6up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5);               // new020128
var is_opera7up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5 && !is_opera6); // new021205 -- dmr
var is_opera8up = (is_opera && !is_opera2
                                   && !is_opera3
                                          && !is_opera4 && !is_opera5 && !is_opera6 && !is_opera7); // 09-19-2006 - jonw
var is_opera9up = (is_opera && !is_opera2
                                   && !is_opera3
                                          && !is_opera4
                                                 && !is_opera5
                                                        && !is_opera6 && !is_opera7 && !is_opera8); // 09-19-2006 - jonw

// Note: On IE, start of appVersion return 3 or 4
// which supposedly is the version of Netscape it is compatible with.
// So we look for the real version further on in the string
// And on Mac IE5+, we look for is_minor in the ua; since 
// it appears to be more accurate than appVersion - 06/17/2004

var is_mac = (agt.indexOf("mac") != -1);
var iePos = appVer.indexOf('msie');
if (iePos != -1)
{
  if (is_mac)
  {
    var iePos = agt.indexOf('msie');
    is_minor = parseFloat(agt.substring(iePos + 5, agt.indexOf(';', iePos)));
  }
  else
    is_minor = parseFloat(appVer.substring(iePos + 5, appVer.indexOf(';', iePos)));

  is_major = parseInt(is_minor);
}

// ditto Konqueror

var is_konq = false;
var kqPos = agt.indexOf('konqueror');
if (kqPos != -1)
{
  is_konq = true;
  is_minor = parseFloat(agt.substring(kqPos + 10, agt.indexOf(';', kqPos)));
  is_major = parseInt(is_minor);
}
var is_getElementById = (document.getElementById) ? "true" : "false";             // 001121-abk
var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false"; // 001127-abk
var is_documentElement = (document.documentElement) ? "true" : "false";           // 001121-abk

var is_safari = ((agt.indexOf('safari') != -1) && (agt.indexOf('mac') != -1)) ? true : false;
var is_khtml = (is_safari || is_konq);

var is_gecko = ((!is_khtml) && (navigator.product) && (navigator.product.toLowerCase() == "gecko")) ? true : false;
var is_gver = 0;
if (is_gecko)
  is_gver = navigator.productSub;
var is_fb = ((agt.indexOf(
                  'mozilla/5') != -1) && (agt.indexOf(
                                              'spoofer') == -1) && (agt.indexOf(
                                                                        'compatible') == -1) && (agt.indexOf(
                                                                                                     'opera') == -1)
                && (agt.indexOf(
                        'webtv') == -1) && (agt.indexOf(
                                                'hotjava') == -1) && (is_gecko) && (navigator.vendor == "Firebird"));
var is_fx = ((agt.indexOf(
                  'mozilla/5') != -1) && (agt.indexOf(
                                              'spoofer') == -1) && (agt.indexOf(
                                                                        'compatible') == -1) && (agt.indexOf(
                                                                                                     'opera') == -1)
                && (agt.indexOf('webtv') == -1) && (agt.indexOf('hotjava') == -1) && (is_gecko)
                && ((navigator.vendor == "Firefox") || (agt.indexOf('firefox') != -1)));
var is_moz = ((agt.indexOf(
                   'mozilla/5') != -1) && (agt.indexOf(
                                               'spoofer') == -1) && (agt.indexOf(
                                                                         'compatible') == -1) && (agt.indexOf(
                                                                                                      'opera') == -1)
                 && (agt.indexOf('webtv') == -1) && (agt.indexOf('hotjava') == -1) && (is_gecko) && (!is_fb) && (!is_fx)
                 && ((navigator.vendor == "") || (navigator.vendor == "Mozilla") || (navigator.vendor == "Debian")));
if ((is_moz) || (is_fb) || (is_fx))
{ // 032504 - dmr
  var is_moz_ver = (navigator.vendorSub) ? navigator.vendorSub : 0;

  if (is_fx && !is_moz_ver)
  {
    is_moz_ver = agt.indexOf('firefox/');
    is_moz_ver = agt.substring(is_moz_ver + 8);
    is_moz_ver = parseFloat(is_moz_ver);
  }

  if (!(is_moz_ver))
  {
    is_moz_ver = agt.indexOf('rv:');
    is_moz_ver = agt.substring(is_moz_ver + 3);
    is_paren = is_moz_ver.indexOf(')');
    is_moz_ver = is_moz_ver.substring(0, is_paren);
  }

  is_minor = is_moz_ver;
  is_major = parseInt(is_moz_ver);
}
var is_fb_ver = is_moz_ver;
var is_fx_ver = is_moz_ver;

var 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) && (!is_khtml) && (!(is_moz)) && (!is_fb)
                 && (!is_fx));

// Netscape6 is mozilla/5 + Netscape6/6.0!!!
// Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20001108 Netscape6/6.0
// Changed this to use navigator.vendor/vendorSub - dmr 060502   
// var nav6Pos = agt.indexOf('netscape6');
// if (nav6Pos !=-1) {
if ((navigator.vendor) && ((navigator.vendor == "Netscape6") || (navigator.vendor == "Netscape")) && (is_nav))
{
  is_major = parseInt(navigator.vendorSub);
  // here we need is_minor as a valid float for testing. We'll
  // revert to the actual content before printing the result. 
  is_minor = parseFloat(navigator.vendorSub);
}
var is_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && is_minor >= 4); // changed to is_minor for
// consistency - dmr, 011001
var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)));

var is_nav6 = (is_nav && is_major == 6);             // new 010118 mhp
var is_nav6up = (is_nav && is_minor >= 6);           // new 010118 mhp

var is_nav5 = (is_nav && is_major == 5 && !is_nav6); // checked for ns6
var is_nav5up = (is_nav && is_minor >= 5);

var is_nav7 = (is_nav && is_major == 7);
var is_nav7up = (is_nav && is_minor >= 7);

var is_nav8 = (is_nav && is_major == 8);
var is_nav8up = (is_nav && is_minor >= 8);

var is_ie = ((iePos != -1) && (!is_opera) && (!is_khtml));
var is_ie3 = (is_ie && (is_major < 4));

var is_ie4 = (is_ie && is_major == 4);
var is_ie4up = (is_ie && is_minor >= 4);
var is_ie5 = (is_ie && is_major == 5);
var is_ie5up = (is_ie && is_minor >= 5);

var is_ie5_5 = (is_ie && (agt.indexOf("msie 5.5") != -1)); // 020128 new - abk
var is_ie5_5up = (is_ie && is_minor >= 5.5);               // 020128 new - abk

var is_ie6 = (is_ie && is_major == 6);
var is_ie6up = (is_ie && is_minor >= 6);

var is_ie7 = (is_ie && is_major == 7);
var is_ie7up = (is_ie && is_minor >= 7);

// 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.

var is_aol = (agt.indexOf("aol") != -1);
var is_aol3 = (is_aol && is_ie3);
var is_aol4 = (is_aol && is_ie4);
var is_aol5 = (agt.indexOf("aol 5") != -1);
var is_aol6 = (agt.indexOf("aol 6") != -1);
var is_aol7 = ((agt.indexOf("aol 7") != -1) || (agt.indexOf("aol7") != -1));
var is_aol8 = ((agt.indexOf("aol 8") != -1) || (agt.indexOf("aol8") != -1));

var is_webtv = (agt.indexOf("webtv") != -1);

// new 020128 - abk

var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1));
var is_AOLTV = is_TVNavigator;

var is_hotjava = (agt.indexOf("hotjava") != -1);
var is_hotjava3 = (is_hotjava && (is_major == 3));
var is_hotjava3up = (is_hotjava && (is_major >= 3));

// end new

// *** JAVASCRIPT VERSION CHECK ***
// Useful to workaround Nav3 bug in which Nav3
// loads <SCRIPT LANGUAGE="JavaScript1.2">.
// updated 020131 by dragle
var is_js;
if (is_nav2 || is_ie3)
  is_js = 1.0;
else if (is_nav3)
  is_js = 1.1;
else if ((is_opera5) || (is_opera6))
  is_js = 1.3; // 020214 - dmr
else if (is_opera7up)
  is_js = 1.5; // 031010 - dmr
else if (is_khtml)
  is_js = 1.5; // 030110 - dmr
else if (is_opera)
  is_js = 1.1;
else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4)
  is_js = 1.2;
else if ((is_nav4 && (is_minor > 4.05)) || is_ie5)
  is_js = 1.3;
else if (is_nav5 && !(is_nav6))
  is_js = 1.4;
else if (is_hotjava3up)
  is_js = 1.4; // new 020128 - abk
else if (is_nav6up)
  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 (is_nav && (is_major > 5))
  is_js = 1.4;
else if (is_ie && (is_major > 5))
  is_js = 1.3;
else if (is_moz)
  is_js = 1.5;
else if (is_fb || is_fx)
  is_js = 1.5; // 032504 - dmr

// what about ie6 and ie6up for js version? abk

// HACK: no idea for other browsers; always check for JS version 
// with > or >=
else
  is_js = 0.0;
// HACK FOR IE5 MAC = js vers = 1.4 (if put inside if/else jumps out at 1.3)
if ((agt.indexOf("mac") != -1) && is_ie5up)
  is_js = 1.4; // 020128 - abk

// Done with is_minor testing; revert to real for N6/7
if (is_nav6up)
{
  is_minor = navigator.vendorSub;
}

// *** PLATFORM ***
var 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.
var is_win95 = ((agt.indexOf("win95") != -1) || (agt.indexOf("windows 95") != -1));

// is this a 16 bit compiled version?
var is_win16 = ((agt.indexOf("win16") != -1) || (agt.indexOf("16bit") != -1) || (agt.indexOf("windows 3.1") != -1)
                   || (agt.indexOf("windows 16-bit") != -1));

var is_win31 = ((agt.indexOf(
                     "windows 3.1") != -1) || (agt.indexOf("win16") != -1) || (agt.indexOf("windows 16-bit") != -1));

var is_winme = ((agt.indexOf("win 9x 4.90") != -1));                                           // new 020128 - abk
var is_win2k = ((agt.indexOf("windows nt 5.0") != -1) || (agt.indexOf("windows 2000") != -1)); // 020214 - dmr
var is_winxp = ((agt.indexOf("windows nt 5.1") != -1) || (agt.indexOf("windows xp") != -1));   // 020214 - dmr

// 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".
var is_win98 = ((agt.indexOf("win98") != -1) || (agt.indexOf("windows 98") != -1));
var is_winnt = ((agt.indexOf("winnt") != -1) || (agt.indexOf("windows nt") != -1));
var is_win32 = (is_win95 || is_winnt || is_win98 || ((is_major >= 4) && (navigator.platform == "Win32"))
                   || (agt.indexOf("win32") != -1) || (agt.indexOf("32bit") != -1));

var is_os2 = ((agt.indexOf("os/2") != -1) || (navigator.appVersion.indexOf(
                                                  "OS/2") != -1) || (agt.indexOf("ibm-webexplorer") != -1));

var is_mac = (agt.indexOf("mac") != -1);
if (is_mac)
{
  is_win = !is_mac;
} // dmr - 06/20/2002
var is_mac68k = (is_mac && ((agt.indexOf("68k") != -1) || (agt.indexOf("68000") != -1)));
var is_macppc = (is_mac && ((agt.indexOf("ppc") != -1) || (agt.indexOf("powerpc") != -1)));
var is_macosx = (is_mac && (agt.indexOf("os x") != -1));

var is_sun = (agt.indexOf("sunos") != -1);
var is_sun4 = (agt.indexOf("sunos 4") != -1);
var is_sun5 = (agt.indexOf("sunos 5") != -1);
var is_suni86 = (is_sun && (agt.indexOf("i86") != -1));
var is_irix = (agt.indexOf("irix") != -1); // SGI
var is_irix5 = (agt.indexOf("irix 5") != -1);
var is_irix6 = ((agt.indexOf("irix 6") != -1) || (agt.indexOf("irix6") != -1));
var is_hpux = (agt.indexOf("hp-ux") != -1);
var is_hpux9 = (is_hpux && (agt.indexOf("09.") != -1));
var is_hpux10 = (is_hpux && (agt.indexOf("10.") != -1));
var is_aix = (agt.indexOf("aix") != -1); // IBM
var is_aix1 = (agt.indexOf("aix 1") != -1);
var is_aix2 = (agt.indexOf("aix 2") != -1);
var is_aix3 = (agt.indexOf("aix 3") != -1);
var is_aix4 = (agt.indexOf("aix 4") != -1);
var is_linux = (agt.indexOf("inux") != -1);
var is_sco = (agt.indexOf("sco") != -1) || (agt.indexOf("unix_sv") != -1);
var is_unixware = (agt.indexOf("unix_system_v") != -1);
var is_mpras = (agt.indexOf("ncr") != -1);
var is_reliant = (agt.indexOf("reliantunix") != -1);
var 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));
var is_sinix = (agt.indexOf("sinix") != -1);
var is_freebsd = (agt.indexOf("freebsd") != -1);
var is_bsd = (agt.indexOf("bsd") != -1);
var is_unix = ((agt.indexOf(
                    "x11") != -1) || is_sun || is_irix || is_hpux || is_sco || is_unixware || is_mpras || is_reliant
                  || is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd);

var is_vms = ((agt.indexOf("vax") != -1) || (agt.indexOf("openvms") != -1));
// additional checks, abk
var is_anchors = (document.anchors) ? "true" : "false";
var is_regexp = (window.RegExp) ? "true" : "false";
var is_option = (window.Option) ? "true" : "false";
var is_all = (document.all) ? "true" : "false";
// cookies - 990624 - abk
document.cookie = "cookies=true";
var is_cookie = (document.cookie) ? "true" : "false";
var is_images = (document.images) ? "true" : "false";
var is_layers = (document.layers) ? "true" : "false"; // gecko m7 bug?
// new doc obj tests 990624-abk
var is_forms = (document.forms) ? "true" : "false";
var is_links = (document.links) ? "true" : "false";
var is_frames = (window.frames) ? "true" : "false";
var is_screen = (window.screen) ? "true" : "false";

// java
var is_java = (navigator.javaEnabled());

// Flash checking code adapted from Doc JavaScript information; 
// see http://webref.com/js/column84/2.html

var is_Flash = false;
var is_FlashVersion = 0;
if ((is_nav || is_opera || is_moz || is_fb || is_fx || is_safari) || (is_mac && is_ie5up))
{
  var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]
                   && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)
          ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

  //      if (plugin) {
  if (plugin && plugin.description)
  {
    is_Flash = true;
    is_FlashVersion = parseInt(plugin.description.substring(plugin.description.indexOf(".") - 1));
  }
}
if (is_win && is_ie4up)
{
  document.write(
      '<scr' + 'ipt language=VBScript>' + '\n' + 'Dim hasPlayer, playerversion' + '\n' + 'hasPlayer = false' + '\n'
          + 'playerversion = 10' + '\n' + 'Do While playerversion > 0' + '\n' + 'On Error Resume Next' + '\n'
          + 'hasPlayer = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & playerversion)))' + '\n'
          + 'If hasPlayer = true Then Exit Do' + '\n' + 'playerversion = playerversion - 1' + '\n' + 'Loop' + '\n'
          + 'is_FlashVersion = playerversion' + '\n' + 'is_Flash = hasPlayer' + '\n' + '<\/sc' + 'ript>');
}

// -->

String.prototype.xTrim = function()
{
  return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, "");
} ;
String.prototype.xFullTrim = function()
{
  return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, "").replace(/\s+/g, " ");
} ;
String.prototype.endsWith = function(pat)
{
  var d = this.length - pat.length;
  return (d >= 0) && (this.lastIndexOf(pat) === d);
} ;
String.prototype.remove = function(start_index, count)
{
  var s1 = '';
  var s2 = '';

  s1 = this.substring(0, start_index);

  if (count)
  {
    s2 = this.substring(start_index + count);
    s1 += s2;
  }  
  return s1;
}
String.replaceAll = function(str, replacements)
{
  for (i = 0; i < replacements.length; i++)
  {
    var idx = str.indexOf(replacements[i][0]);

    while (idx > -1)
    {
      str = str.replace(replacements[i][0], replacements[i][1]);
      idx = str.indexOf(replacements[i][0]);
    }
  }

  return str;
}
String.format = function(s)
{
  for (var i = 1; i < arguments.length; i++)
  {
    //s = s.replace("{" + (i -1) + "}", arguments[i]);
    s = String.replaceAll(s, [["{" + (i - 1) + "}", arguments[i]]]);
  }

  return s;
} ;

/** 
 * returns a HTML object identified by its Id
 * @param {String} str_id
 * @return (Object) a HMTL object
 */
function $(str_id)
{
  return YAHOO.util.Dom.get(str_id);
}
/**
 * wrapper for YAHOO.util.Dom.getElementsByClassName
 * @param {Object} str_className
 * @param {Object} str_parentId
 * @param {Object} str_tag
 */
function $ByClass(str_className, str_parentId, str_tag)
{
  if (!str_tag)
    str_tag = null;

  return YAHOO.util.Dom.getElementsByClassName(str_className, str_tag, $(str_parentId));
}
function $ByTag(str_tag, str_parentEleId)
{
  tag = str_tag || '*';
  var nodes = [];
  var root = null;

  if (str_parentEleId)
  {
    root = $(str_parentEleId);

    if (!root)
    { // if no root node, then no children
      return nodes;
    }
  }
  else
  {
    root = document;
  }

  var nodes = root.getElementsByTagName(tag);

  if (!nodes.length && (tag == '*' && root.all))
  {
    nodes = root.all; // IE < 6
  }

  return nodes;
}
function xGetAttribute(ele, sAtt)
{
  try
  {
    var a = ele.getAttribute(sAtt);

    if (!a)
    {
      a = ele[sAtt];
    }

    return a;
  }
  catch (e)
  {
    return '';
  }
}
function xSetAttribute(ele, attribute, value)
{
  ele.setAttribute(attribute, value);
  var a = ele.getAttribute(attribute);

  if (!a || a != value)
    a = ele[attribute] = value;

  return a;
}

/**
 * 
 * @param {Object} str_ele
 * @param {Object} str_attr
 * @param {Object} str_val
 */
function xAttr(str_ele, str_attr, str_val)
{
  var ele = $(str_ele);

  if (ele != null)
  {
    if (str_val)
    {
      //ele.setAttribute(str_attr,str_val);
      xSetAttribute(ele, str_attr, str_val);
    }

    return xGetAttribute(ele, str_attr);
  }

  return null;
}
/**
 * Returns the value of a Select or TextBox Form Element Triming the string value
 * @param {String} str_id	 the Id of a TextBox or a Select 	
 * @param {String} str_value (optional) if specified the TextBox or the Select value will be setted to this.
 * @param (Boolean) b_noTrim (optional) if specified the TextBox will return the values without trim
 * @return (String) the value of the Select or TextBox
 * 	
 */
function $v(str_id, str_value)
{
  if (!$(str_id))
    return null;

  if (str_value)
  {
    $(str_id).value = str_value;
  }

  return $(str_id).value;
}

/**
 * sets InnerHtml Property
 * @param {String} str_id 		the HTML element Id 
 * @param {String} str_value	the Value of The InnerHTML property
 * @return (String) the InnerHTML property
 */
function $inHtml(str_id, str_value)
{
  if (str_value)
  {
    $(str_id).innerHTML = str_value;
  }

  return $(str_id).innerHTML;
}

/**
 * Appends an event handler
 * 
 * @param {Object} str_ele				 The HTML element Id
 * @param {Object} str_event_name	 The type of event to append
 * @param {Object} p_fn_callback	 The function to Execute
 */
function $al(str_ele, str_event_name, p_fn_callback)
{
  if (!$(str_ele))
    return;

  return YAHOO.util.Event.on($(str_ele), str_event_name, p_fn_callback);
}

/**
 * 
 * @param {Object} e
 * @param {Object} eT
 * @param {Object} eL
 * @param {Object} cap
 */
function $ale(e, eT, eL, cap)
{
  if (!(e = $(e)))
    return;

  eT = eT.toLowerCase();

  var eh = 'e.on' + eT + '=eL';

  if (e.addEventListener)
    e.addEventListener(eT, eL, cap);
  else if (e.attachEvent)
    e.attachEvent('on' + eT, eL);
  else
    eval(eh);
}
// called only from the above
function xResizeEvent()
{
  if (window.xREL)
    setTimeout('xResizeEvent()', 250);

  var w = window, cw = xClientWidth(), ch = xClientHeight();

  if (w.xPCW != cw || w.xPCH != ch)
  {
    w.xPCW = cw;
    w.xPCH = ch;

    if (w.xREL)
      w.xREL();
  }
}
function xScrollEvent()
{
  if (window.xSEL)
    setTimeout('xScrollEvent()', 250);

  var w = window, sl = xScrollLeft(), st = xScrollTop();

  if (w.xPSL != sl || w.xPST != st)
  {
    w.xPSL = sl;
    w.xPST = st;

    if (w.xSEL)
      w.xSEL();
  }
}
function $rle(e, eT, eL, cap)
{
  if (!(e = $(e)))
    return;

  eT = eT.toLowerCase();

  if (e == window)
  {
    if (eT == 'resize' && e.xREL)
    {
      e.xREL = null;
      return;
    }

    if (eT == 'scroll' && e.xSEL)
    {
      e.xSEL = null;
      return;
    }
  }

  if (e.removeEventListener)
    e.removeEventListener(eT, eL, cap || false);
  else if (e.detachEvent)
    e.detachEvent('on' + eT, eL);
  else
    e['on' + eT] = null;
}
function xStopEvent(evt)
{
  try
  {
    YAHOO.util.Event.stopEvent(evt);
  }
  catch (e)
  {
  //
  }
}

// number formatting function
// copyright Stephen Chapman 24th March 2006
// permission to use this function is granted provided
// that this copyright notice is retained intact
//formatNumber(mynum,2,',','.','£ ','','',' CR') 
//http://javascript.about.com/library/blnumfmt.htm

function formatNumber(num, dec, thou, pnt, curr1, curr2, n1, n2)
{
  var x = Math.round(num * Math.pow(10, dec));

  if (x >= 0)
    n1 = n2 = '';

  var y = ('' + Math.abs(x)).split('');
  var z = y.length - dec;
  y.splice(z, 0, pnt);

  while (z > 3)
  {
    z -= 3;
    y.splice(z, 0, thou);
  }

  var r = curr1 + n1 + y.join('') + n2 + curr2;
  return r;
}
YAHOO.namespace('RRRM.Util');
YAHOO.RRRM.Util= 
{ 
	Redirect: function(url)
{
  window.location.href = url;
} ,                 
RunProgram: function(stProgram, stCommand)
{
  var theProgramaExist;
  var fso;
  var couldRunProgram = false;

  try
  {
    fso = new ActiveXObject("Scripting.FileSystemObject");

    if (fso.FileExists("C:/Windows/System32/" + stProgram))
    {
      theProgramaExist = true;
    }

    if (fso.FileExists("C:/WINNT/System32/" + stProgram))
    {
      theProgramaExist = true;
    }

    if (fso.FileExists("D:/Windows/System32/" + stProgram))
    {
      theProgramaExist = true;
    }

    if (fso.FileExists("D:/WINNT/System32/" + stProgram))
    {
      theProgramaExist = true;
    }
  }
  catch (e)
  {
    alert('Run Program Error : ' + e.message);
    theProgramaExist = false;
  }

  if (theProgramaExist)
  {
    try
    {
      var shell = new ActiveXObject("WScript.shell");
      shell.run(stProgram + stCommand, 1, true);
      couldRunProgram = true;
    }
    catch (e)
    {
      alert("Run Program Error (Program Exist but it can't be launched: " + e.message);
      couldRunProgram = false;
    }
  }
  else
  {
    couldRunProgram = false;
  }

  return couldRunProgram;
},                  
RegenerateViewState: function()
{
  try
  {
    __theFormPostData = "";
    __theFormPostData = new Array();

    try
    {
      WebForm_InitCallback();
    }
    catch (e)
    {
    }
  }
  catch (ex)
  {
    alert("[Regenerate ViewState Error] : " + ex.message);
  }
},                  
LoadScript: function(file, pfn_callback)
{
  //Check if the Script is already Loaded
  var doc_scripts = document.getElementsByTagName('script');
  if (doc_scripts && doc_scripts.length > 0) {
	for (var xi = 0; xi < doc_scripts.length; xi++) {
		if (doc_scripts[xi].src) {			
			if (doc_scripts[xi].src.indexOf(file) > -1)  {
				if (typeof (pfn_callback) == 'function')
				{
				   pfn_callback();
				}				
			return;
			}
		}
	}
  }
  
  var Scripts = "";
  
  // Create script DOM element
  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.src = file;
  
  

  // Alert when the script is loaded
  if (typeof (script.onreadystatechange) == 'undefined') // W3C
    script.onload = function()
    {
      this.onload = null;

      if (typeof (pfn_callback) == 'function')
      {
        pfn_callback();
      }
    }
  else // IE
    script.onreadystatechange = function()
    {
      if (this.readyState != 'loaded' && this.readyState != 'complete')
        return;

      this.onreadystatechange = null;

      if (typeof (pfn_callback) == 'function')
      {
        pfn_callback();
      }
    }; // Unset onreadystatechange, leaks mem in IE

  // Add script DOM element to document tree
  document.getElementsByTagName('head')[0].appendChild(script);
},
Trace: function(val, makeApeear)
{
  try
  {
    if (makeApeear)
    {
      $('trace').style.display = 'block';
    }

    $('trace').innerHTML += val + '<br />';
  }
  catch (e)
  {
    //this.xTraceError(e);
  }
},                  
ClearTrace: function()
{
  try
  {
    $('trace').innerHTML = '';
  }
  catch (e)
  {
    this.xTraceError(e);
  }
},                  
AvoidInstantCache: function()
{
  var today = new Date();
  var month = today.getMonth() + 1;
  var day = today.getDate();
  var year = today.getFullYear();

  var semilla = month + day + year + today.getHours() + today.getMinutes() + today.getSeconds();

  return semilla;
},   
GetNoCacheUrl: function(str_url) 
{
  var token = (str_url.indexOf("?") > -1)? "&" : "?";
  
  str_url += String.format("{0}xnocache={1}",token,this.AvoidInstantCache()); //token + 'xnocache=' + this.AvoidInstantCache();    
  return str_url;
},               
AvoidCache: function()
{
  var today = new Date();
  var month = today.getMonth() + 2;
  var day = today.getDate();
  var year = today.getFullYear();
  var semilla = month + day + year + today.getHours();

  return semilla;
},                  
LoadCSS: function(url_, media_)
{

  // We are preventing loading a file already loaded
  var _links = document.getElementsByTagName("link");
  if (_links && _links.length > 0) {
	for (var xi = 0; xi < _links.length; xi++) {
		if (_links[xi].href) {			
			if (_links[xi].href.indexOf(url_) > -1)  {								
				return;
			}
		}
	}
  }

  // Optional parameters check
  var _media = media_ === undefined || media_ === null ? "all" : media_;

  var _elstyle = document.createElement("link");
  _elstyle.setAttribute("rel", "stylesheet");
  _elstyle.setAttribute("type", "text/css");
  _elstyle.setAttribute("media", _media);
  _elstyle.setAttribute("href", url_);

  var _head = document.getElementsByTagName("head")[0];
  _head.appendChild(_elstyle);
},                  
xGetAbsolutePos: function(el)
{
  var SL = 0;
  var ST = 0;
  var is_div = /^div$/i.test(el.tagName);

  if (is_div && el.scrollLeft)
  {
    SL = el.scrollLeft;
  }

  if (is_div && el.scrollTop)
  {
    ST = el.scrollTop;
  }

  var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };

  if (el.offsetParent)
  {
    var tmp = this.xGetAbsolutePos(el.offsetParent);
    r.x += tmp.x;
    r.y += tmp.y;
  }

  return r;
},                  
xGetBounds: function(ele)
{
  var offset = this.xGetAbsolutePos(ele);
  var width = ele.offsetWidth;
  var height = ele.offsetHeight;

  return { left: offset.left, top: offset.top, width: width, height: height };
},
xTraceError : function (e) {
  alert('[xTraceError An Exception has been raised] : ' + e.message );
},
xWindowEventAttached : false,
xEventsAddedForMessage: false,
xLockBackground : function () {				
		if ($('__popupMask') == null) {
			var mask = document.createElement('DIV');
			mask.id = '__popupMask';
			mask.style.display = 'none';
			mask.className = 'xpopupMask';
			document.body.appendChild(mask);						
		}
		if (!YAHOO.RRRM.Util.xWindowEventAttached) {
			YAHOO.RRRM.Util.xWindowEventAttached = true;
			$ale(window,'scroll',YAHOO.RRRM.Util.xLockBackground,false);
			$ale(window,'resize',YAHOO.RRRM.Util.xLockBackground,false);	
		}

		
		var gPopupMask = $('__popupMask');		
		gPopupMask.style.display = "block";

		
		var fullHeight = xClientHeight();
		var fullWidth = xClientWidth();
		
		var theBody = document.documentElement;
		
		var scTop = xScrollTop()//parseInt(theBody.scrollTop,10);
		var scLeft = xScrollLeft()//parseInt(theBody.scrollLeft,10);
		
		gPopupMask.style.height = fullHeight + "px";
		gPopupMask.style.width = fullWidth + "px";
		gPopupMask.style.top = scTop + "px";
		gPopupMask.style.left = scLeft + "px";		
		
		
		$ale(document,'keypress',YAHOO.RRRM.Util.xKeyDownHandler,false);
    
		YAHOO.RRRM.Util.xDisableTabIndexes();
		if (YAHOO.RRRM.Util.xIsIe6()) {			
			YAHOO.RRRM.Util.xHideSelectBoxes();
		}
		
		
	},
	xUnLockBackground : function () {				

		var gPopupMask = $('__popupMask');		
		if (gPopupMask != null) {
			gPopupMask.style.display = "none";						
		}
		if (this.xWindowEventAttached) {
			$rle(window,'scroll',YAHOO.RRRM.Util.xLockBackground,false);
			$rle(window,'resize',YAHOO.RRRM.Util.xLockBackground,false);	
			$rle(document,'keypress',YAHOO.RRRM.Util.xKeyDownHandler,false);
			
			YAHOO.RRRM.Util.xRestoreTabIndexes();
			if (YAHOO.RRRM.Util.xIsIe6()) {				
				YAHOO.RRRM.Util.xDisplaySelectBoxes();
			}
			YAHOO.RRRM.Util.xWindowEventAttached = false;
		}
	},
	xKeyDownHandler: function(e) {
		var ele =  $('__popupMask');
		if (ele != null) {
			if ((ele.style.display == 'block') && e.keyCode == 9) {				
				xStopEvent(e);
				return false;
			} 
		}
	},
	xDisableTabIndexes: function () {
		if (document.all) {
		var i = 0;
		for (var j = 0; j < this.xTabbableTags.length; j++) {
			var tagElements = document.getElementsByTagName(this.xTabbableTags[j]);
			for (var k = 0 ; k < tagElements.length; k++) {
					this.xTabIndexes[i] = tagElements[k].tabIndex;
					tagElements[k].tabIndex="-1";
					i++;
				}
			}
		}
	},
	xRestoreTabIndexes: function () {
		if (document.all) {
			var i = 0;
			for (var j = 0; j < this.xTabbableTags.length; j++) {
				var tagElements = document.getElementsByTagName(this.xTabbableTags[j]);
				for (var k = 0 ; k < tagElements.length; k++) {
					tagElements[k].tabIndex = this.xTabIndexes[i];
					tagElements[k].tabEnabled = true;
					i++;
				}
			}
		}
	},
	xHideSelectBoxes: function () {
		var pageSelects = $ByTag('SELECT');
		for (var i = 0; i < pageSelects.length; i++) {
			if (!(pageSelects[i].className.indexOf('NOHIDE') > -1)) {
				//pageSelects[i].style.
				pageSelects[i].style.visibility = "hidden";
			}
		}
	},
	xDisplaySelectBoxes : function() {
		var pageSelects = $ByTag('SELECT');						
		for (var i = 0; i < pageSelects.length; i++) {
			if (!(pageSelects[i].className.indexOf('NOHIDE') > -1)) {
				//pageSelects[i].style.display = "block";
				pageSelects[i].style.visibility = "visible";
			}
		}
	},
	xHideSelects : false,
	xTabIndexes : new Array(),
	xTabbableTags : new Array("A","BUTTON","TEXTAREA","INPUT","IFRAME","SELECT"),
	
	xIsIe6 : function () {
		return (is_ie && !(is_ie7up));
	},
	xShowLoadingMessage: function (mensaje, 
                                 top,
                                 right,
                                 padding,
                                 bgColor, 
                                 color,                                 
                                 secondsToHide) {	
		if (!mensaje) { 
			mensaje = ':: Procesando ::'; 
		}
		if (!right){
		  right = 20;
		}
		if (!top){
		  top = 20;
		}
		if (!bgColor){
		  bgColor = '#FF0000';
		}
		if (!color) {
			color = '#FFFFFF';
		}
		if(!padding){
		  padding = 5;
		}		
		
    var autoHide = secondsToHide || secondsToHide > 0;		  
		
		if (autoHide) {
		  setTimeout('YAHOO.RRRM.Util.xHideLoadingMessage()',secondsToHide * 1000);
		}
		
    var aDiv = null;
	  if ($('xxxdivLoadingMessage') == null) {
	    var aDiv = document.createElement('DIV');	    
      aDiv.id = 'xxxdivLoadingMessage';	    	    
	    document.body.appendChild(aDiv);
	  } 
    else {
	      aDiv = $('xxxdivLoadingMessage');
	  }
    aDiv.innerHTML = mensaje;			    
    aDiv.style.top = top + 'px';
    aDiv.style.position = 'absolute';
		aDiv.style.right = right + 'px';
		aDiv.style.padding = padding + 'px';
		aDiv.style.color = color;
		aDiv.style.backgroundColor = bgColor;			    
	  aDiv.style.display = 'block';
    aDiv.style.zIndex = 10000;
    aDiv.style.fontWeight = 'normal';
    aDiv.style.fontSize = '80%';

    
    if (!YAHOO.RRRM.Util.xEventsAddedForMessage) {
      $ale(window,'resize',this.xSetMessagePosition,false);
      $ale(window,'scroll',this.xSetMessagePosition,false);
      YAHOO.RRRM.Util.xEventsAddedForMessage = true; 
    }
    
		YAHOO.RRRM.Util.xMessagePosition = top;
		this.xSetMessagePosition();
	},
  xSetMessagePosition: function () {
        YAHOO.util.Dom.setY($('xxxdivLoadingMessage'),xScrollTop() + YAHOO.RRRM.Util.xMessagePosition);     
  },
  xMessagePosition : 0,
	xHideLoadingMessage: function () {
	    if ($('xxxdivLoadingMessage') != null) {
         $('xxxdivLoadingMessage').style.display = 'none';
         YAHOO.RRRM.Util.xMessagePosition = 0;
         YAHOO.RRRM.Util.xEventsAddedForMessage = false; 
         $rle(window,'resize',this.xSetMessagePosition,false);
         $rle(window,'scroll',this.xSetMessagePosition,false);       
      }
	}
};

YAHOO.namespace('RRRM.Cookie');
YAHOO.RRRM.Cookie = {
  /**
	 * Read the JavaScript cookies tutorial at:
	 *   http://www.netspade.com/articles/javascript/cookies.xml
	 */
	
	/**
	 * Sets a Cookie with the given name and value.
	 *
	 * name       Name of the cookie
	 * value      Value of the cookie
	 * [expires]  Expiration date of the cookie (default: end of current session)
	 * [path]     Path where the cookie is valid (default: path of calling document)
	 * [domain]   Domain where the cookie is valid
	 *              (default: domain of calling document)
	 * [secure]   Boolean value indicating if the cookie transmission requires a
	 *              secure transmission
	 */
	setCookie: function (name, value, expires, path)
				{
					document.cookie= name + "=" + escape(value) +
						((expires) ? "; expires=" + expires.toGMTString() : "") +
						((path) ? "; path=" + path : ""); /*+
						((domain) ? "; domain=" + domain : "") +
						((secure) ? "; secure" : "");*/
				},

	/**
	 * Gets the value of the specified cookie.
	 *
	 * name  Name of the desired cookie.
	 *
	 * Returns a string containing value of specified cookie,
	 *   or null if cookie does not exist.
	 */
	getCookie: function (cookieName)
	{
		/*var dc = document.cookie;
		var prefix = name + "=";
		var begin = dc.indexOf("; " + prefix);
		if (begin == -1)
		{
			begin = dc.indexOf(prefix);
			if (begin != 0) return null;
		}
		else
		{
			begin += 2;
		}
		var end = document.cookie.indexOf(";", begin);
		if (end == -1)
		{
			end = dc.length;
		}
		return unescape(dc.substring(begin + prefix.length, end));*/
		var theCookie=""+document.cookie;
		 var ind=theCookie.indexOf(cookieName);
		 if (ind==-1 || cookieName=="") return ""; 
		 var ind1=theCookie.indexOf(';',ind);
		 if (ind1==-1) ind1=theCookie.length; 
		 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));

	},

	/**
	 * Deletes the specified cookie.
	 *
	 * name      name of the cookie
	 * [path]    path of the cookie (must be same as path used to create cookie)
	 * [domain]  domain of the cookie (must be same as domain used to create cookie)
	 */
	deleteCookie: function (name, path, domain)
	{
		if (this.getCookie(name))
		{
			document.cookie = name + "=" + 
				((path) ? "; path=" + path : "") +
				((domain) ? "; domain=" + domain : "") +
				"; expires=Thu, 01-Jan-70 00:00:01 GMT";
		}
	}
};



function xIsNull(aVar,aDefaultValue){
    return (!xDef(aVar))?aDefaultValue:aVar;
   }

// xEvent r9, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xDef()
{
  for (var i = 0; i < arguments.length; ++i)
  {
    if (typeof (arguments[i]) == 'undefined' || arguments[i] == null)
      return false;
  }
  return true;
}

function xNum()
{
  for(var i=0; i<arguments.length; ++i){if(isNaN(arguments[i]) || typeof(arguments[i])!='number') return false;}
  return true;
}


function xClientWidth() {
  return YAHOO.util.Dom.getClientWidth();
}
function xClientHeight(){
  return YAHOO.util.Dom.getClientHeight();
}
function xScrollLeft(e, bWin)
{
  var offset=0;
  if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
    var w = window;
    if (bWin && e) w = e;
    if(w.document.documentElement && w.document.documentElement.scrollLeft) offset=w.document.documentElement.scrollLeft;
    else if(w.document.body && xDef(w.document.body.scrollLeft)) offset=w.document.body.scrollLeft;
  }
  else {
    e = $(e);
    if (e && xNum(e.scrollLeft)) offset = e.scrollLeft;
  }
  return offset;
}
function xScrollTop(e, bWin)
{
  var offset=0;
  if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
    var w = window;
    if (bWin && e) w = e;
    if(w.document.documentElement && w.document.documentElement.scrollTop) offset=w.document.documentElement.scrollTop;
    else if(w.document.body && xDef(w.document.body.scrollTop)) offset=w.document.body.scrollTop;
  }
  else {
    e = $(e);
    if (e && xNum(e.scrollTop)) offset = e.scrollTop;
  }
  return offset;
}
function xPageX(e)
{
  var x = 0;
  e = $(e);
  while (e) {
    if (xDef(e.offsetLeft)) x += e.offsetLeft;
    e = xDef(e.offsetParent) ? e.offsetParent : null;
  }
  return x;
}
function xPageY(e)
{
  var y = 0;
  e = $(e);
  while (e) {
    if (xDef(e.offsetTop)) y += e.offsetTop;
    e = xDef(e.offsetParent) ? e.offsetParent : null;
  }
  return y;
}

function xEvent(evt) // object prototype
{
  var e = evt || window.event;

  if (!e)
    return;

  if (e.type)
    this.type = e.type;

  if (e.target)
    this.target = e.target;
  else if (e.srcElement)
    this.target = e.srcElement;

  // Section B
  if (e.relatedTarget)
    this.relatedTarget = e.relatedTarget;
  else if (e.type == 'mouseover' && e.fromElement)
    this.relatedTarget = e.fromElement;
  else if (e.type == 'mouseout')
    this.relatedTarget = e.toElement;

  // End Section B
  if (xDef(e.pageX, e.pageY))
  {
    this.pageX = e.pageX;
    this.pageY = e.pageY;
  }
  else if (xDef(e.clientX, e.clientY))
  {
    this.pageX = e.clientX + xScrollLeft();
    this.pageY = e.clientY + xScrollTop();
  }

  // Section A
  if (xDef(e.offsetX, e.offsetY))
  {
    this.offsetX = e.offsetX;
    this.offsetY = e.offsetY;
  }
  else if (xDef(e.layerX, e.layerY))
  {
    this.offsetX = e.layerX;
    this.offsetY = e.layerY;
  }
  else
  {
    this.offsetX = this.pageX - xPageX(this.target);
    this.offsetY = this.pageY - xPageY(this.target);
  }

  // End Section A
  this.keyCode = e.keyCode || e.which || 0;
  this.shiftKey = e.shiftKey;
  this.ctrlKey = e.ctrlKey;
  this.altKey = e.altKey;
  // rev8
  this.button = null; // 0=left, 1=middle, 2=right, null=none-mouse event

  if (e.type.indexOf('click') != -1)
    this.button = 0;
  else if (e.type.indexOf('mouse') != -1)
  {
    var ie = 0, v = navigator.vendor;
    /*@cc_on ie = 1; @*/
    // I hate this sniff, but I don't know of any other way to support Safari here.
    if (ie || (v && v.indexOf('Apple') != -1))
    { // IE or Safari
      if (e.button & 1)
        this.button = 0;
      else if (e.button & 2)
        this.button = 2;
      else if (e.button & 4)
        this.button = 1;
    }
    else
      this.button = e.button;
  }
};



///**
// * Allow mozilla elements to simulate the click method for buttons
// */
//if (!is_ie) 
//{
//  HTMLElement.prototype.click = function() {    
//    var evt = this.ownerDocument.createEvent('MouseEvents');
//    evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
//    this.dispatchEvent(evt);
//  }
//}

/**
 * Wrapper for the onDOMReady function of the YAHOO object
 * @param {Object} aFunction
 */
 function $ready (aFunction) {
  if (!YAHOO.util.Event.DOMReady)
    YAHOO.util.Event.onDOMReady(aFunction);
  else {
    try {
      aFunction();
    }
    catch(e) {
      window.status = (e.message);
    }
  }
}

/**
 * Checks if Page_ClientValidate exists and call it. 
 * This function depends on ASP.NET Client validator javascript functions 
 * @param {Object} str_group the ValidationGroup of the Validators
 */ 
function xValidate(str_group) {
  if (str_group) {
      if (typeof(Page_ClientValidate) == 'function') { 
         return Page_ClientValidate(str_group);
      }
  }
  else {
    if (typeof(Page_ClientValidate) == 'function') { 
         return Page_ClientValidate();
    }    
  }
  return false;
}

/**
 * Protect the FormSend
 */
function $pfs(e,str_group,message,title,showPanelOnly) 
  {      
    if (!showPanelOnly) {
      if (xValidate(str_group)) {
        $ShowPanel(xIsNull(title,'Please Wait'),xIsNull(message,'Processing...'));
      }
      else {
        xStopEvent(e);
      }
    }
    else {
      $ShowPanel(xIsNull(title,'Please Wait'),xIsNull(message,'Processing...'));
    }
  }

/**
 * Clear the Form Elements in a Div. the className of the elements must follow the next rules:
 * for TextBox ===> 'FormText'
 * for Select ===> 'FormCbx'
 * for TextArea ===> 'FormText'
 * @param {Object} strDiv
 */
function xFormClear(strDiv) {
	    try {
	      var arrInputs = $ByClass('FormText',$(strDiv),'INPUT');
	      var arrSelects = $ByClass('FormCbx',$(strDiv),'SELECT');
	      var arrTextAreas = $ByClass('FormText',$(strDiv),'TEXTAREA');
  	    
	      for (ini = 0; ini < arrInputs.length ; ini++) {
	        arrInputs[ini].value = '';
	      }
  	    
	      for (ini = 0; ini < arrSelects.length ; ini++) {
	        arrSelects [ini].selectedIndex = 0;
	      }
  	    
	      for (ini = 0; ini < arrTextAreas.length ; ini++) {
	        arrTextAreas[ini].value = '';
	      }
	    }
	    catch(e) {
	      alert("[Error cleaning form] : "+ e.message);
	    }
	    
	  }
	  
/***
 * Check if the array contains a especific value
 * @param {Object} arr the Array object
 * @param {Object} valueToFind the Value to find
 * @return (Boolean) true if the value is in the array, false otherwise.
 */
function xIsInArr(arr,valueToFind, refObj) {
  for (var ix = 0; ix < arr.length; ix++) {
    if (valueToFind == arr[ix]) { 
      refObj.ix = ix;
      return true;
    }
  }
  return false;
}
/**
 * Capture the __doPostBack function to be able to handle some ajax calls for example.
 * @param {Arrary} arrValuesToInspect IDs of the controls which postbacks are going to be captured. 
 * @param {function} ptr_fn_toCall Function that will be called if the controlId of the Control that raises the postback matches the 
 */
function xCapturePostBack(arrValuesToInspect,ptr_fn_toCall)
{
  try 
    {     
 
 
			 YAHOO.namespace("RRRM");
			 if (YAHOO.RRRM._DO_POST_FUNCTIONS == null) {
			    YAHOO.RRRM._DO_POST_FUNCTIONS = new Array();			    
			 }
			 if (YAHOO.RRRM.PostBackElementsArray == null) 
			 {
			 		YAHOO.RRRM.PostBackElementsArray = new Array();					 			 		
			 }
			 for (var ix = 0; ix < arrValuesToInspect.length; ix++) 
			 {  
					YAHOO.RRRM.PostBackElementsArray.push(arrValuesToInspect[ix]);
					YAHOO.RRRM._DO_POST_FUNCTIONS[arrValuesToInspect[ix]] = ptr_fn_toCall;
			 } 					 			 
       if (typeof __doPostBack == 'function') {
       var old_doPostBack = __doPostBack;
       __doPostBack = function (controlId, value) {                  
          var refObj = {};            
					refObj.ix = -1;
          if (xIsInArr(YAHOO.RRRM.PostBackElementsArray,controlId, refObj) ) 
          {   
              if (refObj.ix != -1) YAHOO.RRRM._DO_POST_FUNCTIONS[YAHOO.RRRM.PostBackElementsArray[refObj.ix]](controlId, value);
          }
          else {
              old_doPostBack(controlId,value);
          }
        }                    
      }
    }
    catch(e) {
        
    }
}

/**
 * Wrapper for the xShowLoadingMessage Function
 * @param (String) msg The Message to show
 */
function $ShowMessage(msg,t) {
   if (!t) YAHOO.RRRM.Util.xShowLoadingMessage(msg); 
   else YAHOO.RRRM.Util.xShowLoadingMessage(msg,null,null, null,null, null, t); 
}

/**
 * Wrapper for the xHideLoadingMessage Function 
 */
function $HideMessage() {
   YAHOO.RRRM.Util.xHideLoadingMessage(); 
}

/**
 * Create a WaterMark for the Default Value of a text
 * TODO: Make that the ASP.NET Validators wiew the Initial Default Value as an Empty Value
 * @param {Object} str_id
 * @param {Object} DefaultValue
 * 
 * note: this method depends on the FormText.DefaultValue  css class (color: #999999;)
 */
function xDefaultValueTextBox(str_id, DefaultValue) {
  var ele = $(str_id);
  
  if (DefaultValue) xAttr(ele,'dValue',DefaultValue);
  
  if (!xAttr(ele,'dValue')) return;
  
  $ale(ele,'blur',doBlur,true);
  $ale(ele,'focus',doFocus,true);
  
  doBlur();
  
  
  //Always Free Memory!!!!! Mainly in IE.
  $ale(window,'unload',_doUnload,false);
  
  function _doUnload() {
    $rle(ele,'blur',doBlur,true);
    $rle(ele,'focus',doFocus,true);    
    ele = null;
  }
  
  function doBlur(e) {
    
    if (ele.value == '') {
      ele.value = xAttr(ele,'dValue');  
      YAHOO.util.Dom.addClass(ele,"DefaultValue");
    }    
    
  }
  
  function doFocus(e) {
     if (ele.value == xAttr(ele,'dValue')) 
     {
        ele.value = '';
        YAHOO.util.Dom.removeClass(ele,"DefaultValue");
     }     
  }    
}
/**
 * Apply The Default Values of the TextBox inside a Div
 * @param {Object | String} str_divId Id or Object of a Div that Contains the TextBoxes
 */
function xApplyDefaultValuesInDiv(str_divId) {
  var arr = $ByClass('FormText',str_divId);   
  for (var xi = 0; xi < arr.length; xi++)    
  {
   xDefaultValueTextBox(arr[xi]);
  }
}
/**
 * Search in the DOM for the textbox that have a Default Value
 * 1. Add the dValue Attribute to the TextBox and set its value to the Default Value that will be showed as 
 * 		a WaterMark
 * 
 */
$ready(
  function () {
    var arr = $ByClass('FormText');    
    for (var xi = 0; xi < arr.length; xi++)    
    {
      xDefaultValueTextBox(arr[xi]);
    }
  }
);


var $U = YAHOO.RRRM.Util;