// JavaScript Document
/*include files
  newElement.js
  browser-check.js
*/

var misc = {
  id: new Date().getTime(),
  noTextSelection : function(_el){// prevent IE text selection while dragging!!!+
    var el = _el || document.body;
    el.ondrag = function () { return false; };
    el.onselectstart = function () { return false; };
  },//noTextSelection ends here
  
  newId : function(el_AS_String){
    var id = new Date().getTime();
    while(this.id == id){
      id = new Date().getTime();
    }
    this.id = id;
    return (el_AS_String +'_'+ id);
  },
  
  transparency : function(){
    var scr = new Div();
    var alpha = 30;
    
    with(scr.style){
      position = 'absolute';
      top = 0;
      left = 0;
      width = '100%';
      height = '100%';
      background = 'gray';
      filter = 'progid:DXImageTransform.Microsoft.alpha(opacity=\''+ alpha +'\')';
      opacity = alpha/100;
    }
    
    return scr;
  },
  
  getInnerText : function(el_AS_Object){
    var el = el_AS_Object;
    return (_isIE?el.innerText :el.textContent);
  },//getCellText ends here
  
  setInnerText : function(el_AS_Object, text_AS_String){
    var el = el_AS_Object;
    var val = text_AS_String
    if(_isIE)el.innerText = val;
    else el.textContent = val;
  },//setInnerText ends here
  
  getParentofType : function(el_AS_Object, tag_AS_String){
      var el = el_AS_Object.parentNode;
      var tag = tag_AS_String.toLowerCase();
      while((el.tagName).toLowerCase()!=tag && (el.tagName).toLowerCase()!="body"){
         el = el.parentNode;
      };
      return el;
  },//getParentofType ends here
  
  getXY : function(el_AS_Object){
    var el=el_AS_Object;
    var p=[0,0];
    var tn;
    while(el){
      tn=el.tagName.toUpperCase();
      p[0]+=el.offsetLeft-(tn=="DIV"&&el.scrollLeft?el.scrollLeft:0);
      p[1]+=el.offsetTop-(tn=="DIV"&&el.scrollTop?el.scrollTop:0);
      if (tn=="BODY") break;
      el=el.offsetParent;
    }
    return p;
  },//getXY ends here

  removeElement : function(_el){
    var el = _el;
    if((typeof(_el)).toLowerCase()=='string')el = document.getElementById(_el);
    if(el)el.parentNode.removeChild(el);
    
  },//removeElement ends here
  
  Disable : function(el_AS_Object, color_AS_String){
    var self = this; //misc;
    var alpha = 50;
    var el = el_AS_Object;
    var p = self.getXY(el);
    var u = (el.id+'_screen');
    var doc = document.body;
    
    var alphaScreen = document.createElement('DIV');
    alphaScreen.id = u;
    with(alphaScreen){
      with(style){
        position = 'absolute';
        background = color_AS_String || 'Gray';
        filter = 'progid:DXImageTransform.Microsoft.alpha(opacity=\''+ alpha +'\')';
        opacity = alpha/100;
        left = p[0] +'px';
        top = p[1] +'px';
        //Debug.print((el.tagName).toLowerCase()=='body');
        width = (((el.tagName).toLowerCase()=='body')?doc.clientWidth :el.offsetWidth) +'px';
        height = (((el.tagName).toLowerCase()=='body')?((doc.offsetHeight>doc.scrollHeight)?doc.offsetHeight :doc.scrollHeight) :el.offsetHeight) +'px';
        cursor = 'default';
        display = "block";
        visibility = "visible";
      }
    }
    doc.appendChild(alphaScreen);
    return alphaScreen;
  },//Disable ends here
  
  Enable : function(el_AS_Object){
    var self = this; //misc
    var el = el_AS_Object;
    
    if((typeof(el)).toLowerCase()!='object')return;
    
    var alphaScreenId = (el.id+'_screen');
    self.removeElement(alphaScreenId);
  },//Enable ends here
  
  Resize : function(return_Function, el_AS_Object, ev_Object, minHeight_AS_Number, minWidth_AS_Number){
    var self = this; //misc;
    var ev=ev_Object, el=el_AS_Object, minH=minHeight_AS_Number, minW=minWidth_AS_Number;
    var outLine=new Div('outLine_'+ new Date().getTime() +'_'), p=self.getXY(el), extra=10;
    
    with(outLine){
      with(style){
        var alpha = 50;
        border = '1px dashed #000000';
        position = 'absolute';
        background = 'Gray';
        filter = 'progid:DXImageTransform.Microsoft.alpha(opacity=\''+ alpha +'\')';
        opacity = alpha/100;
        cursor = 'SE-resize';
        //className = 'outLine';
        title = 'Click to Apply this Size';
        left = p[0] +'px';
        top = p[1] +'px';
        width = el.offsetWidth +'px';
        height = el.offsetHeight +'px';
      }
    }
    
    //outLine.onclick = function(e){
    var func1 = document.onmouseup;
    var func2 = document.onmousemove;
    document.onmouseup = function(e){
      document.onmousemove = '';
      return_Function({w:outLine.offsetWidth, h:outLine.offsetHeight});
      self.removeElement(outLine);
      document.onmouseup = func1;
      document.onmousemove = func2;
    }
    
    document.onmousemove = function(e){
      var t = document.body.scrollTop, l = document.body.scrollLeft;
      var ev=e || window.event, w=((ev.clientX+extra)-p[0])+l, h=((ev.clientY+extra)-p[1])+t;
      
      if(w>minW)outLine.style.width = w +'px';
      if(h>minH)outLine.style.height = h +'px';
    }
    
    document.body.appendChild(outLine);
  },//Resize ends here
  
  startDrag : function(obj, bool_AS_Screen, leftOverLay, topOverLay, func_onStopDrag){
    var funcMove = document.onmousemove, funcUp = document.onmouseup;
    var l = (leftOverLay?leftOverLay :0), t = (topOverLay?topOverLay :0);
    var scr = new Div();
    
    if(bool_AS_Screen){
      with(scr.style){
        position = 'absolute';
        top = 0;
        left = 0;
        width = '100%';
        height = '100%';
        background = 'gray';
        filter = 'progid:DXImageTransform.Microsoft.alpha(opacity=\'1\')';
        opacity = .01;
      }
      
      document.body.insertBefore(scr, obj);
    }
    document.onmousemove = function(e){
      var ev = e || window.event;
      var x = ev.clientX;
      var y = ev.clientY;
      var p = misc.getXY(obj);
      
      with(obj.style){
        if(leftOverLay != -1)left = x-l;
        if(topOverLay != -1)top = y-t;
      }
    }
    
    document.onmouseup = function(e){
      if(bool_AS_Screen)misc.removeElement(scr);
      document.onmousemove = funcMove;
      document.onmouseup = funcUp;
      if(func_onStopDrag)func_onStopDrag();
    }
  },
  
  getElem : function(id_AS_String){
  	var id = id_AS_String;
	var el = document.getElementById(id);
	if(!el)return false;
	return el;
  }
};

