

function frm_fieldjump(CurrentField, MaxCharacter, NextFocusObject)
{
    curfield = document.getElementsByName(CurrentField);
    nextfield = document.getElementsByName(NextFocusObject);
    
    if( curfield[0] && nextfield[0] )
    {
    	if(curfield[0].value.length >= MaxCharacter)
    		nextfield[0].focus();

    }
}

function disptonone(thisid)
{
    if( document.getElementById(thisid) )
        document.getElementById(thisid).style.display='none';
}

function popwinnew(divid)
{
    eval("popwin_" +divid +" = new lib_obj('"+divid+"')");

}

function addslashes(str)
{
    str = str.replace(/\'/g, "\\\'").replace(/\"/g, "\\\"");
    return str;
}

/****************************************************************************   
DHTML library from DHTMLCentral.com
*   Copyright (C) 2001 Thomas Brattli 2001
*   This script was released at DHTMLCentral.com
*   Visit for more great scripts!
*   This may be used and changed freely as long as this msg is intact!
*   We will also appreciate any links you could give us.
*
*   Made by Thomas Brattli 2001
***************************************************************************/

//Browsercheck (needed) ***************
function lib_bwcheck(){ 
  this.ver=navigator.appVersion
  this.agent=navigator.userAgent
  this.dom=document.getElementById?1:0
  this.opera5=this.agent.indexOf("Opera 5")>-1
  this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
  this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
  this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
  this.ie=this.ie4||this.ie5||this.ie6
  this.mac=this.agent.indexOf("Mac")>-1
  this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
  this.ns4=(document.layers && !this.dom)?1:0;
  this.bw=(this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5)
  return this
}
bw=new lib_bwcheck() //Browsercheck object

//Debug function ******************
function lib_message(txt){alert(txt); return false}

//Lib objects  ********************
function lib_obj(obj,nest){ 
  if(!bw.bw) return lib_message('Old browser')
  nest=(!nest) ? "":'document.'+nest+'.'
  this.evnt=bw.dom? document.getElementById(obj):
    bw.ie4?document.all[obj]:bw.ns4?eval(nest+"document.layers." +obj):0;	
  if(!this.evnt) return lib_message('The layer does not exist ('+obj+')' 
    +'- \nIf your using Netscape please check the nesting of your tags!')
  this.css=bw.dom||bw.ie4?this.evnt.style:this.evnt; 
  this.ref=bw.dom||bw.ie4?document:this.css.document;
  this.x=parseInt(this.css.left)||this.css.pixelLeft||this.evnt.offsetLeft||0;
  this.y=parseInt(this.css.top)||this.css.pixelTop||this.evnt.offsetTop||0
  this.w=this.evnt.offsetWidth||this.css.clip.width||
    this.ref.width||this.css.pixelWidth||0; 
  this.h=this.evnt.offsetHeight||this.css.clip.height||
    this.ref.height||this.css.pixelHeight||0
  this.c=0 //Clip values
  if((bw.dom || bw.ie4) && this.css.clip) {
  this.c=this.css.clip; this.c=this.c.slice(5,this.c.length-1); 
  this.c=this.c.split(' ');
  for(var i=0;i<4;i++){this.c[i]=parseInt(this.c[i])}
  }
  this.ct=this.css.clip.top||this.c[0]||0; 
  this.cr=this.css.clip.right||this.c[1]||this.w||0
  this.cb=this.css.clip.bottom||this.c[2]||this.h||0; 
  this.cl=this.css.clip.left||this.c[3]||0
  this.obj = obj + "Object"; eval(this.obj + "=this")
  return this
}

//Moving object to **************
lib_obj.prototype.moveIt = function(x,y){
  this.x=x;this.y=y; this.css.left=x;this.css.top=y
}

//Moving object by ***************
lib_obj.prototype.moveBy = function(x,y){
  this.css.left=this.x+=x; this.css.top=this.y+=y
}

//Showing object ************
lib_obj.prototype.showIt = function(){this.css.visibility="visible"}

//Hiding object **********
lib_obj.prototype.hideIt = function(){this.css.visibility="hidden"}

//Changing backgroundcolor ***************
lib_obj.prototype.bg = function(color){ 
	if(bw.opera) this.css.background=color
	else if(bw.dom || bw.ie4) this.css.backgroundColor=color
	else if(bw.ns4) this.css.bgColor=color  
}

//Writing content to object ***
lib_obj.prototype.writeIt = function(text,startHTML,endHTML){
	if(bw.ns4){
    if(!startHTML){startHTML=""; endHTML=""}
	  this.ref.open("text/html"); 
    this.ref.write(startHTML+text+endHTML); 
    this.ref.close()
	}else this.evnt.innerHTML=text
}

//Clipping object to ******
lib_obj.prototype.clipTo = function(t,r,b,l,setwidth){ 
  this.ct=t; this.cr=r; this.cb=b; this.cl=l
  if(bw.ns4){
    this.css.clip.top=t;this.css.clip.right=r
    this.css.clip.bottom=b;this.css.clip.left=l
  }else{
    if(t<0)t=0;if(r<0)r=0;if(b<0)b=0;if(b<0)b=0
    this.css.clip="rect("+t+","+r+","+b+","+l+")";
    if(setwidth){this.css.pixelWidth=this.css.width=r; 
    this.css.pixelHeight=this.css.height=b}
  }
}

//Clipping object by ******
lib_obj.prototype.clipBy = function(t,r,b,l,setwidth){ 
  this.clipTo(this.ct+t,this.cr+r,this.cb+b,this.cl+l,setwidth)
}

//Clip animation ************
lib_obj.prototype.clipIt = function(t,r,b,l,step,fn,wh){
  tstep=Math.max(Math.max(Math.abs((t-this.ct)/step),Math.abs((r-this.cr)/step)),
    Math.max(Math.abs((b-this.cb)/step),Math.abs((l-this.cl)/step)))
  if(!this.clipactive){
    this.clipactive=true; if(!wh) wh=0; if(!fn) fn=0
    this.clip(t,r,b,l,(t-this.ct)/tstep,(r-this.cr)/tstep,
      (b-this.cb)/tstep,(l-this.cl)/tstep,tstep,0, fn,wh)
  }
}
lib_obj.prototype.clip = function(t,r,b,l,ts,rs,bs,ls,tstep,astep,fn,wh){
  if(astep<tstep){
    if(wh) eval(wh); 
    astep++
    this.clipBy(ts,rs,bs,ls,1);
    setTimeout(this.obj+".clip("+t+","+r+","+b+","+l+","+ts+","+rs+","
      +bs+","+ls+","+tstep+","+astep+",'"+fn+"','"+wh+"')",50)
  }else{
    this.clipactive=false; this.clipTo(t,r,b,l,1);
    if(fn) eval(fn)
  }
}

//Slide animation ***********
lib_obj.prototype.slideIt = function(endx,endy,inc,speed,fn,wh){
  if(!this.slideactive){
    var distx = endx - this.x;
    var disty = endy - this.y
    var num = Math.sqrt(Math.pow(distx,2)+Math.pow(disty,2))/inc
    var dx = distx/num; var dy = disty/num
    this.slideactive = 1; 
    if(!wh) wh=0; if(!fn) fn=0
    this.slide(dx,dy,endx,endy,speed,fn,wh)
    }
}
lib_obj.prototype.slide = function(dx,dy,endx,endy,speed,fn,wh) {
  if(this.slideactive&&
  (Math.floor(Math.abs(dx))<Math.floor(Math.abs(endx-this.x))|| 
    Math.floor(Math.abs(dy))<Math.floor(Math.abs(endy-this.y)))){
    this.moveBy(dx,dy); 
    if(wh) eval(wh)
    setTimeout(this.obj+".slide("+dx+","+dy+","+endx+","+endy+","+speed+",'"
    +fn+"','"+wh+"')",speed)
  }else{
    this.slideactive = 0; 
    this.moveIt(endx,endy);
    if(fn) eval(fn)
  }
}

//Circle animation ****************
lib_obj.prototype.circleIt = function(rad,ainc,a,enda,xc,yc,speed,fn) {
  if((Math.abs(ainc)<Math.abs(enda-a))) {
    a += ainc
    var x = xc + rad*Math.cos(a*Math.PI/180)
    var y = yc - rad*Math.sin(a*Math.PI/180)
    this.moveIt(x,y)
    setTimeout(this.obj+".circleIt("+rad+","+ainc+","+a+","+enda+","
      +xc+","+yc+","+speed+",'"+fn+"')",speed)
  }else if(fn&&fn!="undefined") eval(fn)
}

//Document size object ********
function lib_doc_size(){ 
  this.x=0;this.x2=bw.ie && document.body.offsetWidth-20||innerWidth||0;
  this.y=0;this.y2=bw.ie && document.body.offsetHeight-5||innerHeight||0;
  if(!this.x2||!this.y2) return message('Document has no width or height') 
  this.x50=this.x2/2;this.y50=this.y2/2;
  return this;
}

//Drag drop functions start *******************
dd_is_active=0; dd_obj=0; dd_mobj=0
function lib_dd(){
  dd_is_active=1
  if(bw.ns4){
    document.captureEvents(Event.MOUSEMOVE|Event.MOUSEDOWN|Event.MOUSEUP)
  }
  document.onmousemove=lib_dd_move;
  document.onmousedown=lib_dd_down
  document.onmouseup=lib_dd_up
}
lib_obj.prototype.dragdrop = function(obj){
  if(!dd_is_active) lib_dd()
  this.evnt.onmouseover=new Function("lib_dd_over("+this.obj+")")
  this.evnt.onmouseout=new Function("dd_mobj=0")
  if(obj) this.ddobj=obj
}
lib_obj.prototype.nodragdrop = function(){
  this.evnt.onmouseover=""; this.evnt.onmouseout=""
  dd_obj=0; dd_mobj=0
}
//Drag drop event functions
function lib_dd_over(obj){dd_mobj=obj}
function lib_dd_up(e){dd_obj=0}
function lib_dd_down(e){ //Mousedown
  if(dd_mobj){
    x=(bw.ns4 || bw.ns6)?e.pageX:event.x||event.clientX
    y=(bw.ns4 || bw.ns6)?e.pageY:event.y||event.clientY
    dd_obj=dd_mobj
    dd_obj.clX=x-dd_obj.x; 
    dd_obj.clY=y-dd_obj.y
  }
}
function lib_dd_move(e,y,rresize){ //Mousemove
  x=(bw.ns4 || bw.ns6)?e.pageX:event.x||event.clientX
  y=(bw.ns4 || bw.ns6)?e.pageY:event.y||event.clientY
  if(dd_obj){
    nx=x-dd_obj.clX; ny=y-dd_obj.clY
    if(dd_obj.ddobj) dd_obj.ddobj.moveIt(nx,ny)
    else dd_obj.moveIt(nx,ny)
  }
  if(!bw.ns4) return false      
}

function getDetails(obj){
	str="x: " + obj.x + "\n"
	str+="y: " + obj.y + "\n"
	str+="w: " + obj.w + "\n"
	str+="h: " + obj.h + "\n"
	str+="ct: " + obj.ct + "\n"
	str+="cr: " + obj.cr + "\n"
	str+="cb: " + obj.cb + "\n"
	str+="cl: " + obj.cl + "\n"
  alert(str)
}
//Drag drop functions end *************



function DL_GetElementLeft(eElement)
{
    if (!eElement && this)                       // if argument is invalid
    {                                            // (not specified, is null or is 0)
        eElement = this;                         // and function is a method
    }                                            // identify the element as the method owner
    
    var nLeftPos = eElement.offsetLeft;          // initialize var to store calculations
    var eParElement = eElement.offsetParent;     // identify first offset parent element  
    while (eParElement != null)
    {                                            // move up through element hierarchy
        nLeftPos += eParElement.offsetLeft;      // appending left offset of each parent
        eParElement = eParElement.offsetParent;  // until no more offset parents exist
        
    }
    return nLeftPos;                             // return the number calculated
}


function DL_GetElementTop(eElement)
{
    if (!eElement && this)
    {
        eElement = this;
    }

    var nTopPos = eElement.offsetTop;
    var eParElement = eElement.offsetParent;
    while (eParElement != null)
    {
        nTopPos += eParElement.offsetTop;
        eParElement = eParElement.offsetParent;
    }
    return nTopPos;
}




function sleep(Amount)
{
    d = new Date() //today's date
    while (1)
    {
        mill=new Date() // Date Now
        diff = mill-d //difference in milliseconds
        if( diff > Amount ) {break;}
    }
}







// this is becoming depriciated.. should use dom_retnode now
function SL_retxmlitem(parent, tagname, index) {
    var result = "";

    result = parent.getElementsByTagName(tagname)[index];
    
    if (result) {
    
        if(result.childNodes.length == 0)
            return '';
        // get text, accounting for possible
        // whitespace (carriage return) text nodes 
        if (result.childNodes.length > 1) {
            return result.childNodes[1].nodeValue;
        } else {
            return result.firstChild.nodeValue;    		
        }
    } else {
        return "n/a";
    }
}
function DOM_retnode(parent, tagname, index) {
    var result = false;

    result = parent.getElementsByTagName(tagname)[index];
    
    if (result) 
        return result;
    else 
        return false;

}
function DOM_retval(parent, tagname, index) {
    var result = "";

    result = parent.getElementsByTagName(tagname)[index];
    
    if (result) {
    
        if(result.childNodes.length == 0)
            return '';
        // get text, accounting for possible
        // whitespace (carriage return) text nodes 
        if (result.childNodes.length > 1) {
            return result.childNodes[1].nodeValue;
        } else {
            return result.firstChild.nodeValue;    		
        }
    } else {
        return false;
    }
}

function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}


