
var BTN_SENDING = new Image();
BTN_SENDING.src = "/images/buttons/sending.gif";

var BTN_IMPORTING = new Image();
BTN_IMPORTING.src = "/images/buttons/importing.gif";

var REQUEST_SUBMITTED = false;  

monName = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

function checkCanceled(url){
	doCancel = confirm("Are you sure you want to cancel this event?");
	if(doCancel == true) {
		location.href = url;
	}
}

// Browser Detection Javascript
// copyright 1 February 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function whichBrs() {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'Firefox';
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'Internet Explorer';
if (agt.indexOf("netscape") != -1) return 'Netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
if (agt.indexOf('\/') != -1) {
if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
return navigator.userAgent.substr(0,agt.indexOf('\/'));}
else return 'Netscape';} else if (agt.indexOf(' ') != -1)
return navigator.userAgent.substr(0,agt.indexOf(' '));
else return navigator.userAgent;
}
	
function printCurrentDate() {
	now = new Date();
	time = "";
	var min = now.getMinutes();
	var sDisplayMinutes;
	var ampm = "";

	if(min > 9) {
		sDisplayMinutes = min+"";
	} else {
		sDisplayMinutes = "0"+min;
	}

	hour = now.getHours();
	if(hour >= 12) {
		if(hour > 12){
			hour = (hour-12);
		}
		ampm = "pm";
	} else {
		if(hour == 0) {
			hour = 12; // this is to avoid displaying time in millitary format.
		}
		ampm = "am";		
	}
	time = hour + ":" + sDisplayMinutes + " " + ampm;
	
	//this is a simple hack for now, wherein if the host contains ".com" or ".tmcs", the date will be
	//displaye as Month, Date and full year, otherwise it will be Date, Month, full year
	var hostStr = location.hostname;
	if(hostStr != null) {
		if(hostStr.indexOf('.com') > -1 ||
			hostStr.indexOf('.tmcs') > -1) {
			document.write(monName[now.getMonth()]+" "+now.getDate()+", "+now.getFullYear()+", "+time+".");
		} else {
			document.write(now.getDate()+" "+ monName[now.getMonth()] +", "+now.getFullYear()+", "+time+".");
		} 
	} else {
		document.write(monName[now.getMonth()]+" "+now.getDate()+", "+now.getFullYear()+", "+time+".");
	}
}

function clearValue(formField, isSubmit){
	if (formField.value == 'Search Evite') {
		formField.value = "";
		if(isSubmit) {
			alert('You must enter a search term');
		}
		return false;
	} else if (formField.value == 'Search eCards') {
		formField.value = "";
		if(isSubmit) {
			alert('You must enter a search term');
		}
		return false;
	}
}
function addToUserVenueFavorites(venueID, eUserID, venueCat, rurl){
	var urlToAddVenueFavorites = "/pages/venue/pcVenue.jsp?cmd=addFav&venueID=" + venueID + "&eUserID=" + eUserID + "&venueCat=" + venueCat + "&rurl=" + rurl;
	location.href = urlToAddVenueFavorites;
}

function executeOnEnter(element, functionToExecute) {
	element.functionToExecute = functionToExecute;
	element.onkeypress = function(e) {
		if( !e ) {
			//if the browser did not pass the event information to the
			//function, we will have to obtain it from the event register
			if( window.event ) {
				//Internet Explorer
				e = window.event;
			} else {
				//total failure, we have no way of referencing the event
				return;
			}
		}
		var characterCode;
		if(e && e.which) {
			characterCode = e.which;
		} else if (e.charCode) {
			characterCode = e.charCode;
		} else if (e.keyCode) {
			characterCode = e.keyCode;
		}
		if(characterCode == 13) {
			this.functionToExecute.call(this);
		}
	}
}

function addTextBoxElement(inputVal, inputTextVal,tobox,sort,refresh){
	if(inputVal!= ""){
			var no = new Option();
			no.value = inputVal;
			no.text =inputTextVal;
			tobox.options[tobox.options.length] = no;
	}
	if (sort){
		listBoxSort(tobox);
	}
	if(refresh){
		removeListBoxDublicates(tobox);
	}
	return;
}

function addPublicEventToEviteCalendar(cmd, eventID, userID, title){

	var height = 360;
	var width = 535;
	var urlToAdd = "/pages/gt/events/pcEvents.jsp?cmd=" + cmd + " &eventID=" + eventID + "&userID=" + userID;
   	popupWin(urlToAdd,width,height,'yes','yes','yes','no','EviteCalendar','','','center');
	popupWin('/pages/util/popEviteCalendar.jsp?title=' + title,width,height,'yes','yes','yes','no','EviteCalendar','','','center');

}
function addToCalendar(noEventTime, eventId, type){
	if (noEventTime == 'true'){
		alert('Unable to add event to Outlook / Lotus 6.0 Calendar.\nA date and time was not entered for this event.');
	} else {
		if(type == 'WINDOWS'){
			location.href=("/respond/vcal/" + eventId + "/evite.vcs?type=WINDOWS&timezoneOffSet="+(new Date()).getTimezoneOffset());
		} else {
			location.href=("/respond/vcal/" + eventId + "/evite.ics?type=OSX&timezoneOffSet="+(new Date()).getTimezoneOffset());
		}
	}
}

