﻿function queryString(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {
			return ft[1];
		}
	}
}

function submit() {

	var querystring = 	'?img=' + $('#img').val() + 
						'&scaleX=' + $('#scaleX').val() + 
						'&scaleY=' + $('#scaleY').val() + 
						'&x=' + $('#x').val() + 
						'&y=' + $('#y').val() + 
						'&rotation=' + $('#rotation').val() + 
						'&flipped=' + $('#flipped').val() + 
						'&friend=' + $('#FriendsFirstname').val() + 
						'&sender=' + $('#YourFirstname').val();
						
						
	var params = {
		img: $('#img').val(),
		scaleX: $('#scaleX').val(),
		scaleY: $('#scaleY').val(),
		x: $('#x').val(),
		y: $('#y').val(),
		rotation: $('#roitation').val(),
		flipped: $('#flipped').val(),
		friendsfirstname: $('#FriendsFirstname').val(),
		friendslastname: $('#FriendsLastname').val(),
		friendsemail: $('#FriendsEmail').val(),
		yourfirstname: $('#YourFirstname').val(),
		yourlastname: $('#YourLastname').val(),
		youremail: $('#YourEmail').val(),
		querystring: 'http://webbshop.svenskakyrkan.se/' + querystring + '&show=true',
		dummy: new Date().getTime()
	};
	
	//querystring: 'http://rick/shop/index.html' + querystring + '&show=true',//
	
	$.post('/FlashFileUpload/SendXmasCard.ashx', params, function(data) {
		var result= eval('(' + data + ')');
		if(result.status == 200) {
			document.location = 'dela_julkort4.html' + querystring;
		} else {
			popup('.posterror');
			
		}
	});
	
}

$(function() {
	var img = queryString('img');
	var scaleX = queryString('scaleX');
	var scaleY = queryString('scaleY');
	var x = queryString('x');
	var y = queryString('y');
	var rotation = queryString('rotation');
	var flipped = queryString('flipped');
	var sender = queryString('sender');
	var friend = queryString('friend');
	
	if(img != undefined) {
		$('#img').val(img);
	}
	if(scaleX != undefined) {
		$('#scaleX').val(scaleX);
	}
	if(scaleY != undefined) {
		$('#scaleY').val(scaleY);
	}
	if(x != undefined) {
		$('#x').val(x);
	}
	if(y != undefined) {
		$('#y').val(y);
	}
	if(rotation != undefined) {
		$('#rotation').val(rotation);
	}
	if(flipped != undefined) {
		$('#flipped').val(flipped);
	}
	
	
	$('A.xmassharepreviewlink').click(function() {
		var flashvars = {
			img: img,
			scaleX: scaleX,
			scaleY: scaleY,
			x: x,
			y: y,
			rotation: rotation,
			flipped: flipped,
			friend: $('#FriendsFirstname').val(),
			sender: $('#YourFirstname').val()
		};
		flashpopup('./Admin/Sve/Moduler/Skicka%20julkort/Flash/julkort.swf', 700, 530, flashvars);
		
		
	});
	
	$('A.xmasshareshowlink').click(function() {
		/*var qs = 	'?img=' + img + 
					'&scaleX=' + scaleX + 
					'&scaleY=' + scaleY + 
					'&x=' + x + 
					'&y=' + y + 
					'&rotation=' + rotation + 
					'&flipped=' + flipped + 
					'&show=true' + 
					'&friend=' + friend + 
					'&sender=' + sender;
		window.open('index.html' + qs,'show');*/
		
			var flashvars = {
			img: img,
			scaleX: scaleX,
			scaleY: scaleY,
			x: x,
			y: y,
			rotation: rotation,
			flipped: flipped,
			friend: friend,
			sender: sender
		};
		flashpopup('./Admin/Sve/Moduler/Skicka%20julkort/Flash/julkort.swf', 700, 530, flashvars);
		
		return false;
		
		//$(this).attr('href', 'index.html' + qs);
	});
	
	$('A.xmassharesavelink').click(function() {
		flashpopup('./Admin/Sve/Moduler/Skicka%20julkort/Flash/julkort_saveImg.swf', 700, 530);
		
	});
	
});