$(document).ready( 
  function() { 
    $(".browse_heading > em").click(function() {
        var m = 'image_' + $(this).parent().parent().attr('id');
        var new_obj = $(this).parent();
        if ($('../../p.browse_content_middle',new_obj).is(':hidden')) {
          document.getElementById(m).src = THEME_PATH + "/images/grey_arrow.gif";
          $('../../p.browse_content_middle', new_obj).show('slow');
        }
        else {
          document.getElementById(m).src = THEME_PATH + "/images/grey_arrow_right.gif";
          $('../../p.browse_content_middle', new_obj).hide('slow');
        }
      }
    
    );    
  }  
);
  
function hide_show_block(block_id){       // alert(img_id);  
   try{
		  var image = document.getElementById("image_"+block_id);
      var block_obj = document.getElementById(block_id);
      var disp_obj  = document.getElementById(block_id+'_content');
     
      if ($(disp_obj, block_obj).is(':hidden')) {
        image.src = THEME_PATH + "/publicprofile_images/show_hide.gif";
        $(disp_obj, block_obj).show('slow');
      }
      else {
        image.src = THEME_PATH + "/publicprofile_images/show_hide_down.gif";
        $(disp_obj, block_obj).hide('slow');
      }
	}catch(e){
		//
	}
}


function toggleBox(szDivID, iState){ // 1 visible, 0 hidden{
  try{ 
	  if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
	}catch(e){

	}
}

function disable_form(frm) {
  try{
	var frm = frm;
  var all;
  all = document.forms[frm].elements.length;
  for(counter=0; counter < all; counter++) { 
    if(document.forms[frm][counter].name == "other[]") {
      document.forms[frm][counter].disabled = true;
    }
  }
	}catch(e){
		//
	}	
}

function enable_form(frm) {
  try{
	var frm = frm;
  var all;
  all = document.forms[frm].elements.length;
  for(counter=0; counter < all; counter++) { 
    if(document.forms[frm][counter].name == "other[]") {
      document.forms[frm][counter].disabled = false;
    }
  }
	}catch(e){
		//
	}
}

function manage_hidden(id) {
  try{
	var id = id;
  var style = document.getElementById(id).style.display;
  if (style == 'block') {
    new_style = 'none';
  } else {
    new_style = 'block';
  }
  document.getElementById(id).style.display = new_style; 
	}catch(e){
	
	}
}

function validate_dob() {
	try{
  var day = document.getElementById('dob_day');
  var month = document.getElementById('dob_month');
  var year = document.getElementById('dob_year');
  if (day.value && month.value && year.value) {
    return true;
  }
  else {
    alert('Please enter a valid date of birth.');
    return false;
  }
	}catch(e){

	}
}

function change_group(uid) {
  try{
	url = "write_testimonial.php?uid="+uid;
  window.location = url;
	}catch(e){
	
	}
}
function change_group_message(uid, com_id) {
  if (uid == 0) {
    alert('Please select a contact');
    return false;
  }
  url = "addmessage.php?recomm=true&uid="+uid+"&com_id="+com_id;
  window.location = url;
}
//functions for public profile
function show_hidden(id) {
  document.getElementById(id).style.display = 'block'; 
}
function hide_hidden(id) {
  document.getElementById(id).style.display = 'none'; 
}

   function confirm_discussion(comment) {
      //  var opn = (document.topicform.comment.value).replace(/^\s*|\s*$/g,'');
        comment.value = (comment.value).replace(/^\s*|\s*$/g,'');
        var opn=trim(comment.value);
        if (opn == '') {
        alert("Reply cannot be left blank.");
        return false;
        }
	 checkChkBoxStatus(); // Added by Abhishek on 03/06/2009 
        return true;
}

// Below function added by Abhishek on 03/06/2009
function checkChkBoxStatus() {
	if(document.topicform.follow_discussion.checked == true) {
		document.topicform.follow_discussion_chkval.value='Y';
	} else {
		document.topicform.follow_discussion_chkval.value='N';
	}
}
// --------------------

