// Configuration
visitInit = false;
floatboxInit = false;
sliderInit = false;
sendInit = false;
msgInit = false;
calInit = false;
addressFormInit = false;
resizeDuration = "0.3";
fadeDuration = "0.3";
elementId = null;
sliderAct = false;
sliderTabAct = null;
sendAct = false;
sendTabAct = null;
calAct = false;
loaderAct = false;
tabAct = null;
tabActUpdate =null;
turned = false;
id_tag_var = null;
choose_layout=null;
close_target=null;
contentTemp = null;
newWidthTemp =  null; 
newHeightTemp = null;
pay_check=null;
Goto_active=null;
Goto_arg=null;
pcIU = null;
status_msg = null;
//

// Postcard conf.
cardId = null;
tempCardId = null;
pageId = 1;
//



function EnterKeyLogin(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

 if (key == 13){login_script();}
}



function changeUploadedPicture(pictureId){
	//byt aktiv bild i galleriet
callUrl('changeuploadedpicture.php?id='+pictureId);

}


function showCal(){
	if(!calInit){
		var divElem = Builder.node('div', {id: 'calender'});
		Element.extend(divElem);
		$('CalBase').appendChild(divElem);
		$('calender').hide();
		calInit = true;
	}
	if(calAct){
		new Effect.Fade('calender', { from: 1, to: 0, duration: fadeDuration });
		calAct = false;
	} else {
		new Effect.Appear('calender', { from: 0, to: 1, duration: fadeDuration });
		pageUpdate('calender.php', 'calender');
		calAct = true;
	}
}

function hideMap(){
	if(visitInit){
		$('cardmap').setStyle({display: 'none'});
	}
}

function pageLoad(){
	getCardId();
	visitInit = true;
}

function registerClose(){
	if(sliderAct)
		toggleSlider();
	if(sendAct)
		toggleSend();
	if(calAct)
		showCal();
}

function turn2(){
	turned=true;
	registerClose();
	if(calInit == true){
		calInit = false;
	}
	hideMap();
	switchContent(pageId);

}

function switchContent(otherPage){
	if(otherPage == 2){
		if(!addressFormInit){
			var divElem = Builder.node('div', {id: 'recipient'});
			Element.extend(divElem);
			$('postcard').appendChild(divElem);
			$('recipient').hide();
			addressFormInit = true;
		}
		pageUpdate('addressForm.php?Card_id='+cardId + "&rand=" + Math.floor(Math.random()*1001), 'recipient');
		$('recipient').show();
		pcIU = true;


	}else{
		if(addressFormInit){
		if(pay_check==null){
			data = $('address').serialize();
			request.open("GET", 'addaddress.php'+ '?' + data, true);
			request.onreadystatechange = showFloatboxReady2;
			request.send(null);
		}
		pay_check = null;
		}else{
			postcardImageUpdate();
		}
	}
}

function turnPage(){
	if(pageId == 1){
		return 2;
	} else {
		return 1;
	}
}

function Goto_input(arg){

hideSend();
sendAct = false;

if(arg == 1){
GotoPage=1;
} if (arg == 2) {
GotoPage=2;
} if(arg==3) {
GotoPage=2;
}



if(pageId == GotoPage){
	if(arg == 1){
toggleSlider2('edit_button');
} if (arg == 2) {
toggleSlider2('edit_button');
} if(arg ==3) {
showFloatbox('newaddressdialog.php?Card_id='+cardId+'&rand=' + Math.floor(Math.random()*1001), 600, 535)
}


} else {
	
Goto_active=true;
Goto_arg=arg;
	turn();


}

}


function getCardId(){
	if (cardId == null){
	request.open("GET", "create_id.php?rand=" + Math.floor(Math.random()*1001), true);
	request.onreadystatechange = cardIdUpdate;
	request.send(null);
}
}

function getCardId1(){
	if (cardId == null){
	request.open("GET", "create_id.php?rand=" + Math.floor(Math.random()*1001), true);
	request.onreadystatechange = cardIdUpdate1;
	request.send(null);
}
}

function getCardId2(){
	request.open("GET", "create_id.php?rand=" + Math.floor(Math.random()*1001), true);
	request.onreadystatechange = cardIdUpdate2;
	pageId=1;
	request.send(null);

}

function getCardId3(){
	request.open("GET", "create_id.php?rand=" + Math.floor(Math.random()*1001), true);
	request.onreadystatechange = cardIdUpdate3;
	pageId=1;
	request.send(null);

}

function cardIdUpdate(){
	if (request.readyState == 4)
		if (request.status == 200){
			cardId = request.responseText;
			
		}
//		else if (request.status == 404)
//			alert("Request URL does not exist");
//		else
//			alert("Error: status code is " + request.status);
}

function cardIdUpdate1(){
	if (request.readyState == 4)
		if (request.status == 200){
			cardId = request.responseText;
			turn();
		}
	//	else if (request.status == 404)
	//		alert("Request URL does not exist");
	//	else
	//		alert("Error: status code is " + request.status);
}



function cardIdUpdate2(){
	if (request.readyState == 4)
		if (request.status == 200){
			cardId = request.responseText;
			pageId = 1;
			registerClose();
	
			if(calInit == true){
				calInit = false;
			}
	
			hideMap();

			switchContent(pageId);

			postcardImageUpdate();
		}
	//	else if (request.status == 404)
	//		alert("Request URL does not exist");
	//	else
	//		alert("Error: status code is " + request.status);
}

function cardIdUpdate3(){
	if (request.readyState == 4)
		if (request.status == 200){
				close_target=null;
					hideFloatBox();

			cardId = request.responseText;
			pageId = 1;
			registerClose();
	
			if(calInit == true){
				calInit = false;
			}
	
			hideMap();

			switchContent(pageId);

			postcardImageUpdate();

			
		}
	//	else if (request.status == 404)
	//		alert("Request URL does not exist");
	//	else
	//		alert("Error: status code is " + request.status);
}


// Ajax functions:
// Start and try XMLHttpRequest
var request = false;
	try {
		request = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
	    	} catch (failed) {
				request = false;
			}  
		}
	}
	if (!request)
		alert("Error initializing XMLHttpRequest!");


function empty_kundkorg() {
	request.open("GET", "empty_kundkorg.php", true);
	request.onreadystatechange = empty_kundkorgReady;
	request.send(null);
	}
	
function empty_kundkorgReady(){
	if (request.readyState == 4)
		if (request.status == 200){
			getCardId3();
		}
		/*else if (request.status == 404)
			alert("Request URL does not exist");
		else
			alert("Error: status code is " + request.status);*/
}



function send_card(){
	request.open("GET", "skicka_gratis.php?rand=" + Math.floor(Math.random()*1001), true);
	request.onreadystatechange = send_cardReady;
	pageId=1;
	request.send(null);

}

