var userID=0;
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { 
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); 
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


/* Dot Net Stuff */


var mainstart = function(){};
/* GENERIC */
var parseResponse = function(xml) {
	var r = {};
	var type;
	var params;
	var cont;
	var result;
	var message;
	var errorlist;
	var errors;
	type = $("type",xml);
	params = $("params",xml);
	cont = $("content",xml);
	result = $("result",xml);
	message = $("message",xml);
	errorlist = $("errorlist",xml);
	r.type = (type.length) ? type[0].firstChild.nodeValue : null;
	r.params = (params.length) ? params[0].firstChild.nodeValue : null;
	r.cont = (cont.length) ? cont[0].firstChild.nodeValue : null;
	r.result = (result.length) ? result[0].firstChild.nodeValue : null;
	r.message = (message.length) ? message[0].firstChild.nodeValue : null;
	r.haserrors = false;
	errors = {};
	if(errorlist.length) {
		r.haserrors = true;
		$("error",errorlist[0]).each(function(){
			errors[this.firstChild.firstChild.nodeValue] = (this.lastChild.hasChildNodes()) ? this.lastChild.firstChild.nodeValue : "";
		});
	}
	r.errors = errors;
	return r;
};

var serialize = function(jqObj) {
	var oldObj = new Object(arguments[1]);
	var rObj = new Object;
	var aObj = new Object;
	jqObj.filter("input[@type='text']").each(function(){
		rObj[$(this).attr("name")] = $(this).val();
	}).end();

	jqObj.filter("input[@type='password']").each(function(){
		rObj[$(this).attr("name")] = $(this).val();
	}).end();
	
	jqObj.filter("input[@type='hidden']").each(function(){
		rObj[$(this).attr("name")] = $(this).val();
	}).end();
		
	jqObj.filter("select, textarea").each(function(){
		rObj[$(this).attr("name")] = $(this).val();
	}).end();
	
	jqObj.filter("input[@type=checkbox]").each(function(){
		if(this.checked) {
			if(typeof(aObj[$(this).attr("name")])=="undefined") {
				aObj[$(this).attr("name")] = new Array();
			}
			aObj[$(this).attr("name")].push($(this).val());
		}
	}).end();
	
	jqObj.filter("input[@type=radio]").each(function(){
		if(this.checked) {
			rObj[$(this).attr("name")] = $(this).val();
		}
	}).end();
	
	for(var i in aObj) {
		for(var j=0;j<aObj[i].length;j++) {
			var keyName = i +"["+j+"]";
			rObj[keyName] = aObj[i][j];
		}
	}
	
	for (var o in oldObj) {
		rObj[o] = oldObj[o];
	}
		
	return rObj;
};

/* FADE ANIMATION CODE */
function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) {
	var delta = maxValue - minValue;
	var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
	return Math.ceil(stepp)
}

function doBGFade(elem,startRGB,endRGB,finalColor,steps,intervals,powr) {
	if (elem.bgFadeInt) window.clearInterval(elem.bgFadeInt);
	var actStep = 0;
	elem.bgFadeInt = window.setInterval(
		function() {
			elem.style.backgroundColor = "rgb("+
				easeInOut(startRGB[0],endRGB[0],steps,actStep,powr)+","+
				easeInOut(startRGB[1],endRGB[1],steps,actStep,powr)+","+
				easeInOut(startRGB[2],endRGB[2],steps,actStep,powr)+")";
			actStep++;
			if (actStep > steps) {
			elem.style.backgroundColor = finalColor;
			window.clearInterval(elem.bgFadeInt);
			}
		}
		,intervals)
}

$(function() {
	mainstart();
	
	$("#NMostrar").fadeOut(5000,function(){
		$(this).remove(); 		
		window.history.go(-1);
	});
	
	$("#btn_close_popUp_transp").click(function(){
		$("#show_over_pos_").fadeOut("slow",function(){
			$("#over_pos_Hidder").hide();			
		});
		
		return false;
	});
	
	userID = $("#get_user_id").html();
		
});

