$.include("/lib/js/jquery/ui/ui.core.js");
$.include("/lib/js/jquery/ui/ui.tabs.js");
$.include("/lib/js/jquery/plugins/jquery.pager.js");
$.include("/lib/js/jquery/plugins/jquery.treeview.js");
$.include("/lib/js/jquery/plugins/jquery.cookie.js");
$.include("/lib/js/jquery/plugins/jquery.url.packed.js");
$.include("/lib/js/jquery/plugins/jquery.cycle.all.min.js");
$.include("/lib/js/jquery/plugins/jquery.tablesorter.min.js");
$.include("/lib/js/jquery/plugins/jquery.tablesorter.pager.js");

$(function(){init();});

function init()
{
	autoOpenWikiPage();
	$inbox = $('#inbox').html();
	$outbox = $('#outbox').html();
	$('#menu a').each(function(){if($(this).attr('href') == $.url.attr('relative').substring(0, $(this).attr('href').length)) $(this).addClass('active');});
	$('#banner').cycle({timeout:7000});
	$('#browser').treeview({persist:"cookie",collapsed:true,animated:"fast"});
	$('#pagination').pager("li.page",{navClass:"nav",height:"auto"});
	$('#searchWikis').pager("li.page",{navClass:"nav",height:"auto"});
	$('#searchUsers').pager("li.page",{navClass:"nav",height:"auto"});
	$('#searchPages').pager("li.page",{navClass:"nav",height:"auto"});
	$('#notice').show(function(){$('<div id="alert-message"><img src="/images/warning.png" alt="Waarschuwing!" /> Gebruiker niet gevonden!</div>').insertAfter( $(this) ).fadeIn('slow').animate({opacity: 1.0}, 3000).fadeOut('slow', function() {$(this).remove();});});
	$('#alert').show(function(){$('<div id="alert-message"><img src="/images/warning.png" alt="Waarschuwing!" /> U dient eerst in te loggen.</div>').insertAfter( $(this) ).fadeIn('slow').animate({opacity: 1.0}, 3000).fadeOut('slow', function() {$(this).remove();});});
	$('#success').show(function(){$('<div id="success-message"><img src="/images/success.png" alt="Success!" /> Gegevens zijn aangepast!</div>').insertAfter( $(this) ).fadeIn('slow').animate({opacity: 1.0}, 3000).fadeOut('slow', function() {$(this).remove();});});
	$('#userprofile-tabs').tabs({cookie:{expires:30}});
	$('#chapterList').change(function(){changeWikiChapter($(this));});
	$('#pageList').change(function(){changeWikiPage($(this));});
	$('#singleswitch').click(function(){$(".image").hide();$(".desc").hide();});
	$('#compactswitch').click(function(){$(".image").hide();$(".desc").show();});
	$('#fullswitch').click(function(){$(".image").show();$(".desc").show();});
	$('.tablesorter').tablesorter({widgets:['zebra'],headers:{3:{sorter:false}}});
	$('#inbox').tablesorterPager({container: $(".pager-inbox"), positionFixed: false });
	$('#outbox').tablesorterPager({container: $(".pager-outbox"), positionFixed: false });	
	thickboxResize();
}
	
function goTo(url){document.location.href = url;}
function scrollWin(){$('html, body').animate({scrollTop: $("#header").offset().top}, 400);}
function setFontSize(size){$(".page").css("font-size",size);}

tinyMCE.init({
	mode: "textareas",
	editor_selector: "mceSimple",
	width : "320",
	theme: "advanced",
	skin: "o2k7",
	plugins: "paste,emotions",
	language: "nl",
	theme_advanced_toolbar_location: "top",
	theme_advanced_toolbar_align: "left",
	theme_advanced_buttons1: "bold,italic,underline,|,charmap,|,link,unlink,|,pastetext,pasteword,removeformat,cleanup",
 	theme_advanced_buttons2: "",
	relative_urls : true,
	content_css: "/lib/css/tinymce.css"
});

