function newsletterForm(){
var changeElement = $("#userSubscribe");
changeElement.dialog('destroy');
$(changeElement).load("newsletterRegistration.aspx", function(response) {
	$(changeElement).dialog({
			bgiframe: true,
			height: 250,
			width:250,
			modal: true,
			title: 'Thank You for Plugging In!'
	});
	var subscribeForm = { type: 'POST',url: 'newsletterRegistration.aspx',success: function(responseText) {
			$(changeElement).dialog('destroy');
			}};
			$("form#userSubscribeForm").validate({
			submitHandler: function(form) {
			jQuery(form).ajaxSubmit(subscribeForm);
			},
			rules: getRules("subscriber","myRules"),
			messages: getRules("subscriber","myMsg")
			
			});
});
}





function printConfirm($c_id){
	$(function(){
				$("#dialog").html("<p>Please verify that your printer successfully printed your coupons. If you select \"yes\" your coupon will be removed from your coupon cart. if you select \"No\" your coupon cart won't be changed and you will have the opportunity to re-print after you rectify the printer error</p>");
				$("#dialog").dialog({
				bgiframe: true,
				height: 300,
				width:350,
				modal: true,
				title: ' Alert! Confirm Printer Success.',
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				},
				buttons: {
					Yes: function() {
						var $this;
						if($c_id != null){
						$this=$("#"+$c_id);
						//alert($($this).html());
						manageCart($this, "printRemove");
						$(this).dialog('destroy');
						} else {
							clearCart();
						}
						
					},
					No: function() {
						//$("form#aspnetForm").resetForm();
						$(this).dialog('destroy');
					}
				} 
			});
		});
}
function clearCart(){
	$("#dialog").load("ajaxHandler.ashx",{ID: "1", actionType: "printRemoveAll", object:"coupon"}, function(){
	window.location.href = "coupons.aspx";
	$("#dialog").dialog('destroy');
																											});
}
function add_to_cart($this, msgElement, $action, $location_id){
				
	//alert("adding to cart");
	var couponID = $this.attr("id");
	msgElement.html("Doing It Now").fadeIn('fast',function(){
		$this.before("<div id='tempDiv' style='width:1px;height:1px'></div>");	
		$("#tempDiv").load("ajaxHandler.ashx",{ID: couponID, actionType: $action, object:"coupon", extra:$location_id},function(responseText, status) {
			$("#tempDiv").remove();	
			//alert("success");
			var checkError = $(responseText).attr("id");
			if (checkError == "error") {
				$.modal(responseText);
			} else {
			//alert("no error");
				msgElement.html("Completed!").fadeIn('fast',function(){
					
						//$($this).fadeOut().siblings(".remove_from_cart").toggle();
					
					$($this).fadeOut("fast",function(){
						
						if($("div.intForm").length>0){
							$("div.intForm:not('div#location_form.intForm')").children("h2").html("["+responseText+" Coupons]");
						};
					}).siblings(".remove_from_cart").fadeIn("fast");
					
					
					
					
					/*$this.hide(function(){
						if($("div.intForm").length>0){
							$("div.intForm:not('div#location_form.intForm')").children("h2").html("["+responseText+" Coupons]");
						}
						//$this.parent().append("<a id='"+couponID+"' href='javascript:void(0)' class='remove_from_cart'>Remove</a>");
						
					
						
					});*/
				});
			}
			msgElement.hide();
		});
	});
}
function remove_from_cart($this, msgElement, $action){
	var couponID = $this.attr("id");
	msgElement.html("Doing It Now").fadeIn('fast',function(){
		$this.before("<div id='tempDiv' style='width:1px;height:1px'></div>");	
		$("#tempDiv").load("ajaxHandler.ashx",{ID: couponID, actionType: $action, object:"coupon"},function(responseText, status) {
			$("#tempDiv").remove();	
			//alert("success");
			var checkError = $(responseText).attr("id");
			if (checkError == "error") {
				$.modal(responseText);
			} else {
			//alert("no error");
				msgElement.html("Completed!").fadeIn('fast',function(){
					$($this).fadeOut("fast",function(){
						if($("div.intForm").length>0){
							$("div.intForm:not('div#location_form.intForm')").children("h2").html("["+responseText+" Coupons]");
							
						}
						//alert("begin remove");
						if($($this).parent("DIV.pl_checkBox").length>0){
							$this.parents("DIV.pl_cpn").remove();
						//alert("removed");
						} 
						
					}).siblings(".add_to_cart").fadeIn("fast");
				});
			}
			msgElement.hide();
		});
	});	
}

function manageCart($this, $action){
	if($($this).parent("DIV.pl_checkBox").length>0){
	var msgElement = $this.parent().siblings("div.cpn_msg");
	//alert($(msgElement).html());
	} else {
	var msgElement = $this.siblings("div.cpn_msg");
	}
var couponID = $this.attr("id");
if ($action == "addToCart"){
	if($($this).children("img").attr("id").length == 0){
	var changeElement = $("#dialog");
	$(changeElement).html("").load("couponLocationSelect.aspx",{c_id: couponID}, function(responseText) {
		$("#dialog").dialog({
			bgiframe: true,
			height: 300,
			width:350,
			modal: true,
			title: ' Alert! Select A Location.',
			buttons: {
				Cancel: function() {
				//$("form#aspnetForm").resetForm();
					$(this).dialog('destroy');
					return false;
				}
			} 
		});
		$("#sendLocSelect").livequery('click', function(){
			var location_id = $('input:radio[name=rblLocations]:checked').val();
			//alert($('input:radio[name=rblLocations]:checked').val());
			$("form#loc_selectForm").validate({
			submitHandler: function(form) {
			jQuery(form).ajaxSubmit(function(){
			//alert(location_id);
			add_to_cart($this, msgElement, $action, location_id);
								$("#dialog").dialog('destroy');
								return false;

			});
			},
			rules: getRules("loc_select","myRules"),
			messages: getRules("loc_select","myMsg")
			});	
		});
	});
	} else {
		$temp_loc = $($this).children("img").attr("id");
		add_to_cart($this, msgElement, $action, $temp_loc);
		
	}
} else if($action=="removeFromCart" || $action=="printRemove"){
	remove_from_cart($this, msgElement, $action);
}
}

