var timeoutsuporte;
var timeoutservico;

$(document).ready(function() {
	
	$('#menuServicos').mouseenter(function() {
		$('#submenuServicos').stop(true,true).slideDown(200);
		$('#menuServicos').addClass('hover');
		clearTimeout(timeoutservico);
	});
	
	$('#submenuServicos').mouseenter(function() {
		clearTimeout(timeoutservico);
	});
	
	$('#menuServicos').mouseleave(function() {
		timeoutservico = setTimeout("fechaMenuServicos()", 100);
	});
	
	$('#submenuServicos').mouseleave(function() {
		timeoutservico = setTimeout("fechaMenuServicos()", 100);
	});
	
	
	$('#menuSuporte').mouseenter(function() {
		$('#submenuSuporte').stop(true,true).slideDown(200);
		$('#menuSuporte').addClass('hover');
		clearTimeout(timeoutsuporte);
	});
	
	$('#submenuSuporte').mouseenter(function() {
		clearTimeout(timeoutsuporte);
	});
	
	$('#menuSuporte').mouseleave(function() {
		timeoutsuporte = setTimeout("fechaMenuSuporte()", 100);
	});
	
	$('#submenuSuporte').mouseleave(function() {
		timeoutsuporte = setTimeout("fechaMenuSuporte()", 100);
	});
	
	$('.mudaForm').click(function(e){
		e.preventDefault();
		$('.bgLoginTopo').slideUp('fast').delay(200).slideDown('fast');
		$('.mudaForm').removeClass('hover');
		$(this).addClass('hover');
		if ($(this).attr('data-rel') == 'webmail') {
			$('#frm_login').attr('data-email','true');
			$('input[data-xd="usuario"]').attr('name','User');			
			$('input[data-xd="senha"]').attr('name','Password');
		} else if ($(this).attr('data-rel') == 'tellfree') {
			document.getElementById("erro_email").style.display = "none";
			$('#frm_login').attr('data-email','false');
			$('#frm_login').attr('action','http://ngn.tellfree.com.br/login.aspx');
			$('input[data-xd="usuario"]').attr('name','txtUsuario');
			$('input[data-xd="senha"]').attr('name','txtSenha');
		} else if ($(this).attr('data-rel') == 'corporativos') {
			document.getElementById("erro_email").style.display = "none";
			$('#frm_login').attr('data-email','false');
			$('#frm_login').attr('action','http://www.netwizard.com.br/clientes/logon.asp');
			$('input[data-xd="usuario"]').attr('name','user');
			$('input[data-xd="senha"]').attr('name','pass');
		} else if ($(this).attr('data-rel') == 'central') {
			document.getElementById("erro_email").style.display = "none";
			$('#frm_login').attr('data-email','false');
			$('#frm_login').attr('action','../centraldoassinante/logon.asp');
			$('input[data-xd="usuario"]').attr('name','User');
			$('input[data-xd="senha"]').attr('name','Password');
		}
	});
	
	$('#frm_login').submit(function(){
		if($('#frm_login').attr('data-email') == "true"){
			var email = $('input[data-xd="usuario"]').val();
			$('#frm_login').attr('action','#');			
			if ((email.indexOf(".") > 0) && (email.indexOf("@") > 0) && (email.length > 3) && (email != "@.")) {
				
				email = email.split("@");
				if($('#frm_login').attr('data-email') == "true"){
					if(email[1] == "netwizard.com.br"){
						$('#frm_login').attr('action','http://webmail.netwizard.com.br/WorldClient.dll?View=Main');				
						document.getElementById("erro_email").style.display = "none";
					}else{
						$('#frm_login').attr('action','http://corpweb.netwizard.com.br/WorldClient.dll?View=Main');	
						document.getElementById("erro_email").style.display = "none";
					}
				}else{
					return true;
				}
			} else {
				document.getElementById("erro_email").style.display = "";
				return false;
			}		
		}else{
			return true;
		}
	});
	
});
function fechaMenuSuporte() {
	$('#submenuSuporte').stop(true,true).slideUp(200);
	$('#menuSuporte').removeClass('hover');
}

function fechaMenuServicos() {
	$('#submenuServicos').stop(true,true).slideUp(200);
	$('#menuServicos').removeClass('hover');
}

function swapI(obj,focus){
	if(focus){
		if(obj.value == obj.attributes["label"].value){
			obj.value = "";
		}
	} else {
		if(obj.value.trim() == ""){
			obj.value = obj.attributes["label"].value;
		}
	}
}
function swapP(obj,focus){
	if(focus){
		var pass = document.getElementById(obj.attributes["parent"].value);
		if(pass){
			obj.innerHTML = "";
			pass.focus();
		}
	} else {
		if(obj.value == ""){
			var div = document.getElementById("div"+obj.id);
			if(div){
				div.innerHTML = obj.attributes["label"].value;
			}
		}
	}
}

$(function(){ 
	settings = {
		  tl: { radius: 20 },
		  tr: { radius: 20 },
		  bl: { radius: 20 },
		  br: { radius: 20 },
		  autoPad: true,
		  validTags: ["span"]
	  }
	$('.bannerInternas-').corner(settings);
});
