
var View = new Object();
View.trStyle1 = "  ";
View.trStyle2 = "  ";
View.tdStyle1 = " style='font-size:12px;'  height=\"25\"   ";
View.tdStyle2 = " style='font-size:12px;'  height=\"25\"  ";
View.fieldSytle = " style='font-size:12px;'";
View.tableStyle = " width=\"100%\"  border=\"0\" cellspacing=\"1\" cellpadding=\"1\"  ";
View.columnStyle = " font-size: 12px;cursor: hand";
View.columnTr = " height=\"20\"";
View.columnTd = " style='font-size:12px;' ";
View.align = "center";   //align with center
View.columnName = "ÁÐºÅ"; //serial number text name

View.isNumber = false;//show the  serial number in the head of line
 View.columnTr = " height=\"20\"   ";
View.columnTd = "  style='font-size:12px;'  align=\"center\" ";
/**
 * ViewList the list definition
 */
var ViewList = function(name){
	this.records = new Array();
	this.tableSytle = View.tableStyle;
	this.length = 0;
	this.sortNumber = 0;
	this.name = name;
	this.column = new ViewColumn();
	this.curNumber = 0;//ÐÐºÅ
	this.isNumber = View.isNumber;
	//style


}
ViewList.prototype.setColumn = function(column){

	 this.column = column;
	 this.column.plist = this;
}
ViewList.prototype.show = function(num){
	if(num == null){
		num = 0;
	}
	this.sort(num);
	document.getElementById(this.name).innerHTML = this;
}

ViewList.prototype.add = function(record){
	record.plist = this;
	this.records[this.records.length] =  record;
	this.length ++;
}
ViewList.prototype.generate = function(){

	document.write("<table width=100% cellspacing=\"0\" cellpadding=\"0\" ><tr><td id=\""+this.name+"\">"+this+"</td></tr></table>");
	//alert("");
	//document.all.list.innerHTML="ddddddddddddd";
	//alert(document.all.list.name);
}
ViewList.prototype.get = function(num){
	if(num < this.length){
		return this.records[num];
	}
	else{
		alert("exception ViewList: num="+num);
		return "exception ViewList";
	}
}
//sort function
ViewList.prototype.ascending = function(a,b){
	var sn = a.plist.sortNumber;
        var desc = a.plist.desc;
	if(a.fields[sn].getName() > b.fields[sn].getName()){
          	if(desc)
		   return 1;
                else{
                  return -1
                }
	}else{
          if(a.fields[sn].getName() < b.fields[sn].getName())
          	if(desc)
		   return -1;
                else{
                  return 1
                }
          else{

          	return 0;
          }
	}
}
//list sort function
ViewList.prototype.sort = function(sortnum){
  	if(this.desc){
            this.desc = false;
  	}else{
  		this.desc = true;
            }
	this.sortNumber = sortnum;
	this.records = this.records.sort(this.ascending);
}


//remove record from the specified number,and return the removed record
ViewList.prototype.remove = function(num){
	if(num < this.length){
		var record = this.records[num];
		for(var i = num;i < this.length -1;i ++){
			this.records[i] = this.records[i+1];
		}
		return record;
	}
	else{
		alert("exception ViewList: num="+num);
	}
}

ViewList.prototype.toString = function(){
	var rs ="";
	if(this.length > 0){
		rs = "<table "+this.tableSytle+" >";
		rs += this.column;
		for(var i = 0;i < this.length;i ++){
			this.curNumber = i;
			rs += this.get(i);
		}
		rs += "\r\n</table>";
	}
	return rs;
}

/**
 * ViewColumn the ViewColumn definition
 */
var ViewColumn = function(){
	this.fields = new Array();
	this.length = 0;
	this.plist ;
	this.widths = new Array();
	//
	this.style = View.columnStyle;


}


ViewColumn.prototype.add = function(value,width){
	this.fields[this.length] = value;
	this.widths[this.length] = width;
	this.length ++;
}

ViewColumn.prototype.get = function(num){

	if(num < this.length)
		return "    \r\n<td "+View.columnTd+" align="+View.align+" width=\""+this.widths[num]+"\" style=\""+this.style+";cursor: hand\" onclick=\""+this.plist.name+".show("+num+");\">"+this.fields[num]+"</td>";
	else{
		alert("exception ViewRecord: num="+num);
		return "exception ViewRecord";
	}
}

ViewColumn.prototype.toString = function(){
	var rs ;

	if(this.length > 0){
		rs = "  \r\n<tr "+View.columnTr+" >";
		if(this.plist.isNumber){
			rs += "     \r\n<td  "+View.columnTd+" align="+View.align+" style=\""+this.style+"\">"+View.columnName+"</td>";
		}
		for(var i = 0;i < this.length;i ++){
			rs += this.get(i);
		}
		rs += "  \r\n</tr>";
	}
	return rs;
}

/**
 * ViewRecord the record definition
 */
var ViewRecord = function(){
	this.fields = new Array();
	this.length = 0;
	this.plist ;
	this.trStyle = View.trStyle1;
	this.tdStyle = View.tdStyle1;


}

ViewRecord.prototype.add = function(value){

	this.fields[this.length] = value;
	this.length ++;
}

ViewRecord.prototype.get = function(num){
	//alert(this.fields[num].style);
	if(num < this.length){
		//return "    \r\n<td align="+View.align+" "+this.tdStyle+" "+this.fields[num].style+" >"+this.fields[num]+"</td>";
                var value = this.fields[num];

		return "    \r\n<td "+this.tdStyle+" "+this.fields[num].style+" align=\""+View.align+"\"  >"+value+"</td>";
	}
	else{
		alert("exception ViewRecord: num="+num);
		return "exception ViewRecord";
	}
}

ViewRecord.prototype.toString = function(){
	if(this.plist.curNumber % 2 == 0){
		this.trStyle = View.trStyle1;
		this.tdStyle = View.tdStyle1;

	}else{
		this.trStyle = View.trStyle2;
		this.tdStyle = View.tdStyle2;

	}
	var rs ;

	if(this.length > 0){
		rs = "  \r\n<tr "+this.trStyle+" >";
			if(this.plist.isNumber){
				rs += "     \r\n<td "+this.tdStyle+" align=\""+View.align+"\" ><span  "+View.fieldSytle+">"+this.plist.curNumber+"</span></td>";
			}
		for(var i = 0;i < this.length;i ++){
			//
			//alert(this.get(i));
			rs += this.get(i);
		}
		rs += "  \r\n</tr>";
	}
	return rs;
}
/**
 * ViewField
 */

var ViewField = function(name,link,title,style){
	this.name = name;
	this.link = link;
	this.title = title;
	if(style == null){

		this.style = View.fieldSytle;
	}else{
		this.style = style;
	}
}
ViewField.prototype.getName = function(){
	return this.name;
}
ViewField.prototype.toString = function(){


               // alert(value);
	var rs = "<span ";
	if(this.title != null && this.title != "undifined"){
             if(this.title == " ×Ö¶Î "){
        	this.title = this.name;
          }
		rs += " title='"+this.title+"'";

	}

	//if(this.style != null && this.style != "undifined"){
	//	rs += " style='" + this.style + "'";
                //rs += " " + this.style + " ";
	//}
	rs +=">" + this.link + "</span>";
	/*if(this.link != null && this.link != "undifined"){
		rs += "<a href='"+this.link+"'>";
	}*/
	//rs += this.link;
	/*if(this.link != null && this.link != "undifined"){
		rs += "</a>";
	}*/
	//rs += "</span>";
	return rs;
       // return this.name;

}
