// javascript
var ERROR_INSTITUTE_NAME = -901;
var ERROR_INVALID_INSTITUTE_NAME = -902;
var ERROR_FROM_YEAR = -903;
var ERROR_TO_YEAR = -904;
var ERROR_INVALID_FROM_YEAR = -905;
var ERROR_ORGANISATION_NAME = -906;
var ERROR_INVALID_ORGANISATION_NAME = -907;
var ERROR_FAMILY_TYPE = -908;
var ERROR_FRIEND_NAME = -909;
var ERROR_OTHER_TYPE = -910;

var EMPTY_INSTITUTE_NAME = 'Please enter the name of the institute.';
var INVALID_INSTITUTE_NAME = 'Special character not allowed in institute name.';
var EMPTY_INSTITUTE_FROM_YEAR = 'Please select the years spent in the institute.';
var EMPTY_INSTITUTE_TO_YEAR = 'Please select the years spent in the institute.';
var INVALID_INSTITUTE_YEAR = 'From year must be less than to year.';

var EMPTY_ORGANISATION_NAME = 'Please enter the name of the organisation.';
var INVALID_ORGANISATION_NAME = 'Special character not allowed in organisation name.';
var EMPTY_ORGANISATION_FROM_YEAR = 'Please select the years spent in the organisation.';
var EMPTY_ORGANISATION_TO_YEAR = 'Please select the years spent in the organisation.';
var INVALID_ORGANISATION_YEAR = 'From year must be less than to year.';

var EMPTY_FAMILY_TYPE = 'Please select how are you related.';
var EMPTY_FRIEND_NAME = 'Please select friend name.';
var EMPTY_OTHER_TYPE = 'Please enter the reason how you know each other.';
var EMPTY_PERSONAL_MESSAGE = 'Please enter personal message.';


var EMPTY_SEARCH_STRING = 'Please enter keywords to be searched.';
var SEARCH_STRING_SHORT = 'Please enter minimum 3 characters.';

var DELETE_GROUP = 'Are you sure you want to delete this group?';
var div_id; 
var page_name = '';