$(document).ready(function(){
						   
						   
						   
						   
						   
$("a#logout").livequery('click',function(){
	$(this).after("<div id='tempDiv' style='width:1px;height:1px'></div>");	
	$("#tempDiv").load("AjaxProcessor.ashx",{ID:1, actionType:"logOut", object:"system"}, function(responseText){
		window.location.href = "default.aspx";
	});
});



$("#launchSubscribe").livequery('click', function(){
												 
	newsletterForm();
 });
function zip_obj($this, $rule, $hasFocus){
this._field=$this;
this._rule=$rule;
this._hasFocus=$hasFocus;
}

myZip =new zip_obj(null,null,false);
						   

 $(".truncBox").livequery(function(){
		$(this).truncate( 50, {
        chars: /\s/,
        trail: [ " <a href='javascript:void(0);' class='truncate_show'>Full...</a>", "<a href='#' class='truncate_hide'>...Short</a>" ]
    });
});
						   
	
			//alert($.cookies.get('myPanel'));
			
/*---------------------------------	Navigation	Open & close function -------------------------------*/ 
	


var checkPanel = $("body").attr("class");
if (checkPanel == "load_marketing") {
var changeElement = $("#kit1_parent").children("#kit1_child");
var dimElement = $("#kit1_parent").filter(".afd_wrap").siblings();
afd_reveal(changeElement, dimElement, null);
} else if (checkPanel == "load_billing") {
var $this = $("#aff_dash .afd_mod_hdr .subscription_edit"); // give scope to the function
var msgElement = $this.parents("DIV").children(".afd_mod_hdr").children(".msg"); // give scope to message Element
loadBilling($this,true,msgElement);
}

		
		
		var openCat = $.cookies.get('myCookie'); // won't work in localhost unless you alter the hosts file.
		
		$("#lft_nav dd:not(:first)").hide();
		$("#lft_nav dd").hide();
		$("#"+openCat).next().slideDown();
		$("#lft_nav dt a").click(function(){
										
			 var catCookie = $(this).parents("dt").attr("id"); 
			$.cookies.set('myCookie',catCookie);
			// alert($.cookies.get('myCookie'));
			$("#lft_nav dd:visible").slideUp("slow");
			$(this).parent().next().slideDown("slow");
			return false;
		});
		
	
		
	
/*---------------------------------	End Navigation	Open & close function -------------------------------*/
/*---------------------------------	Change Location Functionality -------------------------------*/  
    
    function changeLoc() {
	//reveals the location form
      $("#location_form div").slideDown("normal");
    }


    $("#location_btn").click(changeLoc); // edit tab listener
   /*$("#edit_loc_btn").click(function () { 
	// trigger any other automatic changes from here also. 
        $("#cur_loc").text("Current Location: 99999");    // place variable for new zipcode into the "99999"
        $("#location_form div").hide("normal");  // hides the tab again
      return false; // to stop the submit if you need to.
    });*/
/*---------------------------------	Change Location Functionality -------------------------------*/  
/*---------------------------------	Coupon List Functionality -------------------------------*/  

	function revealDetails() { // shows the coupon details for individial coupon.

	var status=$(this).parent().next().css("display");
			if(status == "none"){
				$(this).parent().next().slideDown("normal");
			} else{
	 			$(this).parent().next().slideUp("normal");
			
		}
	}
	 
	function revealAllDetails() { // shows coupon details for all coupons for an individual comapny
	var status = $(this).text();
	var changeElement = $(this).parents("DIV").filter(".co_header").next().children(".co_coupons_list").children(".coupon").children(".coupon_details");
		if(status == "Expand All Offers") {
			changeElement.slideDown("normal");
			$(this).text("Hide All Details");
		} else {
			changeElement.slideUp("normal");
			$(this).text("Expand All Offers");
		}
	}
	
	function revealAdDetails() { //shows details for specific advertisers
	var status = $(this).text();
	var changeElement = $(this).parents("DIV").filter(".co_header").next().children(".co_details");
		if(status == "Advertiser Details") {
		changeElement.slideDown("normal");
			$(this).text("Hide Advertiser Details");
			
		} else {
			changeElement.slideUp("normal");
			$(this).text("Advertiser Details");
		}
	}

			 	 
$("#center a.add_to_cart").livequery('click', function() { 		 
var $this= $(this);
manageCart($this, "addToCart");
});
$("#center a.remove_from_cart").livequery('click', function() { 		 
var $this= $(this);
manageCart($this, "removeFromCart");
});









$(".coupon_head .details").click(revealDetails); // show coupon details: Listner
$(".expand").click(revealAllDetails); // show coupon details: Listner
$(".ad_details").click(revealAdDetails); // show coupon details: Listner





	
			
/*var myZipForm = { method: 'POST',url: 'default.aspx',success: function(responseText) {
	var checkError = $(responseText).attr("id");
			if (checkError == "error") {
			//alert("error");
		$("#dialog").html(responseText);
	$("#dialog").dialog({
			bgiframe: true,
			height: 200,
			width:350,
			modal: true,
			title: ' zip code problems',
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},
			buttons: {
				Ok: function() {
					$("form#aspnetForm").resetForm();
					$(this).dialog('destroy');
				}
			} 
		});
			} else { 
			window.location.href = "coupons.aspx";
			}
			}};
			*/
var myBizForm = { method: 'POST',url: 'businessreferral.aspx',success: function(responseText) {
			$("form#aspnetForm").resetForm();
			var msgElement = $("div#form_msg");
			msgElement.html("Thank you! You have referred a business!").fadeIn("normal");
			}};
var myFriendForm = { method: 'POST',url: 'friendreferral.aspx',success: function(responseText) {
	$("form#aspnetForm").resetForm();
			var msgElement = $("div#form_msg");
			msgElement.html("Thank you! You have referred a friend!").fadeIn("normal");
			}};
var mySendForm = { method: 'POST',url: 'contactus.aspx',success: function(responseText) {
	$("form#aspnetForm").resetForm();
			var msgElement = $("div#form_msg");
			msgElement.html("Thank you for contacting us! We will respond to your email promptly!").fadeIn("normal");
			}};
var myRegForm = { method: 'POST',url: 'register.aspx',success: function(responseText) {
	//$("form#aspnetForm").resetForm();
	//alert(responseText);
			var checkError = $(responseText).attr("id");
			if (checkError == "error") {
				$("#dialog").html(responseText);
				$("#dialog").dialog({
				bgiframe: true,
				height: 200,
				width:350,
				modal: true,
				title: ' Alert! Registration Error.',
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				},
				buttons: {
					Ok: function() {
						//$("form#aspnetForm").resetForm();
						$(this).dialog('destroy');
					}
				} 
			});
	} else { 
			window.location.href = "coupons.aspx";
			}
}};
 if($("form#aspnetForm").attr("class")=="registerForm"){
	 		
				$("form#aspnetForm").validate({
				submitHandler: function(form) {
				jQuery(form).ajaxSubmit(myRegForm);
				},
				rules: getRules($("form#aspnetForm").attr("class"),"myRules"),
				messages: getRules($("form#aspnetForm").attr("class"),"myMsg")
				
				});
 
			} else if($("form#aspnetForm").attr("class") =="friendForm"){
				$("#location").hide();
					/*$("input#ctl00_widget_location1_boxZip").unbind('submit');*/
				var f =$("form#aspnetForm").validate({
				submitHandler: function(form) {
				jQuery(form).ajaxSubmit(myFriendForm);
				},
				rules: getRules($("form#aspnetForm").attr("class"),"myRules"),
				messages: getRules($("form#aspnetForm").attr("class"),"myMsg")
				
				});
				
			} else if($("form#aspnetForm").attr("class")=="contactForm"){
					$("#location").hide();
				/*$("input#ctl00_widget_location1_boxZip").unbind('submit');*/
				$("form#aspnetForm").validate({
				submitHandler: function(form) {
				jQuery(form).ajaxSubmit(myContactForm);
				},
				rules: getRules($("form#aspnetForm").attr("class"),"myRules"),
				messages: getRules($("form#aspnetForm").attr("class"),"myMsg")
				
				});
			
			} else if($("form#aspnetForm").attr("class")=="bizForm"){
					$("#location").hide();
				/*$("input#ctl00_widget_location1_boxZip").unbind('submit');*/
				$("form#aspnetForm").validate({
				submitHandler: function(form) {
				jQuery(form).ajaxSubmit(myBizForm);
				},
				rules: getRules($("form#aspnetForm").attr("class"),"myRules"),
				messages: getRules($("form#aspnetForm").attr("class"),"myMsg")
								
				});
			
			} else if($("form#aspnetForm").attr("class")=="clipZip"){	
				$("#location").hide();
			}
	

$("input#ctl00_widget_location1_boxZip").livequery('focus',function(){
			
	
			//$(this).bind("submit");
			myZip._field =$(this);
			myZip._rule = "small";
			myZip._hasFocus =true;
			
 });

$("input#ctl00_ContentPlaceHolder1_boxZip").livequery('focus',function(){
		myZip._field =$(this);
		myZip._rule = "clip";
		myZip._hasFocus =true;
	
 });

$("form#aspnetForm").submit(function(){
							 
			if(myZip._hasFocus == true){
				var $this = myZip._field;
				var $zipCode = $(myZip._field).val();
				var $rule = myZip._rule;
				dualZipSubmit($this,$zipCode,$rule); 							
				
			return false;
			}
			
});
$("#sendReg").livequery('click', function(){
		
		$("form#aspnetForm").validate({
		submitHandler: function(form) {
		jQuery(form).ajaxSubmit(myRegForm);
	},
		rules: getRules($("form#aspnetForm").attr("class"),"myRules"),
		messages: getRules($("form#aspnetForm").attr("class"),"myMsg")
	
	});
});
	
$("#sendContact").livequery('click', function(){
		if(myZip._hasFocus == false){
		$("form#aspnetForm").validate({
		submitHandler: function(form) {
		jQuery(form).ajaxSubmit(myContactForm);
	},
		rules: getRules($("form#aspnetForm").attr("class"),"myRules"),
		messages: getRules($("form#aspnetForm").attr("class"),"myMsg")
	
	});
		}
});	
$("#sendFriend").livequery('click', function(){
		if(myZip._hasFocus == false){
		$("form#aspnetForm").validate({
		submitHandler: function(form) {
		jQuery(form).ajaxSubmit(myFriendForm);
	},
		rules: getRules($("form#aspnetForm").attr("class"),"myRules"),
		messages: getRules($("form#aspnetForm").attr("class"),"myMsg")
	
	});
		}
});
$("#sendBiz").livequery('click', function(){
		if(myZip._hasFocus == false){
		$("form#aspnetForm").validate({
		submitHandler: function(form) {
		jQuery(form).ajaxSubmit(myBizForm);
	},
		rules: getRules($("form#aspnetForm").attr("class"),"myRules"),
		messages: getRules($("form#aspnetForm").attr("class"),"myMsg")
								
	});
}
										  
});
$("#smallZip_btn").livequery('click', function(){
											   
			//myZip._field =$(this);
			//myZip._rule = "small";
			//myZip._hasFocus =true;
			//console.log(myZip._field +"\n"+ myZip._rule +"\n"+$(myZip._field).val());
			
				var $this = myZip._field;
				var $zipCode = $(myZip._field).val();
				var $rule = myZip._rule;
				dualZipSubmit($this,$zipCode,$rule); 		
			
			
			
	 });
$("#btnZip").livequery('click', function(){
	//console.log(myZip._field +"\n"+ myZip._rule +"\n"+$(myZip._field).val());
				var $this = myZip._field;
				var $zipCode = $(myZip._field).val();
				var $rule = myZip._rule;
				dualZipSubmit($this,$zipCode,$rule); 		
			
	 });


/*function dualZipSubmit($zipType, $this){
	$this.before("<div id='tempDiv' style='width:1px;height:1px'></div>");
	$("#tempDiv").remove();	
	//alert($zipType);
	if($zipType =="small"){
		$("#ctl00_ContentPlaceHolder1_boxZip").rules("remove");
	}
	$("form#aspnetForm").validate({
		submitHandler: function(form) {
		jQuery(form).ajaxSubmit(myZipForm);
	},
		rules: getRules($zipType+"Zip","myRules"),
		messages: getRules($zipType+"Zip","myMsg")
	
	});
}*/
var z=null;
function dualZipSubmit($this,$zipCode,$zipType){
	//console.log($this+"\n"+$zipCode+"\n"+$zipType);
	//alert($this+"\n"+$zipCode+"\n"+$zipType);

	z = $("form#aspnetForm").validate({
		rules: getRules($zipType+"Zip","myRules"),
		messages: getRules($zipType+"Zip","myMsg")
	
	});
	if ($("form#aspnetForm").valid() ){

		var $action = "checkZip";
		$this.before("<div id='tempDiv' style='width:1px;height:1px'></div>");	
		//alert("created tempDiv");
$("#tempDiv").load("ajaxHandler.ashx",{ID: $zipCode, actionType: $action, object:"zip"},function(responseText, status) {
	// alert(responseText);
		$("#tempDiv").remove();																								
		var checkError = $(responseText).attr("id");
			if (checkError == "error") {
				$("#dialog").html(responseText);
	$("#dialog").dialog({
			bgiframe: true,
			height: 200,
			width:350,
			modal: true,
			title: ' Alert! Zip Code Error.',
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},
			buttons: {
				Ok: function() {
					
					z.resetForm();
					$(this).dialog('destroy');
					
				}
			} 
		});
			} else { 
			window.location.href = "coupons.aspx";
			}
	});
	} 
}













