/***************************************************
 * Checkbox checking/unchecking/inverting functions
 **************************************************/
function checkAll(id){
   var f = document.getElementById(id);
   var inputs = f.getElementsByTagName("input");
   for(var t = 0;t < inputs.length;t++){
     if(inputs[t].type == "checkbox")
       inputs[t].checked = true;
   }
 }
 function uncheckAll(id){
   var f = document.getElementById(id);
   var inputs = f.getElementsByTagName("input");
   for(var t = 0;t < inputs.length;t++){
     if(inputs[t].type == "checkbox")
       inputs[t].checked = false;
   }
 }
 function invertAll(id){
   var f = document.getElementById(id);
   var inputs = f.getElementsByTagName("input");
   for(var t = 0;t < inputs.length;t++){
     if(inputs[t].type == "checkbox")
       inputs[t].checked = !inputs[t].checked;
   }
 }


/***************************************************
 * Hide/Show Divs
 **************************************************/
function hideDiv(div) {
    if (!document.getElementById) return;
    obj = document.getElementById(div);
    obj.style.display="none";
}
function showDiv(div) {
    if (!document.getElementById) return;
    obj = document.getElementById(div);
    obj.style.display="block";
}
function getFileName(file) {
        document.upload.filename_fl.value = file;
}

function changeText() {
        if(document.upload.title.value != "" && document.upload.description.value != "" && document.upload.tags.value != "") {
                document.uploader.SetVariable("filledOut", true);
        }
}

//Animated Collapsible DIV- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Last updated Aug 1st, 07'. Fixed bug with "block" parameter not working when persist is enabled
//Updated June 27th, 07'. Added ability for a DIV to be initially expanded.

var uniquepageid=window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, "") //get current page path and name, used to uniquely identify this page for persistence feature

function animatedcollapse(divId, animatetime, persistexpand, initstate){
        this.divId=divId
        this.divObj=document.getElementById(divId)
        this.divObj.style.overflow="hidden"
        this.timelength=animatetime
        this.initstate=(typeof initstate!="undefined" && initstate=="block")? "block" : "contract"
        this.isExpanded=animatedcollapse.getCookie(uniquepageid+"-"+divId) //"yes" or "no", based on cookie value
        this.contentheight=parseInt(this.divObj.style.height)
        var thisobj=this
        if (isNaN(this.contentheight)){ //if no CSS "height" attribute explicitly defined, get DIV's height on window.load
                animatedcollapse.dotask(window, function(){thisobj._getheight(persistexpand)}, "load")
                if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes" && this.isExpanded!="") //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
                        this.divObj.style.visibility="hidden" //hide content (versus collapse) until we can get its height
        }
        else if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes" && this.isExpanded!="") //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
                this.divObj.style.height=0 //just collapse content if CSS "height" attribute available
        if (persistexpand)
                animatedcollapse.dotask(window, function(){animatedcollapse.setCookie(uniquepageid+"-"+thisobj.divId, thisobj.isExpanded)}, "unload")
}

animatedcollapse.prototype._getheight=function(persistexpand){
        this.contentheight=this.divObj.offsetHeight
        if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes"){ //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
                this.divObj.style.height=0 //collapse content
                this.divObj.style.visibility="visible"
        }
        else //else if persistence is enabled AND this content should be expanded, define its CSS height value so slideup() has something to work with
                this.divObj.style.height=this.contentheight+"px"
}


animatedcollapse.prototype._slideengine=function(direction){
        var elapsed=new Date().getTime()-this.startTime //get time animation has run
        var thisobj=this
        if (elapsed<this.timelength){ //if time run is less than specified length
                var distancepercent=(direction=="down")? animatedcollapse.curveincrement(elapsed/this.timelength) : 1-animatedcollapse.curveincrement(elapsed/this.timelength)
        this.divObj.style.height=distancepercent * this.contentheight +"px"
        this.runtimer=setTimeout(function(){thisobj._slideengine(direction)}, 10)
        }
        else{ //if animation finished
                this.divObj.style.height=(direction=="down")? this.contentheight+"px" : 0
                this.isExpanded=(direction=="down")? "yes" : "no" //remember whether content is expanded or not
                this.runtimer=null
        }
}


