function popup(url, name, height, width, toolbar, menubar, location, scrollbar, resizable){
	window.open(url, name, "height=" + height + ",width=" + width + ",toolbar=" + toolbar + ",menubar=" + menubar + ",location=" + location + ",scrollbars=" + scrollbar + ",resizable=" + resizable);
}

function popImg(url, theWidth, theHeight){
	theWidth = parseInt(theWidth);
	theHeight = parseInt(theHeight);
	if(theWidth>theHeight){
		theWidth = 830;
		theHeight = 630;
	}else if(theWidth == theHeight){
		theWidth = 830;
		theHeight = 630;
	}else{
		theWidth = 610;
		theHeight = 610;
	}
	var imgPop = window.open(url, "popupImage", "height=" + theHeight + ",width=" + theWidth + ",toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
	imgPop.focus();
}

function isEmpty(elm, errDiv, msg){
	if(trim(elm.value) == ''){
		$('#' + errDiv).style.display='block';
		writeToDiv(errDiv, msg);
		return true;
	}
	return false;
}

function writeToDiv(id, theText){
	document.getElementById(id).innerHTML = theText;
}

function trim(strText) { 
    //leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    //trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
   return strText;
}

function hasHTML(txt){
	if( (txt.indexOf("<") > -1) || (txt.indexOf("&lt;") > -1) ){
		return true;
	}
	return false;
}

function viewBlogComments(pId, entryId, updateDiv, noCach){
	//$(document).ready(function(){
		$("#" + updateDiv).toggle("slow");
		$.post("_siteUpdate.asp", 
		{ nav: 'viewBlogComment', pId: pId, entryId: entryId },
			function(data){
		 		document.getElementById(updateDiv).innerHTML = data;
				$('.spamWarning').remove();
				$.get("/global/script/antiSpamToken.asp?noCach=" + Math.random(), function(txt){ //noCach to prevent IE-caching
					$(".secure").append('<input type="hidden" name="ts" value="'+txt+'">');	
				});
			}
		 );
	//});

	$("#closeBox").click(function(){
		$(this).hide("slow");
	});
}
	

function permaLink(updateDiv){
	$("#" + updateDiv).toggle("slow");
} 

function blogCommentPost(frm, id){
	/*if( hasHTML(theName) || hasHTML(msg) || hasHTML(email)){
		document.getElementById('errDiv' + id).innerHTML = 'Du får inte använda HTML-taggar eller tecknen "<" eller ">" i texten. Försök igen.';
		return false;
	}*/
	if(trim(frm.elements['emailFrom'].value)==''){
		document.getElementById('errDiv' + id).innerHTML = 'Du måste fylla i ditt namn';
		return false;
	}else if(trim(frm.elements['msg'].value)==''){
		document.getElementById('errDiv' + id).innerHTML = 'Du måste fylla i en kommentar';
		return false;
	}
	return true;
}

function checkGuestbookInput(frm){
	if(frm.elements['theName'].value==''){
		document.getElementById('statusMsg').innerHTML = 'Du m&aring;ste fylla i ditt namn';
		return false;
	}
	if(frm.elements['message'].value==''){
		document.getElementById('statusMsg').innerHTML = 'Du m&aring;ste skriva något i meddelanderutan';
		return false;
	}
	return true;	
}

function checkEmailForm(frm){
	if(frm.elements['senderName'].value==''){
		writeToDiv('custMailErr_20080123','Du måste fylla i ditt namn');
		return false;
	}
	if(frm.elements['senderEmail'].value==''){
		writeToDiv('custMailErr_20080123','Du måste fylla i din e-postadress');
		return false;
	}
	if(frm.elements['msgBody'].value==''){
		writeToDiv('custMailErr_20080123','Du måste fylla i ett meddelande');
		return false;
	}
	/*if(frm.elements['password'].value==''){
		writeToDiv('custMailErr_20080123','Du måste fylla i spamskyddskoden');
		return false;
	}*/
	frm.submit(); 
	return true;	
}

function showSubmen(ele){
	$('.sm2Container').css("display","none");
	document.getElementById(ele).style.display = "block";
	//$('#' + ele).show("slow");
}
function hideSubmen(ele){
	document.getElementById(ele).style.display = "none";
}
