$j(document).ready(function () {
	
	$j("#ss_open").click(function() {
		$j("#ss_add").fadeIn("slow");
	});
	
	$j("#ss_close").click(function() {
		$j("#ss_add").fadeOut("slow");
	});
	
	$j("#ss_add_amount").focus(function() {
		if($j(this).val() == "$$$") {
			$j(this).val("");
		}
	});
	$j("#ss_add_amount").blur(function() {
		if($j(this).val() == "") {
			$j(this).val("$$$");
		}
	});
	
	$j("#ss_save_button").click(function() {
		if($j("#ss_name").val() == "") {
			alert("Name must be filled out.");
			$j("#ss_name").focus();
			return false;
		}
		if($j("#ss_email").val() == "") {
			alert("Name must be filled out.");
			$j("#ss_email").focus();
			return false;
		}
		if($j("#ss_coach").val() == "") {
			alert("Name must be filled out.");
			$j("#ss_coach").focus();
			return false;
		}
		if($j("#ss_category").val() == "") {
			alert("Name must be filled out.");
			$j("#ss_cateogyr").focus();
			return false;
		}
		if($j("#ss_amount").val() == "") {
			alert("Name must be filled out.");
			$j("#ss_amount").focus();
			return false;
		}
		if($j("#ss_q1").val() == "1. What were you doing before you started this business?") {
			alert("Question 1 must be answered.");
			$j("#ss_q1").focus();
			return false;
		}
		if($j("#ss_q2").val() == "2. How much money were you making previously?") {
			alert("Question 2 must be answered.");
			$j("#ss_q2").focus();
			return false;
		}
		if($j("#ss_q3").val() == "3. How much money are you making now?") {
			alert("Question 3 must be answered.");
			$j("#ss_q3").focus();
			return false;
		}
		if($j("#ss_q4").val() == "4. How has this program positively affected your life?") {
			alert("Question 4 must be answered.");
			$j("#ss_q4").focus();
			return false;
		}
		if($j("#ss_q5").val() == "5. What is the best part of this program?") {
			alert("Question 5 must be answered.");
			$j("#ss_q5").focus();
			return false;
		}
		
		var data = "name="+$j("#ss_add_name").val()+"&email="+$j("#ss_add_email").val()+"&coach="+$j("#ss_add_coach").val()+"&category="+$j("input[name=ss_add_category]:checked").val()+"&amount="+$j("#ss_add_amount").val()+"&q1="+$j("#ss_q1").val()+"&q2="+$j("#ss_q2").val()+"&q3="+$j("#ss_q3").val()+"&q4="+$j("#ss_q4").val()+"&q5="+$j("#ss_q5").val();
		
		$j.ajax({
			type:		'post',
			url:		'/sites/internetsalesinstitute.net/ajax_php/success_story_add.php',
			data:		data,
			success:	function(msg) {
				/* Clear form and fade out div */
				$j("#ss_add").fadeOut();
				$j("#ss_add_name").val("");
				$j("#ss_add_email").val("");
				$j("#ss_add_coach").val("");
				$j("#input[name=ss_add_category]").attr("checked", false);
				$j("#ss_add_amount").val("$$$");
				$j("#ss_q1").val("1. What were you doing before you started this business?");
				$j("#ss_q2").val("2. How much money were you making previously?");
				$j("#ss_q3").val("3. How much money are you making now?");
				$j("#ss_q4").val("4. How has this program positively affected your life?");
				$j("#ss_q5").val("5. What is the best part of this program?");
				
				alert("Your story has been submitted for review.\nThank you.");
			}
		});
	});
	
	$j("#accept_order").click(function() {
		if($j("#npo_toc_check").is(":checked") == false) {
			alert("You must read and agree to the Terms & Conditions.");
			return false;
		}
		if($j("#npo_dig_sig").val() == "") {
			alert("You must enter your full legal name as a valid digital signature.");
			$j("#npo_dig_sig").focus();
			return false;
		}
		if($j("#do_npol").val() == 1) {
			if($j("#npol_toc_check").is(":checked") == false) {
				alert("You must read and agree to the Lightwave Terms & Conditions.");
				return false;
			}
			if($j("#builder_id").val() == "") {
				alert("You must enter your Builder ID.");
				$j("#builder_id").focus();
				return false;
			}
		}
		if($j("#do_npol").val() == 0) {
			var data = "do=accept&lightwave="+$j("#do_npol").val()+"&id="+$j('#npo_id').val()+"&digital_signature="+$j('#npo_dig_sig').val();
		} else {
			var data = "do=accept&lightwave="+$j("#do_npol").val()+"&id="+$j('#npo_id').val()+"&digital_signature="+$j('#npo_dig_sig').val()+"&builder_id="+$j("#builder_id").val();
		}
		
		$j.ajax({
			type:		'post',
			url:		'/sites/internetsalesinstitute.net/ajax_php/product_order_form.php',
			data:		data,
			success:	function(msg) {
				alert(msg);
				$j("#npo_shadow").fadeOut("slow");
				$j("#npo").slideUp("medium");
			}
		});
	});

	$j("#cancel_order").click(function() {
		
		var data = "do=cancel&id="+$j('#npo_id').val();
		
		$j.ajax({
			type:		'post',
			url:		'/sites/internetsalesinstitute.net/ajax_php/product_order_form.php',
			data:		data,
			success:	function(msg) {
				alert(msg);
				$j("#npo_shadow").fadeOut("slow");
				$j("#npo").slideUp("medium");
			}
		});
		
	});
	
	$j(document).bind('keydown', 'Ctrl+backspace', function(evt) {
		var dt_h = $j("#debug_tray").height();
		if(dt_h == 0) {
			$j("#debug_tray").animate({
				height: "400px"
			}, 600);
		} else {
			$j("#debug_tray").animate({
				height: "0px"
			}, 400);
		}
		return false;
	});
	
	
	/**** NICHE IDEAS ORGANIZER ****/
	$j("#nicheTop5creator").draggable({
		handle: $j("#nicheTop5creatorHandle")
	});
	
	$j("#nicheTop5creatorCommit").click(function (){
		var colClass = "nicheG";
		var rowID = $j("#nicheTop5creator").attr("rel");
		var nicheD = "";
		var curVal = "";
		var relStr = "";
		$j("#nicheTop5creator option:selected").each(function (){
			curVal += "&curVal[]=" + $j(this).val();
			relStr += $j(this).val()+"^";
		});
		var myData = 'colClass='+colClass+'&rowID='+rowID+'&nicheD='+nicheD+curVal;
		$j("#nicheTop5creatorAjaxDiv").css("display","block");
		$j.ajax({
			type: 'POST',
			url: '/sites/internetsalesinstitute.net/ajax_php/dashboard_niche_ideas.php',
			data: myData,
			success: function(msg) {
				//alert(msg);
				var topSelVal = $j("#nicheTop5creator select").val();
				$j("#niche_row_"+rowID+" .nicheG").html(topSelVal);
				$j("#niche_row_"+rowID+" .nicheG").attr("rel", relStr);
				$j("#nicheTop5creator").attr("rel","");
				$j("#nicheTop5creator option").removeAttr("selected");
				$j("#nicheTop5creatorAjaxDiv").css("display","none");
				$j("#nicheTop5creator").slideUp("fast");
			}
		});
	});
	
	$j("#nicheTop5creatorCancel").click(function (){
		$j("#nicheTop5creator").attr("rel","");
		$j("#nicheTop5creator option").removeAttr("selected");
		$j("#nicheTop5creator").slideUp("fast");
	});
	
	$j(".textyBoo").click(function () {
		nicheCellClick(this);
	});
	
	$j(".nicheJ").click(function () {
		deleteNicheIdeaRow(this);
	});
	
	$j("#add_niche_brainstorm_row").click(function () {
		$j("#testMSGcell").html("Adding Row...");
		$j.ajax({
			type: 'POST',
			url: '/sites/internetsalesinstitute.net/ajax_php/dashboard_niche_ideas.php?makeNewRow=1',
			data: 'bob=1',
			success: function(msg) {
				var newNicheRow = '<tr class="course_dash_table_blue_bars" id="niche_row_'+msg+'">'
						+'<td class="textyBoo nicheA"><input type="text" id="" value="" style="" class="niche_brainstorm_course_dash_inputs" /></td>'
						+'<td class="textyBoo nicheB" style="border-left: solid #d5eaff 2px;"><input type="text" id="" value="" style="" class="niche_brainstorm_course_dash_inputs" /></td>'
						+'<td class="textyBoo nicheC"><input type="text" id="" value="" style="" class="niche_brainstorm_course_dash_inputs" /></td>'
						+'<td class="textyBoo nicheD"></td>'
						+'<td class="textyBoo nicheE" style="border-right: solid #d5eaff 1px;"><input type="text" id="" value="" style="" class="niche_brainstorm_course_dash_inputs" /></td>'
						+'<td class="textyBoo nicheF" style="border-left: solid #d5eaff 1px;"><input type="text" id="" value="" style="" class="niche_brainstorm_course_dash_inputs" /></td>'
						+'<td class="textyBoo nicheG" style="cursor: pointer;" rel=""><span style="border: solid red 1px;">&nbsp;&nbsp;&nbsp;</span></td>'
						+'<td class="textyBoo nicheH" style="border-right: solid #d5eaff 2px;"><input type="text" id="" value="" style="" class="niche_brainstorm_course_dash_inputs" /></td>'
						+'<td class="textyBoo nicheI"><input type="text" id="" value="" style="" class="niche_brainstorm_course_dash_inputs" /></td>'
						+'<td class="nicheJ" style="text-align: center;"><img src="/images/sites/internetsalesinstitute.net/cancel.png" alt="x" /></td>'
					+'</tr>';
				$j("#add_row_button_row").before(newNicheRow);
				
				$j(".textyBoo").unbind('click');
				$j(".textyBoo").click(function () {
					nicheCellClick(this);
				});
				
				$j(".niche_brainstorm_course_dash_inputs").unbind('keyup');
				$j(".niche_brainstorm_course_dash_inputs").keyup(function () {
					nicheInputBoxKeyUp(this);
				});
				
				$j(".nicheJ").unbind('click');
				$j(".nicheJ").click(function () {
					deleteNicheIdeaRow(this);
				});
				
				$j("#testMSGcell").html("");
			}
		});
	});
	
	
	/**** ALL VIDEOS ****/
	$j(".video_close_text_2,.video_close_button_2").each(function() {
		var id_temp = $j(this).attr('id');
		var id_split = id_temp.split("_");
		var id = id_split[2];
		
		//$j(this).click(function() {
			
			var data = "category="+id;
			
			if($j('#section_'+id+'').is(":hidden")) {
				
				if($j('#section_'+id+'').html() == "") {
					
					$j('#vc_text_'+id+'').html("Loading Videos...");
					$j('#section_arrow_'+id+'').attr('src', '/admin/images/ajax-loader-blue-dots.gif');
					
					$j.ajax({
						type:		'POST',
						url:		'/sites/internetsalesinstitute.net/ajax_php/extras.php',
						data:		data,
						success:	function(msg) {
							$j('#section_'+id+'').html(msg);
							$j('#section_'+id+'').slideDown();
							$j('#vc_text_'+id+'').html("Collapse Section");
							$j('#section_arrow_'+id+'').attr('src', '/images/sites/internetsalesinstitute.net/announce_close.gif');
						}
					});
				} else {
					$j('#section_'+id+'').slideDown();
					$j('#vc_text_'+id+'').html("Collapse Section");
					$j('#section_arrow_'+id+'').attr('src', '/images/sites/internetsalesinstitute.net/announce_close.gif');
				}
			} else {
				$j('#section_'+id+'').slideUp();
				$j('#vc_text_'+id+'').html("Expand Section");
				$j('#section_arrow_'+id+'').attr('src', '/images/sites/internetsalesinstitute.net/announce_open.gif');
			}
		//});
	});
	
	$j('.video_close_text').each(function() {
		var id = $j(this).attr('id');
	
		$j(this).click(function() {
			if($j('#section_'+id+'').is(":hidden")) {
				$j('#section_arrow_'+id+'').attr('src', '/images/sites/internetsalesinstitute.net/announce_close.gif');
				$j('#'+id+'.video_close_text').html("Close Section");
				$j('#section_'+id+'').slideDown('slow');
			} else {
				$j('#section_arrow_'+id+'').attr('src', '/images/sites/internetsalesinstitute.net/announce_open.gif');
				$j('#'+id+'.video_close_text').html("Open Section");
				$j('#section_'+id+'').slideUp('slow');
			}
		});
	});
	
	$j('.video_close_button').each(function() {
		var id = $j(this).attr('id');
	
		$j(this).click(function() {
			if($j('#section_'+id+'').is(":hidden")) {
				$j('#section_arrow_'+id+'').attr('src', '/images/sites/internetsalesinstitute.net/announce_close.gif');
				$j('.video_close_text_'+id+'').html("Close Section");
				$j('#section_'+id+'').slideDown('slow');
			} else {
				$j('#section_arrow_'+id+'').attr('src', '/images/sites/internetsalesinstitute.net/announce_open.gif');
				$j('.video_close_text_'+id+'').html("Open Section");
				$j('#section_'+id+'').slideUp('slow');
			}
		});
	});

	$j(".button_background").each(function() {
		var id = $j(this).attr("id");
		
		$j(this).hover(function() {
			$j(this).addClass("button_background_hover_state");
			$j("#"+id+"_arrow").addClass("button_arrow_hover_state");
		},
		function() {
			$j(this).removeClass("button_background_hover_state");
			$j("#"+id+"_arrow").removeClass("button_arrow_hover_state");
		});
		
		$j(this).click(function() {
			location.href='/account/'+id+'/';
		});
	});
	
	$j(".show_dash").click(function() {
		var id = $j(".show_dash").attr("id");
		location.href='/account/'+id+'/';
	});
	
	/**** ANNOUNCEMENTS ****/
	$j(".announce_repeat.green, .announce_repeat.close").click(function() {
		$j("#announce_container").animate({
	       opacity: .0
	    }, 500, "linear", function(){$j("#announce_container").slideUp("normal");} );
	});
	
	/**** CLOSE ADS ****/
	$j(".ad_close").each(function() {
		var id = $j(this).attr("id");
		
		$j(this).click(function() {
			$j("#"+id+"_ad_container").animate({
				opacity: .0
			}, 500, "linear", function() {$j("#"+id+"_ad_container").slideUp("normal");} );
		});
	});
	
	$j(".button_small_inactive").each(function() {
		var id = $j(this).attr("id");
		id = id.split("_");
		var tab = id[0];
		var type = id[1];
		
		$j(this).hover(function() {
			$j(this).addClass("button_small_active");
		},
		function() {
			$j(this).removeClass("button_small_active");
		});
		
		$j(this).click(function() {
			$j("#"+tab+"_videos").removeClass("button_small_active_clicked");
			$j("#"+tab+"_benchmarks").removeClass("button_small_active_clicked");
			$j("#"+tab+"_tools").removeClass("button_small_active_clicked");
			$j(this).addClass("button_small_active_clicked");
			if(type == "videos") {
				$j("#contentbox").html("<table border=0 cellspacing=0 cellpadding=0 width='685px'><tr><td height='70'></td></tr><tr><td class='ajax_loader'>Retrieving Videos<br><br><img src='/images/sites/internetsalesinstitute.net/ajax-loader.gif' border=0></td></tr></table>");
				$j.ajax({
					type:		'POST',
					url:		'/sites/internetsalesinstitute.net/ajax_php/dashboard_videos.php',
					data:		'getlist='+tab+'',
					success:	function(msg) {
						$j("#contentbox").html(msg);
					}
				});
			} else if(type == "benchmarks") {
				$j("#contentbox").html("<table border=0 cellspacing=0 cellpadding=0 width='685px'><tr><td height='70'></td></tr><tr><td class='ajax_loader'>Retrieving Benchmarks<br><br><img src='/images/sites/internetsalesinstitute.net/ajax-loader.gif' border=0></td></tr></table>");
				$j.ajax({
					type:		'POST',
					url:		'/sites/internetsalesinstitute.net/ajax_php/dashboard_benchmarks.php',
					data:		'getlist='+tab+'',
					success:	function(msg) {
						$j("#contentbox").html(msg);
					}
				});
			} else if(type == "tools") {
				$j("#contentbox").html("<table border=0 cellspacing=0 cellpadding=0 width='685px'><tr><td height='70'></td></tr><tr><td class='ajax_loader'>Retrieving Tools<br><br><img src='/images/sites/internetsalesinstitute.net/ajax-loader.gif' border=0></td></tr></table>");
				$j.ajax({
					type:		'POST',
					url:		'/sites/internetsalesinstitute.net/ajax_php/dashboard_tools.php',
					data:		'getlist='+tab+'',
					success:	function(msg) {
						$j("#contentbox").html(msg);
					}
				});
			}
		});
	});
	
	$j(".header_nav").each(function() {
		var id = $j(this).attr("id");
		
		$j(this).hover(function() {
			$j(this).addClass("header_nav_hover");
		},
		function() {
			$j(this).removeClass("header_nav_hover");
		});
		
		$j(this).click(function() {
			if(id == "dashboard") {
				location.href="/account/";
			} else {
				if(id == "lightwave") {
					open_lightwave();
//					location.href = "http://www.lightwavebuilder.com/";
				} else {
					location.href = "/account/"+id+"/";
				}
			}
		});
	});
	
	/*$j(".header_sub").each(function() {
		var id = $j(this).attr("id");
		$j(this).click(function() {
			location.href="/account/"+id+"/";
		});
	});*/
	
	
	/**** SEARCH BOX ****/
	$j("#search_holder").click(function() {
		$j("#search_holder").css("display", "none");
		$j("#search_actual").css("display", "inline").focus();
	});
	$j("#search_actual").keypress(function(e) {
		if(e.which == 13) {
			$j("#contentbox").html("<table border=0 cellspacing=0 cellpadding=0 width='685px'><tr><td height='70'></td></tr><tr><td class='ajax_loader'>Loading Results<br><br><img src='/images/sites/internetsalesinstitute.net/ajax-loader.gif' border=0></td></tr></table>");
			$j.ajax({
				type:		'POST',
				url:		'/sites/internetsalesinstitute.net/ajax_php/search.php',
				data:		'search='+$j("#search_actual").val()+'',
				success:	function(msg) {
					$j("#contentbox").html(msg);
				}
			});
		}
	});
	$j(".header_sub_search_button").click(function() {
		$j("#contentbox").html("<table border=0 cellspacing=0 cellpadding=0 width='685px'><tr><td height='70'></td></tr><tr><td class='ajax_loader'>Loading Results<br><br><img src='/images/sites/internetsalesinstitute.net/ajax-loader.gif' border=0></td></tr></table>");
		$j.ajax({
			type:		'POST',
			url:		'/sites/internetsalesinstitute.net/ajax_php/search.php',
			data:		'search='+$j("#search_actual").val()+'',
			success:	function(msg) {
				$j("#contentbox").html(msg);
			}
		});
	});
	
	$j(".header_nav_sub_button").each(function() {
		var id = $j(this).attr("id");
		
		$j(this).click(function() {
			location.href = '/account/'+id+'/';
		});
	});
	
	// DASHBOARD UPDATE BUTTONS //
	$j("#ebay_button_1").click(function() {
		$j("#ebay_button_1").val("Saving...");
		$j.ajax({
			type:		'POST',
			url:		'/sites/internetsalesinstitute.net/ajax_php/dashboard_ebay.php',
			data:		'button=1&ebay_user_id='+$j("#ebay_user_id").val()+'&ebay_id_verified='+$j("#ebay_id_verified").val()+'&ebay_paypal_email='+$j("#ebay_paypal_email").val()+'&ebay_item_number='+$j("#ebay_item_number").val()+'&ebay_feedback_score='+$j("#ebay_feedback_score").val()+'&ebay_num_active_listings='+$j("#ebay_num_active_listings").val()+'&ebay_num_items_sold='+$j("#ebay_num_items_sold").val()+'&ebay_gross_sales='+$j("#ebay_gross_sales").val()+'&ebay_store_name='+$j("#ebay_store_name").val()+'',
			success:	function(msg) {
				$j("#ebay_button_1").val("Update");
			}
		});
	});
		$j("#ebay_id_verified_image").click(function() {
			var src = $j("#ebay_id_verified_image").attr("src");
			if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif") {
				$j("#ebay_id_verified_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif");
				$j("#ebay_id_verified").val("1");
			} else if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif") {
				$j("#ebay_id_verified_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif");
				$j("#ebay_id_verified").val("0");
			}
		});
	$j("#ebay_button_2").click(function() {
		$j("#ebay_button_2").val("Saving...");
		$j.ajax({
			type:		'POST',
			url:		'/sites/internetsalesinstitute.net/ajax_php/dashboard_ebay.php',
			data:		'button=2&ebay_paypal_verified='+$j("#ebay_paypal_verified").val()+'',
			success:	function(msg) {
				$j("#ebay_button_2").val("Update");
			}
		});
	});
		$j("#ebay_paypal_verified_image").click(function() {
			var src = $j("#ebay_paypal_verified_image").attr("src");
			if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif") {
				$j("#ebay_paypal_verified_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif");
				$j("#ebay_paypal_verified").val("1");
			} else if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif") {
				$j("#ebay_paypal_verified_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif");
				$j("#ebay_paypal_verified").val("0");
			}
		});
	
	
	$j(".drop_info_field").keyup(function (){
		var curText = $j("#dropship_info_msg_cntr").html();
		if(curText != "Click Update to Save Changes"){
			$j("#dropship_info_msg_cntr").css("color", "red");
			$j("#dropship_info_msg_cntr").html("Click Update to Save Changes");
		}
	});
	
	$j("#drop_button_z").click(function() {
		$j("#drop_button_z").parent("td").css("color","red");
		$j("#drop_button_z").val("Saving...");
		var myData = 'button=Z&drop_tax_id='+$j("#drop_tax_id").val()+'&drop_ein='+$j("#drop_ein").val()+
			'&drop_niche='+$j("#drop_niche").val()+'&drop_supplier_domain='+$j("#drop_supplier_domain").val()+
			'&drop_domain='+$j("#drop_domain").val()+'&drop_coach_approved='+$j("#drop_coach_approved").val()+
			'&drop_ezine='+$j("#drop_ezine").val()+'&drop_keywords='+$j("#drop_keywords").val();
		$j.ajax({
			type:		'POST',
			url:		'/sites/internetsalesinstitute.net/ajax_php/dashboard_drop.php',
			data:		myData,
			success:	function(msg) {
				$j("#drop_button_z").parent("td").css("color","black");
				$j("#drop_button_z").val("Update");
				$j("#dropship_info_msg_cntr").css("color", "black");
				$j("#dropship_info_msg_cntr").html("Successfully Saved");
			}
		});
	});
	
	$j("#drop_button_1").click(function() {
		$j("#drop_button_1").val("Saving...");
		$j.ajax({
			type:		'POST',
			url:		'/sites/internetsalesinstitute.net/ajax_php/dashboard_drop.php',
			data:		'button=1&drop_tax_id='+$j("#drop_tax_id").val()+'&drop_ein='+$j("#drop_ein").val()+'&drop_niche='+$j("#drop_niche").val()+'&drop_supplier_domain='+$j("#drop_supplier_domain").val()+'&drop_domain='+$j("#drop_domain").val()+'&drop_coach_approved='+$j("#drop_coach_approved").val()+'&drop_ezine='+$j("#drop_ezine").val()+'&drop_keywords='+$j("#drop_keywords").val()+'',
			success:	function(msg) {
				$j("#drop_button_1").val("Update");
			}
		});
	});
		$j("#drop_coach_approved_image").click(function() {
			var src = $j("#drop_coach_approved_image").attr("src");
			if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif") {
				$j("#drop_coach_approved_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif");
				$j("#drop_coach_approved").val("1");
			} else if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif") {
				$j("#drop_coach_approved_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif");
				$j("#drop_coach_approved").val("0");
			}
		});
	$j("#drop_button_2").click(function() {
		$j("#drop_button_2").val("Saving...");
		$j.ajax({
			type:		'POST',
			url:		'/sites/internetsalesinstitute.net/ajax_php/dashboard_drop.php',
			data:		'button=2&drop_homepage='+$j("#drop_homepage").val()+'&drop_version1='+$j("#drop_version1").val()+'&drop_google='+$j("#drop_google").val()+'&drop_version2='+$j("#drop_version2").val()+'',
			success:	function(msg) {
				$j("#drop_button_2").val("Update");
			}
		});
	});
		$j("#drop_homepage_image").click(function() {
			var src = $j("#drop_homepage_image").attr("src");
			if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif") {
				$j("#drop_homepage_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif");
				$j("#drop_homepage").val("1");
			} else if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif") {
				$j("#drop_homepage_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif");
				$j("#drop_homepage").val("0");
			}
		});
		$j("#drop_version1_image").click(function() {
			var src = $j("#drop_version1_image").attr("src");
			if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif") {
				$j("#drop_version1_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif");
				$j("#drop_version1").val("1");
			} else if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif") {
				$j("#drop_version1_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif");
				$j("#drop_version1").val("0");
			}
		});
		$j("#drop_google_image").click(function() {
			var src = $j("#drop_google_image").attr("src");
			if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif") {
				$j("#drop_google_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif");
				$j("#drop_google").val("1");
			} else if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif") {
				$j("#drop_google_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif");
				$j("#drop_google").val("0");
			}
		});
		$j("#drop_version2_image").click(function() {
			var src = $j("#drop_version2_image").attr("src");
			if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif") {
				$j("#drop_version2_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif");
				$j("#drop_version2").val("1");
			} else if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif") {
				$j("#drop_version2_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif");
				$j("#drop_version2").val("0");
			}
		});
	
	$j("#aff_button_1").click(function() {
		$j("#aff_button_1").val("Saving...");
		$j.ajax({
			type:		'POST',
			url:		'/sites/internetsalesinstitute.net/ajax_php/dashboard_aff.php',
			data:		'button=1&aff_domain='+$j("#aff_domain").val()+'&aff_domain_passed='+$j("#aff_domain_passed").val()+'&aff_homepage_passed='+$j("#aff_homepage_passed").val()+'&aff_version1_passed='+$j("#aff_version1_passed").val()+'&aff_moveon_passed='+$j("#aff_moveon_passed").val()+'',
			success:	function(msg) {
				$j("#aff_button_1").val("Update");
			}
		});
	});
		$j("#aff_domain_passed_image").click(function() {
			var src = $j("#aff_domain_passed_image").attr("src");
			if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif") {
				$j("#aff_domain_passed_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif");
				$j("#aff_domain_passed").val("1");
			} else if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif") {
				$j("#aff_domain_passed_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif");
				$j("#aff_domain_passed").val("0");
			}
		});
		$j("#aff_homepage_passed_image").click(function() {
			var src = $j("#aff_homepage_passed_image").attr("src");
			if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif") {
				$j("#aff_homepage_passed_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif");
				$j("#aff_homepage_passed").val("1");
			} else if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif") {
				$j("#aff_homepage_passed_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif");
				$j("#aff_homepage_passed").val("0");
			}
		});
		$j("#aff_version1_passed_image").click(function() {
			var src = $j("#aff_version1_passed_image").attr("src");
			if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif") {
				$j("#aff_version1_passed_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif");
				$j("#aff_version1_passed").val("1");
			} else if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif") {
				$j("#aff_version1_passed_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif");
				$j("#aff_version1_passed").val("0");
			}
		});
		$j("#aff_moveon_passed_image").click(function() {
			var src = $j("#aff_moveon_passed_image").attr("src");
			if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif") {
				$j("#aff_moveon_passed_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif");
				$j("#aff_moveon_passed").val("1");
			} else if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif") {
				$j("#aff_moveon_passed_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif");
				$j("#aff_moveon_passed").val("0");
			}
		});
	
	$j("#mark_button_1").click(function() {
		$j("#mark_button_1").val("Saving...");
		$j.ajax({
			type:		'POST',
			url:		'/sites/internetsalesinstitute.net/ajax_php/dashboard_mark.php',
			data:		'button=1&mark_site_visits='+$j("#mark_site_visits").val()+'&mark_ebay_verified='+$j("#mark_ebay_verified").val()+'&mark_total_orders='+$j("#mark_total_orders").val()+'&mark_last_7_days='+$j("#mark_last_7_days").val()+'&mark_num_articles='+$j("#mark_num_articles").val()+'&mark_num_posted='+$j("#mark_num_posted").val()+'&mark_num_yahoo='+$j("#mark_num_yahoo").val()+'&mark_blog_address='+$j("#mark_blog_address").val()+'',
			success:	function(msg) {
				$j("#mark_button_1").val("Update");
			}
		});
	});
		$j("#mark_ebay_verified_image").click(function() {
			var src = $j("#mark_ebay_verified_image").attr("src");
			if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif") {
				$j("#mark_ebay_verified_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif");
				$j("#mark_ebay_verified").val("1");
			} else if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif") {
				$j("#mark_ebay_verified_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif");
				$j("#mark_ebay_verified").val("0");
			}
		});
	$j("#mark_button_2").click(function() {
		$j("#mark_button_2").val("Saving...");
		$j.ajax({
			type:		'POST',
			url:		'/sites/internetsalesinstitute.net/ajax_php/dashboard_mark.php',
			data:		'button=2&mark_ppc='+$j("#mark_ppc").val()+'',
			success:	function(msg) {
				$j("#mark_button_2").val("Update");
			}
		});
	});
		$j("#mark_ppc_image").click(function() {
			var src = $j("#mark_ppc_image").attr("src");
			if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif") {
				$j("#mark_ppc_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif");
				$j("#mark_ppc").val("1");
			} else if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif") {
				$j("#mark_ppc_image").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif");
				$j("#mark_ppc").val("0");
			}
		});
	
	$j(".video_player_back").click(function() {
		var tab = $j(".video_player_back").attr("id");
		$j.ajax({
			type:		'POST',
			url:		'/sites/internetsalesinstitute.net/ajax_php/dashboard_videos.php',
			data:		'getlist='+tab+'',
			success:	function(msg) {
				$j("#contentbox").html(msg);
				$j("#"+tab+"_videos").addClass("button_small_active_clicked");
			}
		});
	});
	
	$j(".benchmark_back").click(function() {
		var tab = $j(".benchmark_back").attr("id");
		$j.ajax({
			type:		'POST',
			url:		'/sites/internetsalesinstitute.net/ajax_php/dashboard_benchmarks.php',
			data:		'getlist='+tab+'',
			success:	function(msg) {
				$j("#contentbox").html(msg);
				$j("#"+tab+"_benchmarks").addClass("button_small_active_clicked");
			}
		});
	});
	
	$j(".benchmark_complete").click(function() {
		var id = $j(".benchmark_complete").attr("id");
		$j.ajax({
			type:		'POST',
			url:		'/sites/internetsalesinstitute.net/ajax_php/dashboard_benchmarks.php',
			data:		'mark_complete='+id+'&type=b',
			success:	function(msg) {
				$j(".benchmark_complete").html("Benchmark Completed");
			}
		});
	});
	$j(".thirty_complete").click(function() {
		var id = $j(".thirty_complete").attr("id");
		$j.ajax({
			type:		'POST',
			url:		'/sites/internetsalesinstitute.net/ajax_php/dashboard_benchmarks.php',
			data:		'mark_complete='+id+'&type=t',
			success:	function(msg) {
				$j(".thirty_complete").html("Step Completed");
			}
		});
	});
	
	$j(".video_player_back_extras").click(function() {
		location.href='/account/extras';
	});
	
	$j(".video_player_back_new").click(function() {
		location.href='/account/newvids';
	});
	
	$j(".open_notes").click(function() {
		if($j("#notes").css("display") == "none") {
			$j("#notes").slideDown("slow");
			$j(".open_notes").html("<img src='/images/sites/internetsalesinstitute.net/video_notes_check.gif' style='vertical-align: middle; ' border=0> Save Notes");
		} else {
			var myData = CKEDITOR.instances["note_body"].getData();
			$j.ajax({
				type:		'POST',
				url:		'/sites/internetsalesinstitute.net/ajax_php/videos.php',
				data:		'save_note=1&video='+$j("#video").val()+'&note_body='+urlencode(myData)+'',
				success:	function(msg) {
					$j("#notes").slideUp("slow");
					$j(".open_notes").html("<img src='/images/sites/internetsalesinstitute.net/video_notes_plus.gif' style='vertical-align: middle; ' border=0> Open Notes");
				}
			});
		}
	});
	
	$j(".faq_item").each(function() {
		var id = $j(this).attr("id");
		
		$j(this).click(function() {
			var pos = $j("#question_"+id+"").position();
			var topPos = pos.top+'px';
			$j.scrollTo( {top:topPos,left:'0px'}, 1500 );
		});
	});
	
	$j('.livechat').click(function() {
		liveChat();
		return false;
	});
	
	$j('.support_contact_bottom_team_chat').click(function() {
		liveChat();
		return false;
	});
	$j('.support_contact_bottom_tech_chat').click(function() {
		liveChat();
		return false;
	});
	$j('.support_contact_bottom_email').click(function() {
		email();
		return false;
	});
	
	$j(".quiz_button").each(function() {
		var id = $j(this).attr("id");
		
		$j(this).click(function() {
			$j("#contentbox").html("<table border=0 cellspacing=0 cellpadding=0 width='685px'><tr><td height='70'></td></tr><tr><td class='ajax_loader'>Preparing Quiz<br><br><img src='/images/sites/internetsalesinstitute.net/ajax-loader.gif' border=0></td></tr></table>");
			$j.ajax({
				type:		'POST',
				url:		'/sites/internetsalesinstitute.net/ajax_php/dashboard_quiz.php',
				data:		'show=1&category='+id+'',
				success:	function(msg) {
					$j("#contentbox").html(msg);
				}
			});
		});
	});
	
	$j("body").append("<div id='ToolTipDiv'></div>");
	$j('.tooltip').hover(function(e) {
		$j().mousemove(function(e) {
	        var tipY = e.pageY + 16;
	        var tipX = e.pageX + 16;
	    	$j("#ToolTipDiv").css({'top': tipY, 'left': tipX});
	    });
		$j("#ToolTipDiv").html('<div class="tooltip_summary">Synopsis</div><div class="tooltip_text">'+$j(this).attr('rel')+'</div>').stop(true,true).fadeIn("fast");
	}, function() {
		$j("#ToolTipDiv").stop(true,true).fadeOut("fast");
	});
	
	$j("body").append("<div id='ToolTipDiv2'></div>");
	$j('.tooltip2').hover(function(e) {
		$j().mousemove(function(e) {
	        var tipY = e.pageY + 16;
	        var tipX = e.pageX + 16;
	    	$j("#ToolTipDiv2").css({'top': tipY, 'left': tipX});
	    });
		$j("#ToolTipDiv2").html('<div class="tooltip_summary2">New Video</div>').stop(true,true).fadeIn("fast");
	}, function() {
		$j("#ToolTipDiv2").stop(true,true).fadeOut("fast");
	});

	/*$j(".gs_next_button").click(function() {
		var id = $j(".gs_next_button").attr("id");
		
		if(id == 1) {
			$j(".gs_next_button").attr("id", "2");
			
			$j("#gs_button_first").removeClass("on").addClass("off");
			$j("#gs_button_second").removeClass("off").addClass("on");
			
			$j("#gs_title_image").attr("src", "/images/sites/internetsalesinstitute.net/gs_text_title_2.jpg");
			
			$j("#gs_comp_image").attr("src", "/images/sites/internetsalesinstitute.net/gs_comp_2.jpg");
			
			$j("#gs_item_1").css("display", "none");
			$j("#gs_item_2").css("display", "inline");
		} else if(id == 2) {
			$j(".gs_next_button").attr("id", "3");
			$j(".gs_next_button").attr("src", "/images/sites/internetsalesinstitute.net/gs_button_finish.jpg");
			
			$j("#tos_agreement_span").css("display", "inline");
			
			$j("#gs_button_second").removeClass("on").addClass("off");
			$j("#gs_button_third").removeClass("off").addClass("on");
			
			$j("#gs_title_image").attr("src", "/images/sites/internetsalesinstitute.net/gs_text_title_3.jpg");
			
			$j("#gs_comp_image").attr("src", "/images/sites/internetsalesinstitute.net/gs_comp_3.jpg");
			
			$j("#gs_item_2").css("display", "none");
			$j("#gs_item_3").css("display", "inline");
		} else if(id == 3) {
			var src = $j("#tos_agree_check").attr("src");
			if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif") {
				alert("Please click the box to agree to the terms of service to continue");
			} else if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif") {
				$j.ajax({
					type: 'POST',
					url: '/sites/internetsalesinstitute.net/ajax_php/gs_update.php',
					data: 'name='+$j("#gs_name").val()+'&phone='+$j("#gs_phone").val()+'&cell='+$j("#gs_cell").val()+'&work_phone='+$j("#gs_work_phone").val()+'&email='+$j("#gs_email").val()+'',
					success: function(msg) {
						if($j("#gs_run_ce_after").val() > 0) {
							$j("#tos").fadeOut("slow");
							$j('#video_player').css('top', '34px');
							$j('#video_player').fadeIn("slow");
						} else {
							$j("#tos").fadeOut("slow");
							$j("#tos_shadow").fadeOut("slow");
							$j(document.body).css('overflow', 'auto');
						}
					}
				});
			}
		}
	});
	
	$j("#close_ce_player").click(function() {
		$j("#video_player").fadeOut("slow");
		$j("#tos_shadow").fadeOut("slow");
		$j(document.body).css('overflow', 'auto');
	});
	
	$j("#tos_agree_check").click(function() {
		var src = $j("#tos_agree_check").attr("src");
		if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif") {
			$j("#tos_agree_check").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif");
		} else if(src == "/images/sites/internetsalesinstitute.net/course_dash_check_yes.gif") {
			$j("#tos_agree_check").attr("src", "/images/sites/internetsalesinstitute.net/course_dash_check_no.gif");
		}
	});*/
	
	$j(".add_button_pop").each(function() {
		var id = $j(this).attr("id");
		
		$j(this).click(function() {
			$j(document.body).css('overflow', 'hidden');
			var winW = $j(document).width();
			var winH = $j(document).height();
			var leftPos = (winW / 2) - ($j('#'+id+'_popup').width() / 2);
			
			$j('#shadow').css('width', winW).css('height', winH);
			$j('#'+id+'_popup').css('top', '140px').css('left', leftPos);
			$j('#shadow').fadeIn('slow');
			$j('#'+id+'_popup').fadeIn('slow');
			
			$j('#ui-datepicker-div').css('z-index', '2000');
		});
	});
	
	$j(".add_button_close").each(function() {
		var id = $j(this).attr("id");
		
		$j(this).click(function() {
			$j('#shadow').fadeOut('slow');
			$j('#'+id+'_popup').fadeOut('slow');
			$j(document.body).css('overflow', 'auto');
		});
	});
	
	//$j("#hw_date_due").datepicker({minDate: 0});
	
	$j("#hw_save").click(function() {
		$j.ajax({
			type:		'post',
			url:		'/sites/internetsalesinstitute.net/ajax_php/homework.php',
			data:		'add=1&title='+$j("#hw_title").val()+'&desc='+$j("#hw_desc").val()+'&link='+$j("#hw_link").val()+'&date_due='+$j("#hw_date_due").val()+'',
			success:	function(msg) {
				$j("#hw_box").html(msg);
				$j("#shadow").fadeOut("slow");
				$j("#homework_popup").fadeOut("slow");
			}
		});
	});
	
	$j(".hw_complete").each(function() {
		var id = $j(this).attr("id");
		
		$j(this).click(function() {
			$j.ajax({
				type:		'post',
				url:		'/sites/internetsalesinstitute.net/ajax_php/homework.php',
				data:		'mk='+id+'',
				success:	function(msg) {
					$j("#hw_box").html(msg);
				}
			});
		});
	});
	
	$j("#goal_date").datepicker({minDate: 0});
	
	$j("#goal_save").click(function() {
		$j.ajax({
			type:		'post',
			url:		'/sites/internetsalesinstitute.net/ajax_php/goals.php',
			data:		'add=1&goal_text='+$j("#goal_text").val()+'&goal_date='+$j("#goal_date").val()+'',
			success:	function(msg) {
				$j("#goals_box").html(msg);
				$j("#shadow").fadeOut("slow");
				$j("#goals_popup").fadeOut("slow");
			}
		});
	});
	
	$j(".goal_complete").each(function() {
		var id = $j(this).attr("id");
		
		$j(this).click(function() {
			$j.ajax({
				type:		'post',
				url:		'/sites/internetsalesinstitute.net/ajax_php/goals.php',
				data:		'mk='+id+'',
				success:	function(msg) {
					$j("#goals_box").html(msg);
				}
			});
		});
	});
});

