function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function clearInput(source, initialValue)
{       //alert(source);
    if(source.value.toUpperCase()==initialValue.toUpperCase())
        source.value='';
        
    return false;    
}

function restoreInput(source, initialValue)
{   
    if(source.value == '')  
        source.value = initialValue;
 
    return false;    
}

function selectdropdownoption(source, optiontext)
{
    for(i=0;i<source.length;i++)
    {
        if(trim(source.options[i].text) == trim(optiontext))
        {
            source.options[i].selected = true;
            break;
        }
    }
    
    return;
}    


function addEvent(obj, type, fn) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}
function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
  } else
    obj.removeEventListener( type, fn, false );
}

function getWebUrl()
{
    var result;
    var currLocation = window.location.href;
    
    currLocation = currLocation.replace('http://','');
    //alert(currLocation);
    
    if(currLocation.toLowerCase().indexOf('localhost')>=0)
    {
        var localhost = currLocation.substr(0,currLocation.indexOf('/')+1);
        var virtualDirectory = currLocation.replace(localhost,'');
        virtualDirectory = virtualDirectory.substr(0,currLocation.indexOf('/')-1);
        result = 'http://' + localhost+virtualDirectory;
    }
    else
    {
        var internethost = currLocation.substr(0,currLocation.indexOf('/'));  
        result = 'http://' + internethost;
    }    
    return result;
    
}



function showdeadcenterdiv(Xwidth,Yheight,divid)
{

    // First, determine how much the visitor has scrolled

    var scrolledX, scrolledY;
    if( self.pageYoffset ) {
    scrolledX = self.pageXoffset;
    scrolledY = self.pageYoffset;
    } else if( document.documentElement && document.documentElement.scrollTop ) {
    scrolledX = document.documentElement.scrollLeft;
    scrolledY = document.documentElement.scrollTop;
    } else if( document.body ) {
    scrolledX = document.body.scrollLeft;
    scrolledY = document.body.scrollTop;
    }

    // Next, determine the coordinates of the center of browser's window

    var centerX, centerY;
    if( self.innerHeight ) {
    centerX = self.innerWidth;
    centerY = self.innerHeight;
    } else if( document.documentElement && document.documentElement.clientHeight ) {
    centerX = document.documentElement.clientWidth;
    centerY = document.documentElement.clientHeight;
    } else if( document.body ) {
    centerX = document.body.clientWidth;
    centerY = document.body.clientHeight;
    }
    // Xwidth is the width of the div, Yheight is the height of the
    // div passed as arguments to the function:
    var leftoffset = scrolledX + ((centerX - Xwidth) / 2)  ;
    var topoffset = scrolledY + ((centerY - Yheight) / 10);
    //alert(leftoffset + 'gfdasf' );
    //alert(topoffset);
    // The initial width and height of the div can be set in the
    // style sheet with display:none; divid is passed as an argument to // the function
    var r=document.getElementById(divid).style;
    r.position='absolute';
    r.top = topoffset  + 'px';
    r.left = leftoffset + 'px';
    r.display = "block";
    //alert("showdeadcenterdiv(600,0," + divid + ")");
    setTimeout("showdeadcenterdiv(600,0,'" + divid + "')",100);
    //setTimeout(showdeadcenterdiv(600,0,divid),100);
    //setTimeout('showdeadcenterdiv(600,0,"PanelDivImage")',100);
    }




function getPageSizeWithScroll()
{
   
    if (window.innerHeight && window.scrollMaxY) {// Firefox
        yWithScroll = window.innerHeight + window.scrollMaxY;
        xWithScroll = window.innerWidth + window.scrollMaxX;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        yWithScroll = document.body.scrollHeight;
        xWithScroll = document.body.scrollWidth;
    } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
        yWithScroll = document.body.offsetHeight;
        xWithScroll = document.body.offsetWidth;
        
        
      /* for window resize */ 
        var divmodalbackground1 =document.getElementById('modelpopup');
        divmodalbackground1.style.width=xWithScroll;
        divmodalbackground1.style.height=yWithScroll;
        divmodalbackground1.style.left=0 + "px";
        setTimeout("getPageSizeWithScroll()",100);
     
    /* ------------------ */
}
    arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
    return arrayPageSizeWithScroll;

}
    
/*alert("height is : " + yWithScroll);
alert("widtht is : " + xWithScroll);*/
    var _windowWidth=0;
    var _windowHeight=0;

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;
    
  }
  
  _windowWidth=myWidth;
  _windowHeight=myHeight;
  
  
  /* for window resize */
   var divmodalbackground1 =document.getElementById('modelpopup');
     divmodalbackground1.style.width=_windowWidth + 'px';
     divmodalbackground1.style.height=_windowHeight + 'px';
     divmodalbackground1.style.position='fixed';    
  setTimeout("getWindowSize()",100);
 /* ------------------ */
 
//  window.alert( 'Width = ' + myWidth );
//  window.alert( 'Height = ' + myHeight );
}
   
/*alert(_windowWidth);
alert(_windowHeight);*/



function FFsetdivmodalbackground1()
{
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for 

 
   getPageSizeWithScroll();
    var divmodalbackground1 =document.getElementById('modelpopup');
    divmodalbackground1.style.width=xWithScroll;
    divmodalbackground1.style.height=yWithScroll;
    divmodalbackground1.style.left=0 + "px";   
    divmodalbackground1.style.position='absolute'; 
      
}
else
{
     getWindowSize();
     
     var divmodalbackground1 =document.getElementById('modelpopup');
     divmodalbackground1.style.width=_windowWidth + 'px';
     divmodalbackground1.style.height=_windowHeight + 'px';
     divmodalbackground1.style.position='absolute';  
}    
       
}

    var setfocuscalled=false;
    function SetControlFocus(FormName)
      {
          bFound = false;
          var myform = document.forms[(FormName === undefined || FormName == '') ? 0 : FormName];
          
          if(myform)
          {
                  for(i=0; i < myform.length; i++)
                  {
                      if (myform[i].type != "hidden")
                      {
                        if (myform[i].disabled != true && myform[i].readOnly != true)
                        {
                            myform[i].focus();
                            var bFound = true;
                        }
                      }
                      if (bFound == true)
                        break;
                  }
                  
                  setfocuscalled = true;
          }
      }

