/* MODALS */
function killModal() {
	var objBody = document.getElementsByTagName("body").item(0);
	objBody.removeChild(document.getElementById('imModalWrapper'));
	objBody.removeChild(document.getElementById('imModal'));
}

function popPlansModal() {
	var buttons = new Array;
	buttons['labels'] = new Array;
	buttons['functions'] = new Array;
	buttons['styles'] = new Array;
	buttons['ids'] = new Array;
	buttons['labels'][0] = 'Expire';
	buttons['labels'][1] = 'Keep';
	buttons['labels'][2] = 'Cancel';
	buttons['ids'][0] = 'expireBtn';
	buttons['ids'][1] = 'keepBtn';
	buttons['ids'][2] = 'cancelBtn';
	buttons['functions'][0] = 'expirePlan()';
	buttons['functions'][1] = 'keepPlan()';
	buttons['functions'][2] = 'killModal()';
	buttons['styles'][0] = 'modalOptionButton keyColourBg';
	buttons['styles'][1] = 'modalOptionButton keyColourBg';
	buttons['styles'][2] = 'modalOptionButton greyBg';
	
	popModal('Would you like to keep or expire your existing plan?',307,100,'You have an EXISTING PLAN...',buttons)
}

function popModal(modalTxt,width,height,modalTitle,buttons,confirmLogic) {
	var objBody = document.getElementsByTagName("body").item(0);

	var objOverlay = document.createElement("div");
	objOverlay.id = 'imModalWrapper';
	objOverlay.className =  'modalWrapperClass';
	var windowSizeY = document.body.clientHeight;
	objOverlay.style.height = windowSizeY + 'px';
	objOverlay.style.display = 'block';
	objBody.appendChild(objOverlay);
	
	var objModal = document.createElement("div");
	objModal.id = 'imModal';
	objModal.className =  'modalClass';
	objModal.style.width = width;
	
	var titleBar = document.createElement("div");
	titleBar.id = 'imModalTitleBar';
	titleBar.className = 'modalTitleBar keyColour';
	titleBar.innerHTML = modalTitle;
	objModal.appendChild(titleBar);
	
	var modalBody = document.createElement("div");
	modalBody.id = 'modalBody';
	var modalMsg = document.createElement("div");
	modalMsg.id = 'modalMsg';
	modalMsg.innerHTML = modalTxt;
	modalBody.appendChild(modalMsg);
	
	var buttonsWrapper = document.createElement("div");
	
	if(buttons=='yesNo') {
		buttonsWrapper.className = 'modalYesNoButtons';
		var yesBtn = document.createElement("a");
		yesBtn.className = 'modalOptionButton keyColourBg';
		yesBtn.id = 'yesBtn';
		if(!modalBtnLabels) yesBtn.innerHTML = 'Yes';
		else yesBtn.innerHTML = modalBtnLabels['yes'];
		yesBtn.href = 'javascript:link();'
		yesBtn.setAttribute('onclick','eval('+confirmLogic+')');
		var noBtn = document.createElement("a");
		noBtn.className = 'modalOptionButton keyColourBg';
		noBtn.id = 'noBtn';
		if(!modalBtnLabels) noBtn.innerHTML = 'No';
		else noBtn.innerHTML = modalBtnLabels['no'];
		noBtn.href = 'javascript:link();'
		noBtn.setAttribute('onclick','killModal();');
		buttonsWrapper.appendChild(yesBtn);
		buttonsWrapper.appendChild(noBtn);
	} else if(buttons['labels']) {
		buttonsWrapper.className = 'modalGenericButton';
		buttonsWrapper.style.width = (buttons['labels'].length * 75) + 'px';
		for(x=0;x<buttons['labels'].length;x++) {
			var newBtn = document.createElement("a");
			if(buttons['styles']) newBtn.className = buttons['styles'][x];
			if(buttons['ids']) newBtn.id = buttons['ids'][x];
			if(buttons['labels']) newBtn.innerHTML = buttons['labels'][x];;
			newBtn.href = 'javascript:link();'
			if(buttons['functions']) newBtn.setAttribute('onclick','eval('+buttons['functions'][x]+')');
			buttonsWrapper.appendChild(newBtn);
		}
		
	} else {
		buttonsWrapper.className = 'modalGenericButton';
		var genericBtn = document.createElement("a");
		genericBtn.className = 'modalOptionButton keyColourBg';
		genericBtn.innerHTML = 'OK';
		genericBtn.href = 'javascript:link();'
		genericBtn.setAttribute('onclick','killModal();');
		buttonsWrapper.appendChild(genericBtn);
	}
	
	buttonsWrapper.innerHTML += "<div class='cssClear'></div>";
	modalBody.appendChild(buttonsWrapper);
	objModal.appendChild(modalBody);
	
	var divWidth  = width;
	var divHeight = height;
	var windowSizeX = document.documentElement.clientWidth;
	var windowSizeY = document.documentElement.clientHeight;
	var currentScrollPos = window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop;
	objModal.style.top = (currentScrollPos+180) + 'px';
	objModal.style.left = (windowSizeX/2)-(divWidth/2)+'px';
	objBody.appendChild(objModal);	
}
