
$(function(){
	var usuarioForm = $('#user').val();
	if(usuarioForm != ''){
		$("#user").css({
			"background": "none"
		});
	}
});

function filtrarUsuario(mostrarFlash){
	var usuario = document.getElementById("user").value;
	var password = document.getElementById("password").value;

	if(usuario==''){
		document.getElementById("msgError").innerHTML = 'Falta el usuario';
		return false;
	}else if(password == ''){
		document.getElementById("msgError").innerHTML = 'Falta la contrase&ntilde;a';
		return false;
	}
	
	$.getJSON(contextPath+'/com/cablevision/controller/email/begin.do',
		{user: usuario,password:password},
		function(data){
			if(data.success){
				//mandar correo gmail
				document.getElementById("Email").value = usuario;
				
				//document.getElementById("msgDiv").innerHTML = 'Por seguridad el correo se abrir&aacute; en otra ventana';
				//document.getElementById("btnDiv1").style.display = 'none';
				//document.getElementById("btnDiv2").style.display = 'block';
				
				//showPopupHeader();
				
				submitGmailForm();
			}else{
				if(mostrarFlash=='true'){
					//mostrar flash para migrar
					document.getElementById("userCorreo").value = usuario;
					document.getElementById("psswrd").value = password;
					document.getElementById("correoCable").submit();
				}else{
					//mandar correo de cablevision
					irCorreoCablevision(usuario, password);
				}
			}
	});
	
	return false;
}
function submitGmailForm(){
	document.getElementById("gaia_loginform").submit();
	disablePopupHeader();
}

function showFlash(){
	var usuario = document.getElementById("user").value;
	var password = document.getElementById("password").value;
	
	document.getElementById("userCorreo").value = usuario;
	document.getElementById("psswrd").value = password;
	document.getElementById("correoCable").submit();	
}


function showCorreo(migrar,user,passw){
	if(migrar=='true'){
		document.getElementById("formMigracion").submit();
	}else{
		if((user=='') || (passw=='')){
			if(document.getElementById("user").value == '' || document.getElementById("password").value == ''){
				document.getElementById("msgDiv").innerHTML = 'Debe de Ingresar Usuario y Contrase&ntilde;a';
				showPopupHeader();
			}else{
				irCorreoCablevision(document.getElementById("user").value, document.getElementById("password").value);	
			}
		}else{
			irCorreoCablevision(user,passw);
		}
	}
}

function irCorreoCablevision(usuario, password){
	document.getElementById("userCable").value = usuario;
	document.getElementById("passwordCable").value = password;
	document.getElementById("formCorreo").submit();
}

function showSubMenu(oElement){
	var y = getY(oElement);
	var x = getX(oElement);
	$("#submenu").css({
			"display": "block",
			"position":"absolute",
			"top": y,
			"left": x
		});
}

function hideSubMenu(){
	$("#submenu").css({
			"display": "none"
		});
}

function getY(oElement){
	var iReturnValue = 0;
	while(oElement != null) {
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getX(oElement){
	var iReturnValue = 0;
	while(oElement != null) {
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}
