function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		areyjones_07_over = newImage("/images/areyjones/areyjones_07-over.gif");
		areyjones_08_over = newImage("/images/areyjones/areyjones_08-over.gif");
		areyjones_09_over = newImage("/images/areyjones/areyjones_09-over.gif");
		areyjones_10_over = newImage("/images/areyjones/areyjones_10-over.gif");
		preloadFlag = true;
	}
}


function fn_PlaceOrder(){
	// Places this order
	if(document.f_summary.UsedFor.value != ''){
		// All OK...
		document.f_summary.action = '/index.php/Order/place_order';
		document.f_summary.submit();	
	}else{
		// No Used For value entered
		alert("Please enter what this system will be used for.");
	}
}

function fn_PDF(){
	// User wants a PDF of this order
	if(document.f_summary.UsedFor.value != ''){
		// All OK...
		document.f_summary.action = '/index.php/Order/pdf_order/';
		document.f_summary.submit();	
	}else{
		// No Used For value entered
		alert("Please enter what this system will be used for.");
	}
}

function fn_BCPDF(OrderNo,SessionID){
	// User wants to generate a PDF of the order (Baldwin specific version)
	document.f_summary.action = '/index.php/Order/pdf_order/'+SessionID+'/'+OrderNo;
	document.f_summary.submit();		
}

function fn_Login(){
	// User wants to login to the system
	if(document.getElementById("vt_Password").value != ''){
		if(document.getElementById("vt_LoginID").value != ''){
			// All looks good... Post it
			document.f_login.action = '/index.php/Welcome/start_login_process';
			document.f_login.submit();
		}else{
			alert("Please enter your login ID");
		}
	}else{
		alert("Please enter your password");
	}
}

function fn_StartRun(CampaignID){
	// User wants to run a campaign
	if(fn_DisplayButtonMsg(1,"Please confirm to start the process of sending emails for this campaign")){	
		document.f_camplist.action = '/index.php/Admin/start_run/'+CampaignID;
		document.f_camplist.submit();	
	}	
}

function fn_SaveList(){
	// User wants to save their Brand Entries
	if(document.f_listadd.listname.value != ''){
		// OK to save
		document.f_listadd.action = '/index.php/Admin/save_list';
		document.f_listadd.submit();
	}else{
		alert("Please enter a name for the List");
	}
}

function fn_SaveSystem(){
	// User wants to save their system entry
	if(document.f_update.system_title.value != ''){
		if(document.f_update.system_brand.value != 'Select'){
			if(document.f_update.system_type.value != 'Select'){
				// All looks good... submit			
				document.f_update.submit();
			}else{
				// No system type selected
				alert("Please select a system type");
			}
		}else{
			// No system brand selected
			alert("Please select a brand");
		}
	}else{
		// No System Title entered
		alert("Please enter a System Title");
	}
}

function fn_SaveOption(){
	// User wants to save their system option entry
	if(document.f_update.option_shortdesc.value != ''){
		if(document.f_update.option_longdesc.value != ''){
			if(document.f_update.option_system.value != 'Select'){
				if(document.f_update.option_type.value != 'Select'){
					// All looks good... submit
					document.f_update.submit();
				}else{
					// No type selected
					alert("Please select an option type");
				}
			}else{
				// No system selected
				alert("Please select the applicable system");
			}
		}else{
			// No Long Desc entered
			alert("Please enter a long description");
		}
	}else{
		// No Short Desc entered
		alert("Please enter a short description");
	}
}

function fn_ChangeListPD(){
	// User has changed a list pulldown item
	var pditem = document.f_recipient.list_records[document.f_recipient.list_records.selectedIndex].value;
	document.f_recipient.action = '/index.php/Admin/manage_recipients/' + pditem;
	document.f_recipient.submit();
	
}

function fn_Refresh(){
	// General function to refresh the current form with the current HREF action string + 'R' at the end
	document.f_update.action = top.location.href + '/R';
	document.f_update.submit();
}

function fn_DeleteList(ListID){
	// User wants to delete a list
	if(fn_DisplayButtonMsg(1,"Please confirm to delete this list")){	
		document.f_lists.action = '/index.php/Admin/delete_list/'+ListID;
		document.f_lists.submit();	
	}
}

