/*
* SVT namespace
*/

if(typeof se == "undefined") var se = new Object();
if(typeof se.svt == "undefined") se.svt = new Object();
if(typeof se.svt.flash == "undefined") se.svt.flash = new Object();
if(typeof se.svt.web == "undefined") se.svt.web = new Object();
if(typeof se.svt.web.util == "undefined") se.svt.web.util = new Object();
if(typeof _hbLink == "undefined") { function _hbLink(){} }

var SgAvailWidth = screen.availWidth;
var SgAvailHeight = screen.availHeight-24;
var SgDOM;
var SgUpWin;
SgIsLoaded = false;

function svtInit(){
	SgIsLoaded = true;
	if(typeof se.svt.web.util.InitHandler.run != "undefined") {
    	se.svt.web.util.InitHandler.run();
    }
}

function SgRandomImage(url){
	var img = new Image(1,1);
    if(url.indexOf('?') > -1){
	    img.src=url+'&rnd='+(new Date()).getTime();
    }else{
	    img.src=url+'?rnd='+(new Date()).getTime();
    }
}

function SgBrowserobj(){
	this.ver = navigator.appVersion.toLowerCase();
	this.agent = navigator.userAgent.toLowerCase();
	this.name = navigator.appName.toLowerCase();
	this.byid = document.getElementById;
	this.opera = (this.agent.indexOf("opera")>-1);
	this.ie = (this.name == 'microsoft internet explorer' && !this.opera);
	this.ie4 = (this.ie && ( this.ver.indexOf("msie 4")>-1 || this.agent.indexOf("msie 4")>-1 ) );
	// ie5 didn't exist in production
    this.ie5 = (this.ie && ( this.ver.indexOf("msie 5")>-1 || this.agent.indexOf("msie 5")>-1 ) );
	this.ns = (this.name == 'netscape' && !this.opera);
	this.ns4 = (this.ns && document.layers);
	this.mac = (this.agent.indexOf("mac")>-1);
	this.windows = (this.agent.indexOf("windows")>-1);
return this;
}
if(!SgDOM){
	SgDOM = new SgBrowserobj();
}
function SgOpenStandard(url) {
	var w_height = 599;
	var w_width = 799;
	if ((SgAvailWidth > 840) && (SgAvailHeight > 640)){
		if (screen.availWidth >= 1024){
			w_height = (SgDOM.ie) ? 748 : 590;
			w_width = 1015;
		} else {
			w_height = (SgDOM.ie) ? (screen.availHeight - 20) : (screen.availHeight - 100);
			w_width = (screen.availWidth - 10);
		}
	} else {
		w_height = (SgDOM.ie) ? "550" : "440";
		w_width = 799;
	}
	SgOpenWindow(url,'standardpopup',w_width,w_height,'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
}
function SgMyPersonalPage(id) { //O pen spinnmembers function
	SgOpenArgs('http://spinn.svt.se/default.ns?strItemID=personal_page&lngUserID='+id+'&section=','Personlig_sida'+id,590,500,'menubar=no,directories=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,location=no');
}
function SgOpenMax(url,name,maxWidth,maxHeight,args){
	var w_width = maxWidth;
	var w_height = maxHeight;
	if( (maxWidth > SgAvailWidth || maxHeight > SgAvailHeight) || (maxWidth < 1 || maxHeight < 1) ){
		w_width = SgAvailWidth;
		w_height = SgAvailHeight;
	}
	SgOpenWindow(url,SgTrimUScore(name),w_width,w_height,args);
}
function SgOpenArgs(url,name,w_width,w_height,args) {
	SgOpenWindow(url,SgTrimUScore(name),w_width,w_height,args);
}
// DEPRECATED
var VideoPlayerURL = "/mediaplayer/mediaplayer_real/default.htm";
function SgOpenVideoWindow(mediapath, title, version){
	var URL = VideoPlayerURL + "?" + mediapath + "&" + escape(title) + "&" + version;
	SgOpenWindow(URL,"videowindow","355","344","scrolling=yes,framespacing=0");
}
// DEPRECATED
function SgOpenVideoWindowNew(mediapath, title, version, inCorpWith){
	var URL = VideoPlayerURL + "?" + mediapath + "&" + escape(title) + "&" + version + "&" + escape(inCorpWith);
	SgOpenWindow(URL,"videowindow","355","344","scrolling=yes,framespacing=0");
}
// Base function to handle SgUpWindows (do not call directly)
function SgOpenWindow(url, name, w_width, w_height, args, placeWindow) {
	name = SgTrim(name);
	args = SgTrim(args);
	if(args !== ''){
		args = args + ',';
	}
	if (!SgUpWin || SgUpWin.closed) {
		center_of_screen_X=Math.floor(SgAvailWidth/2)-Math.floor(w_width/2);
		center_of_screen_Y=Math.floor(SgAvailHeight/2)-Math.floor(w_height/2);
		placeWindow = (SgDOM.opera) ? "" : ",left=" + center_of_screen_X + ",top=" + center_of_screen_Y;
	}
	SgUpWin = window.open(url,name, args + 'width='+w_width+',height='+w_height + placeWindow);
	if(SgUpWin){
		SgUpWin.focus();
	} else {
		alert("Fönstret som skulle öppnas blockerades! Ändra inställningar för svt.se i din popup-blockerare.");
	}
}
function SgIsEmpty(inputString) {
	var theReturn;
	inputString = SgTrim(inputString);
	theReturn = (inputString === " " || inputString === "" || inputString === null);
return theReturn;
}
function SgTrim(inputString) {
	if (typeof inputString != "string") {
		return inputString;
	}
	var theReturn = inputString.replace(/^\s*([\S\s]*)$/,'$1');
	theReturn = theReturn.replace(/\s+$/,'');
	theReturn = theReturn.replace(/\s\s+/g,' ');
	return theReturn;
}
function SgTrimUScore(inputString) {
	var theReturn = SgTrim(inputString);
	theReturn = theReturn.replace(/\s/g,'_');
	return theReturn;
}
// DEPRECATED (Remove when the new menu.jsp is launched)
function SgGo(theForm,theSelect){
	var strURL;
	strURL = theForm.elements[theSelect].options[theForm.elements[theSelect].options.selectedIndex].value;
	if(SgIsEmpty(strURL) || strURL == "0" || strURL == "-1") {
	  alert("En länk i listan måste väljas");
	  return false;
	} else {
	    _hbLink('dropdown_'+theForm.name, '', '0,0,0,0');
		document.location.href=strURL;
		return false;
	}
}
function SgNavigater(theForm,theSelect){
//	alert('SgNavigater');
var strURL = theForm.elements[theSelect].options[theForm.elements[theSelect].options.selectedIndex].value;
	if(SgIsEmpty(strURL) || strURL == "0" || strURL == "-1") {
		  alert("En länk i listan måste väljas");
		  return false;
	} else if(theSelect=="open" || theSelect=="video"){
	    _hbLink('dropdown_'+theForm.name,'', '0,0,0,0');
		SgOpenArgs('/svt/road/Classic/shared/mediacenter/index.jsp?'+strURL,'largevideoplayer',790,585,'scrolling=no,status=yes');
		return false;
	} else {
	    _hbLink('dropdown_'+theForm.name, '', '0,0,0,0');
		document.location.href=strURL;
	}
}
function SgNavigate(theForm,theSelect){
	var strURL = theForm.elements[theSelect].options[theForm.elements[theSelect].options.selectedIndex].value;
	if(SgIsEmpty(strURL) || strURL == "0" || strURL == "-1") {
		  alert("En länk i listan måste väljas");
		  return false;
	} else if(theSelect=="open" || theSelect=="video"){
	    _hbLink('dropdown_'+theForm.name,'', '0,0,0,0');
		SgOpenArgs('/svt/road/Classic/shared/mediacenter/index.jsp?'+strURL,'largevideoplayer',790,585,'scrolling=no,status=yes');
		return false;
	} else {
	    _hbLink('dropdown_'+theForm.name, '', '0,0,0,0');
		document.location.href=strURL;
	}
    return true;
}
function SgSearchValidate(theForm, namnet){
	var ele = theForm.elements[namnet].value;
	if(ele.length < 0){
		alert(" Minst ett tecken måste alltid skrivas in i sökrutan");
		return false;
	}
	_hbLink('search_'+theForm.name, '', '0,0,0,0');
    return true;
}
function SgValidateEmail(inputString){
	inputString = SgTrim(inputString);
	var expr = /^([^\W][a-z_0-9\.-]+[^\W]|[a-z_0-9-]+)@([^\W]+[a-z_0-9\.-]*[^\W]+|[a-z_0-9-]*[^\W]+)\.[a-z]{2,9}$/i;
	if (inputString===""){
		return false;
	}
	var retVal = inputString.replace(expr,"");
	if (retVal === ""){
		return true;
	}
	return false;
}
function SgVoid(){
	// nothing
}
// DEPRECATED
function SM_fncGoRullmeny(strSelbox){
	var strURL;
	strURL = strSelbox.options[strSelbox.selectedIndex].value;
	if(strURL === "") { return false;}
	document.location.href=strURL;
}
function SgBrowserMessage(){
	var theMessage = "<div align=\"left\">";
	theMessage += "<img src=\"http://svt.se/svt_se/images/framework/redalert.gif\" width=\"16\" height=\"14\" alt=\"Alert!\" border=\"0\" valign=\"middle\"> ";
	theMessage += "Din webbläsare kan inte kan hantera alla \"stilmallar\" på Svt.se på ett korrekt sätt. Vi rekommenderar att du laddar hem en senare version av webbläsare, <a href=\"/svt/jsp/Crosslink.jsp?d=1994\">klicka här om du vill ha hjälp</a>.";
	theMessage += "</div><br>";
	return theMessage;
}
function SgForumValidate(theForm, maxContentLength, demandEmail){
	var notValid = false;
	var ele = theForm.elements;
	var alertString = "Formuläret kan inte skickas\n----------------------------\n";
	if(ele.content.value.length > maxContentLength){
		notValid = true;
		alertString += "Inlägget får inte vara längre än \nmaximalt " + maxContentLength + " tecken\n";
		alertString += "\n----------------------------";
	} else {
		if(ele.title.value.length < 1){
			notValid = true;
			alertString += "Rubrik\n";
		}
		if(ele.content.value.length < 1){
			notValid = true;
			alertString += "Inlägg\n";
		}
		if(ele.name.value.length < 1){
			notValid = true;
			alertString += "Namn\n";
		}
		if (demandEmail && !SgValidateEmail(ele.email.value)) {
			notValid = true;
			alertString += "En giltig e-postadress\n";
		}
		alertString += "\n----------------------------\nMåste fyllas i";
	}
	if(notValid){
		alert(alertString);
		return false;
	} else {
		return true;
	}
}
var SgmDI = document.images;
var SgmIsPrel = false;
function SgmNewImage(theImage) {
	if (SgmDI) {
		var theReturn = new Image();
		theReturn.src = theImage;
		return theReturn;
	}
}
function SgmPreload() {
	prelimg = new Array();
	if (SgmDI) {
		for (var i=0; i<SgmPreload.arguments.length; i++) {
			prelimg[i] = SgmNewImage(SgmPreload.arguments[i]);
		}
	SgmIsPrel = true;
	}
}
function SgmSwap() {
	if (SgmDI && (SgmIsPrel === true)) {
		for (var i=0; i<SgmSwap.arguments.length; i+=2) {
			document[SgmSwap.arguments[i]].src = SgmSwap.arguments[i+1];
		}
	}
}
function SgShowHideObjects(obj, showOrHide){
	if(showOrHide == "show"){
		showOrHide = "block";
	} else if (showOrHide == "hide") {
		showOrHide = "none";
	}
	if(getObject(obj) && (showOrHide == "block" || showOrHide == "none")){
		getObject(obj).style.display = showOrHide;
	}
}
function getObject(theObj){
	if(document.getElementById){
		return document.getElementById(theObj);
	} else if (document.all){
		return document.all[theObj];
	}
}
function SgBookmark(url,headline) {
	if(SgDOM.ie){
		window.external.AddFavorite(url,headline);
	} else if(SgDOM.ns) {
		alert("Klicka OK och tryck sedan CTRL+D för att lägga till i favoriter.");
	}
}

/** javascript link that links to a anchor link. **/
function SgSoftLink(e,hrefId) {
	var targ;
    var url = getObject(hrefId).href;

    if (!e) {
        e = window.event;
    }

    if (e.target) {
    	targ = e.target;
    } else if (e.srcElement) {
    	targ = e.srcElement;
    } else {
    	targ = e;
    }

    if (targ.nodeType == 3) {
        targ = targ.parentNode;
    }

    if(targ) {
        targ.className = targ.className + " SgSoftLink";
    }

    if(!targ.onclick) {
        targ.onclick = function (event)	{
        	window.location = url;
        };
    }

	if(!targ.onmouseout){
    	targ.onmouseout	= function (event)	{
      		window.status = '';
        };
    }

    if(!targ.onmousedown) {
    	targ.onmousedown = function (event)	{
        	window.status = url;
        };
    }

    if(document.all) {
        window.status = url;
    }
}


/*
On load function cue handler
*/

if(typeof se.svt.web.util.InitHandler == "undefined") se.svt.web.util.InitHandler = new Object();
se.svt.web.util.InitHandler.add = function(fn) {
    if(typeof this.functionList == "undefined") this.functionList = new Array();
    this.functionList[this.functionList.length] = fn;
}

se.svt.web.util.InitHandler.run = function() {
    if(typeof this.functionList != "undefined" && this.functionList.length > 0) {
        for ( var i=0; i < this.functionList.length; i++) {
            if (typeof this.functionList[i] == "function") this.functionList[i]();
            else if (typeof this.functionList[i] == "string") eval(this.functionList[i]);
        }
    }
}



/*
Flash utils
*/
//(Depricated) use svt.SWFObject
if(typeof se.svt.flash.FlashUtil == "undefined") se.svt.flash.FlashUtil = new Object();


    se.svt.flash.FlashUtil.getPlayerVersion = function() {

        if(typeof this.playerVersion  == "undefined") {
            this.playerVersion = new se.svt.flash.PlayerVersion(0,0,0);

            if(navigator.plugins && navigator.mimeTypes.length) {
                var x = navigator.plugins["Shockwave Flash"];
                if(x && x.description) {
                    this.playerVersion = new se.svt.flash.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
                }
            } else if (window.ActiveXObject) {
                try {
                    var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
                    this.playerVersion = new se.svt.flash.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
                } catch (e) {}
            }
        }
		return this.playerVersion;
	}

    se.svt.flash.PlayerVersion = function(arrVersion) {
		this.major	= parseInt(arrVersion[0]) || 0;
		this.minor	= parseInt(arrVersion[1]) || 0;
		this.rev	= parseInt(arrVersion[2]) || 0;
   	}

/**
* original source : SWFObject v1.4: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
* svt.SWFObject = function(swf, id, w, h, ver, c, useExpressInstall, quality, xiRedirectUrl, redirectUrl, detectKey)
*/

if(typeof svt=="undefined"){
var svt=new Object();
}
if(typeof svt.util=="undefined"){
svt.util=new Object();
}
if(typeof svt.SWFObjectUtil=="undefined"){
svt.SWFObjectUtil=new Object();
}

if(typeof deconcept=="undefined"){var deconcept=new Object();}
if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}
if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}
deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a,_b){if(!document.getElementById){return;}
this.DETECT_KEY=_b?_b:"detectflash";
this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);
this.params=new Object();
this.variables=new Object();
this.attributes=new Array();
if(_1){this.setAttribute("swf",_1);}
if(id){this.setAttribute("id",id);}
if(w){this.setAttribute("width",w);}
if(h){this.setAttribute("height",h);}
if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}
this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();
if(c){this.addParam("bgcolor",c);}
var q=_8?_8:"high";
this.addParam("quality",q);
this.setAttribute("useExpressInstall",_7);
this.setAttribute("doExpressInstall",false);
var _d=(_9)?_9:window.location;
this.setAttribute("xiRedirectUrl",_d);
this.setAttribute("redirectUrl","");
if(_a){this.setAttribute("redirectUrl",_a);}};
deconcept.SWFObject.prototype={setAttribute:function(_e,_f){
this.attributes[_e]=_f;
},getAttribute:function(_10){
return this.attributes[_10];
},addParam:function(_11,_12){
this.params[_11]=_12;
},getParams:function(){
return this.params;
},addVariable:function(_13,_14){
this.variables[_13]=_14;
},getVariable:function(_15){
return this.variables[_15];
},getVariables:function(){
return this.variables;
},getVariablePairs:function(){
var _16=new Array();
var key;
var _18=this.getVariables();
for(key in _18){_16.push(key+"="+_18[key]);}
return _16;},getSWFHTML:function(){var _19="";
if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){
if(this.getAttribute("doExpressInstall")){
this.addVariable("MMplayerType","PlugIn");}
_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";
_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";
var _1a=this.getParams();
for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}
var _1c=this.getVariablePairs().join("&");
if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";
}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");}
_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";
_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";
var _1d=this.getParams();
for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}
var _1f=this.getVariablePairs().join("&");
if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}
return _19;
},write:function(_20){
if(this.getAttribute("useExpressInstall")){
var _21=new deconcept.PlayerVersion([6,0,65]);
if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){
this.setAttribute("doExpressInstall",true);
this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));
document.title=document.title.slice(0,47)+" - Flash Player Installation";
this.addVariable("MMdoctitle",document.title);}}
if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){
var n=(typeof _20=="string")?document.getElementById(_20):_20;
n.innerHTML=this.getSWFHTML();return true;
}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}
return false;}};
deconcept.SWFObjectUtil.getPlayerVersion=function(){
var _23=new deconcept.PlayerVersion([0,0,0]);
if(navigator.plugins&&navigator.mimeTypes.length){
var x=navigator.plugins["Shockwave Flash"];
if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}
}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}
catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}
catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}
catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}
return _23;};
deconcept.PlayerVersion=function(_27){
this.major=_27[0]!=null?parseInt(_27[0]):0;
this.minor=_27[1]!=null?parseInt(_27[1]):0;
this.rev=_27[2]!=null?parseInt(_27[2]):0;
};
deconcept.PlayerVersion.prototype.versionIsValid=function(fv){
if(this.major<fv.major){return false;}
if(this.major>fv.major){return true;}
if(this.minor<fv.minor){return false;}
if(this.minor>fv.minor){return true;}
if(this.rev<fv.rev){
return false;
}return true;};
deconcept.util={getRequestParameter:function(_29){
var q=document.location.search||document.location.hash;
if(q){var _2b=q.substring(1).split("&");
for(var i=0;i<_2b.length;i++){
if(_2b[i].substring(0,_2b[i].indexOf("="))==_29){
return _2b[i].substring((_2b[i].indexOf("=")+1));}}}
return "";}};
deconcept.SWFObjectUtil.cleanupSWFs=function(){if(window.opera||!document.all){return;}
var _2d=document.getElementsByTagName("OBJECT");
for(var i=0;i<_2d.length;i++){_2d[i].style.display="none";for(var x in _2d[i]){
if(typeof _2d[i][x]=="function"){_2d[i][x]=function(){};}}}};
deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};
__flash_savedUnloadHandler=function(){};
if(typeof window.onunload=="function"){
var _30=window.onunload;
window.onunload=function(){
deconcept.SWFObjectUtil.cleanupSWFs();_30();};
}else{window.onunload=deconcept.SWFObjectUtil.cleanupSWFs;}};
if(typeof window.onbeforeunload=="function"){
var oldBeforeUnload=window.onbeforeunload;
window.onbeforeunload=function(){
deconcept.SWFObjectUtil.prepUnload();
oldBeforeUnload();};
}else{window.onbeforeunload=deconcept.SWFObjectUtil.prepUnload;}
if(Array.prototype.push==null){
Array.prototype.push=function(_31){
this[this.length]=_31;
return this.length;};}
var getQueryParamValue=deconcept.util.getRequestParameter;
var FlashObject=deconcept.SWFObject;
var SWFObject=deconcept.SWFObject;

