﻿//Sys.Application.initialize();

$(document).ready(function() {
    //var a = document.getElementById('<%= txbCbo.ClientID %>');
    //alert("K" + a);
    if ($("ul.toggler-c").length) {
        $('ul.toggler-c').toggleElements({
            fxAnimation: 'slide', fxSpeed: 'fast', className: 'toggler'
        });
    }
    if ($("ul.cat-toggler").length) {
    $('ul.cat-toggler').toggleElements({
        fxAnimation: 'slide', fxSpeed: 'fast', className: 'cattoggler'
    });
    }
    
    // Hidden txt of the field
    if ($(".inpFunc").length) { $(".inpFunc").inputLabel("Digite uma função",{force:true}); }
    if ($(".inpSetor").length) { $(".inpSetor").inputLabel("Digite um setor",{force:true}); }
    if ($(".riscoF").length) { $(".riscoF").inputLabel("Digite um novo risco",{force:true}); }
    if ($(".fatorRisco").length) { $(".fatorRisco").inputLabel("Digite um fator de risco",{force:true}); }
    if ($(".txbCtpsSerie").length) { $(".txbCtpsSerie").inputLabel("Série",{force:true}); }
    if ($(".txbCtpsUf").length) { $(".txbCtpsUf").inputLabel("UF",{force:true}); }
    
    /*$("#AddCat").click(function (){ $("#boxHidden1").toggle(); });
    */

    // SELECT ALL CHECKBOX
    $("#ckbAllFunc").click(function(){
        if(this.checked) {v = true;} else {v = false;}
        $(":checkbox[name!='allFunc']").each(function() {this.checked = v;});
    });
    $("#ckbAllSetor").click(function(){
        if(this.checked) {v = true;} else {v = false;}
        $(":checkbox[name!='allSetor']").each(function() {this.checked = v;});
    });
    $("#ckbAllRiscos").click(function(){
        if(this.checked) {v = true;} else {v = false;}
        $(":checkbox[name!='allRiscos']").each(function() {this.checked = v;});
    });
    $("#ckbAllExames").click(function(){
        if(this.checked) {v = true;} else {v = false;}
        $(":checkbox[name!='allExames']").each(function() {this.checked = v;});
    });
    
    /*$(".cInput").focus(function(){ $(this).val(""); });
    $(".cInput").blur(function(){ 
    if ($(this).val() == "") {
    $(this).val("Adicionar Nova Categoria"); 
    }
    });*/

    //Sys.Application.initialize();
    // handle Application init
    //Sys.Application.add_init( function() { alert("init!") } );
    // handle Application load
    //Sys.Application.add_load( function() { alert("load!") } );
    // handle Application unload
    //Sys.Application.add_unload( function() { alert("unload!") } );

    //Sys.Application.add_init( AddInit );
    //Adicione uma function que irá executar seus comandos JQuery no load
    //Sys.Application.add_load( AddLoad );

    // AFTER CLICK HIDDEN MODAL AND REDIRECT FOR PAGE
    $(".btnFechar").click(function() {
        $(".modalPopup").hide();
        window.location = "addPost.aspx";
    });
    /* Slide da home */
    if ($("#crossslide").length) { 
        $('#crossslide').crossSlide({
	          speed: 65,
	          fade: 0.5
	        }, [
	          {
		        src:  'img/h-001.jpg',
		        href: '',
		        dir: 'down'
	          }, {
		        src:  'img/h-002.jpg',
		        href: '',
		        dir: 'up'
	          }, {
		        src:  'img/h-003.jpg',
		        href: '',
		        dir: 'down'
	          }, {
		        src:  'img/h-004.jpg',
		        href: '',
		        dir: 'up'
	          }, {
		        src:  'img/h-005.jpg',
		        href: '',
		        dir: 'up'
	          }, {
		        src:  'img/h-006.jpg',
		        href: '',
		        dir: 'down'
	          }, {
		        src:  'img/h-007.jpg',
		        href: '',
		        dir: 'up'
	          }
	    ]);
	}
	/* Slide da empresa */
	if ($("#empresa").length) { 
        $('#empresa').crossSlide({
          speed: 15,
          fade: 0.5
        }, [
          {
	        src:  'http://www.veraorsi.com.br/img/h-003.jpg',
	        href: '',
	        dir: 'down'
          }, {
	        src:  'img/h-002.jpg',
	        href: '',
	        dir: 'up'
          }, {
	        src:  'img/h-001.jpg',
	        href: '',
	        dir: 'down'
          }, {
	        src:  'img/h-005.jpg',
	        href: '',
	        dir: 'up'
          }, {
	        src:  'img/h-006.jpg',
	        href: '',
	        dir: 'down'
          }, {
	        src:  'img/h-007.jpg',
	        href: '',
	        dir: 'up'
          }
        ]);
    }
    //Raised after all content on the page is refreshed
    //Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);

    //Raised before the processing of an asynchronous postback starts
    //	Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);

    //Raised during the initialization of the asynchronous postback
    //	Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(CheckStatus);

    //Raised after the response from the server to an asynchronous postback
    //Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(pageLoadingHandler)
});