var AjaxObject = {
    handleSuccess_addgroup:function(o){
	error_code = 0;
    },

	handleSuccess_addpopup:function(o){
	document.getElementById('connection_messages_popup').innerHTML= o.responseText ;		
    },

    handleSuccess_editpopup:function(o){
    //	document.getElementById('connection_messages_edit_popup').innerHTML= o.responseText ;		
    },

    handleSuccess_friendprofile:function(o){
	document.getElementById('inner_message').innerHTML = o.responseText;   
    },
    handleFailure_addgroup:function(o){
    },
    handleSuccess_cmsPopup:function(o){
      var messages = [];
      try {
	messages = YAHOO.lang.JSON.parse(o.responseText);
      }
      catch (x) {
	alert("JSON Parse failed!");
	return;
      }
      
      document.getElementById('username').innerHTML = messages.first_name +' '+ messages.last_name ;
      document.getElementById('connection_img').src = messages.mainpicture;   
      
      // The returned data was parsed into an array of objects.
      
      if(document.getElementById('action').value == 'edit')
      {
	//case 1
	if(messages.grew_up_together == true)
	  {
	    document.getElementById('grew_up_together').checked = messages.grew_up_together;
	  }
	//case 2
	if(messages.studied_together == true)
	  {
	    document.getElementById('studied_together').checked = messages.studied_together;
	    document.getElementById('institute_option').style.display = '';
	    document.getElementById('institute_name').value = messages.institute1;
	    document.getElementById('institute_from_Year').value = messages.inst_from1;
	    document.getElementById('institute_to_Year').value = messages.inst_to1;
	    document.getElementById('institute_option1').style.display = 'none';
	    document.getElementById('institute_option2').style.display = 'none';
       
	    //option one institute
	    if(messages.institute2!='')
	      {	
		document.getElementById('institute_option1').style.display = '';
		document.getElementById('institute_name1').value = messages.institute2;
		document.getElementById('institute_from_Year1').value = messages.inst_from2;
		document.getElementById('institute_to_Year1').value = messages.inst_to2;
	      }
	    //option two institute
	    if(messages.institute3!='')
	      {	
		document.getElementById('institute_option2').style.display = '';
		document.getElementById('institute_name2').value = messages.institute3;
		document.getElementById('institute_from_Year2').value = messages.inst_from3;
		document.getElementById('institute_to_Year2').value = messages.inst_to3;
		document.getElementById('add_another_institute').style.display='none';
	      }
            document.getElementById('institute_number').value = messages.institute_number;
	  }
	else
	  {
	    document.getElementById('institute_option1').style.display = 'none';
	    document.getElementById('institute_option2').style.display = 'none';       
	  }
      
	//case 3
	if(messages.worked_together == true)
	  {
	    document.getElementById('worked_together').checked = messages.worked_together;
	    document.getElementById('workplace_option').style.display = '';
	    document.getElementById('organisation_name').value = messages.organisation1;
	    document.getElementById('organisation_from_Year').value = messages.org_from1;
	    document.getElementById('organisation_to_Year').value = messages.org_to1;
	    document.getElementById('organisation_option1').style.display = 'none';
	    document.getElementById('organisation_option2').style.display = 'none';      
       
	    //option one organisation
	    if(messages.organisation2!='' )
	      {
		document.getElementById('organisation_option1').style.display = '';	  
		document.getElementById('organisation_name1').value = messages.organisation2;
		document.getElementById('organisation_from_Year1').value = messages.org_from2;
		document.getElementById('organisation_to_Year1').value = messages.org_to2;
	      }
	    //option two organisation
	    if(messages.organisation3!='')
	      {
		document.getElementById('organisation_option2').style.display = '';	 
		document.getElementById('organisation_name2').value = messages.organisation3;
		document.getElementById('organisation_from_Year2').value = messages.org_from3;
		document.getElementById('organisation_to_Year2').value = messages.org_to3;
		document.getElementById('add_another_organisation').style.display='none';
	      }
	    document.getElementById('organisation_number').value = messages.organisation_number;

	  }
	else
	  {
	    document.getElementById('organisation_option1').style.display = 'none';
	    document.getElementById('organisation_option2').style.display = 'none';       
	  }

	//case 4
	if(messages.in_the_same_family == true)
	  {
	    document.getElementById('in_the_same_family').checked = messages.in_the_same_family;
	    document.getElementById('samefamily').style.display = '';
	    document.getElementById('samefamily_option').value = messages.family_relation;
	    }
     
   /*
	//case 5
	if(messages.through_a_friend == true)
	  {
	    document.getElementById('through_a_friend').checked = messages.through_a_friend;
	    document.getElementById('throughfriend').style.display = '';
	    //document.getElementById('secondary_friend').value = messages.friend_name;
	  }
 */
      //case 6
	if(messages.met_online == true)
	  {
	    document.getElementById('met_online').checked = messages.met_online;
	  }  
            
	//case 7
	if(messages.through_bigAdda == true)
	  {
	    document.getElementById('through_bigAdda').checked = messages.through_bigAdda;
	  }
     
	//case 8
	if(messages.other == true)
	  {
	    document.getElementById('othercase').checked = messages.other;
	    document.getElementById('otheroption').style.display = '';
	    document.getElementById('otheroption_value').value = messages.otheroption_value;
	  }

      }
     
      if(document.getElementById('action').value == 'edit' || document.getElementById('action').value == 'blank')
      {
        document.getElementById('popup_title').innerHTML = '<h2><b>Connection Messages</b></h2>';
        document.getElementById('submit_button').innerHTML = "<a href=\"#\" onClick=\"javascript:submitCMsPopup();\" class=\"lrgblackreverse\"><b>Submit</b></a><br class=\"clear\"><br class=\"spacer0\">";
	document.getElementById('personal_msg').style.display = 'none';
	}
    
	  /*
      if(messages.secondary_contacts == 'blank')
      {
        document.getElementById('through_a_friend_check').style.display = 'none';        
      }    
    */

    },


    handleFailure_cmsPopup:function(o){
      if (!YAHOO.util.Connect.isCallInProgress(o)) {
	alert("Async call failed!");
      }
    },    

        handleSuccess_emsPopup:function(o){
      var messages = [];
      try {
	messages = YAHOO.lang.JSON.parse(o.responseText);
      }
      catch (x) {
	alert("JSON Parse failed!");
	return;
      }
      
      document.getElementById('username_edit').innerHTML = messages.first_name +' '+ messages.last_name ;
      document.getElementById('connection_img_edit').src = messages.mainpicture; 

      // The returned data was parsed into an array of objects.
      
      if(document.getElementById('action_edit').value == 'edit')
      {
	//case 1
	if(messages.grew_up_together_edit == true)
	  {
	    document.getElementById('grew_up_together_edit').checked = messages.grew_up_together_edit;
	  }
	//case 2
	if(messages.studied_together_edit == true)
	  {
	    document.getElementById('studied_together_edit').checked = messages.studied_together_edit;
	    document.getElementById('institute_option_edit').style.display = '';
	    document.getElementById('institute_name_edit').value = messages.institute1_edit;
	    document.getElementById('institute_from_Year_edit').value = messages.inst_from1_edit;
	    document.getElementById('institute_to_Year_edit').value = messages.inst_to1_edit;
	    document.getElementById('institute_option1_edit').style.display = 'none';
	    document.getElementById('institute_option2_edit').style.display = 'none';
       
	    //option one institute
	    if(messages.institute2_edit!='')
	      {	
		document.getElementById('institute_option1_edit').style.display = '';
		document.getElementById('institute_name1_edit').value = messages.institute2_edit;
		document.getElementById('institute_from_Year1_edit').value = messages.inst_from2_edit;
		document.getElementById('institute_to_Year1_edit').value = messages.inst_to2_edit;
	      }
	    //option two institute
	    if(messages.institute3_edit!='')
	      {	
		document.getElementById('institute_option2_edit').style.display = '';
		document.getElementById('institute_name2_edit').value = messages.institute3_edit;
		document.getElementById('institute_from_Year2_edit').value = messages.inst_from3_edit;
		document.getElementById('institute_to_Year2_edit').value = messages.inst_to3_edit;
		document.getElementById('add_another_institute_edit').style.display='none';
	      }
            document.getElementById('institute_number_edit').value = messages.institute_number_edit;
	  }
	else
	  {
	    document.getElementById('institute_option1_edit').style.display = 'none';
	    document.getElementById('institute_option2_edit').style.display = 'none';       
	  }
      
	//case 3
	if(messages.worked_together_edit == true)
	  {
	    document.getElementById('worked_together_edit').checked = messages.worked_together_edit;
	    document.getElementById('workplace_option_edit').style.display = '';
	    document.getElementById('organisation_name_edit').value = messages.organisation1_edit;
	    document.getElementById('organisation_from_Year_edit').value = messages.org_from1_edit;
	    document.getElementById('organisation_to_Year_edit').value = messages.org_to1_edit;
	    document.getElementById('organisation_option1_edit').style.display = 'none';
	    document.getElementById('organisation_option2_edit').style.display = 'none';      
       
	    //option one organisation
	    if(messages.organisation2_edit!='' )
	      {
		document.getElementById('organisation_option1_edit').style.display = '';	  
		document.getElementById('organisation_name1_edit').value = messages.organisation2_edit;
		document.getElementById('organisation_from_Year1_edit').value = messages.org_from2_edit;
		document.getElementById('organisation_to_Year1_edit').value = messages.org_to2_edit;
	      }
	    //option two organisation
	    if(messages.organisation3_edit!='')
	      {
		document.getElementById('organisation_option2_edit').style.display = '';	 
		document.getElementById('organisation_name2_edit').value = messages.organisation3_edit;
		document.getElementById('organisation_from_Year2_edit').value = messages.org_from3_edit;
		document.getElementById('organisation_to_Year2_edit').value = messages.org_to3_edit;
		document.getElementById('add_another_organisation_edit').style.display='none';
	      }
          document.getElementById('organisation_number_edit').value = messages.organisation_number_edit;

	  }
	else
	  {
	    document.getElementById('organisation_option1_edit').style.display = 'none';
	    document.getElementById('organisation_option2_edit').style.display = 'none';       
	  }

	//case 4
	if(messages.in_the_same_family_edit == true)
	  {
	    document.getElementById('in_the_same_family_edit').checked = messages.in_the_same_family_edit;
	    document.getElementById('samefamily_edit').style.display = '';
	    document.getElementById('samefamily_option_edit').value = messages.family_relation_edit;
	    }
     
   /*
	//case 5
	if(messages.through_a_friend == true)
	  {
	    document.getElementById('through_a_friend').checked = messages.through_a_friend;
	    document.getElementById('throughfriend').style.display = '';
	    //document.getElementById('secondary_friend').value = messages.friend_name;
	  }
 */
      //case 6
	if(messages.met_online_edit == true)
	  {
	    document.getElementById('met_online_edit').checked = messages.met_online_edit;
	  }  
            
	//case 7
	if(messages.through_bigAdda_edit == true)
	  {
	    document.getElementById('through_bigAdda_edit').checked = messages.through_bigAdda_edit;
	  }
     
	//case 8
	if(messages.other_edit == true)
	  {
	    document.getElementById('othercase_edit').checked = messages.other_edit;
	    document.getElementById('otheroption_edit').style.display = '';
	    document.getElementById('otheroption_value_edit').value = messages.otheroption_value_edit;
	  }

      }
     
      if(document.getElementById('action_edit').value == 'edit' || document.getElementById('action_edit').value == 'blank')
      {
	//        document.getElementById('popup_title').innerHTML = '<h2><b>Connection Messages</b></h2>';
        //document.getElementById('submit_button').innerHTML = "<a href=\"#\" onClick=\"javascript:submitCMsPopup();\" class=\"lrgblackreverse\"><b>Submit</b></a><br class=\"clear\"><br class=\"spacer0\">";
	//document.getElementById('personal_msg').style.display = 'none';
	}
    
	  /*
      if(messages.secondary_contacts == 'blank')
      {
        document.getElementById('through_a_friend_check').style.display = 'none';        
      }    
    */

    },
    handleFailure_emsPopup:function(o){
      if (!YAHOO.util.Connect.isCallInProgress(o)) {
	alert("Async call failed!");
      }
    },    











    handleSuccess_removefriend:function(o){
      document.getElementById(div_id).innerHTML = o.responseText;
    },
    handleFailure_removefriend:function(o){
    },
    handleSuccess_friendacceptrequestmultiple:function(o){
       document.getElementById("friend_request_multiple_body").innerHTML = o.responseText;   
   },
    handleFailure_friendacceptrequestmultiple:function(o){
   },
    handleSuccess_friendrejectrequestmultiple:function(o){
       document.getElementById("friend_request_multiple_body").innerHTML = o.responseText;
   },
    handleFailure_friendrejectrequestmultiple:function(o){
   },
   handleSuccess_paginationfr:function(o){
	
		document.getElementById(div_id).innerHTML = o.responseText;    		

   },
   handleFailure_paginationfr:function(o){
    // Failure handler                                                                                                                                   
    },
   handleSuccess_addgroup:function(o){
	document.getElementById("group_block").innerHTML = o.responseText;    		
	window.location = system_base_url+'/friends/_managegroup/'+document.getElementById("group_name_to_add").value;
	
   },
   handleFailure_addgroup:function(o){
    // Failure handler                                                                                                                                   

   },

   handleSuccess_friendrequestmultiple:function(o){
      document.getElementById("friends_on_bigadda").innerHTML = o.responseText;    		
   },
   handleFailure_friendrequestmultiple:function(o){
    // Failure handler                                                                                                                                   
    },
   handleSuccess_bigadda_invite:function(o){
     //Success handler
   },
   handleFailure_bigadda_invite:function(o){
    // Failure handler                                                                                                                                   

    } ,
   handleSuccess_sendinvite:function(o){
      document.getElementById("friends_on_bigadda").innerHTML = o.responseText;  
   },
   handleFailure_sendinvite:function(o){
    // Failure handler                                                                                                                                   

   }, 
   handleSuccess_editrelation:function(o){
   
	if(page_name == '_showmyfriend')
	{
	    document.getElementById("friend_default_body").innerHTML = o.responseText;    
	}
	else if(page_name == 'pendingrequestreceived')
        {
	 
	    document.getElementById("friend_request_multiple_body").innerHTML = o.responseText;    		  
	}
        else if(page_name == 'friendrequestconfirmhome')
	{
	    var data = o.responseText;
	    window.location.href = system_base_url+'home/_edit_relation_confirm/'+data+'/';
	 
	}
        else if(page_name == 'friendrequestconfirmalert')
	{
	    var data = o.responseText;
            var pag = document.getElementById("show_from_pag").value;
	    window.location.href = system_base_url+'alerts/_edit_relation_confirm/'+data+'/'+pag;
	 
	}
	else if(page_name == 'showgroups')
        {
	   document.getElementById("friends_group").innerHTML = o.responseText;    		  
	
	}
	else if(page_name == 'showmutualfriend')
	{
	   document.getElementById("friend_mutual_friends_body").innerHTML = o.responseText;    		  
	}
	else if(page_name == '_showsearchfriends')
	{
	   document.getElementById("friend_searchresult_body").innerHTML = o.responseText;    		  
	
	} 


	} , 
   handleFailure_editrelation:function(o){
    // Failure handler
    },
   handleSuccess_confirm:function(o){  
	if(page_name == '_showmyfriend')
	{
	    document.getElementById("friend_default_body").innerHTML = o.responseText;    
	}
	else if(page_name == 'showgroups')
	{
	    document.getElementById("friends_group").innerHTML = o.responseText;    
	}
	else if(page_name == '_showsearchfriends')
	{
	    document.getElementById("friend_searchresult_body").innerHTML = o.responseText;    
	}

   },
   handleFailure_confirm:function(o){
    // Failure handler
   },
   handleSuccess_getsecondaryfriends:function(o){  
     //Success handle
     document.getElementById("secondary_friend").innerHTML = o.responseText;
   },
   handleFailure_getsecondaryfriends:function(o){
    // Failure handler
    },
  handleSuccess_addtogroups:function(o){  
     //Success handle
     document.getElementById("group_block").innerHTML = o.responseText;
	  document.getElementById("update_group_block").style.display = '';
   },
   handleFailure_addtogroups:function(o){
    // Failure handler
    },
  handleSuccess_removegroup:function(o){  
     //Success handle
	if(o.responseText == 'success')
	{
	  window.location = system_base_url+'ajax/friends/';
	}
   },
   handleFailure_removegroup:function(o){
    // Failure handler
    },
  handleSuccess_friendsendrequestmultiple:function(o){  
    //Success handle
    document.getElementById("school_college_workplace").innerHTML = o.responseText;
   },
   handleFailure_friendsendrequestmultiple:function(o){
    // Failure handler
   },
  handleSuccess_inviteresend:function(o){  
    //Success handle
    document.getElementById("pending_invite_body").innerHTML = o.responseText;
  },
  handleFailure_inviteresend:function(o){
    // Failure handler
  }
      
    
};