function getCookie(name)
{
    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));
}


function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function browserCheck(){ 
  this.ver=navigator.appVersion
  this.agent=navigator.userAgent
  this.dom=document.getElementById?1:0
  this.opera5=this.agent.indexOf("Opera 5")>-1
  this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
  this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
  this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
  this.ie=this.ie4||this.ie5||this.ie6
  this.mac=this.agent.indexOf("Mac")>-1
  this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
  this.ns4=(document.layers && !this.dom)?1:0;
  this.bw=(this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5)
  return this
}
var browsertype = browserCheck();
function getWindowSize()
{
    var ret = new Array();
    if( browsertype.ie )
    {
        ret[0] = document.body.clientWidth;
        ret[1] = document.body.clientHeight; 
    }
    else
    {
        ret[0] = window.outerWidth;
        ret[1] = window.outerHeight;
    }

    return ret;
}

var mousePosX = 0;
var mousePosY = 0;

function mousecapture()
{
    // Detect if the browser is IE or not.
    // If it is not IE, we assume that the browser is NS.
    var mouse_isIE = document.all?true:false
    
    // If NS -- that is, !IE -- then set up for mouse capture
    if (!mouse_isIE) document.captureEvents(Event.MOUSEMOVE)
    
    // Set-up to use getMouseXY function onMouseMove
    document.onmousemove = getMouseXY;
    
    // Temporary variables to hold mouse x-y pos.s

    
    // Main function to retrieve mouse x-y pos.s
    
    function getMouseXY(e) {
        
      if (mouse_isIE) { // grab the x-y pos.s if browser is IE
        mousePosX = event.clientX + document.body.scrollLeft;
        mousePosY = event.clientY + document.body.scrollTop;
      } else {  // grab the x-y pos.s if browser is NS
        mousePosX = e.pageX;
        mousePosY = e.pageY;
      }  
      // catch possible negative values in NS4
      if (mousePosX < 0){mousePosX = 0}
      if (mousePosY < 0){mousePosY = 0}  
      // show the position values in the form named Show
      // in the text fields named MouseX and MouseY
    
      return true
    }
}

