var _search_last = '';
var _search_title = new Array("bloggar", "kalender", "vimmel", "retro");
slidePos = 0;
strBrowser = browserCheck();

function urlHash() {
	hash = window.location.hash;
	if (hash.length > 8) {
		hashstr = hash.substr(8,(hash.length - 8));
		document.searchform.searchinput.value = hashstr;
		searchit(hashstr);
	}
}

function changeTitle(text) {
	if (text) {
		document.title = "• NÖJESMIX > "+text;
	} else {
		document.title = "• NÖJESMIX > NOJESMIX.com";
	}
}
function commentSwitchFacebook(obj,uid,name,pic) {
	
	if (obj.checked == true) {
		out = '<div style="float:left; margin-right:10px;"><img src="'+pic+'" width="50"/></div>';
		out += '<div style="float:left;">'+name+'</div><br clear="all" />'
		document.getElementById("comment_facebook_uid").value = uid;
		document.getElementById("comment_facebook").innerHTML = out;
		document.getElementById("comment_name").style.display = 'none';
	} else {
		document.getElementById("comment_facebook").innerHTML = "";
		document.getElementById("comment_name").style.display = 'block';
	}
}
function validateEvenemangForm()
{
	sName = document.getElementById("name").value;
	sDate = document.getElementById("date").value;
	sDesc = document.getElementById("desc").value;
	var i=1;
	var sError = '';
	if (sName.length < 3)
	{
		sError = i+') Ange ett namn på evenemanget\n';
		i++;
	}
	if (sDate.length < 10)
	{
		sError += i+') Ange ett korrekt datum, det skall vara skrivet som YYYY-MM-DD\n';
		i++;
	}
	if (sDesc.length < 5)
	{
		sError += i+') Ange en beskrivning av evenemanget\n';
		i++;
	}
	if (sError) {
		alert('Formuläret innehåller dessa fel:\n--------------------------------------------------------------------\n'+sError+'--------------------------------------------------------------------');
		return false;
	}
	return true;
}
function formDoChange(obj,type,len) {
	/*if (type == 'text') {
		if (obj.value.length <= len) {
			obj.style.color = "#ff0000";
			obj.style.border = "1px";
			obj.style.borderStyle = "solid";
			obj.style.borderColor = "#ff0000";
			document.getElementById("comment_error").innerHTML += "Texten m&aring;ste &ouml;verstiga "+len+" tecken!<br>";
			document.getElementById("comment_error").style.display = "block";
		} else {
			obj.style.color = "";
			obj.style.border = "";
			obj.style.borderStyle = "";
			obj.style.borderColor = "";
			document.getElementById("comment_error").style.display = "none";
		}
	} else if (type == 'email') {
		if (emailCheck(obj.value) == false) {
			obj.style.color = "#ff0000";
			obj.style.border = "1px";
			obj.style.borderStyle = "solid";
			obj.style.borderColor = "#ff0000";
			document.getElementById("comment_error").innerHTML += "E-postadressen är inte giltig, ändra eller ta bort den!<br>";
			document.getElementById("comment_error").style.display = "block";
		} else {
			obj.style.color = "";
			obj.style.border = "";
			obj.style.borderStyle = "";
			obj.style.borderColor = "";
			document.getElementById("comment_error").style.display = "none";
		}
	}*/
}
function emailCheck (emailStr) {

	var checkTLD=1;
	var knownDomsPat=/^(com|net|se|nu|eu|tk|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	
	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {

		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("Ths username contains invalid characters.");
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("Ths domain name contains invalid characters.");
			return false;
		}
	}
	if (user.match(userPat)==null) {
		alert("The username doesn't seem to be valid.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("The domain name does not seem to be valid.");
			return false;
		}
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}
	
	if (len<2) {
		alert("This address is missing a hostname!");
		return false;
	}
	return true;
}

//  End -->
function swapImage(base,id,ext,p) {
	document.getElementById('bigimage_'+p+'_a').href = base+id+""+ext;
	document.getElementById('bigimage_'+p).src = base+id+"_210"+ext;
}
function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}
function formSend() {
	var text = document.htmlForm.sendField.value;
	getFlashMovie("ExternalInterfaceExample").sendTextToFlash(text);
}
 
function loadVimmelComments(id) {
	document.kommentar.id.value = id;
	showVimmelComments(id);
	document.getElementById('vimmel_comments').style.display = 'block';
}
function showVimmelComments(id)
{
	if (id) {
		AjaxRequest.get(
		{
		  'url':sBaseUrl+'inc/vimmel.php?do=showcomments&id='+id
		  ,'onLoading':function() { document.getElementById("vimmel_html").innerHTML = "Laddar data..."; }
		  ,'onSuccess':function(req){ document.getElementById("vimmel_html").innerHTML=req.responseText; }
		}
	  );
	}
}
function showHideVimmelCommentForm()
{
	if (document.getElementById('comment_hidden').style.display == "block") {
		document.getElementById('comment_hidden').style.display = "none";
	} else {
		document.getElementById('comment_hidden').style.display = "block";
	}
}
function searchit(searchstr)
{
	if (searchstr.length > 1) {
		if(searchstr.length != _search_last.length){
			window.location.hash = "search="+searchstr;
			document.getElementById('searchcontent').style.display = "block";
			document.getElementById('search_header').innerHTML = 'S&ouml;kresultat';
			searchit_delayed(searchstr, 0, 100);
			searchit_delayed(searchstr, 1, 120);
			searchit_delayed(searchstr, 2, 140);
			searchit_delayed(searchstr, 3, 160);
			_search_last = searchstr;
		}
	} else {
		window.location.hash = "search=";
		document.getElementById('searchcontent').style.display = "none";
	}
}
function searchit_delayed(str,mode,delay) {
	setTimeout ("searchContent('"+str+"','"+_search_title[mode]+"')", delay);
}
function searchContent(str,target) {
  AjaxRequest.get(
    {
      'url':sBaseUrl+'inc/search.php?section='+target+'&needle='+str
	  ,'onLoading':function() { document.getElementById("searchresult_"+target).innerHTML = "Laddar data..."; }
      ,'onSuccess':function(req){ document.getElementById("searchresult_"+target).innerHTML=req.responseText; }
    }
  );
}

function doSlide() {
objSlider = document.getElementById('searchcontent');
	
	if(slidePos == 1) {
		document.getElementById('searchcontent').style.overflow="hidden";
		slide(200,(-15));
	} else {
		document.getElementById('searchcontent').style.display="block";
		slide(20,15);
	}	
}
function slide(intHeight,intStart){
	if(strBrowser == "IE") {
		document.getElementById('searchcontent').style.height = intStart;
	} else {
		document.getElementById('searchcontent').style.height = intStart + 'px;';	
	}
	//intStart += (intHeight-intStart)/5;
	if(intStart > intHeight) {
		intStart--;
	} else {
		intStart++;	
	}
	if (intStart != intHeight) {
		window.setTimeout("slide(" + intHeight + "," + intStart + ");",5);
	}
}




window.onload = function () { urlHash(); }