function send_cardReady(){
	if (request.readyState == 4)
		if (request.status == 200){
			if(request.responseText==1){
			getCardId3();
			showFloatbox('thanks2.php', 800, 700);
			}
			
		}
//		else if (request.status == 404)
//			alert("Request URL does not exist");
//		else
//			alert("Error: status code is " + request.status);
}





function callUrl(url) {
	request.open("GET", url, true);
	request.onreadystatechange = callUrlReady;
	request.send(null);
	}
	
function callUrlReady(){
	if (request.readyState == 4)
		if (request.status == 200){
			// Update element
		}
		/*else if (request.status == 404)
			alert("Request URL does not exist");
		else
			alert("Error: status code is " + request.status);*/
}

function callUrlLayout(url,id_tag) {
	id_tag_var = id_tag;
	request.open("GET", url, true);
	request.onreadystatechange = callUrlLayoutReady;
	request.send(null);
	}
	
function callUrlLayoutReady(){
	if (request.readyState == 4)
		if (request.status == 200){
			// Update element		  
			tabAct='';
			tabActUpdate=1;
			if(id_tag_var=='slider_nav_bild'){
			tabUpdate('foo_bild.php?Card_id='+cardId+'&Page='+pageId+ '&rand=' + Math.floor(Math.random()*1001), 'slider_content', 'slider_nav_bild');
			}else if(id_tag_var=='slider_nav_bildtext'){
			tabUpdate('foo_bildtext.php?Card_id='+cardId+'&Page='+pageId+ '&rand=' + Math.floor(Math.random()*1001), 'slider_content', 'slider_nav_bildtext');
			}

		}
		/*else if (request.status == 404)
			alert("Request URL does not exist");
		else
			alert("Error: status code is " + request.status);*/
}


function login_script() {
	data = $('login').serialize();
	request.open('GET', 'login.php?'+data+'&rand=' + Math.floor(Math.random()*1001), true);
	request.onreadystatechange = login_scriptReady;
	request.send(null);
	}
	
function login_scriptReady(){
	if (request.readyState == 4){
		if (request.status == 200){
			if(request.responseText == '1'){
			//$('logga_in_ut').innerHTML = "Logga ut";
			}
			changeFloatbox('foo_minsida.php?rand=' + Math.floor(Math.random()*1001), 600, 450);
		
		}

	}
}


function register_script() {
	data = $('register_form').serialize();
	request.open('GET', 'register.php?'+data+'&rand=' + Math.floor(Math.random()*1001), true);
	request.onreadystatechange = register_scriptReady;
	request.send(null);
	}
	
function register_scriptReady(){
	if (request.readyState == 4){
		if (request.status == 200){
			$('logga_in_ut').innerHTML = "Logga ut";
			changeFloatbox('foo_minsida.php?info='+escape(request.responseText)+'&rand=' + Math.floor(Math.random()*1001), 600, 450);
		}

	}
}


function change_script(url,item_id) {
	data = $(item_id).serialize();
	request.open('GET', url+'?'+data+'&rand=' + Math.floor(Math.random()*1001), true);
	request.onreadystatechange = change_scriptReady;
	request.send(null);
	}
	
function change_scriptReady(){
	if (request.readyState == 4){
		if (request.status == 200){
			tabAct=null;
			tabUpdate('foo_in_uppgifter.php?info='+request.responseText+'&rand=' + Math.floor(Math.random()*1001), 'inloggad_index', 'minsida_nav_uppgifter');
		}

	}
}


function callUrl2(url) {
	request.open("GET", url, true);
	request.onreadystatechange = callUrlReady2;
	request.send(null);
	}
	
function callUrlReady2(){
	if (request.readyState == 4)
		if (request.status == 200){
			// Update element
			changeFloatbox('kundkorg_preview.php?rand=' + Math.floor(Math.random()*1001),600,450);
		}
		/*else if (request.status == 404)
			alert("Request URL does not exist");
		else
			alert("Error: status code is " + request.status);*/
}

function callUrlAdressbok(url) {
	request.open("GET", url, true);
	request.onreadystatechange = callUrlAdressbokReady;
	request.send(null);
	}
	
function callUrlAdressbokReady(){
	if (request.readyState == 4)
		if (request.status == 200){
			// Update element
			tabAct = null;
			tabUpdate('foo_in_adressbok.php?rand=' + Math.floor(Math.random()*1001), 'inloggad_index', 'minsida_nav_adressbok');
		}
		/*else if (request.status == 404)
			alert("Request URL does not exist");
		else
			alert("Error: status code is " + request.status);*/
}

function callUrl3(url,id) {
	tempCardId =id;
	request.open("GET", url, true);
	request.onreadystatechange = callUrlReady3;
	request.send(null);
	}
	
function callUrlReady3(){
	if (request.readyState == 4)
		if (request.status == 200){
			// Update element
			changeFloatbox('newaddressdialog.php?Card_id='+ tempCardId +'&rand=' + Math.floor(Math.random()*1001), 600, 535);
		}
		/*else if (request.status == 404)
			alert("Request URL does not exist");
		else
			alert("Error: status code is " + request.status);*/
}



function saveContent(url,form,submitType) {
	data = $(form).serialize();
	request.open(submitType, url + '?' + data, true);
	request.onreadystatechange = saveContentReady;
	request.send(null);
	}
	
function saveContentReady(){
	if (request.readyState == 4)
		if (request.status == 200){
			// Update element
			switchContent(pageId);
			postcardImageUpdate();
		}
		/*else if (request.status == 404)
			alert("Request URL does not exist");
		else
			alert("Error: status code is " + request.status);*/
}

function saveContentRebateSend(url,form,submitType) {
	data = $(form).serialize();
	request.open(submitType, url + '?' + data, true);
	request.onreadystatechange = saveContentRebateSendReady;
	request.send(null);
	}
	
function saveContentRebateSendReady(){
	if (request.readyState == 4)
		if (request.status == 200){
			// Update element
pageUpdate('skicka.php?Card_id='+cardId+'&rand=' + Math.floor(Math.random()*1001),'innerSendSlider');
}
		/*else if (request.status == 404)
			alert("Request URL does not exist");
		else
			alert("Error: status code is " + request.status);*/
}

function saveContentRebateKundkorg(url,form,submitType) {
	data = $(form).serialize();
	request.open(submitType, url + '?' + data, true);
	request.onreadystatechange = saveContentRebateKundkorgReady;
	request.send(null);
	}
	
function saveContentRebateKundkorgReady(){
	if (request.readyState == 4)
		if (request.status == 200){
			// Update element
				pageUpdate('kundkorgen_new.php?rand=' + Math.floor(Math.random()*1001), 'innerFloatbox');
//changeFloatbox('kundkorg_new.php?rand=' + Math.floor(Math.random()*1001));
}
		/*else if (request.status == 404)
			alert("Request URL does not exist");
		else
			alert("Error: status code is " + request.status);*/
}



