var doTheReload = false;

function startUpload()
{
	window.opener.top.document.addpresentation.submit();
}

function killReload()
{
	doTheReload = false;
	return false;
}

function restartReload()
{
	doTheReload = true;
	return false;
}

function raiseAttendeeHandUp(formname, which)
{
	doTheReload = false;
	formname.RAISEATTENDEEHANDUP.value = which;
	formname.submit();
}

function lowerAttendeeHandUp(formname, which)
{
	doTheReload = false;
	formname.LOWERATTENDEEHANDUP.value = which;
	formname.submit();
}

function removeAttendeeHandUp(formname, which)
{
	doTheReload = false;
	formname.HANDLEATTENDEEHANDUP.value = which;
	formname.submit();
}

function hideBlock(formname, which)
{
	doTheReload = false;
	formname.BLOCKTOHIDE.value = which;
	formname.submit();
}

function unhideBlock(formname, which)
{
	doTheReload = false;
	formname.BLOCKTOUNHIDE.value = which;
	formname.submit();
}

function changeSlide(formname, which)
{
	doTheReload = false;
	formname.NEXTSLIDE[formname.NEXTSLIDE.selectedIndex].value = which;
	formname.submit();
}

function approvePerson(formname, which)
{
	doTheReload = false;
	formname.APPROVEPERSON.value = which;
	formname.submit();
}

function verifyPermissionChange(formname)
{
	var res = confirm("Are you sure you want to change the permissions for this user?");
	if(res != false)
	{
		return true;
	}
	return false;
}

function disapprovePerson(formname, which)
{
	doTheReload = false;

	var res = confirm("Are you sure you want to deny approval?");
	if(res != false)
	{
		formname.DISAPPROVEPERSON.value = which;
		formname.submit();
	}
	return false;
}

function verifyEndPresentation(apppage, uniquestring)
{
	var res = confirm("Are you sure you want to end the presentation now?");
	if(res != false)
	{
		var gotourl = apppage;
		document.location.href = gotourl;
	}
	return false;
}

function verifyEmailNotesSendto(formname)
{
	var foundsome = false;
	for(var i=0; i<formname.SENDTO.length; i++)
    {
        if(formname.SENDTO[i].selected)
        {
            // Found a selection
			foundsome = true;
            if(formname.SENDTO[i].value == "-1")
            {
                alert("Please verify your selected recipients.\nDo not select anything that is not a person.");
				return false;
		    }
        }
    }
	
	if(foundsome == false)
	{
		alert("Please select at least one recipient from the list.");
		return false;
	}

	return true;
}

function verifyEmailNotesMessage(formname)
{
	if(formname.MESSAGE.value.length == 0)
	{
		alert("Please enter some text to be sent in the E-mail.");
		return false;
	}

	var foundchar = false;
	for(x=0;x<formname.MESSAGE.value.length;x++)
	{
		if(formname.MESSAGE.value.charAt[x] != ' ' && formname.MESSAGE.value.charAt[x] != '\n')
		{
			foundchar = true;
			break;
		}
	}

	if(foundchar == false)
	{
		alert("Please enter some text to be sent in the E-mail.");
		return false;
	}

	return true;
}

function verifyNewNote(formname)
{
	if(formname.NEWNOTE.value.length == 0)
	{
		alert("Please enter a new note to add");
		return false;
	}
	
	if(formname.NEWNOTE.value.length > 5000)
	{
		alert("A note can only be 5000 characters in length.");
		return false;
	}

	var foundchar = false;
	for(x=0;x<formname.NEWNOTE.value.length;x++)
	{
		if(formname.NEWNOTE.value.charAt[x] != ' ' && formname.NEWNOTE.value.charAt[x] != '\n')
		{
			foundchar = true;
			break;
		}
	}

	if(foundchar == false)
	{
		alert("Please enter a new note to add.");
		return false;
	}

	return true;
}

function showAudioAccessInstructions(admininst, publicinst)
{
	doTheReload = false;
	var outstring = "";

	if(admininst != null)
	{
		outstring = "Administrator Audio Access:\n     " + admininst;
	}
	if(outstring != "")
	{
		outstring = outstring + "\n\n";
	}
	if(publicinst != null)
	{
		outstring = outstring + "Public Audio Access:\n     " + publicinst;
	}

	alert(outstring);

	doTheReload = true;
	return false;
}

function openSlideShowWindow(appdir, uniquecachestring)
{	
	var width = 975;
	var height = 600;

	if (window.screen) 
	{
		var aw = screen.availWidth;
		var ah = screen.availHeight;
		
		if(aw < 975)
		{
			width = aw;
			height = ah;
		}
	}

	var winname = "ECWVIRTUALSLIDESHOWWINDOW";

	if(appdir == null)
	{
		appdir = "";
	}

	var urltoopen = "" + appdir + "index2.cfm?UNIQUE_CACHE_STRING=" + uniquecachestring;

	openNewWindow(winname, urltoopen, 'custom', height, width, "yes");
}