function open_lightwave() {
	window.open('http://www.lightwavebuilder.com', 'lwWin');
}

function liveChat() {
	var chatWin = window.open('/live_chat_client.php', 'chatWin', 'width=600,height=506,toolbar=no,menubar=no,status=no,location=no,scrollbars=no,resizable=no');
	chatWin.moveTo(100,100);
	chatWin.focus();
}

function email() {
	var emailWin = window.open('/sites/internetsalesinstitute.net/email_client.php', 'emailWin', 'width=1024,height=800,toolbar=no,menubar=no,status=no,location=no,scrollbars=no,resizable=no,directories=no,navigation=no');
	emailWin.moveTo(0,0);
	emailWin.focus();
}


function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	if(x.length > 1){
		x2 = '.' + x[1];
	}else{
		x2 = '';
	}
	//x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function deleteNicheIdeaRow(thisElement){
	if(confirm("Are you sure you want to delete this niche idea? ("+$j(thisElement).siblings(".nicheA").html()+")")){
		var removeRowID = ($j(thisElement).parent().attr("id")).replace("niche_row_", "");
		$j("#testMSGcell").html("Removing Row "+removeRowID);
		var deleteRowData = 'removeRowID='+removeRowID;
		$j.ajax({
			type: 'POST',
			url: '/sites/internetsalesinstitute.net/ajax_php/dashboard_niche_ideas.php?removeRow=1',
			data: deleteRowData,
			success: function(msg) {
				//alert(msg);
				if(msg == "removed"){
					$j("#niche_row_"+removeRowID).remove();
					$j("#testMSGcell").html("");
				}else{
					$j("#testMSGcell").html("Delete Failed");	
				}
			}
		});
	}
	return false;
}