svt.SWFObject = deconcept.SWFObject;


/*
Form utils
*/
// only allow set number och checkboxes. Used by poll votes.
// elm = checkbox element , size = numer of allowed checkboxes
function SgCheckboxRange(elm,size){
    var cnt = 0;

    if(elm.checked) {size - 1;}  // TODO: Alex! Expression statement is not an assigment
    for(var i=0; i < elm.form[elm.name].length; i++) {
        var checkbox = elm.form[elm.name][i];
        if(checkbox != elm && checkbox.checked) {
            cnt++;
            if(cnt>=size) checkbox.checked = false;
        }
    }
};

/* requires prototype.js */
function SgMultiToggle(id) {
		$A(document.getElementsByClassName('toggleDisplay',$(id))).each(function(item){
				Element.toggle(item);
			});
}
function SgToggleObjects(id) {
    if(SgDOM.ie && SgDOM.mac){
        // Code that works in IE on Mac
        var element = getObject(id);
        if(element.style.display == 'none'){
            element.style.display = 'block';
        } else {
            element.style.display = 'none';
        }
    } else {
        Element.toggle(id);
    }
}


// Cookie util
var Cookie = {
  set: function(name, value, daysToExpire, path, domain, secure) {
    var expire = '';
    if (daysToExpire != undefined) {
      var d = new Date();
      d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
      expire = '; expires=' + d.toGMTString();
    }

    return document.cookie = escape(name) + "=" + escape(value || '') +
                             expire +
                             ((path) ? "; path=" + path : "") +
                             ((domain) ? "; domain=" + domain : "") +
                             ((secure) ? "; secure" : "");
  },
  get: function(name) {
    var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
    return (cookie ? unescape(cookie[2]) : null);
  },
  erase: function(name) {
    var cookie = Cookie.get(name) || true;
    Cookie.set(name, '', -1);
    return cookie;
  },
  accept: function() {
    if (typeof navigator.cookieEnabled == 'boolean') {
      return navigator.cookieEnabled;
    }
    Cookie.set('_test', '1');
    return (Cookie.erase('_test') === '1');
  }
}


    if(typeof Class == "undefined") {
        var Class = {
          create: function() {
            return function() {
              this.initialize.apply(this, arguments);
            }
          }
        }
    }

    //  PersonalizedDataClass , Peronalisera Article 659 <alexander.aivars>
    var PersonalizedDataClass = Class.create();
        PersonalizedDataClass.prototype = {
            initialize: function(articleId) {
                this.cookieId  = "PersonalizedDataArticle" + articleId;
                this.articleId = articleId;
                this.url = "/svt/personal/";
            },
            getRemoteHTML: function(){
                var myAjax = new Ajax.Updater(
                    'sgUserContentHolder'+this.articleId,
                    this.url,
                    {
                        method: 'get',
                        parameters: Cookie.get(this.cookieId).toString()
                    });

                $('sgUserContentFooter'+this.articleId).show();
                $('sgUserContentHolder'+this.articleId).show();
                $('sgUserContentSelect'+this.articleId).hide();
                $('sgUserContentDefualt'+this.articleId).hide();

            },
            setData: function(data){
                Cookie.set(this.cookieId,data,365,"/","svt.se");
                $('sgUserContentSelect'+this.articleId).hide();
                this.getRemoteHTML(this.cookieId);
            },
            clearData: function(){
                Cookie.erase(this.cookieId);
                $('sgUserContentSelect'+this.articleId).show();
                $('sgUserContentHolder'+this.articleId).innerHTML = "";
            },
            checkData: function(){
                if(Cookie.accept() && Cookie.get(this.cookieId) != null) {
                    $('sgUserContentSelect'+this.articleId).hide();
                    $('sgUserContentDefualt'+this.articleId).hide();
                    $('sgUserContentFooter'+this.articleId).show();
                    this.getRemoteHTML();
                } else {
                    $('sgUserContentDefualt'+this.articleId).show();
                    $('sgUserContentSelect'+this.articleId).show();
                    $('sgUserContentFooter'+this.articleId).hide();
                }
            },
            showSelect: function(){
                $('sgUserContentFooter'+this.articleId).hide();
                $('sgUserContentSelect'+this.articleId).show();
            }
        }


    function PersonalizedData(id) {
        return new PersonalizedDataClass(id);
    }






