function createCampaign()
{
	flag = 0;
	if(checkTitle() == false)
	{
		alert('Please enter a valid title.');
		flag = 1;
	}
	if(flag == 0 && checkURL() == false)
	{
		alert('Please enter a valid URL.');
		flag = 1;
	}
	if (!isKey(document.donForm.urlKey.value)) 
	{
		alert("Web address must start with a letter, followed by zero or more letters and/or digits!");
		flag = 1;
	}
	if(flag == 0 && document.donForm.agree.checked == false)
	{
		alert('You must agree to the terms of service. Please check the \'I Agree\' box before proceeding.');
		flag = 1;
	}
	if(flag == 0)
		document.donForm.submit();
	
}
function updateCampaign()
{
flag = 0;
	if(checkTitle() == false)
	{
		alert('Please enter a valid title.');
		flag = 1;
	}
	if(flag == 0 && checkURL() == false)
	{
		alert('Please enter a valid URL.');
		flag = 1;
	}
	if (!isKey(document.donForm.urlKey.value)) 
	{
		alert("Web address must start with a letter, followed by zero or more letters and/or digits!");
		flag = 1;
	}
	if(flag == 0 && checkGoal() == false)
	{
		alert("Goal must have a non-negative number, with no commas!");
		flag = 1;
	}
	if(flag == 0 && checkSugAmt() == false)
	{
		alert("Please provide a valid numeric value for all suggested donations! (do not use commas or spaces)");
		flag = 1;
	}
	if(flag == 0 && document.getElementById('allowteams'))
	{
		if (document.donForm.allowteams[0].checked == true && document.donForm.allow_team_donations[0].selected == true)
		{
			alert('Please select a response to "Allow donations on behalf of a team?"');
			flag = 1;
		}
	}
	if(flag == 0)
	{
		checkSugLabel();
		//previewCampaign();
		document.donForm.submit();
	}
		
}

function previewCampaign()
{
	var tempaction = document.donForm.myaction.value;
	
	document.donForm.myaction.value="formpreview";
	document.donForm.target="campaign_preview";
	document.donForm.submit();
	document.donForm.myaction.value=tempaction;
	document.donForm.target = "";
}
function previewFundraiser()
{
	var tempaction = document.donForm.myaction.value;
	
	document.donForm.myaction.value="preview";
	document.donForm.target="fundraiser_preview";
	document.donForm.submit();
	document.donForm.myaction.value=tempaction;
	document.donForm.target = "";
}
function createFundraiser()
{
	flag = 0;
	if(checkTitle() == false)
	{
		alert('Please enter a valid title.');
		flag = 1;
	}
	if(flag == 0 && checkURL() == false)
	{
		alert('Please enter a valid URL.');
		flag = 1;
	}
	if (!isKey(document.donForm.urlKey.value)) 
	{
		alert("Web address must start with a letter, followed by zero or more letters and/or digits!");
		flag = 1;
	}
	if(flag == 0 && document.donForm.agree != null && document.donForm.agree.checked == false)
	{
		alert('You must agree to the terms of service. Please check the \'I Agree\' box before proceeding.');
		flag = 1;
	}
	if(flag == 0)
		document.donForm.submit();
	
}
function createOrg()
{
	flag = 0;
	if(flag == 0)
		document.orgForm.submit();
}

function updateFundraiser()
{

	flag = 0;
	if(checkTitle() == false)
	{
		alert('Please enter a valid title.');
		flag = 1;
	}
	if(flag == 0 && checkURL() == false)
	{
		alert('Please enter a valid URL.');
		flag = 1;
	}
	if (!isKey(document.donForm.urlKey.value)) 
	{
		alert("Web address must start with a letter, followed by zero or more letters and/or digits!");
		flag = 1;
	}
	if(flag == 0 && checkGoal() == false)
	{
		alert("Goal must have a non-negative number, with no commas!");
		flag = 1;
	}
	if(flag == 0)
	{
		//previewFundraiser();
		document.donForm.submit();
	}
}
function checkTitle()
{
	if(trim(document.donForm.title.value) == '')
	{
		getFocus(document.donForm.title);
		return false;
	}
	else
		return true;
}
function checkURL()
{
	if(trim(document.donForm.urlKey.value) == '')
	{
		getFocus(document.donForm.urlKey);
		return false;
	}
	else
		return true;
}
function checkGoal()
{
	if (!isNonNegative(document.donForm.goal.value) && trim(document.donForm.goal.value) != '')
	{
		getFocus(document.donForm.goal);
		return false;
	}
	else
		return true;
}	
function trim(mystring)
{
	while(''+mystring.charAt(mystring.length-1)==' ')
		mystring=mystring.substring(0,mystring.length-1);
	while(''+mystring.charAt(0)==' ')
		mystring=mystring.substring(1,mystring.length);
	return mystring;
}
function opencolorPicker(fieldname, formname)
{
	document.open('lib/colorpicker.cfm?inputname='+fieldname+'&formname='+formname,'ActiveColors','width=225, height=250,menubar=no, scrollbars=no');
	ActiveColors.focus();
}

