﻿//Flash version detection
	var requiredVersion = 4;
	var useRedirect = false;
	var flashPage = "movie.html"
	var noFlashPage = "noflash.html"
	var upgradePage = "upgrade.html"
	// =============================================================================
	var flash2Installed = false;
	var flash3Installed = false;
	var flash4Installed = false;
	var flash5Installed = false;
	var flash6Installed = false;
	var maxVersion = 6;
	var actualVersion = 0;
	var hasRightVersion = false;
	var jsVersion = 1.0;

	var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

	jsVersion = 1.1;

	if(isIE && isWin){
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
	document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
	document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
	document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
	document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
	document.write('</SCR' + 'IPT\> \n');
	}


	function detectFlash() {
	if (navigator.plugins) {
		if (navigator.plugins["Shockwave Flash 2.0"]
			|| navigator.plugins["Shockwave Flash"]) {

		var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
		var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
		var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
		flash2Installed = flashVersion == 2;
		flash3Installed = flashVersion == 3;
		flash4Installed = flashVersion == 4;
		flash5Installed = flashVersion == 5;
		flash6Installed = flashVersion >= 6;
		}
	}

	for (var i = 2; i <= maxVersion; i++) {
		if (eval("flash" + i + "Installed") == true) actualVersion = i;
	}

	if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 3;

	if (actualVersion >= requiredVersion) {
		if (useRedirect) {
		if(jsVersion > 1.0) {
			window.location.replace(flashPage);
		} else {
			window.location = flashPage;
		}
		}

		hasRightVersion = true;
	} else {
		if (useRedirect) {
		if(jsVersion > 1.0) {
			window.location.replace((actualVersion >= 2) ? upgradePage : noFlashPage);
		} else {
			window.location = (actualVersion >= 2) ? upgradePage : noFlashPage;
		}
		}
	}
	}

// Makes sure the three main divs are the same height.
function adaptMainDivs()
{
    var leftDiv		   = document.getElementById('leftareadiv');
    var mainDiv		   = document.getElementById('mainareadiv');
    var rightDiv	   = document.getElementById('rightareadiv');
    var mainandleftdiv = document.getElementById('mainandleftdiv');
    var pagemaindiv	   = document.getElementById('pagemaindiv'); 
    var rightShadowDiv = document.getElementById('PageShadowRight');
//    var leftShadowDiv  = xGetElementById('PageShadowLeft');	   

    // min-height
    var height = 400;
       
    // find the highest div
    if (leftDiv)leftDiv.style.height = 'auto';
    if (leftDiv  && leftDiv.clientHeight  > height) height = leftDiv.clientHeight;
    if (mainDiv) mainDiv.style.height = 'auto';
    if (mainDiv  && mainDiv.clientHeight  > height) height = mainDiv.clientHeight;
    if (rightDiv) rightDiv.style.height = 'auto';
    if (rightDiv && rightDiv.clientHeight > height)	height = rightDiv.clientHeight;
    if (mainandleftdiv) mainandleftdiv.style.height = 'auto';
    if (mainandleftdiv && mainandleftdiv.clientHeight > height) height = mainandleftdiv.clientHeight;

    // set new height
    if (leftDiv)  leftDiv.style.height  = height + 'px';
    if (mainDiv)  mainDiv.style.height  = height + 'px';
    if (rightDiv) rightDiv.style.height = height + 'px';
    if (mainandleftdiv) mainandleftdiv.style.height = height + 'px';
    
    //new code to set shadow height
//    rightShadowDiv.style.height =   pagemaindiv.clientHeight;
//    leftShadowDiv.style.height =   pagemaindiv.clientHeight;
}


// This function will fire a click event on the specified control when the 
// enter key is pressed in a text field. Attach this function to the 
// onkeypressed-event on the text field.
function fireClickOnEnter(evt, controlId)
{
    var control = document.getElementById(controlId);
    var keyCode = (typeof window.event == 'object') ? window.event.keyCode : evt.keyCode;

    // If enter is pressed -> fire click-event on the control
    if (control && (keyCode == 13))
    {
        control.focus();
        control.click();
        return false;
    }
    else
    {
        return true;
    }
}
///////////////////////////////////////
/// Expand Politic Boxes
//////////////////////////////////////
function hasCssClass(element,c) 
{
	element = xGetElementById(element);
	if (element) 
	{
		var reg = new RegExp('\\b'+c+'\\b', 'i');
		return reg.test(element.className);
	}
	return false;
}

function removeCssClassName(element, cssClass)
{
	element = xGetElementById(element);
	if ( cssClass.length > 0 && element.className.length > 0 )
	{
		var reg = new RegExp('\\b'+cssClass+'\\b', 'ig');
		var str = element.className;
		element.className = str.replace(reg, "");
	}
}

function addCssClassName(element, cssClass) 
{
	element = xGetElementById(element);
	if ( !hasCssClass(element) ) { element.className = (element.className + " " + cssClass);}
}

function toggleCssClassName(element, cssClass)
{
	element = xGetElementById(element);
	if ( hasCssClass(element, cssClass) ) 
		removeCssClassName(element, cssClass);
	else
		addCssClassName(element, cssClass);
}

