var overlayURL = '';
var featureInterval = 0;

$(function() {
	
	// admin navigation
	// ---------------------------------------------------------------------------------------------
	$("#mainContent").delegate("#adminNav div.navBox","click",function() {
		var bloc = $(this).attr('id').replace("nav","");
		var burl = "";
		var bmethod = "post";
		
		switch(bloc) {
			case "Users":
				burl = "/admin/users.php";
				break;
				
			case "Companies":
				burl = "/admin/companies.php";
				break;
				
			case "Vendors":
				burl = "/admin/vendors.php";
				break;
				
			case "DNC":
				burl = "/admin/dnc.php";
				break;
				
			case "DRS":
				burl = "/admin/drs.php";
				break;
				
			case "Logout":
				burl = false;
				window.location = "/?a=logout";
				break;
		}
		if(burl) {
			$.ajax({
				url: burl,
				type: bmethod,
				beforeSend: function() {
					$("#mainContentLoading").removeClass("hide");
				},
				error: function() {
					$("#mainContentLoading").addClass("hide");
				},
				success: function(html) {
					// turn off the spinny thing...
					$("#mainContentLoading").addClass("hide");
					$("#mainContent").html(html);
					
					$("#calstart").datepicker({maxDate: 0, altField: "#exportStart", altFormat: "yy-mm-dd", numberOfMonths: 2});
					$("#calend").datepicker({maxDate: 0, altField: "#exportEnd", altFormat: "yy-mm-dd", numberOfMonths: 2});
					window.scrollTo(0,0);
				}
			});
		}
		return false;	
	});
	
	// export buttons
	// ---------------------------------------------------------------------------------------------
	$("#mainContent").delegate("#options div.exportBut","click",function() {
		var xportType = $(this).attr('id').replace("export_","");
		// we need the values for start & end...
		//
		var start = $("#exportStart").val();
		var end = $("#exportEnd").val();
		var pub = $("#exportPub").val();
		
		
		switch(xportType) {
			case "dnld":
				$.download('/admin/export.php','action='+xportType+'&source=dnc&pub='+pub+'&start='+start+'&end='+end,'post');
				$("#exportMsg").html("File Successfully Downloaded");
				break;
				
			case "ftp":
				$.ajax({
					url: "/admin/export.php",
					type: "post",
					data: "action="+xportType+"&source=dnc&pub="+pub+"&start="+start+"&end="+end,
					beforeSend: function() {
						$("#mainContentLoading").removeClass("hide");
					},
					error: function() {
						$("#mainContentLoading").addClass("hide");
					},
					success: function(html) {
						// turn off the spinny thing...
						$("#mainContentLoading").addClass("hide");
						$("#exportMsg").html(html);
						window.scrollTo(0,0);
					}
				});
				break;
		}
	});
	
	
	
	
	
	
	// these will be re-used...
	// these are deprecated...
	$("#dncN, #dncNT").click(function() {
		if(!$("#mainContent").hasClass("tools")) {
			$("#mainContent").addClass("tools");
		}
		$.ajax({
			url: "/admin/dnc.php",
			type: "post",
			//data: "cid="+ channel +"&scid="+ subchannel,
			beforeSend: function() {
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				// turn off the spinny thing...
				$("#mainContentLoading").addClass("hide");
				$("#mainContent").html(html);
				$("#calstart").datepicker({maxDate: 0, altField: "#exportStart", altFormat: "yy-mm-dd", numberOfMonths: 2});
				$("#calend").datepicker({maxDate: 0, altField: "#exportEnd", altFormat: "yy-mm-dd", numberOfMonths: 2});
				window.scrollTo(0,0);
			}
		});
		return false;
	});
	
	$("#pnlN").click(function() {
		$.ajax({
			url: "/admin/pnl.php",
			type: "post",
			//data: "cid="+ channel +"&scid="+ subchannel,
			beforeSend: function() {
				// before send goes here...
				// put in the cool ajax spinny thing.
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				//alert('error!');
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				// turn off the spinny thing...
				$("#mainContentLoading").addClass("hide");
				$("#mainContent").html(html);
				window.scrollTo(0,0);
			}
		});
		return false;	
	});
	
	$("#vndN").click(function() {
		$.ajax({
			url: "/admin/vendors.php",
			type: "post",
			//data: "cid="+ channel +"&scid="+ subchannel,
			beforeSend: function() {
				// before send goes here...
				// put in the cool ajax spinny thing.
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				//alert('error!');
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				// turn off the spinny thing...
				$("#mainContentLoading").addClass("hide");
				$("#mainContent").html(html);
				window.scrollTo(0,0);
			}
		});
		return false;	
	});
	
	$("#cmpN").click(function() {
		//alert('running');
		$.ajax({
			url: "/admin/companies.php",
			type: "post",
			//data: "cid="+ channel +"&scid="+ subchannel,
			beforeSend: function() {
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				$("#mainContentLoading").addClass("hide");
				$("#mainContent").html(html);
				window.scrollTo(0,0);
			}
		});
		return false;	
	});
	
	$("#usrN").click(function() {
		//alert('running');
		$.ajax({
			url: "/admin/users.php",
			type: "post",
			//data: "cid="+ channel +"&scid="+ subchannel,
			beforeSend: function() {
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				$("#mainContentLoading").addClass("hide");
				$("#mainContent").html(html);
				window.scrollTo(0,0);
			}
		});
		return false;	
	});
	
	// GLOBAL TOOLS
	
	// global: mini add user display (on-off)... (should be done with toggle syntax)
	// might work for ALL versions of the code... that would be nice...
	$("#mainContent").delegate("#options #userAddShow","click",function() {
		// we need to turn on a few things...
		$(this).addClass("hide");
		$("#userAddHide").removeClass("hide");
		$("#userAdd").removeClass("hide");
	});
	$("#mainContent").delegate("#options #userAddHide","click",function() {
		// we need to turn on a few things...
		$(this).addClass("hide");
		$("#userAddShow").removeClass("hide");
		$("#userAdd").addClass("hide");
	});
	
	
	// USERS
	// ---------------------------------------------------------------------------------------------
	// users: type navigation...
	$("#mainContent").delegate("#userTypeNav div.type","click",function() {
		var userType = $(this).attr('id').replace("user","");
		
		// now, let's turn off ALL of the items in the userTypeNav...
		$("#userTypeNav>div").removeClass("on");
		$(this).addClass("on");
		
		// now, we need to turn on the appropriate window for review...
		// first, we need to turn off all of the appropriate windows...
		
		// we only want to go down one level...
		// not multiple levels...
		$("#userList>div").hide();
		
		
		$("#userList div#usr"+userType).show();
		
		$("#options").html("<div class='warp'><div class='tooltitle'>Select a User from the list at left.</div></div>");
		//alert('works: ' + userType);
	});
	
	// user: listing click...
	$("#mainContent").delegate("div.user","click",function() {
		//alert('yes');
		var userID = $(this).attr('id').replace("user_","");
		//alert("user: "+userID);
		
		$.ajax({
			url: "/admin/users.php",
			type: "post",
			data: "userID="+userID,
			beforeSend: function() {
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				$("#mainContentLoading").addClass("hide");
				$("#mainContent").html(html);
				window.scrollTo(0,0);
				
				// we need to scroll the userlist to the correct location...
				// how to do that...
				var p = $("div.user.on");
				var position = p.position();
				var toppos = (position.top - 375);
				if(toppos < 0) {
					toppos = 0;
				}
				//alert('scrollpos: ' + toppos);
				$("#userList").scrollTop(toppos);
			}
		});
	});
	
	// user: set scope form...
	$("#mainContent").delegate("form#usrChangeScp","submit",function() {
		var formData = $(this).serialize();
		$.ajax({
			url: "/admin/users.php",
			type: "post",
			data: formData,
			beforeSend: function() {
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				$("#mainContentLoading").addClass("hide");
				$("#mainContent").html(html);
				window.scrollTo(0,0);
			}
		});
		return false;
	});
	
	// user: change password form...
	$("#mainContent").delegate("form#usrChangePswd","submit",function() {
		var formData = $(this).serialize();
		$.ajax({
			url: "/admin/users.php",
			type: "post",
			data: formData,
			beforeSend: function() {
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				$("#mainContentLoading").addClass("hide");
				$("#mainContent").html(html);
				window.scrollTo(0,0);
			}
		});
		return false;
	});
	
	
	// COMPANIES
	// ---------------------------------------------------------------------------------------------
	// company: create form...
	$("#mainContent").delegate("form#cmp","submit",function() {
		var formData = $(this).serialize();
		$.ajax({
			url: "/admin/companies.php",
			type: "post",
			data: formData,
			beforeSend: function() {
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				$("#mainContentLoading").addClass("hide");
				$("#mainContent").html(html);
				window.scrollTo(0,0);
			}
		});
		return false;
	});
	
	// company: user create form...
	$("#mainContent").delegate("form#cmpuser","submit",function() {
		var formData = $(this).serialize();
		$.ajax({
			url: "/admin/companies.php",
			type: "post",
			data: formData,
			beforeSend: function() {
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				$("#mainContentLoading").addClass("hide");
				$("#mainContent").html(html);
				window.scrollTo(0,0);
			}
		});
		return false;
	});
	
	// company: listing click...
	$("#mainContent").delegate("div.company","click",function() {
		//alert('yes');
		var companyID = $(this).attr('id').replace("company_","");
		$.ajax({
			url: "/admin/companies.php",
			type: "post",
			data: "companyID="+companyID,
			beforeSend: function() {
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				$("#mainContentLoading").addClass("hide");
				$("#mainContent").html(html);
				window.scrollTo(0,0);
			}
		});
	});
	
	// company: publication listing click...
	$("#mainContent").delegate("div.paper","click",function() {
		var companyID = $(this).parent().attr('id').replace("company_","").replace("_pubs","");
		var paperID = $(this).attr('id').replace("paper_","");
		$.ajax({
			url: "/admin/companies.php",
			type: "post",
			data: "companyID="+companyID+"&paperID="+paperID,
			beforeSend: function() {
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				$("#mainContentLoading").addClass("hide");
				$("#mainContent").html(html);
				window.scrollTo(0,0);
			}
		});
	});
	
	// company: assign...
	$("#mainContent").delegate("#companyVendor","change",function() {
		var accessVar = $(this).val().split("_");
		if(accessVar) {
			//alert("var: " + accessVar[0] + accessVar[1]);
			$.ajax({
				url: "/admin/companies.php",
				type: "post",
				data: "action=assignVendor&companyID="+accessVar[0]+"&paperID="+accessVar[1]+"&vendorID="+accessVar[2],
				beforeSend: function() {
					$("#mainContentLoading").removeClass("hide");
				},
				error: function() {
					$("#mainContentLoading").addClass("hide");
				},
				success: function(html) {
					$("#mainContentLoading").addClass("hide");
					$("#mainContent").html(html);
					window.scrollTo(0,0);
				}
			});
		}
	});
	
	// company: paper/publication create form...
	$("#mainContent").delegate("form#cmppub","submit",function() {
		var formData = $(this).serialize();
		$.ajax({
			url: "/admin/companies.php",
			type: "post",
			data: formData,
			beforeSend: function() {
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				$("#mainContentLoading").addClass("hide");
				$("#mainContent").html(html);
				window.scrollTo(0,0);
			}
		});
		return false;
	});
	
	// company: paper/publication create form display toggle...
	$("#mainContent").delegate("#options div.create","click",function(e) {
	
		// we could do the same thing here, that we do with the remove stuff...
		// this could be a global, and we could modify the way the id is done, allowing 
		// us to run multiple items through this...
		
		// i'm going to do it separately, then we can move this into it...
		var companyID = $(this).attr('id').replace("_pub_create","");
		$("#"+companyID+"_addPubForm").removeClass("hide");
		$("input#pubName").focus();
	});
	
	// company: add notification
	$("#mainContent").delegate("form#cmpNotify","submit",function() {
		var formData = $(this).serialize();
		$.ajax({
			url: "/admin/companies.php",
			type: "post",
			data: formData,
			beforeSend: function() {
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				$("#mainContentLoading").addClass("hide");
				$("#mainContent").html(html);
				window.scrollTo(0,0);
			}
		});
		return false;
	});
	
	
	
	// VENDORS
	// ---------------------------------------------------------------------------------------------
	
	// vendor: create form...
	$("#mainContent").delegate("form#vnd","submit",function() {
		var formData = $(this).serialize();
		$.ajax({
			url: "/admin/vendors.php",
			type: "post",
			data: formData,
			beforeSend: function() {
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				$("#mainContentLoading").addClass("hide");
				$("#mainContent").html(html);
				window.scrollTo(0,0);
			}
		});
		return false;
	});
	
	// vendor: user create form...
	$("#mainContent").delegate("form#vnduser","submit",function() {
		var formData = $(this).serialize();
		$.ajax({
			url: "/admin/vendors.php",
			type: "post",
			data: formData,
			beforeSend: function() {
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				$("#mainContentLoading").addClass("hide");
				$("#mainContent").html(html);
				window.scrollTo(0,0);
			}
		});
		return false;
	});
	
	// vendor: listing click...
	$("#mainContent").delegate("div.vendor","click",function() {
		var vendorID = $(this).attr('id').replace("vendor_","");
		//alert('works ' + vendorID);
		
		// we need to set the value of this div...
		
		$.ajax({
			url: "/admin/vendors.php",
			type: "post",
			data: "vendorID="+vendorID,
			beforeSend: function() {
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				$("#mainContentLoading").addClass("hide");
				$("#mainContent").html(html);
				window.scrollTo(0,0);
			}
		});
		
		
	});
	
	// vendor: assign...
	$("#mainContent").delegate("#vendorAssign","change",function() {
		var accessVar = $(this).val().split("|");
		if(accessVar) {
			//alert("var: " + accessVar[0] + accessVar[1]);
			$.ajax({
				url: "/admin/vendors.php",
				type: "post",
				data: "action=createVendorCompany&vendorID="+accessVar[0]+"&companyID="+accessVar[1]+"&paperID="+accessVar[2],
				beforeSend: function() {
					$("#mainContentLoading").removeClass("hide");
				},
				error: function() {
					$("#mainContentLoading").addClass("hide");
				},
				success: function(html) {
					$("#mainContentLoading").addClass("hide");
					$("#mainContent").html(html);
					window.scrollTo(0,0);
				}
			});
		}
	});
	
	// vendor: add notification
	$("#mainContent").delegate("form#vndNotify","submit",function() {
		var formData = $(this).serialize();
		$.ajax({
			url: "/admin/vendors.php",
			type: "post",
			data: formData,
			beforeSend: function() {
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				$("#mainContentLoading").addClass("hide");
				$("#mainContent").html(html);
				window.scrollTo(0,0);
			}
		});
		return false;
	});
	
	
	
	
	
	// MORE GLOBAL
	// ---------------------------------------------------------------------------------------------
	
	$("#mainContent").delegate("#options span.update","click",function() {
		var clickData = $(this).attr('id').split("_");
		var answer = "";
		var path = "";
		var data = "";
		
		switch(clickData[0]) {
			case "usrScp":
				$("#currentScp").addClass("hide");
				$("#changeScp").removeClass("hide");
				break;
				
			case "usrScpCancel":
				$("#changeScp").addClass("hide");
				$("#currentScp").removeClass("hide");
				break;
				
			case "usrPswd":
				//$("#currentPswd").addClass("hide");
				$("#changePswdSuccess").html("");
				$("#changePswd").removeClass("hide");
				break;
				
			case "usrPswdCancel":
				//$("#currentPswd").addClass("hide");
				$("#changePswd").addClass("hide");
				break;
				
		}
		
		if(clickData && answer && path) {
			// we can run any necessary ajax here...
		}
	});
	
	// remove clicks...
	$("#mainContent").delegate("#options span.remove","click",function() {
		var removeData = $(this).attr('id').split("_");
		var answer = "";
		var path = "";
		var data = "";
		
		switch(removeData[0]) {
		
			// vendors...
			case "vnd":
				answer = confirm("Are you sure you want to delete this vendor?  This will completely remove the vendor and all of their assigned users.  This operation cannot be undone.");
				path = "/admin/vendors.php";
				data = "action=deleteVendor&vendorID="+removeData[1];
				break;
				
			case "vndusr":
				answer = confirm("Are you sure you want to delete this user?  This will completely remove the user from the system.  This operation cannot be undone.");
				path = "/admin/vendors.php";
				data = "action=deleteVendorUser&vendorID="+removeData[1]+"&userID="+removeData[2];
				break;
				
			case "vndcmp":
				answer = "1";
				path = "/admin/vendors.php";
				data = "action=removeVendorCompany&vendorID="+removeData[1]+"&companyID="+removeData[2]+"&paperID="+removeData[3];
				break;
				
			case "vndntfy":
				answer = confirm("Are you sure you want to delete this email notification?");
				path = "/admin/vendors.php";
				data = "action=removeCompanyNotify&vendorID="+removeData[1]+"&email="+removeData[2];
				break;
				
			// companies...
			case "cmp":
				answer = confirm("Are you sure you want to delete this company?  This will completely remove the company and all of their assigned users.  This operation cannot be undone.");
				path = "/admin/companies.php";
				data = "action=deleteCompany&companyID="+removeData[1];
				break;
				
			case "cmpUser":
				answer = confirm("Are you sure you want to delete this user?  This will completely remove the user from the system.  This operation cannot be undone.");
				path = "/admin/companies.php";
				data = "action=deleteCompanyUser&companyID="+removeData[1]+"&paperID="+removeData[2]+"&userID="+removeData[3];
				break;
				
			case "cmpPub":
				answer = confirm("Are you sure you want to delete this paper?  This will completely remove the paper and it's users from the system.  This operation cannot be undone.");
				path = "/admin/companies.php";
				data = "action=deleteCompanyPub&companyID="+removeData[1]+"&paperID="+removeData[2]+"&userID="+removeData[3];
				break;
				
			case "cmpvnd":
				answer = confirm("Are you sure you want to remove the vendor relationship?");
				path = "/admin/companies.php";
				data = "action=removeCompanyVendor&companyID="+removeData[1]+"&paperID="+removeData[2]+"&vendorID="+removeData[3];
				break;
				
			case "cmpntfy":
				answer = confirm("Are you sure you want to delete this email notification?");
				path = "/admin/companies.php";
				data = "action=removeCompanyNotify&companyID="+removeData[1]+"&paperID="+removeData[2]+"&email="+removeData[3];
				break;
				
			// users
			case "usr":
				// here, we just want to make a drop down appear
				// we can then put the actual code into the "change" operator of that component...
				answer = confirm("Are you sure you want to delete this user?  This will completely remove the user from the system.  This operation cannot be undone.");
				path = "/admin/users.php";
				data = "action=deleteUser&userID="+removeData[1];
				break;
		}
		
		
		if(removeData && answer) {
			//alert("remove: "+removeData[0] + " || " + removeData[1]);
			$.ajax({
				url: path,
				type: "post",
				data: data,
				beforeSend: function() {
					$("#mainContentLoading").removeClass("hide");
				},
				error: function() {
					$("#mainContentLoading").addClass("hide");
				},
				success: function(html) {
					$("#mainContentLoading").addClass("hide");
					$("#mainContent").html(html);
					window.scrollTo(0,0);
				}
			});
		}		
	});
	
	
	// DNC
	// ---------------------------------------------------------------------------------------------
	
	// dnc: number entry form...
	$("#mainContent").delegate("form#dnc","submit",function() {		
		
		// we need to set this up with the form stuff.
		var formData = $(this).serialize();
		
		// set variables...
		var phone = $("input#phone").val();
		var phone2 = $("input#2phone").val();
		var notify = "";
		if($("input#notify").attr("checked")) {
			notify = $("input#notify").val();
		};
						
		// validation...
		if( phone.length != "10" ) {
			if(phone) {
				alert("please enter a ten digit phone number");
			} else {
				alert("phone number must be ten digits.\n(i.e. 1235551212)");
			}
		} else {
			if(phone2 && phone2.length != "10") {
				alert("to phone number must be ten digits.\\n\\n(i.e. 1235551212)");
			} else {
				if(phone2.length && phone2 < phone) {
					alert("to phone number must be greater than starting phone number");
				} else {
					
					// we have valid data... submit to server
					$.ajax({
						url: "/admin/dnc.php",
						type: "post",
						data: formData,
						beforeSend: function() {
							$("#mainContentLoading").removeClass("hide");
						},
						error: function() {
							$("#mainContentLoading").addClass("hide");
						},
						success: function(html) {
							$("#mainContentLoading").addClass("hide");
							$("#mainContent").html(html);
							window.scrollTo(0,0);
						}
					});
				}
			}
		}
		return false;
	});
	
	// dnc campaign lookup...
	$("#mainContent").delegate("form#campaignLookup","submit",function() {
		var formData = $(this).serialize();
		
		//alert('works: ' + formData);
		
		// we have valid data... submit to server
		$.ajax({
			url: "/admin/dnc_campaign.php",
			type: "post",
			data: formData,
			beforeSend: function() {
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				$("#mainContentLoading").addClass("hide");
				$("#campaignPhone").val("");
				$("#campaignDetails").html(html).show();
			}
		});			
					
		return false;
	});
	
	// dnc internal number lookup...
	$("#mainContent").delegate("form#dncLookup","submit",function() {
		var formData = $(this).serialize();
		
		$.ajax({
			url: "/admin/dnc_lookup.php",
			type: "post",
			data: formData,
			beforeSend: function() {
				$("#mainContentLoading").removeClass("hide");
			},
			error: function() {
				$("#mainContentLoading").addClass("hide");
			},
			success: function(html) {
				$("#mainContentLoading").addClass("hide");
				$("#lookupPhone").val("");
				$("#lookupDetails").html(html).show();
			}
		});		
		return false;
	});
				
	// dnc: select publication...
	$("#mainContent").delegate("#publication","change",function() {
		var pubinfo = $(this).val().split("_");
		var pubname = $("#publication option:selected").text();
		var pubstring = "";
		if(pubinfo[0]) {
			pubstring = pubinfo[0]+"_"+pubinfo[1];
			if($("#dnctools").hasClass("hide")) {
				$("#dnctools").removeClass("hide");
			}
		} else {
			if(!$("#dnctools").hasClass("hide")) {
				$("#dnctools").addClass("hide");
			}
		}
		
			// step one, we need to set the hidden values for the dnc forms...
		$("input#dncpub").val(pubstring);
		$("input#udncpub").val(pubstring);
		$("input#exportPub").val(pubstring);
		$("input#campaignPub").val(pubstring);
		$("input#lookupPub").val(pubstring);
			
			// step two, we need to show the dnc form into...
		$("#exportSource").html(pubname);
	});		
	
	
	
	// USER REGISTRATION
	// ---------------------------------------------------------------------------------------------
	
	// auto completes
	$("#newspaper").autocomplete({
		source: "/admin/newspapersJSON.php",
		delay: 500,
		minLength: 2,
		select: function(e, ui) {
			$("#paperID").val(ui.item.id);
		}
	});
	$("#company").autocomplete({
		source: "/admin/companysJSON.php",
		delay: 500,
		minLength: 2,
		select: function(e, ui) {
			
			
			//alert('type: '+ui.item.type);
			switch(ui.item.type) {
				case "company":
					// existing company selected.
					$("#companyID").val(ui.item.id);
					$("#companyType").val("company");
					$("#newspaperSelect").show();
					break;
					
				case "vendor":
					// existing vendor selected.
					$("#vendorID").val(ui.item.id);
					$("#companyType").val("vendor");
					break;
			}
			
			// existing company selected.
			$("#bizType").val(ui.item.type);
		}
	});
					
	$("#companyType").change(function() {
		if($(this).val() == "company") {
			$("#newspaperSelect").show();
		} else {
			$("#newspaperSelect").val("");
			$("#newspaperSelect").hide();
		}
	});
	
	// these are just examples...
	/*
	$("#pageWrap").delegate("div.videOver a","click",function() {
	//$("div.videOver a").click(function() {
		var videoID = $(this).parent().parent().attr('id');
		overlayURL = "/dpComponent/video/overlayVideo?id="+videoID;
		var overlayAPI = $("#mediaOverlay").data("overlay");
		overlayAPI.onClose(function() {
			$("#mediaOverlay .overlayWrap").html("");
		});
		overlayAPI.load();
		return false;
	});
	
	// NOT SURE WHAT THIS NEEDS TO DO... SHOULD JUST LINK TO CALENDAR PAGE...
	$("div.day.event").click(function() 
	{
		
		if($("div#calendarScroll").length) {
			// set the date...
			// let's grab the date directly from the id...
			var date = $(this).attr('id').replace("grid_","");
			var scrollPos = $("#calendarScroll").offset();
			var eventScroll = $("#day_"+date).offset();
			var eventScrollPos = $("#calendarScroll").scrollTop();
			var scrollToPos = eventScroll.top - scrollPos.top - 12;
			var finalScroll = eventScrollPos + scrollToPos;
			$("div#calendarScroll").animate({scrollTop:finalScroll},300);
			$("#day_"+date).effect("highlight",{ },5000);
		}
		
		//alert('works' + scrollPos.top + " || eventScroll: " + eventScroll.top + " || Event Scroll Pos: " + eventScrollPos + " || to move: " + scrollToPos + " || lenght: " + eventLength + " || date: " + year + "-" + month + "-" + day);
	}).mouseenter(function() 
	{
		$(this).addClass("over");
	}).mouseleave(function() 
	{
		$(this).removeClass("over");
	});
	
	// customize tabs...
	if($("#classifiedSpotlight").length) {
		$("#classifiedSpotlight").click(function() {
				$.ajax({
					url: "/dpComponent/classifieds/updateListFeature",
					type: "post",
					data: "cid="+ channel +"&scid="+ subchannel,
					beforeSend: function() {
						$("#contentLoading").removeClass("hide");
						$("#classifiedLatest").removeClass("on");
					},
					error: function() {
						//alert('error!');
					},
					success: function(html) {
						//alert('works');
						$("#contentLoading").addClass("hide");
						$("#classifiedSpotlight").addClass("on");
						$("#ajxWndw").html(html);
						$("body").scrollTop(0);
					}
				});
		});
	}

	*/
});