function saveContent2(url,form,submitType,Cid) {
	tempCardId = Cid;
	data = $(form).serialize();
	request.open(submitType, url + '?' + data, true);
	request.onreadystatechange = saveContentReady2;
	request.send(null);
	}
	
function saveContentReady2(){
	if (request.readyState == 4)
		if (request.status == 200){
			// Update element
		changeFloatbox('newaddressdialog.php?Card_id='+tempCardId+'&rand=' + Math.floor(Math.random()*1001),600,535);
		}
		/*else if (request.status == 404)
			alert("Request URL does not exist");
		else
			alert("Error: status code is " + request.status);*/
}

function saveContent3(url,form,submitType,Cid) {
	tempCardId = Cid;
	data = $(form).serialize();
	request.open(submitType, url + '?' + data, true);
	request.onreadystatechange = saveContentReady3;
	request.send(null);
	}
	
function saveContentReady3(){
	if (request.readyState == 4)
		if (request.status == 200){
			// Update element
		changeFloatbox('newaddressdialog.php?Card_id='+tempCardId+'&rand=' + Math.floor(Math.random()*1001),600,535);
		}
		/*else if (request.status == 404)
			alert("Request URL does not exist");
		else
			alert("Error: status code is " + request.status);*/
}


function searchContent(form,Cid) {
	tempCardId = Cid;
	data = $(form).serialize();
	//close_target = 'newaddressdialog.php?Card_id='+tempCardId+'&rand=' + Math.floor(Math.random()*1001);
	changeFloatbox('searchdialog.php?'+data+'&rand=' + Math.floor(Math.random()*1001),600,535);

}


function searchContentAdd(url,Cid) {
	tempCardId = Cid;
	//alert('addaddress4.php?' +url + '&Card_id='+tempCardId);
	request.open('GET', 'addaddress4.php?' +url + '&Card_id='+tempCardId, true);
	request.onreadystatechange = searchContentAddReady;
	request.send(null);
	}
	
function searchContentAddReady(){
	if (request.readyState == 4)
		if (request.status == 200){
			// Update element
		changeFloatbox('newaddressdialog.php?Card_id='+tempCardId+'&rand=' + Math.floor(Math.random()*1001),600,535);
		}
		/*else if (request.status == 404)
			alert("Request URL does not exist");
		else
			alert("Error: status code is " + request.status);*/
}


function saveContentAdressbok(url,form,submitType) {
	data = $(form).serialize();
	request.open(submitType, url + '?' + data, true);
	request.onreadystatechange = saveContentReadyAdressbok;
	request.send(null);
	}
	
function saveContentReadyAdressbok(){
	if (request.readyState == 4)
		if (request.status == 200){
			// Update element
		tabAct = null;
			tabUpdate('foo_in_adressbok.php?rand=' + Math.floor(Math.random()*1001), 'inloggad_index', 'minsida_nav_adressbok');
		}
		/*else if (request.status == 404)
			alert("Request URL does not exist");
		else
			alert("Error: status code is " + request.status);*/
}

function addtocard_function() {
	data = $('addtocard').serialize();
	request.open('GET', 'addtocard.php?Card_id='+cardId+'&' + data, true);
	request.onreadystatechange = addtocardReady;
	request.send(null);
	}
	
function addtocardReady(){
	if (request.readyState == 4)
		if (request.status == 200){
			// Update element
		hideFloatBox();
		showMsg('<div style="position:absolute;left:80px;top:70px;">Adresserna har lagts till.</div>');
		}
		/*else if (request.status == 404)
			alert("Request URL does not exist");
		else
			alert("Error: status code is " + request.status);*/
}


function pageUpdate(url, id) {
	elementId = id;
	$(elementId).update('<div id="loader_holder"><div id="loader"><img src="img/loading.gif" /></div></div>');
	$(elementId).innerHTML;
	request.open("GET", url, true);
	request.onreadystatechange = pageUpdateReady;
	request.send(null);
	}
	
function pageUpdateReady(){
	if (request.readyState == 4){
		if (request.status == 200){
			// Update element
			$(elementId).innerHTML = request.responseText;
			if(tabActUpdate==1){
						postcardImageUpdate();
			}
			if(pcIU==true){
				pcIU=false;
						postcardImageUpdate();
			}
						
		}
	}/*
	else if (request.status == 404)
		alert("Request URL does not exist");
	else
		alert("Error: status code is " + request.status);*/
}



function getPageSize(){
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}

function scrollDown(scrollElement, scrollLength){
	var elementHeight = $(scrollElement).getHeight();
	var parentElementHeight = $(scrollElement).up().getHeight();
	var elementHeightLeft = elementHeight - parentElementHeight;
	var scrollPos = $(scrollElement).getStyle('top').split('px', 1) - scrollLength;
	if(parentElementHeight >= elementHeight){
		scrollPos = 0;
	} else if ((scrollPos*-1) > elementHeightLeft){
		scrollPos = (elementHeightLeft*-1);
	}
	new Effect.Move(scrollElement, {x: 0, y: scrollPos, mode: 'absolute'});
}

function scrollUp(scrollElement, scrollLength){
	var scrollPos = parseInt($(scrollElement).getStyle('top').split('px', 1)) + scrollLength;
	if(scrollPos > 0)
		scrollPos = 0;
	new Effect.Move(scrollElement, {x: 0, y: scrollPos, mode: 'absolute'});
}

function scrollHo(scrollElement, scrollLength){
	var elementLength = $(scrollElement).getWidth();
	var parentElementLength = $(scrollElement).up().getWidth();
	var elementLengthLeft = elementLength - parentElementLength;
	var scrollPos = $(scrollElement).getStyle('left').split('px', 1) - scrollLength;
	if(parentElementLength >= elementLength){
		scrollPos = 0;
	} else if ((scrollPos*-1) > elementLengthLeft){
		scrollPos = (elementLengthLeft*-1);
	}
	new Effect.Move(scrollElement, {x: scrollPos, y: 0, mode: 'absolute'});
}

function scrollVa(scrollElement, scrollLength){
	var scrollPos = parseInt($(scrollElement).getStyle('left').split('px', 1)) + scrollLength;
	if(scrollPos > 0)
		scrollPos = 0;
	new Effect.Move(scrollElement, {x: scrollPos, y: 0, mode: 'absolute'});
}

function toggleFAQ(elementId){
	if($(elementId).next().getStyle('display') == 'none'){
		$(elementId).next().setStyle({display: 'block'});
	} else {
		$(elementId).next().setStyle({display: 'none'});
	}
	
}