/*---------------------------------	Coupon Manager Functionality -------------------------------*/  

function afd_reveal(changeElement, dimElement, response) { //shows details for specific advertisers
		/*if(response){
			changeElement.html(response);
		}*/
		if(changeElement.css("display") == "none"){
			
		//alert("hidden");
			changeElement.siblings().not(".afd_mod_hdr").slideUp("slow");
				//alert("sib-slide up");
			changeElement.slideDown("slow");
				//alert("change slide down");
			dimElement.children().next().slideUp("slow");
			//alert("dim children slide up");
			dimElement.slideUp("slow");
			
		} else if (response != "self") {
		changeElement.slideUp("normal");
		dimElement.slideDown("normal");
		}
		if(  $("#addNewCpn").length>0){
			  $("#addNewCpn").slideDown();
		}
}
function afd_returnList(dimElement) { //hide all child panels and reveals parent rows
		dimElement.siblings().children().next().slideUp("normal") //hides current panel
		dimElement.slideDown("normal");//reveals all other sibs.
}

//////////////////////coupon management listners //////////////////////////////
$("#aff_dash .afd_mod_hdr .details").livequery('click', function() { 
var msgElement = $(this).parents("DIV").children(".afd_mod_hdr").children(".msg");
	 msgElement.html("Loading Screen").fadeIn("fast", function(){
		var couponID = $(this).parents("DIV").filter(".afd_wrap").attr("ID");		
    	var changeElement = $(this).parents("DIV").next(".afd_mod_summary");
		var dimElement = $(this).parents("DIV").filter(".afd_wrap").siblings();
		$(changeElement).load("Coupon_Details.aspx",{c_id: couponID}, function(){
			afd_reveal(changeElement, dimElement, null)
			msgElement.fadeOut("slow");
		});
	});													 
});