/*
 * Define the callback object for success and failure
 * handlers as well as object scope.
 */
var callback_addPopup =
{  	
    success:AjaxObject.handleSuccess_addpopup,
    failure:AjaxObject.handleFailure_addpopup,
    scope: AjaxObject
};

var callback_editPopup =
{  	
    success:AjaxObject.handleSuccess_editpopup,
    failure:AjaxObject.handleFailure_editpopup,
    scope: AjaxObject
};

var callback_addgroup =
{  	
    success:AjaxObject.handleSuccess_addgroup,
    failure:AjaxObject.handleFailure_addgroup,
    scope: AjaxObject
};

var callback_friendprofile =
{
    success:AjaxObject.handleSuccess_friendprofile,
    failure:AjaxObject.handleFailure_friendprofile,
    scope: AjaxObject
};

var callback_friendacceptrequestmultiple =
{
    success:AjaxObject.handleSuccess_friendacceptrequestmultiple,
    failure:AjaxObject.handleFailure_friendacceptrequestmultiple,
    scope: AjaxObject
};

var callback_friendrejectrequestmultiple =
{
    success:AjaxObject.handleSuccess_friendrejectrequestmultiple,
    failure:AjaxObject.handleFailure_friendrejectrequestmultiple,
    scope: AjaxObject
};


var callback_removefriend =
{
    success:AjaxObject.handleSuccess_removefriend,
    failure:AjaxObject.handleFailure_removefriend,
    scope: AjaxObject
};

var callback_paginationfr =
{
        
    success:AjaxObject.handleSuccess_paginationfr,
    failure:AjaxObject.handleFailure_paginationfr,
    scope: AjaxObject
    
};

var callback_cmsPopup =
{
    success:AjaxObject.handleSuccess_cmsPopup,
    failure:AjaxObject.handleFailure_cmsPopup,
    scope: AjaxObject
};

var callback_emsPopup =
{
    success:AjaxObject.handleSuccess_emsPopup,
    failure:AjaxObject.handleFailure_emsPopup,
    scope: AjaxObject
};

var callback_friendrequestmultiple = 
{

  success:AjaxObject.handleSuccess_friendrequestmultiple,
  failure:AjaxObject.handleFailure_friendrequestmultiple,
  scope: AjaxObject

};


var callback_bigadda_invite = 
{

  success:AjaxObject.handleSuccess_bigadda_invite,
  failure:AjaxObject.handleFailure_bigadda_invite,
  scope: AjaxObject

};

var callback_sendinvite = 
{
  success:AjaxObject.handleSuccess_sendinvite,
  failure:AjaxObject.handleFailure_sendinvite,
  scope: AjaxObject
};

var callback_editrelation = 
{
  success:AjaxObject.handleSuccess_editrelation,
  failure:AjaxObject.handleFailure_editrelation,
  scope: AjaxObject
};

var callback_confirm = 
{
  success:AjaxObject.handleSuccess_confirm,
  failure:AjaxObject.handleFailure_confirm,
  scope: AjaxObject
};

var callback_getsecondaryfriends = 
{
  success:AjaxObject.handleSuccess_getsecondaryfriends,
  failure:AjaxObject.handleFailure_getsecondaryfriends,
  scope: AjaxObject
};

var callback_addtogroups = 
{
  success:AjaxObject.handleSuccess_addtogroups,
  failure:AjaxObject.handleFailure_addtogroups,
  scope: AjaxObject
};


var callback_removegroup = 
{
  success:AjaxObject.handleSuccess_removegroup,
  failure:AjaxObject.handleFailure_removegroup,
  scope: AjaxObject
};

var callback_friendsendrequestmultiple = 
{
  success:AjaxObject.handleSuccess_friendsendrequestmultiple,
  failure:AjaxObject.handleFailure_friendsendrequestmultiple,
  scope: AjaxObject
};

var callback_inviteresend = 
{
  success:AjaxObject.handleSuccess_inviteresend,
  failure:AjaxObject.handleFailure_inviteresend,
  scope: AjaxObject
};



function validate_submit_search_form()
{
   
	var frm = document.getElementById('friend_search');
	if(frm.search_string.value == '')
	{
	    alert(EMPTY_SEARCH_STRING);
	}
	else if(frm.search_string.value.length < 3 )
	{
	  alert(SEARCH_STRING_SHORT);
	}
	else
	{
	   
		var search_string = document.getElementById("search_string").value;
		frm.method = 'post'; 
   	frm.action = system_base_url+'friends/_searchfriends';
	
   	frm.submit();
	}


}



function toggle_fr(obj)
{   
    var el = document.getElementById(obj);
    el.style.display = (el.style.display != 'none' ? 'none' : '' );
}



function addNewGroup()
{

  var add_group_inline =  document.getElementById('show_add_group');
  var create_group_link =  document.getElementById('create_group_link');	
  var group_name = document.getElementById('group_name_to_add').value;
  var filter  = /^[a-zA-Z][A-Za-z0-9_ \.]+$/;
	
  if(group_name == 'Type group name' ||  group_name=='' || group_name.length == 0)
    {
       alert('Please Enter Group Name');
      return false;
 	    
    }
  else if(!filter.test(group_name))
  {
    alert('Please Enter Valid Group Name');
    return false;
 	
  }
  else
    {
      var postData = '&groupname='+group_name;
      YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_creategroup/',callback_addgroup,postData);
       var url  = system_base_url+'ajax/friends/_creategroup/';
      create_group_link.style.display = '';	
      add_group_inline.style.display = 'none';
      if(env_value == 'Online')
	{
	    pageTracker._trackPageview(url);
	}
    
      return true;    
    }
}


