
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function start_hide()
{
	document.write('<!--');
}

function end_hide()
{
	document.write('-->');
}

function new_window(url) {

link = window.open(url,"Link","toolbar=0,location=0,directories=0,status=0,width=200, height=370, menubar=0,scrollbars=0,resizable=0,left=200,top=200");

}





function checkForm(ans1Req, ans2Req, ans3Req)
{
	var erStr = '';
	
	if(ans1Req)
	{
    	var answer1 = document.getElementById('answer1');
    	var question1 = document.getElementById('question1');
    	if (answer1.value == '')
        {
            erStr = 'Oblikatoriska svar fattas:\n';
    		erStr = erStr + '- ' + question1.innerHTML +' ' + "\n";
    	}
	}	
	if(ans2Req)
	{
    	var answer2 = document.getElementById('answer2');
    	var question2 = document.getElementById('question2');
    	if (answer2.value == '')
        {
    		erStr = erStr + '- ' + question2.innerHTML +' ' + "\n";
    	}
	}	
	if(ans3Req)
	{
    	var answer3 = document.getElementById('answer3');
    	var question3 = document.getElementById('question3');
    	if (answer3.value == '')
        {
    		erStr = erStr + '- ' + question3.innerHTML +' ' + "\n";
    	}
	}
	if(erStr != '')
	{
		alert(erStr);
		return false;
	}
	return true;
}










function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}






function openUrl(theURL, winName, width, height)
{
	if(!width) width = 800;
	if(!height) height = 600;

	//winName = 'Dialog ';
  	features='width='+width+',height='+height+',directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes,top=0,left=0';
	msgWindow = window.open(theURL, winName, features);
	msgWindow.focus();
}

function closeAndReload()
{
	opener.window.focus();
	opener.window.location.reload();
	self.close();
	return false;
}

function closeAndReloadAttachments()
{
	opener.window.showAttachments();
	opener.window.focus();
	window.setTimeout('self.close()', 2000);
	return false;
}



function showAttachments()
{
	var articleID = document.getElementById("articleID").value;
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get", "/admin/newsletter/archive/attachments.php?articleID="+ articleID, true);
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
            	var divAttachments = document.getElementById("divAttachments");
    			divAttachments.innerHTML = oXmlHttp.responseText;
            } else {
                //statusText is not always accurate
            }
        }
    };
    oXmlHttp.send(null);
}


function removeAttachment(attachmentID, confirmText)
{
	if(!confirm(confirmText))
	{
		return false;
	}

    var oXmlHttp = zXmlHttp.createRequest();
    oXmlHttp.open("get", "/admin/newsletter/archive/delete_attachment.php?attachmentID=" + attachmentID, true);
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
                showAttachments();
            } else {
                //statusText is not always accurate
                //alert('could not remove attachment');
            }
        }
    };
    oXmlHttp.send(null);
    return false;
}

function closeAndSubmit()
{
	opener.window.forms[0].submit();
	opener.window.focus();
	self.close();
	return false;
}

function closeWindow()
{
	opener.window.focus();
	self.close();
	return false;
}


function closeSelf()
{

	self.close();
	return false;
}



function disableForm(theform)
{
  if (document.all || document.getElementById)
  {
    for (i = 0; i < theform.length; i++)
    {
      var tempobj = theform.elements[i];
      if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
      tempobj.disabled = true;
    }
    return true;
  }
}

function tarkista_taytetyt()
{
	for (i=0; i<tarkista_taytetyt.arguments.length; i++)
	{
		if (!document.getElementById(tarkista_taytetyt.arguments[i]).value!='')
		{
			alert(tarkista_taytetyt.arguments[i] + ' puuttuu!');
			document.getElementById(tarkista_taytetyt.arguments[i]).focus();
			return false;
		}
	}
	return true;
}


function CheckFormFilled()
{
	for (i=1; i<CheckFormFilled.arguments.length; i++)
	{
		if (!document.getElementById(CheckFormFilled.arguments[i]).value!='')
		{
			errorBox(CheckFormFilled.arguments[i] + ' ' +CheckFormFilled.arguments[0]);
			document.getElementById(CheckFormFilled.arguments[i]).focus();
			return false;
		}
	}
	return true;
}