$("#aff_dash .afd_mod_hdr .coupon_edit").livequery('click', function() { 
	function getID($this){
		var couponID = $this.parents("DIV").filter(".afd_wrap").attr("ID");
		return(couponID);
	}
	dynoClear($(this).parents("DIV").filter(".afd_wrap").siblings().children().not(".afd_mod_hdr"));
	var msgElement = $(this).parents("DIV").children(".afd_mod_hdr").children(".msg");
			
	msgElement.html("Loading Screen").fadeIn("fast", function(){
		var $c_id = getID($(this));
			if(!$c_id) {
			$("#aff_dash .delete_coupon").hide();
		}
		var changeElement = $(this).parents("DIV").nextAll(".afd_frm");
		var dimElement = $(this).parents("DIV").filter(".afd_wrap").siblings();
			//alert($c_id);
	$(changeElement).load("Coupon_Edit.aspx",{c_id: $c_id},function(response) {
			$("input#hiddenSaveType").val("save");
			afd_reveal(changeElement, dimElement, null);
			$("#boxPrintedExp").datepicker();
			$("#boxDisplayExp").datepicker();
			
			var options = { method: 'POST',url: 'Coupon_Edit.aspx',success: function(responseText) {
			
			var checkError = $(responseText).attr("id");
				//console.log(responseText);
			//alert($(responseText).children().length);
			if (checkError == "error") {
				$.modal(responseText);
				return false;
		
			} else if(checkError != "error" && $(responseText).children().length>0){
				//alert("this is a new coupon");
				$("#no_cpn_msg").remove();
				$("#aff_dash .afd_bdy").append(responseText);
				$c_id = checkError;
			} 
				msg = "Coupon Successfully Edited";
				msgElement.html(msg).fadeIn("fast", function(){
				if(checkError != "error" && $(responseText).children().length==0){
					var changeTitle = responseText;
					$("#"+$c_id).children(".afd_mod_hdr").children("h1").html(changeTitle);
				}
				
				var changeElement = $("#"+$c_id).children(".afd_mod_summary");
				var dimElement = $("#"+$c_id).filter(".afd_wrap").siblings();
				$("#"+$c_id).children(".afd_frm").html("");
				$(changeElement).load("Coupon_Details.aspx",{c_id: $c_id},function() {
																				 
					afd_reveal(changeElement, dimElement, null);
					msgElement.fadeOut("slow");
					$("#addNewCpn").show();
				});
			});
						
				
				
			
			}};
			//$("form#editCoupon").ajaxForm(options);
			$("form#editCoupon").validate({
			onfocusout: function(element) { 
                if (element.name != "boxPrintedExp" && element.name != "boxDisplayExp") 
                        this.element(element); 
        	},
							submitHandler: function(form) {
							jQuery(form).ajaxSubmit(options);
						},
							rules: getRules($("form#editCoupon").attr("id"),"myRules"),
							messages: getRules($("form#editCoupon").attr("id"),"myMsg")
				
						});
			msgElement.fadeOut("slow");
			$("#aff_dash .cancel_edit").livequery('click', function() { 
							var dimElement = $(this).parents("DIV").filter(".afd_wrap").siblings();
							afd_returnList(dimElement);
						});
			$("#aff_dash .delete_coupon").livequery('click', function() { 
				var x=window.confirm("Are you sure you want to delete this coupon?");
					if (x) {
						var options={myID:getID($(this)),myAction:"delete",myObj:"coupon",onKill: function($row){
							//
							var dimElement = $("#aff_dash .delete_coupon").parents("DIV").filter(".afd_wrap").siblings();
							afd_returnList(dimElement);
							$("#"+$row).slideUp("slow",function(){$(this).remove();})
						}};
						$(this).objectKiller(options);								 
						
					}	
			});
			$("#aff_dash .display dd #openLocation").livequery('click', function() { 
				var $this =$(this);
				locationForm($this, msgElement);
		});
			// End LocationForm Reveal/hide
			$("#aff_dash .display dd #openLogo").livequery('click', function() { 
				var $this= $(this);
				logoForm($this,msgElement);
			});
			// End LogonForm Reveal/hide
		});	
	});												  
 });


function locationForm($this, msgElement){
	var mylink = $("#aff_dash .display .toggleMe");
				msgElement.html("Loading Location Form").fadeIn("fast", function(){
					mylink.fadeOut("slow");
					
						var changeElement = $("#aff_dash #location_form");
					
					changeElement.slideDown("fast");
					
					$(changeElement).load("account_locations_edit.aspx", function(response) {
																		  
						$("input#hiddenSaveType").val("save");
						var options = { type: 'POST',url: 'account_locations_edit.aspx',success: function(responseText) {
							var checkError = $(responseText).attr("id");
				
							//alert($(responseText).children().length);
							if (checkError == "error") {
								$.modal(responseText);
								return false;
						
							} else {
			
								msgElement.html("Location Successfully Edited").fadeIn("fast", function(){
								changeElement.html("");																	
								changeElement.slideUp();
								if($("#aff_dash .display table#cblLocations").length==0){
									$("dd#checkList").append("<table id='cblLocations'></table>");
								} 
								$("#aff_dash .display table#cblLocations").prepend(responseText);
								
							});
							msgElement.fadeOut("slow");
								mylink.fadeIn("slow");
							}
						}};
						
			//alert($(changeElement).attr("id"));
		
		$("form#editLocation").validate({
			submitHandler: function(form) {
				jQuery(form).ajaxSubmit(options);
			},
			rules: getRules($("form#editLocation").attr("id"),"myRules"),
			messages: getRules($("form#editLocation").attr("id"),"myMsg")
				
		});
				//$("form#editLocation").ajaxForm(options);
						msgElement.fadeOut("slow");
						mylink.fadeIn("slow");
						$("#aff_dash .cancel_location").livequery('click', function() { 
							dimElement = $("#aff_dash #location_form");
							dimElement.children().slideUp("normal", function(){
								dimElement.html("");
								changeElement.slideUp();
							});
						});
						
				});
			});
}