function submitCMsPopup()
{
    document.getElementById('send').value = "Send Request";
    var friend_id = document.getElementById('friend_id').value;
    var	pagename = document.getElementById('pagename').value;	
    
    var group_name = document.getElementById('group_name').value;
    
    //case 1  
    if(document.getElementById('grew_up_together').checked == true)
    {		
     var grew_up_together =  document.getElementById('grew_up_together').value;
    }
    else
    {
	var grew_up_together = '';
    }
    //case 2
    if(document.getElementById('studied_together').checked == true)
    {						
       var studied_together = document.getElementById('studied_together').value;  
       
       //validate institute
       var num_of_institute = document.getElementById('institute_number').value;
       var error_code = validateInstitute(num_of_institute);
       if(error_code < 0)
	   {
	       if(error_code == ERROR_INSTITUTE_NAME)
		   {
		       alert(EMPTY_INSTITUTE_NAME);
		   }
	       else if(error_code == ERROR_INVALID_INSTITUTE_NAME)
		   {
		       alert(INVALID_INSTITUTE_NAME);
		   }
	       else if(error_code == ERROR_FROM_YEAR)
		   {
		       alert(EMPTY_INSTITUTE_FROM_YEAR);
		   }
	       else if(error_code == ERROR_TO_YEAR)
		   {
		       alert(EMPTY_INSTITUTE_TO_YEAR);
		   }
	       else if(error_code == ERROR_INVALID_FROM_YEAR)
		   {
		       alert(INVALID_INSTITUTE_YEAR);
		   }
	       return false;
	   }
    }
    else
    {
       var studied_together = '';
    }

    var institute_name      = document.getElementById('institute_name').value;
    var institute_year_from = document.getElementById('institute_from_Year').value;
    var institute_year_to   = document.getElementById('institute_to_Year').value;
    //for institute optional values...
    var institute_name1      = '';
    var institute_year_from1 = '';
    var institute_year_to1   = ''; 
    var institute_name2      = '';
    var institute_year_from2 = '';
    var institute_year_to2   = '';    
    //alert("hi "+document.getElementById('institute_number').value)
    if(document.getElementById('institute_number').value==1)
    {
       institute_name1      = document.getElementById('institute_name1').value;
       institute_year_from1 = document.getElementById('institute_from_Year1').value;
       institute_year_to1   = document.getElementById('institute_to_Year1').value;        
    }
    if(document.getElementById('institute_number').value==2)
    {
       institute_name1      = document.getElementById('institute_name1').value;
       institute_year_from1 = document.getElementById('institute_from_Year1').value;
       institute_year_to1   = document.getElementById('institute_to_Year1').value;
       institute_name2      = document.getElementById('institute_name2').value;
       institute_year_from2 = document.getElementById('institute_from_Year2').value;
       institute_year_to2   = document.getElementById('institute_to_Year2').value; 
    }   
     
   //case 3   
   if(document.getElementById('worked_together').checked == true)
    {
 	var organisation = document.getElementById('worked_together').value;        
	//validate organisation
       var num_of_organisation = document.getElementById('organisation_number').value;
       var error_code = validateWorkTogether(num_of_organisation);
       if(error_code < 0)
	   {
	       if(error_code == ERROR_ORGANISATION_NAME)
		   {
		       alert(EMPTY_ORGANISATION_NAME);
		   }
	       else if(error_code == ERROR_INVALID_ORGANISATION_NAME)
		   {
		       alert(INVALID_ORGANISATION_NAME);
		   }
	       else if(error_code == ERROR_FROM_YEAR)
		   {
		       alert(EMPTY_ORGANISATION_FROM_YEAR);
		   }
	       else if(error_code == ERROR_TO_YEAR)
		   {
		       alert(EMPTY_ORGANISATION_TO_YEAR);
		   }
	       else if(error_code == ERROR_INVALID_FROM_YEAR)
		   {
		       alert(INVALID_ORGANISATION_YEAR);
		   }
	       return false;
	   }
    }
    else
    {
        var organisation = '';
    }
   var organisation_name = document.getElementById('organisation_name').value;
   var organisation_year_from = document.getElementById('organisation_from_Year').value;
   var organisation_year_to = document.getElementById('organisation_to_Year').value; 
   //for organisation optional values...
    var organisation_name1      = '';
    var organisation_year_from1 = '';
    var organisation_year_to1   = ''; 
    var organisation_name2      = '';
    var organisation_year_from2 = '';
    var organisation_year_to2   = '';
 
   if(document.getElementById('organisation_number').value==1)
    {  
      organisation_name1      = document.getElementById('organisation_name1').value;
      organisation_year_from1 = document.getElementById('organisation_from_Year1').value;
      organisation_year_to1   = document.getElementById('organisation_to_Year1').value;
    }
   if(document.getElementById('organisation_number').value==2)
    {
      organisation_name1      = document.getElementById('organisation_name1').value;
      organisation_year_from1 = document.getElementById('organisation_from_Year1').value;
      organisation_year_to1   = document.getElementById('organisation_to_Year1').value;
      organisation_name2      = document.getElementById('organisation_name2').value;
      organisation_year_from2 = document.getElementById('organisation_from_Year2').value;
      organisation_year_to2   = document.getElementById('organisation_to_Year2').value;
    }

  //case 4
  if(document.getElementById('in_the_same_family').checked == true)
    {
 	var in_the_same_family = document.getElementById('in_the_same_family').value;	
	var error_code = validateFamily();
        if(error_code < 0)
	   {
	       if(error_code == ERROR_FAMILY_TYPE)
		   {
		       alert(EMPTY_FAMILY_TYPE);
		   }
	       return false;
	   }

    }
    else
    {
        var in_the_same_family = '';
    }		   

    
    var samefamily_option = document.getElementById('samefamily_option').value;

	/*
    //case 5
   if(document.getElementById('through_a_friend').checked == true)
    {
      var through_a_friend = document.getElementById('through_a_friend').value;
      var secondary_friend = document.getElementById('secondary_friend').value;     
      var error_code = validateFriend();
        if(error_code < 0)
	   {
	       if(error_code == ERROR_FRIEND_NAME)
		   {
		       alert(EMPTY_FRIEND_NAME);
		   }
	       return false;
	   }
	
	
    }
    else
    {
        var through_a_friend = '';
    }	
	*/	   
   //case 6
    if(document.getElementById('met_online').checked == true)
    {
 	var met_online = document.getElementById('met_online').value;
    }
    else
    {
        var met_online = '';
    }		   
    //case 7
    if(document.getElementById('through_bigAdda').checked == true)
      {
 	var through_bigAdda = document.getElementById('through_bigAdda').value;
    }
    else
    {
        var through_bigAdda = '';
    }		   
    
    //case 8
    if(document.getElementById('othercase').checked == true)
    {
 	var othercase = document.getElementById('othercase').value;	
	var otheroption_value = document.getElementById('otheroption_value').value;
	var error_code = validateOtherType(otheroption_value);

        if(error_code < 0)
	   {
	       if(error_code == ERROR_OTHER_TYPE)
		   {
		       alert(EMPTY_OTHER_TYPE);
		   }
	       return false;
	   }
    }
    else
    {
        var othercase = '';
    }		   

    var otheroption_value = document.getElementById('otheroption_value').value;
    var msg_style = document.getElementById('personal_msg').style.display;
    var personal_message = document.getElementById('personal_message').value;
    
    var send = document.getElementById('send').value;   

    var postData = '&friend_id='+friend_id+'&pagename='+pagename+'&grew_up_together='+grew_up_together+'&studied_together='+studied_together+'&institute_name='+institute_name+'&institute_year_from='+institute_year_from+'&institute_year_to='+institute_year_to+'&institute_name1='+institute_name1+'&institute_year_from1='+institute_year_from1+'&institute_year_to1='+institute_year_to1+'&institute_name2='+institute_name2+'&institute_year_from2='+institute_year_from2+'&institute_year_to2='+institute_year_to2+'&organisation='+organisation+'&organisation_name='+organisation_name+'&organisation_year_from='+organisation_year_from+'&organisation_year_to='+organisation_year_to+'&organisation_name1='+organisation_name1+'&organisation_year_from1='+organisation_year_from1+'&organisation_year_to1='+organisation_year_to1+'&organisation_name2='+organisation_name2+'&organisation_year_from2='+organisation_year_from2+'&organisation_year_to2='+organisation_year_to2+'&in_the_same_family='+in_the_same_family+'&samefamily_option='+samefamily_option+'&met_online='+met_online+'&through_bigAdda='+through_bigAdda+'&othercase='+othercase+'&otheroption_value='+otheroption_value+'&personal_message='+personal_message+'&send='+send+'&group_name='+group_name;   

   page_name = pagename;
   if(document.getElementById('action').value == 'edit' || document.getElementById('action').value == 'blank')
     {
       YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_editrelation/',callback_editrelation,postData);
       var url =  system_base_url+'ajax/friends/_editrelation/';
       hideCMsPopup();
     }
   else
     {
       YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_addrequest/',callback_friendprofile,postData);
       var url =  system_base_url+'ajax/friends/_addrequest/';
     }
   
   if(env_value == 'Online')
	{
	    pageTracker._trackPageview(url);
	}
    


}


