var _sharepageformid = '';
function autoUpdateFormField(t,old,focusblur) {
	if(!focusblur) {
		if(t.value==old) {
			t.value='';
		}
	}
	else {
		if(t.value=='') {
			t.value=old;
		}
	}
}

function doSharePage(callback, event) {
	if(checkForcedFields(event)){
		if(callback == null) {
			callback = sharePageRedrawHolder;
		}
		$('sharepageformdiv'+_sharepageformid).hide();
		$('sharepageformloader'+_sharepageformid).show();	
		var doSharePageForm = 'doWCM=sendMail&'+$('sharePageForm'+_sharepageformid).serialize();
		new Ajax.Request('/admin/ajax/ajax_sharepage.php', {method:'post', postBody:doSharePageForm, onSuccess:callback});
	}else{
		return false;
	}
}
function sharePageRedrawHolder(t,ajax) {
	if(t.responseText == 'OK') {
		$('sharePageForm'+_sharepageformid).reset();
		$('sharepageformloader'+_sharepageformid).hide();
		$('sharepageformdiv'+_sharepageformid).show();
	}
	else {
		$('sharepageformloader'+_sharepageformid).update(t.responseText);
	}
}
function sharePageHideHolder(t,ajax) {
	if(t.responseText == 'OK') {
		$('sharePageForm'+_sharepageformid).reset();
		$('sharepageformloader'+_sharepageformid).hide();
		$('sharepageformdiv'+_sharepageformid).show();
		$('emailer'+_sharepageformid).hide();
	}
}
var flashvars={};
function copyToClipBoard(text,parentId) {
	var html='';
	var btn='';
	var holderid='';
	if(parentId=='copybuttonholder'){
		var movieId = parentId;
		flashvars=text;
		btn=$('copybutton');
		holderid='copybuttonholder';
	}else{
		var movieId = 'clipboardflash_'+parentId;
		flashvars['c_'+parentId]=text;
		btn=$('copybutton_'+parentId);
		holderid='copybuttonholder_'+parentId;
	}
	var width = 20;
	var height = 20;
	var dim=btn.getDimensions();
	width = dim['width']
	height = dim['height'];
	if($(holderid)){
		if (Prototype.Browser.IE) {
			html = '<object style="top: 0; right: 0; z-index: 2; position: absolute;" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+ width +'" height="'+ height +'" id="'+movieId+'" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="/admin/script/copyuri.swf" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#000000" /><param name="wmode" value="transparent"/><param name="flashvars" value="parentId='+parentId+'" /></object>';
		}
		else {
			html = '<embed style="top: 0; right: 0; z-index: 2; position: absolute" id="'+ movieId +'" src="/admin/script/copyuri.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+ width +'" height="'+ height +'" name="'+ movieId +'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" flashvars="parentId='+parentId+'" />';
		}
		$(holderid).innerHTML += html;
	}
	if($('bloggabout')){
		$('bloggabout').hide();
		$('bloggabout').setStyle({top: '-72px', left: '54px'});
	}
	if(Prototype.Browser.Gecko && $('emailer')) {
		$('emailer').setStyle({top: '-82px', left: '88px'});	
	}
}
function getEmbedTag(parentId) {
	alert('Koden är kopierad, klistra in den i din blogg.');
	hideAllSwitchButtons('',true);
	if(!parentId){
		return flashvars;
	}	
	return flashvars['c_'+parentId];	
}
var curnid='';
function switchButtons(showid,nid,evt) {
	curnid=nid;
	if($(showid).visible()) {
		$(showid).hide();
		Event.stopObserving(document.body, 'click', hideAllSwitchButtons);
		return false;
	}
	hideAllSwitchButtons(evt,true);
	var spl=showid.split('_');
	$(showid).show();
	if(spl[0] && spl[0]=='bloggabout'){
		var dims=$('copybutton_'+spl[1]).getDimensions();
		$('clipboardflash_'+spl[1]).height=dims['height'];
		$('clipboardflash_'+spl[1]).width=dims['width'];
	}
	
	Event.stop(evt);
	Event.observe(document.body, 'click', hideAllSwitchButtons);
	return false;
}
function hideAllSwitchButtons(evt,all) {
	if(all) {
		$$('#socialbuttons_'+curnid+' li').each(function (elm) {
			elm.hide();
		});	
	}
	else {
		var elm=Event.element(evt);
		var soc = elm.up('ul.socialbuttons');
		if(typeof(soc)=='undefined' || soc==document) {
			$$('#socialbuttons_'+curnid+' li').each(function (elm) {
				elm.hide();
			});	
		}
	}
}	