package org.zhios.website.admin.pagelet;

import org.w3c.dom.Document;
import org.zhios.website.admin.model.HtmlOpt;
import org.zhios.website.admin.model.Strings;

public class FramePL extends BasePageLet implements PageLetObj {

	public FramePL(String divid) {
		super(divid);
		// TODO Auto-generated constructor stub
	}
	
	public FramePL(String divid, String okfunc, String cancelfunc, String outterhtml) {
		super(divid,okfunc,cancelfunc,outterhtml);
		// TODO Auto-generated constructor stub
	}
	
	public void setFillStr(){
		//Get previous value of every fills.
		String width="",height="",divfloat="",innerhtml="";
		if(!OuterStr.isEmpty()){
			divfloat=HtmlOpt.readFirstTagStyleAttrValue(OuterStr,"div","float");
			if(divfloat.isEmpty()) divfloat="center";
			
			width=HtmlOpt.readFirstTagStyleAttrValue(OuterStr,"div","width");
			if(!width.isEmpty()){
				int px=width.indexOf("px");
				if(px>0) width=width.substring(0,px);
			}
			
			height=HtmlOpt.readFirstTagStyleAttrValue(OuterStr,"div","height");
			if(!height.isEmpty()){
				int px=height.indexOf("px");
				if(px>0) height=height.substring(0,px);
			}
			
			innerhtml=HtmlOpt.readTaginnerHTML(OuterStr,DivID);
		}
		
		//Set every fills.
		setFill("text",Strings.PLWidth,"width",width,"",true);
		setFill("text",Strings.PLHeight,"height",height,"",true);
		setFill("select",Strings.PLFloat,"float",divfloat,"left,center,right",true);
		setFill("textareahidden","","innerhtml",innerhtml,"",false);
	}

	public void setViewStr(Document doc){
		String divfloat=doc.getElementsByTagName("float").item(0).getTextContent();
		String floatstr;
		if(divfloat.equals("center")) floatstr="margin:auto";
		else floatstr="float:"+divfloat;
		String width=doc.getElementsByTagName("width").item(0).getTextContent();
		String height=doc.getElementsByTagName("height").item(0).getTextContent();
		String innerhtml=doc.getElementsByTagName("innerhtml").item(0).getTextContent();
		
		ViewStr="<div id='"+DivID+"' tmstyle='frame' style='"+floatstr+";width:"+width+"px;height:"+height+"px'>"+innerhtml+"</div>";
	}
	
}