/*function Populated(sender, e) {
    var behavior = $find('AutoCompleteEx');
    var target = behavior.get_completionList();
    var children = target.childNodes;
    
    var searchText = $get('<%= txbCbo.ClientID %>');

    for (var i = 0; i < children.length; i++) {
        var child = children[i];
        var value = child._value;
        //alert("ok - " + child + " - " + value);
        //child.innerHTML = eval("value.replace(/(" + searchText + ")/i, '<b>$1</b>')");
    }
}*/
function itemSelected(ev) { 
    //var index = $find("AutoCompleteEx")._selectIndex;
    //var dd = $find("AutoCompleteEx").get_completionList().childNodes[index]._value;
    //$find("AutoCompleteEx").get_element().value = dd;
    
}

// LOAD FUNCTION OF CATEGORY
function pageLoaded(sender, args) {	ActiveFunction(); }
function pageLoadingHandler(sender, args) {	ActiveFunction(); }
function ActiveFunction() {
	$('#AddCat').click(function(){ $("#boxHidden1").toggle(); });
    $("#DelCat").click(function(){ $("#boxHidden2").toggle(); });

	/*$(".inpFunc").focus(function(){ $(this).val(""); });
    $(".inpFunc").blur(function(){ 
        if ($(this).val() == "") {
            $(this).val("Digite uma função"); 
        }
    });*/
    
    // SELECT ALL CHECKBOX
    /*$("#ckbAllCat").click(function(){
        if(this.checked) {v = true;} else {v = false;}
        $(":checkbox[name!='allCat']").each(function() {this.checked = v;});
    });*/
}
// MODAL
/*var launch = false;
function launchModal() { launch = true; }
function pageLoad() { if (launch) { $find("mpe").show(); } }*/
/*function finalizar() {
    var xmlHttp = false;
    try {
        xmlHttp = new XMLHttpRequest();
    } catch (e1) {
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e2) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    xmlHttp.open("GET", "addPost.aspx", true);
    xmlHttp.send(null);*/
//}
// Valida CPF
function validaCPF(oSrc, args) {
    s = args.Value;
    //substituir os caracteres que nÆo sÆo n£meros
    if (document.layers && parseInt(navigator.appVersion) == 4) {
        x = s.substring(0, 3);
        x += s.substring(4, 7);
        x += s.substring(8, 11);
        x += s.substring(12, 14);
        s = x;
    }
    /*else {
    s = s. replace (".","");
    s = s. replace (".","");
    s = s. replace ("-","");
    }*/
    if (s.length != 11 || s == "00000000000" || s == "11111111111" || s == "22222222222" || s == "33333333333" || s == "44444444444" || s == "55555555555" || s == "66666666666" || s == "77777777777" || s == "88888888888" || s == "99999999999" || s == "12345678909") {
        return args.IsValid = false;
    }
    //args.isValid = (s >= 3);
    //document.write(oSrc.Value + ',' + args.Value);
    if (isNaN(s)) {
        return args.IsValid = false;
    }
    var i;
    var c = s.substr(0, 9);
    var dv = s.substr(9, 2);
    var d1 = 0;
    for (i = 0; i < 9; i++) {
        d1 += c.charAt(i) * (10 - i);
    }
    if (d1 == 0) {
        return args.IsValid = false;
    }
    d1 = 11 - (d1 % 11);
    if (d1 > 9) d1 = 0;
    if (dv.charAt(0) != d1) {
        return args.IsValid = false;
    }
    d1 *= 2;
    for (i = 0; i < 9; i++) {
        d1 += c.charAt(i) * (11 - i);
    }
    d1 = 11 - (d1 % 11);
    if (d1 > 9) d1 = 0;
    if (dv.charAt(1) != d1) {
        return args.IsValid = false;
    }
    return args.IsValid = true;
}