function startSlideShow(appdir, uniquecachestring)
{	
	var width = 975;
	var height = 600;
	var display = "HORIZONTAL";

	if (window.screen) 
	{
		var aw = screen.availWidth;
		var ah = screen.availHeight;
		
		if(aw < 975)
		{
			width = aw;
			height = ah;
			display = "VERTICAL";
		}
	}

	window.top.document.location.href = "" + appdir + "virtualframeset.cfm?DISPLAY=" + display + "&UNIQUE_CACHE_STRING=" + uniquecachestring;
}

function isANumber(instr)
{
	if(instr == null) return true;
	if(instr.length < 1) return true;

	for(x=0;x < instr.length; x++)
	{
		if(instr.charAt(x) < '0' || instr.charAt(x) > '9')
		{
			return false;
		}
	}
	return true;
}

function isAFloat(instr)
{
	if(instr == null) return true;
	if(instr.length < 1) return true;

    var foundone = false;
	for(x=0;x < instr.length; x++)
	{
		if(instr.charAt(x) < '0' || instr.charAt(x) > '9')
		{
		    if(!(instr.charAt(x) == '.' && foundone))
			    return false;
		}
		foundone = true;
	}
	return true;
}

function findBadChar(formfield)
{
	for(i=0;i<formfield.value.length;i++)
	{
		if(formfield.value.charAt(i) == '^' ||
			formfield.value.charAt(i) == ':' ||
			formfield.value.charAt(i) == ';' ||
			formfield.value.charAt(i) == '*' ||
			formfield.value.charAt(i) == '"')
		{
			return true;
		}
	}
	
	return false;
}

function removeApostropheChar(formfield)
{
	var newstring = new String();
	for(i=0;i<formfield.value.length;i++)
	{
		if(formfield.value.charAt(i) == '\'')
		{
			newstring = newstring + '`';
		} else
		{
			newstring = newstring + formfield.value.charAt(i);
		}
	}

	formfield.value = newstring;
}

function checkEmailAddress(formfield)
{
	var foundat = false;
	var founddot = false;

	for(i=0;i<formfield.value.length;i++)
	{	
		if(formfield.value.charAt(i) == ' ')
		{
			return false;
		}
		if(formfield.value.charAt(i) == '@')
		{
			foundat = true;
		}
		if(formfield.value.charAt(i) == '.')
		{
			founddot = true;
		}
	}
	if(!foundat || !founddot)
	{
		return false;
	}
	return true;
}

function openNotesWindow(apppage, uniquecachestring)
{	
	doTheReload = false;
	var winname = "ECWNOTESWINDOW";

	var urltoopen = apppage;
	
	openNewWindow(winname, urltoopen, 3, null, null, null);

	doTheReload = true;
	return false;
}

function openNewWindow(winName, inUrl, size, height, width, statusbar)
{
	if(statusbar == null)
	{
		statusbar = "no";
	}
	if(winName == null)
	{
		winName = "eCWPOPUPWINDOW_" + size;
	} else
	{
		winName = "eCWPOPUPWINDOW_" + winName;
	}
	if(size == "1")
	{
		win_chk = window.open( inUrl, winName,'scrollbars=yes,toolbar=no,location=no,status=" + statusbar + ",resizable=yes,width=300,height=200,screenX=0,screenY=0,left=0,top=0',false);
	}
	if(size == "2")
	{
		win_chk = window.open( inUrl, winName,'scrollbars=yes,toolbar=no,location=no,status=" + statusbar + ",resizable=yes,width=500,height=400,screenX=0,screenY=0,left=0,top=0',false);
	}
	if(size == "3")
	{
		win_chk = window.open( inUrl, winName,'scrollbars=yes,toolbar=no,location=no,status=" + statusbar + ",resizable=yes,width=600,height=500,screenX=0,screenY=0,left=0,top=0',false);
	}
	if(size == "4")
	{
		win_chk = window.open( inUrl, winName,'scrollbars=yes,toolbar=no,location=no,status=" + statusbar + ",resizable=yes,width=600,height=600,screenX=0,screenY=0,left=0,top=0',false);
	}
	if(size == "5")
	{
		win_chk = window.open( inUrl, winName,'scrollbars=yes,toolbar=no,location=no,status=" + statusbar + ",resizable=yes,width=975,height=600,screenX=0,screenY=0,left=0,top=0',false);
	}
	if(size == "6")
	{
		win_chk = window.open( inUrl, winName,'scrollbars=yes,toolbar=no,location=no,status=" + statusbar + ",resizable=yes,width=1105,height=600,screenX=0,screenY=0,left=0,top=0',false);
	}
	if(size == "custom")
	{
		var customstring = "scrollbars=yes,toolbar=no,location=no,status=" + statusbar + ",resizable=yes,width=" + width + ",height=" + height + ",screenX=0,screenY=0,left=0,top=0";
		win_chk = window.open( inUrl, winName, customstring, false);
	}
	if(size == "full")
	{
		win_chk = window.open( inUrl, winName,'scrollbars=yes,toolbar=no,location=no,status=" + statusbar + ",resizable=yes,screenX=0,screenY=0,left=0,top=0',false);
	}
}

