// bulletin.js

//Bulletin Class


function Bulletin(id, count, dataSource, labels)
{
	if(count == 0){
		return;
	}
    this.id = id;
    this.count = count;
    this.dataSource = dataSource;
    this.labels = labels;
    this.pos = 0;
    this.win = null;
    this.width = 400;
    this.height = 300;
    this.left	= document.documentElement.clientWidth / 2 - this.width /2;
	this.top	= document.documentElement.clientHeight / 2 - this.height /2
	    
    this.clear= function(){
        DestroyWindow(this.id);
    }  
    
    this.next = function(){
        
        if( this.pos < count-1 ) {
            this.pos++;
        }else{
            return;
        }
        
        this.create(); 
    
    }
    
    this.previous = function(){
        
        if ( this.pos!=0 ) 
        {
            this.pos--;
        }
        else
        {
            return;
        }
        
        this.create(); 
        
    }
    
    
    
    this.create = function() {
        
        var width	 = this.width;
    	var height	 = this.height;
    	var left 	 = this.left;
    	var top 	 = this.top;
    	
    	var title    = dataSource["title" + this.pos];
    	var from     = dataSource["from" + this.pos];
    	var body     = dataSource["body" + this.pos];
    	var bid 	 = dataSource["bid" + this.pos];
    	
    	
    	var text = ""
    	    + "<div align=\"center\" class=\"bulletin\" width=\"100%\">"
    	    + "   <table border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"\" width=\"" + width + "\" height=\"98%\" >"
            + "      <tr>"
            + "         <td align=\"left\" colspan=\"2\" style=\"padding-top: 10px\" class=\"from\">"
            + "               &nbsp;<span class=\"fromlabel\">" + this.labels["fromLabel"] + ":</span><span class=\"labeltext\"> " + from + "</span>"
            + "         </td>"
            + "        </tr>"
            + "        <tr>"
            + "            <td align=\"center\" valign=\"top\" colspan=\"2\">"
            + "                <div id=\"Blrc\" style=\"width: 100%; height: 100px;\">"
            + "                    <div style=\"border-right: #b4c2e2 1px solid; border-top: #b4c2e2 1px solid; font-size: 12px; border-left: #b4c2e2 1px solid; width: " + (width-20) + "px; border-bottom: #b4c2e2 1px solid; text-align: left\">"
            + "                        <table cellpadding=\"0\" cellspacing=\"0\" style=\"background: #fae8c0\" width=\"" + (width -20) + "\">"
            + "                            <tr>"
            + "                                <td style=\"padding-right: 10px; padding-left: 10px; padding-bottom: 1px; padding-top: 5px; text-align: left\">"
            + "                                    <span class=\"contentlabel\">" + this.labels["contentLabel"] + ":</span></td>"
            + "                                <td style=\"text-align: right\">"
            + "                                </td>"
            + "                            </tr>"
            + "                        </table>"
            + "                        <div id=\"LrcShower" + this.id + this.pos + "\" style=\"overflow-y: scroll; overflow-x: hidden;line-height: 20px; height: 150px\" class=\"contenttext\">"
            + body                            
            + "                        </div>"
            + "                    </div>"
            + "						   <div align='left'><input type=\"checkbox\" id=\"noshow" + this.id + this.pos + "\" ><label for=\"noshow" + this.id + this.pos + "\">"+ this.labels["noshow"] + "</label></div>"
            + "                </div>"
            + "            </td>"
            + "        </tr>"
            + "    </table>"
            + "</div>"
        
         	this.win = new CoolWin(this.id + this.pos, width, height, left, top, title, text);
         	 
        
    }
    
   
   	for(var i=0; i<count; i++){
   		var bid = dataSource["bid" + this.pos];
    	var ckNoShow = getCookie("bnoshow");    	
		
		if(ckNoShow!=null && ckNoShow.indexOf(bid, 0) != -1){
			this.pos++;
			continue;
		}    	

    	this.create();
    	document.getElementById(this.id + this.pos).setAttribute("bid", bid);
    	
    	this.pos++;
    	this.left = this.left + 30;
   		this.top = this.top + 30; 
    	
    }

}


function saveStatus(id)
{
	var win = document.getElementById(id);
	if(!win){
		return;
	}
	
	var bid = win.getAttribute("bid");
	var bNoShow = getCookie("bnoshow");
	var checkBt = document.getElementById("noshow" + id);
	
	if(checkBt==null)return;
	
	if(checkBt.checked){
		if(bNoShow==null || bNoShow.trim() == ""){
			setCookie30d("bnoshow", bid);
		}else{
			setCookie30d("bnoshow", bNoShow + "," + bid);
		}
	}

}