function checkSugLabel()
{
	if(sugAmtArray.length > 1)
	{
		for(i=0; i<sugAmtArray.length; i++)
		{
			if(trim(document.donForm.sugLabel[i].value) == "")
				document.donForm.sugLabel[i].value ="<none>";
		}
	}
	else if(sugAmtArray.length == 1)
	{
		if(trim(document.donForm.sugLabel.value) == "")
			{
				document.donForm.sugLabel.value="<none>";
			}
	}
}

function checkSugAmt()
{
	var checkSugAmtflag = 0;
	if(sugAmtArray.length > 1)
	{
		for(i=0; i<sugAmtArray.length; i++)
		{
			if(trim(document.donForm.sugAmt[i].value) == "" || isNaN(document.donForm.sugAmt[i].value))
				checkSugAmtflag = 1;
		}
	}
	else if(sugAmtArray.length == 1)
	{
		if(trim(document.donForm.sugAmt.value) == "" || isNaN(document.donForm.sugAmt.value))
				checkSugAmtflag = 1;
	}
	if(checkSugAmtflag ==0)
		return true;
	else
		return false;
}

function changeIt()
{
	var i = sugAmtArray.length;
	if(sugAmtArray.length ==0)
	{
		my_div.innerHTML = "<b>Label&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Amount</b>";
	}
	sugAmtArray[i]=new Array();
	sugAmtArray[i][0]="";
	sugAmtArray[i][1]="";
 	my_div.innerHTML = my_div.innerHTML + "<br><input type='text' size=15 name='sugLabel'> $<input type='text' size=6 name='sugAmt'> <input type='button' value='delete' onclick='deleteSug("+i+")'>";
}

function deleteSug(sugID)
{	
if(sugAmtArray.length > 1)
{
	for(i=0; i<sugAmtArray.length; i++)
	{
		if(document.donForm.sugLabel[i].value == "")
			sugAmtArray[i][0] = "";
		else
			sugAmtArray[i][0] = document.donForm.sugLabel[i].value== "" ? "" : document.donForm.sugLabel[i].value;
			
		if(document.donForm.sugAmt[i].value == "")
			sugAmtArray[i][1] = "";
		else
			sugAmtArray[i][1] = document.donForm.sugAmt[i].value== "" ? "" : document.donForm.sugAmt[i].value;
		
	}
}
	sugAmtArray.splice(sugID,1);
	if(sugAmtArray.length > 0 )
		my_div.innerHTML = "<b>Label&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Amount</b>";
	else
		my_div.innerHTML = "";

	if(sugAmtArray.length > 1)
	{
		
		for(i=0; i<sugAmtArray.length; i++)
			{
				my_div.innerHTML = my_div.innerHTML + "<br><input type='text' size=15 name='sugLabel' value='"+sugAmtArray[i][0]+"'> $<input type='text' size=6 name='sugAmt' value='"+sugAmtArray[i][1]+"'> <input type='button' value='delete' onclick='deleteSug("+i+")'>";
				//my_div.innerHTML = my_div.innerHTML + "<br><input type='text' size=15 name='sugLabel' > $<input type='text' size=6 name='sugAmt'> <input type='button' value='delete' onclick='deleteSug("+i+")'>";
				if(i > 0)
				{
				document.donForm.sugLabel[i].value = sugAmtArray[i][0];
				document.donForm.sugAmt[i].value = sugAmtArray[i][1];
				}
				else
					document.donForm.sugLabel.value = sugAmtArray[i][0];
					document.donForm.sugAmt.value = sugAmtArray[i][1];
			}
	}
	else if(sugAmtArray.length == 1)
	{
		my_div.innerHTML = my_div.innerHTML + "<br><input type='text' size=15 name='sugLabel' value='"+sugAmtArray[0][0]+"' > $<input type='text' size=6 name='sugAmt' value='"+sugAmtArray[0][1]+"'> <input type='button' value='delete' onclick='deleteSug(0)'>";
		document.donForm.sugLabel.value = sugAmtArray[0][0];
		document.donForm.sugAmt.value = sugAmtArray[0][1];
	}
}
function addImage(imagetext, imagename)
{
	document.donForm.img[donForm.img.length] = new Option(imagetext, imagename, false, true);
	swapOrgImg(document.donForm.img.options[donForm.img.options.selectedIndex].value)
}