animatedcollapse.prototype.slidedown=function(){
        if (typeof this.runtimer=="undefined" || this.runtimer==null){ //if animation isn't already running or has stopped running
                if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
                        alert("Please wait until document has fully loaded then click again")
                else if (parseInt(this.divObj.style.height)==0){ //if content is collapsed
                        this.startTime=new Date().getTime() //Set animation start time
                        this._slideengine("down")
                }
        }
}

animatedcollapse.prototype.slideup=function(){
        if (typeof this.runtimer=="undefined" || this.runtimer==null){ //if animation isn't already running or has stopped running
                if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
                        alert("Please wait until document has fully loaded then click again")
                else if (parseInt(this.divObj.style.height)==this.contentheight){ //if content is expanded
                        this.startTime=new Date().getTime()
                        this._slideengine("up")
                }
        }
}

animatedcollapse.prototype.slideit=function(){
        if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
                alert("Please wait until document has fully loaded then click again")
        else if (parseInt(this.divObj.style.height)==0)
                this.slidedown()
        else if (parseInt(this.divObj.style.height)==this.contentheight)
                this.slideup()
}

// -------------------------------------------------------------------
// A few utility functions below:
// -------------------------------------------------------------------

animatedcollapse.curveincrement=function(percent){
        return (1-Math.cos(percent*Math.PI)) / 2 //return cos curve based value from a percentage input
}


animatedcollapse.dotask=function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
        var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
        if (target.addEventListener)
                target.addEventListener(tasktype, functionref, false)
        else if (target.attachEvent)
                target.attachEvent(tasktype, functionref)
}

animatedcollapse.getCookie=function(Name){
        var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
        if (document.cookie.match(re)) //if cookie found
                return document.cookie.match(re)[0].split("=")[1] //return its value
        return ""
}

animatedcollapse.setCookie=function(name, value){
                document.cookie = name+"="+value



}
//** Featured Content Slider script- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Last updated: Nov 3rd- 07- Added optional fade transition effect.

////Ajax related settings
var csbustcachevar=0 //bust potential caching of external pages after initial Ajax request? (1=yes, 0=no)
var enabletransition=1 //enable fade into view transition effect? (1=yes, 0=no)
var csloadstatustext="<img src='loading.gif' /> Requesting content..." //HTML to indicate Ajax page is being fetched
var csexternalfiles=[] //External .css or .js files to load to style the external content(s), if any. Separate multiple files with comma ie: ["cat.css", dog.js"]

////NO NEED TO EDIT BELOW////////////////////////
var enablepersist=true
var slidernodes=new Object() //Object array to store references to each content slider's DIV containers (<div class="contentdiv">)
var csloadedobjects="" //Variable to store file names of .js/.css files already loaded (if Ajax is used)