function changeFloatbox(content, newWidth, newHeight){
	
	// Change width and height
	new Effect.Morph('floatbox', {style: {width: newWidth + 'px', height: newHeight + 'px', marginLeft: '-' + newWidth/2 + 'px'}, duration: resizeDuration, delay: resizeDuration });
	
	// Change content
	pageUpdate(content, 'innerFloatbox');
}

function createFloatbox(content){
	if (!floatboxInit) {
		if (content == "" || content == null) {
			var content = Builder.node('a', { href: "#", onClick: "hideFloatBox()"}, "No added content");
		}
		var background = Builder.node('div',{id:'overlay' });
		Element.extend(background);
		var divElem = Builder.node('div', { id:'floatbox' }, [
			Builder.node('a', {href: 'JavaScript:void(0)', onclick: 'hideFloatBox()', className: 'floatbox_close'}, [
				Builder.node('span', 'St&auml;ng')
			]),
			Builder.node('div', {id: 'innerFloatbox'})
		]);
		Element.extend(divElem);
		
		// Create and hide elements
		$('site_body').appendChild(background);
		$('overlay').hide();
		$('site_body').appendChild(divElem);
		$('floatbox').hide();
		
		// Add content
		pageUpdate(content, 'innerFloatbox');
		
		// stretch overlay to fill page and fade in
	    var arrayPageSize = this.getPageSize();
	    $('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
	
		floatboxInit = true;
	} else {
		pageUpdate(content, 'innerFloatbox');
	}
}


	
function showFloatboxReady(){
	if (request.readyState == 4)
		if (request.status == 200){
			// Update element
			$('recipient').hide();
			showFloatbox2(contentTemp, newWidthTemp, newHeightTemp)
		}
		/*else if (request.status == 404)
			alert("Request URL does not exist");
		else
			alert("Error: status code is " + request.status);*/
}

function showFloatboxReady2(){
	if (request.readyState == 4)
		if (request.status == 200){
				$('recipient').hide();
				postcardImageUpdate();
		}
		/*else if (request.status == 404)
			alert("Request URL does not exist");
		else
			alert("Error: status code is " + request.status);*/
}


function showFloatbox(content, newWidth, newHeight){
	
	if(addressFormInit){
	contentTemp = content;
	newWidthTemp =  newWidth; 
	newHeightTemp = newHeight;
	data = $('address').serialize();
	request.open("GET", 'addaddress.php'+ '?' + data, true);
	request.onreadystatechange = showFloatboxReady;
	request.send(null);
	}else{
		showFloatbox2(content, newWidth, newHeight)
	}
}
	function showFloatbox2(content, newWidth, newHeight){
	getCardId();
	
	// Start of construct
	createFloatbox(content);
	
	// Fade in 
	new Effect.Appear('overlay', { from: 0, to: 0.7, duration: fadeDuration });
	new Effect.Appear('floatbox', { from: 0, to: 1, duration: fadeDuration, delay: 0.2 });
	
	// Morph to right size
	new Effect.Morph('floatbox', {style: {width: newWidth + 'px', height: newHeight + 'px', marginLeft: '-' + newWidth/2 + 'px'}, duration: resizeDuration, delay: resizeDuration });
	scroll(0,0);
}


function hideFloatBox(){
	
	if(calInit == true){
		calInit = false;
	}
	
	if(close_target==null){
	if(turned==true){
	if(pageId == 2){
		if(!addressFormInit){
			var divElem = Builder.node('div', {id: 'recipient'});
			Element.extend(divElem);
			$('postcard').appendChild(divElem);
			$('recipient').hide();
			addressFormInit = true;
		}
		pageUpdate('addressForm.php?Card_id='+cardId + "&rand=" + Math.floor(Math.random()*1001), 'recipient');
		$('recipient').show();
		
	}}

	
	// Fade and morph floatbox into oblivion
	new Effect.Fade('floatbox', { from: 1, to: 0, duration: fadeDuration});
	new Effect.Morph('floatbox', {style: {width: '250px', height: '250px', marginLeft: '-125px'}, duration: resizeDuration, delay: fadeDuration });
	new Effect.Fade('overlay', { from: 0.7, to: 0, duration: fadeDuration});
	}else{

			changeFloatbox(close_target,600,450);
	}
	close_target=null;
	}

function toggleSend(content, elemId){
	if(calInit == true){
		calInit = false;
	}
	
	if(sendAct){

		if(sendTabAct == null) {
			sendTabAct = elemId;
			hideSend();
			sendAct = false;
		} else {
			hideSend();
			sendAct = false;
		}
		
		if(turned==true){
	if(pageId == 2){
		if(!addressFormInit){
			var divElem = Builder.node('div', {id: 'recipient'});
			Element.extend(divElem);
			$('postcard').appendChild(divElem);
			$('recipient').hide();
			addressFormInit = true;
		}
		pageUpdate('addressForm.php?Card_id='+cardId + "&rand=" + Math.floor(Math.random()*1001), 'recipient');
		$('recipient').show();
		
	}}
		
	} else {
		if(sliderAct)
		toggleSlider();
		
		sendTabAct = elemId;
		if(addressFormInit){
			contentTemp = content;
			data = $('address').serialize();
			request.open("GET", 'addaddress.php'+ '?' + data, true);
			request.onreadystatechange = showSendReady;
			
			
			setTimeout(request.send(null),700);
		
		}else{
		showSend(content);
		sendAct = true;
		}
		
	}
}


function toggleSend2(){
	new Effect.Fade('sendSlider', { from: 1, to: 0, duration: fadeDuration });
	new Effect.Fade('innerSendSlider', { from: 1, to: 0, duration: fadeDuration });
	new Effect.Morph('sendSlider', {style: {width: '400px', height: '10px'}, duration: resizeDuration, delay: fadeDuration });
showFloatbox('kundkorgen_new.php', 600, 450);
	$('send_button').firstDescendant().src = $('send_button').firstDescendant().src.split("_active.png", 1) + ".gif";
		$('send_button').setStyle({zIndex: '1'});
		sendAct = null;

}

function showSendReady(){
	if (request.readyState == 4)
		if (request.status == 200){
			// Update element
		$('recipient').hide();
		showSend(contentTemp);
		sendAct = true;
		}
		/*else if (request.status == 404)
			alert("Request URL does not exist");
		else
			alert("Error: status code is " + request.status);*/
}





function showMsg(content){

	// Configuration
	// End of configuration
	
	// Construct
	createMsg(content,option);

	
	// Fade in
	new Effect.Appear('msgSlider', { from: 0, to: 1, duration: fadeDuration});
	new Effect.Appear('msgShadow', { from: 0, to: 1, duration: fadeDuration});
	new Effect.Appear('innerMsgSlider', { from: 0, to: 1, duration: fadeDuration, delay: fadeDuration});
	
	
	// Morph to right size
	new Effect.Morph('msgSlider', {style: {width: '307px', height: '200px'}, duration: resizeDuration});
	
}

function createMsg(content){
	if(!msgInit){
		if (content == "" || content == null) {
			var content = Builder.node('a', { href: 'Javascript:void(0)', onClick: 'hideMsg()'}, 'No added content');
		}
		
		
		var divElem = Builder.node('div', {id: 'msgSlider'}, [
			Builder.node('div', {id: 'msgShadow'}),
			Builder.node('div', {id: 'innerMsgSlider'}),
			Builder.node('a', {href: 'JavaScript:void(0)', className: 'msg_close', onClick: 'hideMsg()'}, [
				Builder.node('span', 'St&auml;ng')]),
			Builder.node('a', {href: 'JavaScript:void(0)', className: 'msg_close2', onClick: 'hideMsg()'}, [
				Builder.node('span', 'St&auml;ng')

			])
		]);
		Element.extend(divElem);

		// Create and hide slider
		$('postcard').appendChild(divElem);
		$('msgSlider').hide();
		$('innerMsgSlider').hide();
		$('msgShadow').hide();
		
		// Add content

		$('innerMsgSlider').innerHTML = content;
		
		msgInit = true;
	} else {

		$('innerMsgSlider').innerHTML = content;
	}
}



function hideMsg(){
	
	
	// Fade and morph floatbox into oblivion
	new Effect.Fade('msgSlider', { from: 1, to: 0, duration: fadeDuration });
	new Effect.Fade('innerMsgSlider', { from: 1, to: 0, duration: fadeDuration });
	new Effect.Morph('msgSlider', {style: {width: '307px', height: '10px'}, duration: resizeDuration, delay: fadeDuration });
}



function showSend(content){

	// Configuration
	// End of configuration
	
	// Construct
	createSend(content);
	
	// Fade in
	new Effect.Appear('sendSlider', { from: 0, to: 1, duration: fadeDuration});
	new Effect.Appear('sendShadow', { from: 0, to: 1, duration: fadeDuration});
	new Effect.Appear('innerSendSlider', { from: 0, to: 1, duration: fadeDuration, delay: fadeDuration});
	
	toggleSendTab(sendTabAct);
	
	// Morph to right size
	new Effect.Morph('sendSlider', {style: {width: '400px', height: '378px'}, duration: resizeDuration});
}

function createSend(content){
	if(!sendInit){
		if (content == "" || content == null) {
			var content = Builder.node('a', { href: 'Javascript:void(0)', onClick: 'hideSend()'}, 'No added content');
		}
		var divElem = Builder.node('div', {id: 'sendSlider'}, [
			Builder.node('div', {id: 'sendShadow'}),
			Builder.node('div', {id: 'innerSendSlider'}),
			Builder.node('a', {href: 'JavaScript:void(0)', className: 'slider_close', onclick: 'toggleSend()'}, [
				Builder.node('span', 'St&auml;ng')
			])
		]);
		Element.extend(divElem);

		// Create and hide slider
		$('postcard').appendChild(divElem);
		$('sendSlider').hide();
		$('innerSendSlider').hide();
		$('sendShadow').hide();
		
		// Add content
		pageUpdate(content, 'innerSendSlider');
		
		sendInit = true;
	} else {
		pageUpdate(content, 'innerSendSlider');
	}
}

function hideSend(){
	toggleSendTab(sendTabAct);
	
	// Fade and morph floatbox into oblivion
	new Effect.Fade('sendSlider', { from: 1, to: 0, duration: fadeDuration });
	new Effect.Fade('innerSendSlider', { from: 1, to: 0, duration: fadeDuration });
	new Effect.Morph('sendSlider', {style: {width: '400px', height: '10px'}, duration: resizeDuration, delay: fadeDuration });
}


function toggleSendTab(sendTabAct){
	if(sendAct){
		// Slidern ska bli inaktiv; byt ut bilden till inaktiv och flytta ner den i Z-led
		$(sendTabAct).firstDescendant().src = $(sendTabAct).firstDescendant().src.split("_active.png", 1) + ".gif";
		$(sendTabAct).setStyle({zIndex: '1'});
	} else {
		// Slider ska bli aktiv; byt ut bilden till aktiv och flytta upp den i Z-led
		$(sendTabAct).firstDescendant().src = $(sendTabAct).firstDescendant().src.split(".gif", 1) + "_active.png";
		$(sendTabAct).setStyle({zIndex: '89'});
	}
}

function toggleSlider(content, elemId, tab, textTab, bildTab, textbildTab){
	if(sliderAct){
		if(sliderTabAct == null) {
			sliderTabAct = elemId;
			hideSlider(sliderTabAct);
			nullifyTab();
			sliderAct = false;
		} else {
			hideSlider(sliderTabAct);
			nullifyTab();
			sliderAct = false;
		}
	} else {
		if(sendAct)
			toggleSend();
		sliderTabAct = elemId;
		tabAct = tab;
		showSlider(content, sliderTabAct, textTab, bildTab, textbildTab);
		sliderAct = true;
	}
}

function toggleSliderTab(sliderTabAct){
	if(sliderAct){
		// Slidern ska bli inaktiv; byt ut bilden till inaktiv och flytta ner den i Z-led
		var path = $(sliderTabAct).firstDescendant().src.split("_active.png", 1) + ".gif";
		var img = document.createElement('img');
			img.onload = function (evt) {
				$(sliderTabAct).firstDescendant().src = this.src;
			}
		img.src = path;
		$(sliderTabAct).firstDescendant().setStyle({zIndex: '1'});
	} else {
		// Slider ska bli aktiv; byt ut bilden till aktiv och flytta upp den i Z-led
		var path = $(sliderTabAct).firstDescendant().src.split(".gif", 1) + "_active.png";
		var img = document.createElement('img');
			img.onload = function (evt) {
				$(sliderTabAct).firstDescendant().src = this.src;
			}
		img.src = path;
		$(sliderTabAct).firstDescendant().setStyle({zIndex: '81'});
	}
}


function toggleSliderTab2(sliderTabAct){
	if(sliderAct){
		// Slidern ska bli inaktiv; byt ut bilden till inaktiv och flytta ner den i Z-led
		var path = $(sliderTabAct).firstDescendant().src.split("_active.png", 1) + ".gif";
		var img = document.createElement('img');
			img.onload = function (evt) {
				$(sliderTabAct).firstDescendant().src = this.src;
			}
		img.src = path;
		$(sliderTabAct).firstDescendant().setStyle({zIndex: '1'});
	} else {
		// Slider ska bli aktiv; byt ut bilden till aktiv och flytta upp den i Z-led
		var path = $(sliderTabAct).firstDescendant().src.split(".gif", 1) + "_active.png";
		var img = document.createElement('img');
			img.onload = function (evt) {
				$(sliderTabAct).firstDescendant().src = this.src;
			}
		img.src = path;
		$(sliderTabAct).firstDescendant().setStyle({zIndex: '81'});
		
	}
}



function createSlider(content){
	if(!sliderInit){
		if (content == "" || content == null) {
			var content = Builder.node('a', { href: 'Javascript:void(0)', onClick: 'hideSlider()'}, 'No added content');
		}
		
		if(tabAct == "slider_nav_bild"){
			var bildClass = 'active';
			var textClass = 'inactive';
			var bildtextClass = 'inactive';
		}
		if(tabAct == "slider_nav_text"){
			var bildClass = 'inactive';
			var textClass = 'active';
			var bildtextClass = 'inactive';
		}
		if(tabAct == "slider_nav_bildtext"){
			var bildClass = 'inactive';
			var textClass = 'inactive';
			var bildtextClass = 'active';
		}
		
		var divElem = Builder.node('div', {id: 'slider'}, [
			Builder.node('div', {id: 'sliderShadow'}),
			Builder.node('div', {id: 'innerSlider'}, [
				Builder.node('div', {id: 'inner'}, [
					Builder.node('ul', {id: 'slider_nav'}, [
						Builder.node('li', {id: 'slider_nav_bild', className: bildClass, onclick: "tabUpdate('foo_bild.php?Card_id='+cardId+'&Page='+pageId+ '&rand=' + Math.floor(Math.random()*1001), 'slider_content', this.id)"}, [
							Builder.node('a', {href: 'JavaScript:void(0)', title: 'Bild'}, 'Bild')
						]),
						Builder.node('li', {id: 'slider_nav_text', className: textClass, onclick: "tabUpdate('foo_text.php?Card_id='+cardId+'&Page='+pageId+ '&rand=' + Math.floor(Math.random()*1001), 'slider_content', this.id)"}, [
							Builder.node('a', {href: 'JavaScript:void(0)', title: 'Text'}, 'Text')
						]),
						Builder.node('li', {id: 'slider_nav_bildtext', className: bildtextClass, onclick: "tabUpdate('foo_bildtext.php?Card_id='+cardId+'&Page='+pageId+ '&rand=' + Math.floor(Math.random()*1001), 'slider_content', this.id)"}, [
							Builder.node('a', {href: 'JavaScript:void(0)', title: 'Bild + Text'}, 'Bild + Text')
						]),
					]),
					Builder.node('div', {id: 'slider_content'})
				]),
				Builder.node('a', {href: 'JavaScript:void(0)', className: 'slider_close', onclick: 'toggleSlider()'}, [
					Builder.node('span', 'St&auml;ng')
				]),
			]),
		]);
		Element.extend(divElem);

		// Create and hide slider
		$('postcard').appendChild(divElem);
		$('slider').hide();
		$('sliderShadow').hide();
		$('innerSlider').hide();
		$('inner').hide();
		$('slider_nav').hide();
		$('slider_content').hide();
		
		// Add content
		pageUpdate(content, 'slider_content');

		
		sliderInit = true;
	} else {
		pageUpdate(content, 'slider_content');
		$(tabAct).removeClassName('inactive');
		$(tabAct).addClassName('active');
	}
}

function showSlider(content, sliderTabAct, textTab, bildTab, textbildTab){

	// Configuration
	// End of configuration
	
	// Construct
	createSlider(content);
	
	// Fade in
	new Effect.Appear('slider', { from: 0, to: 1, duration: fadeDuration});
	new Effect.Appear('sliderShadow', { from: 0, to: 1, duration: fadeDuration});
	new Effect.Appear('innerSlider', { from: 0, to: 1, duration: fadeDuration});
	new Effect.Appear('inner', { from: 0, to: 1, duration: fadeDuration});
	new Effect.Appear('slider_nav', { from: 0, to: 1, duration: fadeDuration, delay: fadeDuration});
	new Effect.Appear('slider_content', { from: 0, to: 1, duration: fadeDuration, delay: fadeDuration});
	
	toggleSliderTab(sliderTabAct);
	
	// Morph to right size
	// Get height of postcard
	//var sliderHeight = $('postcard').style.height;
	//var sliderHeight = ($('postcard').getHeight() - 15);
	//new Effect.Morph('slider', {style: {width: '310px', height: '368px'}, duration: resizeDuration});
}

function hideSlider(elemId){
	
	// Configuration
	// End of Configuration
	
	toggleSliderTab(sliderTabAct);
	
	// Fade and morph floatbox into oblivion
	new Effect.Fade('slider', { from: 1, to: 0, duration: fadeDuration });
//	new Effect.Morph('slider', {style: {width: '10px', height: '10px'}, duration: resizeDuration, delay: fadeDuration });
}

function tabUpdate(content, location, tabId) {
	if(tabAct != tabId){
	pageUpdate(content, location);
	
	if(tabId != 'minsida_nav_hem' && tabId.split('_', 1) == 'minsida'){
		if($('minsida_nav_hem').hasClassName('active')){
			$('minsida_nav_hem').removeClassName('active');
			$('minsida_nav_hem').addClassName('inactive');
		}
	}
	
	if(tabId == 'kundkorg_nav_kort'){
		if($('kundkorg_nav_lista').hasClassName('active')){
			$('kundkorg_nav_lista').removeClassName('active');
			$('kundkorg_nav_lista').addClassName('inactive');
		}
	}
	
	// Funkar inte i IE6
	if(tabAct == '' || tabAct == null){
		tabAct = tabId;
		if($(tabAct).hasClassName('inactive')){
			$(tabAct).removeClassName('inactive');
			$(tabAct).addClassName('active');
		}
	} else {
		if($(tabAct).hasClassName('active')){
			$(tabAct).removeClassName('active');
			$(tabAct).addClassName('inactive');
		}
		if($(tabId).hasClassName('inactive')){
			$(tabId).removeClassName('inactive');
			$(tabId).addClassName('active');
		}
		tabAct = tabId;
	}
}
}

function nullifyTab(){
	$(tabAct).removeClassName('active');
	$(tabAct).addClassName('inactive');
}

function chooseImage(galleryId,objId){
	url = "insert_image.php?Card_id=" + cardId + "&Gallery_id=" + galleryId + "&Page=" + pageId + "&Object_id=" + objId;
	request.open("GET", url, true);
	request.onreadystatechange = postcardUpdate;
	request.send(null);
}

function postcardUpdate(){
	if (request.readyState == 4)
		if (request.status == 200){
			pageId=1;
			request.open("GET", "toggle.php?Card_id="+cardId+"&Page="+pageId, true);
			request.onreadystatechange = toggleSliderImageReady;
			request.send(null);
}
/*else if (request.status == 404)
			alert("Request URL does not exist");
		else
			alert("Error: status code is " + request.status);*/
}

function getImage(){
	hideMap();
	registerClose();
	var url = "image_preview.php?Card_id=" + cardId + "&Page=" + pageId + "&rand=" + Math.floor(Math.random()*1001);
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(){
			var imageObj = "<img id=\"postcard_image\" src=\"" + url + "\" width=\"540px\" height=\"383px\" />";
			$('postcard_image_container').update(imageObj);
		}
	});
}