function nicheInputBoxKeyUp(thisElement){
	$j("#testMSGcell").html("Updating...");
	var nicheD = "";
	/**NicheB and NicheC are multiplied to get NicheD*/
	if($j(thisElement).parent().hasClass("nicheB") || $j(thisElement).parent().hasClass("nicheC")){
		var demand = 0;
		var customerValue = 0;
		/**If we are changing nicheB, fill the demand variable. Else (nicheC), fill the customerValue variable.*/
		if($j(thisElement).parent().hasClass("nicheB")){
			demand = ($j(thisElement).val()).replace(/[^0-9\.]/g, "");
			if($j(thisElement).parent().siblings(".nicheC").find("input").length > 0){
				customerValue = ($j(thisElement).parent().siblings(".nicheC").find("input").val()).replace(/[^0-9\.]/g, "");
			}else{
				customerValue = ($j(thisElement).parent().siblings(".nicheC").html()).replace(/[^0-9\.]/g, "");
			}
		}else if($j(thisElement).parent().hasClass("nicheC")){
			customerValue = ($j(thisElement).val()).replace(/[^0-9\.]/g, "");
			if($j(thisElement).parent().siblings(".nicheB").find("input").length > 0){
				demand = ($j(thisElement).parent().siblings(".nicheB").find("input").val()).replace(/[^0-9\.]/g, "");
			}else{
				demand = ($j(thisElement).parent().siblings(".nicheB").html()).replace(/[^0-9\.]/g, "");
			}
		}
		/**If nicheB and nicheC have properly filled their respective variables, it's safe to do the math for nicheD.*/
		/**Only numbers and period can be in the variables at this point. Stylistic commas and such will be added onBlur.*/
		if((customerValue != "")&&(demand != "")){
			var nicheValue = addCommas((parseFloat(demand) * parseFloat(customerValue)));
			if($j(thisElement).parent().siblings(".nicheD").find("input").length > 0){
				$j(thisElement).parent().siblings(".nicheD").find("input").val("$"+nicheValue);
			}else{
				$j(thisElement).parent().siblings(".nicheD").html("$"+nicheValue);
			}
			nicheD = $j(thisElement).parent().siblings(".nicheD").html();
		}
	}
	var colClass = ($j(thisElement).parent().attr("class")).replace("textyBoo ", "");
	var curVal = $j(thisElement).val();
	var rowID = ($j(thisElement).closest(".course_dash_table_blue_bars").attr("id")).replace("niche_row_", "");
	var curInputData = 'curVal='+curVal+'&colClass='+colClass+'&rowID='+rowID+'&nicheD='+nicheD;
	$j.ajax({
		type: 'POST',
		url: '/sites/internetsalesinstitute.net/ajax_php/dashboard_niche_ideas.php',
		data: curInputData,
		success: function(msg) {
			//alert(msg);
			$j("#testMSGcell").html("");
		}
	});
}

