/*
function iniciar(){
	    var auto_retract_normal_accordion_options={
	    	panelWidth:203,
	    	panelHeight:"auto",
	    	tabLocation:'inline',
	    	onLoadShowTab:-2,
	    	expandedBg:"#000",
	    	collapsedBg:"#88C43E",
	    	collapsedFontWeight:"bold",
	    	collapsedTextColor	:"#fff",
			hoverBg				:"#000",
	    	hoverTextColor		:"#88C43E",
	    	borderColor			:"#000",
	    	expandedTextColor	:"#88C43E",
	    	duration:	100,
	    	hoverImg       		: "../images/nav_box_left_act.gif",
	    	expandedBgImg       : "../images/nav_box_left_act.gif",
         	collapsedBgImg      : "../images/nav_box_left.gif"
	    };

    var myAccordion = new Rico.Accordion($('auto_retract_normal_accordion'),auto_retract_normal_accordion_options);
    myAccordion.showTabByIndex(0,false);
    $("auto_retract_normal_accordion").style.visibility="visible";
}


*/



var ChannelTimer = Class.create({
	initialize: function(timers){
		if(Object.isUndefined(timers)){
			this.timers = new Array();
		}
		if(Object.isArray(timers)){
			if(Object.isArray(timers[0])){
				this.timers = timers;
			} else {
				this.timers = new Array();
				this.timers.push(timers);
			}
			this.update();
		}
		this.type = "";
        this.daysString = { singular : 'Tag' , plural : 'Tage' };
		//this.hoursString = { singular : 'Std' , plural : 'Std' };
		this.hoursString = { singular : 'h' , plural : 'h' };
	},
	setDaysString : function(singular,plural){
		this.daysString = { singular : singular , plural : plural };
	},
	setHoursString : function(singular,plural){
		this.hoursString = { singular : singular , plural : plural };
	},
	setTimer : function(domId,endtime,type,server_timestamp){
        this.type = type;
		var now = new Date();
        this.delta_time = server_timestamp*1000 - now.getTime();
		var timer = new Array();
		timer.push(domId);
		timer.push(endtime);
		this.timers.push(timer);
		this.update();
		return this;
	},
	recalculate : function(endtime){
		var now = new Date();
		var end = new Date( endtime );
		var diff = Math.floor(end.getTime() - (now.getTime() + this.delta_time) );

    	if(diff<=0 && diff>-60000){
    		location.reload();
    		return;
    	}

        //alert(diff);
		var newtime = "00:00:00";
		if(diff > 0){
			var days = Math.floor(diff/(1000*60*60*24));
			diff = diff - (days*1000*60*60*24);
			var hours = Math.floor(diff/(1000*60*60));
			diff = diff - (hours*1000*60*60);
			var minutes = Math.floor(diff/(1000*60));
			diff = diff - (minutes*1000*60);
			var seconds = Math.floor(diff/1000);
			if(days>1){
				if(hours > 1){
					if(this.type == "short"){
                        newtime = days+" "+this.daysString.plural+" "+hours+" "+this.hoursString.plural;
                    } else {
                        newtime = days+" "+this.daysString.plural+" : "+hours+" "+this.hoursString.plural+" : "+minutes+" min";
                    }
				} else if(hours > 0){
					if(this.type == "short"){
					   newtime = days+" "+this.daysString.plural+" "+hours+" "+this.hoursString.singular;
                    } else {
					   newtime = days+" "+this.daysString.plural+" : "+hours+" "+this.hoursString.singular+" : "+minutes+" min";
                    }
				} else {
					newtime = days+" "+this.daysString.plural;
				}
			} else if(days>0) {
				if(hours > 1){
				   newtime = days+" "+this.daysString.singular+" "+hours+" "+this.hoursString.plural;
				} else if(hours > 0){
					newtime = days+" "+this.daysString.singular+" "+hours+" "+this.hoursString.singular;
				} else {
					newtime = days+" "+this.daysString.singular;
				}
			} else {
				if(seconds<10) seconds = '0'+seconds;
				if(minutes<10) minutes = '0'+minutes;
				if(this.type == "short"){
				    newtime = ""+hours+":"+minutes+":"+seconds+"";
                } else {
				    newtime = ""+hours+" h : "+minutes+" min : "+seconds+" sec";
                }
			}
		} 
		return newtime;
	},
	update: function(){
		this.timers.each( function(el){
			var element;
			if(element = $(el[0])){
				element.update(this.recalculate(el[1]));
			} else {
				var elements = $$('.'+el[0]);
				elements.invoke('update',this.recalculate(el[1]));
			}
		},this)
	}
});