tinyMCE.init({
	mode: "textareas",
	editor_selector: "mceSimpleDevelop",
	width : "460",
	height: "200",
	theme: "advanced",
	skin: "o2k7",
	plugins: "media",
	language: "nl",
	theme_advanced_toolbar_location: "top",
	theme_advanced_toolbar_align: "left",
	theme_advanced_buttons1: "bold,italic,underline,|,charmap,|,link,unlink,|,image,media,|,removeformat,cleanup,|,code",
 	theme_advanced_buttons2: "",
	file_browser_callback: "flexFilemanager",
	context: "user",
	relative_urls : true,
	remove_script_host: false,
	convert_urls : false,
	content_css: "/lib/css/tinymce.css"
});

tinyMCE.init({
	mode: "textareas",
	editor_selector: "mceAdvancedNoTable",
	width: "442",
	height: "200",
	theme: "advanced",
	skin: "o2k7",
	plugins: "paste,emotions",
	language: "nl",
	theme_advanced_toolbar_location: "top",
	theme_advanced_toolbar_align: "left",
	theme_advanced_buttons1: "bold,italic,underline,|,justifyleft,justifycenter,justifyright,|,bullist,|,outdent,indent,|,pastetext,pasteword,removeformat,cleanup,|,charmap,|,link,unlink,image,|,emotions",
	theme_advanced_buttons2: "",
	theme_advanced_buttons3: "",
	relative_urls : true,
	content_css: "/lib/css/tinymce.css"
});

tinyMCE.init({
	mode: "textareas",
	editor_selector: "mceAdvanced",
	width : "600",
	theme: "advanced",
	skin: "o2k7",
	plugins: "paste,table",
	language: "nl",
	theme_advanced_toolbar_location: "top",
	theme_advanced_toolbar_align: "left",
	theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,|,pastetext,removeformat,cleanup,|,charmap,|,link,unlink,image,|,forecolor,backcolor",
	theme_advanced_buttons2: "tablecontrols",
	theme_advanced_buttons3: "",
	relative_urls : true,
	content_css: "/lib/css/tinymce.css"
});

tinyMCE.init({
	mode: "textareas",
	editor_selector: "mceWikiPage",
	width : "700",
	height: "350",	
	theme: "advanced",
	skin: "o2k7",
	plugins: "paste,table,emotions",
	language: "nl",
	theme_advanced_toolbar_location: "top",
	theme_advanced_toolbar_align: "left",
	theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,|,pastetext,removeformat,cleanup,|,charmap,|,link,unlink,|,image,|,forecolor,backcolor,|,emotions",
	theme_advanced_buttons2: "tablecontrols",
	theme_advanced_buttons3: "",
	relative_urls : true,
	content_css: "/lib/css/tinymce.css"
});

$(window).bind('resize', thickboxResize );

function thickboxResize(){
	var boundHeight = 530; // min height
	var boundWidth = 400; // min width
	var viewportWidth = (self.innerWidth || (document.documentElement.clientWidth || (document.body.clientWidth || 0)))
	var viewportHeight =(self.innerHeight || (document.documentElement.clientHeight || (document.body.clientHeight || 0)))
	$('a.autoresize').each(function(){
		$el = $(this);
		var text = $el.attr("href");
		text = text.replace(/height=[0-9]*/,'height=' + Math.round(viewportHeight * .9)).replace(/width=[0-9]*/,'width=' + Math.round(viewportWidth * .9));
		if ( viewportHeight < boundHeight)
		{
			text = text.replace(/height=[0-9]*/,'height=' + boundHeight);
		}
		if ( viewportWidth < boundWidth)
		{
			text = text.replace(/width=[0-9]*/,'width=' + boundWidth);
		}
		$el.attr("href", text);
	});
}

function toggleWiki(id)
{
	$('#'+id).next('ul').toggle();
	if($('#'+id).next('ul').css("display") == "block")
	{
		$('#img_'+id).attr("src","/lib/images/icons/folder_open.gif");
	}
	if($('#'+id).next('ul').css("display") == "none")
	{
		$('#img_'+id).attr("src","/lib/images/icons/folder_closed.gif");
	}
}