//Scripts for the Profile page
var defaultChoice = true;
var validateSwitch;
 //Called by show_large_map
 function stretchprofile(){
    document.getElementById('user_prof').style.width=761+'px';
    document.getElementById('prof_top').style.backgroundImage="url('"+THEME_PATH+"/images/green_bg_top_wide.gif')";
    document.getElementById('prof_top').style.width=761+'px';
    document.getElementById('prof_middle').style.backgroundImage="url('"+THEME_PATH+"/images/green_bg_middle_wide.gif')";
    document.getElementById('prof_middle').style.width=761+'px';
    document.getElementById('prof_bot').style.backgroundImage="url('"+THEME_PATH+"/images/green_bg_bottom_wide.gif')";
    document.getElementById('prof_bot').style.width=761+'px';
    document.getElementById('prof_midleft').style.width=646+'px'; 
 }
 //called when shrink button is clicked
 function shrinkprofile(){
    document.getElementById('user_prof').style.width=517+'px';
    document.getElementById('prof_top').style.backgroundImage="url('"+THEME_PATH+"/images/greenwithwhite_bg_top.gif')";
    document.getElementById('prof_top').style.width=517+'px';
    document.getElementById('prof_middle').style.background="url('"+THEME_PATH+"/images/greenwithwhite_bg_middle.gif') repeat-y";
    document.getElementById('prof_middle').style.width=517+'px';
    document.getElementById('prof_bot').style.backgroundImage="url('"+THEME_PATH+"/images/greenwithwhite_bg_bottom.gif')";
    document.getElementById('prof_bot').style.width=517+'px';
    document.getElementById('prof_midleft').style.width=405+'px'; 
 }
 //Called whnen clicked on the Peopleexplorer or Map link on the profile page
 function show_large_map(){
    document.getElementById('profile_s_map').style.display = 'none';
    document.getElementById('profile_large_map').style.display = 'block';
    document.getElementById('map_box').style.display = 'block';
    document.getElementById('warp_box').style.display = 'none';
    document.getElementById('large_map').className = 'active';
    document.getElementById('large_warp').className = '';
    var mapurl = base_url + "/map.php" ; 
    if(document.getElementById('frameId').src!=mapurl){
      document.getElementById('frameId').src= mapurl;
    }
  stretchprofile();
  return;
}

function show_large_warp(){
    document.getElementById('profile_s_map').style.display = 'none';
    document.getElementById('profile_large_map').style.display = 'block';
    document.getElementById('map_box').style.display = 'none';
    document.getElementById('warp_box').style.display = 'block';
    document.getElementById('large_map').className = '';
    document.getElementById('large_warp').className = 'active';
    stretchprofile();
    return;
}

function show_small_map(){
    document.getElementById('profile_s_map').style.display = 'block';
    document.getElementById('profile_large_map').style.display = 'none';
    shrinkprofile();
    return;
}  

function ToggleView(){
   if(defaultChoice == false){
    document.getElementById('sml_map').className = '';
    document.getElementById('sml_warp').className = 'active';
    document.getElementById('smallwarp').style.display = 'block';
    document.getElementById('smallmap').style.display = 'none';
    defaultChoice = true;
    return;    
   }
   else{
    document.getElementById('sml_map').className = 'active';
    document.getElementById('sml_warp').className = '';
    document.getElementById('smallwarp').style.display = 'none';
    document.getElementById('smallmap').style.display = 'block';
    defaultChoice = false;
    return;    
   }
} 
function ShowHideBlock(id, obj){
 $('#'+id).slideDown('slow');
 obj.style.display = 'none';
 return false;
}
function HideSearchBlock(id,id2){
  document.getElementById(id).style.display = 'none';
  document.getElementById(id2).style.display = 'inline';
}

function fillTargetBox(type) {
	if(type == "email") {
		document.getElementById('trg_email').innerHTML = document.getElementById('src_email').value;
	}
	if(type == "mobile") {
		var mValCheck = document.getElementById('src_mobile').value;
		if(isNaN(mValCheck)) {
			alert('Only numbers are allowed in Mobile field.');
			return false;
		} else {
			document.getElementById('trg_mobile').innerHTML = document.getElementById('src_mobile').value;
		}
	}
	if(type == "profile") {
		document.getElementById('trg_profile').innerHTML = document.getElementById('src_profile').value;
	}

}

