// -------------------------------------------------------------------
// Switch Content Script- By Dynamic Drive, available at: http://www.dynamicdrive.com
// Created: Jan 5th, 2007
// April 5th, 07: Added ability to persist content states by x days versus just session only
// March 27th, 08': Added ability for certain headers to get its contents remotely from an external file via Ajax (2 variables below to customize)
// -------------------------------------------------------------------

var switchcontent_ajax_msg="<em>Loading Ajax content...</em>",switchcontent_ajax_bustcache=!0;function switchcontent(a,b){this.className=a;this.collapsePrev=!1;this.persistType="none";this.filter_content_tag=typeof b!="undefined"?b.toLowerCase():"";this.ajaxheaders={}}switchcontent.prototype.setStatus=function(a,b){this.statusOpen=a;this.statusClosed=b};switchcontent.prototype.setColor=function(a,b){this.colorOpen=a;this.colorClosed=b}; switchcontent.prototype.setPersist=function(a,b){a==!0?typeof b=="undefined"?this.persistType="session":(this.persistType="days",this.persistDays=parseInt(b)):this.persistType="none"};switchcontent.prototype.collapsePrevious=function(a){this.collapsePrev=a};switchcontent.prototype.setContent=function(a,b){this.ajaxheaders["header"+a]=b}; switchcontent.prototype.sweepToggle=function(a){if(typeof this.headers!="undefined"&&this.headers.length>0)for(var b=0;b<this.headers.length;b++)a=="expand"?this.expandcontent(this.headers[b]):a=="contract"&&this.contractcontent(this.headers[b])};switchcontent.prototype.defaultExpanded=function(){for(var a=[],b=0;!this.collapsePrev&&b<arguments.length||this.collapsePrev&&b==0;b++)a[a.length]=arguments[b];this.expandedindices=a.join(",")}; switchcontent.prototype.togglecolor=function(a,b){if(typeof this.colorOpen!="undefined")a.style.color=b};switchcontent.prototype.togglestatus=function(a,b){if(typeof this.statusOpen!="undefined")a.firstChild.innerHTML=b};switchcontent.prototype.contractcontent=function(a){document.getElementById(a.id.replace("-title","")).style.display="none";this.togglestatus(a,this.statusClosed);this.togglecolor(a,this.colorClosed)}; switchcontent.prototype.expandcontent=function(a){var b=document.getElementById(a.id.replace("-title",""));a.ajaxstatus=="waiting"&&switchcontent.connect(a.ajaxfile,a);b.style.display="block";this.togglestatus(a,this.statusOpen);this.togglecolor(a,this.colorOpen)}; switchcontent.prototype.toggledisplay=function(a){document.getElementById(a.id.replace("-title","")).style.display=="block"?this.contractcontent(a):(this.expandcontent(a),this.collapsePrev&&typeof this.prevHeader!="undefined"&&this.prevHeader.id!=a.id&&this.contractcontent(this.prevHeader));if(this.collapsePrev)this.prevHeader=a}; switchcontent.prototype.collectElementbyClass=function(a){a=RegExp("(^|\\s+)"+a+"($|\\s+)","i");this.headers=[];this.innercontents=[];for(var b=this.filter_content_tag!=""?document.getElementsByTagName(this.filter_content_tag):document.all?document.all:document.getElementsByTagName("*"),c=0;c<b.length;c++)typeof b[c].className=="string"&&b[c].className.search(a)!=-1&&document.getElementById(b[c].id+"-title")!=null&&(this.headers[this.headers.length]=document.getElementById(b[c].id+"-title"),this.innercontents[this.innercontents.length]= b[c])}; switchcontent.prototype.init=function(){var a=this;this.collectElementbyClass(this.className);if(this.headers.length!=0){this.persistType=="days"&&parseInt(switchcontent.getCookie(this.className+"_dtrack"))!=this.persistDays&&switchcontent.setCookie(this.className+"_d","",-1);for(var b=this.persistType=="session"&&switchcontent.getCookie(this.className)!=""?","+switchcontent.getCookie(this.className)+",":this.persistType=="days"&&switchcontent.getCookie(this.className+"_d")!=""?","+switchcontent.getCookie(this.className+"_d")+ ",":this.expandedindices?","+this.expandedindices+",":"",c=0;c<this.headers.length;c++){if(typeof this.ajaxheaders["header"+c]!="undefined")this.headers[c].ajaxstatus="waiting",this.headers[c].ajaxfile=this.ajaxheaders["header"+c];if(typeof this.statusOpen!="undefined")this.headers[c].innerHTML='<span class="status"></span>'+this.headers[c].innerHTML;if(b.indexOf(","+c+",")!=-1){if(this.expandcontent(this.headers[c]),this.collapsePrev)this.prevHeader=this.headers[c]}else this.contractcontent(this.headers[c]); this.headers[c].onclick=function(){a.toggledisplay(this)}}switchcontent.dotask(window,function(){a.rememberpluscleanup()},"unload")}}; switchcontent.prototype.rememberpluscleanup=function(){for(var a=["none"],b=0;b<this.innercontents.length;b++){if(this.persistType!="none"&&this.innercontents[b].style.display=="block"&&(!this.collapsePrev||this.collapsePrev&&a.length<2))a[a.length]=b;this.headers[b].onclick=null}a.length>1&&a.shift();if(typeof this.statusOpen!="undefined")this.statusOpen=this.statusClosed=null;this.persistType=="session"?switchcontent.setCookie(this.className,a.join(",")):this.persistType=="days"&&typeof this.persistDays== "number"&&(switchcontent.setCookie(this.className+"_d",a.join(","),this.persistDays),switchcontent.setCookie(this.className+"_dtrack",this.persistDays,this.persistDays))};switchcontent.dotask=function(a,b,c){c=window.addEventListener?c:"on"+c;a.addEventListener?a.addEventListener(c,b,!1):a.attachEvent&&a.attachEvent(c,b)}; switchcontent.connect=function(a,b){var c=!1,d="";if(window.ActiveXObject)try{c=new ActiveXObject("Msxml2.XMLHTTP")}catch(e){try{c=new ActiveXObject("Microsoft.XMLHTTP")}catch(f){}}else if(window.XMLHttpRequest)c=new XMLHttpRequest;else return!1;c.onreadystatechange=function(){switchcontent.loadpage(c,b)};switchcontent_ajax_bustcache&&(d=a.indexOf("?")!=-1?"&"+(new Date).getTime():"?"+(new Date).getTime());c.open("GET",a+d,!0);c.send(null)}; switchcontent.loadpage=function(a,b){var c=document.getElementById(b.id.replace("-title",""));c.innerHTML=switchcontent_ajax_msg;if(a.readyState==4&&(a.status==200||window.location.href.indexOf("http")==-1))c.innerHTML=a.responseText,b.ajaxstatus="loaded"};switchcontent.getCookie=function(a){a=RegExp(a+"=[^;]+","i");if(document.cookie.match(a))return document.cookie.match(a)[0].split("=")[1];return""}; switchcontent.setCookie=function(a,b,c){if(typeof c!="undefined"){var d=new Date;d.setDate(d.getDate()+c);document.cookie=a+"="+b+"; expires="+d.toGMTString()}else document.cookie=a+"="+b};