function openFullScreen(url)
{
	fs = window.open(url,"Link","toolbar=0,location=0,directories=0,status=0, menubar=0,scrollbars=0,resizable=0,left=0,top=0");
	fs.resizeTo(fs.screen.availWidth, fs.screen.availHeight);
}


function showScreen()
{
	var blurscreen = document.getElementById('blurscreen');
	blurscreen.setAttribute('class', 'displayNone');
	blurscreen.setAttribute('className', 'displayNone');

	var info = document.getElementById('info');
	info.setAttribute('class', 'displayNone');
	info.setAttribute('className', 'displayNone');

}




function InfoBox()
{
	this.setData = setData;
	this.addButton = addButton;
	this.showInfoBox = showInfoBox;
	this.setAlert = setAlert;
	this.setInfo = setInfo;
	this.addInputText = addInputText;

	var txtCaption = document.getElementById('infoboxData');
	var infoButtons = document.getElementById('infoButtons');
	var infoImg = document.getElementById('infoImg');

	var SwapImgNumber = 200;
	infoButtons.innerHTML = '';

	function setData(usrCaption)
	{
		txtCaption.innerHTML = usrCaption;
	}

	function addButton(butCaption, callBackFunc)
	{
		//infoButtons.innerHTML = infoButtons.innerHTML + '<input type="submit" value="' + butCaption +'" onclick="' + callBackFunc + '">&nbsp;';
		infoButtons.innerHTML = infoButtons.innerHTML + '<a onclick="' + callBackFunc + '" href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'Image' + SwapImgNumber +'\',\'\',\'/images/'+butCaption+'_over.jpg\',1)"><img src="/images/'+butCaption+'.jpg" name="Image' + SwapImgNumber +'" width="113" height="56" border="0" id="Image' + SwapImgNumber +'" /></a>';
		SwapImgNumber++;
		//alert(butCaption);
	}

	function addInputText(butCaption)
	{
		//infoButtons.innerHTML = infoButtons.innerHTML + '<input type="submit" value="' + butCaption +'" onclick="' + callBackFunc + '">&nbsp;';
		txtCaption.innerHTML = txtCaption.innerHTML + '<br>' + butCaption + '<input type="text" id="infoBoxInputText" class="textfieldi">';
		SwapImgNumber++;
		//alert(butCaption);
	}

	function showInfoBox()
	{
		var blurscreen = document.getElementById('blurscreen');
		blurscreen.setAttribute('class', 'blurscreen');
		blurscreen.setAttribute('className', 'blurscreen');

		/*
		//var pageSize = getDocumentSize();	// contrib by jr 20.06.2007
		var pageSize = getPageSize();
		var pageScroll = getPageScroll();

		var x = pageSize[0]+pageScroll[0];
		var y = pageSize[1]+pageScroll[1];

		//blurscreen.style.width = x + 'px';
		//blurscreen.style.height = x + 'px';

		//alert(blurscreen.style.height);
		*/

		var info = document.getElementById('info');
		info.setAttribute('class', 'info');
		info.setAttribute('className', 'info');

		var textField = document.getElementById('infoBoxInputText');	// contrib by jr 12.06.2007
		if (textField) textField.focus();
	}

	function setAlert()
	{
		infoImg.src = "/images/alert.jpg";
	}

	function setInfo()
	{
		infoImg.src = "/images/info.jpg";
	}
}

