function explode( delimiter, string ) {
	
	// http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: kenneth
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
 
	var emptyArray = { 0: '' };
 
    if ( arguments.length != 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
 
    return string.toString().split ( delimiter.toString() );
}


function getDayOfWeek( dateObject )
{
	var dayNames = new Array( 'Sunday', 'Monday','Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
	return dayNames[dateObject.getDay()];
	
}

function attachTrimButton( elID, trimValue)
{
	var el = document.getElementById(elID);

	// get parent element x and y offset
	
   	var elWidth = el.offsetWidth;
	var elHeight = el.offsetHeight;

	var PixelAmtX = el.offsetLeft;
	var PixelAmtY = el.offsetTop;

	while( (el.tagName != 'BODY') && (el.tagName != 'HTML') )
	{
	  el = el.offsetParent;
	  PixelAmtX += el.offsetLeft;
	  PixelAmtY += el.offsetTop;
    }

	// create the trim link
	var trimLink = 'javascript: trimText( \'' + elID + '\', '+ trimValue + ' );';	
	
	//create the trim button div
	document.writeln('<div id="trimButton" class="trimButton"><a href="' + trimLink + '" title="Trim text to ' + trimValue + ' characters">Trim</a></div>');
	
	//position the trim button div
	var trimButton = document.getElementById('trimButton');
	var trimButtonX = PixelAmtX //+ elWidth - trimButton.offsetWidth ;
	var trimButtonY = PixelAmtY //+ elHeight + 4;

	//alert(trimButtonX);
	trimButton.style.left = trimButtonX + 'px';
	trimButton.style.top = trimButtonY + 'px';
	trimButton.style.position = 'absolute';
}

function trimText( elID, trimValue )
{
	var el = document.getElementById(elID);	
	var shortdescText = el.value;
	var charsToCopy = trimValue
	
	if ( shortdescText.length > charsToCopy )
	{
		shortdescText = shortdescText.substring(0, charsToCopy);
		shortdescText = shortdescText.replace(/\w+$/, '');
		el.value = shortdescText + "...";
	}
	else
	{
		alert('Not enough characters to trim.');
	}

}

/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}




function ajaxCall( pageUrl, contentElement, loadingHTML )
{
	$(contentElement).ajaxStart(function(){
	   $(this).html(loadingHTML);
	});
	
	$.ajax({
	  url: pageUrl,
	  dataType:"html",
	  type: "get",
	  cache: false,
	  success: function(html){
		$(contentElement).html(html);
	  }
	});
}


function getSiteRoot()
{
	var theURLPreffix = document.location.href.split( 'riverraft' )[0];
	var theURLSuffix = document.location.href.split( theURLPreffix )[1];
	var theSiteName = theURLSuffix.split( '/' )[0];
	return( theURLPreffix + theSiteName );

}


function filterSearchResults( filterName )
{
    $( 'ul.pageMenuItemChildren li a' ).removeClass( 'selected' );
    $( 'ul.pageMenuItemChildren li .search_' + filterName ).addClass( 'selected' );
    if( $( 'ul.pageMenuItemChildren li' ).length > 2 )
        $( 'ul.pageMenuItemChildren li.extra' ).show();
    
    //$( '#searchResults .searchResultItem' ).hide().animate({'opacity': 0}, 0, function(){});
    //$( '#searchResults .search_' + filterName ).show().animate({'opacity': 1}, 500, function(){});
    $( '#searchResults .searchResultItem' ).hide();
    $( '#searchResults .search_' + filterName ).show();
}

function showAllSearchResults()
{
    $( 'ul.pageMenuItemChildren li a' ).removeClass( 'selected' );
    $( 'ul.pageMenuItemChildren li.extra' ).hide();
    
    //$( '#searchResults .searchResultItem' ).hide().animate({'opacity': 0}, 0, function(){});
    //$( '#searchResults .searchResultItem' ).show().animate({'opacity': 1}, 500, function(){});
    $( '#searchResults .searchResultItem' ).hide();
    $( '#searchResults .searchResultItem' ).show();
}


function showContactInfo( articleName )
{
    $( 'ul.pageMenuItemChildren li a' ).removeClass( 'selected' );
    $( 'ul.pageMenuItemChildren li .contact_' + articleName ).addClass( 'selected' );
        
    $( '#contactText .contactArticleItem' ).hide();
    $( '#contactText .contact_' + articleName ).show();
    
    var formAction = langRoot + 'contact/';
    var newAction = formAction + articleName + '#contact_form';
    $( '#cForm' ).attr( 'action', newAction );
    
    var domeniu = $( 'ul.pageMenuItemChildren li a.selected').text();
    $( '#d_domeniu option:selected' ).removeAttr( 'selected' );
    $( '#d_domeniu' ).val( articleName ).attr( 'selected', 'selected' );
    $( '#d_domeniu' ).customSelect( 'destroy' ).customSelect();
}

function displayVersionError()
{
    drawOverlayWindow( 400, 250 );
    $( '#overlayWindow .oTitle' ).html( 'Missing version' );
}

function drawOverlayWindow( width, height )
{
    // overlay div 100% covering the screen
    
    $( '#overlay' ).fadeTo( 'fast', 0.3 );
    
    // overlay window itself
    
    $( '#overlayWindow' ).css( { 
        'display': 'block',
        'top': '50%',
        'left': '50%',
        'height': height + 'px',
        'width': width + 'px',
        'margin': '-' + height/2 + 'px auto 0 -' + width/2 + 'px',
        'z-index': 1002
    });
    
    var oWidth = width - 70; // window is 26px padded
    $( '.oHeaderC, .oContentC, .oFooterC' ).css({ 'width' : oWidth + 'px' });
    var oHeight = height - 70;
    $( '.oContentL, .oContentC, .oContentR' ).css({ 'height' : oHeight + 'px' });
    
    //size iframe & position underneath (prevent rendering of select elements in IE)
    
    $( '#oIframe' ).css( { 
        'display': 'block',
        'left' : $( '#overlayWindow' ).offset().left + 'px',
        'top' : $( '#overlayWindow' ).offset().top + 'px',
        'width' : width +'px',
        'height' : height +'px',
        'z-index': 1001
    });
}
