function onloadQueue(func) {

var oldonload = window.onload;
if (typeof window.onload != 'function') {
	window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
				}
			func();
			}
		}
}

function is_array( mixed_var ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Legaev Andrey
    // +   bugfixed by: Cord
    // *     example 1: is_array(['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
    // *     example 2: is_array('Kevin van Zonneveld');
    // *     returns 2: false
 
    return ( mixed_var instanceof Array );
}

function array_keys( input, search_value, strict ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: array_keys( {firstname: 'Kevin', surname: 'van Zonneveld'} );
    // *     returns 1: {0: 'firstname', 1: 'surname'}
 
    var tmp_arr = new Array(), strict = !!strict, include = true, cnt = 0;
 
    for ( key in input ){
        include = true;
        if ( search_value != undefined ) {
            if( strict && input[key] !== search_value ){
                include = false;
            } else if( input[key] != search_value ){
                include = false;
            }
        }
 
        if( include ) {
            tmp_arr[cnt] = key;
            cnt++;
        }
    }
 
    return tmp_arr;
}

function in_array(needle, haystack, strict) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
 
    var found = false, key, strict = !!strict;
 
    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    }	
 
    return found;
}

	function addDate(e, input_day, input_month, input_year, container) {

		var element = Event.element(e);
		
		var junk = element.getAttribute("rel").split(".");
		var day = junk[0];
		var month = junk[1];
		var year = junk[2];

		var day = 

		$(input_day).setAttribute("value", day);
		$(input_month).setAttribute("value", month);
		$(input_year).setAttribute("value", year);

		new Effect.toggle(container, 'appear');

		}

	function initUpload() {

		$("upload").previous("form").disable();
		$('upload_loading').show();
	
		$("upload").submit();

		}

	function remainingLetters(input, limit, result) {
		var current = $F(input).length;
		var remaining = current < limit ? limit - current : 0;
		$(result).update(remaining);
		}

	function tabber(e) {
	
		var element = Event.element(e);
		if (element.tagName == "A") {	
			var target = element.readAttribute("rel");
			$("productii_dj").hide();
			$("mixuri_dj").hide();
			$("evenimente_dj").hide();
			$(target + "_dj").show();
			$$("#dj_content li a").each(function(f) {
				f.removeClassName("selected");
				})
			element.addClassName("selected");
			}	
		}

	function selectContent() {
		var url = document.location.href.split("#");
		if (url[1]) {
			var current = url[1];
			$$('#dj_content li a[rel="productii"]').invoke('removeClassName', 'selected');
			$$('#dj_content li a[rel="' + current + '"]').invoke('addClassName', 'selected');
			$("productii_dj").hide();
			$(current + "_dj").show();
			}

		}

function clone(elem) {
	var cloned = $(elem).cloneNode(true);
	cloned.childElements()[0].update("selectati alt trainer (optional)");
	$('select_container').appendChild(cloned);
	Event.observe(cloned, 'change', function(e) {
		clone(cloned);
		});
	}

	function confirmation(e, message) {
	
		var element = Event.element(e);
		var url = element.getAttribute("href");
		
		element.setAttribute("href", "#");
		if (confirm(message)) {
			document.location = url;
			}

		}


function countdown(time, div)
{	
	if(time <= 0)
	{
		content.innerHTML = "Oferta a expirat";
		if ($('offer-bid-item')) {
			$('offer-bid-item').addClassName('disabled');
			$('offer-unique-item').addClassName('disabled');
			}
		// refresh cu ajax la counter
	}
	else
	{
		msg_zi = ' zile '; 
		msg_ore = ' ore ';
		content = document.getElementById(div);
		
		days = Math.floor(time/86400);
		hours = Math.floor((time - (days * 86400 )) / 3600);
		mins = Math.floor((time - (days * 86400 ) - (hours *3600 )) / 60);
		secs = Math.floor((time - (days * 86400 ) - (hours *3600 ) - (mins*60))); 
		
		if (days <= 1)
			msg_zi = ' zi ';
		if (hours <= 1)
			msg_ore = ' ora ';
		
		content.innerHTML = ( days > 0 ? days + msg_zi : '') + ( hours > 0 ? hours + msg_ore : '' ) + ( mins > 0 ? mins + ' min ' : '' ) + secs + ' sec';
		setTimeout('countdown(' + --time + ',"' + div + '");', 1000);
	}
}

function daysInMonth(iMonth, iYear)
{
	return 32 - new Date(iYear, iMonth, 32).getDate();
}

function toggle_buttons(id, size)
{	
		var element_array = id.split('-');
		var element_no = element_array[1];
		for (i = 1; i <= size; i++)
		{
			var current = document.getElementById('slidernav-' + i);
			if (element_no == i)
			{
				current.className = 'selected';
			}
			else
			{
				current.className = '';
			}
		}
}

onloadQueue(function() {
	$$('.toggle').each(function(e) {
		Event.observe(e, 'focus', function(f) {
			if (e.value == e.title) {
				e.removeClassName('toggle');
				e.value = '';
				}
			});
		Event.observe(e, 'blur', function(f) { 
			if ((e.value == '') || (e.value == e.title)) {
				e.addClassName('toggle');
				e.value = e.title;
				}
			});
		});	
	$$('.verified').each(function(e) {
		Event.observe(e, 'mouseover', function(f) {
			var element = Event.element(f);
			var position = element.positionedOffset(element);
			$('tooltip').setStyle({left: position.left - 14 + 'px', top: position.top - 125 + 'px'});
			$('tooltip').show();
			});
		Event.observe(e, 'mouseout', function(f) {
			$('tooltip').hide();
			});
		});
	});