/*
function getWindowSize() {
	var dimensions = Array(2);
	dimensions['width']		= 0;
	dimensions['height']	= 0;
	if (typeof(window.innerWidth ) == 'number' ) {
		dimensions['width']		= window.innerWidth;
		dimensions['height']	= window.innerHeight;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		dimensions['width']		= document.documentElement.clientWidth;
		dimensions['height']	= document.documentElement.clientHeight;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		dimensions['width']		= document.body.clientWidth;
		dimensions['height']	= document.body.clientHeight;
	}
	return dimensions;
}

function getDocumentSize(){
	var dimensions = Array(2);
	dimensions['width']		= 0;
	dimensions['height']	= 0;


	if (window.innerHeight && window.scrollMaxY) {
		dimensions['height']	= window.innerHeight+window.scrollMaxY;
		dimensions['width']		= window.innerWidth+window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		dimensions['height']	= document.body.scrollHeight;
		dimensions['width']		= document.body.scrollWidth;
	} else if (document.body) {
		dimensions['height']	= document.body.offsetHeight+document.body.offsetTop;
		dimensions['width']		= document.body.offsetWidth+document.body.offsetLeft;

		alert(dimensions['height']);
  	}
	return dimensions;
}


function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}

	arrayPageScroll = new Array(xScroll,yScroll)
	return arrayPageScroll;
}

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}
*/


function apu()
{
	var infobox = new InfoBox();
	infobox.setAlert();
	infobox.setData('Oletko aivan varma?');
	infobox.addButton('peruuta', 'alert(\'EN\');');
	infobox.addButton('ok', 'alert(\'OLEN\');');

	infobox.showInfoBox();
}
function showAlertScreen()
{
	//alert('alert');
	apu();

	var blurscreen = document.getElementById('blurscreen');
	blurscreen.setAttribute('class', 'blurscreen');
	blurscreen.setAttribute('className', 'blurscreen');

	var info = document.getElementById('info');
	info.setAttribute('class', 'info');
	info.setAttribute('className', 'info');
}

function setActiveTab(tabNum)
{
	var curTab;
	var curFormPage;
	for(i=1;i<11;i++)
	{
		curTab = document.getElementById('form_tab_'+i);
		curFormPage = document.getElementById('form_page_'+i);
		if(curTab && curFormPage)
		{
			if(i == tabNum)
			{
				curTab.setAttribute('class', 'adminFormTabActive');
				curTab.setAttribute('className', 'adminFormTabActive');
				curFormPage.setAttribute('class', 'displayAll');
				curFormPage.setAttribute('className', 'displayAll');
			}
			else
			{
				curTab.setAttribute('class', 'adminFormTab');
				curTab.setAttribute('className', 'adminFormTab');
				curFormPage.setAttribute('class', 'displayNone');
				curFormPage.setAttribute('className', 'displayNone');
			}
		}

	}
}

function leftNaviHide()
{
	var leftNaviArrow = document.getElementById('leftNaviArrow');
	if(leftNaviArrow.src.indexOf('arrow_up.png') == -1)
	{
		leftNaviHide2();
		new Effect.MoveBy('left_navi_hidden', 0, 200, {duration:1, fps:25, from:0.0, to:1.0});
		leftNaviArrow.src = leftNaviArrow.src.replace('arrow_down.png', 'arrow_up.png');
	}
	else
	{
		new Effect.MoveBy('left_navi_hidden', 0, -200, {duration:1, fps:25, from:0.0, to:1.0});
		leftNaviArrow.src = leftNaviArrow.src.replace('arrow_up.png', 'arrow_down.png');
		window.setTimeout('leftNaviHide2()', 1000);
	}

}

function leftNaviHide2()
{
	//alert('hidden');
	var left_navi_hidden = document.getElementById('left_navi_hidden');
	if(left_navi_hidden.getAttribute('class') != 'displayNone')
	{
		left_navi_hidden.setAttribute('class', 'displayNone');
		left_navi_hidden.setAttribute('className', 'displayNone');
	}
	else
	{
		left_navi_hidden.setAttribute('class', 'displayAll');
		left_navi_hidden.setAttribute('className', 'displayAll');
	}
}

function confirmation(capt, URLobj)
{
	var infobox = new InfoBox();
	infobox.setData(capt);
	infobox.addButton('peruuta', 'showScreen()');

	if (typeof(URLobj) == 'string') infobox.addButton('ok', URLobj + '; showScreen();');
	else if(URLobj) infobox.addButton('ok', 'window.location = \'' + URLobj.href + '\'');

	infobox.showInfoBox();
	return false;
}

function errorBox(capt, URLobj)
{
	var infobox = new InfoBox();
	infobox.setAlert();
	infobox.setData(capt);
	infobox.addButton('ok', 'showScreen()');
	if(URLobj) infobox.addButton('ok', 'window.location = \'' + URLobj.href + '\'');

	infobox.showInfoBox();
	return false;
}

