function DateDiff(IntervalType, StartDate, EndDate)
{
    var Interval = 0;
    var DevideBy = 1;
    if (EndDate < StartDate)
    {
        return Interval;
    }
    switch (IntervalType)
    {
        //date portion  
        case 'd': //add days
            DevideBy = 1000 * 60 * 60 * 24;
            Interval = EndDate - StartDate;
            Interval = Math.floor(Interval / DevideBy);
            

            break;
        case 'm': //add months
            var MonthsInFullYear = EndDate.getFullYear() - StartDate.getFullYear();
            if (MonthsInFullYear > 0)
            {
                MonthsInFullYear = (MonthsInFullYear - 1) * 12;
                Interval = EndDate.getMonth() + (12 - StartDate.getMonth());
                Interval = Interval + MonthsInFullYear
            }
            else
            {
                Interval = EndDate.getMonth() - StartDate.getMonth();
            }

            break;
        case 'y': //years
            Interval = EndDate.getFullYear() - StartDate.getFullYear();
            break;

        //time portion        
        case 'h': //days
            DevideBy = 1000 * 60 * 60;
            Interval = EndDate - StartDate;
            Interval = Math.floor(Interval / DevideBy);
            break;
        case 'n': // minutes
            DevideBy = 1000 * 60;
            Interval = EndDate - StartDate;
            Interval = Math.floor(Interval / DevideBy);
            break;
        case 's': //seconds
            DevideBy = 1000
            Interval = EndDate - StartDate;
            Interval = Math.floor(Interval / DevideBy);
            break;
    }

    return Interval;
} 


function Mid(str, start, len)
{
// Make sure start and len are within proper bounds
    if (start < 0 || len < 0) return "";
    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
          iEnd = iLen;
    else
          iEnd = start + len;
    return String(str).substring(start,iEnd);
}







	
	
// Ajax Global Funcion
	
	var ajax_url_default
	ajax_url_default='http://www.mensen.com.br/portal/';

	
    function ajax_request(url, method, args, function_status, error_dispose)
	{
		var ajax_http = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            ajax_http = new XMLHttpRequest();
            if (ajax_http.overrideMimeType) {
                ajax_http.overrideMimeType('text/xml');
            }
        } else if (window.ActiveXObject) { // IE
            try {
                ajax_http = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    ajax_http = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        
		if (!ajax_http) {
            ajaxresult_show(error_dispose);
            return false;
        }
		
		
        
		ajax_http.onreadystatechange = function_status;
		//alert(ajax_url_default+url);
		
        if (method == 'GET')
		{	
		    if (args == '')
			{	ajax_http.open(method, ajax_url_default+url, true); }
			else
			{	ajax_http.open(method, ajax_url_default+url+'?'+args, true); }
			ajax_http.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
			ajax_http.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
			ajax_http.setRequestHeader("Pragma", "no-cache");
			ajax_http.send(null);
		}
		else
		{	
			ajax_http.open(method, url, true); 
			ajax_http.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
			ajax_http.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
			ajax_http.setRequestHeader("Pragma", "no-cache");
			ajax_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        	ajax_http.setRequestHeader("Content-length", args.length);
        	ajax_http.setRequestHeader("Connection", "close");
			ajax_http.send(args);
		}
			
		return ajax_http;
			
    }
	
	
	
	function ajaxresult_show(id, tempo)
	{
		$('#'+id).slideDown('normal');

		if (tempo != 1)
		{ window.setTimeout(function(){ $('#'+id).slideUp('normal'); } , 7000 ); }
	}
	
	
// #####################################################

	
	function show_error_form(campo)
	{
	 	$('#error_'+campo).hide(0);
		$('#error_'+campo).fadeIn('fast');
		return false;
 	}

// #####################################################


function default_nova_janela(url, janela, opcoes)
{  window.open(url, janela, opcoes); }