function logoForm($this, msgElement){
	var mylink = $this.parents("dl").children(".toggleMe");
				msgElement.html("Loading Logo Form").fadeIn("fast", function(){
					mylink.fadeOut("slow");
					var changeElement = $("#aff_dash #logo_form");
					$(changeElement).load("account_details_logo.aspx", function(response) {
						changeElement.slideDown("slow");
						$("input#hiddenSaveType").val("save");
						var options = { method: 'POST',url: 'account_details_logo.aspx',target:$("#aff_dash dd#logo_preview"), success: function(response) {
							msgElement.html("Logo Successfully Edited").fadeIn("fast", function(){
								changeElement.html("");																	
								changeElement.slideUp();
							});
							msgElement.fadeOut("slow");
							mylink.fadeIn("slow");
						}};
						
						
						$("form#editLogo").validate({
			
							submitHandler: function(form) {
							jQuery(form).ajaxSubmit(options);
						},
							rules: getRules($("form#editLogo").attr("id"),"myRules"),
							messages: getRules($("form#editLogo").attr("id"),"myMsg")
				
						});
						
						//$("form#editLogo").ajaxForm(options);
						msgElement.fadeOut("slow");
						$("#aff_dash .cancel_logo").livequery('click', function() { 
							dimElement = $("#aff_dash #logo_form");
							dimElement.children().slideUp("normal", function(){
								dimElement.html("");
								mylink.fadeIn("slow");
							});
						});
				});
			});
}
$("#aff_dash .afd_mod_hdr .status").livequery('click', function() { 
var $this= $(this);
editCouponStatus($this);
});
function editCouponStatus($this){
	var msgElement = $this.parents("DIV").children(".afd_mod_hdr").children(".msg");
	var couponID = $this.parents("DIV").filter(".afd_wrap").attr("ID");
		msgElement.html("Changing Coupon Status").fadeIn("fast", function(){
		$this.before("<div id='tempDiv' style='width:1px;height:1px'></div>");															 
	$("#tempDiv").load("ajaxProcessor.ashx",{ID: couponID, actionType: "changeCouponStatus", object:"coupon"},function(responseText, status) {
		$("#tempDiv").remove();																								
		var checkError = $(responseText).attr("id");
			if (checkError == "error") {
				$.modal(responseText);
			} else {
				//alert(responseText);
				msgElement.html("Coupon Status Successfully Changed")
				$($this).html(responseText);
			}
	msgElement.fadeOut("slow");
	});
});
}
//
$("#aff_dash .afd_mod_hdr .report").livequery('click', function() { 
	var msgElement = $(this).parents("DIV").children(".afd_mod_hdr").children(".msg");
	 msgElement.html("Loading Screen").fadeIn("fast", function(){
		var couponID = $(this).parents("DIV").filter(".afd_wrap").attr("ID");			
    	var changeElement = $(this).parents("DIV").nextAll(".afd_rpt");
		var dimElement = $(this).parents("DIV").filter(".afd_wrap").siblings();
		$(changeElement).load("Coupon_Stats.aspx",{ c_id: couponID}, function(){
			afd_reveal(changeElement, dimElement, null)
			msgElement.fadeOut("slow");
		});
	});
});
$("#aff_dash .afd_mod_hdr .edit").click(function () { 
   var changeElement = $(this).parents("DIV").nextAll(".afd_frm");
			var dimElement = $(this).parents("DIV").filter(".afd_wrap").siblings();
			afd_reveal(changeElement, dimElement, null);
    });

/////////////////////// Account Manager Listeners ////////////////////////
$("#aff_dash .afd_mod_hdr .acct_details").click(function () {	
	var msgElement =	$(this).parents("DIV").children(".afd_mod_hdr").children(".msg");
	  msgElement.html("Loading Screen").fadeIn("fast", function(){
		var changeElement = $("#acct_details").next(".afd_mod_summary");
		var dimElement = $("#acct_details").filter(".afd_wrap").siblings();
		$(changeElement).load("account_details_details.aspx", function(){
		   afd_reveal(changeElement, dimElement, null);
		   msgElement.fadeOut("slow");
		});
		
	});
});

$("#aff_dash .afd_mod_hdr .location_add").click(function () {
var msgElement = $(this).parents("DIV").children(".afd_mod_hdr").children(".msg");
	 msgElement.html("Loading Screen").fadeIn("fast", function(){	
		var changeElement = $(this).parents("DIV").nextAll(".afd_frm");
		var dimElement = $(this).parents("DIV").filter(".afd_wrap").siblings();
			$(changeElement).load("account_locations_edit.aspx", function(response) {
																							
						 $(this).children("form").children(":not('.optionPanel')").wrapAll("<dl class='display'></dl>");
						  $(this).children("form").children(".optionPanel").wrapAll("<dl class='display right'></dl>");
					
							afd_reveal(changeElement, dimElement, null)
							msgElement.fadeOut("slow");											 
						$("input#hiddenSaveType").val("save");
						var options = { method: 'POST',url: 'account_locations_edit.aspx',success: function(response) {
							//alert(response);
							msgElement.html("Location Successfully Edited").fadeIn("fast", function(){
							var checkError = $(response).attr("id");
							if (checkError == "error") {
								$.modal(response);
							} else {
						msg = "Location Successfully Edited";
						msgElement.html(msg).fadeIn("fast", function(){
						var changeElement = $(this).parents("DIV").next(".afd_mod_summary");
						var dimElement = $(this).parents("DIV").filter(".afd_wrap").siblings();
						$(changeElement).load("account_locations_details.aspx",function() {
							afd_reveal(changeElement, dimElement, null);
							msgElement.fadeOut("slow");
						});
					});
				
							}
							});
							msgElement.fadeOut("slow");
							
						}};
						$("form#editLocation").validate({
			
							submitHandler: function(form) {
							jQuery(form).ajaxSubmit(options);
						},
							rules: getRules($("form#editLocation").attr("id"),"myRules"),
							messages: getRules($("form#editLocation").attr("id"),"myMsg")
				
						});
					
						msgElement.fadeOut("slow");
					$("#aff_dash .cancel_location").click(function () { 
							 var dimElement = $(this).parents("DIV").filter(".afd_wrap").siblings();
							afd_returnList(dimElement);
					});
						
				});
	});
});


