window.oBorderStyleList=false;
function BorderStyleList() {
    this.styles=new Array();
    oBorderStyleList=this;
    this.setted=new Array();
}
BorderStyleList.prototype.add=function(sname,stemp) {
    this.styles.push(new BorderStyle(sname,stemp,this));
}
BorderStyleList.prototype.set=function(sname,onimg) {
    for(var i=0;i<this.styles.length;i++) {
        if(this.styles[i].name==sname) {
            k=this.setted.push(new SettedStyle(onimg,this.styles[i].set(onimg),this.styles[i]));
            return this.setted[k];
        }
    }
    return "noMatch";
}
BorderStyleList.prototype.setOnAll=function(domelem) {
    this.domelem=domelem;
    //testReady
    for(var i=0;i<this.styles.length;i++) {
        if(!this.styles[i].ready) {
            this.toFast=true;
            return this.checkReady();
        }
    }
    arrImg=domelem.getElementsByTagName("img");
    if(arrImg.length>0) {
        arrImg=new Array();
        arr=domelem.getElementsByTagName("div");
        for(var i=0;i<arr.length;i++) {
            arrImg.push(arr[i]);
        }
        arr=domelem.getElementsByTagName("img");
        for(var i=0;i<arr.length;i++) {
            arrImg.push(arr[i]);
        }
    }
    else arrImg=domelem.getElementsByTagName("div");
    for(var i=0;i<arrImg.length;i++) {
        for(var j=0;j<this.styles.length;j++) {
            if(arrImg[i].className==this.styles[j].name) {
                this.setted.push(new SettedStyle(arrImg[i],this.styles[j].set(arrImg[i]),this.styles[j]));
            }
        }
    }
}
BorderStyleList.prototype.checkReady=function() {
    if(this.toFast) {
        for(var i=0;i<this.styles.length;i++) {
            if(!this.styles[i].ready) {
                this.toFast=true;
           }
        }
        setTimeout("window.oBorderStyleList.setOnAll(window.oBorderStyleList.domelem)",500);
    }
}


function BorderStyle(sname,stemp,olist) {
    this.name=sname;
    this.parent=olist;
    rpc(stemp,function(req,bs) {
        bs.template=req.responseText;
        bs.ready=true;
        //bs.parent.checkReady();
    },false,this);
}
BorderStyle.prototype.set=function(onelem) {
    onelem.style.visibility="visible";
    onelem.style.margin="0";
    odiv=onelem.ownerDocument.createElement("div");
    nelem=onelem.ownerDocument.createElement(onelem.tagName);

    if(onelem.src) nelem.src=onelem.src;
    if(onelem.innerHTML) nelem.innerHTML=onelem.innerHTML;

    nelem.style.height=(onelem.style.height)?onelem.style.height:onelem.offsetHeight;
    nelem.style.width=(onelem.style.width)?onelem.style.width:onelem.offsetWidth;
    nelem.style.backgroundColor=onelem.style.backgroundColor;
    nelem.style.verticalAlign=onelem.style.verticalAlign;
    nelem.style.fontFamily=onelem.style.fontFamily;
    nelem.style.fontSize=onelem.style.fontSize;
    nelem.style.fontWeight=onelem.style.fontWeight;
    nelem.style.color=onelem.style.color;
    nelem.style.textAlign=onelem.style.textAlign;

    nelem.onmouseover=onelem.onmouseover;
    nelem.onclick=onelem.onclick;
    nelem.onmouseout=onelem.onmouseout;
    nelem.style.border=onelem.style.border;
    nelem.style.cursor=onelem.style.cursor;

    odiv.style.position=onelem.style.position;
    odiv.style.top=onelem.offsetTop;
    odiv.style.left=onelem.offsetLeft;
    if(!isIE) odiv.style.cssFloat=onelem.style.cssFloat;
    else odiv.style.styleFloat=onelem.style.styleFloat;

    odiv.innerHTML=this.template.replace("#element#","<img id='newAdded"+onelem.className+"'/>");
    onelem.parentNode.replaceChild(odiv,onelem);

    relem=odiv.ownerDocument.getElementById("newAdded"+onelem.className);
    elemcont=relem.parentNode;
    elemcont.replaceChild(nelem,relem);
}

function SettedStyle(domElem,funcReturn,borderStyle) {
    this.domElem=domElem;
    this.funcReturn=funcReturn;
    this.borderStyle=borderStyle;
}