// a generic function to toggle
function toggle(id) {
$("#"+id).toggle();
}

function showLoader(){$(".save-button").css({backgroundImage:"url('/lib/images/loading_circleball_24.gif')"});}
function confirmDeleteBlogItem(id) {if (confirm("Weet u het zeker?")){document.location.href = "/?event=user.blog.delete&id="+id;}}
function confirmDeleteNewsItem(newsId, teamId) {if (confirm("Weet u het zeker?")){document.location.href = "/?event=news.item.delete&nId="+newsId+"&id="+teamId;}}
function confirmDeleteNewsComment(commentId, newsId){if (confirm("Weet u het zeker?")){document.location.href = "/?event=news.comment.remove&commentId="+commentId+"&id="+newsId;}}
function confirmDeleteTeamAgenda(teamId, eventId) {if (confirm("Weet u het zeker?")){document.location.href = "/?event=team.agenda.delete&id="+teamId+"&eId="+eventId;}}
function confirmDeleteTeamMember(teamId, userId) {if (confirm("Weet u het zeker?")){document.location.href = "/?event=team.member.delete&id="+teamId+"&uId="+userId;}}

function editUser(userId) {
	window.parent.location = "/?event=user.info.edit&id="+userId;
	window.parent.tb_remove();		
}

// function to active or deactive user's status
function changeUserStatus(userId) {
	document.location.href = "/?event=user.change.status&userId="+userId;
}

/* wiki */
var dataCount = 0;
var dataCalls = 1;
var wikiIds = new Array();
var boekIds = new Array();
function changeWikiChapter(obj){document.location.href = "/?event=wiki.chapter.view&id="+obj.val();}
function changeWikiPage(obj){document.location.href = "/?event=wiki.page.view&id="+obj.val();}
function autoOpenWikiPage() {
	var url = document.location.href;
	var url = url.split("pageId=");
	if(url.length>1){tb_show("test","/index.cfm?event=wiki.page.view&id="+url[1]+"&KeepThis=true&TB_iframe=true&width=850&height=500",false);}
}

function getWikiChildren(boekId,treeId){
	$('#img_'+treeId).attr("src","/lib/images/loading_circleball_16.gif");
	if((!!$.inArray(treeId, wikiIds) && treeId) || (!!$.inArray(boekId, boekIds)&&!treeId))
	{
		wikiIds.push(treeId);
		boekIds.push(boekId);
		$.post('/?event=get.wiki.children.list.ajax',{'id':boekId,'treeId':treeId},function(data){
			if(treeId){handleWikiChildren(data,treeId);}
			else{handleWikiChildren(data,boekId);}
		},'json');
	}
}