$("#aff_dash .afd_mod_hdr .location_details").click(function () {
	var msgElement = $(this).parents("DIV").children(".afd_mod_hdr").children(".msg");
	 msgElement.html("Loading Screen").fadeIn("fast", function(){
		var changeElement = $(this).parents("DIV").next(".afd_mod_summary");
		var dimElement = $(this).parents("DIV").filter(".afd_wrap").siblings();
		$(changeElement).load("account_locations_details.aspx", function(){
			afd_reveal(changeElement, dimElement, null)
			msgElement.fadeOut("slow");
			//Begin Location Form Procedure
			
			
		function getID($this){	
			var locationID = $this.parents("DIV").filter(".loc_box").attr("ID");
			return(locationID);
		}
			
			
		$("#aff_dash .display dd .openLocation").livequery('click',function(){
														 
				var msgElement = $(this).nextAll(".msg");
				var mylink = $(this).parents("dd").children("a");
				mylink.fadeOut("fast",function(){
				msgElement.html("Loading Screen").fadeIn("fast", function(){
					
					var $l_id = getID($(this));
					//var $l_id = $(this).parents("DIV").filter(".loc_box").attr("ID");
				
					var changeElement = $("#"+$l_id).children(".display.right.form");
					//alert("test");		
					$(changeElement).load("account_locations_edit.aspx",{l_id: $l_id}, function(response) {
							msgElement.fadeOut("slow");
							$("input#hiddenSaveType").val("save");
					
						var options = { method: 'POST',url: 'account_locations_edit.aspx',success: function(response) {
							//alert(response);
							mylink.fadeOut("slow");
							msgElement.html("Location Successfully Edited").fadeIn("fast", function(){
							var checkError = $(response).attr("id");
							if (checkError == "error") {
								$.modal(response);
							} else {
							changeElement.html("");
							$("#"+$l_id).children(".display.detail").html("");
							$("#"+$l_id).children(".display.detail").html(response);
							}
							});
							msgElement.fadeOut("slow");
							mylink.fadeIn("slow");
						}};
						$("form#editLocation").validate({
			
							submitHandler: function(form) {
							jQuery(form).ajaxSubmit(options);
						},
							rules: getRules($("form#editLocation").attr("id"),"myRules"),
							messages: getRules($("form#editLocation").attr("id"),"myMsg")
				
						});
						//$("form#editLocation").ajaxForm(options);
					
						
						$("#aff_dash .cancel_location").livequery('click',function(){
							 dimElement = $("#"+$l_id).children(".display.right.form");
							dimElement.children().slideUp("normal", function(){
							dimElement.html("");
							mylink.fadeIn("slow");
						});
					});
				});
			}); });
		});
														
			//End Location Form Procedure
			
				$("#aff_dash .display dd .delLocation").livequery('click',function(){
					var x=window.confirm("Deleting this recored will delete all references to this location. Continue?");
					if (x) {
						var options={myID:getID($(this)),myAction:"delete",myObj:"location",onKill: function($test){
							$("#"+$test).fadeOut("slow").slideUp("slow",function(){$(this).remove();})
						}};
						$(this).objectKiller(options);								 
						
					}
			});
		});
	});
});

$("#aff_dash .afd_mod_hdr .billing_edit").livequery('click',function(){
	var msgElement =$(this).parents("DIV").children(".afd_mod_hdr").children(".msg");
	msgElement.html("Loading Screen").fadeIn("fast", function(){
		var changeElement = $(this).parents("DIV").next(".afd_mod_summary");
		var dimElement = $(this).parents("DIV").filter(".afd_wrap").siblings();
		$(changeElement).load("account_billing_edit.aspx", function(){
			afd_reveal(changeElement, dimElement, null);
			msgElement.fadeOut("slow");
			$(".edit_card").livequery('click',function(){
				$this = $(this);  
				loadBillingForm($this, msgElement, "billingEdit");
				
			});
		});	
	});
});
$("#aff_dash .afd_mod_hdr .billing_history").livequery('click',function(){
	var msgElement = $(this).parents("DIV").children(".afd_mod_hdr").children(".msg");
	 msgElement.html("Loading Screen").fadeIn("fast", function(){
		var changeElement = $(this).parents("DIV").next(".afd_mod_summary");
		var dimElement = $(this).parents("DIV").filter(".afd_wrap").siblings();
	$(changeElement).load("account_billing_history.aspx",  function(){
			afd_reveal(changeElement, dimElement, null);
			msgElement.fadeOut("slow");

		});
	});
});




//++++++++++++++++++++++ billing subscription functions++++++++++++++++++++++ //
function loadBilling($this, $auto, msgElement) {
	var msgElement = $this.parents("DIV").children(".afd_mod_hdr").children(".msg");
	 msgElement.html("Loading Screen").fadeIn("fast", function(){
		var changeElement = $this.parents("DIV").nextAll(".afd_frm");
		var dimElement = $this.parents("DIV").filter(".afd_wrap").siblings();
		$(changeElement).load("account_billing_subscription.aspx",function(response) {
			if($auto) {
				loadBillingForm($(".edit_sub"), msgElement, "billingSubscription");
			}
			afd_reveal(changeElement, dimElement, null);
			msgElement.fadeOut("slow");
			$(".edit_sub").livequery('click',function(){
				$this = $(this);  
				loadBillingForm($this, msgElement, "billingSubscription");
			});
		});
	});												  
 }
 
