jQuery(document).ready(function() {
								
jQuery("#international").click(function(){
	if(jQuery(this).attr("checked") == true) {
		jQuery('select#stateorprovince').attr("disabled", true); 
		jQuery('span#stateprovince').css("text-decoration","line-through");
		jQuery('input#country').val("");
		jQuery('input#country').focus(); 
	}else{
		jQuery('select#stateorprovince').attr("disabled", false); 
		jQuery('span#stateprovince').css("text-decoration","none");
		var stateprov = jQuery('select#stateorprovince').val();
		if(stateprov.length==2){
			jQuery('input#country').val("USA"); 
		}else{
			jQuery('input#country').val("Canada");
		}
	}
});	

jQuery("select#stateorprovince").change(function(){
    var stateprov = jQuery(this).val();
	if(stateprov=='select'){
		jQuery('input#country').val("");
	}else if(stateprov.length==2){
		jQuery('input#country').val("USA"); 
	}else{
		jQuery('input#country').val("Canada");
	}
	
});

jQuery("[name^=edit_supp]").click(function(){
	var row = $(this).attr('id');
	var supplier = $(this).attr('title');
	jQuery.get("http://www.pppmag.com/findit/admin/rs.php", { gs: row, supp: supplier },
  function(data){
	  jQuery("td[id="+row+"]").html(data);
	});	
});	

jQuery("#add_rs_supp").click(function(){
	var lastid = jQuery('#rs_suppliers tr:last').attr('id');
	var issue_num = jQuery('#rs_suppliers').attr('name');
	jQuery("#add_rs_supp").hide();
	jQuery("#add_rs_supp_status").text('Loading...');
   jQuery.get("http://www.pppmag.com/findit/admin/rs.php", { ad: lastid, issue_number: issue_num },
  function(data){
	     jQuery('#rs_suppliers tr:last').after(data);
		 jQuery("#add_rs_supp").show();
		 jQuery("#add_rs_supp_status").text('');


	});	
});	

jQuery('#add_rs_supp').mouseover(function() {
  		$(this).addClass('rs_supp_over');
	}).mouseout(function(){
    	$(this).removeClass('rs_supp_over');
  });	
		
jQuery("[id^=delete]").click(function(){
    var a = confirm("Are you sure you want to delete this?");
	if(!a){
		return false;	
	}
});		

jQuery("[id^=delete_cat]").click(function(){
    var a = confirm("Are you sure you want to delete this category?");
	if(!a){
		return false;	
	}
});

jQuery("[id^=delete_sup]").click(function(){
    var a = confirm("Are you sure you want to delete this supplier?");
	if(!a){
		return false;	
	}
});
		
jQuery("[id^=delete_user]").click(function(){
    var a = confirm("Are you sure you want to delete this user?");
	if(!a){
		return false;	
	}
});
								
jQuery("#firstpane p.menu_head").click(function(){
    $(this).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
});


jQuery("a#help").mouseover(
	function(){
		var nh = jQuery(this).attr('name');
		jQuery('#help_img').attr('src','http://www.pppmag.com/findit/images/help-on.gif');
    }).mouseout(function(){
		var nh = jQuery(this).attr('name');
		if(jQuery('#help_'+nh).is(":hidden")){
     		jQuery('#help_img').attr('src','http://www.pppmag.com/findit/images/help-off.gif');
		}
    }).toggle(
	function () {
		var nh = jQuery(this).attr('name');
		jQuery('#help_'+nh).fadeIn("fast");
		jQuery('#help_img').attr('src','http://www.pppmag.com/findit/images/help-on.gif');
	},
    function () {
     	var nh = jQuery(this).attr('name');
		jQuery('#help_'+nh).fadeOut("fast");
    }
);
								
jQuery("input#leads_edit_button").click(function() {
	  jQuery("#leads_edit").hide();
	  jQuery('#leads_users').show();										  
});

jQuery("input#leads_close_button").click(function() {
	  jQuery("#leads_edit").show();
	  jQuery('#leads_users').hide();										  
});
								
jQuery('#product_categorySelect').change(function () {
	var value = jQuery(this).attr('value');
	jQuery.get("http://www.pppmag.com/findit/m/products.php", { a: value },
  function(data){
	  if(data=='Y'){
		 jQuery("#product_categoryresult").css("color","green").html('You are approved to select this category.'); 
	  }else{
		 jQuery("#product_categoryresult").css("color","red").html('You are not approved to select this category. We will review your product when submitted.');  
	  }
	});	
	
});
								
jQuery("input#add_user_email").keyup(function () {
	var email = jQuery(this).attr("value");
	var eCheck = email.match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i);
	if(eCheck){
	jQuery.get("http://www.pppmag.com/findit/m/users.php", { e: email },
  function(data){
	  if(data=='r'){
			jQuery("#add_user_result").css("color","green").html('This user was found in the database, you can add them to your user list.');
			jQuery('input#invite_email').attr("disabled", true); 
			jQuery('input#add_email').attr("disabled", false); 
		}else if(data=='n'){
			jQuery("#add_user_result").css("color","red").html('This user is cannot be added.');
			jQuery('input#invite_email').attr("disabled", true);
			jQuery('input#add_email').attr("disabled", true); 
		}else{
			jQuery("#add_user_result").css("color","red").html('This user was not found in the database, you can invite them to join.');
			jQuery('input#invite_email').attr("disabled", false);
			jQuery('input#add_email').attr("disabled", true); 
	  }
  
	});				
	}else{
	jQuery("#add_user_result").html('');
	jQuery('input#add_email').attr("disabled", true); 
	jQuery('input#invite_email').attr("disabled", true); 
	}
});

								
jQuery('div.accordionButton').click(function() {
		jQuery('div.accordionContent').slideUp('normal');	
		jQuery(this).next().slideDown('normal');
	});
	
						   				   	 


jQuery("a.zoom").fancybox({
	'hideOnContentClick': false,
	'zoomSpeedIn'		:	500,
	'zoomSpeedOut'		:	500,
	'frameHeight'       :   545,
	'enableEscapeButton': true

});
jQuery("a.manage_images").fancybox({
	'hideOnContentClick': false,
	'zoomSpeedIn'		:	500,
	'zoomSpeedOut'		:	500,
	'frameHeight'       :   545,
	'enableEscapeButton': true

});
jQuery("a.leads_view").fancybox({
	'hideOnContentClick': false,
	'zoomSpeedIn'		:	500,
	'zoomSpeedOut'		:	500,
	'frameHeight'       :   545,
	'enableEscapeButton': true

});

jQuery("input#register_include_email").click(function() {
	if(jQuery(this).attr("checked") == true) {
		jQuery('#register_additional_info').show("slide", { direction: "left" }, 500);

    }else{
		jQuery('#register_additional_info').hide("slide", { direction: "left" }, 500);
	}											  
});

jQuery("input#[id^=magazinesubscribed]").click(function() {
											
	var onoff = jQuery(this).attr('value');
	var subscribed = jQuery("#subscribedhide").attr('value');
	if(subscribed == 0) {
		if(jQuery(this).attr("id") == "magazinesubscribed-yes") {
		jQuery('#register_additional_info').show("slide", { direction: "left" }, 500);
		}else{
			jQuery('#register_additional_info').hide("slide", { direction: "left" }, 500);
		}
    }											  
});

jQuery("input#productmodify").click(function() {
	if(jQuery("#pname").attr("value") == "") {
		alert('Please fill in a product name.');
		return false;
	}
});

jQuery("#rg_cats").toggle(
	function () {
		var rgcats = jQuery(this).attr("name");
		var srgcats = rgcats.split(",");
		
		jQuery('input[id^=reqcat]').each( function () {
		var cCheck = jQuery(this).attr('checked');
		var cName = jQuery(this).attr('name');
		var rgcheck = jQuery.inArray(cName, srgcats);
		if(rgcheck!='-1'){
			jQuery('span#' + cName).css({'text-decoration' :  'underline'});
		}
	  	
    });
        jQuery(this).text("Hide previous year categories");
      },
      function () {
        jQuery(this).text("Show previous year categories");
		jQuery('input[id^=reqcat]').each( function () {
		var cName = jQuery(this).attr('name');
			jQuery('span#' + cName).css({'text-decoration' :  'none'});
	  	
    });
      }
    );

jQuery("input[id^=reqcat]").click(function() {
	var data = jQuery(this).attr('id');
	var gh = data.split("-");
	var id = gh[1];
	var color = gh[2];
	if(jQuery(this).attr("checked") == true) {
		jQuery('span#' + id).css({'background-color' :  color , 'font-weight' : 'bolder'});

    }else{
		jQuery('span#' + id).css({'background-color' : 'white', 'font-weight' : 'normal'});
	}
});

jQuery('input#price_request').change(function () {
    if(jQuery(this).attr("checked") == true) {
		jQuery('input#price').attr("disabled", true); 
    }else{
		jQuery('input#price').attr("disabled", false); 
	}
});


jQuery.get("http://www.pppmag.com/findit/keywords.php",function(data){
	var keywords = data.split("|");
	jQuery("#findit_search").autocomplete(keywords);
	});	


jQuery('#forgot_password_link').click(function() {
											   
	jQuery('#forgot_password').html("<form method='post'>Email address: <input type='text' name='forgot'> <input type='submit' value='Request'></form>");
	jQuery('#forgot').html('');
											   
});

jQuery('input#catSelectCheck').click(function() {
	var supplier = jQuery(this).attr('name');
	var productsCats = '';
	jQuery('input:checkbox').each( function () {
		jQuery(this).attr('checked', true);
		var cCheck = jQuery(this).attr('checked');
		var cName = jQuery(this).attr('name');
	  	productsCats += cName + "|";
    });		
	jQuery.get("http://www.pppmag.com/findit/vendorProducts.php", { p: productsCats, s: supplier },
  function(data){
	jQuery("#products").html(data);
	});								
});

jQuery('input#catSelectUnCheck').click(function() {
	var supplier = jQuery(this).attr('name');
	jQuery('input:checked').each( function () {
		jQuery(this).attr('checked', false);
    });		
	jQuery.get("http://www.pppmag.com/findit/vendorProducts.php", { s: supplier },
  function(data){
	jQuery("#products").html(data);
	});
});

jQuery('a#imgselect').click(function() {
 	var vName = jQuery(this).attr('name');
	var vNameS = vName.split("|");
	var supplierid = vNameS[1];
	var img = vNameS[0];
 	jQuery("#displaypImage").attr("src", "http://www.pppmag.com/findit/pImage.php?w=200&s=" + supplierid + "&image=" + img);
	jQuery("a.zoom").attr("href", "http://www.pppmag.com/findit/pImage.php?w=500&s=" + supplierid + "&image=" + img);
	return false;
});


jQuery('input[id^=cBoxcatSelect]').click(function() {
										 
	var productsCats = '';
	var supplier = jQuery(this).attr('value');

	jQuery('input:checked').each( function () {
		var cCheck = jQuery(this).attr('checked');
		var cName = jQuery(this).attr('name');
	  	productsCats += cName + "|";
    });
	jQuery.get("http://www.pppmag.com/findit/vendorProducts.php", { p: productsCats, s: supplier },
  function(data){
	jQuery("#products").html(data);
  });

});

jQuery("a[name=track],a.track,input[name=ViewVendorWebsite]").click(function() {
	var lid = jQuery(this).attr("id");
	var data = lid.split("|");
	var s = data[0];
	var p = data[1];
	jQuery.get("http://www.pppmag.com/findit/click.php", { s: s, p: p });
});

 });

var desc_box;

function add_desc_box() {
	desc_box = new nicEditor({fullPanel : true}).panelInstance('desc_box');
}
  
function remove_desc_box() {
	desc_box.removeInstance('desc_box');
}
