/* function for making members onclicking of upload if he is not a member --laxmi*/

function makeMember(gid,rurl)
{
	var base_url = jQuery("#base_url").val();
	jQuery.ajax(
	{
		type: "POST",
		url: base_url+'Groups/makeMember/'+gid,
		data: "",
		success: function(msg)
		{
		msg = msg.replace(/^\s+|\s+$/g,"");
		if(rurl!=''){
		location.href=rurl;
		}
		
		}
	
		});
}

function stripTags(o)
{
var st =o.value;

st=st.replace("<!--","");
st=st.replace("-->","");

st=st.replace(/^\s*|\s*$/,"");
st=st.replace(/\"/g,"");
st=st.replace(/\'/g,"");

o.value=st.replace(/<.*>/g, '' );
o = o.value;
o= o.trim();
}

function isNum(o)
{
if(isNaN(o.value))
{ 
	o.value='';

	o.focus();

alert("Please put in number only!!");

o.value='';

return false;

}

}
/* ends here*/

/* ibibo rocks dropdown header menu */

var flagState = 0;

function rockopenMenul(strOpen) {	

	if(this.flagState == 0)

	    rockshow(strOpen);

	else

	    rockhide(strOpen);
}

function rockopenMenu(strOpen){	

   for(i = 1 ; i <= 6; i++){

       if(strOpen!=('rocktopmenu'+i)){

       rockhide('rocktopmenu'+i);

        }

   }

   if(document.getElementById(strOpen).style.display != 'block'){ 

     rockshow(strOpen);

   }

}

function rockhide(str){	

	document.getElementById(str).style.display = 'none'; 

	this.flagState = 0; 

}

function rockshow(str){

	document.getElementById(str).style.display = 'block';

	this.flagState = 1; 

}

function rockmenuhide(str){

	setTimeout("rockhide('"+str+"')",300);

}

function rockHideCont(str){

	document.getElementById(str).style.display = 'none'; 

}



function rockShowCont(str){

	document.getElementById(str).style.display = 'block'; 

}

function rockHideAllCont(){

 for(i = 1 ; i <= 6; i++){

   	document.getElementById('rocktopmenu'+i).style.display = 'none';

  }

}


// function to send friendship request.
function prSendFriendRequest(uId,frndUId)
{
	if(uId == ""){
		
		var auth_url = document.getElementById('auth_url').value;
		window.location.href=auth_url;
		return;
	}
	
	var url=base_url+'friends/sendFriendRequest';
	
	jQuery.ajax({
   type: "POST",
   url: url,
   data: "frndUId="+frndUId,
   success: function(msg){
     
     
     if(parseInt(msg) != 0){
	getAdxPU( 0, 500, escape(msg), 'Friend request sent');

     	
     	//document.getElementById('friendBlock').disabled=true;
     	
     	document.getElementById('addFriend_'+frndUId).innerText = "Cancel request";
     	jQuery("#addFriend_"+frndUId).text("Cancel request");
     	jQuery("#addFriend_"+frndUId).unbind('click');
     	jQuery("#addFriend_"+frndUId).click(function(){
     		prCancelFriendRequest(uId,frndUId);
     	});
     	
     }
   }
 });
}


// function to cancel friendship request.
function prCancelFriendRequest(uId,frndUId)
{
	if(uId == ""){
		
		var auth_url = document.getElementById('auth_url').value;
		window.location.href=auth_url;
		return;
	}
		
	//var base_url = jQuery("#base_url").val();
	var url=base_url+'profile/CancelFriendRequest/'+uId+'/'+frndUId;
	
	jQuery.ajax({
   type: "POST",
   url: url,
   data: "",
   success: function(msg){
     
     jQuery("#myPUTitle").text("Friend Request");
     getMyPU(45);
     
     if(parseInt(msg) == 1){
     	
     	document.getElementById('friendBlock').innerText = "Add as a friend";
     	jQuery("#friendBlock").text("Add as a friend");
     	jQuery("#friendBlock").unbind('click');
     	jQuery("#friendBlock").click(function(){
     		sendFriendRequest(uId,frndUId);
     	});
     	
     }
   }
 });
}


/*
* function to delete friend.
*
*/
function removeAsFriend(frndUId)
{
	
	jQuery.post( 
		base_url + "friends/removeFriend",
		{ 
			frndUId: frndUId 
		},
		function(data){
			data = jQuery.trim(data);
			jQuery('#remove_loader_'+frndUId).addClass('myDispNone');
			if(data == 1){
				document.getElementById('friendBlock').innerText = "Add as a friend";
		     	jQuery("#friendBlock").text("Add as a friend");
		     	jQuery("#friendBlock").unbind('click');
		     	jQuery("#friendBlock").click(function(){
		     		addAsFriend(uId,frndUId);
		     	});
     	
			}
			else{	
				getMyPU(52);
			}
  		}
	);
}
/** View Friends **/
var cur_frndUId = '';
var cur_frndName = '';
function confirmFriendRemoval( frndUId, name ){
	cur_frndUId = frndUId;
	cur_frndName = name;
	getMyPU(51);
}



function prOpenSend(id) {
	Fr_Send_uId = id;
	getMyPU(10);
}

function sendSmtpMail(curuid){
	var mailBody = document.getElementById("mailBody_"+curuid).value;
	if(mailBody=='Write Your Message Here' || mailBody=='' ) {  
		document.getElementById("mailBody_"+curuid).value = 'Write Your Message Here';
		document.getElementById("Emptyerror_"+curuid).style.display = "block";
		return false;
	}
	jQuery('#send_msg_loader_'+curuid).removeClass('myDispNone');
	mailBody = encodeURIComponent( mailBody );
	jQuery.ajax({
		type: "POST",
		url: base_url+"profile/send/",
		data: "mailBody="+mailBody+"&curuid="+curuid+"&send=send",
		success: function(msg) {               
			if(msg==1) {  
			   jQuery('#send_msg_loader_'+curuid).addClass('myDispNone');
			   jQuery('#sendbodyContmsg_'+curuid).hide();
			   jQuery('#sendbodyContconf_'+curuid).show();
			   document.getElementById("mailBody_"+curuid).value = 'Write Your Message Here';
			   document.getElementById("Emptyerror_"+curuid).style.display = "none";
			   setTimeout( "hidePUDelay(1000)", 4000 );
			}
		} 
	}); 

	/* jQuery('#mailBody_'+curuid).keyup(function() {
		var charLength = jQuery(this).val().length;
		jQuery('#charlimit_'+curuid).html(charLength + ' of 500 characters used');
	}); */
}