function fn_SaveCampaign(){
	// User wants to save a campaign from the form
	// Assign the content of TinyMCE to the textarea var
	document.f_campaign.email_body.value = tinyMCE.get('email_body').getContent();
	
	if(document.f_campaign.cpg_name.value != ''){
		if(document.f_campaign.email_subject.value != ''){
			if(document.f_campaign.email_body.value != ''){
				if(document.f_campaign.email_replyto.value != ''){
					if(document.f_campaign.email_replytoname.value != ''){
						// Make sure that there is an unsubscribe link in the email body
						var check_text = document.f_campaign.email_body.value;
						var where_is_unsubscribe = check_text.indexOf('{unsubscribe}');
						if(where_is_unsubscribe >=0){
							// Looks ok from here...
							document.f_campaign.action = '/index.php/Admin/campaign_save';
							document.f_campaign.submit();
						}else{
							alert("You must include an {unsubscribe} tag somewhere in the email body (its case sensitive).");
						}						
					}else{
						alert("You must enter a Reply To name");
					}
				}else{
					alert("You must enter a Reply To email address");
				}
			}else{
				alert("Please enter some text for the email body");
			}
		}else{
			alert("Please enter the email subject");
		}
	}else{
		alert("Please enter a name for this campaign");
	}  
}

function fn_DeleteCampaign(CampaignID){
	if(fn_DisplayButtonMsg(1,"Please confirm to delete this campaign")){	
		document.f_camplist.action = '/index.php/Admin/campaign_delete/'+CampaignID;
		document.f_camplist.submit();	
	}	
}

function fn_SendTestEmail(){
	// User wants to send a test email
	if(document.f_testemail.vt_TestEmail.value != ''){
		document.f_testemail.action = '/index.php/Admin/test_email/'+document.f_testemail.cpg_id.value;
		document.f_testemail.submit();
	}else{
		alert("Please enter an email address to send to");
	}
}

function fn_DisplayButtonMsg(ConfirmAlert,MsgField,AdditionalMsg){
       // ConfirmAlert = 0 for Alert   message
       //              = 1 for Confirm message
       //              = 2 for Request message
       // Replace  "|" with a new line (carage return) in the displayed message
       // Boolean is returned
       //Replace the | delimitor with a new line
       var Msg;
       NumOfArguments=fn_DisplayButtonMsg.arguments.length;
       Msg = MsgField;
       var MsgArray = Msg.split("|");
       ArraySize = MsgArray.length;
       Msg = "";
        for(i=0;i<ArraySize;i++){
           var Msg = Msg + MsgArray[i]+"\n";
           }
        if(NumOfArguments>2){
           Msg =Msg+AdditionalMsg;}

        if(ConfirmAlert==0){
          return alert(Msg);}

        if(ConfirmAlert==1){
           return confirm(Msg);}

        if(ConfirmAlert==2){
           return window.prompt(Msg,"");
		}
}


function fn_ConfirmUpload(UploadType){
	// User wants to upload a file of email addresses to the database
	if(document.f_emailupload.list_records[document.f_emailupload.list_records.selectedIndex].value != ''){
		if(document.f_emailupload.uploadedfile.value != ''){
			// All looks good so far... Get user confirmation
			if(fn_DisplayButtonMsg(1,"Please confirm to upload this file to list "+document.f_emailupload.list_records[document.f_emailupload.list_records.selectedIndex].text)){
				// All ok to upload
				document.f_emailupload.action = '/index.php/Admin/upload_complete/'+UploadType+'/'+document.f_emailupload.list_records[document.f_emailupload.list_records.selectedIndex].value;
				document.f_emailupload.submit();
			}
		}else{
			alert("Please choose a file for uploading");
		}
	}else{
		alert("Please select a list to assign the email addresses to.");
	}
}

function fn_DeleteConfirm(ConfirmMsg){
	// Confirm a delete
	return fn_DisplayButtonMsg(1,ConfirmMsg,'');
}

function fn_DeleteOption(a_client_no){
	// The user has requested to delete an option
	if(fn_DeleteConfirm('Please confirm to delete the selected option')){
		// User has confirmed the delete
		document.f_update.action = '/index.php/Admin/deleteOption/'+a_client_no+'/'+document.f_update.option_id.value;
		document.f_update.submit();
	}
}

function fn_DeleteSystem(a_client_no){
	// The user has requested to delete an option
	if(fn_DeleteConfirm('Please confirm to delete the selected system')){
		// User has confirmed the delete
		document.f_update.action = '/index.php/Admin/deleteSystem/'+a_client_no+'/'+document.f_update.system_id.value;
		document.f_update.submit();
	}
}