function check_validation(){

    				if (document.myForm.src_email.value.replace(/ /g,'') == "")
    				{
            				document.myForm.src_email.value='';
            				alert ('Please enter Email id. ');
            				document.myForm.src_email.focus();
            				return false;
    				}

    				if (!check_email(document.myForm.src_email))
    				{
            				alert ('Please enter valid email id. ');
            				document.myForm.src_email.focus();
            				return false;
    				}

			if(document.myForm.src_mobile.value.length == 0 || document.myForm.src_mobile.value.length < 10) {
				alert('Please enter Mobile no. ');
				document.myForm.src_mobile.focus();
				return false;
			}
			if(document.myForm.src_mobile.value.length != 0) {
        			var numericExpression = /^[0-9]+$/;
               		if(!document.myForm.src_mobile.value.match(numericExpression)){
                        		alert('Only numbers are allowed in Mobile field. ');
                        		document.myForm.src_mobile.focus();
                        		return false;
                		}
			}

                    if(document.myForm.src_profile.value.length == 0) {
				alert('Please enter Public Profile. ');
				document.myForm.src_profile.focus();
				return false;
			}

return;
}
// Email validation function.....
function check_email(formField)
{
   var emailReg="^[\\w_-]+(\\.[\\w_-]+)*@[\\w_-]+(\\.[\\w_-]+)*\\.[a-z]{2,4}$";
   var regex = new RegExp(emailReg);
   regex.multiline=true;
   return regex.test(formField.value);
}


 function saveUserProfileTxt(uid) {

  	var dataFlag;
   	if(navigator.appName =="Microsoft Internet Explorer"){
       	dataFlag = null;
   	}else{
       	dataFlag = true;
   	}
   var inputTxt = document.getElementById('src_profile').value;
   if(inputTxt.replace(/ /g, '') == "") {
	alert('Please enter Public Profile');
	return;
   }

   ExecuteCall("general_ajax_task.php?action=save_user_profile&user_id="+uid+"&profileMsg="+inputTxt,"update_profile_msg",dataFlag);
  }


// below function added for stop following feature, added by Abhishek on 10 June 2009
 function stopFollowId(msgId, groupId, loginUid, msgType, baseUrl) {
//   alert(msgId+'=='+groupId+'=='+loginUid+'=='+msgType+"=="+baseUrl);
   if(navigator.appName =="Microsoft Internet Explorer"){
        var dataFlag = null;
    }else{
        var dataFlag = true;
    }
    ExecuteCall(baseUrl+"/general_ajax_task.php?action=stop_follow&msgId="+msgId+"&groupId="+groupId+"&loginUid="+loginUid+"&msgType="+msgType,"Stop_follow",dataFlag);
 }


