// Global Variables

function addToOutlook(noEventTime, eventId){
	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 {
		location.href=("/respond/vcal/" + eventId + "/evite.vcs");
	}
}

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 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?")){
   	if(confirm("ARE YOU DEFINITELY, 100%, ABSOLUTELY SURE? (NO TURNING BACK??)")){
   			location.href=("/pages/admin/pcPartner.jsp?cmd=clearCacheAllServers");
  	 }
   }
}


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

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 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 pushDesignGallery(){
   if(confirm("Are you sure you want to push the Design Gallery to production?")){
   	if(confirm("ARE YOU DEFINITELY, 100%, ABSOLUTELY SURE? (NO TURNING BACK??)")){
   			location.href=("/pages/admin/pcPartner.jsp?cmd=pushDesignGallery");
  	 }
   }
}

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 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));
}

// Author: David Rowland
// Date  : 09-17-2002
// Desc  : Goes to URL

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

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

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

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){
	var index = box.options.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[nextIndex].value = oldVal;
		box.options[nextIndex].text = oldText;
		box.options.selectedIndex = nextIndex;
	}
}

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 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 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();
    }
}

// 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){
	// Evaluate the window arguments.
	var win = eval("window.open(loc, '"
		+ winName
		+ "','width=" + width
		+ ",height=" + height
		+ ",resizable=" + resizable
		+  ",scrollbars=" + scrollbars
		+  ",toolbar=" + toolbar
		+  ",dependent=" + dependent
		+  ",screenX=1,screenY=1,top=1,left=1"
		+  ",status=no,location=no')");
	// 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){
	// 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);
} // function popupWin

function previewEmail(eventID, inviteId, inviteMoreNotes)	{
	var previewWinURL = "/pages/invite/inviteEmailPreview.jsp?eventId=" + eventID + "&inviteId=" + inviteId + "&inviteMoreNotes=" + inviteMoreNotes;
	var previewWin = window.open(previewWinURL, "Preview", "width=750,height=600,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);
	if (sortListitems) {
		listBoxSort(tbox);
	}
	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 Start(page) {
	OpenWin = this.open(page, "CtrlWindow", "toolbar=0,menubar=0,location=0,scrollbars=0,resizable=0,width=250,height=300");
}


function uniPop(href,winname,width,height,toolbar,scrollbars,resizable,status) {
	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';
	var theParam = "width=" +width+ 
					",height=" +height+  
					",toolbar=" +toolbar+ 
					",scrollbars=" +scrollbars+ 
					",resizable=" +resizable+ 
					",status=" +status+
					",screenX=1,screenY=1,top=1,left=1";
	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;
}