function addToMyYahooCalendar (noEventTime, sYahooURL){
	if (noEventTime == 'true'){
		alert('Unable to add event to My Yahoo Calendar.\nA date and time was not entered for this event.');
	} else {
		location.href="javascript:uniPop('" + sYahooURL + "','yahoo','775','725')";
	}
}

function autoGeneratePopup(){

	var eventIDLen = getURLValues('eventID');
	var popupTheKnot = true;
	if(eventIDLen != null){
		eventIDLen = eventIDLen.length;
	} else {
		eventIDLen = 0;
	}

	if(eventIDLen > 0 || eventIDLen == null){
		popupTheKnot = false;
	}
	displayTheKnotPopup(popupTheKnot);
}

function breakFrame(url){
	if(url != null){
		top.location.href = url;
	}

}
function cancelPublicEvent(eventID) {
 	if(confirm("Are you sure you want to cancel this public event?")) {
		location.href="/pages/gt/events/cancel.jsp?event=" + eventID;
	}
}

function deletePublicEventReview(pubEventID) {
 	if(confirm("Are you sure you want to delete this review?")) {
		location.href = ("/pages/gt/events/viewPub.jsp?eventID=" + pubEventID + "&deleteUserReview=true");
	}
}

function deleteVenueReview(venueID) {
 	if(confirm("Are you sure you want to delete this review?")) {
		location.href = ("/pages/venue/venueDetails.jsp?venueID=" + venueID + "&deleteUserReview=true");
	}
}

function changeUsername(form){
	form.changeUsername.value='true';
	form.submit();
}


function checkBoxes (form,checked, fieldName) {
	len = form.elements.length;
	var i=0;
	for( i=0; i<len; i++) {
		if (form.elements[i].name==fieldName){
			form.elements[i].checked=checked;
		}
	}
}

function checkCookies(){
	if (document.cookie == ""){
		return false;
	} else {
		return true;
	}
}

function checkUpdateModuleClass() {
	var formEditArray = document.editForm.elements;
	var exists = false;
	for (var i = 0; i < formEditArray.length; i++) {
		if (formEditArray[i].name == "moduleJump") {
			exists = true;
		}
	}
	if(exists) {
		document.editForm.moduleJump.value='com.evite.create.guides.ExtraQuestions';
		document.editForm.submit();
	} else {
		document.editForm.module.value='com.evite.create.guides.ExtraQuestions';
		document.editForm.submit();
	}
}

function clearCacheAllServers(){
   if(confirm("Are you sure you want to clear the cache on all servers on production?")){
 	  location.href=("/pages/admin/pcPartner.jsp?cmd=clearCacheAllServers");
   }
}

function cookiesEnabled() {
	var Expiration = new Date();
	Expiration.setTime(Expiration.getTime() + (2* 24 * 60 * 60 * 1000));
	document.cookie = "temp=test; expires=" + Expiration.toGMTString();

	offset = -1;
	if(document.cookie.length > 0) {
		offset = document.cookie.indexOf("temp=");
	}
	if (offset == -1) {
		return false;
	} else {
		document.cookie = "temp=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT";
		document.cookie = "temp; expires=Thu, 01-Jan-1970 00:00:01 GMT";
		return true;
	}
}

function createEventWithVenue(venueID){
	location.href="/pages/invitations/create/index.jsp?venueID=" + venueID;
}

function createEviteEvent(eventType){
	location.href="/compose?type=" + eventType;
}

function deleteInviteMessage(messageID, rurl){
 	if(confirm("Are you sure you want to delete this message from the invite?")) {
		location.href="/pages/invite/pcInvite.jsp?cmd=deleteInviteMessage&inviteMessageID=" + messageID + "&rurl=" + rurl;
	}
}

function deletePublicEventCalendarItem(cmd, userID, eventID, rurl) {
 	if(confirm("Are you sure you want to delete this item from your calendar?")) {
		location.href="/pages/gt/events/pcEvents.jsp?cmd=" + cmd + " &eventID=" + eventID + "&userID=" + userID + "&rurl=" + rurl;
	}
}

function deleteEvent(eventID, rurl) {
 	if(confirm("Are you sure you want to delete this draft?")) {
		location.href=("/schedule/delDraft/noheaders/expireNow?eventID=" + eventID + "&rurl=" + rurl);
	}
}