function ContentSlider(sliderid, autorun, customPaginateText, customNextText){
        var slider=document.getElementById(sliderid)
        if (typeof customPaginateText!="undefined" && customPaginateText!="") //Custom array of pagination links text defined?
                slider.paginateText=customPaginateText
        if (typeof customNextText!="undefined" && customNextText!="") //Custom HTML for "Next" link defined?
                slider.nextText=customNextText
        slidernodes[sliderid]=[] //Array to store references to this content slider's DIV containers (<div class="contentdiv">)
        ContentSlider.loadobjects(csexternalfiles) //Load external .js and .css files, if any
        var alldivs=slider.getElementsByTagName("div")
        for (var i=0; i<alldivs.length; i++){
                if (alldivs[i].className=="opacitylayer")
                        slider.opacitylayer=alldivs[i]
                else if (alldivs[i].className=="contentdiv"){
                        slidernodes[sliderid].push(alldivs[i]) //add this DIV reference to array
                        if (typeof alldivs[i].getAttribute("rel")=="string") //If get this DIV's content via Ajax (rel attr contains path to external page)
                                ContentSlider.ajaxpage(alldivs[i].getAttribute("rel"), alldivs[i])
                }
        }
        ContentSlider.buildpagination(sliderid)
        var loadfirstcontent=true
        if (enablepersist && getCookie(sliderid)!=""){ //if enablepersist is true and cookie contains corresponding value for slider
                var cookieval=getCookie(sliderid).split(":") //process cookie value ([sliderid, int_pagenumber (div content to jump to)]
                if (document.getElementById(cookieval[0])!=null && typeof slidernodes[sliderid][cookieval[1]]!="undefined"){ //check cookie value for validity
                        ContentSlider.turnpage(cookieval[0], parseInt(cookieval[1])) //restore content slider's last shown DIV
                        loadfirstcontent=false
                }
        }
        if (loadfirstcontent==true) //if enablepersist is false, or cookie value doesn't contain valid value for some reason (ie: user modified the structure of the HTML)
                ContentSlider.turnpage(sliderid, 0) //Display first DIV within slider
        if (typeof autorun=="number" && autorun>0) //if autorun parameter (int_miliseconds) is defined, fire auto run sequence
                window[sliderid+"timer"]=setTimeout(function(){ContentSlider.autoturnpage(sliderid, autorun)}, autorun)
}

ContentSlider.buildpagination=function(sliderid){
        var slider=document.getElementById(sliderid)
        var paginatediv=document.getElementById("paginate-"+sliderid) //reference corresponding pagination DIV for slider
        var pcontent=""
        for (var i=0; i<slidernodes[sliderid].length; i++) //For each DIV within slider, generate a pagination link
                pcontent+='<a href="#" onClick=\"ContentSlider.turnpage(\''+sliderid+'\', '+i+'); return false\">'+(slider.paginateText? slider.paginateText[i] : i+1)+'</a> '
        pcontent+='<a href="#" style="font-weight: bold;" onClick=\"ContentSlider.turnpage(\''+sliderid+'\', parseInt(this.getAttribute(\'rel\'))); return false\">'+(slider.nextText || "Next")+'</a>'
        paginatediv.innerHTML=pcontent
        paginatediv.onclick=function(){ //cancel auto run sequence (if defined) when user clicks on pagination DIV
        if (typeof window[sliderid+"timer"]!="undefined")
                clearTimeout(window[sliderid+"timer"])
        }
}

ContentSlider.turnpage=function(sliderid, thepage){
        var paginatelinks=document.getElementById("paginate-"+sliderid).getElementsByTagName("a") //gather pagination links
        for (var i=0; i<slidernodes[sliderid].length; i++){ //For each DIV within slider
                paginatelinks[i].className="" //empty corresponding pagination link's class name
                slidernodes[sliderid][i].style.display="none" //hide DIV
        }
        paginatelinks[thepage].className="selected" //for selected DIV, set corresponding pagination link's class name
        if (enabletransition){
                if (window[sliderid+"fadetimer"])
                        clearTimeout(window[sliderid+"fadetimer"])
                this.setopacity(sliderid, 0.1)
        }
        slidernodes[sliderid][thepage].style.display="block" //show selected DIV
        if (enabletransition)
                this.fadeup(sliderid, thepage)
        //Set "Next" pagination link's (last link within pagination DIV) "rel" attribute to the next DIV number to show
        paginatelinks[paginatelinks.length-1].setAttribute("rel", thenextpage=(thepage<paginatelinks.length-2)? thepage+1 : 0)
        if (enablepersist)
                setCookie(sliderid, sliderid+":"+thepage)
}

