function popWindow(url, width, height) {
  day = new Date();
  id = day.getTime();
  wnd = window.open(url, id,'scrollbars=no, width='+width+', height='+height);
  wnd.focus();
}

function inputClick(obj) {
	if (obj.value == obj.defaultValue) {
		obj.value = '';
	}
	obj.style.color = '#000000';
}

function inputBlur(obj) {
	if (obj.value == '') {
		obj.value = obj.defaultValue;
	}
	obj.style.color = '#999999';
}

/**
 * img hover
 **/
function viewImgData(imgId) {
	$('img_'+imgId).style.display = 'block';
}
function hideImgData(imgId) {
	$('img_'+imgId).style.display = 'none';
}

/**
 * comments
 **/
function addComment(user_id, owner_id, photo_id) {
	var comment = $('comment_text').getValue();
	
	if(comment.length>1) { //string lenght 2 or more

		new Ajax.Request('/sb_comment.php', {
			method:'post',
			parameters: {req:'add',userId:user_id, ownerId: owner_id, photoId:photo_id, comment:escape(comment)},
			onSuccess: function(transport) {
				var htmldata = transport.responseText;
				$('comments').insert({top: htmldata});
				$('comment_count').innerHTML = parseInt($('comment_count').innerHTML)+1;
				$('comment_reply').style.display = 'none';
			},
			onFailure: function(){ alert('Beklager det skjedde en feil, prøvd igjen...') }
	});
	}
}
function rmComment(comment_id) {
	if(comment_id) {
	
		new Ajax.Request('/sb_comment.php', {
			method:'post',
			parameters: {req:'rm', commentId:comment_id},
			onSuccess: function(transport) {
				if(transport.responseText == "ok") {
					$('comment_'+comment_id).remove();
				}
				$('comment_count').innerHTML = parseInt($('comment_count').innerHTML)-1;
			},
			onFailure: function(){ alert('Beklager det skjedde en feil, prøvd igjen...') }
	});
	}
}

/**
 * favorites
 **/
function favorite(action, user_id) {
	if(user_id) {
	
		new Ajax.Request('/sb_favorite.php', {
			method:'post',
			parameters: {action:action,user_id:user_id},
			onSuccess: function() {
				
				if(action == 'add') {
					$('favorite').innerHTML = 'Lagt til';
				}else {
					$('favorite').innerHTML = 'Fjernet';
				}
			},
			onFailure: function(){ alert('Beklager det skjedde en feil, prøvd igjen...') }
		});
	}
}
