// hide default value of textfields 
var swap_text_boxes = [];
function init_swap_text_boxes(){
  $('input[type=text][value]').each(function() {
    swap_text_boxes[$(this).attr('id')] = $(this).attr('value');
  });
  $('input[type=text][value]').bind('focus', function() {
    if ($(this).attr('ID') == 'txtsearch') {
      if($(this).val() == swap_text_boxes[$(this).attr('id')]) {
        $(this).val('');
      }
    }
  });
  $('input[type=text][value]').bind('blur', function() { 
    if ($(this).attr('ID') == 'txtsearch') {
      if($(this).val() == '') {
        $(this).val(swap_text_boxes[$(this).attr('id')]);
      }
    }
  });
}

$(document).ready(function(){
	
	init_swap_text_boxes();

	var usernames = new Array();

    $("span.loginstatus[@username]").each( function()
    {
        if ($(this).attr("username") != null && $(this).attr("username") != "")
        {
            usernames.push($(this).attr("username"));
        }
    });
    
    if (usernames.length > 0)
    {               
        $.ajaxSetup({ cache: false });
        $.getJSON("/_layouts/woonbronportal/userloginstatus.ashx", 
            { username: usernames.join(';')}, statusupdate);
    }
	
});

// Checks for Portal Search
$(document).ready(function(){
	
var bool = new Boolean(false)
	$("a[searchbuttonvalidate='true']").click(function(){
	
		if($("input[hiddenvalue='hiddenvalue_txtSearchBox']").attr('value') != ""){
			bool = true; 
		}

	if(bool == false){
 		$("#deletehiddenbutton").click();
		return false; 
	}
	});
});

// Employee Search
$(document).ready(function(){
	var bool = new Boolean(false)	

	$("a[searchbuttonvalidate='true']").click(function(){
		
	    if($("input[hiddenvalue='hiddenvalue_SRCH_Naam']").attr('value') != ""){
		    bool = true;
	    }

	    if($("input[hiddenvalue='hiddenvalue_SRCH_Department']").attr('value') != ""){
		    bool = true;
	    }
	    if($("input[hiddenvalue='hiddenvalue_SRCH_Functie']").attr('value') != ""){
		    bool = true;
	    }

	    if($("select[hiddenvalue='hiddenvalue_SRCH_Vestiging']").attr('value') != ""){
		    bool = true;
	    }
    	
	    if(bool == false){	
		    $("#deletehiddenbutton").click();
		    return false; 
	    }

    });

});

/*-----------------------------------------------------------------------------------------------*/
/*                                      SIMPLE jQUERY TOOLTIP                                    */
/*                                      VERSION: 1.1                                             */
/*                                      AUTHOR: jon cazier                                       */
/*                                      EMAIL: jon@3nhanced.com                                  */
/*                                      WEBSITE: 3nhanced.com                                    */
/*-----------------------------------------------------------------------------------------------*/

$(document).ready(function() {
	$('.tnhToolTip').hover(
		function() {
		this.tip = this.title;
		$(this).append(
			'<div class="tnhToolTipWrapper">'
				+'<div class="tnhToolTipTop"></div>'
				+'<div class="tnhToolTipMid">'
					+this.tip
				+'</div>'
				+'<div class="tnhToolTipBtm"></div>'
			+'</div>'
		);
		this.title = "";
		this.width = $(this).width();
		$(this).find('.tnhToolTipWrapper').css({left:this.width+12})
		$('.tnhToolTipWrapper').fadeIn(300);
	},
	function() {
		$('.tnhToolTipWrapper').fadeOut(100);
		$(this).children().remove();
			this.title = this.tip;
		}
	);
});

/*** Supertooltip ***/

function configureSuperTooltipStandard()
{
	$('.supertooltip span').css('visibility', 'hidden') 

	$('.supertooltip').each(function (i){
        $(this).hover(function() {
            $(this).find('span').css('visibility', 'visible')       
        },
            function() {
            $(this).find('span').css('visibility', 'hidden')       
        });                                              
    });
}

function configureSuperTooltip()
{
	$('.supertooltipError span.supertooltipErrorSpan').css('visibility', 'hidden') 

	$('.supertooltipError').each(function (i){
        $(this).hover(function() {
            $(this).find('span.supertooltipErrorSpan').css('visibility', 'visible')       
        },
            function() {
            $(this).find('span.supertooltipErrorSpan').css('visibility', 'hidden')       
        });                                              
    });
    
    $('.supertooltipError span').bgiframe();
}

$(document).ready(function() {
    configureSuperTooltipStandard();
});

(function($){$.fn.bgIframe=$.fn.bgiframe=function(s){if($.browser.msie&&/6.0/.test(navigator.userAgent)){s=$.extend({top:'auto',left:'auto',width:'auto',height:'auto',opacity:true,src:'javascript:false;'},s||{});var prop=function(n){return n&&n.constructor==Number?n+'px':n;},html='<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+'style="display:block;position:absolute;z-index:-1;'+(s.opacity!==false?'filter:Alpha(Opacity=\'0\');':'')+'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+'"/>';return this.each(function(){if($('> iframe.bgiframe',this).length==0)this.insertBefore(document.createElement(html),this.firstChild);});}return this;};})(jQuery);
/*** End of Supertooltip ***/

function showErrorTip(elementId, controlId){
	var offset = $("#" + controlId).offset();

$("#" + elementId).css({
		'left' : '450px',
		'top' : offset.top + 24,
		'position' : 'absolute',
		'height' : '100px',
		'width' : '300px'
	});

	$('div.tooltip').hide();
	$("#" + elementId + " div").addClass("content");
	$("#" + elementId).fadeIn();
}

function hideErrorTip(){
	$('div.tooltip').hide();
}

function showInfoTip(elementId, controlId){
	var offset = $("#" + controlId).offset();

	$("#" + elementId).css({ 
		'top' : offset.top + 14,
		//'left' : offset.left -440,
		//'margin-left' : '0px', 
		'left' : offset.left + 40,
		'position' : 'absolute',
		'height' : '100px',
		'width' : '300px'
	});

	$('div.tooltip').hide();
	$("#" + elementId + " div").addClass("content");
	$("#" + elementId).fadeIn();
}

function hideInfoTip(){
	$('div.tooltip').hide();
}

function statusupdate(result)
{
    for(var i = 0; i < result.length; i++)
    {
        var userName = result[i].userName;		    
        if (userName.length > 0)
        {
            var text = $("span[@username='" + userName + "']").attr("text");
            if (text == "" || text == null) 
                text = "Ja";
            if (result[i].IsLoggedIn)
            {		           
                $("span[@username='" + userName + "']").addClass("loggedin in").html(text);
            }
            else
            {
                $("span[@username='" + userName + "']").addClass("loggedout out");
            }
        }		    
    }
}

// custom textExtraction function for jQuery tablesorter
// used in TaskListAd (for dates) & SearchPerson (for lastnames)
function titleSorter(node) {
    if ($(node).hasClass('titlesort')) {
        return $(node).attr('title');
    } else {
        return $(node).text();
    }
}