function countdown( endtime, jetzt, init, adjust ) {
	var now = new Date();
	var end = new Date( endtime );
	if(init){
		var start = new Date( jetzt );
		adjust = Math.floor(start.getTime() - now.getTime());
	}
		 
    now.setTime(now.getTime() + adjust);
    
    var diff = Math.floor(end.getTime() - now.getTime() );

	if(diff<=0){
	//	location.reload();
		return;
	}

    var hours = Math.floor(diff/(1000*60*60));
    diff = diff - (hours*1000*60*60);
    var minutes = Math.floor(diff/(1000*60));
    diff = diff - (minutes*1000*60);
    var seconds = Math.floor(diff/1000);
	if(seconds<10) seconds = '0'+seconds;
	if(minutes<10) minutes = '0'+minutes;
	if(hours<10) hours = '0'+hours;
    document.getElementById('timeleft').innerHTML = ""+hours+":"+minutes+":"+seconds;

	setTimeout( "countdown('"+ endtime +"','" +jetzt +"', false, "+adjust+")", 1000);
}

function checkCategory(formid,formitem,cat_ctrl_name){
    //alert("formid "+formid+" item "+formitem);
    var cats = document.getElementById(formid).elements[cat_ctrl_name];
    var catlen = cats.length;
    if(formitem==361){
      var checkit=false;
      for(var i=0;i<catlen;i++){
        if(cats[i].checked){
          checkit=true;
        }
      }
      if(!checkit) {
        for(var i=0;i<catlen;i++){
          cats[i].checked = true;
        }
      }

    }else if(formitem==360||formitem==0){
      for(var i=0;i<catlen;i++){
        cats[i].checked = false;
      }
    }
}

function setAboType(formid, cat_ctrl_name, abotype_ctrl_name){
    var cats = document.getElementById(formid).elements[cat_ctrl_name];
    var abo_types = document.getElementById(formid).elements[abotype_ctrl_name];
    var abo_type = 360; 
        // check themes checkboxes
        for(var i=0; i<cats.length; i++){
            if(cats[i].checked==true){
                abo_type = 361;
                break;
            }
        }
        // set abo_type
        for(var i=0; i<abo_types.length; i++){
            if(abo_types[i].value==abo_type){
                abo_types[i].checked = true;
        }
    }
}

function clearMobile (field){
	var text = ''+field.value;
    var textlen = text.length;
	if(textlen == 0) return;
	var strippedText = text.replace(/(<([^>]+)>)/ig,"");
	strippedText = strippedText.replace("<\?","");  
	var re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;		
	strippedText = strippedText.replace(re,"");
	re = /^\s+/;
	strippedText = strippedText.replace(re,"");
	re = /^0+/;
	strippedText = strippedText.replace(re,"");
	field.value = strippedText;
}

function idx_wrapper (doc_group,doc_name,action,memberid){
	var tracking_object = createITT();
	tracking_object.DOCUMENTNAME=doc_name;
	tracking_object.DOCUMENTGROUP=doc_group;
	tracking_object.MEMBERID=memberid;
	if(action!=''){
		tracking_object.ACTION=action;
		tracking_object.submit_action();
	} else {
		tracking_object.submit();
	}
}

function showMeTheStars(star){
    star.className="stars-yellow";
}

function hideAllTheStars(star){
    star.className="stars-gray";
}