function AjaxCallback(str,id)
{ 
    try
    {
        if (id=="update_profile_msg"){ // this section for sending the event invite to functional Area members...
	    var finalStr = str.split("#");	
	    document.getElementById('show_profile_response').innerHTML = finalStr[1];	
	
        }// if(id=="update_profile_msg")

        if (id=="Stop_follow"){
		var finalStr = str.split("#");
//		alert(finalStr);
		if(finalStr[0] == "Y") {
			if(finalStr[1] == "A") {
				var redirectUrl;
				redirectUrl = finalStr[3]+"/group.php?gid="+finalStr[2]+"&post_type=blog&follow_article=Y";
				document.location.href=redirectUrl;
			} else {
				document.getElementById('show_follow_msg').style.display='none';
			}
		} else {
			// alert(str);			
		}	
        }// if(id=="Stop_follow")

    }
    catch(e)
    {
    }
}// AjaxCallback(str,id)

  function checksearch(){
  
  if(document.search_form.keyword.value.length == 0) {
	alert('Please enter search string. ');
	document.search_form.keyword.focus();
	return false;
   } else {
	var a =  document.search_form.keyword.value;
      var b = a.replace(/^(?:\s)*/g,'').replace(/(?:\s)*$/g,'');
	if(b.length == 0) {
		alert('Please enter search string. ');
		document.search_form.keyword.value = '';
		document.search_form.keyword.focus();
		return false;
	} else {
		return true;
	}
   }
  }

  function checkadvancesearch(loginId){
    var keyword = document.search_form.keyword.value;
	  keyword = keyword.replace(/ /g, '');
	  var company = document.search_form.company.value;
	  company = company.replace(/ /g, '');
	  var department = document.search_form.department.value;
	  department = department.replace(/ /g, '');
	  var institute = document.search_form.institute.value;
	  institute = institute.replace(/ /g, '');
	  var first_name = document.search_form.first_name.value;
	  first_name = first_name.replace(/ /g, '');
	  var country = document.search_form.country.value;
	  country = country.replace(/ /g, '');
	  var main_functional_area = document.search_form.main_functional_area.value;
	  main_functional_area = main_functional_area.replace(/ /g, '');
	  var wants = document.search_form.wants.value;
	  wants = wants.replace(/ /g, '');
	  var haves = document.search_form.haves.value;
	  haves = haves.replace(/ /g, '');
	  var interests = document.search_form.interests.value;
	  interests = interests.replace(/ /g, '');

	if(loginId == 1) {
		var company_job_title = document.search_form.company_job_title.value;
		company_job_title = company_job_title.replace(/ /g, '');

		var profile_freshness = "";
		for (var i=0; i < document.search_form.profile_freshness.length; i++)
		{
		   if (document.search_form.profile_freshness[i].checked)
			{
      				profile_freshness = document.search_form.profile_freshness[i].value;
      			}
   		}
		profile_freshness = profile_freshness.replace(/ /g, '');
/*
		var search_radio = "";
		for (var i=0; i < document.search_form.search_radio.length; i++)
		{
		   if (document.search_form.search_radio[i].checked)
			{
      				search_radio = document.search_form.search_radio[i].value;
	      		}
   		}
		search_radio = search_radio.replace(/ /g, '');
*/
	}

	if(loginId == 1) {
	  	if(keyword == "" && company == "" && department == "" && institute == "" && first_name == "" && country == "" && main_functional_area == "" && wants == "" && haves == "" && interests == "" && company_job_title == "" && profile_freshness == "") {
    			alert('Please provide atleast one search criteria. ');
			return false;
		} else {
			return true;
		}
	} else {
	  	if(keyword == "" && company == "" && department == "" && institute == "" && first_name == "" && country == "" && main_functional_area == "" && wants == "" && haves == "" && interests == "") {
    			alert('Please provide atleast one search criteria. ');
			return false;
		} else {
			return true;
		}
	}
 }
 
 // TODO
function select_group(id) {
  if (id == 'colleague') {
    document.getElementById('colleague_div').style.display = 'block';
    document.getElementById('classmate_div').style.display = 'none';
    document.getElementById('specializedfunctionalarea_div').style.display = 'none';
    document.getElementById('client_div').style.display = 'none'; // Added by Abhishek
    document.getElementById('classmate').value = '--select--';
//    document.getElementById('client').value='--select--';
    if (document.getElementById('specializedfunctionalarea')) {
      document.getElementById('specializedfunctionalarea').value = '--select--';
    }
  }

  if (id == 'classmate') {
    document.getElementById('colleague_div').style.display = 'none';
    document.getElementById('classmate_div').style.display = 'block';
    document.getElementById('specializedfunctionalarea_div').style.display = 'none';
    document.getElementById('client_div').style.display = 'none'; // Added by Abhishek
    document.getElementById('colleague').value = '--select--';
//    document.getElementById('client').value='--select--';
    if (document.getElementById('specializedfunctionalarea')) {
      document.getElementById('specializedfunctionalarea').value = '--select--';
    }
  }

  if (id == 'specializedfunctionalarea') {
    document.getElementById('colleague_div').style.display = 'none';
    document.getElementById('classmate_div').style.display = 'none';
    document.getElementById('client_div').style.display = 'none'; // Added by Abhishek
    document.getElementById('specializedfunctionalarea_div').style.display = 'block';
    document.getElementById('colleague').value = '--select--';
    document.getElementById('classmate').value = '--select--';
//    document.getElementById('client').value='--select--';
  }

  if (id == 'others') {
    document.getElementById('colleague_div').style.display = 'none';
    document.getElementById('classmate_div').style.display = 'none';
    document.getElementById('specializedfunctionalarea_div').style.display = 'none';
    document.getElementById('client_div').style.display = 'none'; // Added by Abhishek
    document.getElementById('colleague').value = '--select--';
    document.getElementById('classmate').value = '--select--';
//    document.getElementById('client').value='--select--';
    if (document.getElementById('specializedfunctionalarea')) {
      document.getElementById('specializedfunctionalarea').value = '--select--';
    }
  }
 // below block added by Abhishek
  if (id == 'client') {
    document.getElementById('colleague_div').style.display = 'none';
    document.getElementById('classmate_div').style.display = 'none';
    document.getElementById('specializedfunctionalarea_div').style.display = 'none';
    document.getElementById('client_div').style.display = 'block'; // Added by Abhishek
    document.getElementById('colleague').value = '--select--';
    document.getElementById('classmate').value = '--select--';
    if (document.getElementById('specializedfunctionalarea')) {
      document.getElementById('specializedfunctionalarea').value = '--select--';
    }
  }

  if (id == 'friends' || id == 'interested_profile') {
    document.getElementById('colleague_div').style.display = 'none';
    document.getElementById('classmate_div').style.display = 'none';
    document.getElementById('specializedfunctionalarea_div').style.display = 'none';
    document.getElementById('client_div').style.display = 'none';
    document.getElementById('colleague').value = '--select--';
    document.getElementById('classmate').value = '--select--';
    if (document.getElementById('specializedfunctionalarea')) {
      document.getElementById('specializedfunctionalarea').value = '--select--';
    }
//    document.getElementById('client').value='--select--';
  }

 // till here
}

