
// function for showing and hiding default texts in inputs
function inputDefaultShowHide(inputId, defaultText, isBlurAction)
{
    var obj = document.getElementById(inputId);
    
    if (isBlurAction)
    {
        if (obj.value == "")
            obj.value = defaultText;
    }
    else
    {
        if (obj.value == defaultText)
            obj.value = "";
    }
}


// loading top articles movement functionality
jQuery(document).ready(function() {
    jQuery('#carouselList').jcarousel({
        vertical: false, //Specifies wether the carousel appears in horizontal or vertical orientation. Changes the carousel from a left/right style to a up/down style carousel.
        start: 1, //The index of the item to start with.
        offset: 1, //The index of the first available item at initialisation.
        scroll: 1, //The number of items to scroll by.
        visible: null, //If passed, the width/height of the items will be calculated and set depending on the width/height of the clipping, so that exactly that number of items will be visible.
        animation: "fast", //The speed of the scroll animation as string in jQuery terms ("slow" or "fast") or milliseconds as integer (See jQuery Documentation). If set to 0, animation is turned off.
        easing: null, //The name of the easing effect that you want to use (See jQuery Documentation).
        auto: 3, //Specifies how many seconds to periodically autoscroll the content. If set to 0 (default) then autoscrolling is turned off.
        wrap: "circular", //Specifies whether to wrap at the first/last item (or both) and jump back to the start/end. Options are "first", "last" or "both" as string. If set to null, wrapping is turned off (default). You can also pass "circular" as option to enable support for circular carousels. See the example Circular carousel on how to implement it.
        initCallback: null, //JavaScript function that is called right after initialisation of the carousel. Two parameters are passed: The instance of the requesting carousel and the state of the carousel initialisation (init, reset or reload)
        itemLoadCallback: null, //JavaScript function that is called when the carousel requests a set of items to be loaded. Two parameters are passed: The instance of the requesting carousel and the state of the carousel action (prev, next or init). Alternatively, you can pass a hash of one or two functions which are triggered before and/or after animation:
        itemFirstInCallback: null, //JavaScript function that is called (after the scroll animation) when an item becomes the first one in the visible range of the carousel. Four parameters are passed: The instance of the requesting carousel and the <li> object itself, the index which indicates the position of the item in the list and the state of the carousel action (prev, next or init). Alternatively, you can pass a hash of one or two functions which are triggered before and/or after animation:
        itemFirstOutCallback: null, //JavaScript function that is called (after the scroll animation) when an item isn't longer the first one in the visible range of the carousel. Four parameters are passed: The instance of the requesting carousel and the <li> object itself, the index which indicates the position of the item in the list and the state of the carousel action (prev, next or init). Alternatively, you can pass a hash of one or two functions which are triggered before and/or after animation:
        itemLastInCallback: null, //JavaScript function that is called (after the scroll animation) when an item becomes the last one in the visible range of the carousel. Four parameters are passed: The instance of the requesting carousel and the <li> object itself, the index which indicates the position of the item in the list and the state of the carousel action (prev, next or init). Alternatively, you can pass a hash of one or two functions which are triggered before and/or after animation:
        itemLastOutCallback: null, //JavaScript function that is called when an item isn't longer the last one in the visible range of the carousel. Four parameters are passed: The instance of the requesting carousel and the <li> object itself, the index which indicates the position of the item in the list and the state of the carousel action (prev, next or init). Alternatively, you can pass a hash of one or two functions which are triggered before and/or after animation:
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback}, //JavaScript function that is called (after the scroll animation) when an item is in the visible range of the carousel. Four parameters are passed: The instance of the requesting carousel and the <li> object itself, the index which indicates the position of the item in the list and the state of the carousel action (prev, next or init). Alternatively, you can pass a hash of one or two functions which are triggered before and/or after animation:
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}, //JavaScript function that is called (after the scroll animation) when an item isn't longer in the visible range of the carousel. Four parameters are passed: The instance of the requesting carousel and the <li> object itself, the index which indicates the position of the item in the list and the state of the carousel action (prev, next or init). Alternatively, you can pass a hash of one or two functions which are triggered before and/or after animation
        buttonNextCallback: null, //JavaScript function that is called when the state of the 'next' control is changing. The responsibility of this method is to enable or disable the 'next' control. Three parameters are passed: The instance of the requesting carousel, the control element and a flag indicating whether the button should be enabled or disabled.
        buttonPrevCallback: null, //JavaScript function that is called when the state of the 'previous' control is changing. The responsibility of this method is to enable or disable the 'previous' control. Three parameters are passed: The instance of the requesting carousel, the control element and a flag indicating whether the button should be enabled or disabled.
        buttonNextHTML: "<div></div>", //The HTML markup for the auto-generated next button. If set to null, no next-button is created.
        buttonPrevHTML: "<div></div>", //The HTML markup for the auto-generated prev button. If set to null, no prev-button is created.
        buttonNextEvent: "click", //Specifies the event which triggers the next scroll.
        buttonPrevEvent: "click" //Specifies the event which triggers the prev scroll.
    });
});