var animation = {
  SlideDown : function(el_AS_Object, num_AS_MaxHeight, num_AS_Speed){
    var el = el_AS_Object;
    var maxH = num_AS_MaxHeight;
    var speed = num_AS_Speed;
    var overflow = el.style.overflow;
    
    with(el.style){
      height = '1px';
      overflow = 'hidden';
    }
    
    var rep = function(){
      var h = el.offsetHeight;
      h+=speed;
      el.style.height = h +'px';
      
      if(h>=maxH){
        clearInterval(timer);
        if(overflow)el.style.overflow = overflow;
      }
    }
    
    var timer = setInterval(rep, 10);
  }
};
var fullForm = {
  Align : function(v){
    switch(v.toUpperCase()){
      case 'L':
        v = 'left';
      break;
      case 'R':
        v = 'right';
      break;
      case 'J':
        v = 'justify';
      break;
      case 'C':
        v = 'center';
      break;
      case 'T':
        v = 'top';
      break;
      case 'B':
        v = 'bottom';
      break;
      case 'M':
        v = 'middle';
      break;
    };
    return v;
  }
};

function ScrollIframe(){
  var timerId, _inc = 1;
  
  var startScroll = function(frm, speed, dir, inc){
    if (timerId) clearTimeout(timerId);
    
    if (window.frames[frm]) {
      if (dir=="V") window.frames[frm].scrollBy(0, inc); //for vertical scroll
      else window.frames[frm].scrollBy(inc, 0); //for horizontal scroll
      timerId = setTimeout(function(){startScroll(frm, speed, dir, inc)}, speed);
    }
  };
  
  this.stopScroll = function(){
    if(timerId)clearTimeout(timerId);
  };
  
  this.Down = function(frm,speed){
    startScroll(frm, speed, 'V', _inc);
  };
  
  this.Up = function(frm,speed){
    startScroll(frm, speed, 'V', _inc*-1);
  };
  
  this.Left = function(frm,speed){
    startScroll(frm, speed, 'H', _inc*-1);
  };
  
  this.Right = function(frm,speed){
    startScroll(frm, speed, 'H', _inc);
  };
}

function defaultDate(_dt,_mn,_yr,_hr,_min){

	var myDate = new Date();
	
	var dt = myDate.getDate();
	var mn = myDate.getMonth()+1;
	var yr = myDate.getFullYear();
	var hr = myDate.getHours();
	var Min = myDate.getMinutes();
	
	if(hr<10)hr = '0'+hr;
	
	Min = (Min%5)?(parseInt(Min/5)*5) :Min;
	
	if(!Min || Min<5)Min = 0;
	
	if(Min<10)Min = '0'+Min;
	
	(document.getElementById(_dt)).value = dt;
	(document.getElementById(_mn)).value = mn;
	(document.getElementById(_yr)).value = yr;
	(document.getElementById(_hr)).value = hr;
	(document.getElementById(_min)).value = Min;
}