/*
Email overlays for item and designer updates
Paul Le paul.le@net-a-porter.com
*/

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

var locale_channel = getCookie("channel"),
	overlay = "&amp;overlay=true";
 
function designerEmailUpdate(ID, opt) {
	opt = opt || {};
	opt.url = opt.url || "/"+locale_channel+"/designerUpdatesRegistration.nap?designerKey="+ID+overlay;
	
	NAP.overlayPanel ({
		title: "Designer Updates",
		message: "<iframe src='"+opt.url+"' frameborder='0' id='registration-form' name='registrationFrame' height='480' width='850'></iframe>",
		type: "info",
		theme: "light",
		addClass: 'print-dialog',
		width: 888,
		height: 554
	});
}

function registerAndMoveFromBasketToWishlist(ID, opt) {
	opt = opt || {};
	opt.url = opt.url || "/"+locale_channel+"/registerbaskettowishlist.nap?productid="+ID+overlay;

	NAP.overlayPanel ({
		title: "Sign In Required",
		message: "<iframe src='"+opt.url+"' frameborder='0' id='registration-form' name='registrationFrame' height='480' width='850'></iframe>",
		type: "info",
		theme: "light",
		addClass: 'print-dialog',
		width: 888,
		height: 554
	});
}
	
function itemEmailUpdate(ID, opt) {
	opt = opt || {};
	opt.url = opt.url || "/"+locale_channel+"/productUpdatesRegistration.nap?productId="+ID+overlay;
	opt.status = opt.status || "";

	var key = "_" + ID,
		itemStatus = (product.length == 0 || typeof product == "undefined") ? opt.status : product[key].status;

	if (itemStatus == 0 || itemStatus == "UNAVAILABLE") {
		NAP.overlayPanel ({
			title: "Item Updates",
			message: "<iframe src='"+opt.url+"' frameborder='0' id='registration-form' name='registrationFrame' height='480' width='850'></iframe>",
			type: "info",
			theme: "light",
			addClass: 'print-dialog',
			width: 888,
			height: 554
		});
	} else {
		window.location.href = "/"+locale_channel+"/product/"+ID;
	}
}