function showVoteMode(id) {
    $('ratingMode_' +id).show();
    $('averageRatingVote_' +id).hide();
    return false;
    }

function showHideInfo(artId, num) {
    if(num == 0) {
        $('info_text_' + artId).show();
    }
    else {
        $('info_text_' + artId).hide();
    }

    if(num == 1) {
        $('info_text_' + artId + '_1').show();
    }
    else {
        $('info_text_' + artId + '_1').hide();
    }

    if(num == 2) {
        $('info_text_' + artId + '_2').show();
    }
    else {
        $('info_text_' + artId + '_2').hide();
    }

    if(num == 3) {
        $('info_text_' + artId + '_3').show();
    }
    else {
        $('info_text_' + artId + '_3').hide();
    }

    if(num == 4) {
        $('info_text_' + artId + '_4').show();
    }
    else {
        $('info_text_' + artId + '_4').hide();
    }

    if(num == 5) {
        $('info_text_' + artId + '_5').show();
    }
    else {
        $('info_text_' + artId + '_5').hide();
    }
}



/* STAR RATING */

function showRating(url, divName) {

    se.svt.web.util.StarRatingLoader.add(url, divName);

}


var StarRating = {
    init: function () {

        $$('li.starRatingHover').each(function(elm) {
            elm.setStyle({cursor: 'pointer'});
            //elm.onmouseover = StarRating.onMouseOver.bind(StarRating);
            //elm.onmouseuut = StarRating.onMouseOut.bind(StarRating);
              elm.observe('mouseover',StarRating.onMouseOver);
              elm.observe('mouseout', StarRating.onMouseOut);
        });
    },

    onMouseOver: function(event) {

        var e = Event.element(event);
        var p = Event.element(event).up('ul');
        var a = p.immediateDescendants();

        for ( var i=0,t=false;i<a.length;i++) {
            if(!t) {
                a[i].addClassName("active")
                t = (a[i] == e)?true:false;

            } else a[i].removeClassName("active");
        }
        clearTimeout(p.timmerId);
        e.up('.articleRating').down(".ratingInfo").innerHTML = e.down('a').title;
    },

    onMouseOut: function(event) {
        Event.element(event).up('.articleRating').down(".ratingInfo").innerHTML = "";

        var p = Event.element(event).up('ul');
        clearTimeout(p.timmerId);
        p.timmerId = setTimeout(function() { StarRating.hideRateContainer(p); },2000);

        var a = Event.element(event).up('ul').immediateDescendants();
        for ( var i=0;i<a.length;i++) {
            a[i].removeClassName("active");
        }
    },

    hideRateContainer: function (elm) {
        elm.up('.articleRating').down('.userRating').hide();
        elm.up('.articleRating').down('.currentRating').show();
    },

    rate: function(elm) {
        $(elm).up('.articleRating').down('.userRating').show();
        $(elm).up('.articleRating').down('.currentRating').hide();
    },

    submitVote: function(url,elm) {

        var showRating = new Ajax.Updater(
        {success: elm.up('.articleRating').down('.currentRating ')},
	    url,
	    {
	        method: 'get',
	        onFailure: StarRating.submitError,
            onComplete: function() { StarRating.submitComplete(elm); }
        });
    },

    submitError: function(request) {
        //alert('StarRating.submitError:'+ request.responseText)
    },

    submitComplete: function(elm) {
        StarRating.hideRateContainer(elm);
    }

}






var StarRatingLoaderClass = Class.create();

StarRatingLoaderClass.prototype = {

    initialize: function() {

        this.requestStack = new Array();
        this.isLoading = false;
    },
    add: function(url,divName) {

        this.requestStack.push([
            {success: divName},
	        url, {
	        method: 'get',
	        onFailure: se.svt.web.util.StarRatingLoader.requestError,
            onComplete: se.svt.web.util.StarRatingLoader.requestComplete
            } ]);

        //alert(this.requestStack[this.requestStack.length -1 ]);
    },
    request: function() {
        this.isLoading = true;
        var args = this.requestStack.shift();
        var showRating = new Ajax.Updater(args[0],args[1],args[2]);

    },
    requestComplete: function (args) {
        var oRef = se.svt.web.util.StarRatingLoader;
        if(oRef.requestStack.length>0) oRef.request();
        else {
            StarRating.init();
            this.isLoading = false;
        }
    },
    requestError: function() {

    },

    start: function () {
        if(!this.isLoading) {
            this.request();
        }
    }

}

if(typeof se.svt.web.util.StarRatingLoader=="undefined"){
    se.svt.web.util.StarRatingLoader = new StarRatingLoaderClass();
}