function togglePoliticBox(type,state)
{
	params = PolBoxes[type];
	stateClass = "";
	if ( state != null )
	{
		state.value = state.value == "0" ? "1" : "0";
		stateClass = state.value = state.value == "0" ? "show" : "hidden";
	}
	
	if (params != null)
	{
		stringArr = params.split(';'); 
		toggleCssClassName(stringArr[0], 'hidden');
		if (state.value == "0")
		{
			removeCssClassName(stringArr[1], 'OpenAccDiv');
			toggleCssClassName(stringArr[1], 'ClosedAccDiv');
		}
		else
	
		{
			removeCssClassName(stringArr[1], 'ClosedAccDiv');
			toggleCssClassName(stringArr[1], 'OpenAccDiv');
		}
		toggleCssClassName(stringArr[1], 'ClosedAccDiv');
		toggleCssClassName(stringArr[2], 'hidden');
		toggleCssClassName(stringArr[3], 'hidden');
		state = xGetElementById(state);
		adaptDivsExpand();
	}
	else
	{
		alert('ingen boxarr ' + type ); 
	}
}		  /* */

function adaptDivsExpand()
{
    var leftDiv		   = document.getElementById('leftareadiv');
    var mainDiv		   = document.getElementById('mainareadiv');
    var rightDiv	   = document.getElementById('rightareadiv');
    var mainandleftdiv = document.getElementById('mainandleftdiv');

    // min-height
    var height = 400;
    mainDiv.style.height = 'auto';
    mainandleftdiv.style.height = 'auto';
    // find the highest div
    if (leftDiv  && leftDiv.clientHeight  > height) height = leftDiv.clientHeight;
    if (mainDiv  && mainDiv.clientHeight  > height) height = mainDiv.clientHeight;
    if (rightDiv && rightDiv.clientHeight > height)	height = rightDiv.clientHeight;
    if (mainandleftdiv && mainandleftdiv.clientHeight > height) height = mainandleftdiv.clientHeight;

    // set new height
    if (leftDiv)  leftDiv.style.height  = height + 'px';
    if (mainDiv)  mainDiv.style.height  = height + 'px';
    if (rightDiv) rightDiv.style.height = height + 'px';
    if (mainandleftdiv) mainandleftdiv.style.height = height + 'px';
}

// Open print office window
function PrintPage(url)
{

		if (document.getElementById != null)
	{
		var html = '<HTML>\n<HEAD>\n';

		html += '<LINK rel="stylesheet" type="text/css" href="http://www.socialdemokraterna.se/styles/main_edit.css">';
		
		html += '\n</HE' + 'AD>\n<BO' + 'DY class="printCopy" bgcolor="#ffffff" style="BACKGROUND-COLOR: #ffffff; background-image: "";">\n';
		html += '<style> .Normal{ font-family: arial, verdana, helvetica, tahoma; font-size: 11px; color: #000000; line-height: 14px;} body, span, div, p, td,  textarea, select{ color: #000000;}</style> '	
		html += '<div align="center" style="BACKGROUND-COLOR: #ffffff"><table cellspacing="0" width="580px"><tr>';
		html += '<td><img src="http://www.socialdemokraterna.se/images/sociald_knapp_sv.jpg" /></td>';
		html += '<td valign="bottom" align="right" style="font-weight: bold; font-size: 10px; font-family: Tahoma, Verdana, Arial, \'Trebuchet MS\'; padding-bottom: 5px;">';
		html += 'En utskrift från socialdemokraterna.se';
		html += '</td></tr><tr><td colspan="2"><hr noshade size="2" color="black" width="580px" /></td></tr><tr valign="top"><td colspan="2">';
		html += '<div id="mainareadiv">';
		
		
		var printReadyElem = document.getElementById("mainareadiv");
		
		if (printReadyElem != null)
		{
				html += printReadyElem.innerHTML;
		}
		else
		{
			alert("Could not find the printReady section in the HTML");
			return;
		}
		
		html += '</div></div></td></tr><tr><td colspan="2"><hr noshade size="2" color="black" width="580px" /></td></tr>';
		html += '<tr><td colspan="2" style="font-weight: bold; font-size: 10px; font-family: Tahoma, Verdana, Arial, \'Trebuchet MS\'; padding-bottom: 5px;">';
		html += '<center>En utskrift från socialdemokraterna.se.</center></td></tr></table></div>';
			
		html += '\n</BO' + 'DY>\n</HT' + 'ML>';		
		

		var printWin = window.open('', 'printSpecial', 'width=666,height=614,location=no,scrollbars=yes,menubar=yes,toolbar=no,resizable=no,status=yes');
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
//		if (gAutoPrint)
			printWin.print();
	}
	else
	{
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}
	



//    w = window.open(url, 'PrintOfficeWindow', 'width=666,height=614,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=no,status=yes');
//    w.focus();
}
function TipPage(url)
{
    w = window.open(url, 'PrintOfficeWindow', 'width=340,height=600,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=no,status=yes');
    w.focus();
}

/*function PoliticBox_Init()
{
	for( var i=0; i < PoliticBox.length; i++ ) 
	{
		var o = PoliticBox[i];
		var box		= xGetElementById();
		var state	= xGetElementById(o.state);
		if ( state != null && state.value == "1" )
			addClassName(o.box, o.className);
	}
}  */
function oWin(url,name,w,h){

                      var pop = window.open(url,name,'width='+w+',height='+h);

                      pop.moveTo(screen.width/2-w/2,screen.height/2-h/2);

                      pop.focus();

                      return;

}
/*Webbradiotillägg*/
function oppnaradio()
{
remote = window.open('', 'RadioAktiv', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no, width=330,height=480');
remote.location.href = 'http://213.204.177.241/webbradio/index.php';
if (remote.opener == null) remote.opener = window;
remote.opener.name = 'opener';
}