function loadBillingForm ($this, msgElement, $Type) {
	var $billingType = $Type;
	var mylink = $this;
	msgElement.html("Loading Screen").fadeIn("fast", function(){
		var changeElement = $("#sub_form");
		$(changeElement).load("account_billing_edit_form.aspx",{actionType: $billingType}, function(response) {
			$("input#hiddenSaveType").val("save");
			var options = { method: 'POST',url: 'account_billing_edit_form.aspx',success: function(response) {
				var checkError = $(response).attr("id");
					if (checkError != "error") {
						mylink.fadeOut("slow");
						msgElement.html("Subscription Successfully Edited").fadeIn("fast", function(){
						changeElement.html("");
						$("#sub_panel").html("");
						$("#sub_details").children().not("dd:last").remove();
						$("#sub_details dd").before(response);
							
						});
					} else {
						$.modal(response);
					}
				msgElement.fadeOut("slow");
				mylink.fadeIn("slow");
			}};
			$("form#edit_sub").validate({
			
							submitHandler: function(form) {
							jQuery(form).ajaxSubmit(options);
						},
							rules: getRules($("form#edit_sub").attr("id"),"myRules"),
							messages: getRules($("form#edit_sub").attr("id"),"myMsg")
				
						});
			//$("form#edit_sub").ajaxForm(options);
			msgElement.fadeOut("slow");
			mylink.fadeIn("slow");
			$("#aff_dash .cancel_edit").livequery('click',function(){
				dimElement = $("#sub_form");
				dimElement.children().slideUp("normal", function(){
					dimElement.html("");
				});
			});
		});
	});
}
$("#aff_dash .afd_mod_hdr .subscription_edit").click(function() {
	$this = $(this);  
	loadBilling($this,null,null);
});
//++++++++++++++++++++++ billing subscription functions++++++++++++++++++++++ //





$("#aff_dash .afd_mod_hdr .acct_edit").click(function () {
	//$(this).parents("DIV").children(".afd_mod_hdr").children(".msg").jGrowl("Loading Edit Panel1", {theme: 'lcc_msg',life:500,glue:'after',speed: 500,easing: 'swing',closer:false });
	//$(this).parents("DIV").children(".msg").jGrowl("Loading Edit Panel1", {theme: 'lcc_msg',life:500,glue:'after',speed: 500,easing: 'swing',closer:false });
	var msgElement = $(this).parents("DIV").children(".afd_mod_hdr").children(".msg");
	 msgElement.html("Loading Screen").fadeIn("fast", function(){
		var changeElement = $(this).parents("DIV").nextAll(".afd_frm");
		var dimElement = $(this).parents("DIV").filter(".afd_wrap").siblings();
	$(changeElement).load("account_details_edit.aspx",function(response) {
			$("input#hiddenSaveType").val("save");
			afd_reveal(changeElement, dimElement, null);
			var options = { method: 'POST',url: 'account_details_edit.aspx',success: function(response) {
				var checkError = $(response).attr("id");
							if (checkError == "error") {
								$.modal(response);
							} else {
								var changeElement = $("#acct_details").next(".afd_mod_summary");
								changeElement.html("");
								var dimElement = $("#acct_details").filter(".afd_wrap").siblings();
								$(changeElement).load("account_details_details.aspx", afd_reveal(changeElement, dimElement, null));
							}
			}};
			$("form#editAccount").validate({
			
							submitHandler: function(form) {
							jQuery(form).ajaxSubmit(options);
						},
							rules: getRules($("form#editAccount").attr("id"),"myRules"),
							messages: getRules($("form#editAccount").attr("id"),"myMsg")
				
						});
			//$("form#editAccount").ajaxForm(options);
			msgElement.fadeOut("slow");
			$("#aff_dash .cancel_edit").livequery('click',function(){
							var dimElement = $(this).parents("DIV").filter(".afd_wrap").siblings();
							afd_returnList(dimElement);
						});
			$("#aff_dash .display dd #openLogo").livequery('click',function(){
				var $this= $(this);
				logoForm($this,msgElement);
			});
		});
	});												  
 });

$("#aff_dash .afd_mod_hdr .pass_edit").livequery('click',function(){
	var msgElement = $(this).parents("DIV").children(".afd_mod_hdr").children(".msg");
	var changeElement = $(this).parents("DIV").nextAll(".afd_frm");
	 msgElement.html("Loading Screen").fadeIn("fast", function(){
		
		var dimElement = $(this).parents("DIV").filter(".afd_wrap").siblings();
	$(changeElement).load("account_security_edit.aspx",function(response) {
			$("input#hiddenSaveType").val("save");
			afd_reveal(changeElement, dimElement, null);
			var options = { method: 'POST',url: 'account_security_edit.aspx',success: function(response) {
				var checkError = $(response).attr("id");
							if (checkError == "error") {
								$.modal(response);
							} else {
							 msgElement.html("Loading Screen").fadeIn("fast", function(){
								var dimElement = changeElement.parents("DIV").filter(".afd_wrap").siblings();;
								afd_returnList(dimElement);
							});
							}
							
							msgElement.fadeOut("slow");
							
				
			}};
			
	
			
				$("form#editPass").validate({
			
							submitHandler: function(form) {
							jQuery(form).ajaxSubmit(options);
						},
							rules: getRules($("form#editPass").attr("id"),"myRules"),
							messages: getRules($("form#editPass").attr("id"),"myMsg")
				
						});
		
			msgElement.fadeOut("slow");
			$("#aff_dash .cancel_edit").livequery('click',function(){
							var dimElement = $(this).parents("DIV").filter(".afd_wrap").siblings();
							afd_returnList(dimElement);
						});
		});	
	});												  
 });

////////////////////////////////////////////////////////////////////////////
//////////////////////media kit listners //////////////////////////////
$("#aff_dash .loc_box .edit").livequery('click',function(){
    var changeElement = $(this).parents("DIV").nextAll(".afd_frm");
		var dimElement = $(this).parents("DIV").filter(".afd_wrap").siblings();
	afd_reveal(changeElement, dimElement);
    });	
$("#aff_dash .login_reveal").livequery('click',function(){
   var changeElement = $("#login_parent").children("#login_child");
   $("#login_parent").next().children(".afd_wrap").slideDown("fast", function(){$(this).children(":last").slideUp("fast",function(){
				changeElement.slideDown();																												  
	});});
    });
$("#aff_dash .nextElement").livequery('click',function(){
	 var changeElement = $(this).parents("DIV").filter(".afd_wrap").next().children(":last");
	  var dimElement = $(this).parents("DIV").filter(".afd_wrap").next().siblings();
	 // alert(changeElement.children(":first").next().css("display"));
	 
	 /*if (changeElement.parent().css("display") == "none"){
	 changeElement.parent().slideDown();
	 } 
	 changeElement.slideDown();
	 */
	  //changeElement.show().children(".kit").show();
	// changeElement.show().children(":last").css("display","block");
	  changeElement.parent().slideDown("slow",afd_reveal(changeElement, dimElement, null));
		});

$("#aff_dash .kit1_reveal").livequery('click',function(){	   
	 var changeElement = $("#kit1_parent").children("#kit1_child");
     var dimElement = $("#kit1_parent").filter(".afd_wrap").siblings();
	 $("#login_parent").children("#login_child").slideUp("slow",afd_reveal(changeElement, dimElement, null));
	
    });
$("#aff_dash .kit2_reveal").livequery('click',function(){
	var changeElement = $("#kit2_parent").children("#kit2_child");
	var dimElement = $("#kit2_parent").filter(".afd_wrap").siblings();
	 $("#login_parent").children("#login_child").slideUp("slow",afd_reveal(changeElement, dimElement, null));
	
    });	
