//a place for kpc javascript 



//Toggle User Picture Permissions

function phjSetPicPerm(x){
	var y = $('#'+x.id+' img').attr('alt');
	var cleanID= x.id.replace('pperm','');
	var z = "0";
	$('#'+x.id).html("<img src='/img/phjwait2.gif' border='0px' height='16' style='vertical-align:text-top;' />");
	if(y=='Public'){
		z="2";
		}
	
	//update db
	$.ajax({
		   type: "POST",
		   url: "/works/process/pic_updateInfo.asp",
		   data: "which_a=prm&i="+cleanID+"&perm="+z,
		   success: function(msg){
		   		//update page
				if(z=="2"){
					$('#'+x.id).html("<img src='/img/lock_icon.png' border='0px' class='phjPicPermBut' alt='Private' />");
					}
					else{
						$('#'+x.id).html("<img src='/img/open_lock_icon.png' border='0px' class='phjPicPermBut' alt='Public' />");
						}
				}
		 });
	}



//_____________Set Textarea Character Countdown and Maximums
	//mlmIniCharCountdown(x,n) is all that is required
	//textarea should have an established css width
	//x is textareaID
	//n is max characters
	

	function mlmIniCharCountdown(x,n){
				var y = $('#'+x).css('width');
				$('#'+x).after('<span id="'+x+'TxtCntSpan" style="color:#666666;display:none;width:'+y+';margin-bottom:0px;padding-bottom:0px;">Characters remaining: <span id="'+x+'TxtCnt" style="font-weight:600;"></span></span>');
				mlmCharCountdown(x, n);
				onblur="mlmCharCountdownHideUp(this.id);">
				$('#'+x).bind("blur", function(){
						  mlmCharCountdownHideUp(x);
						});
				$('#'+x).bind("focus", function(){
						  mlmCharCountdownShowDown(x);
						});
				$('#'+x).bind("keyup", function(){
						  mlmCharCountdown(x,n);
						});
				
				}
			
			function mlmCharCountdown(x, n){
				
				var y = $('#'+x).val();
				if(y.length>n){
					//alert('You have reached the maximum amount of text.');
					$('#'+x).val(mlmLeft(y, n));
					}
				var z = n-y.length;
					if(z == 0){z='0';}
				$('#'+x+"TxtCnt").html(z);
				}
						
			function mlmCharCountdownHideUp(x){
				//accepts textarea id
				$('#'+x+"TxtCntSpan").slideUp();
				}
			
			function mlmCharCountdownShowDown(x){
				//accepts textarea id
				$('#'+x+"TxtCntSpan").slideDown();
				}
			
			function mlmLeft(str, n){
				if (n <= 0)
					return "";
				else if (n > String(str).length)
					return str;
				else
					return String(str).substring(0,n);
				}
			
//_________________________________________


$(function(){
		mlmActivateButtons();
	});


function mlmActivateButtons(){
	
		//all hover and click logic for buttons
		$(".fg-button:not(.ui-state-disabled)")
		.hover(
			function(){ 
				$(this).addClass("ui-state-hover"); 
			},
			function(){ 
				$(this).removeClass("ui-state-hover"); 
			}
		)
		.mousedown(function(){
				$(this).parents('.fg-buttonset-single:first').find(".fg-button.ui-state-active").removeClass("ui-state-active");
				if( $(this).is('.ui-state-active.fg-button-toggleable, .fg-buttonset-multi .ui-state-active') ){ 
					$(this).removeClass("ui-state-active"); }
				else { $(this).addClass("ui-state-active"); }	
		})
		.mouseup(function(){
			if(! $(this).is('.fg-button-toggleable, .fg-buttonset-single .fg-button,  .fg-buttonset-multi .fg-button') ){
				$(this).removeClass("ui-state-active");
			}
		});
	}
	
	
	




function loadBuddySuggest(x){
		$("#"+x).html("<img src='/img/phjloading.gif' />");
		$.post("/buddybox_wkr.asp", function(data) {
				 $("#"+x).html(data);
				});
		
	}