function fn_PlaceOrder(){
	// Places this order
	if(document.f_summary.UsedFor.value != ''){
		// All OK...
		document.f_summary.action = '/index.php/Order/print_order/'+document.f_session.sesionid.value+'/'+document.f_summary.vBrandID.value+'/'+document.f_summary.vTypeID.value+'/'+document.f_summary.vSysID.value;
		document.f_summary.submit();	
	}else{
		// No Used For value entered
		alert("Please enter what this system will be used for.");
	}
}

function fn_Print(){
		// Ready to print
	   bV = parseInt(navigator.appVersion)
	   if (bV >= 4){
	   	 window.print();
		}else{
			alert("Your browser is not compatible with printing this page.  Select PRINT from the File menu on your browser to print this document.");
		}
}

function fn_PDF(){
	// User wants a PDF of this order
	if(document.f_summary.UsedFor.value != ''){
		// All OK...
		document.f_summary.action = '/index.php/Order/pdf_order/'+document.f_session.sessionid.value;
		document.f_summary.submit();	
	}else{
		// No Used For value entered
		alert("Please enter what this system will be used for.");
	}
}

function fn_PrintOrder(){
	// User wants to print an order - do this in a clean window
	var TheURI = location.pathname;
	var URIString = new String();
	URIString.value = TheURI;
	
	// Now open in its own window
	//alert("The URI bit to work with is "+URIString.value+" and the args are "+URIString.value.substring(23));
	winref = window.open('/index.php/Order/printorder'+URIString.value.substring(23),'mywin',
'left=70,top=70,width=700,height=500,toolbar=1,resizable=0,scrollbars');
}

function fn_OCILogin(){
	// User wants to login to the system
	if(document.f_login.hook_url.value != ''){
		// All looks good... Post it
		document.f_login.action = '/index.php/Welcome';
		document.f_login.submit();
	}else{
		alert("Missing HOOK_URL value");
	}
}

function fn_ValidateClientLogin(){
	// Handles user login validation - designed for LA County but will work with any user/email type starting form
	if(document.f_start.vt_LoginID.value != ''){
		// All ok - begin
		document.f_start.action = '/index.php/Welcome/user_start_process';
		document.f_start.submit();
	}else{
		alert("Please enter your email address");
	}
}

function fn_ProcessOrder(){
	// User wants to process their current order
	document.f_summary.action = '/index.php/Order/process/'+document.f_session.sessionid.value;
	document.f_summary.submit();
}

function fn_SubmitToSRM(){
	// Submits the current order page to SAP SRM
	if(document.f_ocisummary.action != ''){
		document.f_ocisummary.submit();
	}else{
		alert('Unable to submit order.  No form action found.');
	}
}

function fn_ValidateUserStart(){
	// Handles user login validation - designed for LA County but will work with any user/email type starting form
	if(document.f_start.useremail.value != ''){
		// All ok - begin
		document.f_start.action = '/index.php/Welcome/user_start_process';
		if (typeof(vt_LoginID) != "undefined") {
			document.f_start.useremail.value = document.f_start.vt_LoginID.value;
			document.f_start.userpassword.value = document.f_start.vt_Password.value;	
		}
		document.f_start.submit();
	}else{
		alert("Please enter your email address");
	}
}

function fn_ValidateUserOrderLogin(){
	// Handles user login validation - designed for LA County but will work with any user/email type starting form
	if(document.f_form.vt_CustEmail.value != ''){
		// All ok - begin
		document.f_form.action = '/index.php/Welcome/user_login_checkout/'+document.f_form.SessionID.value+'/'+document.f_form.cart_no.value;
		document.f_form.submit();
	}else{
		alert("Please enter your email address");
	}
}

function fn_BCCompleteOrder(){
	// User wants to complete an order
	if(document.f_summary.vt_Memo.value != ''){
		if(fn_DisplayButtonMsg(1,document.f_summary.ConfMsg.value)){
			document.f_summary.action = '/index.php/Order/complete_order/'+document.f_summary.SessionID.value+'/'+document.f_summary.CartNo.value;
			document.f_summary.submit();
		}
	}else{
		alert("Please enter your school name and intended usage information");
	}
}

