﻿var YRN;
if(!YRN){
    YRN={};
}
YRN.Element=function(ele){
        this.Init(ele);
}
//Properties Declareation
YRN.Element.prototype.element=null;;
YRN.Element.prototype.className=null;

//Method declara
YRN.Element.prototype.$=FncGetElement;
YRN.Element.prototype.SetElement=FncSetElement;
YRN.Element.prototype.Init=FncInit;
YRN.Element.prototype.GetLeft=FncGetLeft;
YRN.Element.prototype.GetWidth=FncGetWidth;
YRN.Element.prototype.GetRight=FncGetRight;
YRN.Element.prototype.GetTop=FncGetTop;
YRN.Element.prototype.GetBottom=FncGetBottom;
YRN.Element.prototype.GetHeight=FncGetHeight;
YRN.Element.prototype.GetProperty=FncGetProperty;
YRN.Element.prototype.SetProperty=FncSetProperty;
YRN.Element.prototype.SetProperties=FncSetProperties;

YRN.Element.prototype.HasClass=FncHasClass;
YRN.Element.prototype.SetClass=FncSetClass;
YRN.Element.prototype.RemoveClass=FncRemoveClass;
YRN.Element.prototype.AddEventListener=FncAddEventListener;
YRN.Element.prototype.CreateIFrame=FncCreateIFrame; //To display over other form controls or ActiveX control
YRN.Element.prototype.RemoveIFrame=FncRemoveIFrame;
YRN.Element.prototype.SetAlpha=FncSetAlpha;

YRN.Element.prototype.GetChildren=FncGetChildren;
YRN.Element.prototype.SetToTarget=FncSetToTarget;


function FncGetElement(elementId){
    if (elementId && typeof elementId == "string") return document.getElementById(elementId);
	return elementId;
}

function FncInit(ele){        
    this.element=ele;
}
    
function FncGetLeft(){
    var x = 0;
    var elm=this.$(this.element);
    while (elm != null) {
        x+= elm.offsetLeft;
        elm = elm.offsetParent;
    }
    return parseInt(x);
}

function FncSetElement(ele){
    this.element=ele;
}
    
function FncGetWidth(){
    var elm=this.$(this.element);        
    elm.innerHTML="Fdasf";
    return parseInt(elm.offsetWidth);
}

function FncGetRight(){
    return this.GetLeft() + this.GetWidth();
}    
    
 function FncGetTop() {
    var y = 0;
    var elm=this.$(this.element);
    while (elm != null) {
        y+= elm.offsetTop;
        elm = elm.offsetParent;
    }
    return parseInt(y);
}
function FncGetHeight(){
    var elm=this.$(this.element);
    return parseInt(elm.offsetHeight);
}    

function FncGetBottom(){
    return this.GetTop() + this.GetHeight();
}    
    
function FncGetProperty(property){
    var elm = this.$(this.element);                
    if(elm.style){
        elm = elm.style;
        if(elm[property]){
          return elm[property];
        } else {
          return null;
        }
    }
    return null;     
}
    
function FncSetProperty(propertyName, value){  
   	var elm=this.$(this.element);         
  	if((elm != null) && (elm.style != null)){
        elm = elm.style;
        elm[propertyName] = value;            
    }
}


function FncHasClass(className){
    var ele=this.$(this.element);
    if (!ele || !className || !ele.className || ele.className.search(new RegExp("\\b" + className + "\\b")) == -1) return false;	
	return true;
}
function FncSetClass(className){
    var ele=this.$(this.element);
    if (!ele || !className || this.HasClass(ele, className)) return;
	ele.className += (ele.className ? " " : "") + className;
	this.className=className;
}
function FncRemoveClass(){
    var ele=this.$(this.element);
    if (!ele || !this.className || !this.HasClass(this.className))return;
	ele.className = ele.className.replace(new RegExp("\\s*\\b" + this.className + "\\b", "g"), "");
}


function FncAddEventListener(eventType, handler){
    var ele=this.$(this.element);
    try{
        if(ele.addEventListener) ele.addEventListener(eventType, handler, false);
        else if (ele.attachEvent) ele.attachEvent("on"+eventType,handler);
    }catch(e){}
}


function FncCreateIFrame(){
    var ele=this.$(this.element);
    var layer=document.createElement("iframe");
    layer.tabIndex="-1";
    layer.src="javascript:false;";    
    layer.style.position="absolute";
    layer.style.left=this.GetLeft()+"px";
    layer.style.top=this.GetTop()+"px";
    layer.style.width=this.GetWidth()+"px";
    layer.style.height=this.GetHeight()+"px";      
}

function FncRemoveIFrame(){
    var ele=this.$(this.element);
    var layers= ele.parentNode.getElementsByTagName("iframe");
    if(layers.length>0)layers[0].parentNode.removeChild(layers[0]);
}

function FncGetChildren(){
    var ele=this.$(this.element);
    var children=new Array();
    var child=ele.firstChild;
    while(child){
        if(child.nodeType==1)children.push(child);
        child=child.nextSibling;
    }
    return children;
}

function FncSetToTarget(ele){
    this.element = this.$(ele);
}

function FncSetAlpha(opacity){
	var ele=this.$(this.element);
	ele.style.filter="alpha(opacity="+ opacity +")";
	ele.style.mozOpacity=opacity/100;
	ele.style.opacity=opacity/100;
}

function FncSetProperties(objProperties){
	var ele=this.$(this.element);
	for(var property in objProperties){
		this.SetProperty(property, objProperties[property]);
	}
}