/*
* IframeUI class
* This class will manage the display and function of iframe specific UI
*/

function IframeUI(modelObj, elId, merchantId, newURL)
{
	this.model = modelObj;
	this.pointAtEl = elId;
	this.merchantId = merchantId;
	this.newURL = newURL;
	this.windowId = -1;
}

IframeUI.prototype.setURL = function(newURL)
{
	this.newURL = newURL;
}

IframeUI.prototype.leaveSite = function()
{
	if (this.isDontShowAgain())
	{
		// create new window and go!
		var x = window.open(this.newURL);		
	}
	else
	{
		// need to either create it or show existing version of it
		this.showLeavingWindowContent();
	}	
}

IframeUI.prototype.showLeavingWindowContent = function()
{
	if (this.windowId == -1)
	{
		var container = document.createElement("div");
		container.id = "cf_leaving_container";

		var titleDiv = document.createElement("div");
		titleDiv.appendChild(document.createTextNode("Open Cellfire in new window?"));
		titleDiv.style.fontSize = "14px";
		titleDiv.style.fontWeight = "bold";
		titleDiv.style.margin = "2px 5px 10px 5px";
		container.appendChild(titleDiv);

		var messDiv = document.createElement("div");
		messDiv.appendChild(document.createTextNode("Click \"OK\" to open Cellfire.com in a new window. There you'll find instructions on how to access Cellfire Mobile with your mobile phone."));
		messDiv.style.fontSize = "12px";
		messDiv.style.margin = "2px 5px 5px 5px";
		container.appendChild(messDiv);

		var formDiv = document.createElement("div");
		formDiv.style.cssFloat = "left";
		formDiv.style.styleFloat = "left";

		var form = document.createElement("form");
		var checkBox = document.createElement("input");
		checkBox.type = "checkbox";
		checkBox.id = "cf_leaving_checkbox";
		checkBox.checked = false;

		form.appendChild(checkBox);
		formDiv.appendChild(form)
		container.appendChild(formDiv);
		
		var dontDiv = document.createElement("div");
		dontDiv.style.cssFloat = "left";
		dontDiv.style.styleFloat = "left";
		dontDiv.style.margin = "2px 0px 0px 2px";
		dontDiv.appendChild(document.createTextNode("Don't show this again"));
		
		container.appendChild(dontDiv);
		
		var c = document.createElement("div");
		c.className = "clear";
		container.appendChild(c);

		var okButtonContainer = document.createElement("div");
		okButtonContainer.style.height = "25px";
		okButtonContainer.style.textAlign = "center";
		var okButton = document.createElement("img");
		okButton.src = "/includes/templates/affiliate/" + this.model.iframeCssId + "/button_ok.jpg";
		okButton.onclick = function(){ifui.setDontShowAgain();wm.closeOpenWindow()};
		okButton.style.cursor = "pointer";
		okButton.alt = "OK";
		
		okButtonContainer.appendChild(okButton);
		
		container.appendChild(okButtonContainer);

		this.windowId = wm.createNewWhiteOutWindow(container, 350, 0, this.pointAtEl, true);
	}	
	wm.showWindow(this.windowId);
	
}

IframeUI.prototype.getCookieName = function()
{
	return "cf_if_ds_" + this.merchantId + "_" + this.model.user.id;
}	

IframeUI.prototype.setDontShowAgain = function()
{
	var cookieName = this.getCookieName();
	var expireWhen = -3;	// delete it if it exists
	var cBox = document.getElementById("cf_leaving_checkbox");
	if (cBox && cBox.checked)
	{
		expireWhen = 3;
	}	
	// set the cookie expire
	var exDate = new Date();
	exDate.setFullYear(exDate.getFullYear() + expireWhen);
	var cookieExpire = exDate.toGMTString();
	document.cookie = cookieName + "=1;expires=" + cookieExpire;
	
	// create new window and go!
	var x = window.open(this.newURL);		
}	

IframeUI.prototype.isDontShowAgain = function()
{
	var returnVal = false;
	if (document.cookie.length > 0)
	{
		returnVal = (document.cookie.indexOf(this.getCookieName()) > -1);
	}
	return returnVal;
}

IframeUI.prototype.showDeckInstructions = function()
{
	if (this.windowId == -1)
	{
		var container = document.createElement("div");
		container.id = "cf_leaving_container";

		var titleDiv = document.createElement("div");
		titleDiv.appendChild(document.createTextNode("Access coupons from your phone!"));
		titleDiv.style.fontSize = "14px";
		titleDiv.style.fontWeight = "bold";
		titleDiv.style.margin = "2px 5px 10px 5px";
		container.appendChild(titleDiv);

		var messDiv = document.createElement("div");
		messDiv.appendChild(document.createTextNode("Verizon Wireless customers can browse, save, and view coupons on the go using their mobile phone! To access Spend Smart Mobile on your Verizon Wireless phone:"));
		messDiv.style.fontSize = "12px";
		messDiv.style.margin = "2px 5px 5px 5px";
		
		messDiv.appendChild(document.createElement("br"));
		var ulist = document.createElement("ol");
		messDiv.appendChild(ulist);
		var li2 = document.createElement("li");
		li2.appendChild(document.createTextNode("Open Verizon Mobile Web or Get It Now/News & Info"));
		var li3 = document.createElement("li");
		li3.appendChild(document.createTextNode("Click More"));
		var li4 = document.createElement("li");
		li4.appendChild(document.createTextNode("Click Shopping "));
		var li5 = document.createElement("li");
		li5.appendChild(document.createTextNode("Click Spend Smart"));
		ulist.appendChild(li2);
		ulist.appendChild(li3);
		ulist.appendChild(li4);
		ulist.appendChild(li5);
		
		container.appendChild(messDiv);

		var okButtonContainer = document.createElement("div");
		okButtonContainer.style.height = "25px";
		okButtonContainer.style.textAlign = "center";
		var okButton = document.createElement("img");
		okButton.src = "/includes/templates/affiliate/" + this.model.iframeCssId + "/button_ok.jpg";
		okButton.onclick = function(){wm.closeOpenWindow()};
		okButton.style.cursor = "pointer";
		okButton.alt = "OK";
		
		okButtonContainer.appendChild(okButton);
		
		container.appendChild(okButtonContainer);

		this.windowId = wm.createNewWhiteOutWindow(container, 350, 0, this.pointAtEl, true);
	}	
	wm.showWindow(this.windowId);

}