//==========================================================================
// Core JavaScript 1.0
//==========================================================================
//var UPage = new UPage();
//var UFormat = new UFormat();
//var UDate = new UDate();
//--------------------------------------------------------------------------
function UFormat()
{
    this.LTrim = UFormat.LTrim;
    this.RTrim = UFormat.RTrim;
    this.Trim = UFormat.Trim;
    this.IsDate = UFormat.IsDate;
    this.IsNum = UFormat.IsNum;
}
function UFormat.LTrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) 
   {   
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
      {
         j++;
      }
      s = s.substring(j, i);
   }
   return s;
}
function UFormat.RTrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) 
   {
      var i = s.length - 1;       
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
      {
         i--;
      }
      s = s.substring(0, i+1);
   }
   return s;
}
function UFormat.Trim(str)
{
   return this.RTrim(this.LTrim(str));
}
function UFormat.IsDate(date)
{
    if(date != null)
    {
		var a = date.split("/");
		if(a.length == 3)
		{
			var iy = parseInt(a[0]);
			var im = parseInt(a[1]);
			var id = parseInt(a[2]);
			if(isNaN(iy)==false && isNaN(im)==false && isNaN(id)==false)
			{
				var days = UDate.DaysInMonth(iy,im);
				if(days>0 && id>0 && id<=days)
				{
					return true;
				}
			}
		}
    }
    return false;
} 
function UFormat.IsNum(value)
{
    var exp = /^\d+\D{0}$/;
    return exp.test(value);
}
//--------------------------------------------------------------------------
function UDate()
{
    this.DaysInMonth = UDate.DaysInMonth;
}
function UDate.DaysInMonth(year,month)
{
    var iy = parseInt(year);
    var im = parseInt(month);
    
    if(isNaN(iy)==false && isNaN(im)==false)
    {
        var m = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

		if((year%4==0 && year%100!=0) || year%400==0) m[1] = 29;
		
        if(iy>0 && im>0 && im<=12)
        {
            return m[im-1];
        }
    }
    return 0;
}
//--------------------------------------------------------------------------
function UPage()
{
    this.OleWindow = null;
    this.OpenForm = UPage.OpenForm;
    this.OpenDialog = UPage.OpenDialog;
    this.Resize = UPage.Resize;
    this.Close = UPage.Close;
}
function UPage.OpenForm(url,width,height,other)
{
    var top,left;
    var features = "";
    
    if(width != null && UFormat.Trim(width) != "")
    {
		if(width > screen.availWidth) width = screen.availWidth;
		left = (screen.availWidth - width)/2;
		features += "width="+width+",left="+left+",";
    }
    if(height != null && UFormat.Trim(height) != "")
    {
        if(height > screen.availHeight) height = screen.availHeight;
        top = (screen.availHeight - height)/3;
		features += "height="+height+",top="+top+",";
    }
    if(other != null && UFormat.Trim(other) != "")
    {
        features += other+",";
    }
   
    if(this.OleWindow != null) this.OleWindow.close();
     
    if(features == "")
        this.OleWindow = window.open(url);
    else
        this.OleWindow = window.open(url,'',features);
}
function UPage.OpenDialog(url,width,height,other)
{
    var features = "";
    
    if(width != null && UFormat.Trim(width) != "")
    {
        if(width > screen.availWidth) width = screen.availWidth;
        features +=  "dialogWidth:"+width+"px;";
    }
    if(height != null && UFormat.Trim(height) != "")
    {
        if(height > screen.availHeight) height = screen.availHeight;
        features += "dialogHeight:"+height+"px;";
    }
    if(other != null && UFormat.Trim(other) != "")
    {
        features += other;
    }
    
    window.showModelessDialog(url,window,features);
}
function UPage.Resize(width,height)
{
    var top,left;
    if(width > screen.availWidth) width = screen.availWidth;
    if(height > screen.availHeight) height = screen.availHeight;
    top = (screen.availHeight - height)/3;
    left = (screen.availWidth - width)/2;
    window.moveTo(left,top);
    window.resizeTo(width,height);
}
function UPage.Close(reload)
{
    if(window.opener != null && reload == true)
    {
        window.opener.document.forms(0).__UPAGE_RELOAD.value = "true";
        window.opener.document.forms(0).submit();
    }
    window.close();
}