function deleteDesignTheme(themeID, themeDispName, returnURL) {
	if(confirm("Are you sure you want to delete the design theme: " + themeDispName + "?")) {
		var url ="/pages/admin/pcDesignTheme.jsp?&cmd=delete&themeID=" + themeID + "&returnURL=" + returnURL;
		document.location = url;
	}
}

function deleteArtist(artistId, artistName, returnURL) {
	if(confirm("Are you sure you want to delete the artist name: " + artistName + "?")) {
		var url ="/pages/admin/editArtist.jsp?&cmd=delete&artistId=" + artistId + "&returnURL=" + returnURL;
		document.location = url;
	}
}

function confirmAndForward(msg, url) {
	if(confirm(msg)) {
		document.location = url;
	}
}

function changeActionAndSubmit(form, action) {
	form.action = action;
	form.submit();
}

function deleteEmail(form, email, rurl) {
	form.rurl.value = rurl;
	form.cmd.value = 'update';
	form.cmd2.value = 'profile';
	form.submit();
	var url = '/pages/profile/deleteEmail.jsp?deleteEmail=' + email;
	document.location = url;
}


function deleteEventType(eventTypeID,returnURL) {
	if(confirm("Are you sure you want to delete the event type: " + eventTypeID + "?")) {
		var url ="/pages/admin/pcEventType.jsp?&cmd=delete&eventTypeID=" + eventTypeID + "&returnURL=" + returnURL;
		document.location = url;
	}
}

function deleteInvite(inviteID) {
	if(confirm("Are you sure you want to delete this invite?")) {
		location.href=("/schedule/delInvite/noheaders/expireNow?iid=" + inviteID);
	}
}


function deletePhoto(returnURL) {
	if(confirm("Are you sure you want to delete your photo ?")) {
		var url ="/pages/gt/people/pcProfile.jsp?&cmd=deletePhoto&rurl=" + returnURL;
		document.location = url;
	}
}

function deletePublicEvent(eventID, rurl) {
	if(confirm("Are you sure you want to delete the entire Event?")) {
 		location.href=("/pages/gt/events/cancel.jsp?event=" + eventID + "&rurl=" + rurl);
 	}
}

function deletePublicInvite(eventID,inviteID) {
	if(confirm("Are you sure you want to be taken off the guest list?")) {
 		location.href=("/pages/gt/events/cancel.jsp?event=" + eventID + "&inviteID=" + inviteID);
 	}
}

function displayTheKnotPopup(popupTheKnot){
	var eventID = '';
	var location = '';
	var eventType = '';
	var partner = '';
	if(document.eventForm != null){
		eventID = document.eventForm.eventID.value;
		location = document.eventForm.theKnotLocation.value;
		eventType = document.eventForm.type.value;
		if(eventType == null){
			eventType = getURLValues('type');
		}
		partner = getPartnerValue();
		if(eventType == 'Wedding_Themes_top' || partner == 'theknot'){
			if(popupTheKnot != false){
		    	popupWin('/pages/partners/theknot/registrySearch.jsp?eventID=' + eventID+ '&loc=' + location,'515','400','yes','yes','yes','no','TheKnotRegistrySearch','','','topright');
		    	document.eventForm.theKnot.value='true';
		    	document.eventForm.details.value='OK';
				document.eventForm.submit();
			}
		}
	}
}

function inviteSearchKeywordDown(form,e){
    if (e.keyCode == 13){
    		venueSearch('places', form.citystatezip.value, '', 25, '', form.keywords.value);
     }
 }


function pushDesignGallery(){
  if(confirm("Are you sure you want to push the Design Gallery to production?")){
  	location.href=("/pages/admin/pcPartner.jsp?cmd=pushDesignGallery");
   }
}

function pushEvitePolls(){
   if(confirm("Are you sure you want to push Evite Polls to production?")){
   		location.href=("/pages/admin/pcEvitePollAdmin.jsp?cmd=pushEvitePoll");
   }
}

function sendDynamicTextToYahoo(partnerId, message) {
	if(confirm("Are you sure you want to send the dynamic text to the My Yahoo Module?")) {
		var rurl = "/pages/admin/dynamicText.jsp?partnerId=" + partnerId + "&cmd=sendMessage";
		rurl = escape(rurl);
		location.href=("/pages/admin/pcPartner.jsp?partnerId=" + partnerId + "&message=" + message + "&cmd=sendMessage&rurl=" + rurl);
	}
}

