
/*
function $() 
{
  var results = [], element;
  for (var i = 0; i < arguments.length; i++) {
	element = arguments[i];
	if (typeof element == 'string')
	  element = document.getElementById(element);
	results.push((element));
  }
  return results.length < 2 ? results[0] : results;
}
*/

if (!isDefined(momentoAtual)){
	var momentoAtual = new Date();
}

var globalUser = "";

function isDefined(variable){
    return (typeof(window[variable]) == "undefined")?  false: true;
}
function i18nTranslationNow(){
	$(".i18n").each(function(){
		var i18n_item = $(this).attr('class').split(" ").slice(0,1);
		$("." + i18n_item).html($.i18n._(i18n_item));
	});
}
function i18nTranslationNowHtml(){
	$(".i18n").each(function(){
		var i18n_item = $(this).attr('class').split(" ").slice(0,1);
		$("." + i18n_item).html($.i18n._(i18n_item));
	});
}
function js_details(item){
	var camada = "#tr_details_" + item;
	if ($(camada).attr("state") == "opened"){
		$(camada).attr("state","closed");
		$("#tr_details_" + item).hide();
		$("#keywordslistbox2").css("height", parseInt($("#keywordslistbox2").css("height")) - 130 + "px");
	}else{
		$(camada).attr("state","opened");
		$("#tr_details_" + item).show();
		$("#keywordslistbox2").css("height", parseInt($("#keywordslistbox2").css("height")) + 130 + "px");
	}
}
function bigAjaxLoading(camada){
	$(camada).html("<span style='color:#C63232; margin-top: -20%; padding-top: 50%; min-width: 100%; width: 100%; height: 100%; text-align: center;'><img src='interface/images/bigloading.gif' hspace='10' align='absmiddle' border='0' /><br/>AGUARDE</span>");
}
function smallAjaxLoading(camada){
	$(camada).html("<img src='interface/images/smallloading.gif' hspace='10' align='absmiddle' border='0' />");
}
function getCursor(){
	$.browser.msie?cssCursor='hand':cssCursor='pointer';
}
function setCursor(object){
	$(object).css("cursor", cssCursor);
}
function pngBugFix(){
	$('img[src$=.png]').each(function() {
       fixPng(this);
    });
}
function getRelativeCoordinates(event, reference) {
	var x, y;
	event = event || window.event;
	var el = event.target || event.srcElement;

	if (!window.opera && typeof event.offsetX != 'undefined') {
	// Use offset coordinates and find common offsetParent
	var pos = { x: event.offsetX, y: event.offsetY };

	// Send the coordinates upwards through the offsetParent chain.
	var e = el;
	while (e) {
		e.mouseX = pos.x;
		e.mouseY = pos.y;
		pos.x += e.offsetLeft;
		pos.y += e.offsetTop;
		e = e.offsetParent;
	}
	// Look for the coordinates starting from the reference element.
	var e = reference;
	var offset = { x: 0, y: 0 }
	while (e) {
		if (typeof e.mouseX != 'undefined') {
			x = e.mouseX - offset.x;
			y = e.mouseY - offset.y;
			break;
		}
		offset.x += e.offsetLeft;
		offset.y += e.offsetTop;
		e = e.offsetParent;
	}

	// Reset stored coordinates
	e = el;
	while (e) {
		e.mouseX = undefined;
		e.mouseY = undefined;
		e = e.offsetParent;
	}
}else{
	// Use absolute coordinates
	var pos = getAbsolutePosition(reference);
	x = event.pageX  - pos.x;
	y = event.pageY - pos.y;
}
  // Subtract distance to middle
return { x: x, y: y };
} 
function getAbsolutePosition(element) {
	var r = { x: element.offsetLeft, y: element.offsetTop };
	if (element.offsetParent) {
		var tmp = getAbsolutePosition(element.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}
function centerHor(object){
	var wObj = parseInt($(object).outerWidth());
	var leftObject = (bodywidth - wObj)/2;
	$(object).css("left", leftObject);
}
function certerVer(object){
	bodyheight = $(document).height();
	var topObject = (parseInt(bodyheight) - parseInt($(object).outerHeight())) / 2 + "px";
	$(object).css("top", topObject);
}
function getGeoPositionByIp(target){
	$.ajax({
		dataType: "json",
		//url: "http://iplocationtools.com/ip_query.php?output=json&callback=?&ip=",
		url: "http://ipinfodb.com/ip_query.php?output=json&callback=?&ip=",
		beforeSend: smallAjaxLoading("#"+target),
		success:function(data){
			if(data['Status'] == 'OK'){
				var seuip = data['Ip'];
				var cidade = data['City'];
				var estado = data['RegionName'];
				var pais = data['CountryCode'];
				var saida = cidade + "/" + estado + "/" + pais;
				$("#"+target).html("<b>Você está conectado por: </b>" + saida + "<br/><b>Seu IP:</b> " +seuip);
			}
		},
		error:function(){
			alert("erro");
		}
	});
}
function normalPageFunctions(){
	$("#versionbox").corner();
	$("#keywordsbox").corner();
	$("#keywordslistbox").corner();
	$("#keywordslistbox2").corner();
	$("#wishbox").corner();
	$("#portal").corner("15px");
	showHelpMsg("default");
	
	ipinternet = "192.168.0.101";
	ipinterno = "192.168.2.1";

	var optionsEST = {
		utc: true,
		utc_offset: -3,
		fontFamily: 'verdana',
		fontSize: '10px',
		foreground: '#505050'		
	}
	setCursor(".mainbuttons");
	setCursor(".mainbuttons2");
	setCursor(".minibuttons");
	setCursor(".minibuttonstxt");
	setCursor(".minibuttonclassic");
	setCursor(".navbuttons");
	$("#helpertext").corner("15px top br backgroundColor: cc:#cbcbcb");
	
	moveRelogio();
		
	$(".navbuttons").bind("mouseover", function(){
		$(this).css("background-position","-62px 0px");
	});
	$(".navbuttons").bind("mouseout", function(){
		$(this).css("background-position","0px 0px");
	});
	$(".navbuttons").bind("click", function(){
		if ($(this).attr("id") == "btnback"){
			$("#formNumber0").val($(this).attr("longdesc"));
			$("#frmBack").submit();
		}else{
			$("#formNumber").val($(this).attr("longdesc"));
			$("#frmMenu").submit();
		}
	});
	$(".mainbuttons").bind("mouseover", function(){
		$(this).css("background-position","-204px 0px");
	});
	$(".mainbuttons").bind("mouseout", function(){
		$(this).css("background-position","0px 0px");
	});
	$(".mainbuttons").bind("click", function(){
		if ($(this).attr("id") == "btnback"){
			$("#formNumber0").val($(this).attr("longdesc"));
			$("#frmBack").submit();
		}else{
			$("#formNumber").val($(this).attr("longdesc"));
	
			if ($("#formNumber").val() == 104){
			  if ( confirm ($.i18n._("confirm_restart") + "?") ) {
  			    $("#frmMenu").submit();
			  }else{
				return true;
			  }
			}else{
  			  $("#frmMenu").submit();
			}
		}
	});
	$(".mainbuttons2").bind("mouseover", function(){
		$(this).css("background-position","-204px 0px");
	});
	$(".mainbuttons2").bind("mouseout", function(){
		$(this).css("background-position","0px 0px");
	});
	$(".mainbuttons2").bind("click", function(){
		$("#formNumber1").val($(this).attr("longdesc"));
		$("#frmMenu").submit();
	});
	$(".minibuttons").bind("mouseover", function(){
		$(this).css("background-position","-32px 0px");
	});
	$(".minibuttons").bind("mouseout", function(){
		$(this).css("background-position","0px 0px");
	});
	
	$(".minibuttonclassic").bind("click", function(){
		if ($(this).is(".blocksel")) return false;
		$(".minibuttonclassic").toggleClass("blocksel");
		$("#politica").val($(this).attr("rel"));
	});
	
	$(".btnhelp").bind("click",function(){
		showHelpMsg($(this).attr("rel"));
		$("#helpertext").corner("15px top br backgroundColor: cc:#cbcbcb");
		window.setTimeout(function() {
			showHelpMsg("default");
			$("#helpertext").corner("15px top br backgroundColor: cc:#cbcbcb");
		}, 20000);
	});

	setCursor("select");
	setCursor(".btnhelp");

	$("#helperbox").css("background-color","transparent");
	$("#block_ip").bind("change",function(){
		if($(this).val() == 1){
			$("#mac").hide();
			$("#mac").val("");
			$("#ip").show();
			$("#ip").focus();
		}else if($(this).val() == 2){
			$("#ip").hide();
			$("#ip").val("");
			$("#mac").show();
			$("#mac").focus();
			$("#mac").mask("************",{completed:function(){
					var i = 0;
					var dIp = this.val();
					var dIPerror = false;
					var blocos = dIp.split("-");
					var blocklist = "";
					for (i=0;i<6;i++){
						if (!isHex(blocos[i])){
							blocklist = blocklist + (i + 1) + ",";
							dIPerror = true;
						}
					}
					if (dIPerror){
						alert($.i18n._("error_macaddress") + " "  + blocklist);
					}
				}
			});
		}else if($(this).val() == 0){
			$("#ip").hide();
			$("#ip").val("");
			$("#mac").hide();
			$("#mac").val("");
		}
	});
	$("#time").bind("change",function(){
		if($(this).val() == 1){
			$("#moredetailshoras").show();
			$("#moredetailshoras").ready(function(){
				var str_checks = new String("");
				var str_line = new String("");
				var _REQUEST = new Array(0,0);
				
				_REQUEST['h_ini'] = timeCtrlStart; 
				_REQUEST['h_fin'] = timeCtrlEnd;
				
				for ( i = 0; i < 24; i++ ) {
					// pula as horas que nao estao configuradas no horario de expediente
					if ( i < _REQUEST['h_ini'] || i >= _REQUEST['h_fin'] )
						continue;
					str_checks += '\
					<input checked style="display: none" type="checkbox" name="check_hour_' + i + '_10" id="check_hour_' + i + '_10" value="' + i + '_10">\
					<input checked style="display: none" type="checkbox" name="check_hour_' + i + '_20" id="check_hour_' + i + '_20" value="' + i + '_20">\
					<input checked style="display: none" type="checkbox" name="check_hour_' + i + '_30" id="check_hour_' + i + '_30" value="' + i + '_30">\
					<input checked style="display: none" type="checkbox" name="check_hour_' + i + '_40" id="check_hour_' + i + '_40" value="' + i + '_40">\
					<input checked style="display: none" type="checkbox" name="check_hour_' + i + '_50" id="check_hour_' + i + '_50" value="' + i + '_50">\
					<input checked style="display: none" type="checkbox" name="check_hour_' + i + '_60" id="check_hour_' + i + '_60" value="' + i + '_60">\
					<input checked style="display: none" type="checkbox" name="check_hour_' + i + '_A"  id="check_hour_' + i + '_A"  value="A">\
					';
					str_line  = '<tr>';
					str_line += '<td bgcolor="#E3E3E3" id="td_hour_' + i + '_A"  class="checkallhour" rel="'+i+'" align="center" nowrap height="40">' + i + ':00/' + (i + 1)  + ':00</td>';
					str_line += '<td bgcolor="#28D22B" id="td_hour_' + i + '_10" class="checkonehour" rel="'+i+'_10" align="center" height="40">' + i + ':00<hr style="border:1px dashed #CCCCCC">' + i + ':10</td>';
					str_line += '<td bgcolor="#28D22B" id="td_hour_' + i + '_20" class="checkonehour" rel="'+i+'_20" align="center" height="40">' + i + ':10<hr style="border:1px dashed #CCCCCC">' + i + ':20</td>';
					str_line += '<td bgcolor="#28D22B" id="td_hour_' + i + '_30" class="checkonehour" rel="'+i+'_30" align="center" height="40">' + i + ':20<hr style="border:1px dashed #CCCCCC">' + i + ':30</td>';
					str_line += '<td bgcolor="#28D22B" id="td_hour_' + i + '_40" class="checkonehour" rel="'+i+'_40" align="center" height="40">' + i + ':30<hr style="border:1px dashed #CCCCCC">' + i + ':40</td>';
					str_line += '<td bgcolor="#28D22B" id="td_hour_' + i + '_50" class="checkonehour" rel="'+i+'_50" align="center" height="40">' + i + ':40<hr style="border:1px dashed #CCCCCC">' + i + ':50</td>';
					str_line += '<td bgcolor="#28D22B" id="td_hour_' + i + '_60" class="checkonehour" rel="'+i+'_60" align="center" height="40">' + i + ':50<hr style="border:1px dashed #CCCCCC">' + (i+1) + ':00</td>';
					str_line += '</tr>';
					$("#blocogrid").append(str_line);
				}
			
				$("#blocogrid").append('<input type="checkbox" style="display: none" name="check_hour_00" id="check_hour_00" value="FIRST">');
				$("#blocogrid").append(str_checks);
				$("#blocogrid").append('<input type="checkbox" style="display: none" name="check_hour_23" id="check_hour_23" value="LAST">');
				$("#grid_time").show();
				$(".checkonehour").css("background-color","#28D22B");
				js_calcTimes();
				//$("#grid_grid_time").corner("15px top br backgroundColor:#ffffff cc:#cbcbcb");
				/*$("#grid_days").flexigrid({
					onToggleCol: false,
					showToggleBtn: true, 
					showTableToggleBtn: true, 
					width:450, 
					height:80,
					title: "Dias da semana",
					noSelect: true,
					onSuccess: function(){
					}
				});*/
				
				/*
				$("#grid_grid_time").flexigrid({
					onToggleCol: false,
					showToggleBtn: true, 
					showTableToggleBtn: true, 
					width:450, 
					height:480,
					title: "Grade de horários",
					onSuccess: function(){
					}
				});
				*/		var verde = "#28D22B";
						var vermelho = "#FF3333";
						
						setCursor(".checkallhour");
						setCursor(".checkonehour");
						
						$(".checkallhour").bind("click",function(){
							var level = $(this).attr("rel");
							var i=0;
							if ($("#check_hour_"+level+"_A").attr("checked") == true){
								$("#check_hour_"+level+"_A").attr("checked",false);
								for (i=1;i<7;i++){
									$("#td_hour_"+level+"_"+i+"0").css("background-color",vermelho);
									$("#check_hour_"+level+"_"+i+"0").attr("checked",false);
								}
							}else{
								$("#check_hour_"+level+"_A").attr("checked",true);
								for (i=1;i<7;i++){
									$("#td_hour_"+level+"_"+i+"0").css("background-color",verde);
									$("#check_hour_"+level+"_"+i+"0").attr("checked",true);
								}
							}
							js_calcTimes();
						});
						
						
						$(".checkonehour").bind("click",function(){
							var level = $(this).attr("rel");
							if ($("#check_hour_"+level).attr("checked") == true){
								$("#check_hour_"+level).attr("checked",false);
								$("#td_hour_"+level).css("background-color",vermelho);
							}else{
								$("#check_hour_"+level).attr("checked",true);
								$("#td_hour_"+level).css("background-color",verde);
							}
							js_calcTimes();
						});
			});
		}else{
			$("#moredetailshoras").hide();
		}
	});

	$(".minibuttons").bind("click", function(){
		var btnname = $(this).attr("type");
		switch (btnname){
			case "morepalavra":
				var state = $(this).attr("rel");
				if (state == "closed"){
					$(this).attr("rel","opened");
					$("#moredetails").corner("top cc:#ffffff");
					$("#moredetails").show("fast");
				}else{
					$(this).attr("rel","closed");
					$("#moredetails").hide("fast");
				}
			break;
		}
	});
	$(".minibuttonstxt").bind("click", function(){
		
		var btnname = $(this).attr("type");
		switch (btnname){
			case "morepalavra":
				var state = $(this).attr("rel");
				$(this).html($.i18n._("label_lessoptions"));
				if (state == "closed"){
					$(this).attr("rel","opened");
					$("#moredetails").corner("top cc:#ffffff");
					$("#moredetails").show("fast");
				}else{
					$(this).html($.i18n._("label_moreoptions"));
					$(this).attr("rel","closed");
					$("#moredetails").hide("fast");
				}
			break;
		}
	});
}
function loginPageFunctions(){
	$("#loginbox").corner("15px");
	$("#user").focus();
	//getGeoPositionByIp("message");
	centerHor("#portallogin");
	certerVer("#portallogin");
	setCursor(".loginbtnok");
	setCursor(".apsite");
	centerHor("#portallogin");
	$("#aplogo").css("position", "absolute");
	$("#aplogo").css("top", "90%");
	$("#aplogo").css("height", "56px");
	
	$(".loginbtnok").bind("mouseover", function(){
		$(this).css("background-position","-96px 0px");
	});
	$(".loginbtnok").bind("mouseout", function(){
		$(this).css("background-position","0px 0px");
	});
	$("#user").bind("keypress", function(){
		$("#message").hide();
	});
	$("#password").bind("keypress", function(){
		$("#message").hide();
	});
	$(".loginbtnok").bind("click", function(){
		var user = $("#user").val();
		globalUser = user;		
		var password = $("#password").val();
		var formNumber = $("#formNumber").val();
		$.ajax({
			type: "POST",
			url: "/cgi-bin/aprouter.cgi",
			data: "user="+user+"&password="+password+"&formNumber="+formNumber,
			dataType: "script, html",
			processData: false, 
			async: false,
			success:function(dadosPagina){
				$("#portallogin").hide(100,function(){
					$("#aplogo").hide();
					$("#portal").html(dadosPagina);
				});
				
				var newheight = $("#portal").height();
				var newtop = parseInt($("#portal").css("top"));
				$("#portal").parent().css("height",(newheight+newtop+15)+"px");
				$("#portal").parent().css("overflow-x","hidden");
				portaltop = $("#portal").css("top");
				portalleft = $("#portal").css("left");
				bodyheight = $(document).height();
				bodywidth = $(document).width();
				login = false;
				mainpage = true;
			}
		});
		return true;
	});
	$(".apsite").bind("click", function(){
		document.location.href = "http://www.aprouter.com.br";
	});

}
function isHex(entry){
	validChar='0123456789ABCDEF';   
	strlen=entry.length;
	if(strlen<1){
		return false;
	}
	entry=entry.toUpperCase();
	for(idx=0;idx<strlen;idx++){
		if(validChar.indexOf(entry.charAt(idx))<0){
			return false;
		}
	}	 
	return true;
}
function saveTimeGrid(com,grid){
	if (com=='Gravar'){
		$("#message").html("");
		var i = 0;
		$(".cellbox").each(function(){
			i++;
			$("#message").append("<b>"+i+"</b> "+$(this).attr("name")+" "+$(this).attr("rel")+" "+$(this).is(":checked")+"<br/>");
		});
		$("#message").show();
		$("div.ptogtitle").click();
		//confirm('Selecionados ' + $('.cellbox',grid).length + ' items?')
	}
}
function showHelpMsg(item){
	$("#helpertext").html(msgArr[item]);
}
jQuery.fn.corner = function(o) {
    function hex2(s) {
        var s = parseInt(s).toString(16);
        return ( s.length < 2 ) ? '0'+s : s;
    };
    function gpc(node) {
        for ( ; node && node.nodeName.toLowerCase() != 'html'; node = node.parentNode  ) {
            var v = jQuery.css(node,'backgroundColor');
            if ( v.indexOf('rgb') >= 0 ) { 
                rgb = v.match(/\d+/g); 
                return '#'+ hex2(rgb[0]) + hex2(rgb[1]) + hex2(rgb[2]);
            }
            if ( v && v != 'transparent' )
                return v;
        }
        return '#ffffff';
    };
    function getW(i) {
        switch(fx) {
        case 'round':  return Math.round(width*(1-Math.cos(Math.asin(i/width))));
        case 'cool':   return Math.round(width*(1+Math.cos(Math.asin(i/width))));
        case 'sharp':  return Math.round(width*(1-Math.cos(Math.acos(i/width))));
        case 'bite':   return Math.round(width*(Math.cos(Math.asin((width-i-1)/width))));
        case 'slide':  return Math.round(width*(Math.atan2(i,width/i)));
        case 'jut':    return Math.round(width*(Math.atan2(width,(width-i-1))));
        case 'curl':   return Math.round(width*(Math.atan(i)));
        case 'tear':   return Math.round(width*(Math.cos(i)));
        case 'wicked': return Math.round(width*(Math.tan(i)));
        case 'long':   return Math.round(width*(Math.sqrt(i)));
        case 'sculpt': return Math.round(width*(Math.log((width-i-1),width)));
        case 'dog':    return (i&1) ? (i+1) : width;
        case 'dog2':   return (i&2) ? (i+1) : width;
        case 'dog3':   return (i&3) ? (i+1) : width;
        case 'fray':   return (i%2)*width;
        case 'notch':  return width; 
        case 'bevel':  return i+1;
        }
    };
    o = (o||"").toLowerCase();
    var keep = /keep/.test(o);                       // keep borders?
    var cc = ((o.match(/cc:(#[0-9a-f]+)/)||[])[1]);  // corner color
    var sc = ((o.match(/sc:(#[0-9a-f]+)/)||[])[1]);  // strip color
    var width = parseInt((o.match(/(\d+)px/)||[])[1]) || 10; // corner width
    var re = /round|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dog/;
    var fx = ((o.match(re)||['round'])[0]);
    var edges = { T:0, B:1 };
    var opts = {
        TL:  /top|tl/.test(o),       TR:  /top|tr/.test(o),
        BL:  /bottom|bl/.test(o),    BR:  /bottom|br/.test(o)
    };
    if ( !opts.TL && !opts.TR && !opts.BL && !opts.BR )
        opts = { TL:1, TR:1, BL:1, BR:1 };
    var strip = document.createElement('div');
    strip.style.overflow = 'hidden';
    strip.style.height = '1px';
    strip.style.backgroundColor = sc || 'transparent';
    strip.style.borderStyle = 'solid';
    return this.each(function(index){
        var pad = {
            T: parseInt(jQuery.css(this,'paddingTop'))||0,     R: parseInt(jQuery.css(this,'paddingRight'))||0,
            B: parseInt(jQuery.css(this,'paddingBottom'))||0,  L: parseInt(jQuery.css(this,'paddingLeft'))||0
        };

        if (jQuery.browser.msie) this.style.zoom = 1; // force 'hasLayout' in IE
        if (!keep) this.style.border = 'none';
        strip.style.borderColor = cc || gpc(this.parentNode);
        var cssHeight = jQuery.curCSS(this, 'height');

        for (var j in edges) {
            var bot = edges[j];
            strip.style.borderStyle = 'none '+(opts[j+'R']?'solid':'none')+' none '+(opts[j+'L']?'solid':'none');
            var d = document.createElement('div');
            var ds = d.style;

            bot ? this.appendChild(d) : this.insertBefore(d, this.firstChild);

            if (bot && cssHeight != 'auto') {
                if (jQuery.css(this,'position') == 'static')
                    this.style.position = 'relative';
                ds.position = 'absolute';
                ds.bottom = ds.left = ds.padding = ds.margin = '0';
                if (jQuery.browser.msie)
                    ds.setExpression('width', 'this.parentNode.offsetWidth');
                else
                    ds.width = '100%';
            }
            else {
                ds.margin = !bot ? '-'+pad.T+'px -'+pad.R+'px '+(pad.T-width)+'px -'+pad.L+'px' : 
                                    (pad.B-width)+'px -'+pad.R+'px -'+pad.B+'px -'+pad.L+'px';                
            }

            for (var i=0; i < width; i++) {
                var w = Math.max(0,getW(i));
                var e = strip.cloneNode(false);
                e.style.borderWidth = '0 '+(opts[j+'R']?w:0)+'px 0 '+(opts[j+'L']?w:0)+'px';
                bot ? d.appendChild(e) : d.insertBefore(e, d.firstChild);
            }
        }
    });
};

js_calcTimes = function() {
	$('#horasHidden').val('|'); 
	$('#horas').html('&nbsp;');
	F  = document.forms
	data_ini = new Date( 1970, 0, 1, 0, 0, 0, 0 ); 
	data_fin = new Date( 1970, 0, 1, 0, 0, 0, 0 );
	first = false; 
	last  = false;

	for ( i = 0; i < F.length; i++ ) {
		FF = F[i];

		for( x = 0; x < FF.length; x++ ) {
			if ( FF.elements[x].type == 'checkbox' && FF.elements[x].id.indexOf( 'check_hour_' ) != -1 ) {
				if ( FF.elements[x].value != 'A') {
					arr_val = FF.elements[x].value.split( '_' );
					
					if ( FF.elements[x].checked && !first ) {
						first = true;
						data_ini.setHours( arr_val[0] );
						data_ini.setMinutes( arr_val[1] - 10 );
						data_fin.setHours( arr_val[0] );
						data_fin.setMinutes( arr_val[1] );
					}
					
					if ( first && !last ) {
						if ( typeof( FF.elements[x + 2] ) == 'undefined' ) {
							if ( FF.elements[x + 1].value == 'LAST' ) {
								last  = true;
								data_fin.setHours( arr_val[0] );
								data_fin.setMinutes( arr_val[1] );
							}
						}

						if ( FF.elements[x + 1].value != 'A' ) {
							if ( ( !FF.elements[x + 1].checked ) ) {
								last  = true;
								data_fin.setHours( arr_val[0] );
								data_fin.setMinutes( arr_val[1] );
							}
						} else if ( ( !FF.elements[x + 2].checked ) ) {
							last  = true;
							data_fin.setHours( arr_val[0] );
							data_fin.setMinutes( arr_val[1] );
						}
					}
 
					
					if ( first && last ) {
					    var strHours =  str_pad( data_fin.getHours(), 2, 0 );
						if (strHours == 0) {
						  strHours = 24;
						}
						$('#horas').append(str_pad( data_ini.getHours(), 2, 0 ) + ':' + str_pad( data_ini.getMinutes(), 2, 0 ) + ' até ' + strHours + ':' + str_pad( data_fin.getMinutes(), 2, 0 ) + '<br>');
						$('#horas').css("background-color", '#00D22B'); 
						first = false;
						last  = false;
						$('#horasHidden').val($('#horasHidden').val() + str_pad( data_ini.getHours(), 2, 0 ) + ':' + str_pad( data_ini.getMinutes(), 2, 0 ) + ',' + strHours + ':' + str_pad( data_fin.getMinutes(), 2, 0 ) + '|');
					}
				}
			}
		}
	}
	
}

//	js_calcTimes();
var STR_PAD_LEFT = 1;
var STR_PAD_RIGHT = 2;
var STR_PAD_BOTH = 3;

function str_pad(str, len, pad, dir) {
    str = new String( str );
    if (typeof(len) == "undefined") { var len = 1; }
    if (typeof(pad) == "undefined") { var pad = ' '; }
    if (typeof(dir) == "undefined") { var dir = STR_PAD_LEFT; }

    if (len + 1 >= str.length) {

        switch (dir){

            case STR_PAD_LEFT:
                str = Array(len + 1 - str.length).join(pad) + str;
            break;

            case STR_PAD_BOTH:
                var right = Math.ceil((padlen = len - str.length) / 2);
                var left = padlen - right;
                str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
            break;

            default:
                str = str + Array(len + 1 - str.length).join(pad);
            break;

        } // switch

    }

    return str;

}
	
function putClockBar(hora, data){
	str_hora = hora;
	arr_hora = str_hora.split(':');
	hora     = arr_hora[0];
	minuto   = arr_hora[1];
	segundo  = arr_hora[2];

	str_data = data;
	arr_data = str_data.split('/');
	dia      = arr_data[0] - 1;
	mes      = arr_data[1];
	ano      = arr_data[2];

	momentoAtual = new Date(ano, mes, dia, hora, minuto, segundo);
}
function createDivInfo( str_id, str_msg ) {
	str_div   = null;
	str_divId = str_id + '_div';
	str_div   = document.createElement("DIV");
	str_div.id                    = str_divId;
	str_div.style.bgColor         = 'transparent';
	str_div.style.color           = '#000000';
	str_div.style.visibility      = 'hidden';
	str_div.style.position        = 'absolute';
	str_div.style.width           = '300px';
	str_div = $( str_id ).appendChild( str_div ); 
	str_imgSrc = imgbase + '/ic_alert.gif';
	str_iframeId = 'iframe_' + str_id;
	str_tableId  = 'iframe_' + str_id;
	int_sizeLine = new Number( str_msg.length / 40 );
	int_sizeLine = ( ( Math.ceil( int_sizeLine ) ) * 15 );
	int_sizeLine = ( int_sizeLine < 90 ? 90 : int_sizeLine );
	
	if( arguments[2] )
		int_sizeLine = arguments[2];
	
	str_html     = '<iframe id="' + str_iframeId + '" style="position:absolute; top: 0px; left: 0px; z-index: 1; width: 300px;" frameborder="0" height="' + int_sizeLine + '"></iframe><div style="width: 300px; height: ' + int_sizeLine + 'px; position:absolute; top:0px; left:0px; border: 2px solid #829DD1; background-color:#FFFFFF; z-index: 2"><table height="100%"><tr><td valign="top"><img border="0" src="' + str_imgSrc + '"></td><td valign="top" style="padding-top: 8px">' + str_msg + '</td></tr></table></div>';
	$( str_divId ).innerHTML       = str_html;

	$( str_id ).onmousemove = function( event ){
		getTopLeft( event );
		str_divId                 = str_id + '_div';
		$( str_divId ).style.top  = ( ( iens6 ? int_posTop : ( Event.pointerY( event ) + 5 ) ) ) + 'px';
		$( str_divId ).style.left = ( ( iens6 ? ( int_posLeft + 20 ) : ( Event.pointerX( event ) + 20 ) ) ) + 'px';
		$( str_divId ).style.visibility = 'visible';
	}
	$( str_id ).onmouseout = function(){
		str_divId                       = str_id + '_div';
		$( str_divId ).style.visibility = 'hidden';
	}

	$( str_id ).onclick = function(){
		$( str_id ).onmouseout
	}
}
function moveRelogio(){
    hora    = momentoAtual.getHours()
    minuto  = momentoAtual.getMinutes()
    segundo = momentoAtual.getSeconds()

    str_segundo = new String (segundo)
    if (str_segundo.length == 1)
       segundo = "0" + segundo

    str_minuto = new String (minuto)
    if (str_minuto.length == 1)
       minuto = "0" + minuto

    str_hora = new String (hora)
    if (str_hora.length == 1)
       hora = "0" + hora

    horaImprimivel = hora + ":" + minuto + ":" + segundo

    $("#clockbar").html(horaImprimivel);

	momentoAtual = Math.round( momentoAtual.getTime() / 1000 );
	momentoAtual = momentoAtual + 1;
	momentoAtual = new Date( momentoAtual * 1000 );

    setTimeout("moveRelogio()",1000)
}
function checkIpAddress(field){
	var dIp = field.val();
	var dIPerror = false;
	var blocos = dIp.split(".");
	var blocklist = "";
	if(blocos.length < 4)
		dIPerror = true;
	for (i=0;i<4;i++){
		blocos[i] = parseInt(blocos[i]);
		if (blocos[i] > 255){
			blocklist = blocklist + (i + 1) + ",";
			dIPerror = true;
		}
	}
	if (dIPerror){
		alert($.i18n._("error_ipaddress") + " " + blocklist);
		$(field).focus();
		return false;
	}
	return true;
}
function checkIpMask(field){
	var dIp = field.val();
	var dIPerror = false;
	var blocos = dIp.split(".");
	var blocklist = "";
	if(blocos.length < 4)
		dIPerror = true;
	for (i=0;i<4;i++){
		blocos[i] = parseInt(blocos[i]);
		if (blocos[i] > 255){
			blocklist = blocklist + (i + 1) + ".";
			dIPerror = true;
		}else{
			if( !(blocos[i]==0 || blocos[i]==128 || blocos[i]==192 || blocos[i]==224 || blocos[i]==240 || blocos[i]==248 || blocos[i]==252 || blocos[i]==254 || blocos[i]==255 )){
				blocklist = blocklist + (i + 1) + ",";
				dIPerror = true;
			}
		}
	}
	if (dIPerror){
		alert($.i18n._("error_subnetmask") + " " + blocklist);
		$(field).focus();
		return false;
	}
}

$(function() {
  if($.browser.msie && parseInt($.browser.version) < 7) {
	$.ajaxSetup({async: false});
	$.getScript('../interface/js/jquery.ifixpng.js');
	$.ajaxSetup({async: true});
	$.ifixpng('/blank.gif');
    $('div, span, table, img').ifixpng();
  };
});