function isUndefined(a)
{
    return typeof a == 'undefined';
} 

/*
 * Returns a new XMLHttpRequest object, or false if this browser
 * doesn't support it
 */
function newXMLHttpRequest() {

  var xmlreq = false;

  if (window.XMLHttpRequest) {

    // Create XMLHttpRequest object in non-Microsoft browsers
    xmlreq = new XMLHttpRequest();

  } else if (window.ActiveXObject) {

    // Create XMLHttpRequest via MS ActiveX
    try {
      // Try to create XMLHttpRequest in later versions
      // of Internet Explorer

      xmlreq = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e1) {

      // Failed to create required ActiveXObject

      try {
        // Try version supported by older versions
        // of Internet Explorer

        xmlreq = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (e2) {

        // Unable to create an XMLHttpRequest with ActiveX
      }
    }
  }

  return xmlreq;
}

function xml_getReadyStateHandler(req, responseXmlHandler, useresponseText) {

  // Return an anonymous function that listens to the 
  // XMLHttpRequest instance
  return function () {

    // If the request's status is "complete"
    if (req.readyState == 4) {
      
      // Check that a successful server response was received
      if (req.status == 200) {

        // Pass the XML payload of the response to the 
        // handler function
        if( typeof(useresponseText) == 'undefined')
            responseXmlHandler(req.responseXML);
        else
            responseXmlHandler(req.responseText);

      } else {

        // An HTTP problem has occurred
        responseXmlHandler(false);
      }
    }
  }
}
function adddebug(text)
{
    if( newDiv = document.getElementById('debugdiv') )
    {
        
    }
    else
    {
        newDiv = document.createElement("DIV");
        newDiv.id = "debugdiv"; 
        newDiv.style.display="block";
        newDiv.style.backgroundColor="#ffdddd";
        newDiv.style.width="300px";

        newDiv.style.border='solid 1px black';
        newDiv.style.position='absolute';        
        newDiv.style.fontFamily='tahoma';
        newDiv.style.fontSize='11px';
        document.body.appendChild(newDiv); 
        
    }
    var screenOffsets = getScrollXY();
    var screenSize = getWindowSize();
    newDiv.innerHTML +=text+'<BR>';
    newDiv.style.top = screenOffsets[1];
    newDiv.style.left = screenSize[1] - 300;
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}
function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth, myHeight];

}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
function get_radio_value(frmobj)
{
    var rad_val = false;
    for (var i=0; i < frmobj.length; i++)
    {
        if (frmobj[i].checked)
        {
            var rad_val = frmobj[i].value;
        }
    }
    
    return rad_val;
}