function nicheInputBoxBlur(thisElement){
	$j("#testMSGcell").html("Updating...");
	var nicheD = $j(thisElement).parent().siblings(".nicheD").html();
	var colClass = ($j(thisElement).parent().attr("class")).replace("textyBoo ", "");
	var curVal = $j(thisElement).val();
	var rowID = ($j(thisElement).closest(".course_dash_table_blue_bars").attr("id")).replace("niche_row_", "");
	var curInputData = 'curVal='+curVal+'&colClass='+colClass+'&rowID='+rowID+'&nicheD='+nicheD;
	$j.ajax({
		type: 'POST',
		url: '/sites/internetsalesinstitute.net/ajax_php/dashboard_niche_ideas.php',
		data: curInputData,
		success: function(msg) {
			$j("#testMSGcell").html("");
		}
	});
	if($j(thisElement).parent().hasClass("nicheA") || $j(thisElement).parent().hasClass("nicheI")){
		$j(thisElement).parent().html($j(thisElement).val());	
	}else if($j(thisElement).parent().hasClass("nicheC")){
		var nicheC = addCommas(($j(thisElement).val()).replace(/[^0-9\.]/g, ""));
		if(nicheC != ""){
			$j(thisElement).parent().html("$"+nicheC);
		}else{
			$j(thisElement).parent().html(nicheC);
		}
	}else if($j(thisElement).parent().hasClass("nicheG")){
		$j(thisElement).parent().html($j(thisElement).val());
	}else{
		$j(thisElement).parent().html(addCommas(($j(thisElement).val()).replace(/[^0-9\.]/g,"")));
	}
}