function submitEMsPopup()
{
  
    document.getElementById('send_edit').value = "Send Request";
    var action = document.getElementById('action_edit').value;
    var friend_id = document.getElementById('friend_id_edit').value;
    var	pagename = document.getElementById('pagename_edit').value;	
    
    var group_name = document.getElementById('group_name_edit').value;
    
    //case 1  
    if(document.getElementById('grew_up_together_edit').checked == true)
    {		
     var grew_up_together =  document.getElementById('grew_up_together_edit').value;
    }
    else
    {
	var grew_up_together = '';
    }
    //case 2
    if(document.getElementById('studied_together_edit').checked == true)
    {						
       var studied_together = document.getElementById('studied_together_edit').value;  
       
       //validate institute
       var num_of_institute = document.getElementById('institute_number_edit').value;
       var error_code = validateEditInstitute(num_of_institute);
       if(error_code < 0)
	   {
	       if(error_code == ERROR_INSTITUTE_NAME)
		   {
		       alert(EMPTY_INSTITUTE_NAME);
		   }
	       else if(error_code == ERROR_INVALID_INSTITUTE_NAME)
		   {
		       alert(INVALID_INSTITUTE_NAME);
		   }
	       else if(error_code == ERROR_FROM_YEAR)
		   {
		       alert(EMPTY_INSTITUTE_FROM_YEAR);
		   }
	       else if(error_code == ERROR_TO_YEAR)
		   {
		       alert(EMPTY_INSTITUTE_TO_YEAR);
		   }
	       else if(error_code == ERROR_INVALID_FROM_YEAR)
		   {
		       alert(INVALID_INSTITUTE_YEAR);
		   }
	       return false;
	   }
    }
    else
    {
       var studied_together = '';
    }

    var institute_name      = document.getElementById('institute_name_edit').value;
    var institute_year_from = document.getElementById('institute_from_Year_edit').value;
    var institute_year_to   = document.getElementById('institute_to_Year_edit').value;
    //for institute optional values...
    var institute_name1      = '';
    var institute_year_from1 = '';
    var institute_year_to1   = ''; 
    var institute_name2      = '';
    var institute_year_from2 = '';
    var institute_year_to2   = '';    
    //alert("hi "+document.getElementById('institute_number').value)
    if(document.getElementById('institute_number_edit').value==1)
    {
       institute_name1      = document.getElementById('institute_name1_edit').value;
       institute_year_from1 = document.getElementById('institute_from_Year1_edit').value;
       institute_year_to1   = document.getElementById('institute_to_Year1_edit').value;        
    }
    if(document.getElementById('institute_number_edit').value==2)
    {
       institute_name1      = document.getElementById('institute_name1_edit').value;
       institute_year_from1 = document.getElementById('institute_from_Year1_edit').value;
       institute_year_to1   = document.getElementById('institute_to_Year1_edit').value;
       institute_name2      = document.getElementById('institute_name2_edit').value;
       institute_year_from2 = document.getElementById('institute_from_Year2_edit').value;
       institute_year_to2   = document.getElementById('institute_to_Year2_edit').value; 
    }   
     
   //case 3   
   if(document.getElementById('worked_together_edit').checked == true)
    {
 	var organisation = document.getElementById('worked_together_edit').value;        
	//validate organisation
       var num_of_organisation = document.getElementById('organisation_number_edit').value;
       var error_code = validateEditWorkTogether(num_of_organisation);
       if(error_code < 0)
	   {
	       if(error_code == ERROR_ORGANISATION_NAME)
		   {
		       alert(EMPTY_ORGANISATION_NAME);
		   }
	       else if(error_code == ERROR_INVALID_ORGANISATION_NAME)
		   {
		       alert(INVALID_ORGANISATION_NAME);
		   }
	       else if(error_code == ERROR_FROM_YEAR)
		   {
		       alert(EMPTY_ORGANISATION_FROM_YEAR);
		   }
	       else if(error_code == ERROR_TO_YEAR)
		   {
		       alert(EMPTY_ORGANISATION_TO_YEAR);
		   }
	       else if(error_code == ERROR_INVALID_FROM_YEAR)
		   {
		       alert(INVALID_ORGANISATION_YEAR);
		   }
	       return false;
	   }
    }
    else
    {
        var organisation = '';
    }
   var organisation_name = document.getElementById('organisation_name_edit').value;
   var organisation_year_from = document.getElementById('organisation_from_Year_edit').value;
   var organisation_year_to = document.getElementById('organisation_to_Year_edit').value; 
   //for organisation optional values...
    var organisation_name1      = '';
    var organisation_year_from1 = '';
    var organisation_year_to1   = ''; 
    var organisation_name2      = '';
    var organisation_year_from2 = '';
    var organisation_year_to2   = '';
 
   if(document.getElementById('organisation_number_edit').value==1)
    {  
      organisation_name1      = document.getElementById('organisation_name1_edit').value;
      organisation_year_from1 = document.getElementById('organisation_from_Year1_edit').value;
      organisation_year_to1   = document.getElementById('organisation_to_Year1_edit').value;
    }
   if(document.getElementById('organisation_number_edit').value==2)
    {
      organisation_name1      = document.getElementById('organisation_name1_edit').value;
      organisation_year_from1 = document.getElementById('organisation_from_Year1_edit').value;
      organisation_year_to1   = document.getElementById('organisation_to_Year1_edit').value;
      organisation_name2      = document.getElementById('organisation_name2_edit').value;
      organisation_year_from2 = document.getElementById('organisation_from_Year2_edit').value;
      organisation_year_to2   = document.getElementById('organisation_to_Year2_edit').value;
    }

  //case 4
  if(document.getElementById('in_the_same_family_edit').checked == true)
    {
 	var in_the_same_family = document.getElementById('in_the_same_family_edit').value;	
	var error_code = validateEditFamily();
        if(error_code < 0)
	   {
	       if(error_code == ERROR_FAMILY_TYPE)
		   {
		       alert(EMPTY_FAMILY_TYPE);
		   }
	       return false;
	   }

    }
    else
    {
        var in_the_same_family = '';
    }		   

    
    var samefamily_option = document.getElementById('samefamily_option_edit').value;

	/*
    //case 5
   if(document.getElementById('through_a_friend').checked == true)
    {
      var through_a_friend = document.getElementById('through_a_friend').value;
      var secondary_friend = document.getElementById('secondary_friend').value;     
      var error_code = validateFriend();
        if(error_code < 0)
	   {
	       if(error_code == ERROR_FRIEND_NAME)
		   {
		       alert(EMPTY_FRIEND_NAME);
		   }
	       return false;
	   }
	
	
    }
    else
    {
        var through_a_friend = '';
    }	
	*/	   
   //case 6
    if(document.getElementById('met_online_edit').checked == true)
    {
 	var met_online = document.getElementById('met_online_edit').value;
    }
    else
    {
        var met_online = '';
    }		   
    //case 7
    if(document.getElementById('through_bigAdda_edit').checked == true)
      {
 	var through_bigAdda = document.getElementById('through_bigAdda_edit').value;
    }
    else
    {
        var through_bigAdda = '';
    }		   
    
    //case 8
    if(document.getElementById('othercase_edit').checked == true)
      {
 	var othercase = document.getElementById('othercase_edit').value;	
	var otheroption_value = document.getElementById('otheroption_value_edit').value;
	var error_code = validateOtherType(otheroption_value);

        if(error_code < 0)
	   {
	       if(error_code == ERROR_OTHER_TYPE)
		   {
		       alert(EMPTY_OTHER_TYPE);
		   }
	       return false;
	   }
    }
    else
    {
        var othercase = '';
    }		   

    var otheroption_value = document.getElementById('otheroption_value_edit').value;
    //var msg_style = document.getElementById('personal_msg_edit').style.display;
    //var personal_message = document.getElementById('personal_message').value;
    
    var send = document.getElementById('send_edit').value;   
    
    var postData = '&friend_id='+friend_id+'&pagename='+pagename+'&grew_up_together='+grew_up_together+'&studied_together='+studied_together+'&institute_name='+institute_name+'&institute_year_from='+institute_year_from+'&institute_year_to='+institute_year_to+'&institute_name1='+institute_name1+'&institute_year_from1='+institute_year_from1+'&institute_year_to1='+institute_year_to1+'&institute_name2='+institute_name2+'&institute_year_from2='+institute_year_from2+'&institute_year_to2='+institute_year_to2+'&organisation='+organisation+'&organisation_name='+organisation_name+'&organisation_year_from='+organisation_year_from+'&organisation_year_to='+organisation_year_to+'&organisation_name1='+organisation_name1+'&organisation_year_from1='+organisation_year_from1+'&organisation_year_to1='+organisation_year_to1+'&organisation_name2='+organisation_name2+'&organisation_year_from2='+organisation_year_from2+'&organisation_year_to2='+organisation_year_to2+'&in_the_same_family='+in_the_same_family+'&samefamily_option='+samefamily_option+'&met_online='+met_online+'&through_bigAdda='+through_bigAdda+'&othercase='+othercase+'&otheroption_value='+otheroption_value+'&send='+send+'&group_name='+group_name;
    
    page_name = pagename;

    if((document.getElementById('action_edit').value == 'edit' || document.getElementById('action_edit').value == 'blank') && (pagename == 'friendrequestconfirmhome' || pagename == 'friendrequestconfirmalert'))
      {   
       YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/alerts/_editrelation/',callback_editrelation,postData);
       var url = system_base_url+'ajax/alerts/_editrelation/';
       hideEMsPopup();
     }
    else if(document.getElementById('action_edit').value == 'edit' || document.getElementById('action_edit').value == 'blank')
     { 
       YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_editrelation/',callback_editrelation,postData);
       var url = system_base_url+'ajax/friends/_editrelation/';
       hideEMsPopup();
     }
     else
     {
       YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_addrequest/',callback_friendprofile,postData);
       var url = system_base_url+'ajax/friends/_addrequest/';
     }


    if(env_value == 'Online')
	{
	    pageTracker._trackPageview(url);
	}
    

}




//! Method to remove a friend 
/*!
 * \ method get profile id from popup 
 * \ it call remove function with AJAX 
 */
function removeFriend(divid)
{

  var friend_id = document.getElementById('remove_friend_id').value; 
  var divid = document.getElementById('div_id').value; 	
  var group_name = document.getElementById('group_name').value; 	
  var postData = '&friend_id='+friend_id+'&divid='+divid+'&group_name='+group_name;
  div_id = divid;
  YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_remove/',callback_removefriend,postData);
  var url = system_base_url+'ajax/friends/_remove/';
  if(env_value == 'Online')
	{
	    pageTracker._trackPageview(url);
	}
    
}



//! Method to activate group top actions
/*!
 * \param action viz. scribble,sendmail,manage,delete 
 * \ change css class of action 
 * \return true on success 
 */ 
function groupTopActive(action)
{
    var action_array = new Array();
   // action_array[0] = "scribble";
   // action_array[1] = "sendmail";
    action_array[0] = "manage";
    action_array[1] = "delete";
    for(var i=0; i<action_array.length;i++)
	{
	    var inactive_div = document.getElementById('group_top_'+action_array[i]);
            inactive_div.className="inactive";
	}
   
    var active_div =  document.getElementById('group_top_'+action);
    //active_div.innerHTML="<b>"+action+"</b>";
    active_div.className="active";
   
    return true;
}


//! Function to check all / uncheck all checkbox
function checkAll_fr(frm_id)
{
 
 var frm = document.getElementById(frm_id);
 var len = frm.elements.length;
 var i=0;
 for(i=0; i<len; i++)
  {
    if(frm.elements[i].name=='check_box') 
      {        
        frm.elements[i].checked = true;
      }
  }
}

function uncheckAll_fr(frm_id)
{
 var frm = document.getElementById(frm_id);
 var len = frm.elements.length;
 var i=0;
 for(i=0; i<len; i++)
  {
    if(frm.elements[i].name=='check_box') 
      {        
        frm.elements[i].checked = false;
      }
  }
}




//! Function to check all / uncheck all checkbox
function checkAllmulti_fr(frm_id, checkboxname)
{
 var frm = document.getElementById(frm_id);
 var len = frm.elements.length;
 var i=0;
 for(i=0; i<len; i++)
  {
	
    if(frm.elements[i].name == checkboxname) 
      {       
 
        frm.elements[i].checked = true;
      }
  }
}

function uncheckAllmulti_fr(frm_id, checkboxname)
{
 var frm = document.getElementById(frm_id);
 var len = frm.elements.length;
 var i=0;
 for(i=0; i<len; i++)
  {
    if(frm.elements[i].name == checkboxname) 
      {        
        frm.elements[i].checked = false;
      }
  }
}



//! Method to check action for multiple check boxes 
/*!
 * \ method get profile ids from check box
 * \ check actions viz. confirm and ignore
 * \ as per actions it call function with AJAX 
 */ 
function check_send_friend_request_fr()
{
   //var fields = document.frm_request_received.check_box;
   var frm = document.getElementById('search_form');
   var len = frm.elements.length;
   var i=0;
   var str=""
   for(i=0; i<len; i++)
   {
     if(frm.elements[i].checked)
     { 
       if(str=="")
      {  
        str =frm.elements[i].value;
      }
      else
      {
       str +=","+frm.elements[i].value;
      }
     }

   }

   if(str=="")
   alert("select at least one");
   else
   {
     var pagename = 'school_college';	
     var postData = '&friend_ids='+str+'&pagename='+pagename;      
     YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_sendrequestmultiple/',callback_friendsendrequestmultiple,postData);
     if(env_value == 'Online')
	{
	    var url  = system_base_url+'ajax/friends/_sendrequestmultiple/';
	    pageTracker._trackPageview(url);
	}
    
  }	
}



