function $(id_AS_String){
  var id = id_AS_String;
  var el = document.getElementById(id);
  if(!el)return false;
  return el;
};

var Email = {
  isValid : function(email){
    var emailCheck = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    return emailCheck.test(email);
  }
};


var Window = {
  maximize : function(){
    window.moveTo(0,0);
    window.resizeTo(screen.availWidth, screen.availHeight);
  },
  
  scrollBars : {
    hide : function(){
      document.body.style.overflow = 'hidden';
    },
    
    show : function(){
      document.body.style.overflow = 'auto';
    }
  },
  
  scrollTo : function(top, left){
	  var autoScrollTop, autoScrollLeft, delay = 30;
	  if(!top || isNaN(top) || top<0)top = 0;
	  if(!left || isNaN(left) || left<0)left = 0;
		
		/*function autoScroll(){
			Debug.print('top='+top);
			Debug.print('document.body.scrollTop='+document.body.scrollTop, 1);
			if((document.body.scrollTop+delay)>=(top-delay)){
				clearTimeout(timer);
				document.body.scrollTop = (top-delay);
			}
			else{
				var scrollAmount = Math.floor((top-document.body.scrollTop)/delay);
				document.body.scrollTop += scrollAmount;
				timer = setTimeout(autoScroll, 1);
			};
		};
		
		timer = setTimeout(autoScroll, 1);
	  
	  var timer = function(){
	  	var scrollAmount = Math.floor((top-document.body.scrollTop)/delay);
	  	document.body.scrollTop += scrollAmount;
	  	if(document.body.scrollTop>=top)document.body.scrollTop = top;
			else timer();
	  };
		
	  timer();*/
		autoScrollUp = function(){
			var scrollAmount = Math.ceil((document.body.scrollTop-top)/delay);
			document.body.scrollTop -= scrollAmount;
			if(document.body.scrollTop<top)document.body.scrollTop = top;
			else autoScrollUp();
		};
		
		autoScrollDown = function(){
			var scrollAmount = Math.floor(((top+delay)-document.body.scrollTop)/delay);
			document.body.scrollTop += scrollAmount;
			if(document.body.scrollTop>=(top+delay))document.body.scrollTop = top;
			else autoScrollDown();
		};
		
		autoScrollLeft = function(){
			
		};
		
		autoScrollRight = function(){
			
		};
		
		if(top>document.body.scrollTop)autoScrollDown();
		else if(top<document.body.scrollTop)autoScrollUp();
		
		if(left>document.body.scrollLeft)autoScrollRight();
		else if(left<document.body.scrollTop)autoScrollLeft();
  }
};

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);
  },
  
  checkAll : function(chkbox, _checked){
    if((typeof(chkbox)).toLowerCase()=='string')chkbox = document.getElementsByName(chkbox);
    
    for(var i=0, l=chkbox.length; i<l; (chkbox[i++].checked = _checked)){};
  },
  
  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
  
  setFocus : function(el){
    if(!el)return;
    if((typeof(el)).toUpperCase()=='STRING')el = document.getElementById(el);
    
    el.focus();
  },//setFocus 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
  
  isDescendant : function(childObject, parentObject){
    var el = childObject.parentNode;
    var p = parentObject;
		
		if(!el || !p)return false;
    
    while(el != document.body){
      if(el==p)return true;
      else el = el.parentNode;
    };
    
    return false;
  },
  
  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

  getCoords : function(el){
    var coords={exactLeft:0, exactTop:0, width:el.offsetWidth, height:el.offsetHeight, left:el.offsetLeft, top:el.offsetTop};
    var tn;
    while(el){
      tn=el.tagName.toUpperCase();
      
      coords.exactLeft+=(el.offsetLeft-(tn=="DIV"&&el.scrollLeft?el.scrollLeft:0));
      coords.exactTop+=(el.offsetTop-(tn=="DIV"&&el.scrollTop?el.scrollTop:0));
      
      if (tn=="BODY") break;
      el=el.offsetParent;
    };
    return coords;
  },
  
  cursor : function(ev){
    //var ev = window.event || e;
    return {top:(ev.clientY), left:(ev.clientX)};
    //return {top:ev.pageX, left:ev.pageY};
  },

  removeElement : function(_el){
    if(!_el)return;
    
    var el = _el;
    if((typeof(_el)).toLowerCase()=='string')el = document.getElementById(_el);
    
    if(!el.parentNode)return;
    
    if(el)el.parentNode.removeChild(el);
    
  },//removeElement ends here
  
  removeClass : function(_el){
    if(!_el)return;
    
    var el = _el;
    if((typeof(_el)).toLowerCase()=='string')el = document.getElementById(_el);
    
    el.removeAttribute('class');
    el.removeAttribute('className');
  },
  
  Disable : function(el_AS_Object, color_AS_String, show_PreloaderGiF){
    var self = this; //misc;
    var alpha = color_AS_String?(show_PreloaderGiF?60 :60) :0;
    var el = el_AS_Object;
    var p = self.getXY(el);
    var u = (el.id+'_screen');
    var doc = document.body;
    
    if(show_PreloaderGiF){
      var tbl = new Table(1,1);
      with(tbl){
        width = '100%';
        style.height = '100%';
        border = 0;
        
        with(rows[0].cells[0]){
          vAlign = 'middle';
          align = 'center';
		  cellPadding = 2;
		  cellSpacing = 0;
          innerHTML = '<table border="0" cellpadding="3" cellspacing="0" bgcolor="#DDF4FF" style="border:1px solid #3399CC"><tr><td height="4" colspan="4" align="center"></td></tr><tr><td align="center">&nbsp;</td><td align="center"><img src="'+ pathLib +'/imgs/srch-loading.gif" width="20" height="20" /></td><td nowrap="nowrap">Please Wait...</td><td nowrap="nowrap">&nbsp;</td></tr><tr><td height="4" colspan="4" align="center"></td></tr></table>';
        };
      };
    };
    
    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;
        //background = 'url(\''+ pathLib +'/imgs/alphaBg.gif' +'\')';
        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";
      };
      if(show_PreloaderGiF)appendChild(tbl);
      
    };
    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;
  },
  
  linkBar : function(arr_AS_Array, func_AS_Function){
    var links = arr_AS_Array;
    var lenLinks = links.length;
    var _links = new Table((lenLinks*2)+1, 4);
    
    with(_links){
      cellSpacing = '0';
      cellPadding = '0';
      border = '0';
      //style.border = '#cccccc 1px solid';
      width = '100%';
      
      with(rows[0]){
        with(cells[0]){
          height = '7';
        };
        
        with(cells[1]){
          height = '7';
        };
        
        with(cells[2]){
          height = '7';
        };
        
        with(cells[3]){
          height = '7';
        };
      };
      
      row = 1;
      for(var i=0; i<lenLinks; i++){
        var obj = links[i];
        obj.isActive = false;
        with(rows[row]){
          with(cells[0]){
            width = '4';
            innerHTML = '&nbsp;';
          };
          
          with(cells[1]){
            width = '27';
            if(obj.icon){
              align = 'middle';        
              var img = new Image();
              with(img){
                src = obj.icon;
              };
              appendChild(img);
            }else innerHTML = '&nbsp;';
          };
          
          with(cells[2]){
            width = '4';
            innerHTML = '&nbsp;';
          };
          
          with(cells[3]){
            //width = '100%';
            noWrap = 'noWrap';
            var anchor = document.createElement('A');
            with(anchor){
              href = 'javascript:void(0)';
              id = 'link_'+i;
              innerHTML = obj.text;
            };
            
            anchor.onclick = function(){
              var id = this.id;
              id = id.replace('link_', '');
              var _obj = links[id];
              func_AS_Function(_obj, id);
            };
            
            anchor.onfocus = function(){
              this.blur();
            };
            
            appendChild(anchor);
          }
        }
        
        with(rows[row+1]){
          cells[0].height = '7';
          cells[1].height = '7';
          cells[2].height = '7';
          cells[3].height = '7';
        };
        
        row+=2;
      };
    };
    
    return _links;
  },
  
  removeAttribute : function(obj, attribute){
    if(_isIE)obj.removeAttribute(attribute);
		else obj.removeProperty(attribute);
  },
  
  formQueryString : function(frm, unified){
    if(!frm || !frm.elements.length)return false;
    var qs = ((unified?'arr[]':frm.elements[0].name) +'='+ frm.elements[0].value);
    
    for(var i=1, l=frm.elements.length; i<l; i++){
      var el = frm.elements[i];
			var tagName = (el.tagName).toUpperCase();
			var type = (el.type).toUpperCase();
			var nm = (unified?'arr[]' :el.name);
      
			if (tagName == "INPUT"){
				if (type == "TEXT")qs += ('&'+ nm +'='+ el.value);
        else if(type == "CHECKBOX")qs += ('&'+ nm +'='+ (el.checked?el.value :''));
				else if (type == "RADIO" &&  el.checked)qs += ('&'+ nm +'='+ el.value);
			}
			else if (tagName == "TEXTAREA")qs += ('&'+ nm +'='+ el.value);
			else if (tagName == "SELECT")qs += ('&'+ nm +'='+ el.options[el.selectedIndex].value);
		};
    
    return qs;
  }
};