function postcardImageUpdate(){
	if(tabActUpdate==1){
	   						tabActUpdate=0;
}else{
	hideMap();
	registerClose();
}
	//$('load_slot').show();
	//$('load_slot').update('<div id="loader_holder"><div id="loader"><img src="img/loading.gif" /></div></div>');
	loaderAct = true;

	var url = "image_preview.php?Card_id=" + cardId + "&Page=" + pageId + "&rand=" + Math.floor(Math.random()*1001);
	var img = document.createElement('img');
		img.onload = function (evt) {
			$('postcard_image').src = this.src;
		//	hidePostcardLoader();
		}
		img.src = url;
	//var foobar = "<img id=\"postcard_image\" src=\"" + url + "\" width=\"540px\" height=\"383px\" />";
	//new Ajax.Request(url, {
	//	method: 'get',
	//	onSuccess: function(){
	//		var imageObj = "<img id=\"postcard_image\" src=\"" + url + "\" width=\"540px\" height=\"383px\" />";
	//		$('postcard_image_container').update(imageObj);
	//		$('postcard_image_container').innerHTML;
	//		$('postcard_image').observe('load', hidePostcardLoader);
	//	}
	//});
	//	$('postcard_image').observe('load', showpostcardimage);
	// dölj bilden medan den laddar och en till liknande observe kan visa den när den är klar.
	
if(Goto_active==true){
	
	Goto_active=false;
	if(Goto_arg == 1){
toggleSlider2('edit_button');
} if (Goto_arg == 2) {
toggleSlider2('edit_button');
} if(Goto_arg ==3) {
showFloatbox('newaddressdialog.php?Card_id='+cardId+'&rand=' + Math.floor(Math.random()*1001), 530, 535)
}
}
	
	
}

