var app = angular.module('app', ['ngResource']);
app.controller('LoginCtrl', function ($scope, $http) {
	$scope.usrname = "";
	$scope.usrpass = "";
	$scope.users = [];
	$scope.validator = "";
	$scope.GetLogin = function() {
		//console.log($scope.usrname+","+$scope.usrpass);
		if($scope.usrname == "demo" && $scope.usrpass == "demo"){
			window.location = "home.html";
			//localStorage.setItem('key', 'value');
			//localStorage.removeItem('key');
			//var value = localStorage.getItem('key');
		}else{
			alert("Usuario y/o contraseña incorrecta");
		}
		//$http.get('js/services/login.php?usrname='+$scope.usrname+'&pss='+$scope.usrpass).
        //success(function(data) {
            // here the data from the api is assigned to a variable named users
            //$scope.users = data;
			//$scope.Type = data.split(",")[1];
			//sharedProperties.setProperty($scope.Type);
			//$scope.validator = data.split(",")[0];
        //}).then(function (data){
			//if($scope.validator == 1){
				//alert("Credenciales Validas");
				//$scope.usrname = "";
				//$scope.usrpass = "";
				//window.location = "Home.html";
			//}else{
				//alert("Credenciales No Validas");
				//$scope.usrname = "";
				//$scope.usrpass = "";
			//}
		//});
	};
});
app.service('sharedProperties', function () {
        var property;
        return {
            getProperty: function () {
                return property;
            },
            setProperty: function(value) {
                property = value;
            }
        };
    });
	
app.directive('ngEnter', function () {
    return function (scope, element, attrs) {
        element.bind("keydown keypress", function (event) {
            if(event.which === 13) {
				//alert("enter");
                scope.$apply(function (){
                    scope.$eval(attrs.ngEnter);
                });
 
                event.preventDefault();
            }
        });
    };
});
app.controller('Escenarios',function ($scope, $http, $location, sharedProperties){
	$scope.DelEsc = function () {
		var EscId = document.getElementById("hiddeninput").value.split(",")[0];
		var Estado = document.getElementById("hiddeninput").value.split(",")[1];
		console.log(EscId);
		$http.get('js/services/delesc.php?EscId='+EscId).
        success(function(data) {
			console.log(data);
			location.reload();
			//document.getElementById("example").style.display = "none";
			//document.getElementById("example").style.display = "block";
        });
    }
	$scope.ChangPen = function () {
		var EscId = document.getElementById("hiddeninput").value;
		var Est = "Pendiente";
		//console.log(EscId);
		$http.get('js/services/changuest.php?EscId='+EscId+'&Est='+Est).
        success(function(data) {
			console.log(data);
			location.reload();
			//document.getElementById("example").style.display = "none";
			//document.getElementById("example").style.display = "block";
        });
    }
	$scope.ChangInac = function () {
		var EscId = document.getElementById("hiddeninput").value;
		var Est = "Inactivo";
		//console.log(EscId);
		$http.get('js/services/changuest.php?EscId='+EscId+'&Est='+Est).
        success(function(data) {
			console.log(data);
			location.reload();
			//document.getElementById("example").style.display = "none";
			//document.getElementById("example").style.display = "block";
        });
    }
	$scope.AddEsc = function () {
		var Nesc = document.getElementById("txtNombreEscenario").value;
		var Cesc = document.getElementById("txtCicloEscenario").value;
		var Vesc = document.getElementById("txtVersionEscenario").value;
		$http.get('js/services/addesc.php?Nesc='+Nesc+'&Cesc='+Cesc+'&Vesc='+Vesc).
        success(function(data) {
			console.log(data);
			location.reload();
			//document.getElementById("example").style.display = "none";
			//document.getElementById("example").style.display = "block";
			var dialog = document.getElementById('window');
			dialog.close();
        });
        //alert(data);
		//console.log(EscId);
		//alert("El valor es: "+document.getElementById(data).value);
		//alert(data);
    }
	$scope.UpdateNEsc = function (data) {
		var idelement = data.split(",")[0];
		var Nesc = document.getElementById(data.split(",")[0]).value;
		var EscId = data.split(",")[1];
		document.getElementById(data.split(",")[0]).readOnly = true;
		$http.get('js/services/updesc.php?Nesc='+Nesc+'&EscId='+EscId).
        success(function(data) {
			console.log(data);
        });
        //alert(data);
		//console.log(EscId);
		//alert("El valor es: "+document.getElementById(data).value);
		//alert(data);
    }
	$scope.UpdateVer = function (data) {
		var idelement = data.split(",")[0];
		var Nesc = document.getElementById(data.split(",")[0]).value;
		var EscId = data.split(",")[1];
		document.getElementById(data.split(",")[0]).readOnly = true;
		$http.get('js/services/updver.php?Nesc='+Nesc+'&EscId='+EscId).
        success(function(data) {
			console.log(data);
        });
        //alert(data);
		//console.log(EscId);
		//alert("El valor es: "+document.getElementById(data).value);
		//alert(data);
    }
	$scope.UpdateCic = function (data) {
		var idelement = data.split(",")[0];
		var Nesc = document.getElementById(idelement).value;
		var EscId = data.split(",")[1];
		document.getElementById(data.split(",")[0]).readOnly = true;
		$http.get('js/services/updcic.php?Nesc='+Nesc+'&EscId='+EscId).
        success(function(data) {
			console.log(data);
        });
        //alert(data);
		//console.log(EscId);
		//alert("El valor es: "+document.getElementById(data).value);
		//alert(data);
    }
	$scope.escenarios = [];
	$http.get('js/services/GetEscs.php').
        success(function(data) {
			$scope.escenarios = data;			

        });
		
});