function fn_CompleteOrder(){
	// User wants to complete an order
	if(fn_DisplayButtonMsg(1,document.f_summary.ConfMsg.value)){
		document.f_summary.action = '/index.php/Order/complete_order/'+document.f_summary.SessionID.value+'/'+document.f_summary.CartNo.value;
		document.f_summary.submit();
	}
}

function fn_CartDelLine(LineNo){
	// User wants to remove a line from their shopping cart
	if(fn_DisplayButtonMsg(1,'Please confirm to delete the selected line from your shopping cart')){
		// User confirmed
		document.f_summary.action = '/index.php/Order/del_line/'+document.f_summary.SessionID.value+'/'+LineNo;
		document.f_summary.submit();
	}
}

function fn_KeepShopping(){
	// User wants to return to the start of the shopping process again
	document.f_summary.action = '/index.php/Order/keep_shopping/'+document.f_summary.SessionID.value;
	document.f_summary.submit();
}

function fn_UpdateQty(LineNo,NewQty){
	// User wants to update the quantity of a line
	document.f_summary.action = '/index.php/Order/update_qty/'+document.f_summary.SessionID.value+'/'+LineNo+'/'+NewQty;
	document.f_summary.submit();
}

function fn_ForgotPassword(){
	// User has forgotten their password
	if(document.f_forgot.useremail.value != ''){
		document.f_forgot.action = '/index.php/Welcome/forgotpasswordprocess';
		document.f_forgot.submit();
	}else{
		alert("Please enter your email address");
	}
}

function fn_GotoForgotPassword(){
	// User wants to retrieve their password from Order Login page
	document.f_form.action = '/index.php/Welcome/forgotpassword';
	document.f_form.submit();
}

function fn_GotoRegisterAccount(){
	// User wants to register a new account
	document.f_form.action = '/index.php/Welcome/createaccount';
	document.f_form.submit();
}

function fn_SendTo(URLAddress){
	// For the registration - sends the user to a specified URL as a post
	document.f_form.action = URLAddress;
	document.f_form.submit();
}

function fn_ValidateCreateAccount(){
	// User is submitting a create account request
	if(document.f_customer.cust_email.value != ''){
		if(document.f_customer.cust_pass1.value != ''){
			if(document.f_customer.cust_pass2.value != ''){
				if(document.f_customer.cust_name.value != ''){
					if(document.f_customer.cust_phone.value != ''){
						if(document.f_customer.cust_billaddr.value != ''){
							if(document.f_customer.cust_billcitystate.value != ''){
								if(document.f_customer.cust_billzip.value != ''){
									if(document.f_customer.cust_shipaddr.value != ''){
										if(document.f_customer.cust_shipcitystate.value != ''){
											if(document.f_customer.cust_shipzip.value != ''){
												// check that the passwords match
												if(document.f_customer.cust_pass1.value == document.f_customer.cust_pass2.value){
													// All ok to process
													document.f_customer.action = '/index.php/Welcome/createaccountprocess/';
													document.f_customer.submit();
												}else{
													alert("Your passwords do not match");
												}
											}else{
												alert("Please enter your shipping address zip code");
											}
										}else{
											alert("Please enter your shipping address city & state");
										}
									}else{
										alert("Please enter your shipping address");
									}
								}else{
									alert("Please enter your billing address zip code");
								}
							}else{
								alert("Please enter your billing address city & state");
							}
						}else{
							alert("Please enter your billing address");
						}
					}else{
						alert("Please enter your telephone number");
					}
				}else{
					alert("Please enter your name");
				}
			}else{
				alert("Please re-type in your password");
			}
		}else{
			alert("Please enter your password");
		}
	}else{
		alert("Please enter your email address");
	}
}

function fn_BillToShip(ButtonState){
	// User wants to copy bill address data to ship address
	if(ButtonState){
		// The button is checked
		document.f_customer.cust_shipaddr.value = document.f_customer.cust_billaddr.value;
		document.f_customer.cust_shipcitystate.value = document.f_customer.cust_billcitystate.value;
		document.f_customer.cust_shipzip.value = document.f_customer.cust_billzip.value;
		// Select the appropriate pulldown value
		document.f_customer.cust_shipcountrypd[document.f_customer.cust_shipcountrypd.selectedIndex].value = document.f_customer.cust_billcountrypd[document.f_customer.cust_billcountrypd.selectedIndex].value;
	}
}