function postcardImageUpdate2(){
	if(tabActUpdate==1){
	   						tabActUpdate=0;
}else{
	hideMap();
	registerClose();
}
	//$('load_slot').show();
	//$('load_slot').update('<div id="loader_holder"><div id="loader"><img src="img/loading.gif" /></div></div>');
	loaderAct = true;

	var url = "image_preview.php?Card_id=" + cardId + "&Page=" + pageId + "&rand=" + Math.floor(Math.random()*1001);
	var img = document.createElement('img');
		img.onload = function (evt) {
			$('postcard_image').src = this.src;
		//	hidePostcardLoader();
		}
		img.src = url;
	//var foobar = "<img id=\"postcard_image\" src=\"" + url + "\" width=\"540px\" height=\"383px\" />";
	//new Ajax.Request(url, {
	//	method: 'get',
	//	onSuccess: function(){
	//		var imageObj = "<img id=\"postcard_image\" src=\"" + url + "\" width=\"540px\" height=\"383px\" />";
	//		$('postcard_image_container').update(imageObj);
	//		$('postcard_image_container').innerHTML;
	//		$('postcard_image').observe('load', hidePostcardLoader);
	//	}
	//});
	//	$('postcard_image').observe('load', showpostcardimage);
	// dölj bilden medan den laddar och en till liknande observe kan visa den när den är klar.



}


