$.fn.dropdown = function() {
	return this.each(function() {
		$(this).hover(function(){
			$(this).addClass("hover");
			$('> .dir',this).addClass("open");
			$('ul:first',this).css('visibility', 'visible');
		},function(){
			$(this).removeClass("hover");
			$('.open',this).removeClass("open");
			$('ul:first',this).css('visibility', 'hidden');
		});
	});
}

// show hide mainDet content
function show(divID)
{
	if (document.getElementById(divID))	document.getElementById(divID).style.display='block';
}
function showi(divID)
{
	if (document.getElementById(divID))	document.getElementById(divID).style.display='inline';
}
function hide(divID)
{
	if (document.getElementById(divID))	document.getElementById(divID).style.display='none';
}
function showHide(divID) 
{
	document.getElementById(divID).style.display == 'none' ? document.getElementById(divID).style.display = 'block' : document.getElementById(divID).style.display = 'none';
}

// Checks if a field is empty, and if so, resets the input's content to the default value
function checkField( obj, value )
{
	// Match any amount of white spaces
	if( obj.value == "" )
	{
		obj.value = value;
	}
	
	return false;
}

// Clears an input's content
function clearField( obj, value )
{
	if( obj.value == value )
	{
		obj.value = "";
	}
	
	return false;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function reloadWindow()
{
	window.location=window.location;
	
	return;
}

function obiect(id)
{
	if (document.getElementById(id)) return document.getElementById(id); else return false;
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function indexInArray(arr,val)
{
	for(var i=0;i<arr.length;i++) if(arr[i]==val) return i;
	return -1;
}

function closeWindow(id)
{
	if (document.getElementById(id)) document.getElementById(id).style.display = 'none';
}

function markFields(campuri)
{
	var vector = new Array;
	vector = campuri.split("%");
	for (i=0;i<vector.length;i++)
	if (obiect(vector[i]) || obiect(vector[i]+'_label'))
	{
		if (obiect(vector[i]) && obiect(vector[i]).className != 'nonCheck')
		{
			obiect(vector[i]).style.backgroundColor = '#EEC8C8';
			obiect(vector[i]).style.color = '#9C3030';
		}
		else if (obiect(vector[i]+'_label'))
		{
			obiect(vector[i]+'_label').style.color = '#b93939';
		}
	}
}

function columns()
{
	var h1 = $("div#sidebar").outerHeight(true);
	var h2 = $("div#contWrap").outerHeight(true);
	$("div.column").height(Math.max(h1, h2));
}

function toggleNext(elId)
{
	$("#"+elId).slideToggle();
	return false;
}

$().ready(function(){
	$("ul.dropdown li").find("li").each(function(){
		$(this).parent().parent().addClass('dir').dropdown();
	});
	$("a[href=#top]").click(function() {
		$("html, body").animate({ scrollTop:0 }, "1000");
		return false;
	});
	$(".hiddenContent").hide();
	$(".hiddenContentTrigger").click(function(){
		$(this).next("."+$(this).attr("href").substr(1)).slideToggle();
		return false;
	});
});
