/*
 ************************************************************************
 * Sydsvenskan Escenic
 * $Date: 2005/04/19 07:25:08 $
 * $Author: escenic $
 * $Id: functions.js,v 1.3 2005/04/19 07:25:08 escenic Exp $
 ************************************************************************
*/
// JavaScript Document


// Nyhetsticker, johannes, 14 sept 2007
// Ticker startup
function startTicker()
{
	// Define run time values
	theCurrentStory     = -1;
	theCurrentLength    = 0;
	// Locate base objects
	if (document.getElementById) {	
		    theAnchorObject     = document.getElementById("tickerAnchor");
			runTheTicker();   	
		 }
	else {
            document.write("<style>.ticki{display:none;}.ticko{border:0px; padding:0px;}</style>");
            return true;
	}
}

// Ticker main run loop
function runTheTicker()
{
	var myTimeout;  
	// Go for the next story data block
	if(theCurrentLength == 0)
	{
		theCurrentStory++;
		theCurrentStory      = theCurrentStory % theItemCount;
		theStorySummary      = theSummaries[theCurrentStory].replace(/&quot;/g,'"');		
		theTargetLink        = theSiteLinks[theCurrentStory];
		theAnchorObject.href = theTargetLink;
		thePrefix 	     = "<span class=\"tickls\">" + theLeadString + "</span>";
	}
	// Stuff the current ticker text into the anchor
	theAnchorObject.innerHTML = thePrefix + 
	theStorySummary.substring(0,theCurrentLength) + whatWidget();
	// Modify the length for the substring and define the timer
	if(theCurrentLength != theStorySummary.length)
	{
		theCurrentLength++;
		myTimeout = theCharacterTimeout;
	}
	else
	{
		theCurrentLength = 0;
		myTimeout = theStoryTimeout;
	}
	// Call up the next cycle of the ticker
	setTimeout("runTheTicker()", myTimeout);
}

// Widget generator
function whatWidget()
{
	if(theCurrentLength == theStorySummary.length)
	{
		return theWidgetNone;
	}

	if((theCurrentLength % 2) == 1)
	{
		return theWidgetOne;
	}
	else
	{
		return theWidgetTwo;
	}
}


/**	Öppnar popup för veckans fråga 
  	Används från includes/rightcolumn.jsp */
function OpenSurvey(openPage){
  //alert(openPage);
  window.open(openPage,'survey','toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=400,height=480');
}

/**	Skriver ut aktiv sida 
  	Används från artikel_print.jsp */
function printArticle(){
  if(window.print){
    window.print();
  } else {
    alert("Din browser stödjer inte den här funktionen.");
  }
}

/**	Används för rightcol webbkameror */

    function goto_url(object) {
        window.location.href = object.options[object.selectedIndex].value;
    }


/**	Skifte side for serier og annet 
  	Används från serier.jsp */
function changeArt(page) {
  window.location.href = page.options[page.selectedIndex].value;
}

/*
Check required form elements script-
By JavaScript Kit (http://javascriptkit.com)
Over 200+ free scripts here!
*/

function checkrequired(which){
var pass=true
if (document.images){
for (i=0;i<which.length;i++){
var tempobj=which.elements[i]
if (tempobj.name.substring(0,8)=="required"){
if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
pass=false
break
}
}
}
}
if (!pass){
alert("Ett eller flera fält är inte ifyllda. Var vänlig och komplettera formuläret och försök sedan skicka igen!")
return false
}
else
return true
}

// 20071106: Flamman, PODCAST TOGGLE används i filen: components/pod/podcasting.jsp
function toggleContent(section) {
	if(document.getElementById && document.getElementById(section)) {

		cabinet = document.getElementById(section); //columnGroup

		if(cabinet.getElementsByTagName("h5")) {
			toggleHeadings = cabinet.getElementsByTagName("h5");
		}
		for(i=0;i<toggleHeadings.length;i++){
			toggleHeadings[i].onclick=function() {
				if(this.parentNode.getElementsByTagName("div")) {
					drawer = this.parentNode.getElementsByTagName("div");
					if(drawer[0].style.display=="none"){
						drawer[0].style.display="block"; this.className="open";
					} else {
						drawer[0].style.display="none";this.className="closed";
					}
				}
			} //funnction
		}//for
	}
}