function hidePostcardLoader(){
	if(loaderAct){
		$('load_slot').update('');
		$('load_slot').innerHTML;
		$('load_slot').hide();
		loaderAct = false;
		$('postcard_image').stopObserving();
	}
}

function add_text(texten,targ){
	
//marker = document.getElementById(targ).selectionStart;
//alert(marker);
//var temp_str = document.getElementById(targ).value;
//document.getElementById(targ).value = temp_str.substr(0,marker) + texten + temp_str.substr(marker,temp_str.length);
document.getElementById(targ).value =+ texten;

}



		function betala(){

			if($('payCard').checked == true){
			showFloatbox('cardpayment.php?email='+$('email').value, 800, 700);	
			}
			else if($('paySms').checked == true){
			showFloatbox('sms.php?Cost=<? echo $over_all_cost;?>&email='+$('email').value, 600, 450);
			}
			else{
			showFloatbox('cardpayment.php?email='+$('email').value, 800, 700);	
			}
		}
			function betala2(){

			if($('payCard2').checked == true){
			showFloatbox('cardpayment.php?email='+$('email2').value, 800, 700);	
			}
			else if($('paySms2').checked == true){
			showFloatbox('sms.php?Cost=<? echo $over_all_cost;?>&email='+$('email2').value, 600, 450);
			}
			else{
			showFloatbox('cardpayment.php?email='+$('email2').value, 800, 700);
			}
		}

		function oneWay(elemId){
			if(elemId == "payCard")
				document.getElementById('paySms').checked = false;
			if(elemId == "paySms")
				document.getElementById('payCard').checked = false;
		}
		
				function oneWay2(elemId){
			if(elemId == "payCard2")
				document.getElementById('paySms2').checked = false;
			if(elemId == "paySms2")
				document.getElementById('payCard2').checked = false;
		}

	function changeCard(id){

cardId = id;
registerClose();
	
	if(calInit == true){
		calInit = false;
	}
	
	hideMap();
	
	pageId = 1;

	switchContent(pageId);

	postcardImageUpdate();


}
function displayQCalendar(m,y) {
	var ran_no=(Math.round((Math.random()*9999))); 
pageUpdate('calender.php?' + 'm='+m+'&y='+y+'&ran='+ran_no, 'calender');
}
	function addDate(dateText) {
			callUrl('adddate.php?Delivery_date=' + dateText + '&Card_id=' + cardId);
			showCal();
		}
		
	function addDate2(dateText) {

$('deliverydate').value = dateText;
		}
		
		

function displayQCalendar2(m,y) {
	var ran_no=(Math.round((Math.random()*9999))); 
	request.open('get', 'calender2.php?m='+m+'&y='+y+'&ran='+ran_no);
   	request.onreadystatechange = function() {
		if(request.readyState == 4 && request.status == 200) { 
      		var response = request.responseText;
      		if(response) { 
				$("quickCalender2").innerHTML = request.responseText; 
      		} 
   		} 
	} 
   	request.send(null); 
}
function add_text(texten,targ){
document.getElementById(targ).value += texten;
}



function toggleSlider2(id_tag){
	if(pageId==2 && addressFormInit){
			data = $('address').serialize();
			request.open("GET", 'addaddress.php'+ '?' + data, true);
			request.onreadystatechange = toggleSlider2bReady;
			setTimeout(request.send(null),700);
			
		}else{
					if (cardId == null){
	request.open("GET", 'create_id.php?rand=' + Math.floor(Math.random()*1001), true);
	request.onreadystatechange = cardIdUpdate;
	request.send(null);
}
	request.open("GET", "toggle.php?Card_id="+cardId+"&Page="+pageId + '&rand=' + Math.floor(Math.random()*1001), true);
	request.onreadystatechange = toggleSlider2Ready;
	request.send(null);
		}


}

