/* ALL SCRIPTS MUST RETURN FALSE TO ACCOUNT FOR USERS WHO DO NOT HAVE JAVASCRIPT INSTALLED */

function jqCheckAll2( id, pID ){
   $( "#" + pID + " :checkbox").attr('checked', $('#' + id).is(':checked'));
}
function check_extension(fld)  
 {  
    var filename = document.getElementById(fld).value;
    var fileArray = filename.split('.');
    var sizeOfArray = fileArray.length;
    var fileExtension = fileArray[sizeOfArray-1];
    if((fileExtension == "jpg") || (fileExtension == "jpeg") || (fileExtension == "gif") || (fileExtension == "png")){ 
    	return true;
    }else{
    	alert("You tried to upload a " +fileExtension + " file. Please only choose an Excel file!");
    	return false;
    }
    
}
 
 $.fn.clearForm = function() {
        return this.each(function() {
          var type = this.type, tag = this.tagName.toLowerCase();
          if (tag == 'form')
            return $(':input',this).clearForm();
          if (type == 'text' || type == 'password' || tag == 'textarea')
            this.value = '';
          else if (type == 'checkbox' || type == 'radio')
            this.checked = false;
          else if (tag == 'select')
            this.selectedIndex = -1;
        });
      };

function clearbg(){
	$("#txt_search").attr("class","txt_search1");
}

function showbg(){
	$("#txt_search").attr("class","txt_search_image");

}

function spamKill(user,domain) { 
locationstring = "mailto:" + user + "@" + domain; 
window.location = locationstring; 
}