function forwardDialog(capt, forwardTo)
{
	var infobox = new InfoBox();
	infobox.setData(capt);
	infobox.setInfo();
	//infobox.addButton('ok', 'showScreen()');
	if(forwardTo) infobox.addButton('ok', 'window.location = \'' + forwardTo + '\'');

	infobox.showInfoBox();
	return false;
}

function textBox(capt, divToSetVal)
{
	var infobox = new InfoBox();
	infobox.setData(capt);
	infobox.addButton('peruuta', 'showScreen()');
	if(divToSetVal) infobox.addButton('ok', '');

	infobox.showInfoBox();
	return false;
}

/***** FORM **/
function saveForm(theID)
{
	if(is_defined('SpawEngine'))
	{
		//alert('Spawengine found');
		SpawEngine.updateFields();
	}

	var infobox = new InfoBox();
	infobox.setInfo();
	infobox.setData('Tietoja tallennetaan...');
	infobox.showInfoBox();

	var formData = document.getElementById(theID);

	new Ajax.Updater('popUpInfo', formData.action, {asynchronous:true, encoding:'UTF-8', parameters:Form.serialize(theID), onComplete:formSaved, onFailure:formSaveFailure, evalScripts:true});
}

function formSaveFailure()
{
	var infobox = new InfoBox();
	infobox.setAlert();
	infobox.setData('Tietojen tallennus epäonnistui. Yritä hetken kuluttua uudelleen.');
	//infobox.addButton('peruuta', '');
	infobox.addButton('ok', 'showScreen()');

	infobox.showInfoBox();
}

function formSaved()
{
	var saveSuccessful = document.getElementById('popUpInfo');

	var infobox = new InfoBox();

	if(saveSuccessful.innerHTML == 1)
	{
		infobox.setInfo();
		infobox.setData('Information är sparad');
		infobox.addButton('ok', 'showScreen()');

		infobox.showInfoBox();

	}
	else
	{
		infobox.setAlert();
		infobox.setData('Tietojen tallennus epäonnistui');
		infobox.addButton('ok', 'showScreen()');

		infobox.showInfoBox();
	}
}
/***  */

function textboxdemo()
{
	var textboxdemo = document.getElementById('textboxdemo');
	var infobox = new InfoBox();

	infobox.setInfo();
	infobox.setData('Tietojen muokkaus');
	infobox.addInputText('Tekstikenttä:');
	infobox.addButton('ok', 'settextboxdemo()');

	infobox.showInfoBox();

}
function settextboxdemo()
{
	var infoBoxInputText = document.getElementById('infoBoxInputText');
	var textboxdemo = document.getElementById('textboxdemo');
	textboxdemo.innerHTML = infoBoxInputText.value;
	showScreen();
}




function setPublished(handlerScript, dbItemID, imgPublished, parameters)
{
	if (!parameters) parameters = '';
	//alert(handlerScript+'.php?id='+dbItemID+parameters);
	new Ajax.Updater('popUpInfo', handlerScript+'.php?id='+dbItemID+parameters, {asynchronous:true, evalScripts:true});

	if(imgPublished.src.indexOf('x.png') == -1) //not x.png --> x.png
	{
		imgPublished.src = imgPublished.src.replace('y.png', 'x.png');
	}
	else
	{
		imgPublished.src = imgPublished.src.replace('x.png', 'y.png');
	}

}



function setLocked(handlerScript, dbItemID, imgLocked, parameters)
{
	if (!parameters) parameters = '';
	//alert(handlerScript+'.php?id='+dbItemID+parameters);
	new Ajax.Updater('popUpInfo', handlerScript+'.php?id='+dbItemID+parameters, {asynchronous:true, evalScripts:true});

	if(imgLocked.src.indexOf('lock_locked.png') == -1) 
	{
		imgLocked.src = imgLocked.src.replace('lock_unlocked.png', 'lock_locked.png');
	}
	else
	{
		imgLocked.src = imgLocked.src.replace('lock_locked.png', 'lock_unlocked.png');
	}

}