var animation = {
  SlideDown : function(el_AS_Object, num_AS_MaxHeight, num_AS_Speed, onComplete_AS_Function){
    var el = el_AS_Object;
    var maxH = num_AS_MaxHeight;
    var speed = num_AS_Speed;
    var overflow = el.style.overflow || '';
    
    with(el.style){
      overflow = 'hidden';
      height = '1px';
    };
    
    var rep = function(){
      var h = el.offsetHeight;
      h+=speed;
      
      if(h>=maxH){
        clearInterval(timer);
        if(overflow)el.style.overflow = overflow;
        el.style.height = maxH +'px';
        if(onComplete_AS_Function)onComplete_AS_Function();
      }
      else el.style.height = h +'px';
    };
    
    var timer = setInterval(rep, 10);
  },
  
  SlideUp : function(el_AS_Object, num_AS_MinHeight, num_AS_Speed, onComplete_AS_Function){
    var el = el_AS_Object;
    var minH = num_AS_MinHeight;
    var speed = num_AS_Speed;
    var overflow = el.style.overflow || '';
    
    with(el.style){
      overflow = 'hidden';
    };
    
    var h = el.offsetHeight;
    var _h = h;
    
    var rep = function(){
      h-=speed;
      
      if(h<=minH){
        clearInterval(timer);
        if(overflow)el.style.overflow = overflow;
        el.style.height = _h +'px';
        if(onComplete_AS_Function)onComplete_AS_Function();
      }
      else el.style.height = h +'px';
    };
    
    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);
  };
};