function fn_CustServiceBack(){
	// User wants to return to the customer service main menu
	document.f_ordersearch.action = '/index.php/Welcome/mainmenu/'+document.f_ordersearch.SessionID.value;
	document.f_ordersearch.submit();
}


function fn_CustServiceStart(){
	// User wants to return to the customer service main menu
	document.f_poreview.action = '/index.php/Welcome/mainmenu/'+document.f_poreview.session_id.value;
	document.f_poreview.submit();
}

function fn_DelPOLine(LineNo,PONo){
	// Deletes a Purchase Order Line
	if(fn_DisplayButtonMsg(1,'Please confirm to delete the selected line from the purchase order')){
		document.f_poedit.action = '/index.php/Admin/del_line_from_po/'+PONo+'/'+LineNo;
		document.f_poedit.submit();
	}
}

function fn_ValidatePOLine(){
	// Validate the data entry from a PO Line 
	var OKToSubmit = false;
	if(document.f_editpo.line_qty.value >0){
		if(document.f_editpo.line_desc.value != ''){
			if(document.f_editpo.tracking_info.value != ''){
				if(document.f_editpo.ship_carrier.value != 'Select'){
					OKToSubmit = true;
				}else{
					// You can't have a shipping tracking info field without selecting a carrier
					alert("Please select a carrier for the tracking info");
				}
			}else{
				OKToSubmit = true;
			}
			
			if(OKToSubmit){
				// All looks ok - submit the form
				document.f_editpo.action = '/index.php/Admin/save_po_line/'+document.f_editpo.line_id.value+'/'+document.f_editpo.po_id.value;
				document.f_editpo.submit();
			}
		}else{
			alert("The line description cannot be blank");
		}
	}else{
		// Line quantity invalid
		alert("Invalid line quantity.  Must be greater than 0");
	}
}

function fn_ValidatePOLineForAdd(){
	// Validate the data entry from a PO Line 
	if(document.f_editpo.line_qty.value >0){
		// Qty is valid - save it
		document.f_editpo.action = '/index.php/Admin/save_default_lines/'+document.f_editpo.po_id.value+'/'+document.f_editpo.qty_to_create.value;
		document.f_editpo.submit();
	}else{
		// Line quantity invalid
		alert("Invalid line quantity.  Must be greater than 0");
	}
}

function fn_ValidateNewPO(){
	// Validates the data entry for a new PO 
	var QtyToCreate = 0;
	var SubmitOK = false;
	if(document.f_newpo.vt_PONo.value != ''){
		if(document.f_newpo.ordertype[document.f_newpo.ordertype.selectedIndex].value != 'Select'){
			if(document.f_newpo.vt_LineQty.value != ''){
				QtyToCreate = parseInt(document.f_newpo.vt_LineQty.value);
				// Submit
				SubmitOK = true;
			}else{
				// No line qty provided - assume 0
				QtyToCreate = 0;
				// Submit
				SubmitOK = true;
			}
		}else{
			// No type selected
			alert("Please select a type");
		}
	}else{
		alert("Please enter an Order Number");
	}
	
	if(SubmitOK){
		// Submit the form
		document.f_newpo.action = '/index.php/Admin/save_new_po/'+QtyToCreate;
		document.f_newpo.submit();
	}
}

function fn_ConfirmDeletePO(){
	// User wants to delete a PO - validate this first
	if(fn_DisplayButtonMsg(1,'WARNING:  This will delete the entire Purchase Order and is irreversible.  Please confirm that this is exactly what you want to do.')){
		if(fn_DisplayButtonMsg(1,'You are absolutely sure, right?  This is not un-doable.')){
			document.f_poedit.action = '/index.php/Admin/delete_entire_po/'+document.f_poedit.po_id.value;
			document.f_poedit.submit();
		}
	}	
}

function fn_ExportPO(){
	// User wants to export a Purchase Order to a CSV file
	document.f_poedit.action = '/index.php/Admin/export_po/'+document.f_poedit.po_id.value;
	document.f_poedit.submit();
}

function fn_ValidatePart(){
	// Validates the edit part form
	if(document.f_editpart.part_desc.value != ''){
		// This is ok to save
		document.f_editpart.action = '/index.php/Admin/save_part';
		document.f_editpart.submit();
	}else{
		alert("You must enter a Part descrption");
	}
}