ContentSlider.autoturnpage=function(sliderid, autorunperiod){
        var paginatelinks=document.getElementById("paginate-"+sliderid).getElementsByTagName("a") //Get pagination links
        var nextpagenumber=parseInt(paginatelinks[paginatelinks.length-1].getAttribute("rel")) //Get page number of next DIV to show
        ContentSlider.turnpage(sliderid, nextpagenumber) //Show that DIV
        window[sliderid+"timer"]=setTimeout(function(){ContentSlider.autoturnpage(sliderid, autorunperiod)}, autorunperiod)
}

ContentSlider.setopacity=function(sliderid, value){ //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
        var targetobject=document.getElementById(sliderid).opacitylayer || null //reference slider container itself
        if (targetobject && targetobject.filters && targetobject.filters[0]){ //IE syntax
                if (typeof targetobject.filters[0].opacity=="number") //IE6
                        targetobject.filters[0].opacity=value*100
                else //IE 5.5
                        targetobject.style.filter="alpha(opacity="+value*100+")"
                }
        else if (targetobject && typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax
                targetobject.style.MozOpacity=value
        else if (targetobject && typeof targetobject.style.opacity!="undefined") //Standard opacity syntax
                targetobject.style.opacity=value
        targetobject.currentopacity=value
}

ContentSlider.fadeup=function(sliderid){
        var targetobject=document.getElementById(sliderid).opacitylayer || null //reference slider container itself
        if (targetobject && targetobject.currentopacity<1){
                this.setopacity(sliderid, targetobject.currentopacity+0.1)
                window[sliderid+"fadetimer"]=setTimeout(function(){ContentSlider.fadeup(sliderid)}, 100)
        }
}

function getCookie(Name){
        var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
        if (document.cookie.match(re)) //if cookie found
                return document.cookie.match(re)[0].split("=")[1] //return its value
        return ""
}

function setCookie(name, value){
        document.cookie = name+"="+value
}

////////////////Ajax Related functions //////////////////////////////////

ContentSlider.ajaxpage=function(url, thediv){
        var page_request = false
        var bustcacheparameter=""
        if (window.XMLHttpRequest) // if Mozilla, Safari etc
                page_request = new XMLHttpRequest()
        else if (window.ActiveXObject){ // if IE
                try {
                page_request = new ActiveXObject("Msxml2.XMLHTTP")
                }
                catch (e){
                try{
                page_request = new ActiveXObject("Microsoft.XMLHTTP")
                }
                catch (e){}
                }
        }
        else
                return false
        thediv.innerHTML=csloadstatustext
        page_request.onreadystatechange=function(){
                ContentSlider.loadpage(page_request, thediv)
        }
        if (csbustcachevar) //if bust caching of external page
                bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
        page_request.open('GET', url+bustcacheparameter, true)
        page_request.send(null)
}

ContentSlider.loadpage=function(page_request, thediv){
        if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
                thediv.innerHTML=page_request.responseText
}

ContentSlider.loadobjects=function(externalfiles){ //function to load external .js and .css files. Parameter accepts a list of external files to load (array)
        for (var i=0; i<externalfiles.length; i++){
                var file=externalfiles[i]
                var fileref=""
                if (csloadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
                        if (file.indexOf(".js")!=-1){ //If object is a js file
                                fileref=document.createElement('script')
                                fileref.setAttribute("type","text/javascript");
                                fileref.setAttribute("src", file);
                        }
                        else if (file.indexOf(".css")!=-1){ //If object is a css file
                                fileref=document.createElement("link")
                                fileref.setAttribute("rel", "stylesheet");
                                fileref.setAttribute("type", "text/css");
                                fileref.setAttribute("href", file);
                        }
                }
                if (fileref!=""){
                        document.getElementsByTagName("head").item(0).appendChild(fileref)
                        csloadedobjects+=file+" " //Remember this object as being already added to page
                }
        }
}