$(document).ready(function(){



$('#registersweepstakes').click(function(){
window.open("sweepstakes.php","","width=820,height=1000,scrollbars=1");
return false;
});

		$('a.lightbox').lightBox();

$('#username').focus(function(){
	if($(this).val() == "username"){
		$(this).val('');
	}
});

$('#username').blur(function(){
	if($(this).val() == ""){
		$(this).val("username");
	}
});

$('#password').focus(function(){
	if($(this).val() == "password"){
		$(this).val('');
	}
});

$('#password').blur(function(){
	if($(this).val() == ""){
		$(this).val("password");
	}
});


$("form").keypress(function(e){
var id = $(this).attr("id");
	if(id!="createMessage"){
	if(e.keyCode == 13){
		$(this).submit();
	}
}

});
 
$("#buyadbtn").click(function(){
		 window.location.href="https://www.advertisernet.com/payforad.php?item=classified";
	});
	
		$("#startoverbtn").click(function(){
		window.location.href="postclassified.php";
	});
 
$("#selectArea").change(function () {
		
		  $("#SelectedAreasDescriptions").html("");

          $("#selectArea option:selected").each(function () {
              // alert($(this).val());
              //pass off the values selected to an ajax function that returns the correct 
              var datastring = "AreaID="+$(this).val();
              	$.ajax({
					type: "POST",
					url: "ajax/ajax_getdescription.php",
					data: datastring,
					success: function(msg){
					
						$("#SelectedAreasDescriptions").append(msg);
					}
		});
              });
	       });


//png fixes
$('img[@src$=.png]').ifixpng();
$(".submit_link").ifixpng();
$(".CommentsCommunity").ifixpng();

$("#modsearch").click(function(){
      	$("#modify_search").toggle("slow");
      	return false;
    });    
$(".rollover").hover(
 function()
 {
  this.src = this.src.replace("_off","_on");
 },
 function()
 {
  this.src = this.src.replace("_on","_off");
 }
);

/* MOUSEOVERS */

$('.textlink').mouseover(function() {
   
   var aid = $(this).attr("rel");
   
   $('#icon_'+aid).attr({"src":  $('#icon_'+aid).attr("src").replace("_off","_on")});
});

$('.textlink').mouseout(function() {
   var aid = $(this).attr("rel");
   $('#icon_'+aid).attr({"src":  $('#icon_'+aid).attr("src").replace("_on","_off")});
});
 
$('.iconlink').mouseover(function(){
	var idarr = $(this).attr("id");
	var id = idarr.split("_");
	$(this).attr({"src":  $(this).attr("src").replace("_off","_on")});
	$("#textlink_"+id[1]).css("color","#3399d9");
});
$('.iconlink').mouseout(function(){
	var idarr = $(this).attr("id");
	var id = idarr.split("_");
	$(this).attr({"src":  $(this).attr("src").replace("_on","_off")});
	$("#textlink_"+id[1]).css("color","#333");

	
});

/* END MOUSEOVERS*/


//if we've got JS we can hide the ugly buttons and show the niceones
$('.regularbtn').hide();
$('#postanadlink').hide();
$('.submit_link').show();
$('.noscript').hide();
$('.yesscript').show();
//swap
$('.submit_link').hover(
	function(){
	$(this).attr("class","submit_link_hover");
},
	function(){
	$(this).attr("class","submit_link");
}


);

/* CHECK IF THERE ARE OTHER ADS IN THIS SPOT*/
$("#rotatecheckbox").click(function(){
	var checked = $('#rotatecheckbox').attr('checked');
	if(checked == true){
		//run query to see if there are ads in this spot.
		var selectedlocation = $('#adlocation').val();
		var datastring = "location="+selectedlocation;
		$.ajax({
			type: "POST",
			url: "/ajax/ajax_adinthislocation.php",
			data: datastring,
			success: function(msg){
				if(msg == 1){
					alert("Ads already exist in this ad location. If you select this option, the other ads will not be shown!");
			}		

	}

});

}
//return false;

});

$("#adlocation").click(function(){
	var checked = $('#rotatecheckbox').attr('checked');
	if(checked == true){
		//run query to see if there are ads in this spot.
		var selectedlocation = $('#adlocation').val();
		var datastring = "location="+selectedlocation;
		$.ajax({
			type: "POST",
			url: "/ajax/ajax_adinthislocation.php",
			data: datastring,
			success: function(msg){
				if(msg == 1){
					alert("Ads already exist in this ad location. If you select this option, the other ads will not be shown!");
			}		

	}

});

}
//return false;

});



//* call submit event when buttons are clicked *//

$('#pollbtn_new').bind("click",function(){
	$("#SubmitPoll").submit();
});

$('#statusbtn_new').bind("click",function(){
	$("#statusUpdate").submit();
});

$('#selectregion_new').bind("click",function(){
	$("#selectRegion").submit();
});

$('#couponbtn_new').bind("click",function(){
	$("#createcouponform").submit();
});

$('#selectcategory_new').bind("click",function(){
	$("#selectcategoryform").submit();
});

$('#region_new').bind("click",function(){
	$("#selectregionform").submit();
});


$('#btlogin_new').bind("click",function(){
	$("#loginform").submit();
});

$('#invitetogroup_new').bind("click",function(){
	$("#invitetogroup").submit();
});

$('#composebtn').bind("click", function(){
	$("#createMessageForm").submit();
});

$('#messagesendbtn').bind("click", function(){
	$("#createMessage").submit();
});

$('#update_btn_new').click(function(){
	$("#updateuserform").submit();
});

$('#updateprofilenew').bind("click", function(){
	$("#updateprofileelementsform").submit();
});


$('#postanadbtn').bind("click", function(){
	window.location = "postclassified.php";
});

$('#updateevent_new').bind("click", function(){
	$("#DisplayExistingEvents").submit();
});

$('#eventcreation_new').bind("click", function(){
	$("#CreateEventForm").submit();
});

$('#DeleteEventNew').bind("click", function(){
	$("#genericformitem").attr("name","deleteEventUpdate");
	$("#UpdateEventForm").submit();
});

$('#SubmitEventNew').bind("click", function(){
	$("#genericformitem").attr("name","submitEventUpdate");
	$("#UpdateEventForm").submit();
});


$('#CancelEventNew').bind("click", function(){
	$("#genericformitem").attr("name","cancelEventUpdate");
	$("#UpdateEventForm").submit();
});


$('#blogentry').bind("click",function(){
	$("#createblogform").submit();
});


$("#newsendmsg").bind("click",function(){
	$("#createMessage").submit();
});

$("#searchclassads").bind("click",function(){
	$("#searchadsform").submit();
});

$("#newsendmsg").bind("click",function(){
	$("#createMessage").submit();
});

$("#purchaselisting_new").bind("click",function(){
	$("#createdininglistingform").submit();
});

$("#BuyNowLink").bind("click",function(){
	$("#DoDirectPaymentForm").submit();
});

$("#reviewad_new").bind("click",function(){
$("#addetailsform").submit();
});

$("#addphotonew").bind("click",function(){
$("#AddPhoto").submit();
});

$("#updateevent_new").bind("click",function(){
$("#DisplayExistingEvents").submit();
});

$("#createvent_new").bind("click",function(){
$("#CreateEvent").submit();
});

$("#login_2").bind("click",function(){
$("#loginformprompt").submit();
});

$("#btn_createpost").bind("click",function(e){
		e.preventDefault();
			$.nyroModalManual({
				url: "community.php?startdiscussion=1"	
			});

});


$("#btn_createevent").bind("click",function(){
	window.location = "myaccount.php?section=6";
});

$("#selectadtypesubmit").bind("click",function(){
	if($("#AdTypeSelect").val() == "3"){
		window.location = "postdininglisting.php";
	}else{
		$("#selectadtypeform").submit();
	}
});


$("#bt_backtoinbox").bind("click",function(){
			window.location = "myaccount.php?section=5";
});


$("#bt_cancelmsg").bind("click",function(){
			window.location = "myaccount.php?section=5";
});


$("#AdParentSelect").change(function(){
	switch($("#AdParentSelect").val()){
		case "For Sale":
			$("#description").html("<i>General Merchandise, Vehicles, Motorcycles, Snowmobiles, ATVs, Firewood, Avon/Vendors, Trees / Plants</i>");
			break;
		case "Garage Sale":
			$("#description").html("<i>Single Family, Community/Neighborhood, Church, Craft Fair, Auction, Estate</i>");
			break;
		case "Real Estate":
			$("#description").html("<i>By Owner, New Construction, Agent, Rent w/ Option</i>");
			break;
		case "Wanted":
			$("#description").html("<i>General Merchandise, Junk Removal, Cars/Trucks</i>");
			break;
		case "Jobs Wanted":
			$("#description").html("<i>Housecleaning, Babysitting</i>");
			break;
		case "Pets":
			$("#description").html("<i>For Sale, Services</i>");
			break;
		case "Equine":
			$("#description").html("<i>Boarding, Services, For Sale</i>");
			break;
		case "General":
			$("#description").html("<i>Rent, Business Opportunities, Notices, Services Offered, Give Away, Trade</i>");
			break;				
		default:
			$("#description").html("");
		}
});


$(".bannerstatus").change(function(){
if($(this).val()){
	var f = $(this).attr("id");
	var splitarr = f.split("_");
	$("#updatebanneradstatus_"+splitarr[1]).submit();
}else{
	return false;
}
});

$(".abusestatusthread").change(function(){
	if($(this).val()){
		var f = $(this).attr("id");
		var splitarr = f.split("_");
		$("#updateabusestatusthread_"+splitarr[1]).submit();
	}
});

$(".abusestatuscomments").change(function(){
	if($(this).val()){
		var f = $(this).attr("id");
		var splitarr = f.split("_");
		$("#updateabusestatuscomment_"+splitarr[1]).submit();
	}
});

$("#bloglink").click(function(){
		window.location = "myaccount.php?section=9";
});


$("#btn_buylisting").click(function(){
			window.location = "postdininglisting.php";

});

/* VALIDATION */
//sign up form
$("#adminaddnewcategory").validate();

	$("#signupform").validate({
		rules: {
				firstName: "required",
				lastName: "required",
				username:{
					required: true,
					minlength: 5
				},
				password1:{
					required: true,
					minlength: 5
				},
				passwordConfirm: {		
					equalTo: "#password1"
				},
				email: {
						required: true,
						email: true
					}
		},
		messages: {
			firstName: "You must provide a First name.",
			lastName: "You must provide a Last name.",
			username: {
				required: "You must indicate a desired username.",
				minlength: "Usernames must be at least 5 characters in length."
				},
			password: {
				required: "Please indicate a password.",
				minlength: "Passwords must be at least 5 characters in length"
			},
			passwordConfirm: {
				equalTo: "Your passwords do not match!"
			},
			email: {
				required: "Please insert your email address.",
				email: "Please format your email correctly. Example: user@email.com"
			}
			
		
		}
		
	});
	
		$("#signupform2").validate({
		rules: {
				firstName: "required",
				lastName: "required",
				username:{
					required: true,
					minlength: 5
				},
				password1:{
					required: true,
					minlength: 5
				},
				passwordConfirm: {		
					equalTo: "#password1"
				},
				email: {
						required: true,
						email: true
					}
		},
		messages: {
			firstName: "You must provide a First name.",
			lastName: "You must provide a Last name.",
			username: {
				required: "You must indicate a desired username.",
				minlength: "Usernames must be at least 5 characters in length."
				},
			password: {
				required: "Please indicate a password.",
				minlength: "Passwords must be at least 5 characters in length"
			},
			passwordConfirm: {
				equalTo: "Your passwords do not match!"
			},
			email: {
				required: "Please insert your email address.",
				email: "Please format your email correctly. Example: user@email.com"
			}
			
		
		}
		
	});
		
		
	$("#AutoSearchForm").validate({
  rules: {
   	price_low: {
      required: false,
      number: true
    },
    price_high:{
      required: false,
      number: true
    }
    
   },
    messages: {
			price_low: "Numbers only please! (example: 10000)",
			price_high: "Numbers only please! (example: 10000)"
	 }
});


$("#addetailsform2").validate();
$("#posthelpwantedpublic").validate();
$("#postbannerad").validate({
	
	rules:{
		Name: "required",
		AllowedImpressions:{
			required: true,
    		number: true
		},
	    TargetURL:{
	    	required: true,
	    	url: true
	    },
	    AllowedClicks:{
	    	required: true,
	    	number: true,
	    	min: 0
	    }
	    
	},
	messages:{
		Name: "Please provide a simple name for your ad.",
		AllowedImpressions: "What is the maximum number of impressions (views) purchased for this ad? Numbers only, please",
		TargetURL: "Please format your url like this: http://www.google.com",
		AllowedClicks: "Please use a whole number only.  If not applicable, leave as 0."
	}
	
});




//forgot password page
	$("#forgotform").validate({
		rules: {
				email: {
						required: true,
						email: true
					}
		},
		messages: {
			email: {
				required: "Please insert your email address.",
				email: "Please format your email correctly. Example: user@email.com"
			}
			
		
		}
		
	});
	
//add profile element form
	$("#addprofilelementform").validate();

//login form (listed on every page)

$("#loginform").validate();
$("#signupform").validate();
$("#createblogform").validate();
$("#createMessage").validate();
$("#invitetogroup").validate();
$("#createdininglistingform").validate();
$("#selectregionform").validate();
$("#CreateEvent").validate();
$("#createMessage").validate();






/* AJAX FORM SUBMISSION */

//sign up form	
	
	$("#signupform").submit(function() {
	
	if($("#signupform").valid()){
		//grab values
		var firstName = $("input#firstName").val();
		var lastName = $("input#lastName").val();
		var username = $("input#desiredusername").val();
		var password = $("input#password1").val();
		var email =  $("input#email").val();
		//construct datastring to pass to PHP
		var datastring = "firstName="+firstName+"&lastName="+lastName+"&username="+username+"&password="+password+"&email="+email;
		$.ajax({
			type: "POST",
			url: "ajax/ajax_signup.php",
			data: datastring,
			success: function(msg){
				if(msg == "no"){
					alert("Username exists. Please choose a different username.");
				}else if(msg == "dirty"){
					alert("Please choose an appropriate user name.");
					$("#desiredusername").focus();
				}else{
				
					$("#confirm").html("Thank you for signing up with the advertiser site! You can now login.");
					$("#confirm").slideDown();
					document.getElementById('firstName').value = "";
  					document.getElementById('lastName').value = "";
  					document.getElementById('desiredusername').value = "";
  					document.getElementById('password1').value = "";
  					document.getElementById('passwordConfirm').value = "";
  					document.getElementById('email').value = "";
  					
  					//we want to sign the user in.
	/*
	var datastring2 = "username="+username+"&password="+password;
		
			$.ajax({
			type: "POST",
			url: "ajax/ajax_login.php",
			data: datastring2,
			success: function(msg){
			//do stuff
				if(msg == "0"){
						alert("Username or password incorrect.");
				}else{
							window.location = "index.php";

				}
			}
		
			});
*/

	
				}
			}
		});
		
		//do NOT submit form. form only submits when JS is disabled.
		return false;		
	}
	});
//update status form
	
	$("#statusUpdatea").submit(function() {
		//grab values
		var status = $("input#myStatus").val();
		var currPage = $("input#curr_page").val();
				//construct datastring to pass to PHP
		var datastring = "status="+status+"&currPage="+currPage;
		$.ajax({
			type: "POST",
			url: "ajax/ajax_updatestatus.php",
			data: datastring,
			success: function(msg){
				if(msg === 0){
					alert("Error updating status.");
				}else{
					//we get status in "STATUS|DATE" format.
					//let's parse this array and place in DOM
					var statusArray = msg.split("|");
					username = statusArray[0];
					statusTxt = statusArray[1];
					statusTime = statusArray[2];
					currPage = statusArray[3];
					//set the appropriate fields
					
					var statusForm = '<a href="updateStatus.php" id="showUpdate" style="display:none;">Update</a></div><div id="update"><b>Update Your Status!</b> <form name="statusUpdate" id="statusUpdate" action="updateStatus.php"><input type="text" name="myStatus" id="myStatus" class="statusTxt" width="140"/><input type="submit" name="submitStatus" value="Update" class="statusBtn"/><input type="hidden" name="curr_page" id="curr_page" value="'+currPage+'"/></form></div>';					
					$("#statusArea").html('<div id="currentStatus"><b>Your status: </b>'+statusTxt+ ' <i>on ' +statusTime+'</i>'+statusForm); 			
				}
			}
		});
		
		//do NOT submit form. form only submits when JS is disabled.
		return false;		
	});

	
	
//login form
	/* NOTE NOT USED! */ 
	$("#loginformasdf").submit(function() {
	if($("#loginformasdf").valid()){
		var username = $("input#username").val();
		var password = $("input#password").val();
		var datastring = "username="+username+"&password="+password;
		
		$.ajax({
		type: "POST",
		url: "ajax/ajax_login.php",
		data: datastring,
		success: function(msg){
			//do stuff
			if(msg == "0"){
					alert("Username or password incorrect.");
			}else{
				// alert("logged in");
					$("#login").html("<div>You are logged in as " +msg+ ". <a href='logout.php'>Logout</a>  | <a href='myaccount.php'>My Account</a></div>");
			}
		}
		
		});
	return false;
	}	
	});

//forgot pw form
	
	$("#forgotform").submit(function() {
	if($("#forgotform").valid()){
		var datastring = "email="+$("input#email").val();
		$.ajax({
		type: "POST",
		url: "ajax/ajax_regenpassword.php",
		data: datastring,
		success: function(msg){
			//do stuff
			if(msg == "0"){
					alert("Email address does not exist in our system.  Please sign up.");
			}else if(msg == "2"){
				// alert("logged in");
					alert("Your username and password has been emailed to you. Please check your email.");
  					document.getElementById('email').value = "";
  					top.location.href="index.php";
			}else{
					alert("There was a problem submitting your request. Please try again later.");
			}
		}
		
		});
	return false;
	}	
	return false;
	});

	function getUserSearchResults(datastring){
	
		$.ajax({
		type: "POST",
		url: "ajax/ajax_finduser.php",
		data: datastring,
		success: function(msg){
			//clear results
			$("#results").html("");

			if(msg == "0"){
					alert("User not found!");
			}else{
			//expecting array of users in this format: userinfo|userinfo|userinfo||userinfo2|userinfo2|userinfo2
			//first, split by ||
			
			var results = '<table width="600" cellspacing="0" cellpadding="0" border="1" id="resultstable"><tr><td valign="top" class="tbl_hdr">UserID</td><td valign="top" class="tbl_hdr">User Name</td><td valign="top" class="tbl_hdr">Name</td><td valign="top" class="tbl_hdr">Email</td><td valign="top" class="tbl_hdr">Permissions Level</td><td valign="top" class="tbl_hdr">Is Locked?</td><td class="tbl_hdr">Edit</td><td class="tbl_hdr">Lock User</td></tr>';
			var userArray=msg.split("||");
				
				//now we loop through and split this array:
				var userArrayLength = userArray.length-1;
				var i;
				for(i=0;i<userArrayLength;i++){
					//now we're just on one user. split even further by |
					var userData = userArray[i].split("|");
					var userDataLength = userData.length;
					var n;
						results+= "<tr id='resultsrow_"+i+"'>";
						for(n=0;n<userDataLength;n++){
							
							//now we can spit out individual user data
							results+="<td class='tbl_results'>"+userData[n]+"</td>";
						}
						results+='<td class="tbl_results"><a href="/ajax/ajax_userdata.php?userID='+userData[0]+'" class="nyroModalD"><img src="/images/pencil.png" alt="" border="0"/></a></td><td class="tbl_results"><a href="/ajax/ajax_lockuser.php?userID='+userData[0]+'" class="nyroModalD"><img src="/images/lock.png" alt="" border="0"/></a></td>';
						results+="</tr>";
							
				}		
						results +="</table></div>";
						$("#results").append(results);
						$(".nyroModalD").click(function(e){
								e.preventDefault();
								$.nyroModalManual({
								url: $(this).attr("href")	
							});
							return false;
							});
			}
		}
		
		});
	}
	
	

	
	$("#edituserform").submit(function() {
		var datastring = "keyword="+$("input#keyword").val()+"&searchparams="+$("select#searchBy").val();
		getUserSearchResults(datastring);
	return false;
	});
	
	$("#selectUserID").change(function() {
		if($("#selectUserID").val()){
			var datastring = "keyword="+$("#selectUserID").val()+"&searchparams=UserID";
			getUserSearchResults(datastring);
		}else{
		return;
		}
	});
	
	$("#addprofilelementform").submit(function() {
	if($("#addprofilelementform").valid()){
	var datastring = "profileElementName="+$("input#profileElementName").val()+"&profileElementType="+$("select#profileElementType").val();
		
		if(($("select#profileElementType").val() == "MultiOptions") || $("select#profileElementType").val() == "Options"){
		
			//add it and launch modal on success
				$.ajax({
		type: "POST",
		url: "ajax/ajax_addprofileelements.php",
		data: datastring,
		success: function(msg){
			//do stuff
			if(msg == "0"){
					alert("Error creating profile element");
			}else{
				//ok we've inserted successfully now we have to launch this window to add options. let this script handle from here.
				
				var profileElArray = msg.split("||");
				profileElId = profileElArray[1];
				$.nyroModalManual({url: "/ajax/ajax_addprofileelementoptions.php?id="+profileElId});
				
				}	
			}
		});
		return false;	
					
		}else{
			//add it but don't launch modal
		
		$.ajax({
		type: "POST",
		url: "ajax/ajax_addprofileelements.php",
		data: datastring,
		success: function(msg){
			//do stuff
			if(msg == "0"){
					alert("Error creating profile element");
			}else{
				//replace current ones
				//now we are going to export list of profile elements from php
				var profileElArray = msg.split("||");
				//we know that profileElArray[1] = theID
				//we also know that profileElArray[0] = the data
				//split each result on the |
					var profileElData = profileElArray[0].split("|");
					var profileElDataLength = profileElData.length;
					var n;
						$("#listofelements").append("<tr id='profElResultsRow'>");
						for(n=0;n<profileElDataLength;n++){
							//now we spit out data itself
							$("#profElResultsRow").append("<td class='tbl_results'>"+profileElData[n]+"</td>");
						}	
							$("#profElResultsRow").append('<td class="tbl_results"><a href="/ajax/ajax_editprofileelement.php?id='+profileElArray[1]+'" class="nyroModal nyroModalD2"><img src="/images/pencil.png" alt="" border="0"/></a></td>');
							$("#listofelements").append('</tr>');
							$("input#profileElementName").val("");
								$("#results").append(results);
								$(".nyroModalD2").click(function(e){
								e.preventDefault();
								$.nyroModalManual({
								url: $(".nyroModalD2").attr("href")	
							});
							return false;
							});
					}
					
				}
				
		
		});
	return false;
	}
}



});

//friend request
	
	$(".addfriend").click(function(){
		var user1 = $("input#user1").val();
		var user2 = $("input#user2").val();
		//construct datastring to pass to PHP
		var datastring = "user1="+user1+"&user2="+user2;
		$.ajax({
			type: "POST",
			url: "ajax/ajax_addfriend.php",
			data: datastring,
			success: function(msg){
				alert(msg);
				$(".friendstatus").html(msg);
				}
			});

		
	});
	
	//leave group
	$(".leaveGroup").click(function(){
		var id = $(this).attr("id");
		var datastring = "groupID="+id+"&userID="+$(this).attr("rel");
		$.ajax({
			type: "POST",
			url: "ajax/ajax_leavegroup.php",
			data: datastring,
			success: function(msg){
				if(msg == 1){
					alert("Group Left!");
					$("#GroupDisplay_"+id).slideUp();
				}else{
				
					alert("There was a problem leaving this group. Please try again later!");
				
				}
				
			}
		
		
		
		});
				
	
	return false;
	});

	//leave group
	$(".joingroup").click(function(){
		var id = $(this).attr("id");
		var datastring = "groupID="+id+"&userID="+$(this).attr("rel");
		$.ajax({
			type: "POST",
			url: "ajax/ajax_joingroup.php",
			data: datastring,
			success: function(msg){
				if(msg == 1){
					alert("You Joined this group");
					$(this).hide();
				}else{
				
					alert("There was a problem joining this group. Please try again later!");
				
				}
				
			}
		
		
		
		});
				
	
	return false;
	});
	
	
	$("#showUpdate").click(function(){
		$("#update").slideDown();
		return false;
	});
	
	$("#update").hide();
	$("#showUpdate").show();



/*AUTOMOTIVE AUTO POPULATE SCRIPTS */


	
});