function toggleSlider2bReady(){
	if (request.readyState == 4){
		if (request.status == 200){
			// Update element
			if (cardId == null){
	request.open("GET", 'create_id.php?rand=' + Math.floor(Math.random()*1001), true);
	request.onreadystatechange = cardIdUpdate;
	request.send(null);
}
	request.open("GET", "toggle.php?Card_id="+cardId+"&Page="+pageId + '&rand=' + Math.floor(Math.random()*1001), true);
	request.onreadystatechange = toggleSlider2Ready;
	request.send(null);
			
		}
	}
}


function toggleSlider2Ready(){
	if (request.readyState == 4){
		if (request.status == 200){
			// Update element
			var st = request.responseText;
			if (st.substr(0,1)=='1'){
				toggleSlider('foo_bild.php?Card_id='+cardId+'&Page='+pageId+ '&rand=' + Math.floor(Math.random()*1001), 'edit_button', 'slider_nav_bild', 1, 1, 0);
			}else if(st.substr(0,1)=='3'){
				toggleSlider('foo_text.php?Card_id='+cardId+'&Page='+pageId+ '&rand=' + Math.floor(Math.random()*1001), 'edit_button', 'slider_nav_text', 1, 1, 0);
			}else if(st.substr(0,1)=='2'){
				toggleSlider('foo_bildtext.php?Card_id='+cardId+'&Page='+pageId+ '&rand=' + Math.floor(Math.random()*1001), 'edit_button', 'slider_nav_bildtext', 1, 1, 0);
			}else{
				toggleSlider('foo_bild.php?Card_id='+cardId+'&Page='+pageId+ '&rand=' + Math.floor(Math.random()*1001), 'edit_button', 'slider_nav_bild', 1, 1, 0);
			}
			$('slider_nav_bild').show();
			$('slider_nav_text').show();
			$('slider_nav_bildtext').show();
			if(st.substr(1,1)==0) $('slider_nav_bild').hide();
			if(st.substr(3,1)==0) $('slider_nav_text').hide();
			if(st.substr(2,1)==0) $('slider_nav_bildtext').hide();
			
			
		}
	}
}


function turn(){
	
if (cardId == null){
	request.open("GET", "create_id.php", true);
	request.onreadystatechange = cardIdUpdate;
	request.send(null);
}
	url = "lappar.php?rand=" + Math.floor(Math.random()*1001);
	request.open("GET", url, true);
	request.onreadystatechange = turn3Update;
	request.send(null);
}
	
	

function turn3Update(){
	if (request.readyState == 4)
		if (request.status == 200){
			var response = request.responseText;
			var resp_array = response.split("$");
			
			//$('lappar_kort_1').innerHTML = resp_array[0];
			//$('lappar_kort_2').innerHTML = resp_array[1];
			
			pageId = turnPage();
			request.open("GET", "toggle.php?Card_id="+cardId+"&Page="+pageId, true);
			request.onreadystatechange = toggleSliderImageReady;
			request.send(null);
			
}

}
	
	
	
	
function toggleSliderImageReady(){
	if (request.readyState == 4){
		if (request.status == 200){
			// Update element
			var st = request.responseText;
			if (st.substr(0,1)=='1' || st.substr(0,1)=='2'){
					var path = 'img/edit_button2.gif';
			}else if(st.substr(0,1)=='3'){
					var path = 'img/edit_button.gif';
			}
			
			var img = document.createElement('img');
			img.onload = function (evt) {
				$('edit_button').firstDescendant().src = this.src;
			}
		img.src = path;
		
		if (pageId==1){
					var path = 'img/turn2.png';
			}else if(pageId==2){
					var path = 'img/turn.png';
			}
	var img = document.createElement('img');
			img.onload = function (evt) {
				$('turn_img').src = this.src;
			}
		img.src = path;
		
		turn2();	
			
		}
	}
}
var gradientshadow={};
gradientshadow.depth=10; //Depth of shadow in pixels
gradientshadow.containers=[];

gradientshadow.create=function(){
var a = document.all ? document.all : document.getElementsByTagName('*');
for (var i = 0;i < a.length;i++) {
	if (a[i].className == "shadow") {
		for (var x=0; x<gradientshadow.depth; x++){
			var newSd = document.createElement("DIV");
			newSd.className = "shadow_inner";
			newSd.id="shadow"+gradientshadow.containers.length+"_"+x; //Each shadow DIV has an id of "shadowL_X" (L=index of target element, X=index of shadow (depth) 
			if (a[i].getAttribute("rel"))
				newSd.style.background = a[i].getAttribute("rel");
			else
				newSd.style.background = "black"; //default shadow color if none specified
			document.body.appendChild(newSd);
		}
	gradientshadow.containers[gradientshadow.containers.length]=a[i];
	}
}
gradientshadow.position();
window.onresize=function(){
	gradientshadow.position();
}
}

gradientshadow.position=function(){
	if(navigator.appName=="Microsoft Internet Explorer"){
	}else{
if (gradientshadow.containers.length>0){
	for (var i=0; i<gradientshadow.containers.length; i++){
		for (var x=0; x<gradientshadow.depth; x++){
  		var shadowdiv=document.getElementById("shadow"+i+"_"+x);
			shadowdiv.style.width = gradientshadow.containers[i].offsetWidth + "px";
			shadowdiv.style.height = gradientshadow.containers[i].offsetHeight + "px";
			shadowdiv.style.left = gradientshadow.containers[i].offsetLeft + x +$('postcard_image').cumulativeOffset()[0] + "px";
			shadowdiv.style.top = gradientshadow.containers[i].offsetTop + x +$('postcard_image').cumulativeOffset()[1] + "px";


		}
	}
}}
}

if (window.addEventListener)
window.addEventListener("load", gradientshadow.create, false);
else if (window.attachEvent)
window.attachEvent("onload", gradientshadow.create);
else if (document.getElementById)
window.onload=gradientshadow.create;


function HideFontTest(){
new Effect.Fade('FontPreview', { from: 1, to: 0, duration: fadeDuration });
}

function ShowContentFontTest(imgIdName){
$('FontPreview').show();
$('FontPreview').Left = $(imgIdName).offsetLeft;
$('FontPreview').Top = $(imgIdName).offsetTop;

	var img = document.createElement('img');
			img.onload = function (evt) {
				$('FontPreviewImg').src = this.src;
			}
		img.src = 'skicka_vykort/font_example/'+$(imgIdName).value+'.jpg';
 }

