
// HTMLオブジェクトを作成
var CObject = function(id){
	
	this.dom = null;
	
	this.x = null;
	this.y = null;
	this.w = null;
	this.h = null;
	
	this.clarity = null;
	
	this.tmr = null;
	this.accl = null;
	
	if(id){
		this.dom = document.getElementById(id)? document.getElementById(id): document.getElementsByName(id)[0];
		//alert(this.dom);
	}
	
	this.mkelm = function(tag, pelm){
		this.dom = document.createElement(tag);
		if(pelm){
			this.setParent(pelm);
		}
	}
	
	//HTMLへの設定
	this.setParent = function(pelm){
		pelm.appendChild(this.dom);
		
		//ついでに位置も取得
		this.getPos();
	}
	this.setChild = function(celm){
		this.dom.appendChild(celm);
	}
	
	//座標、大きさ
	this.getPos = function(){
		var elem = this.dom;
		if(elem){
			var pw = elem.offsetWidth;
			var ph = elem.offsetHeight;
			
			var px = 0;
			var py = 0;
			
			while(elem){
				px += elem.offsetLeft;
				py += elem.offsetTop;
				elem = elem.offsetParent;
			}
			
			this.x = px;
			this.y = py;
			this.w = pw;
			this.h = ph;
			return;
			
		}else{
			alert("error2");
			return;
		}
	}
	//透明度
	this.getCla = function(){
	}
	
	//アトリビュート関連
	this.setAtt = function(attname, val){
		if(navigator.userAgent.indexOf("Opera") != -1){
			
		}else if(navigator.userAgent.indexOf("MSIE") != -1){
			if(attname == "style"){
				this.dom.style.cssText = value;
			}else if(attname == "class"){
				this.dom["className"] = val;
			}else{
				this.dom[attname] = val;
			}
			
		}else if(navigator.userAgent.indexOf("Firefox") != -1){
			this.dom.setAttribute(attname, val);
			
		}else if(navigator.userAgent.indexOf("Netscape") != -1){
			
		}else if(navigator.userAgent.indexOf("Safari") != -1){
			
		}else{
			alert(navigator.userAgent);
		}
	}
	this.getAtt = function(attname){
		if(navigator.userAgent.indexOf("Opera") != -1){
			
		}else if(navigator.userAgent.indexOf("MSIE") != -1){
			return this.dom.getAttribute(attname);
			
		}else if(navigator.userAgent.indexOf("Firefox") != -1){
			return this.dom.getAttribute(attname);
			
		}else if(navigator.userAgent.indexOf("Netscape") != -1){
			
		}else if(navigator.userAgent.indexOf("Safari") != -1){
			
		}else{
			alert(navigator.userAgent);
		}
	}
	this.removeAtt = function(attname){
		// 工事中
	}
	
	
	//フェードイン/アウト
	this.fade = function(alpha, speed, acc){
		
		this.dom.style.
		
		tmr = window.setTimeout("fade(alpha, speed, acc)", speed);
	}
	
	
	//値の取得
	this.getVal = function(){
		
		var ret;
		
		switch(this.dom.tagName.toLowerCase()){
			case "select":
				
				var n = this.dom.selectedIndex;
				
				ret = this.dom.options[n].value == ""? this.dom.options[n].text: this.dom.options[n].value;
				break;
				
			case "input":
				
				switch(this.dom.type){
					case "text":
						ret = this.dom.value;
						break;
						
					case "checkbox":
						ret = this.dom.checked;
						break;
						
					case "radio":
						var lst = document.getElementsByName(this.dom.name);
						ret = false;
						for(i = 0; i < lst.length; i++){
							if(lst[i].checked == true){
								ret = lst[i].value;
								break;
							}
						}
						break;
						
					case "hidden":
						ret = this.dom.value;
						break;
				}
				break;
			
			case "textarea":
				//alert("this.dom.innerHTML = " + this.dom.innerHTML + "\n" + "this.dom.value = " + this.dom.value);
				ret = this.dom.value;
				break;
		}
		
		return ret;
	}
	
	
	//値を設定
	this.setVal = function(val){
		
		switch(this.dom.tagName.toLowerCase()){
			case "select":
				var opt = this.dom.getElementsByTagName("option");
				for(var i = 0; i < opt.length; i++){
					if(opt[i].value == val){
						this.dom.selectedIndex = i;
						break;
					}
				}
				break;
				
			case "input":
				
				switch(this.dom.type){
					case "text":
						this.dom.value = val;
						break;
						
					case "password":
						this.dom.value = val;
						break;
						
					case "checkbox":
						if(val == "on" || val == "1"){
							this.dom.checked = true;
						}else{
							this.dom.checked = false;
						}
						break;
						
					case "radio":
						var nm = this.dom.getAtt("name");
						var lst = parent.getElementsByName(nm);
						for(i = 0; i < lst.length; i++){
							if(lst[i].value == val){
								lst[i].checked = true;
								break;
							}
						}
						break;
						
					case "hidden":
						this.dom.value = val;
						break;
						
				}
				break;
			
			case "textarea":
				
				this.dom.value = val;
				break;
		}
	}
}