function fn_DeletePart(){
	// User wants to delete a part
	if(document.f_editpart.part_id.value != 0){
		if(fn_DisplayButtonMsg(1,'Please confirm to delete this part record.')){
			document.f_editpart.action = '/index.php/Admin/del_part/'+document.f_editpart.part_id.value;
			document.f_editpart.submit();
		}
			
	}else{
		alert("You must be editing an existing part to delete it");
	}
}

function fn_ViewCart(SessionID){
	// User wants to view their shopping cart
	document.f_session.action = '/index.php/Order/show_shoppingcart/'+SessionID;
	document.f_session.submit();
}

function fn_ValidateTrial(){
	// User wants to submit a trial request
	if(document.f_trial.vt_TrialName.value != ''){
		if(document.f_trial.vt_Email1.value != ''){
			if(document.f_trial.vt_Email2.value != ''){
				if(document.f_trial.vt_Email1.value == document.f_trial.vt_Email2.value){
					if(document.f_trial.vt_Org.value != ''){
						if(document.f_trial.vt_Phone.value != ''){
							if(document.f_trial.vt_ChosenLoginID.value != ''){
								if(document.f_trial.vt_Describe.value != ''){
									if(document.f_trial.vt_Address1.value != ''){
										if(document.f_trial.vt_City.value != ''){
											if(document.f_trial.vt_State.value != ''){
												if(document.f_trial.vt_Zip.value != ''){
													if(document.f_trial.vt_Country.value != ''){
														// All looks ok... submit it
														document.f_trial.action = '/index.php/Welcome/user_form_process';
														document.f_trial.submit();														
													}else{
														alert("Please enter your Country");
													}
												}else{
													alert("Please enter your Zip or Postal Code");
												}
											}else{
												alert("Please enter your State/Province");
											}
										}else{
											alert("Please enter your city");
										}
									}else{
										alert("Please enter your street address");
									}
								}else{
									alert("Please describe your need for our services");
								}
							}else{
								alert("Please enter a login ID for your account");
							}
						}else{
							alert("Please enter your phone number");
						}
					}else{
						alert("Please enter your organization name");
					}
				}else{
					alert("The email addresses you entered do not match.  Please correct the problem.");
				}
			}else{
				alert("Please enter your confirmation email address");
			}
		}else{
			alert("Please enter your email address");
		}
	}else{
		alert("Please enter your name");
	}
}

function fn_ValidateSpamReport(){
	// User wants to submit a trial request
	if(document.f_trial.vt_TrialName.value != ''){
		if(document.f_trial.vt_Email1.value != ''){
			if(document.f_trial.vt_Email2.value != ''){
				if(document.f_trial.vt_Email1.value == document.f_trial.vt_Email2.value){
					if(document.f_trial.vt_Describe.value != ''){
						// All looks ok... submit it
						document.f_trial.action = '/index.php/Welcome/spamreport_submit';
						document.f_trial.submit();
					}else{
						alert("Please describe why you feel this is spam");
					}
				}else{
					alert("The email addresses you entered do not match.  Please correct the problem.");
				}
			}else{
				alert("Please enter your confirmation email address");
			}
		}else{
			alert("Please enter your email address");
		}
	}else{
		alert("Please enter your name");
	}
}

function fn_ExplainImages(){
	// User wants an explanation to the different types of image handling
	winref = window.open('/index.php/Admin/explain_images','mywin',
'left=70,top=70,width=700,height=500,toolbar=1,resizable=0,scrollbars');	
}

function fn_SaveUploadImages(GoNext){
	// User wants to save the upload images page
	if(GoNext == 1){
		document.f_uploadimages.action = '/index.php/Admin/upload_images_save/'+document.f_uploadimages.campaign_id.value+'/1';		
	}else{
		if(GoNext == 2){
			document.f_uploadimages.action = '/index.php/Admin/upload_images_save/'+document.f_uploadimages.campaign_id.value+'/2';
		}else{
			document.f_uploadimages.action = '/index.php/Admin/upload_images_save/'+document.f_uploadimages.campaign_id.value;
		}
	}
	document.f_uploadimages.submit();
}


function fn_SaveUploadAttachments(){
	// User wants to save the upload attachments page
	document.f_uploadimages.action = '/index.php/Admin/upload_attachments_save/'+document.f_uploadimages.campaign_id.value;
	document.f_uploadimages.submit();
}

function fn_VersionInfo(AppID){
	// User wants to see revision history for the app id
	var SendTo = 'http://www.edgeneering.com/edg_relhistory.php?AppID='+AppID;
	// Open a new window, pointed to this URL
	winref = window.open(SendTo,'mywin','toolbar=no,scrollbars=no,location=no,resizable=yes,width=765,height=550,left=225,top=120');
}

