package com.csc.library.components;


public class Textarea extends MyTag {

	private static final long serialVersionUID = 1L;
	private String lines = "";
	private String sizechar = "";
	private String wrap = "";
	private String tagInput = "";
	private String hspace = "";

	public Textarea() {
		this.type = "textarea";
	}

	public Textarea(ComponentManager cm) {
		super(cm);
		
		if(cm.getProperty("size").equals("")) {
	    	this.setSize(cm.getStringWidth());
		} else {
	    	this.setSize(cm.getProperty("size"));
		}
		
		this.setSizeChar(cm.getProperty("sizechar"));
		this.setLines(cm.getProperty("lines"));
		this.setWrap(cm.getProperty("wrap"));
		
		if(this.onKeyUp.equals("")){
    		this.setonKeyup("chkLimitTextArea(this,"+cm.getStringWidth()+");");	    		
    	}
		if(cm.getProperty("isvalid").equals("")||cm.getProperty("isvalid").equals("true")){
			this.onBlur = "trimValue(this);"+this.onBlur;
			this.onKeyPress="chkSpecialStr(event);"+this.onKeyPress;
		}
	    if((cm.getLang() == 'E')||(cm.getLang()== 'e' )){
	    	this.onKeyPress = "chkNotThaiChaOnly(event);" +this.onKeyPress;
	    }
	    
    	this.ini();
	}

	public void setLines(String lines) {
		this.lines = lines;
	}

	public void setSizeChar(String sizechar) {
		this.sizechar = sizechar;
	}

	public void setWrap(String wrap) {
		this.wrap = wrap;
	}

	public void ini() {
		String label2;
		label2 = "";

		tagInput =
			"<TEXTAREA NAME='"
				+ this.name
				+ "'"
				+ " COLS='"
				+ this.sizechar
				+ "'"
				+ " ROWS='"
				+ this.lines
				+ "'"
				+ " WRAP='"
				+ this.wrap
				+ "'"
				+ " onClick=\""
				+ onClick
				+ "\""
				+ " onChange=\""
				+ onChange
				+ "\""
				+ " onMouseOver=\""
				+ this.onMouseOver
				+ "\""
				+ " onMouseOut=\""
				+ this.onMouseOut
				+ "\""
				+ " onKeyPress=\""
				+ this.onKeyPress
				+ "\""
				+ " onKeyUp=\""
                + this.onKeyUp+"sysIsEdit();"
                + "\""
                + " onBlur=\""+this.onBlur+"\""
                +" onFocus=\""+this.onFocus+"\""                
				+ ((this.disable.equalsIgnoreCase("true")) ? " DISABLED" : "")
				+ ((this.readonly.equalsIgnoreCase("true")) ? " READONLY" : "")
				+" alt=\""+((com!=null)?com.getAlt():"")+"\""
				+" >" + this.value + "</TEXTAREA>" + label2;
	}

	public String process() {
		this.ini();
		if ((this.point != null) && (this.point.equalsIgnoreCase("l"))) {
			return this.tagInput + this.hspace + this.label;
		} else {
			return this.label + this.hspace + this.tagInput;
		}
	}

	public void setSpace(int space) {
		for (int i = 0; i < space; i++) {
			hspace = hspace + "&nbsp;";
		}
	}

	public String getInput() {
		return this.tagInput;
	}

	private void setSize(String size) {
		this.sizechar = size;
	}
	
}