String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function TrimString(str)
{
  return str.replace(/^\s*/, "").replace(/\s*$/, "");
}

function getIEVersionNumber() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");
    
    if (MSIEOffset == -1) {
        return 0;
    } else {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
}
var IEVersionNumber = getIEVersionNumber();
var IE = false;
var NN = false;
if (navigator.appName == 'Microsoft Internet Explorer')
 IE = true;
else
 NN = true;
    
var isIE6 = (IE && IEVersionNumber == 6);

function getCenteredWindowFeatures(height, width, status, location, menubar, directories, scrollbars, resizable, toolbar)
{
  var iY = 0, iX = 0, iH = 0, iW = 0, wndPos = top;
  var wndftr = "toolbar="+(toolbar ? "yes" : "no")+
    ",status=" + (status ? "yes" : "no") + 
    ",location=" + (location ? "yes" : "no") +
    ",menubar=" + (menubar ? "yes" : "no") +
    ",directories=" + (directories ? "yes" : "no") +
    ",scrollbars=" + (scrollbars ? "yes" : "no") +
    ",resizable=" + (resizable ? "yes" : "no");
  wndftr+=",height="+height+",width="+width;
  if(document.all){iH=window.screen.availHeight;iW=window.screen.availWidth;}
  else if(wndPos.screen&&wndPos.screen!=""){iH=wndPos.screen.height;iW=wndPos.screen.width;}
  var itmp=Math.round((iH-height)/2);
  if(itmp>0)iY=itmp;
  itmp=Math.round((iW-width)/2);
  if(itmp>0)iX=itmp;
  if(document.all)wndftr+=",top="+iY+",left="+iX;
  else wndftr+=",screenY="+iY+",screenX="+iX;
  return wndftr;
}

function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
            if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
    
    function MM_swapImgRestore() { //v3.0
        var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }
    
    function MM_findObj(n, d) { //v4.01
        var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
            d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
        if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
        for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
        if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    
    function MM_swapImage() { //v3.0
        var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
            if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }
    

function getWndFeatures(height,width,bResizable,bSBars){
                    var iY=0,iX=0,iH=0,iW=0,wndPos=top;
                    var wndftr="status=yes,location=no,menubar=no,directories=no,scrollbars=yes,toolbar="
                    if (bSBars)wndftr+="yes";
                    else wndftr+="no";
                    if(bResizable) wndftr+=",resizable=yes";
                    else wndftr+=",resizable=no";
                    wndftr+=",height="+height+",width="+width;
                    if(document.all){iH=window.screen.availHeight;iW=window.screen.availWidth;}
                    else if(wndPos.screen&&wndPos.screen!=""){iH=wndPos.screen.height;iW=wndPos.screen.width;}
                    var itmp=Math.round((iH-height)/2);
                    if(itmp>0)iY=itmp;
                    itmp=Math.round((iW-width)/2);
                    if(itmp>0)iX=itmp;
                    if(document.all)wndftr+=",top="+iY+",left="+iX;
                    else wndftr+=",screenY="+iY+",screenX="+iX;
                    return wndftr;
                  }

function openPopup(file)
{    
    var szScreenAttributes = getWndFeatures(700,940,false,false);
    var hwnd = window.open(file, "", szScreenAttributes);
    
    if(IE)
    {
        //sender.value = "";
        window.event.returnValue = false;
    }
    else
    {
        e.stopPropagation();
        e.preventDefault();
        return false;
    }
    return false;
}

function parseDate(dateStr)
{
  var mm;
  var dd;
  var yy;
  var date;

  dateStr = dateStr.replace(/^\s+|\s+$/g, '');
  
  if (dateStr.length == 0)
  {
    throw 1;
  }
  
  var re1 = new RegExp("^\\d{2}/\\d{2}/\\d{2}(\\d{2})?$");
  var re2 = new RegExp("^\\d{6}(\\d{2})?$");   
  
  if (re1.test(dateStr))
  {
    mm = dateStr.substring(0, 2);
    dd = dateStr.substring(3, 5);
    yy = dateStr.substring(6, dateStr.length)
  }
  else if (re2.test(dateStr))
  {
    mm = dateStr.substring(0, 2);
    dd = dateStr.substring(2, 4);
    yy = dateStr.substring(4, dateStr.length)
  }
  else
  {
    throw 2;
  }
  
  if (yy.length == 2)
  {              
    yy = ((yy > 30) ? "19" : 20) + yy              
  }
  
  try
  {
    date = new Date(yy,mm-1,dd);
    if (yy != date.getFullYear() || mm - 1 != date.getMonth() || dd != date.getDate())
    {
      throw 3;
    }  
  }
  catch (er)
  {
    throw 3;
  }
  
  return date;
} 

function isEmailValid(email)
{
  var re = new RegExp("^[0-9A-z\\.\\_\\-]+\\@[0-9A-z\\.\\_\\-]+\\.(com|net|org|gov|biz|info|us|cc|bz|tv|coop|edu|nu|ws)$");
  
  return (email && email.length >= 7 && re.test(email));
}

function addLoadEvent(func) 
{
  var oldonload = window.onload;
  if(typeof window.onload != "function")
    window.onload = func;
  else
    window.onload = function() {
      oldonload();
      func();   
    }
}
