function hideFormElement(selector) {
	if ($.inArray($(selector).parent().css('position'),["absolute","relative","fixed"])==-1)
		$(selector).parent().css('position', "relative");
	
	if ($(selector).css('z-index')=="auto")
		zindex= 2;
	else
		zindex= $(selector).css('z-index');
	
	if ($.inArray($(selector).css('position'),["absolute","relative","fixed"])>-1)
		position= $(selector).css('position');
	else
		position= "relative";
	
	$(selector)
		.css({
			'opacity': "0",
			'position': position,
			'z-index': zindex,
			'background': "0 none", /* for OSX... */
			'filter': "alpha(opacity=0)" /* for IE7 */
		})
	;
	
	$(selector).next()
		.css({
			//~ 'position': "relative",
			'position': "absolute",
			'z-index': (zindex-1),
			//~ 'display': "inline-block"
			'display': "block"
		})
	;
	
	$(selector)
		.width($(selector).next().width())
		.height($(selector).next().height())
	;
	$(selector).next()
		.offset($(selector).offset())
	;
}
/* 
$(document).ready(function() {
	/* NEWS LINKS 
	$("#prefooter table tr").click(function() {
		location.href= "news.html#news_no"+$(this).attr('id').substr(10);
	});
	
	
	/*FORM ELEMENTS 
	$("input[type='text'], input[type='password'], textarea").each(function() {
		$(this).addClass('default');
		
		$(this).bind("click, focus", function() {
			var defaultValue= $(this)[0].defaultValue; 
			$(this).removeClass('default');
			if ($(this).val()==defaultValue)
				$(this).val('');
		});
		$(this).bind("change, blur", function() {
			var defaultValue= $(this)[0].defaultValue; 
			if (!$(this).val().length) {
				$(this).val(defaultValue);
				$(this).addClass('default');
			}
		});
	});
	
	$("input[type='checkbox']").each(function() {
		$(this).click(function () {
			if ($(this).prop("checked"))
				$(this).next().addClass("checked");
			else
				$(this).next().removeClass("checked");
		});
		$("<span></span>")
			.addClass("checkboxmimic")
			.insertAfter(this);
		
		if ($(this).prop("checked"))
			$(this).next().addClass("checked");
		else
			$(this).next().removeClass("checked");
		
		hideFormElement(this);
	});
	
	$("select").each(function() {
		$(this).bind("click, change, keypress", function() {
			$(this).next().children(".mid").text($(this).children(":selected").text());
			$(this).width($(this).next().width());
		});
		
		$("<span></span>")
			.addClass("selectmimic")
			.append($("<span></span>").addClass("left"))
			.append($("<span></span>").addClass("mid").text($(this).children(":selected").text()))
			.append($("<span></span>").addClass("right"))
			.insertAfter(this)
			.offset($(this).offset())
		;
		
		hideFormElement(this);

	});
});*/


function modalBox(title, text, showit) {
	this.title= title;
	this.text= text;
	this.showed= false;
	if (showit!=false)
		this.show();
}
modalBox.prototype.show= function() {
	if ($("#modalboxwrapper").length)
		this.refresh();
	else {
		$("body")
			.prepend($("<div/>").attr('id', "modalboxhider"))
			.prepend(
				$("<div/>").attr('id', "modalboxwrapper").append(
					$("<div/>")
						.attr("id", "modalbox")
						.append($("<h1/>").text(this.title))
						.append($("<a/>").addClass("close").text("close").append($("<span/>").text("X")))
						.append($("<div/>").addClass("text").text(this.text))
						.append($("<div/>").addClass("bottom").append($("<a/>").addClass("okay").text("ok")))
				)
			)
		;
		$("#modalbox a").attr('href', "javascript: void(0);").click(function() {
			$("#modalboxhider, #modalboxwrapper").remove();
			$(document).unbind('scroll');
		});
		$("#modalboxhider").height($(document).height());
		$("#modalboxhider").width($(document).width());
		$("#modalboxwrapper").css('top', ((($(window).height()-$("#modalboxwrapper").outerHeight())/2)+$(window).scrollTop())+"px");
		
		$(document).scroll(function() {
			$("#modalboxwrapper").css('top', ((($(window).height()-$("#modalboxwrapper").outerHeight())/2)+$(window).scrollTop())+"px");
		});
	}
	this.showed= true;
}
modalBox.prototype.refresh= function() {
	if ($("#modalboxwrapper").length) {
		$("#modalbox h1").text(this.title);
		$("#modalbox div.text").text(this.text);
	} else
		this.show();
}
modalBox.prototype.hide= function() {
	if ($("#modalboxwrapper").length) {
		$("#modalboxhider, #modalboxwrapper").remove();
		$(document).unbind('scroll');
		this.showed= false;
	}
}
modalBox.prototype.toggle= function() {
	if ($("#modalboxwrapper").length)
		this.hide();
	else
		this.show();
}


function formSubmit(form) {
	var filledError= 0;
	$(form).find("input[type='password'], input[type='text'], textarea").each(function() {
		var defaultValue= $(this)[0].defaultValue; 
		if ($(this).val()==defaultValue && $(this).hasClass("req"))
			filledError|= 1;
		
		if ($(this).hasClass("req") && $(this).val().length == 0)
			filledError|= 2;
	});
	$(form).find("input.email.req").each(function() {
		filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test($(this).val()))
			filledError|= 4;
	});
	if (filledError>0) {
		errormsg= "";
		if (filledError & 1)
			errormsg+= " - You must change the required inputs from the default value!\n";
		if (filledError & 2)
			errormsg+= " - You need to fill all required inputs!\n";
		if (filledError & 4)
			errormsg+= " - You need to fill the email input correctly!\n";
		var messenger= new modalBox("Error", errormsg);
		return false;
	}
	
	return true;
}