function generateRandom() {
    if (Math.random)
        return Math.round(Math.random() * 1000000);
    else {
        var now = new Date();
        return (now.getTime() / 1000) % 10000;
    }
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
  begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function getElement(eid) {
   if (document.all) {
      return document.all[eid];
   }
      if (document.getElementById) {
		return document.getElementById(eid);
   }
}

function getPartnerValue(name) {
// This parses the url and determines the host.  For example
// http://xxx.evite.com will return xxx.

	var url = window.location.href;
	var partner = '';
	var searchString = url.substring(7);
	var endValue = searchString.indexOf('.');
	if(endValue > 0){
		partner = searchString.substring(0,endValue);
	}
	return unescape(partner);
}

function getRadioValue(oRadioGrp){
 var sValue = null;
 if (typeof oRadioGrp.length == "undefined"){
  // get value for single radio button
  if (oRadioGrp.checked)
   sValue = oRadioGrp.value;
 } else {
  // get value for group of radio buttons
  for (var i=oRadioGrp.length-1; i>=0; i--){
   if (oRadioGrp[i].checked){
    sValue = oRadioGrp[i].value;
   }
  }
 }
 return sValue;
}

function getURLValues(name) {
	var url = window.location.href;
	var searchStart = url.indexOf('?');
	if (searchStart < 0){
		return null;
	}
	var searchString = url.substring(searchStart+1);
	var namePosition = searchString.indexOf(name);
	if (namePosition < 0){
		return null;
		}
	var pairIndicatorPos = searchString.indexOf('=',(namePosition+1));
	if (pairIndicatorPos < 0){
		return null;
		}
	var nextDelimiter = searchString.indexOf('&', pairIndicatorPos);
	if (nextDelimiter < 0){
		var endOfValue = searchString.length;
		}
	else{
		var endOfValue = nextDelimiter;
		}
	if (pairIndicatorPos == (endOfValue-1)){
		return null;
		}
	var value = searchString.substring((pairIndicatorPos+1), endOfValue);
		return unescape(value);
}

function goBack(){
	history.back();
}

function goToURL(rurl){
	top.document.location=rurl;
}

// Checks for null
function isNull(val){
	val += "";
	if ((val == "null") || (val == "") || (val == "undefined")){
		return true;
	}else{
		return false;
	}
}

function limitText(field, maxlimit) {
	if (field.value.length > maxlimit) {
		alert("You've reached the character limit.");
		field.value = field.value.substring(0, maxlimit);
	}
}

function listBoxBumpUp(box){
	for(var i=0; i<box.options.length; i++){
		if(box.options[i].value == ""){
			for(var j=i; j<box.options.length-1; j++){
				box.options[j].value = box.options[j+1].value;
				box.options[j].text = box.options[j+1].text;
			}
			var ln = i
			;
			break;
		}
	}
	if(ln < box.options.length){
		box.options.length -= 1;
		listBoxBumpUp(box);
	}
	return;
}

function listBoxMoveUpDown(box,direction, returnIndex){
	var index = box.selectedIndex;
	if(index != -1){
		var nextIndex = index +( direction? -1 : 1);
		if (nextIndex < 0 ){
			nextIndex = box.options.length-1;
		}
		if (nextIndex >= box.options.length) {
			nextIndex = 0;
		}
		var oldVal = box.options[index].value;
		var oldText = box.options[index].text;
		box.options[index].value = box.options[nextIndex].value;
		box.options[index].text = box.options[nextIndex].text;
		box.options[index].selected = false;
		box.options[nextIndex].value = oldVal;
		box.options[nextIndex].text = oldText;
		box.options[nextIndex].selected = true;
		//box.selectedIndex = nextIndex;
		
		if( returnIndex) {
			return nextIndex;
		}	
	}
	
	if( returnIndex) {
		return -1;
	}
}

function listBoxMoveToTop(box){
	while( listBoxMoveUpDown(box, -1, true) > 0 ){}
}

function listBoxMoveToBottom(box){
	while( listBoxMoveUpDown(box, 1, true) < box.options.length-1 ){}
}

function listBoxSort(box){
	var temp_opts = new Array();
	var temp = new Object();
	for(var i=0; i<box.options.length; i++){
		temp_opts[i] = box.options[i];
	}
	for(var x=0; x<temp_opts.length-1; x++){
		for(var y=(x+1); y<temp_opts.length; y++){
			if(temp_opts[x].text > temp_opts[y].text){
				temp = temp_opts[x].text;
				temp_opts[x].text = temp_opts[y].text;
				temp_opts[y].text = temp;
				temp = temp_opts[x].value;
				temp_opts[x].value = temp_opts[y].value;
				temp_opts[y].value = temp;
			}
		}
	}
	for(var i=0; i<box.options.length; i++){
		box.options[i].value = temp_opts[i].value;
		box.options[i].text = temp_opts[i].text;
	}
	return;
}

function loadinparent(url, closeSelf){

	if(opener != null){

		if (opener.parent.frames[1]) {
			opener.top.location.href = url;
		} else {
	 		self.opener.location = url;
		}

		if(closeSelf){
			self.close();
		}
	} else {
		document.location = url;
	}
}

function moveListBoxElement(fbox,tbox,sort,refresh){
	for(var i=0; i<fbox.options.length; i++){
		if(fbox.options[i].selected && fbox.options[i].value != ""){
			var no = new Option();
			no.value = fbox.options[i].value;
			no.text = fbox.options[i].text;

			tbox.options[tbox.options.length] = no;
			fbox.options[i].value = "";
			fbox.options[i].text = "";
		}
	}
	listBoxBumpUp(fbox);
	if (sort){
		listBoxSort(tbox);
	}
	if(refresh){
		removeListBoxDublicates(tbox);
	}

	return;
}

function moveTextBoxElement(textbox,tobox,sort,refresh){
	if(textbox.value!= ""){
			var no = new Option();
			no.value = textbox.value;
			no.text = textbox.value;
			tobox.options[tobox.options.length] = no;
			textbox.value = "";
	}
	if (sort){
		listBoxSort(tobox);
	}
	if(refresh){
		removeListBoxDublicates(tobox);
	}
	return;
}

function navOver(img_name,img_src) {
	document[img_name].src=img_src;
	}

function navOff(img_name,img_src) {
	document[img_name].src=img_src;
	}


function pause(numberMillis) {
    var dialogScript = 
       'window.setTimeout(' +
       ' function () { window.close(); }, ' + numberMillis + ');';
    var result = null;
//For IE5.
	if(window.showModalDialog && window.showModalDialog != null) {
    result = window.showModalDialog('javascript:document.writeln("<script>' + dialogScript + '</script>")');
	}
 }

function rightMyEviteAction(e, redirectURL, deleteLink){
	var url = redirectURL;
	if (e.button==2) {
		document.oncontextmenu=new Function('return false;');
		url = unescape(deleteLink);
	}
	location.href = url;
}
function openEmail(id, suffix) {
    var win = window.open('/sendEmail?to=' + id + suffix, '_blank','scrollbars=yes,width=450,height=380,screenX=300,screenY=20,resizable=yes,status=yes,toolbar=yes');

    if(navigator.userAgent.indexOf("MSIE 3") == -1)	{
    	win.focus();
    }
}

function openProfile(username)	{
	document.location = '/pages/gt/people/view.jsp?username=' + username;
}

function openProfilePublicEvent(username, publicEventID)	{
	document.location = '/pages/gt/people/view.jsp?username=' + username + '&pubEventID=' + publicEventID;
}


// Creates a popup window based on specified arguments. A handle to the
// popup window is returned so the developer can programmatically manipulate the
// window after it has been launched.
function getPopupWinHandle(loc, width, height, resizable, scrollbars, toolbar, dependent, winName, locationBar, statusBar, align){
	// Evaluate the window arguments.
	var alignValue = "top=1,left=1"

	if(align== 'center'){

		LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
		alignValue = "top=" + TopPosition + ",left=" + LeftPosition;
	} else if (align=='topright'){
		LeftPosition = (screen.width) ? (screen.width-width): 0;
		TopPosition = 1;
		alignValue = "top=" + TopPosition + ",left=" + LeftPosition;
	} else if (align=='topcenter'){
		LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
		TopPosition = 1;
		alignValue = "top=" + TopPosition + ",left=" + LeftPosition;
	} else if (align=='topleft'){
		alignValue = "top=1,left=1";
	}

	var win = eval("window.open(loc, '"
		+ winName
		+ "','width=" + width
		+ ",height=" + height
		+ ",resizable=" + resizable
		+  ",scrollbars=" + scrollbars
		+  ",toolbar=" + toolbar
		+  ",dependent=" + dependent
		+  ",screenX=1,screenY=1," + alignValue
		+  ",location=" + locationBar
		+ ",status=" + statusBar + "')");
		//set the focus to the newly created window.
		win.focus();
	// Return a handle to the newly created window.
	return win;
} // function getPopupWinHandle

// Creates a popup window based on specified arguments.
function popupWin(loc, width, height, resizable, scrollbars, toolbar, dependent, winName,locationBar, statusBar,align){
	// Here we DO NOT return the handle to the window just created as it may
	// cause problems when embedding JavaScript statements in HTML anchor tags.
	var newWin = getPopupWinHandle(loc, width, height, resizable, scrollbars, toolbar, dependent, winName,locationBar, statusBar, align);
} // function popupWin

function previewProfile(form, url, username){
	var popURL = '/pages/gt/people/view.jsp?username=' + username + '&popup=true&preview=true'
	form.rurl.value = url;
	form.submit();
	popupWin(popURL,'780','700','yes','yes','no','no','DependentWindow','center');
}

// edit keyword popup
function simplePopup(url, width, height) {
	popupWin(url, width, height, 'yes', 'yes', 'no', 'no', 'DependentWindow', 'center');
}

// preview invite more email.
function previewInviteMoreEmail(eventID, inviteID, inviteMoreNotes)	{
	var previewWinURL = "/app/virtual/preview/inviteMore.do?eventID=" + eventID + "&inviteID=" + inviteID + "&inviteMoreNotes=" + encodeURI(inviteMoreNotes);
	previewEmail(previewWinURL);
}

// preview invitation email from view invite. expects form bean in session
function previewInviteEmail(eventID)	{
	var previewWinURL = "/app/virtual/preview/inviteEmailForViewInvite.do?eventID=" + eventID;
	previewEmail(previewWinURL + "&rnd=" + generateRandom());
}

// preview invitation email from view invite. expects form bean in session
function previewEmail(url)	{
	var previewWin = window.open(url, "DependentWindow", "width=650,height=730,resizable=yes,scrollbars=yes", true);
 	if(navigator.userAgent.indexOf("MSIE 3") == -1)	{
		previewWin.focus();
	}
}

function removeListBoxElement(fbox,refresh){
	sortListitems = refresh;
	for(var i=0; i<fbox.options.length; i++){
		if(fbox.options[i].selected && fbox.options[i].value != ""){
			fbox.options[i].value = "";fbox.options[i].text = "";
		}
	}
	listBoxBumpUp(fbox);
	return;
}

function removeListBoxDublicates(field){
	var temp = null;
	for(i = 0 ; i < field.options.length; i++){
		temp = field.options[i].value;
		for(j = i+1; j < field.options.length;j++){
			if(temp == field.options[j].value){
				field.options[j].value = "";
				field.options[j].text = "";
			}
		}
	}
	listBoxBumpUp(field);
}



function selectAll(selectBox){
	for(var i=0;i<selectBox.options.length;i++){
		selectBox.options[i].selected = true;
	}
	return;
}

function selectGiftExchange(){
	document.privateCreateForm.includeGiftExchange.checked = true;
}


function searchGT(category, location, date, radius, searchCategory, keywords){
	top.document.location = "/pages/gt/search/searchResults.jsp?category=" + category + "&date_range=" + date +"&location=" + location + "&radius=" + radius + "&searchCategory=" +searchCategory + "&keywords=" + keywords + "&submitForm=true";
}

function venueSearch(category, location, date, radius, searchCategory, keywords){
	top.document.location = "/app/places/search/venueSearch.do?category=" + category + "&date_range=" + date +"&location=" + location + "&radius=" + radius + "&searchCategory=" +searchCategory + "&keywords=" + keywords + "&submitForm=true";
}

  function setCookie(name, value, maxAge, path, domain, secure) {
  // hard coded this for now.  Definitely need to change this for future.

  var expires="Thu, 01-Jan-2004 00:00:01 GMT";
    var curCookie = name + "=" + escape(value) +
      ((path) ? "; path=" + path : "") +
      ((expires) ? "; expires=" +expires : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
    document.cookie = curCookie;
  }

function setPrimaryEmail(form, email, rurl) {
	form.changePrimaryEmail.value = email;
	form.rurl.value = rurl;
	form.cmd.value = 'update';
	form.cmd2.value = 'profile';
	form.cmd3.value = 'changePrimaryEmail';
	form.submit();
}

function showPickDate(fieldId,fieldName){
	formatDDate(fieldId);
    pass = "";
    for(i=0;i<document.forms[1].elements.length;i++){
       if(document.forms[1].elements[i].name == fieldId){
          if(document.forms[1].elements[i].value.length > 1){
             delim = "/";
             fpos = dateText.indexOf(delim,0);
             var month = dateText.substring(0,fpos);
             spos = dateText.indexOf(delim,(fpos+1));
             if(spos==-1){
             	var day = dateText.substring((fpos+1),99);
                var year = "";
              } else {
                 var day = dateText.substring((fpos+1),spos);
                 var year = dateText.substring((spos+1),99);
                 if(year.length == 2){
                 	year = '20' + year;
                 }
              }
              pass = "&month=" + month + "&day=" + day + "&year=" + year+"&p=y";
         }
      }
   }// for
   var fieldValue = '';
   if(isNull(fieldName) == false){
	  fieldValue = '&fieldName=' + fieldName;
   }

	var redirectURL ='/pages/util/popDatePicker.jsp?fieldId='+fieldId+pass+fieldValue;
	popupWin(redirectURL,'235','593','yes','no','no','no','calendar','','','center');
}

function Start(page) {
	OpenWin = this.open(page, "CtrlWindow", "toolbar=0,menubar=0,location=0,scrollbars=0,resizable=0,width=250,height=300");
}
function submitChangeMyEviteView(favorite){
	var appendString = "?fav=" + favorite;
	appendString += "&startDate=" + document.myevite.weekof.value;
	document.location="/pages/myevite/myEvite.jsp" + appendString;
}
function submitCitySearchPromo(){
	document.formCitySearch.submit();
}

// Set waitButton to null if not an image button.
function submitOnce(form, button, waitButton) {
	if (!REQUEST_SUBMITTED){
//		if (waitButton != null) {
//			button.src = waitButton.src; // swap image
//		} else {
//			button.value = "  Please Wait...  ";
//		}
		REQUEST_SUBMITTED = true;	
		form.submit();
	} else {
		return false;
	}
}

function submitTheKnotRegistrySearch(eventID,location){
	// Determines if a registry has been selected.  If so, then returns the value of the
	// selected radiobutton.
	var registry = getRadioValue(document.registrySearch.registryRadio);
	var registryLen = 0;
	if(registry != null){
		registryLen = registry.length;
	} else {
		registryLen = 0;
	}
	var url = '';
	if(registryLen > 0){
		if(location== 'edit'){
			url = '/schedule/rescheduleForm?eventID='+eventID+'&'+registry;
		} else {
			url = '/compose?eventID='+eventID+'&'+registry;
		}
		loadinparent(url,true);
	} else {
		alert('A couple\'s registry must be selected before proceeding.');
	}
}

function submitWizardWhereZip(){

	var URLString = '';
	var zip = document.whereForm.zipSearch.value;
	var radius = document.whereForm.radiusSearch.value;
	var title = document.whereForm.titleSearch.value.toUpperCase();
	var cat = document.whereForm.cat.value;

	if(zip!=null){
		URLString =  '/pages/wizard/where.jsp?zip=' + zip + '&radius=' + radius;
		if(title!=null){
			URLString += '&title=' + title;
		}
		if(cat!=null){
			URLString +='&cat='+cat;
		}

		document.location = URLString;
	}
}


function submitGTWizardWhereZip(){

	var URLString = '';
	var zip = document.whereForm.zipSearch.value;
	var radius = document.whereForm.radiusSearch.value;
	var title = document.whereForm.titleSearch.value.toUpperCase();
	var cat = document.whereForm.cat.value;

	if(zip!=null){
		URLString =  '/pages/gt/wizard/where.jsp?zip=' + zip + '&radius=' + radius;
		if(title!=null){
			URLString += '&title=' + title;
		}
		if(cat!=null){
			URLString +='&cat='+cat;
		}

		document.location = URLString;
	}
}
function formatDDate(fieldId){
     dateText = "";
     for(i=0;i<document.forms[1].elements.length;i++) {
        if(document.forms[1].elements[i].name == fieldId) {
           dateText = document.forms[1].elements[i].value;
         }
      }

       if(dateText=="" || dateText==null) {
          return false;
       }
        var delim = "";
        if(dateText.indexOf("-")>0) {
                delim = "-";
        } else if(dateText.indexOf("/")>0) {
                delim = "/";
        } else if(dateText.indexOf(".")>0) {
                delim = ".";
        } else {
                return false;
        }
        fpos = dateText.indexOf(delim,0);
        var month = dateText.substring(0,fpos);
        spos = dateText.indexOf(delim,(fpos+1));
        if(spos==-1){
                var day = dateText.substring((fpos+1),99);
                var year = "";
        } else {
                var day = dateText.substring((fpos+1),spos);
                var year = dateText.substring((spos+1),99);
        }
        if(month.length < 2){
                month = 0 + month;
        }
        if(day.length < 2){
                day = 0 + day;
        }
        if(year.length < 1) {
                dateObject = new Date();
                year = dateObject.getYear();
                if(year < 1000){
                        year = year + 1900;
                }
        } else if(year.length < 4) {
                year = 20 + year;
        }
        for(i=0;i<document.forms[1].elements.length;i++) {
                if(document.forms[1].elements[i].name == fieldId){
                   document.forms[1].elements[i].value = month + "/" + day + "/" + year;
                }
        }
        return month + "/" + day + "/" + year;
}

function submitFormOnReturn(form,e){
    if (e.keyCode == 13){
    		form.submit();
     }
 }


function submitUnsubscribe(){
	document.formUnsubscribe.submit();
}

function changeDivTag(div, state){
  	if(document.getElementById){
        var obj = document.getElementById(div);
        obj.style.display = state;
    }
}

function swapDivs(divID1, divID2) {
	var divElement1 = document.getElementById(divID1);
	var divElement2 = document.getElementById(divID2);
	if(divElement1.style.display == 'block') {
		divElement1.style.display = 'none';
		divElement2.style.display = 'block';
	} else {
		divElement1.style.display = 'block';
		divElement2.style.display = 'none';
	}
}


function toggleDisplay(id) {
	var e = document.getElementById(id);
	if(e.style.display == 'none')
	e.style.display = 'block';
	else
	e.style.display = 'none';
	}




function toggleDivTags(div, state)  {

    if(document.layers){

       document.layers[div].visibility = state ? "block" : "none";
    }
  	if(document.getElementById){
        var obj = document.getElementById(div);
        obj.style.display = state ? "block" : "none";
    }
    else if(document.all)	// IE 4
    {
        document.all[div].style.display = state ? "block" : "none";
    }
}

function toggleTRColor(checboxVal, target, color) {
   if(checboxVal.checked == true){
      getElement(target).style.background = color;
   } else {
      getElement(target).style.background = "white";
   }
}

function toggleTRColorWhenBoxesChecked (form, fieldName, color) {
	if(form != null) {
		len = form.elements.length;
		var target = "";
		var i=0;
		var rowCounter=0;
		for( i=0; i<len; i++) {
			if (form.elements[i].name==fieldName){
				target = "tr" + rowCounter;
				rowCounter++;
				toggleTRColor(form.elements[i], target, color)
			}
		}
	}
}

function uniPop(href,winname,width,height,toolbar,scrollbars,resizable,status,align) {
	if (href == "") href = '/support';
	if (winname == 'spellChecker') href+=escape(document.eventForm.notes.value);
	if ((width < 100) || (width == null)) var width = '515';
	if ((height < 100) || (height == null)) var height = '475';
	if (toolbar == null) var toolbar = 'yes';
	if (scrollbars == null) var scrollbars = 'yes';
	if (resizable == null) var resizable = 'yes';
	if (status == null) var status = 'yes';

	// Evaluate the window arguments.
	var alignValue = "top=1,left=1"
	if(align == null) {
		align = 'topcenter';
	}
	if(align== 'center'){
		LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
		alignValue = "top=" + TopPosition + ",left=" + LeftPosition;
	} else if (align=='topright'){
		LeftPosition = (screen.width) ? (screen.width-width): 0;
		TopPosition = 1;
		alignValue = "top=" + TopPosition + ",left=" + LeftPosition;
	} else if (align=='topcenter'){
		LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
		TopPosition = 1;
		alignValue = "top=" + TopPosition + ",left=" + LeftPosition;
	} else if (align=='topleft'){
		alignValue = "top=1,left=1";
	}

	var theParam = "width=" +width+
					",height=" +height+
					",toolbar=" +toolbar+
					",scrollbars=" +scrollbars+
					",resizable=" +resizable+
					",status=" +status+
					",screenX=1,screenY=1,"+alignValue+
					";";

	var thePopup = window.open(href,winname,theParam);
}

function unSelectAll(selectBox){
	for(var i=0;i<selectBox.options.length;i++){
		selectBox.options[i].selected = false;
	}
	return;
}

function displayHeaderWarning(warningMsg, cssClassName) {
	if(cssClassName == null || cssClassName.length == 0) {
		cssClassName = 'lgwarning';
	}

	if(warningMsg != null) {
		if(warningMsg.length > 0) {
			document.write('<table cellpadding="0" cellspacing="0" border="0" width="760" bgcolor="#ffffff">');
			document.write('<tr>');
			document.write('    <td><img border="0" src="/images/t.gif" width="1" height="5"/></td>');
			document.write('</tr>');
			document.write('<tr>');
			document.write('    <td valign="center" align="center" class="'+cssClassName+'" height="25">'+warningMsg+'</td>');
			document.write('</tr>');
			document.write('</table>');
		}
	}
}

function killNull(str) {
	if(str == null || str == 'null' || str == 'undefined') return "";
	return str;
}

function doSelectDesign(redirectURL, customColor) {
	// alert('In select design');
	// alert('custom color ' + customColor); 
	if(customColor == 'yes') {
		if(confirm("Selecting a new design will override your previous design customizations. Are you sure?")) {
			window.location.href=redirectURL;
		}
	} else {
		window.location.href=redirectURL;
	}
}

function goToPage(url) {
	try {
		location.href = url;
	} catch (e1) {
		try {
			document.location.href = url;
		} catch (e2) {
			try {
		 		window.location.replace(url);
			} catch (e3) {}
		}
	}
}

function flashVersion() {  
  // If navigator.plugins exists...
  var hasFlash = false;
  var output = "";
  
  if (navigator.plugins) {
    // ...then check for flash 2 or flash 3+.
    if (navigator.plugins["Shockwave Flash 2.0"]
        || navigator.plugins["Shockwave Flash"]) {

      // Some version of Flash was found. Time to figure out which.
      var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
      var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
 
      flash2Installed = flashVersion == 2;    
      flash3Installed = flashVersion == 3;
      flash4Installed = flashVersion == 4;
      flash5Installed = flashVersion == 5;
      flash6Installed = flashVersion == 6;
      flash7Installed = flashVersion == 7;
      flash8Installed = flashVersion == 8;
      flash9Installed = flashVersion >= 9;

    }
  }
  for (var i = 2; i <= maxVersion; i++) {  
    if (eval("flash" + i + "Installed") == true) actualVersion = i;
  }
  
  if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 3;  

  // Lets set the proper variable depending if the user has flash installed.
  return actualVersion;
  
}