$("#aff_dash .kit3_reveal").livequery('click',function(){
   var changeElement = $("#kit3_parent").children("#kit3_child");
	var dimElement = $("#kit3_parent").filter(".afd_wrap").siblings();
	 $("#login_parent").children("#login_child").slideUp("slow",afd_reveal(changeElement, dimElement, null));
	
    });	
$("#aff_dash .kit4_reveal").livequery('click',function(){
   var changeElement = $(this).parents("DIV").nextAll(".kit.4");
		var dimElement = $(this).parents("DIV").filter(".afd_wrap").siblings();
		 $("#login_parent").children("#login_child").slideUp("slow",afd_reveal(changeElement, dimElement, null));
	
    });	
//////////////////////Close All listener //////////////////////////////
$("#aff_dash .returnList").livequery('click', function() { 
  var $this = $(this).parents("DIV").filter(".afd_wrap").siblings();
  showListView($this);
    });
function showListView($this){
	 var dimElement = $this;
	// console.log(dimElement.html());
	afd_returnList(dimElement);
}
		 
/*--------------------------------- UI Functionality ----------------------------------*/

/************************************utilities*****************************************/
	
 /*function objectKiller($this,$id,$obj){
	 $this.before("<div id='tempDiv' style='width:1px;height:1px'></div>");															 
	$("#tempDiv").load("ajaxProcessor.ashx",{ID: $id, actionType: "delete", object:$obj},function(responseText, status) {
		$("#tempDiv").remove();	
		return(responseText);
	 });
	 
 }*/

/*$("#lft_nav .nav dl dd ul li a").click(function(){
	$("#dialog").html("<P>Please first enter your zipcode before browsing categories.</p>");
	$("#dialog").dialog({
			bgiframe: true,
			height: 200,
			width:350,
			modal: true,
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},
			buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
		});
	
	
	});*/

$("#coupon_list .more").livequery("click", function(){
		var $parent = $(this);
		$(this).parent().next().slideDown("fast", function(){
														 
							$parent.fadeOut();							 
														 
														 });							
});

		$("#coupon_list .less").livequery("click", function(){
													
		$(this).parents("dl").slideUp("fast", function(){
														 
							$("#coupon_list .more").fadeIn();
							});			
														   });										
/*--------------------------------- AntiCache ----------------------------------*/

	function dynoClear(scope){
		var $scope = scope;
		$scope.html("");
		return;
	}
/*--------------------------------- end AntiCache ----------------------------------*/

/*---------------------------------	FAQ Functionality -------------------------------*/  
$("#faq dl.expander dd").livequery(function(){
		$(this).truncate( 120, {
        chars: /\s/,
        trail: [ " ( <a href='#' class='truncate_show'>More</a> . . . )", " ( . . . <a href='#' class='truncate_hide'>Less</a> )" ]
	
				 });
	});
 
/*-------------------------- tool tip functionality ------------------------------*/
var config = {    
     sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
     interval: 200, // number = milliseconds for onMouseOver polling interval    
     over: showTip, // function = onMouseOver callback (REQUIRED)    
     timeout:0, // number = milliseconds delay before onMouseOut    
     out: hideTip // function = onMouseOut callback (REQUIRED)    
};
function showTip(){  
if($(this).children("a").attr("class") == "status"){
$(this).find("span").animate({opacity: "show", top: "-60"}, "normal");  	
	return false;
}
	var iconName = $(this).find("img").attr("src");  
	//alert(iconName);
	var origen = iconName.split(".")[0];  
	$(this).find("img").attr({src: "" + origen + "_on.png"});  
	$(this).find("span").animate({opacity: "show", top: "-60"}, "normal"); 

}  
function hideTip(){ 
if($(this).children("a").attr("class") == "status"){
	
	$(this).find("span").animate({opacity: "hide", top: "-50"}, "fast"); 
	return false;
}
	var iconName = $(this).find("img").attr("src"); 
	var origen = iconName.split("_on.")[0];  
	
	$(this).find("img").attr({src: "" + origen + ".png"});
	
	$(this).find("span").animate({opacity: "hide", top: "-50"}, "fast"); 

}

$(".toolbar li").hoverIntent(config);
/*---------------------------- end tooltip --------------------------------------*/
/*++++++++++++++++++++++++ char counter ++++++++++++++++++++++++++++*/
function limitChars(textid, limit, infodiv)
{
var text = $('#'+textid).val(); 
var textlength = text.length;
if(textlength > limit)
{
 $('#' + infodiv).html('You cannot write more then '+limit+' characters!');
 $('#'+textid).val(text.substr(0,limit));
 return false;
 }
else
 {
 $('#' + infodiv).html('You have <h2 style=\"display:inline;\">'+ (limit - textlength) +'</h2> characters left.');
 return true;
 }
 }
 
 $('#instr textarea').livequery('keyup', function() { 
		limitChars("boxInstructions", 255, 'infodiv');
	});
/*++++++++++++++++++++++++ end char counter ++++++++++++++++++++++++++++*/		
/*---------------------------- checkAll --------------------------------------*/

 $('#chkAll').livequery('click', function() { 
 var pID = "cblLocations";
 var id = $(this).attr("id");
 checkToggle(pID, id);
});
 
 function checkToggle(pID, id) {
		 $( "#" + pID + " :checkbox").attr('checked', $('#' + id).is(':checked'));
 }
 
 /*---------------------------- end checkAll --------------------------------------*/
 
 $('a.helpTip').livequery('click', function() { 
											
		var myTip = $(this).attr("id");
       $.modal( $(this).load("tips.aspx",{tip_id: myTip}));
	});
 
	
/*-------------------------------- masked input rules --------------------------*/
$(".date").livequery(function(){ 
	$(this).mask("99/99/9999");
});
$(".phone").livequery(function(){ 
	$(this).mask("(999) 999-9999", {placeholder:" "});
});
$(".bizPhone").livequery(function(){ 
															  
	$(this).mask("(999) 999-9999", {placeholder:" "});
});
$(".tin").livequery(function(){ 
	$(this).mask("99-9999999");
});
$(".ssn").livequery(function(){ 
	$(this).mask("999-99-9999");
});
$(".myZip").livequery(function(){ 
	$(this).mask("99999", {placeholder:""});
});
// $(".avs").mask("9999", {placeholder:""});
$(".ccnumber").livequery(function(){ 
	$(this).mask("9999999999999999", {placeholder:""});
});
   
 
/*-------------------------------- masked input rules --------------------------*/
/*------------------------------------- calendar hooks -------------------------*/

 
 
 

});


