/*Javascript*/
function goBack(url){
	window.location.href=url;
}	

function changeClassName(divID, linkID, linkName){
	var divIDs = divID.substring(0,divID.lastIndexOf(":"));
	divTagCloud = document.getElementById(divIDs);
	arrLinkTagCloud = divTagCloud.getElementsByTagName('A');
	for ( y = 0; y< arrLinkTagCloud.length; y++ ) {
		
		if(arrLinkTagCloud[y].id==linkID){
			sClass = arrLinkTagCloud[y].className + " filter";
			arrLinkTagCloud[y].className = sClass;
		}else{
			sClass = arrLinkTagCloud[y].className
			if(sClass.indexOf(" filter")>-1){
				sClass = sClass.substring(0,sClass.indexOf(" filter"));
				arrLinkTagCloud[y].className = sClass
			}
		}
	}
}

function filterTagCloud(divID, linkID, linkName){
	var divIDs = divID.substring(0,divID.lastIndexOf(":"));
	divTagCloud = document.getElementById(divIDs);
	arrLinkTagCloud = divTagCloud.getElementsByTagName('A');
	for ( y = 0; y< arrLinkTagCloud.length; y++ ) {
		
		if(arrLinkTagCloud[y].id==linkID){
			arrLinkTagCloud[y].parentNode.style.display = "none"
			displayTagCloudFilter(arrLinkTagCloud[y].innerHTML)
		}else{
			arrLinkTagCloud[y].parentNode.style.display = "inline"
		}
	}
}

function displayTagCloudFilter(tag){
	document.getElementById("tag_filter").innerHTML = tag;
	document.getElementById("tag_filter_overview").style.display = "block"
}

function resetTagcloud(divID){
	divTagCloud = document.getElementById(divID);
	arrLinkTagCloud = divTagCloud.getElementsByTagName('A');
	for ( y = 0; y< arrLinkTagCloud.length; y++ ) {
		if(arrLinkTagCloud[y].parentNode.style.display == "none"){
			arrLinkTagCloud[y].parentNode.style.display = "inline"
		}
	}
	document.getElementById("tag_filter").innerHTML = ""
	document.getElementById("tag_filter_overview").style.display = "none"
}
function checkEnter(event) {
getEvent=event.keyCode;
if (getEvent == "13") {
startSearch();
return false;
} else {
return true;
}
}
function startSearch(){
	var q = document.getElementById('searchInput').value;
	window.location.href = '/'+dbPath+'/search.xsp?OpenXpage&q='+q;
}
/*TWITTER Scripts*/
function relative_time(time_value) {
  var values = time_value.split(" ");
  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
  var parsed_date = Date.parse(time_value);
  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
  delta = delta + (relative_to.getTimezoneOffset() * 60);

  if (delta < 60) {
    return 'less than a minute ago';
  } else if(delta < 120) {
    return 'about a minute ago';
  } else if(delta < (60*60)) {
    return (parseInt(delta / 60)).toString() + ' minutes ago';
  } else if(delta < (120*60)) {
    return 'about an hour ago';
  } else if(delta < (24*60*60)) {
    return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
  } else if(delta < (48*60*60)) {
    return '1 day ago';
  } else {
    return (parseInt(delta / 86400)).toString() + ' days ago';
  }
}	

var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0; 
function collapseBlock(katman){
 	if ( document.getElementById(katman) != null ) {
    		document.getElementById(katman).style.display='none'
    }
}

function restoreBlockRow(katman){
	if (isIE ){
		document.getElementById( katman ).style.display = 'inline'
	}else{
		document.getElementById( katman ).style.display = 'table-row'
	}
}

function restoreBlock(katman){
	document.getElementById(katman).style.display='block'
}
//ContentCommonFieldsContainer
function openFieldBlock(oLink){
	oImg = document.getElementById('img'+oLink.id)
	oImg.src = '/'+dbPath+'/minusButton.gif'
	oLink.onclick = function() { closeFieldBlock(this); };
	oLink.title = 'close panel';
	restoreBlock('ContentCommonFieldsContainer')
}

function closeFieldBlock(oLink){
	oImg = document.getElementById('img'+oLink.id)
	oImg.src = '/'+dbPath+'/plusButton.gif'
	oLink.onclick = function() { openFieldBlock(this); };
	oLink.title = 'open panel';
	collapseBlock('ContentCommonFieldsContainer')
}

/*WebChat - OCS code*/
$(function() {

            // Specify license Id
            var licenseId = '7E7204A5-34A3-483F-9D59-0E49D54A0408';
            // Number of milliseconds before a presence check is performed
            var presenceTimeout = 5000;

            // Find all the places where a webchat should be enabled
            $("div.chat").each(function() {
                $(this).webchat(licenseId,
                {
                    identifier: $(this).attr("identifier"),
                    displayName: 'Ik',
                    emptyInputText: 'stel uw vraag hier',
                    offlineText: 'er is momenteel niemand die u kan helpen.',
                    nameTimeSeperator: ' &gt; ',
                    showAvailableText: true,
                    availableText: 'bereikbaar per chat',
                    unavailableText: 'niet bereikbaar per chat',
                    collapsed: true,
                    showEmail: false
                });
            });
            
            $("div.chatOpen").each(function() {
                $(this).webchat(licenseId,
                {
                    identifier: $(this).attr("identifier"),
                    displayName: 'Ik',
                    emptyInputText: 'stel uw vraag hier',
                    offlineText: 'ik kan u momenteel niet helpen.',
                    nameTimeSeperator: ' &gt; ',
                    showAvailableText: true,
                    availableText: 'bereikbaar per chat',
                    unavailableText: 'niet bereikbaar per chat',
                    collapsed: false,
                    showEmail: false
                });
            });           

        });

   function makeid()
{
    var text = "";
    var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    for( var i=0; i < 5; i++ )
        text += possible.charAt(Math.floor(Math.random() * possible.length));

    return text;
}    