function checkWhiteSpace(formfield, fieldname, fieldtype)
{
	if(fieldtype == null)
	{
		fieldtype = 1;
	}

	if(fieldtype == 1)
	{
		// text boxes
		if(formfield.value.length == 0)
		{
			alert(fieldname + " cannot be blank.");
			return false;
		}
		var i = 0;
		for(i=0;i<formfield.value.length;i++)
		{
			if(formfield.value.charAt(i) != ' ')
			{
				return true;
			}
		}
		if(i == formfield.value.length)
		{
			alert(fieldname + " cannot be blank.");
			formfield.focus();
			return false;
		}
	} else if(fieldtype == 2)
	{
		// pull-downs - must be set to something other than 0
		if(formfield.selectedIndex == 0)
		{
			alert("You must select " + fieldname + ".");
			return false;
		} else
		{
			return true;
		}
	}
	return false;
}

function help(num)
{
    var message = new Array();

    // General
    message[0]  = "Help goes here.";
    message[1]  = "This is a required field.";
    message[2]  = "This is an optional field.";
    message[3]  = "This is your e-mail address.";
    message[4]  = "This is your telephone number.\nArea code first.";

    // Login
    message[10] = "This is your User ID (usually your e-mail address).";
    message[11] = "This is your Password.";
    
    // New Login
    message[20] = "This is your first name.";
    message[21] = "This is your last name.";
    message[22] = "This is your company name.\nThis is an optional field.";
    message[23] = "This is your job title.\nThis is an optional field.";
    message[24] = "This is the first line of your address.";
    message[25] = "This is the second line of your address.\nThis is an optional field.";
    message[26] = "This is the third line of your address.\nThis is an optional field.";
    message[27] = "This is your city name.";
    message[28] = "This is your state or province name.";
    message[29] = "This is your zip or postal code.";
    message[30] = "This is your country name.";
    message[31] = "This is your work telephone number.\nArea code first.";
    message[32] = "This is your home telephone number.\nArea code first.\nThis is an optional field.";
    message[33] = "This is your cellular telephone number.\nArea code first.\nThis is an optional field.";
    message[34] = "This is your fax number.\nArea code first.\nThis is an optional field.";
    message[37] = "This is your e-mail address.";
    message[38] = "This is your password.\nPlease be creative. Use a combination of letters, numbers and punctuations.";
    message[39] = "This is your password again.\nBoth password fields have to match.";
    message[40] = "This is your User ID.\nWe suggest to make the userid the same as your e-mail address.";
    message[41] = "This is your SMS paging number.\nSMS stands for 'Short Message Service'.\nIt represents how to reach you by sending a\ntext message to your cellphone, your pager or your PDA.\nIt normally looks like an e-mail address.\nThis is an optional field.";
           
    // Daily Schedule
    message[300] = "This is the identifier of the program event.\nEach program event has a unique identifier.";
    message[301] = "This is the name of the presentation that will be displayed\nto viewers. This is NOT the filename of the presentation.\nThis name should be the unique title of your presentation that\ndistinguishes it from others.";
    message[302] = "This determines how people are authenticated before allowing\nthem to view the presentation with the presenter:\n\n     Presenter Approval - Presenter selectively grants approval as people join the presentation\n     User ID/Password - Everyone must enter a valid user ID and password to join the presentation\n     NONE - Anyone can view the presentation without authenticating";
    message[303] = "This is a list of all of the people allowed to administer,\nmodify and present this presentation. You must be included in\nthis list to complete the upload of the presentation.\nTo include multiple people, hold down the \'Ctrl\' key\nwhile clicking on each person.";
    message[304] = "This is the person that will be shown to all attendees as the speaker.";
    message[305] = "This is the type of storage used for the presentation after it is uploaded.\n\nIf you choose \"Encrypted\" you will be asked for a password for this presentation.\nThis password will be used to encrypt every slide in the presentation.\nThis password can be anything you choose and it must be entered by\nanyone joining the presentation as an administrator, or anyone\ntrying to view this presentation without the presenter or administrator present.\n\nIf you choose \"Unencrypted\" all of the slides are stored unencrypted\nand no password will be required.\n\nThis field has no bearing on user authentication. It only\neffects how the slides are stored and, if \"Encrypted\", requires\nthat an additional password be provided anytime the presentation\nis going to be viewed.";
    message[306] = "Because you chose \"User ID/Password\" Attendee Authentication on\nthe previous page, you must specify which\nusers and groups will be allowed to view this presentation.\nIf you select \"ALL VALID USERS\", you cannot select any groups or people.\nTo include multiple people and groups, hold down the \'Ctrl\' key\nwhile clicking on each person and group.";
    message[307] = "Because you chose the \"Encrypted\" Storage Type on\nthe previous page, you must specify the password that will be\nused to encrypt all of the slides in the presentation.\nThis password can be anything you choose and it must be entered by\nanyone trying to joining the presentation as an administrator, or anyone\ntrying to view this presentation without the presenter or administrator present.";
    message[308] = "Just enter the same password you just entered above.";
	message[309] = "By clicking the \'Browse\' button, locate your presentation on your computer.\nClicking the \'Browse\' button will open a new window to help you find your presentation.\nBe careful. Some browsers, by default, will not show you\nall of the files on your computer in this new window unless you change\nthe \'Files of type\' entry at the bottom of the window to *.*.";
	message[310] = "This is the status of the presentation.\nA status of \"ACTIVE\" means that the presentation will be viewable and displayed to users.\nA status of \"INACTIVE\" means that the presentation will not be viewable or displayed to users.\nA status of \"ACTIVE-HIDDEN\" means that the presentation will be viewable but not displayed to users.\n";
    message[311] = "Because \"Encrypted\" Storage Type was chosen when this\npresentation was uploaded, the presentation password must be entered by\nanyone trying to joining the presentation as an administrator, or anyone\ntrying to view this presentation without the presenter or administrator present.\nThis password is NOT your user password and it must be the same password\nthat was used when the presentation was uploaded.";
    message[312] = "This is the telephone call-in information for this presentation. If you are using a\nconferencing system and would like to make the information available to attendees, enter it here.\nThis is an optional field.";
    message[313] = "This is the telephone call-in information for this presentation. If you are using a\nconferencing system and would like to make the information available to administrators or presenters, enter it here.\nThis is an optional field.";
	
    // Secure People     
	// Edit User
    message[420] = "This is the user's first name.";
    message[421] = "This is the user's last name.";
    message[422] = "This is the user's company name.\nThis is an optional field.";
    message[423] = "This is the user's job title.\nThis is an optional field.";
    message[424] = "This is the first line of the user's address.";
    message[425] = "This is the second line of the user's address.\nThis is an optional field.";
    message[426] = "This is the third line of the user's address.\nThis is an optional field.";
    message[427] = "This is the user's city name.";
    message[428] = "This is the user's state or province name.";
    message[429] = "This is the user's zip or postal code.";
    message[430] = "This is the user's country name.";
    message[431] = "This is the user's work telephone number.\nArea code first.";
    message[432] = "This is the user's home telephone number.\nArea code first.\nThis is an optional field.";
    message[433] = "This is the user's cellular telephone number.\nArea code first.\nThis is an optional field.";
    message[434] = "This is the user's fax number.\nArea code first.\nThis is an optional field.";
    message[437] = "This is the user's e-mail address.";
    message[438] = "This is the user's password.\nPlease be creative. Use a combination of letters, numbers and punctuations.";
    message[439] = "This is the user's password again.\nBoth password fields have to match.";
    message[440] = "This is the user's User ID.\nWe suggest to make the userid the same as the user's e-mail address.";
    message[441] = "This is the user's SMS paging number.\nSMS stands for 'Short Message Service'.\nIt represents how to reach the user by sending a\ntext message to the user's cellphone, the user's pager or the user's PDA.\nIt normally looks like an e-mail address.\nThis is an optional field.";
    message[442] = "This is the status of the user.\nUsers in the INVALID state will not be able to login.\nUsers in the RESET PASSWORD state will be forced to select a new password the next time they login.";
    message[443] = "This is the list of permissions granted to this user.\nTo select multiple permissions, hold down the Ctrl key while clicking the desired permissions.\nTo select no permissions, hold down the Ctrl key and click on any permission that is highlighted so it becomes unhighlighted.";
    message[444] = "This is a message that will be e-mailed to the user when these changes are made.\nIt may be helpful to include any special instructions the user may need such as a URL or temporary password.\nThis is an optional field.";

    if(num != null && message[num] != null)
        alert(message[num]);
    else
        alert("[" + num + "] " + message[0]);

    return false;
}
