function closeWindow() {
   top.window.close();
}

$(document).ready(function()
{
	$(".entry-detail-checkbox").mouseover(function () {
		index = this.id.split('__')[1];
	  	$(this).addClass("searchResults-item-link_hover");
	}).mouseout(function () {
		index = this.id.split('__')[1];
	  	$(this).removeClass("searchResults-item-link_hover");
	}).click(function () {
		index = this.id.split('__')[1];
		//css
	  	$(this).addClass("searchResults-item-link_selected");
		return true;
	});

	$(".searchResults-item .entry_checkbox").mouseover(function () {
		index = this.id.split('__')[1];
	  	$('.searchResults-item-link', this.parentNode).addClass("searchResults-item-link_hover");
	}).mouseout(function () {
		index = this.id.split('__')[1];
	  	$('.searchResults-item-link', this.parentNode).removeClass("searchResults-item-link_hover");
	}).click(function () {
		index = this.id.split('__')[1];		
		//css
		if ($('input[type=checkbox]', this).attr('checked')) {			
			$('.searchResults-item-link', this.parentNode).addClass("searchResults-item-link_marked");
			$('.entry_checkbox', this.parentNode).addClass("entry_checkbox_marked");
			$('#marked_counter_value').html(parseInt($('#marked_counter_value').html())+1);
			return true;
		} else {					
	  		$('.searchResults-item-link', this.parentNode).removeClass("searchResults-item-link_marked");
	  		$('.entry_checkbox', this.parentNode).removeClass("entry_checkbox_marked");
	  		var result = parseInt($('#marked_counter_value').html())-1;
	  		if(!result || result < 0) { result = '0'; }
	  		$('#marked_counter_value').html(result);
	  		//$('input[type=checkbox]', this).attr('checked', false);
	  		return true;
	  	}		
	});

	$(".searchResults-item-link").mouseover(function () {
		index = this.id.split('__')[1];
	  	$(this).addClass("searchResults-item-link_hover");
	}).mouseout(function () {
		index = this.id.split('__')[1];
	  	$(this).removeClass("searchResults-item-link_hover");
	}).click(function () {
		index = this.id.split('__')[1];
		//css
		$(".searchResults-item-link").removeClass("searchResults-item-link_selected")
	  	$(this).addClass("searchResults-item-link_selected");		
	  	// checkbox
	  	//indexString = '000000'.substr(index.length) + index;
	    //$('input[name=PageController__hostrequest__PageRequestCollection__landingpage__ViewEntryList__'+indexString+'__XTRRowSelected]').each(function() {
	    //	this.checked = true;
	    //});
	    return true;
	});
	
});


function field_addCSSClassName(object, className) {
    object.className = object.className + ' ' + className;
}

function field_removeCSSClassName(object, className) {
    classArray = object.className.split(" ");
    object.className = '';
    for(i=0;i<classArray.length;i++) {
        if (classArray[i] != className) {
            object.className = object.className + ' ' + classArray[i];
        }
    }
    return;
}

function pagingSwitchPage(step) {
	pageNo    = parseInt($('div.paging td.caption b.pageno').html()) + step;
	pageCount = parseInt($('div.paging td.caption b.pagecount').html());
	if (pageNo < 1) {
		pageNo = pageCount;
	} else if (pageNo > pageCount) {
		pageNo = 1;
	}
	
	
	$('.searchResults').css('display', 'none');
	$('#searchResults-'+pageNo).css('display', 'block');
	
	$('div.paging td.caption b.pageno').html(pageNo)
}

function pagingNext() {
	pagingSwitchPage(1);
}

function pagingPrevious() {
	pagingSwitchPage(-1);
}

function fieldDatePicker_open(fieldUniqueId, args) {
	$.plugin('datepicker', function () {
		args.createButton = false;
		$('input[name=\''+fieldUniqueId+'\']').datePicker(args).dpSetOffset(25, 60).dpDisplay();
	});
	return void(0);
}


function viewAddEvents(uniqueId) {
	// status
	$('#'+uniqueId+' div.view-status-first-message a').mouseover(function () {
		$('div#'+uniqueId+'-status').addClass('view-status-over').removeClass('view-status-out');
		$('div#'+uniqueId+'-status  div.view-status-other-messages').css('display', 'block').css('position', 'relative');
	}).mouseout(function () {
		$('div#'+uniqueId+'-status').addClass('view-status-out').removeClass('view-status-over');
		$('div#'+uniqueId+'-status  div.view-status-other-messages').css('display', 'none').css('position', 'abosulte');
	});
	$('#'+uniqueId+' div.view-status-other-messages').mouseover(function () {
		$('div#'+uniqueId+'-status').addClass('view-status-out').removeClass('view-status-over');
		$('div#'+uniqueId+'-status  div.view-status-other-messages').css('display', 'none').css('position', 'abosulte');
	});
}