//! Method to check action for multiple check boxes 
/*!
 * \ method get profile ids from check box
 * \ check actions viz. confirm and ignore
 * \ as per actions it call function with AJAX 
 */ 
function checkAction_fr(selection)
{
  var action = document.getElementById(selection).value;
  if(action!="")
  {
    //var fields = document.frm_request_received.check_box;
    var frm = document.getElementById('frm_request_received_pending');
    var len = frm.elements.length;
    var i=0;
    var str=""
    for(i=0; i<len; i++)
    {
      if(frm.elements[i].name=='check_box') 
      {  
        if(frm.elements[i].checked)
	  { 
	    if(str=="")
	    {  
	      str =frm.elements[i].value;
	    }
	    else
	    {
	      str +=","+frm.elements[i].value;
	    }
	}
      }
    }
   if(str=="")
   alert("select at least one");
   else
   {
     var postData = '&friend_ids='+str;      
     if(action=='confirm')
       {
         YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_acceptrequestmultiple/',callback_friendacceptrequestmultiple,postData);
	 var url  = system_base_url+'ajax/friends/_acceptrequestmultiple/';
       }
     else if(action=='ignore')
       {
         YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_rejectrequestmultiple/',callback_friendrejectrequestmultiple,postData);
	 var url  = system_base_url+'ajax/friends/_rejectrequestmultiple/';
       }

     if(env_value == 'Online')
	{
	    pageTracker._trackPageview(url);
	}
    

    }
  }
}




//! Method to check action for multiple check boxes  
/*!
 * \ method get profile ids from check box
 * \ as per actions it call function with AJAX 
 */ 
function checkActionAddFriend_fr(mode)
{
    
    var frm = document.getElementById('frm_on_bigadda');
    var len = frm.elements.length;
    var i=0;
    var str=""
    for(i=0; i<len; i++)
    {
      if(frm.elements[i].name=='check_box') 
      {  
        if(frm.elements[i].checked)
	  { 
	    if(str=="")
	    {  
	      str =frm.elements[i].value;
	    }
	    else
	    {
	      str +=","+frm.elements[i].value;
	    }
	}
      }
    }

   if(str=="")
     {
       alert("select at least one");
     }
   else if(mode == 'quick')
     {
       var invite_email = document.getElementById('invite_email_ids').value;
       var postData = '&friend_ids='+str+'&invite=quick'+'&invite_email='+invite_email;       
       YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_sendrequestmultiple', callback_friendrequestmultiple, postData); 
       var url  = system_base_url+'ajax/friends/_sendrequestmultiple';
     }
   else
   {

     var gobble_email_id = document.getElementById("gobbled_email_ids").value;
     var show_only_thankyou_message = document.getElementById("show_only_thankyou_message").value;	
     var postData = '&friend_ids='+str+'&gobble_email_id='+gobble_email_id+'&show_only_thankyou_message='+show_only_thankyou_message;      
       
     YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_sendrequestmultiple', callback_friendrequestmultiple, postData);
     var url  = system_base_url+'ajax/friends/_sendrequestmultiple';
    }

   if(env_value == 'Online')
	{
	    pageTracker._trackPageview(url);
	}
    
 
}


//! Method to check action for multiple check boxes  
/*!
 * \ method get profile ids from check box

 * \ as per actions it call function with AJAX 
 */ 
function skiptoinvite(mode)
{

  if(mode == 'quick')
    {
       var invite_email = document.getElementById('invite_email_ids').value;
       var postData = '&invite=quick'+'&invite_email='+invite_email;       
       YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_quickInvite', callback_friendrequestmultiple, postData);

       if(env_value == 'Online')
	{
	    var url  = system_base_url+'ajax/friends/_quickInvite';
	    pageTracker._trackPageview(url);
	}
    
    }
  else
    {
      var gobble_email_id = document.getElementById("gobbled_email_ids").value;
      var frm = document.getElementById('frm_on_bigadda');
      frm.action = system_base_url+'friends/_bigadda_invite';  
      frm.submit();
    }

}


//! Method to check action for multiple check boxes and send invitaion 
/*!
 * \ method get email ids from check box
 * \ as per actions it call function with AJAX 
 */ 
function checkActionsendinvitation_fr()
{

    var frm = document.getElementById('invite_email_form');
    var personal_message = document.getElementById('personal_message').value;
    var len = frm.elements.length;
    var i=0;
    var str=""
    for(i=0; i<len; i++)
    {
      if(frm.elements[i].name=='check_box') 
      {  
        if(frm.elements[i].checked)
	  { 
	    if(str=="")
	    {  
	      str =frm.elements[i].value;
	    }
	    else
	    {
	      str +=","+frm.elements[i].value;
	    }
	}
      }
    }

   if(str=="")
   alert("select at least one");
   else
   {

    var postData = '&email_ids='+str+'&personal_message='+personal_message;      
    YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_sendinvite', callback_sendinvite, postData);
     if(env_value == 'Online')
	{
	    var url  = system_base_url+'ajax/friends/_sendinvite';
	    pageTracker._trackPageview(url);
	}
    
    }
 
}




//! Method to check action for multiple check boxes and invitaion resend 
/*!
 * \ method get email ids from check box
 * \ as per actions it call function with AJAX 
 */ 
function inviteResend_fr()
{
    var frm = document.getElementById('frm_peniding_invite'); 
    var len = frm.elements.length;
    var i=0;
    var str=""
    for(i=0; i<len; i++)
    {
      if(frm.elements[i].name=='check_box') 
      {  
        if(frm.elements[i].checked)
	  { 
	    if(str=="")
	    {  
	      str =frm.elements[i].value;
	    }
	    else
	    {
	      str +=","+frm.elements[i].value;
	    }
	}
      }
    }

   if(str=="")
   alert("select at least one");
   else
   {
      var postData = '&email_ids='+str+'&invite_mode=resend';      
      YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_inviteresend', callback_inviteresend, postData);
      if(env_value == 'Online')
	{
	    var url  = system_base_url+'ajax/friends/_inviteresend';
	    pageTracker._trackPageview(url);
	}
    
    }
 
}


//! Method to resend invitaion individual 
/*!
 * \ method get email ids from perameter
 * \ send invitation with AJAX 
 */ 
function inviteResendIndividual_fr(email_id)
{
  var postData = '&email_ids='+email_id+'&invite_mode=resend';      
  YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_inviteresend', callback_inviteresend, postData);
  if(env_value == 'Online')
	{
	    var url  = system_base_url+'ajax/friends/_inviteresend';
	    pageTracker._trackPageview(url);
	}
    
}




//! Method to check action for multiple check boxes  
/*!
 * \ method get profile ids from check box
 * \ as per actions it call function with AJAX 
 */ 
function skipfrominvite(invite_mode)
{
  if(invite_mode == 'invite')
    {
      window.location = system_base_url+'ajax/friends/_invite';
    }
  else
    {
      window.location = system_base_url+'ajax/friends/_find';
    }
}





YAHOO.namespace("example.container1");
function init_friends()
 {
	// Instantiate the Dialog
       YAHOO.example.container1.friends_remove_dialog1 = new YAHOO.widget.Dialog("friends_remove_dialog1", 
							{ width : "50em",
							  context:["popup_context","tl","bl"],
							  visible : false, 
							  modal:true,
							  xy:[300,200],
							  zIndex:1000
							});
       YAHOO.example.container1.friends_remove_dialog1.render();


 	
       YAHOO.example.container1.connection_messages_popup = new YAHOO.widget.Dialog("connection_messages_popup", 
							{ width : "50em",
 							 context:["popup_context","tl","bl"],
							  visible : false, 
							  modal:true,
							  xy:[300,200],
							  zIndex:1000
							});
   YAHOO.example.container1.connection_messages_popup.render();
	YAHOO.example.container1.manager = new YAHOO.widget.OverlayManager();
	YAHOO.example.container1.manager.register([YAHOO.example.container1.friends_remove_dialog1,
											  YAHOO.example.container1.connection_messages_popup]);

	YAHOO.example.container1.connection_messages_edit_popup = new YAHOO.widget.Dialog("connection_messages_edit_popup", 
							{ width : "50em",
 							 context:["popup_context","tl","bl"],
							 visible : false, 
							  modal:true,
							  xy:[300,200],
							  zIndex:1000
							});
   YAHOO.example.container1.connection_messages_edit_popup.render();
	YAHOO.example.container1.manager = new YAHOO.widget.OverlayManager();
	YAHOO.example.container1.manager.register([YAHOO.example.container1.friends_remove_dialog1,
											  YAHOO.example.container1.connection_messages_edit_popup]);


}

YAHOO.util.Event.onDOMReady(init_friends);

