var timeout	= 500;
var closetimer = 0;
var ddmenuitem = 0;

function addPageView(page)
{
	//filname = document.location.href.split("/");
	//filname[filname.length-1
	setView('addViewDiv', 'list&page='+page, 'addPageView.php');
}

function goto(lnk)
{	
	self.location = lnk;
}

function mopen(id)
{	
	mcancelclosetime();

	if(ddmenuitem) ddmenuitem.style.display = 'none';

	if(document.getElementById("subMenu_"+id))
	{
		ddmenuitem = document.getElementById("subMenu_"+id);
		ddmenuitem.style.display = 'inline';
	}
}

function mclose()
{
	if(ddmenuitem) ddmenuitem.style.display = 'none';
}


function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}


function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

document.onclick = mclose; 



var win=null;

function newWindow(mypage,myname,w,h,scroll,pos)
{
	if(pos=="random")
	{
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if(pos=="center")
	{
		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;
	}
	else if((pos!="center" && pos!="random") || pos==null)
	{
		LeftPosition=0;
		TopPosition=20;
	}
	
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);
}
     

//*** AJAX START *** 
var xmlHttp;
var styrDiv = 'temp';

function setView(obj, view, file)
{ 
	styrDiv = obj;
	//document.getElementById(obj).innerHTML = "<center>Laddar...</center>";
	xmlHttp = GetXmlHttpObject()

	if (xmlHttp==null)
 	{
 		alert ("Din webbläsare stödjer inte HTTP Requests");
 		return
 	}
	
	var url = "Ajax/" + file;
	url=url+"?q2=" + view
	url=url+"&sid=" + Math.random()
	xmlHttp.onreadystatechange = stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChanged() 
{ 
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 	{document.getElementById(styrDiv).innerHTML = xmlHttp.responseText;} 
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
 	{xmlHttp=new XMLHttpRequest();} // Firefox, Opera 8.0+, Safari
	catch (e)
 	{
		try //Internet Explorer
		{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e)
		{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
 	}
	return xmlHttp;
}     
//*** AJAX SLUT *** 


function checkVote(obj, view, file, nr) 
{ 
	var motTxt = document.getElementById("motTxt").value;
	document.getElementById("motivation").style.display = "none";

	if(nr > 3)
	{
		setView(obj, view, file);
	}
	else
	{
		if(motTxt.length > 9) //om 1-3 MED motivering
		{
			view = view + "&mot="+motTxt;
			setView(obj, view, file);
			document.getElementById("motivation").value="";
		}
		else
		{
			alert("Ange en motivering med minst 10 tecken!");
			document.getElementById("motivation").style.display = "inline";
			document.getElementById("vtno").value = view;
		}
	}
}

function previewBB(bbcode)
{
	newBB = escape(bbcode);
	NewWindow('bbPreview.php?bb='+newBB,'previewBB','500','350','yes','center');
}
