var isPdfCover = false;

function coverPopup()
{
	popup(500, 'lulu_cover', wizard.showSharedStripe);
	
	isPdfCover = false;
}

function submitCover()
{
	if(getInputValue("size") == -1)
	{
		updatePopupInfo("Please select the desided book size")
	}
	else
	{
		makeHTTPRequest(
			appBaseUrl + "async.php?page=lulu_code_check&lulu_code=" + getInputValue('lulu_code'),
			'GET',
			null,
			luluCodeOk,
			luluCodeError
		);
		
		updatePopupInfo('Checking Lulu code..');
	}
	return false;
}
function luluCodeOk(req)
{
	var responseCode = req.responseText;
	
	if(responseCode == 1)
	{
		downloadCover();
		
		updatePopupInfo("");
		
		updatePopup("Downloading cover...");
	}
	else
	{
		updatePopupInfo("Code error. Please check it and try again.");
	}
}
function luluCodeError(req)
{
	updatePopupInfo("Connection error. Please retry later.");
}

function downloadCover()
{
	var paramString = null;
	
	if(!isPdfCover)
	{
		var paramString = 
			'page=lulu_cover&lulu_code=' + getInputValue('lulu_code') + 
			'&size=' + getInputValue("size") + 
			'&' + wizard.lastParamString
		;
	}
	else
	{
		var paramString = 
			'page=lulu_pdf_cover&lulu_code=' + getInputValue('lulu_code') + 
			'&spine=' + getInputValue("spine") + 
			'&size=' + getInputValue("size") + 
			'&' + wizard.lastParamString
		;
	}

	location.href = 
		appBaseUrl + "async.php?" + paramString
	;
}

function openPdfCover()
{
	closePopup();
	
	popup(500, 'lulu_pdf_cover', wizard.showSharedStripe);
	
	isPdfCover = true;
}