function showCMsPopup(mode,profile_id, pagename, group_name)
{  
    //to shift the focus to search text box for displaying popup
    
    document.getElementById('searched_keyword').focus(); 

    if(document.getElementById('mymedia'))
	{
	    document.getElementById('mymedia').style.display = 'none';
	}

  if( pagename == undefined)
   {
      pagename = '';	 
   }		
  
  if(group_name == undefined)
   {
      group_name = '';	 
   }		



  var post_data = '&action='+mode+'&friend_id='+profile_id+'&pagename='+pagename+'&group_name='+group_name;  
   

    if(mode == 'add')
      {
	cleanCMsPopupData();	
	YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_getcmsdata/', callback_cmsPopup, post_data);  
	document.getElementById('action').value=mode;
	document.getElementById('pagename').value=pagename;
	document.getElementById('friend_id').value=profile_id;
	document.getElementById('group_name').value=group_name;
	document.getElementById('connection_messages_popup').style.display='';
	YAHOO.example.container1.connection_messages_popup.show(); 
      }
    else
      {
	cleanEMsPopupData();	
	YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_getcmsdata/', callback_emsPopup, post_data);  
	document.getElementById('action_edit').value=mode;
	document.getElementById('pagename_edit').value=pagename;
	document.getElementById('friend_id_edit').value=profile_id;
	document.getElementById('group_name_edit').value=group_name;
	document.getElementById('connection_messages_edit_popup').style.display='';
	YAHOO.example.container1.connection_messages_edit_popup.show(); 
      }

    if(env_value == 'Online')
	{

	     var url  = system_base_url+'ajax/friends/_getcmsdata/';
	 
	    pageTracker._trackPageview(url);
	}
    
  
}

function cleanCMsPopupData()
{
  document.getElementById('friend_id').value = '';	
  document.getElementById('action').value = '';
  document.getElementById('pagename').value = '';
  document.getElementById('send').value = '';  

  document.getElementById('grew_up_together').checked = false;		

  document.getElementById('studied_together').checked = false;	
  document.getElementById('institute_name').value = '';	
  document.getElementById('institute_from_Year').value = '';	
  document.getElementById('institute_to_Year').value = '';
  document.getElementById('institute_option').style.display = 'none';
  //option 1
  document.getElementById('institute_option1').style.display = 'none'; 
  document.getElementById('institute_name1').value = '';	
  document.getElementById('institute_from_Year1').value = '';	
  document.getElementById('institute_to_Year1').value = '';
  //option 2
  document.getElementById('institute_option2').style.display = 'none'; 
  document.getElementById('institute_name2').value = '';	
  document.getElementById('institute_from_Year2').value = '';	
  document.getElementById('institute_to_Year2').value = '';

  document.getElementById('worked_together').checked = false;
  document.getElementById('organisation_name').value = '';	
  document.getElementById('organisation_from_Year').value = '';	
  document.getElementById('organisation_to_Year').value = '';	
  document.getElementById('workplace_option').style.display = 'none';
  //option 1
  document.getElementById('organisation_option1').style.display = 'none'; 
  document.getElementById('organisation_name1').value = '';	
  document.getElementById('organisation_from_Year1').value = '';	
  document.getElementById('organisation_to_Year1').value = '';
  //option 2
  document.getElementById('organisation_option2').style.display = 'none'; 
  document.getElementById('organisation_name2').value = '';	
  document.getElementById('organisation_from_Year2').value = '';	
  document.getElementById('organisation_to_Year2').value = '';
	
  document.getElementById('in_the_same_family').checked = false;
  document.getElementById('samefamily_option').value = ''; 
  document.getElementById('samefamily').style.display = 'none';	

//  document.getElementById('through_a_friend').checked = false;	
//  document.getElementById('secondary_friend').value = ''; 
//  document.getElementById('throughfriend').style.display = 'none';

  document.getElementById('met_online').checked = false;	

  document.getElementById('through_bigAdda').checked = false;	

  document.getElementById('othercase').checked = false;	
  document.getElementById('otheroption_value').value = '';	
  document.getElementById('otheroption').style.display = 'none';

}

function cleanEMsPopupData()
{
  document.getElementById('friend_id_edit').value = '';	
  document.getElementById('action_edit').value = '';
  document.getElementById('pagename_edit').value = '';
  document.getElementById('send_edit').value = '';  

  document.getElementById('grew_up_together_edit').checked = false;		

  document.getElementById('studied_together_edit').checked = false;	
  document.getElementById('institute_name_edit').value = '';	
  document.getElementById('institute_from_Year_edit').value = '';	
  document.getElementById('institute_to_Year_edit').value = '';
  document.getElementById('institute_option_edit').style.display = 'none';
  //option 1
  document.getElementById('institute_option1_edit').style.display = 'none'; 
  document.getElementById('institute_name1_edit').value = '';	
  document.getElementById('institute_from_Year1_edit').value = '';	
  document.getElementById('institute_to_Year1_edit').value = '';
  //option 2
  document.getElementById('institute_option2_edit').style.display = 'none'; 
  document.getElementById('institute_name2_edit').value = '';	
  document.getElementById('institute_from_Year2_edit').value = '';	
  document.getElementById('institute_to_Year2_edit').value = '';

  document.getElementById('worked_together_edit').checked = false;
  document.getElementById('organisation_name_edit').value = '';	
  document.getElementById('organisation_from_Year_edit').value = '';	
  document.getElementById('organisation_to_Year_edit').value = '';	
  document.getElementById('workplace_option_edit').style.display = 'none';
  //option 1
  document.getElementById('organisation_option1_edit').style.display = 'none'; 
  document.getElementById('organisation_name1_edit').value = '';	
  document.getElementById('organisation_from_Year1_edit').value = '';	
  document.getElementById('organisation_to_Year1_edit').value = '';
  //option 2
  document.getElementById('organisation_option2_edit').style.display = 'none'; 
  document.getElementById('organisation_name2_edit').value = '';	
  document.getElementById('organisation_from_Year2_edit').value = '';	
  document.getElementById('organisation_to_Year2_edit').value = '';
	
  document.getElementById('in_the_same_family_edit').checked = false;
  document.getElementById('samefamily_option_edit').value = ''; 
  document.getElementById('samefamily_edit').style.display = 'none';	

//  document.getElementById('through_a_friend').checked = false;	
//  document.getElementById('secondary_friend').value = ''; 
//  document.getElementById('throughfriend').style.display = 'none';

  document.getElementById('met_online_edit').checked = false;	

  document.getElementById('through_bigAdda_edit').checked = false;	

  document.getElementById('othercase_edit').checked = false;	
  document.getElementById('otheroption_value_edit').value = '';	
  document.getElementById('otheroption_edit').style.display = 'none';

}



function hideCMsPopup()
{
  if(document.getElementById('mymedia'))
      {
	  document.getElementById('mymedia').style.display = 'block';
      }

  YAHOO.example.container1.connection_messages_popup.hide();
  //  YAHOO.example.container1.connection_messages_edit_popup.hide();
  document.getElementById('connection_messages_popup').style.display='none';  
  //document.getElementById('connection_messages_edit_popup').style.display='none';  
  YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_addpopup/', callback_addPopup);    

  if(env_value == 'Online')
	{
	    var url = system_base_url+'ajax/friends/_addpopup/';
	    pageTracker._trackPageview(url);
	}
    
}


function hideEMsPopup()
{
  if(document.getElementById('mymedia'))
      {
	  document.getElementById('mymedia').style.display = 'block';
      }

  YAHOO.example.container1.connection_messages_edit_popup.hide();
  document.getElementById('connection_messages_edit_popup').style.display='none';  
  YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_editpopup/', callback_editPopup);    
  if(env_value == 'Online')
	{
	    var url = system_base_url+'ajax/friends/_editpopup/';
	    pageTracker._trackPageview(url);
	}
    
}



function showRemoveFriendsPopup(profile_id,f_name,l_name, divid, group_name)
{
//to shift the focus to search text box for displaying popup                                                                                               
  document.getElementById('searched_keyword').focus(); 
  if(divid == undefined)	
  {
    divid = 'friend_default_body';	
  }

  if(group_name == undefined)	
  {
    group_name = '';	
  }

		
  document.getElementById('friends_remove_dialog1').style.display='';
  document.getElementById('friend_name_1').innerHTML=f_name+" "+l_name;
  document.getElementById('friend_name_2').innerHTML=f_name+" "+l_name+" will not be notified.";
  document.getElementById('remove_friend_id').value=profile_id;
  document.getElementById('div_id').value=divid;	
  document.getElementById('group_name').value= group_name;	
  YAHOO.example.container1.friends_remove_dialog1.show();
}

function hideRemoveFriendsPopup()
{
  YAHOO.example.container1.friends_remove_dialog1.hide();
  document.getElementById('friends_remove_dialog1').style.display='none';
}



function getSecondaryFriends()
{
  //var profile_id = document.getElementById('friend_id').value;    
  var post_data = '';
  YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_getSecondaryContacts/', callback_getsecondaryfriends, post_data);  
  if(env_value == 'Online')
	{
	    var url = system_base_url+'ajax/friends/_getSecondaryContacts/';
	    pageTracker._trackPageview(url);
	}
    
}


function addMore(org)
{
  var ni   = document.getElementById('more_'+org);
  var numi = document.getElementById(org+'_number');
   var num  = (document.getElementById(org+'_number').value -1)+ 2;
 
  if(num <= 2)
  { 
     numi.value = num;   
     document.getElementById(org+'_option'+num).style.display='';
     
     if(num==2)
       {
         document.getElementById('add_another_'+org).style.display='none'; 
       }
  }
}

function addMoreForEdit(org)
{
  var ni   = document.getElementById('more_'+org+'_edit');
  var numi = document.getElementById(org+'_number_edit');
  var num  = (document.getElementById(org+'_number_edit').value -1)+ 2;
  
  if(num <= 2)
  { 
    numi.value = num;
    document.getElementById(org+'_option'+num+'_edit').style.display='';
     
    if(num==2)
      {
	document.getElementById('add_another_'+org+'_edit').style.display='none'; 
      }
  }
}