function ShowLess(id,table){
	
	var datastring = "table="+table+"&id="+id;
	$.ajax({
		type: "POST",
		url: "ajax/ajax_getless.php",
		data: datastring,
		success: function(msg){
			if(table == "Dining"){
			var info = msg + "<a href=\"javascript:ShowAll('"+id+"','"+table+"');\">(Show More)</a>";
				$("#dining_description_"+id).html(info);
			}
			
			if(table == "Events"){
			var info = msg + "<a href=\"javascript:ShowAll('"+id+"','"+table+"');\">(Show More)</a>";
				$("#events_description_"+id).html(info);
			}
			
			if(table == "HelpWanted" || table == "Directories"){
			var info = msg + "<a href=\"javascript:ShowAll('"+id+"','"+table+"');\">(Show More)</a>";
				$("#helpwanted_description_"+id).html(info);
			}
		}
	
	});

}

function ShowAll(id,table){
	
	var datastring = "table="+table+"&id="+id;
	$.ajax({
		type: "POST",
		url: "ajax/ajax_getall.php",
		data: datastring,
		success: function(msg){
			if(table == "Dining"){
			var info = msg + " <a href=\"javascript:ShowLess('"+id+"','"+table+"');\">(Show Less)</a>";
				$("#dining_description_"+id).html(info);
			}
			if(table == "Events"){
				var info = msg + " <a href=\"javascript:ShowLess('"+id+"','"+table+"');\">(Show Less)</a>";
				$("#events_description_"+id).html(info);
			}
			if((table == "HelpWanted") || (table == "Directories")){
				var info = msg + " <a href=\"javascript:ShowLess('"+id+"','"+table+"');\">(Show Less)</a>";
				$("#helpwanted_description_"+id).html(info);
			}
		}
	
	});

}	






	
	
	function addProfileElementTable(myid){
		id = myid+1;
		$("#profelemnts").append('<tr><td class="tbl_results"><input type="text" name="profileElementName_'+id+'" id="profileElementName_'+id+'" style="display:inline;"/></td><td class="tbl_results"><select name="profileElementType_'+id+'" id="profileElementType_'+id+'" ><option value="URL">URL</option><option value="ImgURL">URL</option><option value="Date">Date</option><option value="TextField">Text Field</option><option type="TextArea">Text Area</option></select></td><td class="tbl_results"><a href="#" onclick="javascript:addProfileElementTable(\''+myid+'\');" id="addanother_'+myid+'"><img src="/images/add.png" border="0" alt=""/></a></td></tr>');
		
		//remove the last one
		$("#addanother_"+myid).remove();
		
		//add +1 to the total count to pass to PHP
		document.getElementById('table_count').value = parseInt(document.getElementById('table_count').value,10)+1;
		}

	
			function addNewOption(currOptions){
				var newOptions = parseInt(currOptions,10) + 1;
				$("#availoptions").append('<tr id="optionrow_'+newOptions+'"><td class="tbl_results"><input type="text" name="option_'+newOptions+'" id="option_'+newOptions+'"></td><td class="tbl_results"><img src="../images/add.png" id="addAnother_'+newOptions+'" onclick="addNewOption(\''+newOptions+'\');" border="0"></td></tr>');
				$("#numberofoptions").val(newOptions);
				$("#addAnother_"+currOptions).hide();
				
			}
			
			
			function addNewOptionModal(currOptions){
				var newOptions = parseInt(currOptions,10) + 1;
				$("#availoptions").append('<tr><td><input type="text" name="value_'+currOptions+'" value=""/></td></tr>');
				$("#numberofoptions").val(newOptions);
			}

function showTab(tabid,maxtabs){
var n;
var l = maxtabs + 1;
for(n=1;n<l;n++){
	$('#tab_'+n).hide();
	$('#tab_li_'+n).attr("class","");
}
		//show tab
	$('#tab_'+tabid).show();
	$('#tab_li_'+tabid).attr("class","tab"+tabid);
}


function showSubTab(tabid,maxtabs){
var n;
var l = maxtabs + 1;
for(n=1;n<l;n++){
	$('#subtab_'+n).hide();
	$('#subtab_li_'+n).attr("class","");
}
		//show tab
	$('#subtab_'+tabid).show();
	$('#subtab_li_'+tabid).attr("class","subtab"+tabid);
}