function fn_FindByEmail(){
	// User wants to find a specific email address as entered
	if(document.f_recipient.vt_SearchEmail.value != ''){
		// Got something to search for
		document.f_recipient.action = '/index.php/Admin/find_by_email/'+document.f_recipient.list_records[document.f_recipient.list_records.selectedIndex].value;
		document.f_recipient.action = document.f_recipient.action + '/'+vt_SearchEmail.value;
		document.f_recipient.submit();
	}
}

function checkEnter(e){ //e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}else{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		document.forms[0].submit(); //submit the form
		return false;
	}else{
		return true;
	}
}

function recipEnter(e){ //e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}else{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		document.forms[0].action = 'javascript:fn_FindByEmail()';
		document.forms[0].submit(); //submit the form
		return false;
	}else{
		return true;
	}
}

function addemailEnter(e){ //e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}else{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		document.forms[0].action = 'javascript:fn_SaveEmailToList()';
		document.forms[0].submit(); //submit the form
		return false;
	}else{
		return true;
	}
}

function fn_AddEmailToList(){
	// User wants to add an email address to a selected list
	// Make sure that a list has been first selected
	var SelList = document.f_recipient.list_records[document.f_recipient.list_records.selectedIndex].value; 
		
	if(SelList != 0){
		// Something has been selected
		document.f_recipient.action = '/index.php/Admin/add_email/'+document.f_recipient.list_records[document.f_recipient.list_records.selectedIndex].value;
		document.f_recipient.submit();
	}else{
		alert("Please select the list you wish to add the emails to first");
	}
}

function fn_SaveEmailToList(){
	// User wants to save a new email to a list
	var SelList = document.f_addemail.list_records[document.f_addemail.list_records.selectedIndex].value; 
	
	if(document.f_addemail.vt_NewEmail.value != ''){
		// Email address was entered
		if(SelList != 0){	
			// Validate the email address to make sure its ok
			if(echeck(document.f_addemail.vt_NewEmail.value)){
				document.f_addemail.action = '/index.php/Admin/save_email/'+document.f_addemail.list_records[document.f_addemail.list_records.selectedIndex].value;
				document.f_addemail.submit();
			}
		}else{
			alert("Please select a list for this email");
		}
	}else{
		alert("Please enter an email address");
	}
}

function fn_RemoveRecipient(RecipNo,ListNo){
	// User wants to delete a recipient
	if(fn_DisplayButtonMsg(1,'You are absolutely sure, right?  This deletion is permanent.')){
		document.f_recipient.action = '/index.php/Admin/remove_recipient/'+RecipNo+'/'+ListNo;
		document.f_recipient.submit();
	}
}

function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail address")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail address")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail address")
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail address")
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail address")
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid E-mail address")
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail address")
	    return false
	 }

		 return true					
}

function fn_DownloadEmails(){
	// User wants to download emails from the Recipients list page
	document.f_recipient.action = '/index.php/Admin/download_email/'+document.f_recipient.list_records[document.f_recipient.list_records.selectedIndex].value;
	document.f_recipient.submit();
}

function fn_UseHTMLEditor(){
	// User wants to open a seperate window for HTML editing of a Campaign
	winref = window.open('/index.php/Admin/explain_images','mywin',	'left=70,top=70,width=700,height=500,toolbar=1,resizable=0,scrollbars');	
}

function fn_SaveCampaignAdd(){
	// User wants to create a new campaign
	if(document.f_campaignadd.campaign_name.value != ''){
		// This should be enough to save it
		document.f_campaignadd.action = '/index.php/Admin/save_new_campaign';
		document.f_campaignadd.submit();		
	}else{
		alert("You must enter a name for the campaign");
	}
}

function fn_SubscribeFormBuild(){
    // User wants to submit a double optin subscribe form
    if(document.f_subscribe.vt_successurl.value != ''){
        if(document.f_subscribe.vt_failurl.value != ''){
            // OK to post
            document.f_subscribe.action = '/index.php/Admin/build_double_optin_form';
            document.f_subscribe.submit();
        }else{
            alert('Please enter the URL for failed subscribe requests');
        }
    }else{
        alert('Please enter the URL for successful subscribe requests');
    }
}