//! Method for pagination
function pagination_fr(base_url,keyword,show_from,divid)
{       
        
	 
    var post_data = 'keyword='+keyword+'&pagination=y'+'&show_from='+show_from+'&divid='+divid;
    div_id = divid;
    if(keyword == '')
	{          
	    YAHOO.util.Connect.asyncRequest('POST',base_url, callback_paginationfr, post_data);       
  
	}
    else
	{            
  
	    YAHOO.util.Connect.asyncRequest('POST',base_url, callback_paginationfr, post_data);       
	}

    if(env_value == 'Online')
	{
	   var url = base_url;
	    pageTracker._trackPageview(url);
	}
    
}


function update_confirm(user_id, friend_id, pagename, group_name)
{
  
  if( group_name == undefined)
   {
      group_name = '';	 
   }	

  var post_data = '&user_id='+user_id+'&friend_id='+friend_id+'&pagename='+pagename+'&group_name='+group_name;
  YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_updateconfirm/', callback_confirm, post_data);       
  if(env_value == 'Online')
	{
	    var url = system_base_url+'ajax/friends/_updateconfirm/';
	    pageTracker._trackPageview(url);
	}
    
  page_name = pagename;	
  
}

function getSecondaryFriends()
{
  //var profile_id = document.getElementById('friend_id').value;    
  var post_data = '';
  YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_getSecondaryContacts/', callback_getsecondaryfriends, post_data);  

  if(env_value == 'Online')
	{
	    var url = system_base_url+'ajax/friends/_getSecondaryContacts/';
	    pageTracker._trackPageview(url);
	}
    

}

function deletegroup(group_name)
{ 	
    if(confirm(DELETE_GROUP))
       {	   
	   var post_data = '&group_name='+group_name;
	   YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/friends/_removegroup/', callback_removegroup, post_data); 
	   if(env_value == 'Online')
	{
	    var url = system_base_url+'ajax/friends/_removegroup/';
	    pageTracker._trackPageview(url);
	}
    
 
       }

}

//! Function to validate institute
function validateInstitute(cnt)
{
    var error_code = '';
    var filter  = /^[a-zA-Z \' \.]+$/; 
    for(var i=0;i<=cnt;i++)
	{
	    if(i > 0)
		{
		    inst_nm      = document.getElementById('institute_name'+i).value;
		    inst_yr_from = document.getElementById('institute_from_Year'+i).value;
		    inst_yr_to   = document.getElementById('institute_to_Year'+i).value;
		}
	    else
		{
		    inst_nm      = document.getElementById('institute_name').value;
		    inst_yr_from = document.getElementById('institute_from_Year').value;
		    inst_yr_to   = document.getElementById('institute_to_Year').value;
		}

	    if(inst_nm == '')
		{
		    error_code = ERROR_INSTITUTE_NAME;
		}
	    else if(!filter.test(inst_nm))
		{
		    error_code =  ERROR_INVALID_INSTITUTE_NAME;
		}
	    else if(inst_yr_from == '')
		{
		   error_code = ERROR_FROM_YEAR;
		}
	    else if(inst_yr_to == '')
		{
		   error_code = ERROR_TO_YEAR;
		}
	    else if(inst_yr_from > inst_yr_to)
		{
		   error_code = ERROR_INVALID_FROM_YEAR;
		}
	    if(error_code != '')
		{
		    return error_code;
		}
	}
    
    return error_code;
       
}

function validateEditInstitute(cnt)
{
    var error_code = '';
    var filter  = /^[a-zA-Z \' \.]+$/; 
    for(var i=0;i<=cnt;i++)
	{
	    if(i > 0)
		{
		    inst_nm      = document.getElementById('institute_name'+i+'_edit').value;
		    inst_yr_from = document.getElementById('institute_from_Year'+i+'_edit').value;
		    inst_yr_to   = document.getElementById('institute_to_Year'+i+'_edit').value;
		}
	    else
		{
		    inst_nm      = document.getElementById('institute_name_edit').value;
		    inst_yr_from = document.getElementById('institute_from_Year_edit').value;
		    inst_yr_to   = document.getElementById('institute_to_Year_edit').value;
		}

	    if(inst_nm == '')
		{
		    error_code = ERROR_INSTITUTE_NAME;
		}
	    else if(!filter.test(inst_nm))
		{
		    error_code =  ERROR_INVALID_INSTITUTE_NAME;
		}
	    else if(inst_yr_from == '')
		{
		   error_code = ERROR_FROM_YEAR;
		}
	    else if(inst_yr_to == '')
		{
		   error_code = ERROR_TO_YEAR;
		}
	    else if(inst_yr_from > inst_yr_to)
		{
		   error_code = ERROR_INVALID_FROM_YEAR;
		}
	    if(error_code != '')
		{
		    return error_code;
		}
	}
    
    return error_code;
       
}


//! Function to validate work together
function validateWorkTogether(cnt)
{
    var error_code = '';
    var filter  = /^[a-zA-Z \' \.]+$/; 
    for(var i=0;i<=cnt;i++)
	{
	    if(i > 0)
		{
		    org_nm      = document.getElementById('organisation_name'+i).value;
		    org_yr_from = document.getElementById('organisation_from_Year'+i).value;
		    org_yr_to   = document.getElementById('organisation_to_Year'+i).value;
		}
	    else
	      {
		    org_nm      = document.getElementById('organisation_name').value;
		    org_yr_from = document.getElementById('organisation_from_Year').value;
		    org_yr_to   = document.getElementById('organisation_to_Year').value;
		}
	    
	    if(org_nm == '')
		{
		    error_code = ERROR_ORGANISATION_NAME;
		}
	    else if(!filter.test(org_nm))
		{
		    error_code =  ERROR_INVALID_ORGANISATION_NAME;
		}
	    else if(org_yr_from == '')
		{
		   error_code = ERROR_FROM_YEAR;
		}
	    else if(org_yr_to == '')
		{
		   error_code = ERROR_TO_YEAR;
		}
	    else if(org_yr_from > org_yr_to)
		{
		   error_code = ERROR_INVALID_FROM_YEAR;
		}
	    if(error_code != '')
		{
		    return error_code;
		}
	}
    
    return error_code;       
}

function validateEditWorkTogether(cnt)
{
    var error_code = '';
    var filter  = /^[a-zA-Z \' \.]+$/; 
    for(var i=0;i<=cnt;i++)
	{
	    if(i > 0)
		{
		    org_nm      = document.getElementById('organisation_name'+i+'_edit').value;
		    org_yr_from = document.getElementById('organisation_from_Year'+i+'_edit').value;
		    org_yr_to   = document.getElementById('organisation_to_Year'+i+'_edit').value;
		}
	    else
		{
		    org_nm      = document.getElementById('organisation_name_edit').value;
		    org_yr_from = document.getElementById('organisation_from_Year_edit').value;
		    org_yr_to   = document.getElementById('organisation_to_Year_edit').value;
		}

	    if(org_nm == '')
		{
		    error_code = ERROR_ORGANISATION_NAME;
		}
	    else if(!filter.test(org_nm))
		{
		    error_code =  ERROR_INVALID_ORGANISATION_NAME;
		}
	    else if(org_yr_from == '')
		{
		   error_code = ERROR_FROM_YEAR;
		}
	    else if(org_yr_to == '')
		{
		   error_code = ERROR_TO_YEAR;
		}
	    else if(org_yr_from > org_yr_to)
		{
		   error_code = ERROR_INVALID_FROM_YEAR;
		}
	    if(error_code != '')
		{
		    return error_code;
		}
	}
    
    return error_code;       
}

//! Funcation to validate family
function validateFamily()
{
    var family_option = document.getElementById('samefamily_option').value;
    var error_code = '';

    if(family_option == '')
	{
	    error_code = ERROR_FAMILY_TYPE;
	}
    return error_code;
}

function validateEditFamily()
{
    var family_option = document.getElementById('samefamily_option_edit').value;
    var error_code = '';

    if(family_option == '')
	{
	    error_code = ERROR_FAMILY_TYPE;
	}
    return error_code;
}

//! Function to validate friend
function validateFriend()
{
    var sec_friend = document.getElementById('secondary_friend').value;
    var error_code = '';

    if(sec_friend == '')
	{
	    error_code = ERROR_FRIEND_NAME;
	}
    return error_code;
}

//! Function to validate other type
function validateOtherType(otheroption_value)
{ var other = otheroption_value;
  //var other = document.getElementById('otheroption_value').value;
    var error_code = '';

    if(other == '')
	{
	    error_code = ERROR_OTHER_TYPE;
	}
    return error_code;
}

//! Pagination New                                                                                                                                           
function paginationNew(base_url,keyword,show_from)
{
    document.getElementById('keyword').value = keyword;
    document.getElementById('pagination').value = 'y';
    document.getElementById('show_from').value = show_from;
    document.frm_pagination.submit();
}




//! Function to count character of personal message field on add as friend popup
function messageCharacterCounter(Textid,Countid)
{
  var limit = '1000';        
  var val = document.getElementById(Textid).value;
  var len = val.length;
  var text = '';
  if(len > limit)
    {   
      text = val.substring(0,limit);
      document.getElementById(Textid).value = text;
      return false;
    }    
  document.getElementById(Countid).innerHTML = len;
}