// JavaScript Document
//	Widget Part
function selectEmbedCode(id)
{
    var codeTextarea = document.getElementById(id);
    if (codeTextarea != null)
    {
        selectTextArea(codeTextarea);
        copyToClipBoard(codeTextarea)
    }
}


function selectTextArea(textAreaControl)
{
    textAreaControl.focus();
    textAreaControl.select();
}
function copyToClipBoard(textAreaControl)
{
    //This property is used to detect if the Flash Player is installed. 
    if(!FlashDetect.installed)
    {
        Copied = textAreaControl.createTextRange();
        Copied.execCommand("RemoveFormat");
        Copied.execCommand("Copy");
    }
    else
    {
        copy(textAreaControl);
    }
}

function copy(inElement) 
{
  if (inElement.createTextRange) 
  {
	// IE
    var range = inElement.createTextRange();
    if (range)
    {
      range.execCommand("RemoveFormat"); // added by me
      range.execCommand('Copy');
    }
  } 
  else 
  {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) 
    {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
	  //divholder.style.display = 'none';
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="./flash/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
}




function toggleAll(checked){
	$('.contact_list_container').empty();
	if(checked){
		$('input[name="contact[]"]').attr("checked",true);
		$('input[name="contact[]"]').click();
		$('input[name="contact[]"]').attr("checked",true);
	} else {
		$('input[name="contact[]"]').attr("checked",false);
		$('input[name="contact[]"]').click();
		$('input[name="contact[]"]').attr("checked",false);
	}
}
function changeCompany(value){
	$("#company1").val(value);
	$("#company2").val(value);
}

function displayContacts(letter){
	$(".letter_focus").removeClass('letter_focus');
	$(".contacts").hide();
	$("#letter-"+letter).addClass('letter_focus');
	$("#contact-"+letter).show();
	$("#contacts_number").html($("#contact-"+letter).children().length);
}




// Wall part
function postOnWall(id){
	$('#company-wall-tab').html(load_gif);
	$('#frmWal').ajaxSubmit({
		target: '#company-wall-tab',
		success:    function(text,status) { 
			$('#frmWal').clearForm();
		} 
	});
}


function nextPage(limit, receiver_id){
	$('#company-wall-tab').html(load_gif);
	$('#currPage').html(limit);
	$.ajax({
		type:'POST',
		url:'community-wall.php',
		data:'action=getWall&limit='+limit+"&paging=true&receiver_id="+receiver_id,
		success: function(data){
			$('#company-wall-tab').html(data);
		}
	});
}

function delWall(id, del,receiver_id){
	if(id){
		if(receiver_id === undefined) { receiver_id = ''; }
		var currPage = parseInt(document.getElementById('currPage').innerHTML);
		$("#wall-"+id).fadeOut();
		$.ajax({
			type:'POST',
			url:'community-wall.php',
			data:'action=delWall&id='+id+'&limit='+currPage+'&deleteAs='+del+'&receiver_id='+receiver_id,
			success: function(data){
				$('#company-wall-tab').html(data);
			}
		});
	}
}

function contactPoster(id, type){
	if(type == "company"){
		var updateTab = '#TabbedPanels1-TabbedPanels1';
		getUnreadMessages();
	}
	else{
		var updateTab = "#company-investment-info";
		$('#TabbedPanels1').hide();
	}
	$(updateTab).html(load_gif);
	$.ajax({
		type:'POST',
		url:'message-center.php',
		data:'action=contactPoster&id='+id+'&type='+type,
		success: function(data){
			$(updateTab).html(data);
		}
	});
}

function animCollapsible(element){
	$(element).next().toggle('slow');
	$(element).next().next().toggle('slow');
	$(element).prev().prev().toggle('slow');
	$(element).prev().toggle('slow');
}