function openAddressBook()
{
	document.open('form_addressbook.cfm?addemail=yes','ActiveAddressBook','width=725, height=600,menubar=no, scrollbars=yes');
}

function openContestDetails()
{
	document.open('lib/Win250Email.cfm','EmailCampaign','width=350, height=520,menubar=no, scrollbars=no');
}
function saveDraft()
{
	document.emailform.myaction.value='savedraft';
	document.emailform.submit();
}
function sendEmail()
{
	if(document.emailform.email_to.value=="") {
		alert('You must have at least one valid email in the \'To:\' field.');
	}
	else if (document.emailform.recaptcha_response_field.value=="") {
			alert("Please enter the security text at the bottom of the page.");
			getFocus(form.recaptcha_response_field);
	}
	else {
		document.emailform.myaction.value='send';
		document.emailform.submit();
	}
}
function previewEmail()
{
	document.emailform.myaction.value='mailsample';
	document.emailform.submit();
}
function useTemplate()
{
	if(document.emailform.template_id.selectedIndex == 0)
	{
		document.emailform.email_subject.value ='';
		document.emailform.email_message.value ='';
		document.emailform.myaction.value='usetemplate';
		document.emailform.submit();
	}
	else
	{
	document.emailform.myaction.value='usetemplate';
	document.emailform.submit();
	}
}
function updateTemplates()
{
	document.emailform.myaction.value='usetemplate';
	document.emailform.submit();
}
function updateOfflineUndetailed()
{
	document.donForm.off_action.value='new';
	document.donForm.submit();
}


function manageAddressBook()
{
	document.open('form_addressbook.cfm','ActiveAddressBook','width=725, height=600,menubar=no, scrollbars=yes');
}

function updateReportOfflineUpdate()
{
	//document.donForm.off_action.value='new';
	document.donForm.submit();
}
function previewTemplate()
{
	var tempaction = document.donForm.myaction.value;
	
	document.donForm.myaction.value="preview";
	document.donForm.target="preview";
	document.donForm.submit();
	document.donForm.myaction.value=tempaction;
	document.donForm.target = "";
}
function previewThisTemplate(option, num_temps)
{
	if(num_temps > 1)
		document.donForm.template_id[option].checked=true;
	else
		document.donForm.template_id.checked = true;
	previewTemplate();
}
function previewFormColors()
{
	var tempaction = document.donForm.myaction.value;
	document.donForm.myaction.value="previewcolors";
	document.donForm.target="template_preview";
	document.donForm.submit();
	document.donForm.action = "form_colors.cfm";
	document.donForm.myaction.value=tempaction;
	document.donForm.target = "";
}
function updateFormTemplate()
{	
	document.donForm.myaction.value="update";
	document.donForm.submit();
}
function updateFormColors()
{	
	document.donForm.myaction.value="update";
	document.donForm.submit();
}
function uploadFormTemplate(qstring)
{
	document.open('form_upload_template.cfm?'+qstring,'UploadTemplate','width=375, height=375,menubar=no, scrollbars=no');
}
function previewHeaders()
{
	var tempaction = document.donForm.myaction.value;
	document.donForm.myaction.value="previewHeaders";
	document.donForm.target="template_preview";
	document.donForm.submit();
	document.donForm.action = "form_headers.cfm";
	document.donForm.myaction.value=tempaction;
	document.donForm.target = "";
}


// AG-116
function checkAllowTeams() {
	if (document.donForm.allowteams[0].checked == true) {	
		document.donForm.allow_team_donations[1].selected = true;
		document.donForm.allow_team_donations.disabled = false;
	}
	else {
		document.donForm.allow_team_donations[0].selected = true;
		document.donForm.allow_team_donations.disabled = true;
	}
}

function toggle_top_donations(oThis)
{
	if(oThis.name == 'displayDonors')
	{
		if(oThis.value == 1)
		{
			document.donForm.scroll_donations.value=0;
			document.donForm.scroll_donations[1].click();
			
		}
		
	}
	else
	{
		if(oThis.value == 1)
			{
				document.donForm.displayDonors.value=0;
				document.donForm.displayDonors[1].click();
			}
		
	}
}

function toggle_top_fundraisers(oThis)
{
	if(oThis.name == 'displayfundraisers')
	{
		if(oThis.value == 1)
		{
			document.donForm.scroll_fundraisers.value=0;
			document.donForm.scroll_fundraisers[1].click();
			
		}
		
	}
	else
	{
		if(oThis.value == 1)
			{
				document.donForm.displayfundraisers.value=0;
				document.donForm.displayfundraisers[1].click();
			}
		
	}
}








