	
	function trim(str, chars) {
		return ltrim(rtrim(str, chars), chars);
	}
	 
	function ltrim(str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
	}
	 
	function rtrim(str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
	}
	
	
	
	function setValue(id,value)
	{
		//alert(id);
		document.getElementById(id).value=value;
	}
	
	function getValue(id)
	{
		return $("#"+id).val();	
	}
	
	function setMode(mode)
	{		
		setValue("hdnMode",mode)		
	}

	function check_mode()
	{
		if (getValue("hdnMode")==2&&getValue("hdnq")=='')	{return false;}
		return true;
	}

	function load_favourite_result()
	{
		setMode(3);
		if (getValue("cmbFavSearch")!='')	document.frm.submit();
	}
	function toggle_display(id)
	{
		if (document.getElementById(id).style.display=='block')	
		{
			document.getElementById(id).style.display='none';	
		}
		else
		{
			document.getElementById(id).style.display='block';
		}
	}

	function hide(id)
	{
		$("#"+id).hide();	
	}
	function setFocus(id)
	{
		document.getElementById(id).focus();	
	}
	
	function update_interest()
	{		
		interest=$("#bio").val();		
		//alert(interest);
		Ajax('ajax_update_member.php','mode=1&interest='+interest);
	}
	function update_interesttext()
	{
		interest=$("#interest_text").val();
		Ajax('ajax_update_member.php','mode=2&interesttext='+interest);
		
	}

	function update_hobbies()
	{
		interest=$("#hobbies_text").val();
		Ajax('ajax_update_member.php','mode=3&hobbiestext='+interest);
		
	}

	function update_introduction()
	{
		introduction=$("#introduction_text").val();
		Ajax('ajax_update_member.php','mode=4&introductiontext='+introduction);
		
	}


	function Ajax(url,data)
	{
		$.ajax({
			type: "POST",
			url: ""+url+"",
			data: ""+data+"",
			success: function(Response)
			{
				AjaxResponse(Response);			
			}
		});	
		
	}
	function AjaxResponse(Response)
	{

		Response=Response.split("||");	
		
		Mode=Response[0];	
		
		if (Mode==1)
		{
			//$("#ComboBox").val(2);
			//$("#interest").val
			//alert('Successfull updated.');	
			
			$("#interestedIn").html(Response[1]);
			$("#interestedIn").show();
		}
		if (Mode==2)
		{
			//alert('Successfull updated.');	
			text='N/A';
			if (Response[1]!='')	{text=Response[1];}
			$("#interesttext").html(text);
			$("#interesttext").show();
		}
		if (Mode==3)
		{
			//alert('Successfull updated.');	
			text='N/A';
			if (Response[1]!='')	{text=Response[1];}
			$("#hobbiestext").html(text);
			$("#hobbiestext").show();
		}
		if (Mode==4)
		{
			//alert('Successfull updated.');	
			text='N/A';
			if (Response[1]!='')	{text=Response[1];}
			$("#introductiontext").html(text);
			$("#introductiontext").show();
		}
		
		
		
	}
	function getChecked(id)
	{
		return document.getElementById("chkTerms").checked;		
	}
	function setElemValue(id,value)
	{
		$("#"+id+"").val(value);	
	}
	function set_mode_before_form_submit(mode,idx)
	{	
		$('#mode').val(mode);
		$('#idx').val(idx);	
		if (mode==3)
		{
			return confirm('Are you sure to delete?');	
		}
		return true;	
	}
	function submit_form(action)
	{
		//$("#agentForm").attr("action", "somewhere.html");
		document.frm.action=action;
		document.frm.submit();	
	}
	function checkAll(bmode)
	{
		 var cbs=document.getElementsByName('contacts[]');	 
		 for (var zxc0=0;zxc0<cbs.length;zxc0++)
		 {
			  cbs[zxc0].checked=bmode;
		 }
	}
	
	function select1()
	{
			
		if (document.getElementById("select_all").checked)
		{
			checkAll(true);	
		}
		else
		{
			checkAll(false);		
		}
	}

	function Test(nme)
	{
		 var cbs=document.getElementsByName('contacts[]');	 
		 for (var zxc0=0;zxc0<cbs.length;zxc0++)
		 {
			  cbs[zxc0].checked=true;
		 }
	}
	
	function validate_login()
	{
		if ($("#user").val()=='')	{alert('Please enter Username');return false;}	
		if ($("#passwd").val()=='')	{alert('Please enter password');return false;}	
		return true;
	}
	
	function validate_poll()
	{
		var checkedValue = $('[EMAIL PROTECTED]"poll_entry_idx"]:checked').val();
		if (checkedValue==undefined)	{alert('Please select at least one option.');return false;}
		return true;
	}
	
	function validate_user_registration()
	{
		
		if (!getChecked("chkTerms"))	{alert('Please accept terms and conditions.');return false;}
		return true;
	}
	
	function validate_user_registration_()
	{
		//alert(getChecked("test"));
		if (!getChecked("chkTerms_1"))	{alert('Please accept terms and conditions.');return false;}
		return true;
	}
	
	function termsandconditions()
	{
		//alert(getChecked("chkTerms_1"));	
		return false;
	}


	function set_language(language)
	{
		Ajax(ROOTDIR+"/client/set_language.php","language="+language);		
	}
	
	function validate_payment_methods()
	{
		 chk=0;
		 var cbs=document.getElementsByName('payment_method[]');	 
		 
		 for (var zxc0=0;zxc0<cbs.length;zxc0++)
		 {
			  if (cbs[zxc0].checked==true)	{chk=1;}
		 }
		 
		 if (chk==0)
		 {
			alert('Please select at least one payment method to proceede.');			 
			return false;
		 }
		 
		 return true;
		
	}
	function toggle_status()
	{
		
		if ($("#country").val()=='US')	
		{
			$("#text_states2").hide();			
			$("#text_states1").show();				
		}
		else
		{
			$("#text_states1").hide();
			$("#text_states2").show();					
		}
		
	}
	
	function validate_comment(index)
	{
		
		$("#comments"+index).val(trim($("#comments"+index).val(), ' '));
		if ($("#comments"+index).val()=='')	{alert('Please enter comments first.');$("#comments"+index).focus();return false;}	
		return true;
	}
	
	function isdefined( variable)
	{
    	return (typeof(window[variable]) == "undefined")?  false: true;
	}

	
	function select_all_messages()
	{			

		var mutli_education = document.frm_compose.elements["messages[]"];
		
		
		//if (typeof(document.frm_compose.messages) != 'undefined')
		//{
			if (document.getElementById("select_all").checked)
			{
				for(i=0;i<mutli_education.length;i++)
				{
					mutli_education[i].checked=true;
				}		
			}
			else
			{
				for(i=0;i<mutli_education.length;i++)
				{
					mutli_education[i].checked=false;
				}
			}
		/*}
		else
		{
			alert(1);	
		}*/
	
	}
	
	function friend_count()
	{	
		
		var mutli_education = document.frm_compose.elements["user[]"];
		selected=0;	
		for(i=0;i<mutli_education.length;i++)
		{
		 	if (mutli_education[i].checked)
			{
				selected++;
			}
		}		
		$("#friend_counter").html(selected);
	
	}
	function validate_compose_form()
	{
		selected=0;
		for (var x = 0; x < document.frm_compose.users.length; x++)
        {
			if (document.frm_compose.users[x].checked == true)
			{
				selected++;	
			}
		}
		if (selected==0)	{alert('Please select at least one user.');return false;}
		return true;
	}
	
	function set_elite_check_box()
	{
		if ($("#user_type_id").val()==7)	
		{
			$("#tr_elite_checkbox").show();	
		}
		else
		{
			$("#tr_elite_checkbox").hide();	
		}
	}
	
	
	$(document).ready(function(){ 
    	
		$("#membership tr").click( function(){ 
			$("#membership tr").removeClass("tr_highlight");
			$(this).addClass("tr_highlight");			
//			$(this).attr('checked', true);
			$(':radio', this).attr('checked', true);
		});
		

	});
	
	function check_folder_name()
	{
		if ($("#folder_name").val()=='')	{alert('Please enter folder name.');return false;}	
		return true;
	}
	
	function create_folder()
	{
		if ($("#folder_option").val()==0)	{return false;}
		if ($("#folder_option").val()=='create')
		{
			centerPopup();  
			
			//$("#popupcontent").load("//addmilestone.html");
			
			$("#popupcontent").html('<form onsubmit="return check_folder_name();" action="" method="post"><table style="color:#000000"><tr><td colspan="2"><h1>Create a Folder</h1></td></tr><tr><td>Folder Name</td><td><input type="text" id="folder_name" name="folder_name" value=""></td></tr><tr><td colspan="2"><input type="submit" id="btnSubmit" name="btnSubmit" value=" Add "></td></tr></table><input type="hidden" id="mode" name="mode" value="5"></form>');
			//load popup  
			loadPopup();  
			
		}
		else
		{
			//document.getElementById('mode').value=11;		
			//document.frm_compose.submit();				
		}
		
	}	
	
	function create_folder2()
	{
		if ($("#folder_option2").val()==0)	{return false;}
		if ($("#folder_option2").val()=='create')
		{
			centerPopup();  
			
			//$("#popupcontent").load("//addmilestone.html");
			
			$("#popupcontent").html('<form onsubmit="return check_folder_name();" action="" method="post"><table style="color:#000000"><tr><td colspan="2"><h1>Create a Folder</h1></td></tr><tr><td>Folder Name</td><td><input type="text" id="folder_name" name="folder_name" value=""></td></tr><tr><td colspan="2"><input type="submit" id="btnSubmit" name="btnSubmit" value=" Add "></td></tr></table><input type="hidden" id="mode" name="mode" value="5"></form>');
			//load popup  
			loadPopup();  
			
		}
		else
		{
			//document.getElementById('mode').value=12;		
			//document.frm_compose.submit();				
		}
		
	}	
	
	   //CLOSING POPUP  
   //Click the x event!  
    $("#popupContactClose").click(function(){  
    disablePopup();  
    });  
	
    //Click out event!  
	//Press Escape event!  
	 $(document).keypress(function(e){  
	 if(e.keyCode==27 && popupStatus==1){  
	 disablePopup();  
	 }  
	 });  
	
	function filter_messages()
	{
		document.getElementById('mode').value=3;		
		document.frm_compose.submit();			
	}
	
	function check_message_mode()
	{
		mode=$("#mode").val();
		var mutli_education = document.frm_compose.elements["messages[]"];
		selected=0;	
		for(i=0;i<mutli_education.length;i++)
		{
		 	if (mutli_education[i].checked)
			{
				selected++;
			}
		}
		
		if (selected==0)
		{
			alert('Please select at least one message.')	
			return false;
		}
		else
		{
			if (mode==2)
			{
				if ($("#folder_option").val()==0||$("#folder_option").val()=='create')	
				{
					alert('Please select folder.')	
					return false;	
				}					
			}			
			else
			if (mode==22)
			{
				if ($("#folder_option2").val()==0||$("#folder_option2").val()=='create')	
				{
					alert('Please select folder.')	
					return false;	
				}					
			}
		}
		
		return true;
		
	}
	
	
	function change_source(index)
	{
		document.getElementById('aaaaaa').value=index;	
		$('#'+'img_rate_'+index+'').attr("src","images/client/rating-fill.gif");	
	}
	function change_source_1(index)
	{
		
		$('#'+'img_rate_'+index+'').attr("src","images/client/rating-empty.gif");	
	}
	
	function create_list()
	{
		if ($("#list").val()=='')	{return false;}
		if ($("#list").val()==0)
		{
			
			centerPopup();  

			$("#popupcontent").html('<form onsubmit="return check_list();" action="add_list.php" method="post"><table style="color:#000000"><tr><td colspan="2"><h1>Create a List</h1></td></tr><tr><td>List:</td><td><input type="text" id="list" name="list" value=""></td></tr><tr><td colspan="2"><input type="submit" id="btnSubmit" name="btnSubmit" value=" Add "></td></tr></table><input type="hidden" id="mode" name="mode" value="5"></form>');
			
			//$("#popupcontent").height(200);
			
			//load popup  
			loadPopup();  			
		}
		else
		{
			document.getElementById('mode').value=3;
			document.frm_friend_request.submit();	
		}
		
	}
	
	function check_list()
	{
		if ($("#list").val()=='')	{alert('Please enter list name.');return false;}	
		return true;
	}
	
	// this function add comment on group on group details page
	//  by m.shafique 12/30/2009
	function addComments()
	{
		
		var comments = $("#addGroupCommentTxtField").val();
		var grupRandIdx = $("#GroupRandIdx").val();
			//alert(grupRandIdx);
		$.ajax({
			   type: "POST",
			   url: "add_group_comments.php",
			   data: "groupId="+grupRandIdx+"&comments="+comments+"&test="+grupRandIdx,
			   success: function(msg){
				   $("#groupComment").html(msg);
				// alert( "Data Saved: " + msg );
			   }
			 });
		$("#addGroupCommentTxtField").val('');
		$("#addGroupCommentTxtField").focus();
	}
	function deletComments(commentId)
	{
		var grupRandIdx = $("#GroupRandIdx").val();
		$.ajax({
			   type: "POST",
			   url: "add_group_comments.php",
			   data: "groupId="+grupRandIdx+"&action=delete&comment_id="+commentId,
			   success: function(msg){
				   $("#groupComment").html(msg);
				// alert( "Data Saved: " + msg );
			   }
			 });
	
	}