function is_defined( variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}

function addToCart( theID )
{
	var formData = document.getElementById(theID);

	new Ajax.Updater('shoppingCart', formData.action, {asynchronous:true, encoding:'UTF-8', parameters:Form.serialize(theID), evalScripts:true});
	//new Ajax.Updater('shoppingCart', '/ostoskori/ajax/true/lisaa/'+pubID, {asynchronous:true, evalScripts:true});
	return false;
}


function orderDetails(toActive)
{
	//alert(toActive);
	var newState = (toActive == 'yksityisTiedot') ? 'displayTableCell' : 'displayNone';
	var formPart = document.getElementById('yksityisTiedot');

	formPart.setAttribute('class', newState);
	formPart.setAttribute('className', newState);

	var newState = (toActive == 'yritysTiedot') ? 'displayTableCell' : 'displayNone';
	var formPart = document.getElementById('yritysTiedot');

	formPart.setAttribute('class', newState);
	formPart.setAttribute('className', newState);

	var newState = (toActive == 'oppilaitosTiedot') ? 'displayTableCell' : 'displayNone';
	var formPart = document.getElementById('oppilaitosTiedot');

	formPart.setAttribute('class', newState);
	formPart.setAttribute('className', newState);
}

function requestServerTime()
{
    var oXmlHttp = zXmlHttp.createRequest();
    oXmlHttp.open("get", "/admin/servertime.php", true);
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
                displayServerTime(oXmlHttp.responseText);
            } else {
                //statusText is not always accurate
            }
        }
    };
    showServerTime();
    oXmlHttp.send(null);
}

function showServerTime()
{
	window.setTimeout('requestServerTime()', 30000);
}

function startClock()
{
	requestServerTime();
	showServerTime();
}

function displayServerTime(sText)
{
    var divServerTime = document.getElementById("divServerTime");
    divServerTime.innerHTML = sText;
}

function updateImages(newsID)
{
	new Ajax.Updater('newsImages', 'images.php?newsID='+newsID, {asynchronous:true, evalScripts:true});
}


function updateImages2(itemID)
{
	new Ajax.Updater('itemImages', 'images.php?shopItemID='+itemID, {asynchronous:true, evalScripts:true});
}


function showNewsImg(thumbId, imgName, imgCaption, photographer)
{
	var newClassName = 'thumb';
	//alert(thumbId);
	var imgCount = document.getElementById('newsImgCount').innerHTML;
	for(i=1; i<=imgCount;i++)
	{
		var curImg = document.getElementById('thumbImg_'+i);
		var curImgDiv = document.getElementById('thumbImgDiv_'+i);

		if(curImg && curImgDiv)
		{
			if(thumbId == i)
			{
				newClassName = 'thumb_selected';
			}
			else newClassName = 'thumb';

			curImgDiv.setAttribute('class', newClassName);
			curImgDiv.setAttribute('className', newClassName);
		}
	}
	document.getElementById('mainImgArea').innerHTML = '<img src=/images/news/medium/'+imgName+'><p>'+imgCaption+'</p>';
	document.getElementById('name_area').innerHTML = 'Foto: '+photographer;
	//document.getElementById('imageCaption').innerHTML = imgCaption;
	//alert(imgCaption);
}

function latestIssuePrevPage()
{
	alert('prev');
	return;
	new Ajax.Updater('latestCover', 'prev.php?id='+dbItemID+parameters, {asynchronous:true, evalScripts:true});
}

function latestIssuePage(direction)
{
	//alert(direction);
	//return;
	var sivu = document.getElementById('uusin_kansi');
	if(sivu)
	{
		new Ajax.Updater('latestCover', '/pages/page.php?src='+sivu.src+'&direction='+direction, {asynchronous:true, evalScripts:true});
	}

}


function viewWebCam()
{
	//alert(direction);
	//return;
	var webcamImg = document.getElementById('webcamImg');
	if(webcamImg)
	{
		new Ajax.Updater('webcam', '/webbkamera/image.php?src='+webcamImg.src, {asynchronous:true, evalScripts:true});
	}
	showWebCam();
}


