var popup_cfg = {};
function winPopup(u, t, w, h)
{
	popup_cfg.u = u;
	popup_cfg.t = t;
	popup_cfg.w = w;
	popup_cfg.h = h;
	$("#button").trigger("click");
}

function winPopupHandler()
{
	var popup=window.open(popup_cfg.u, popup_cfg.t);
	if ( popup )
	{
		if ( popup.focus )
			popup.focus();
	}
}

$().ready(function() {
	$("body").append("<input id='button' type='button' value='button' onclick='winPopupHandler()' style='display:none;'>"); 
});

function alert_beforeunload()
{
	if ( canbeclosed == false )
	{
		return 'If you have finished uploading all the images and wish to use the service of our graphic designers then you must press the "Checkout" button to make payment first. \nRemember to "save" your work before exit.';
	}
}

function bookSaveFinishedHandler(exit)
{

}

function bookSaveCanceledHandler()
{

}

function bookInvoiceHandler(buyingPhotosID)
{
	canbeclosed = true;
	if ( buyingPhotosID != "" )
	{
 		location.href = "/design/checkout/start.php"+paramsURL()+"&buyingPhotosID="+buyingPhotosID;
 	}
 	else
 	{
 		location.href = "/design/checkout/start.php"+paramsURL();
 	}
}

var photos_todownload;
function bookDownloadHandler(photos)
{
	photos_todownload = photos;
	var win = winPopup("/design/download.html", "DownloadPhotos", 700, 500);
}

function bookHelpHandler(helpID)
{
	if ( helpID )
		winPopup("/design/help/help.php?helpID="+helpID,"_blank",750,600);
	else
		winPopup("/design/help/help.php"+paramsURL(), "_blank", 850, 600);
}

function paramsURL()
{
	var str = "?ordernum="+params.orderID;	
	str += "&userID="+params.userID;
	str += "&editor="+params.editor;
	str += "&orderID="+params.orderID;
	str += "&locale="+params.locale;
	str += "&prodID="+params.prodID;
	str += "&upload="+params.upload;
	str += "&larcodeID="+params.larcodeID;
	if ( params.direction != "" )
		str += "&direction="+params.direction;
	if ( params.state != "" )
		str += "&state="+params.state;
	if ( params.bookLoadXml != "" )
		str += "&bookLoadXml="+params.bookLoadXml;
	if ( params.prof != "" )
		str += "&prof="+params.prof;
	if ( params.admin_log != "" )
		str += "&admin_log="+params.admin_log;
	str += "&targetstate="+params.targetstate;
	return str;
}

function bookPricelistHandler()
{
 	window.open("/design/pricelist"+(params.prof>1?"":"_retails")+".php"+paramsURL(), "_blank");
}

function bookSharePopupHandler(userID, invitor, orderID)
{
	winPopup("/design/share/step1"+(params.prof>11?"_p":"")+".php"+paramsURL(), "_blank", 700, 500);
}

function bookDesignStyleConditions()
{
	window.open("/design/designStyleConditions.php", "_blank");
}

function bookOpenUrl(address,targetwin)
{
	window.open(address, targetwin);
}

function bookLogoUploadedHandler(u)
{
	
}

function bookBannerUploadedHandler(u)
{
	
}