function handleWikiChildren(data,treeId){
	$('#img_'+treeId).attr("src","/lib/images/icons/folder_open.gif");
	var number = ++dataCount;//first add one to dataCount and then stores the it in number
	var list = '<ul>';
	for(i=0; i<data.ROWCOUNT; i++){
		list += '<li class="first" ><a id="'+data.DATA.ID[i]+'" ';
		if(!data.DATA.TYPEID[i] || data.DATA.HASSUBACTIVITIES[i]){
			if(currentWiki == 0)
			{
				list += 'href="javascript:getWikiChildren('+data.DATA.WIKIID[i]+','+data.DATA.ID[i]+');"><img src="/lib/images/icons/folder_closed.gif" alt="" id="img_'+data.DATA.ID[i]+'" /> ';
			}
			else
			{
				getWikiChildren(data.DATA.WIKIID[i],data.DATA.ID[i]);
				dataCalls++;
				list += 'href="javascript:toggleWiki('+data.DATA.ID[i]+');"><img src="/lib/images/icons/folder_closed.gif" alt="" id="img_'+data.DATA.ID[i]+'" /> ';
				wikiParent.push(new Array(data.DATA.ID[i],data.DATA.PARENTID[i], 1)); 
			}
		}
		else{
			wikiParent.push(new Array(data.DATA.ID[i],data.DATA.PARENTID[i], 0));
			list += 'href="/?event=wiki.page.view&id='+data.DATA.ID[i]+'"';
			if(getURLParam('id') == data.DATA.ID[i]) list += ' class="active"';
			list += '><img src="/lib/images/icons/document.png" alt="" /> ';
		}
		list += data.DATA.TITLE[i];
		list += '</a></li>';
	}
	list += '</ul>';
	$tree = $('#'+treeId);
	$tree.attr('href','javascript:toggleWiki('+treeId+');');
	$tree.parent('li').append(list);
	if(number >= dataCalls && currentWiki != 0)
	{
		for(var i = 0; i < wikiParent.length; i++)
		{
			if(wikiParent[i][2])
			{
				toggleWiki(wikiParent[i][0]);
			}
		}
		var count = 0;
		var openParent = currentWiki;
		if(wikiParent.length && currentWiki != 0)
		{
			while(true)
			{
				if(wikiParent[count][0] == openParent)
				{
					toggleWiki(wikiParent[count][1]);
					openParent = wikiParent[count][1];
					wikiParent.splice(count, 1);
					count = 0;
					if(wikiParent.length == 0)
					{
						break;
					}
				}
				++count;
				if(count >= wikiParent.length)
				{
					break;
				}
			}
			$("#wiki").show();
			$(".wikiTreePlaceHolder").hide();
		}
	}
}