function nicheCellClick(thisElement){
	if($j(thisElement).hasClass("nicheD")){
		return false;
	}
	if($j(thisElement).hasClass("nicheG")){
		var rowID = ($j(thisElement).closest(".course_dash_table_blue_bars").attr("id")).replace("niche_row_", "");
		if($j(thisElement).attr("rel") != ""){
			var top5Arr = ($j(thisElement).attr("rel")).split("^");
			$j("#nicheTop5creator select").each(function (index, value){
				$j(this).val(top5Arr[index]);
			});
		}
		$j("#nicheTop5creator").attr("rel", rowID);
		var myOffset = $j(thisElement).offset();
		$j("#nicheTop5creator").css("top", (myOffset.top + 40)+"px");
		$j("#nicheTop5creator").slideDown("fast");
		return false;
	}
	if($j(thisElement).find("input").length < 1){
		var cellValue = ($j(thisElement).html()).replace("$", "");
		$j(thisElement).html('<input type="text" id="" value="'+cellValue+'" class="niche_brainstorm_course_dash_inputs" />');
		var newTextBox = $j(thisElement).find("input");
		newTextBox.focus();
		$j(thisElement).find("input").unbind('keyup');
		$j(thisElement).find("input").keyup(function (){
			nicheInputBoxKeyUp(this);
		});
	}
	$j(".textyBoo input").unbind('blur');
	$j(".textyBoo input").blur(function () {
		nicheInputBoxBlur(this);
	});
}