/*
var mycarousel_itemList = [
    {url: 'http://static.flickr.com/66/199481236_dc98b5abb3_s.jpg', title: 'Flower1'},
    {url: 'http://static.flickr.com/75/199481072_b4a0d09597_s.jpg', title: 'Flower2'},
    {url: 'http://static.flickr.com/57/199481087_33ae73a8de_s.jpg', title: 'Flower3'},
    {url: 'http://static.flickr.com/77/199481108_4359e6b971_s.jpg', title: 'Flower4'},
    {url: 'http://static.flickr.com/58/199481143_3c148d9dd3_s.jpg', title: 'Flower5'},
    {url: 'http://static.flickr.com/72/199481203_ad4cdcf109_s.jpg', title: 'Flower6'},
    {url: 'http://static.flickr.com/58/199481218_264ce20da0_s.jpg', title: 'Flower7'},
    {url: 'http://static.flickr.com/69/199481255_fdfe885f87_s.jpg', title: 'Flower8'},
    {url: 'http://static.flickr.com/60/199480111_87d4cb3e38_s.jpg', title: 'Flower9'},
    {url: 'http://static.flickr.com/70/229228324_08223b70fa_s.jpg', title: 'Flower10'}
];*/


function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, mycarousel_itemList.length -1);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
    return '<a href="'+item.url+'" title="'+item.title+'"><img src="'+item.img+'" alt="'+item.title+'" title="'+item.title+'" /><span>&nbsp;</span></a>';
};


// **************************************************************************************************************************
// GPS conversions
// **************************************************************************************************************************

// conversion from GPS into 
function GetGPS_LatLon(value)
{
	while (value.indexOf(" ") > -1)
	{
		value = value.replace(" ", "");
	}
	
	var val4lat = value.split(",")[0];
	var latHH = parseFloat(val4lat.split(String.fromCharCode(176))[0]);
	var latMM = parseFloat(val4lat.split("'")[0].split(String.fromCharCode(176))[1]);
	var latSS = parseFloat(val4lat.split("'")[1].replace("\"",""));
	//alert(val4lat +":   "+ latHH + "," + latMM + "," + latSS);
	
	
	var val4lon = value.split(",")[1];
	var lonHH = parseFloat(val4lon.split(String.fromCharCode(176))[0]);
	var lonMM = parseFloat(val4lon.split("'")[0].split(String.fromCharCode(176))[1]);
	var lonSS = parseFloat(val4lon.split("'")[1].replace("\"",""));
	//alert(val4lon +":   "+ lonHH + "," + lonMM + "," + lonSS);
	
	var lat = 0;
	var lon = 0;
	
    try
	{           
		lat = latSS / 60.0;
		lat = (lat + latMM) / 60.0;
		lat = lat + latHH;
                
		lon = lonSS / 60.0;
        lon = (lon + lonMM) / 60.0;
        lon = lon + lonHH;
    }
    catch (exception) {}
    
    return lat.toString() +";"+ lon.toString();
}

function GetGPS_Deg(value)
{
	value = value.toString().replace(" ","").replace("(","").replace(")","");
	var value1 = "", value2 = "";
	var hh = 0, mm = 0, ss = 0, actual = 0;
	var hh1 = 0, mm1 = 0, ss1 = 0, actual1 = 0;
	actual = parseFloat(value.split(",")[0]);
	actual1 = parseFloat(value.split(",")[1]);
						
	hh = parseInt(actual);
	var remainder = actual - (hh * 1.0);
	mm = remainder * 60.0;
	var remainder2 = mm - (parseInt(mm)*1.0);
	ss = Math.round(remainder2 * 60.0 * 1000.0) / 1000.0;
	mm = parseInt(mm);
						
	var hh1 = parseInt(actual1);
	remainder = actual1 - (hh1 * 1.0);
	mm1 = remainder * 60.0;
	remainder2 = mm1 - (parseInt(mm1)*1.0);
	ss1 = Math.round(remainder2 * 60.0 * 1000.0) / 1000.0;
	mm1 = parseInt(mm1);
						
	return hh +String.fromCharCode(176)+ mm +'\''+ ss +'"N ' + hh1 +String.fromCharCode(176)+ mm1 +'\''+ ss1 +'"E';
}