function getURLParam(strParamName){
  var strReturn = '';
  var strHref = window.location.href;
	var loc = strHref.indexOf('?');
  if(loc > -1 ){
    var aQueryString = strHref.substr(loc).toLowerCase().split('&');
    for(var iParam = 0; iParam < aQueryString.length; iParam++){
      if(aQueryString[iParam].indexOf(strParamName.toLowerCase() + '=') > -1 ){
        var aParam = aQueryString[iParam].split('=');
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}

function confirmDeleteWiki(teamId, title, id){if(confirm("Weet u het zeker wiki " + title + "?\nWaarschuwing: alle inhoud en mappen in de map worden verwijderd")){document.location.href = "/?event=wiki.delete&id="+teamId+"&wikiId="+id;}}

function confirmDeleteWikiItem(title, isFolder, pageId, id, treeId) {
	var message = "Weet u het zeker " + title + "?";
	if (isFolder) {	message += "\nWaarschuwing: alle inhoud en mappen in de map worden verwijderd";}
	if(confirm(message)){document.location.href = "/?event=wiki.item.delete&pageId="+pageId+"&id="+id+"&treeId="+treeId;}
}
function deleteWikiItem(pageId, id, treeId) {document.location.href = "/?event=wiki.item.delete&pageId="+pageId+"&id="+id+"&treeId="+treeId;}
function confirmDeleteWikiComment(commentId, wikiId) {if (confirm("Weet u het zeker?")){document.location.href = "/?event=wiki.item.comment.remove&commentId="+commentId+"&id="+wikiId;}}
function deleteWikiComment(cId, wId) {document.location.href = "/?event=wiki.item.comment.remove&commentId="+cId+"&id="+wId;}

/* delete newsletter */
function confirmDeleteNewsletter(newsletterId,teamid) {if (confirm("Weet u het zeker?")){document.location.href = "/?event=newsletter.delete&newsletterId="+newsletterId+"&id="+teamid;}}

/* form validation */
var error = false;
var alerttext = "";
function validate_required(field,alerttxt){
	with(field){
		if(value==null || value==""){alerttext += alerttxt+"\n"; error=true;}
	}
}
function validate_radio(field,alerttxt){
	var cnt = -1;
	for(var i=field.length-1; i>-1; i--){
		if(field[i].checked){cnt=i; i=-1;}
	}
	if(cnt < 0){alerttext += alerttxt+"\n"; error=true;}
}
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}
function validate_email(field,alerttxt){
	with(field){
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if(apos< 1|| dotpos-apos<2){alerttext += alerttxt+"\n"; error=true;}
	}
}
function validate_form(thisform){
	with(thisform){
		validate_email(email,"U heeft geen (geldig) emailadres ingevuld.");
		validate_required(bericht,"U heeft geen bericht ingevuld.");
	}
	if(error){alert(alerttext); alerttext=""; error=false; return false;}
	else{return true;}
}
function validate_comparison(field1,field2,alerttxt){with(field1){if(value != field2.value){alerttext += alerttxt+"\n"; error=true;}}}

function validateDate(dateField) {	
	if (!isDateValid(dateField.value)){
		alert("Ongeldige Datumnotatie: " + dateField.value);
    dateField.focus();
	}	
}
function isDateValid(date) {	
	// regular expression to match required date format
    re = /^\d{1,2}\-\d{1,2}\-\d{4}$/;
    if(date != '' && !date.match(re))     
    return false;
    else
		return true;
}
function trim(value){return value.replace(/^\s+/,'').replace(/\s+$/,'');}//removes leading and trailing spaces

//show the subfolders/pages of a folder off the team pages.
function teamPagesToggle(id)
{
	el = document.getElementById("child_"+id);
	imgel = document.getElementById("img_"+id);
	if(el.style.display=='block')
	{
		el.style.display='none'
		imgel.src='/images/arrow-right.png';
	}
	else if(el.style.display=='none' || el.style.display=='')
	{
		el.style.display='block'
		imgel.src='/images/arrow-down.png';
	}
}

function checkbox(id, toggleBoxesOpt)
{
	$el = $("#"+id);
	$el.attr("checked",!$el.attr("checked"));
	if(toggleBoxesOpt)
	{checkBoxes($el.attr("name"));}
}

function checkBoxes(name)
{
	var items = $('input[name="'+name+'"]');
	var itemsLen = items.length;
	var checked = 0;
	for (var i=0; i<itemsLen; i++) {
		if(items[i].checked)
		{
			checked++;
		}
	}
	$('input[name="chk_selectItems"]')[0].checked = (checked >= itemsLen/2);
}

function toggleBoxes(selItms, checkboxName) {	
	var items = $('input[name="'+checkboxName+'"]');
	var itemsLen = items.length;
	for (var i=0; i<itemsLen; i++) {
		if(!items[i].disabled)
		{
			items[i].checked = $(selItms).attr("checked");
		}
	}
}

function TrackCount(fieldObj,countFieldName,maxChars) {
	var countField = eval("fieldObj.form."+countFieldName);
	var diff = maxChars - fieldObj.value.length;
	if (diff < 0)
	{
		fieldObj.value = fieldObj.value.substring(0,maxChars);
		diff = 0;
	}
	countField.value = diff;
}
	
function LimitText(fieldObj,maxChars) {
	var result = true;
	result = !(fieldObj.value.length >= maxChars);
	if (window.event){window.event.returnValue = result;}
	return result;
}

function setImageUrl(data) {
	data = unescape(data);	
	data = eval('('+data+')');	
	$preview = $("#preview");
	$("#imageField").attr("value",data.filepath);
	if($preview != null){$preview.attr("src",data.filepath)}
}
	
function CF_RunContent(src){document.write(src);}

var isInputValid = false;	
function validateEventDetails(){
	var agenda = document.frmTeamAgenda;
	var titleVal = agenda.title.value;
	if(titleVal == ''){
		alert('Event titel is niet gespecificeerd. Alsjeblieft! Voer een geldige waarde');
		return false;
	}
	var sYearVal = agenda.sYear.value;
	var sMonthVal = agenda.sMonth.value;
	var sDayVal = agenda.sDay.value;
	var sHourVal = agenda.sHour.value;
	var sMinVal = agenda.sMinute.value;
	var sDate = new Date(sYearVal, sMonthVal, sDayVal, sHourVal, sMinVal);
	var eYearVal = agenda.eYear.value;
	var eMonthVal = agenda.eMonth.value;
	var eDayVal = agenda.eDay.value;
	var eHourVal = agenda.eHour.value;
	var eMinVal = agenda.eMinute.value;
	var eDate = new Date(eYearVal, eMonthVal, eDayVal, eHourVal, eMinVal);
	if(sDate > eDate){
		alert('De startdatum is later dan de einddatum, AUB! Voer een geldige waarde');
		return false;
	}
	isInputValid = true;
	return true;
}

function cancelApproval() {document.location.href = "/?event=wiki.folder.edit.view&id=#page.getWiki().getId()#&treeId=0";}

var isInputValid = false;
function validateInput() {
	var nameField = $("#nameField");
	if (nameField.value.length < 1 || trim(nameField.value).length < 1) {
		alert("Naam invoeren");
		nameField.focus();
		return false;
	}	
	isInputValid = true;
	return true;		
}

function addNewFolder(wikiID, zindex, pageID, superParentID) {
	var actionURL = "/?event=wiki.folder.add.view&id="+wikiID+"&zIndex="+zindex;		
	if(pageID != 0)
	{
		actionURL += "&treeId="+pageID+"&superParentId="+superParentID;
	}
	else
	{
		actionURL += "&treeId=0";		
	}				
	document.location.href = actionURL;
}	

function addNewPage(editPageUrl, wikiID, zindex, pageID, superParentID) {
	var actionURL = editPageUrl+"&id="+wikiID+"&zIndex="+zindex;	
	if(pageID != 0)
	{
		actionURL += "&treeId="+pageID+"&superParentId="+superParentID;						 
	}							
	document.location.href = actionURL;
}

function confirmDeleteTeam(teamId){
	if (confirm("Weet u het zeker?")){
		document.location.href = "/?event=team.delete&teamId="+teamId;
	}
}

function addNew()
{
	if($(".new").attr("selected"))
	{
		$(".newCat").show();
	}
	else
	{
		$(".newCat").hide();
	}
}

function confirmDeleteCategorie(catId){if(confirm("Weet u het zeker?")){document.location.href = "/?event=news.categorie.delete&catId="+catId;}}

function confirmDeleteMessage(id,mode){if(confirm("Weet u het zeker?")){deleteMessage(id,mode);}}

function deleteMessage(id,mode)
{
	el = $("#img_"+id+mode);
	el.html('<img src="/lib/images/loading_circleball_16.gif" alt="Verwijderen" />');
	el.removeAttr("href");
	$.post("/?event=delete.message",{'id':id,'mode':mode},function(data){
		responce = data.split(",")//splits the response, so you can acces the id and the mode.
		if(responce[1] == 1)
		{
			table = $('#inbox');//stores the inbox object in the table var
			table.html($inbox);//replaces the table with the one stored in memory from before the paging.
			$(".pager-inbox .next").unbind('click');//remove the click handler
			$(".pager-inbox .prev").unbind('click');//remove the click handler
			$(".pager-inbox .first").unbind('click');//remove the click handler
			$(".pager-inbox .last").unbind('click');//remove the click handler
		}
		else
		{
			table = $('#outbox');
			table.html($outbox);
			$(".pager-outbox .next").unbind('click');
			$(".pager-outbox .prev").unbind('click');
			$(".pager-outbox .first").unbind('click');
			$(".pager-outbox .last").unbind('click');
		}
		table.find("#"+responce[0]+responce[1]).remove(); //removes the row after it has been deleted in the database
		table.tablesorter({widgets:['zebra'],headers:{3:{sorter:false}}});//adds the table sorter
		if(responce[1] == 1)
		{
			$inbox = table.html();//stores the table html for later use
			table.tablesorterPager({container: $(".pager-inbox"), positionFixed: false });//adds the table pager
		}
		else
		{
			$outbox = table.html();
			table.tablesorterPager({container: $(".pager-outbox"), positionFixed: false });
		}
		$.include("/lib/js/jquery/plugins/jquery.thickbox.js");//to make the thickbox work again
	},'json');
}

function markMessage(id, read)
{
	$("#"+id+"_read").attr("src","/lib/images/loading_circleball_16.gif");
	$("#"+id+"_link").removeAttr("href");
	$.post('/?event=mark.message',{'id':id,'read':read},function(data){
			responce = data.split(",");
			$link = $("#"+responce[0]+"_link");
			$title = $("#"+responce[0]);
			text = $title.html();
			if(responce[1] == 0)
			{
				text = "<strong>"+text+"</strong>";
				$("#"+responce[0]+"_read").attr("src","/lib/images/icons/unread.png");
				$link.attr("href","javascript:markMessage("+responce[0]+",1)");
				$link.attr("title","Markeren als gelezen");
			}
			else if(responce[1] == 1)
			{
				text = text.replace("</strong>","").replace("<strong>","");//strips the strong tags from the tags
				$("#"+responce[0]+"_read").attr("src","/lib/images/icons/read.png");
				$link.attr("href","javascript:markMessage("+responce[0]+",0)");
				$link.attr("title","Markeren als ongelezen");
			}
			$title.html(text);
		},'json');
}
/* @author: Muhammad Haris (19-05-2010) */
function importFromLinkedIn() {
	var requestToken = "";
	if (confirm("Weet u zeker dat u wilt importeren uit LinkedIn?")) {
		callLinkedIn('');		
	}
}

function callLinkedIn(oauthVerifier) {
	
	$.get('/?event=user.import.linkedin',{'oauth_verifier':oauthVerifier},
		function(xml) {
			var redirectionURL = "";				
			
			$(xml).find('person').each(function() {
				redirectionURL = $(this).find('redirect').text();				
				
				if (redirectionURL.length < 1) {
					firstName = $(this).find('first-name').text();
					lastName = $(this).find('last-name').text();
					functie = $(this).find('headline').text();
					profiel = $(this).find('summary').text();
					expertise = $(this).find('specialities').text();
					mainAddress = $(this).find('main-address').text();
					
					/*$(this).find('educations').each(function() {
						
					});*/
					
					telephone = "";
					mobile = "";
					/*$(this).find('phone-numbers').each(function() {
						
					});*/
					
					dateOfBirth = "";
					$(this).find('date-of-birth').each(function() {
						dateOfBirth = $(this).find('day').text() + "-" +
									  $(this).find('month').text() + "-" +
									  $(this).find('year').text();
					});
					
					$("#firstname").val(firstName);
					$("#lastname").val(lastName);
					$("#role").val(functie);
					$("#profile").val(profiel);
					$("#expertise").val(expertise);
					$("#dateofbirth").val(dateOfBirth);
										
				}
			});			
				
			if (redirectionURL.length > 0) {					
				//tb_show("",redirectionURL,"");
				window.open(redirectionURL);
			}			
		},'xml');
}

/*  rating functions */

/**
* Function to get the rating of a particular item
* @itemId: the particular content id
* @moduleId: the module id, like NWS is for news
* 31-05-2010
* 
*/
function getRating(itemId, moduleId) {
	
	$.post('/?event=user.rating.ajax',{'itemId':itemId,'moduleId':moduleId},function(data){
		handleUserRating(data,itemId,moduleId);		
	},'json');
}

function handleUserRating(data, itemId, moduleId) {	
	var ratingValue = data.DATA.RATING;	
	
	if (ratingValue != "") {
		//$("#rating-star"+ratingValue).attr('checked',true);
		//$('input:radio[name=rating-star]').rating('select', 2);	
		
		$("input[@name='rating-star']").val(ratingValue);
		$("#rating-star"+ratingValue).attr("checked", "checked"); 
	}
	
	$("#rating_comments").val("");			
}

// funciton to save user rating
function saveRating(itemId, moduleId) {
	//showLoader();
	
	comments = $("#rating_comments").val();	
	ratingValue = $('input:radio[name=rating-star]:checked').val()
	
	$.post('/?event=save.user.rating.ajax',{'itemId':itemId,'moduleId':moduleId,'comments':comments,'rating':ratingValue},function(data){
		handleUserRating(data,itemId,moduleId);		
	},'json');
}