function check_add_contact_validations() {
  if (document.getElementById('specializedfunctionalarea_div').style.display == 'block') {
    if (document.getElementById('functionalarea')) {
      if (document.getElementById('functionalarea').disabled == true) {
        alert('Please choose another option, You do not share any specialized functional area');
        return false;
      }
    }
  } else if (document.getElementById('colleague_div').style.display == 'block') {
    if (document.getElementById('colleague').value == 'No companies found') {
      alert('Please choose another option, You dont have specified any company');
      return false;
    }
    if(document.getElementById('colleague').value == '--select--'){
      alert('Please select a company from the list');
      return false;
    }
  } else if (document.getElementById('classmate_div').style.display == 'block') {
    if (document.getElementById('classmate').value == 'No insititute found') {
      alert('Please choose another option, You dont have specified any institute');
      return false;
    }
  }
 else if (document.getElementById('client_div').style.display == 'block') {
    if (document.getElementById('client').value == 'No companies found') {
      alert('Please choose another option, You dont have specified any company');
      return false;
    }
    if(document.getElementById('client').value == '--select--'){
      alert('Please select a client from the list');
      return false;
    }
  }
  //  && (document.getElementById('others').value == '--select--')
  if ((document.getElementById('colleague').value == '--select--') && (document.getElementById('classmate').value == '--select--' ) && document.getElementById('friends_radio').checked == false && document.getElementById('client_radio').checked == false && document.getElementById('interested_profile_radio').checked == false && document.getElementById('others_radio').checked == false) {
    if (document.getElementById('specializedfunctionalarea')) {
      if (document.getElementById('specializedfunctionalarea').value == '--select--') {
        alert('Cannot submit blank form. Please select the reason.');
      } else {
        return true;
      }
    } else if (document.getElementById('functionalarea')) {
      if (document.getElementById('functionalarea').disabled == true) {
        alert('Cannot submit blank form. Please select the reason.');
      }
    }
    return false;
  } else {
    return true;
  }
}


 	//function to be used by the Thickbox for opening links into the parent window
	function change_parent_url(url){
	  document.getElementById('TB_window').style.display='none';
	  document.getElementById('TB_overlay').style.display='none';
	  window.location=url;
	}

/*
 * Creates an HTTP GET request and sends the response to the callback function
 */
function HTTPGet(uri, callbackFunction, callbackParameter, callbackParameter2 ) {
  var xmlHttp = new XMLHttpRequest();
  var bAsync = true;
  if (!callbackFunction)
    bAsync = false;    
  xmlHttp.open('GET', uri, bAsync);
  xmlHttp.send(null);  
  if (bAsync) {
    if (callbackFunction) {
      xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4)
            callbackFunction(xmlHttp.responseText, xmlHttp, callbackParameter, callbackParameter2)
        }
    }
    return true;
  }
  else {
    return xmlHttp.responseText;
  }
}
