// to open the popup
function openPopup(url) {
	newwindow=window.open(url,'name','height=600,width=580,left=400,top=200,titlebar=no,scrollbars=yes,resizable=no,status=no,toolbar=no,menubar=no,location=no');
	if (window.focus) {newwindow.focus()}
	return false;
}
function openPopupHistory(url) {
	newwindow=window.open(url,'name','height=650,width=695,left=400,top=200,titlebar=no,scrollbars=yes,resizable=no,status=no,toolbar=no,menubar=no,location=no');
	if (window.focus) {newwindow.focus()}
	return false;
}
/* to submit when pressing enter from keyboard*/
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}
/*
	Reveal the first invisible row, containing a field to add another customer
	name and email address.  Afterwards, check to see if the maximum number of
	contact fields are being displayed.  If so, hide the "add contacts" link.
*/
function fAddContact() {
	var intVisibleContacts = 0;
	var boolFound = false;
	$("#tblEcardCustomerInfo tr").each(function() {
		if($(this).css("display") == "none") {	//	invisible
			if(!boolFound) {
				$(this).show();
				boolFound = true;
				intVisibleContacts++;
			}
		} else {	//	visible
			intVisibleContacts++;
		}
	});
	if(intVisibleContacts >= 20) {
		$("#addContact").hide();
	} else {
		$("#addContact").show();
	}
	$("#removeContact").show();
	return false;
}

/*
	Open a modal window prompting the user to upload a CSV file containing a list of contacts for an ecard to be sent to.
*/
var boolContactPromptOpen = false;
function fPromptContactList() {
//alert($("#id_freeform").val().length);
/*this is to fill out the input hidden tag with the value of txtFreeform textarea, so that it is also populated when upload contact is selected.*/
	var textvalue = $("#id_freeform").val();
	($("#txt_freeform").val(textvalue))
	var intWidth = 500;
	var intLeft = 100;
	var intTop = 100;
	fOpenModal("contactListPromptModal", "div", "contactListModal", "Upload an ecard contact list", "width=" + intWidth + "px,left=" + intLeft + "px,top=" + intTop + "px,resize=0,scrolling=0,positionRelativeToScreen=1");
	$("#contactListPromptModal .drag-contentarea").css({ height: "auto"	});
	if(document.getElementById("csvError") != undefined) {
		if(boolContactPromptOpen) {	//	hide the error if the user has closed and then reopened the modal window.
			fHide("csvError");
		}
		boolContactPromptOpen = true;
	}
	return false;
}

/*
	Remove a row from the end of the ecard contact list table if there is more
	than one visible contact.  Afterwards, check to see if there is only one
	visible contact left.  If so, hide the link to remove contacts, otherwise show
	it.
*/
function fRemoveContact() {
//alert("fRemoveContact() called.");
	var intVisibleContacts = 0;
	var boolFound = false;
	$("#tblEcardCustomerInfo tr").each(function() {
		if($(this).css("display") != "none") {	//	It is currently visible.
			intVisibleContacts++;
		}
	});
	var strRowID = "contactRow" + intVisibleContacts;
//alert("intVisibleContacts = " + intVisibleContacts + "\n$(\"#" + strRowID + "\") = " + $("#" + strRowID));
	$("#" + strRowID).css("display", "none");
//alert("$(\"#" + strRowID + " input\").val() = " + $("#" + strRowID + " input").val());
	$("#" + strRowID + " input").val("");	//	clear the value of this field.
	$("#addContact").show();
	if(intVisibleContacts <= 2) {
		$("#removeContact").hide();
	} else {
		$("#removeContact").show();
	}
	return false;
}

/*
	Indicate whether or not the current user is authorized to send an ecard.
*/
function fVerifyEcardUser() {
	if(!boolAuthorizedEcardUser) {
		alert("We're sorry, but you are not authorized to send an ecard at this time.\nPlease contact Agency Automation at 1.800.243.1334 if you have any questions.");
	} else {
		location.href = "ecards_library.php";
	}
}

function fWriteFlashDemo() {
	document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="980" height="588" id="intro" align="middle" />');
	document.writeln('<param name="allowScriptAccess" value="sameDomain" />');
	document.writeln('<param name="Movie" value="flash/Aetna_Blitz.swf" />');
	document.writeln('<param name="quality" value="high" />');
	document.writeln('<param name="wmode" value="transparent" />');
	document.writeln('<param name="bgcolor" value="#ffffff">');
	document.writeln('<embed src="flash/Aetna_Blitz.swf" wmode="transparent" bgcolor="#ffffff" quality="high" width="980" height="588" name="intro" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.writeln('</object>');
}