// Javascript functions
//
//


function Bol(broadcasts) { 
 this.broadcasts = broadcasts?broadcasts:new Array();
 
 this.getBroadcast = function(){				        
	       if(this.broadcasts.length>0){
	         return this.broadcasts[0];
	       }
   }
}

function Broadcast(name) {  				
				var events = new Array();
				var id = -1;
				var start;
				var end;
				var scheduledStart;
				var scheduledEnd;
				var description = "";				
				var startoffset = 0;
				var template = "";
				var stream="stream.asx";
				
				this.id=id;
				this.name=name?name:"";
				this.start=start;
				this.end=end;
		        this.template= template;
				this.stream = stream;		        
		        this.startoffset= startoffset;
   		        this.scheduledStart= scheduledStart;
   		        this.scheduledEnd= scheduledEnd;
   		        this.events=events;
	
				this.isLive=function(){
				    if(this.end != undefined ){
					    return false;
				    }
				    else {
					    return true;
				    }
				}
			}
			
			
function Speaker(id) {  				
					this.id=id;
	 }
		

function Function(id) {  									
					this.id=id;
	 }
function Party(id) {  				
					this.id=id;
	 }
	 
function Event(type,value,time){
		var id="";
		var url="";
		var topic=new Topic();
		var speaker=new Speaker();
		var documents=new Array();
		var presentation=new Presentation();		
		var slide=new Slide();				

		var duration=new Duration().validDuration("PT0H0M0.000S");
		
		this.id=id;
		this.value=value?value:"";
		this.url=url;
		this.type=type;
		this.topic=topic;
		this.speaker=speaker;
		this.time=time?time:new Duration().validDuration("PT0H0M0.000S");
		this.duration = duration;
}


function Duration(pm, years, months, days, hours, minutes, seconds, fraction){
		 
	var giYearMill = 31536000000;	var giMonthMill = 2592000000;
	var giDayMill = 86400000;	var giHourMill = 3600000;
	var giMinMill = 60000;	var giSecMill = 1000;

	this.pm = pm;
	this.years = years*1;
	this.months = months*1;
	this.days = days*1;
	this.hours = hours*1;
	this.minutes = minutes*1;
	this.seconds = seconds*1;
	this.fraction = fraction*1;
	if(fraction != undefined){
	   this.milliseconds = eval('0.'+fraction) * 100;
	}
	else {
	   this.milliseconds = 0;
	}
	this.mask = ((this.years?1:0)<<6) + ((this.months?1:0)<<5) + ((this.days?1:0)<<4) + ((this.hours?1:0)<<3) + ((this.minutes?1:0)<<2) + ((this.seconds?1:0)<<1) + (this.milliseconds?1:0);
	this.Seconds = function(){
	          if (this.years || this.months){
			          return Number.NaN;
			  }
		if(isNaN(this.days)){
				this.days=0;		
		}			  
		if(isNaN(this.hours)){
				this.hours=0;		
		}			  
		if(isNaN(this.minutes)){
				this.minutes=0;		
		}	
		if(isNaN(this.seconds)){
				this.seconds=0;		
		}	
		return this.days*giDayMill + this.hours*giHourMill + this.minutes*giMinMill + this.seconds*giSecMill;

	}
	
	this.validDuration = function(d){
        var parts;
        var re = new RegExp("^([\-])?P(([0-9]+)Y)?(([0-9]+)M)?(([0-9]+)D)?((T)?(([0-9]+)H)?(([0-9]+)M)?((([0-9]+)(\.([0-9]+))?)S)?)?$");
        if (parts = re.exec(d)){
                
                if ((/T$/.exec(d)) || (parts[9] == "T" && parts[11]+parts[13]+parts[16]+parts[18]== ""))// ~(:+(|) duh!!!
                       return Number.NaN;
                return new Duration(parts[1]?parts[1]:"", parts[3], parts[5], parts[7], parts[11], parts[13], parts[16], parts[18]);				
        }
        return Number.NaN;
	 }	 	

}
	 

function Topic(id){
	this.id=id;

}

function Presentation(id){
      this.id=id;
      
   }


function Slide(id){
		this.id=id;
		this.number=id;
}

function Poll(id){
		this.id=id;
}

function Option(id){
     this.id=id;
}

function Document(id){
	this.id=id;

}

function DocumentType(id){
    this.id=id;
}

    