function showWebCam()
{
	window.setTimeout('viewWebCam()', 60000);
}



function CheckFormFilled2()
{
	var erStr = '';
	for (i=1; i<CheckFormFilled2.arguments.length; i++)
	{
		if (!document.getElementById(CheckFormFilled2.arguments[i]).value!='')
		{
			//alert(CheckFormFilled2.arguments[i] + ' ' +CheckFormFilled2.arguments[0] + '<br>');
			erStr = erStr + CheckFormFilled2.arguments[i] + ' ' +CheckFormFilled2.arguments[0] + "\n";
		}
	}

	if(erStr != '')
	{
		alert(erStr);
		return false;
	}
	return true;
}


function pollVote()
{
   var pollform = document.getElementById('pollform');
   var pollID = document.getElementById('pollID');
   var answer1 = document.getElementById('answer1');
   var answer2 = document.getElementById('answer2');
   var answer3 = document.getElementById('answer3');
   
   if(answer1 == null)
   {
       ans1 ='';
   }
   else
   {
       ans1 = answer1.value;
   }
   if(answer2 == null)
   {
       ans2 ='';
   }
   else
   {
       ans2 = answer2.value;
   }
   if(answer3 == null)
   {
       ans3 ='';
   }
   else
   {
       ans3 = answer3.value;
   }
   
   for (i=0, n=pollform.vote.length; i<n; i++)
   {
     if (pollform.vote[i].checked)
     {
       var checkvalue = pollform.vote[i].value;
       break;
     }
   }
   new Ajax.Updater('poll_results', '/vote.php?ajax=1&pollID='+pollID.value+'&vote='+checkvalue+'&answer1='+URLEncode(ans1)+'&answer2='+URLEncode(ans2)+'&answer3='+URLEncode(ans3), {asynchronous:true, evalScripts:true});
   document.getElementById('a_resultat').className='selected';
   document.getElementById('a_gallup').className='';
   document.getElementById('poll_questions').className='nodisp';
   document.getElementById('poll_results').className='';
   return false;
}

function SetItemDimensions(height, width, item_id)
{
  	if (height) document.getElementById(item_id).height=height;
  	if (width) document.getElementById(item_id).width=width;
}


function FileUploadDeleteAction(index, attachmentID, prefix, ID)
{
	new Ajax.Updater('attachment_'+index, prefix+'_attachment.delete.php?attachmentID='+attachmentID+'&ID='+ID);

	//Clears gap between elements
	//This prevents user seeing possible error messages.
	document.getElementById('attachment_'+index).style.display='none';
}


function InsertNewFileUploadDiv(index, new_index, ID, prefix, height, loaded_height)
{
	var newdiv = document.createElement('div');
	newdiv.id = 'attachment_'+new_index;

	newdiv.style.height = height+'px';
	newdiv.style.minHeight = '0px';
	newdiv.style.valign = 'bottom';
	newdiv.style.clear = 'both';
	//newdiv.style.border = '1px solid black';

	//newdiv.appendChild(document.createTextNode(' '));

	var newa = document.createElement('a');
	newa.href='#';
	newa.setAttribute("class", "link");
	newa.className = "link";
	newa.onclick = function() {a_onclick_event_file_upload_div(index, new_index, ID, prefix, height, loaded_height)}
	newa.innerHTML='Lägg till ny bild';
	

	newdiv.appendChild(newa);

	var scr = document.getElementById('placeholder');
	scr.parentNode.insertBefore(newdiv, scr);
}

function a_onclick_event_file_upload_div(index, new_index, ID, prefix, height, loaded_height)
{
	new Ajax.Updater('attachment_'+new_index, prefix+'_attachment_new_form.php?index='+new_index+'&ID='+ID+'&prefix='+prefix+'&height='+height+'&loaded_height='+loaded_height, {asynchronous:true, evalScripts:true})
}

function SetIframeHeight(index, height)
{
	document.getElementById('attachment_'+index).style.height=height+'px';

	var iframeElement = parent.document.getElementById('attachment_iframe_'+index);

	iframeElement.style.height = height+'px';
}

function HideElement(id)
{
	document.getElementById(id).style.display='none';
}