﻿function findDocumento(obj, obj1)
{
   if (obj1.value != null && obj1.value != '')
 	  App_SuRVirtual_Default.FindDocumento(obj.value, obj1.value, FindDocumento_callback);      
}

function FindDocumento_callback(response)
{
   if (response.error == null){
        var ds = response.value; 
		if(ds!= null && typeof(ds) == "object" && ds.Tables!= null){
		    if (ds.Tables[0].Rows[0]!=null)
		    {
  		        document.getElementsByName("ctl00$mainCopy$txtApellido")[0].value = ds.Tables[0].Rows[0].Apellido;
  		        document.getElementsByName("ctl00$mainCopy$txtNombres")[0].value = ds.Tables[0].Rows[0].Nombre;
                document.getElementsByName("ctl00$mainCopy$txtMail")[0].value = ds.Tables[0].Rows[0].Mail;
                document.getElementsByName("ctl00$mainCopy$txtTelefono")[0].value = ds.Tables[0].Rows[0].Telefonos;
                document.getElementsByName("ctl00$mainCopy$ddlDomicilioTipo")[0].value = ds.Tables[0].Rows[0].TC_ID;
                document.getElementsByName("ctl00$mainCopy$txtDomicilioNro")[0].value = ds.Tables[0].Rows[0].Calle_Numero;
                document.getElementsByName("ctl00$mainCopy$ddlDomicilioLocalidad")[0].value = ds.Tables[0].Rows[0].LOC_ID;
                document.getElementsByName("ctl00$mainCopy$txtDomicilioNombre")[0].value = ds.Tables[0].Rows[0].Calle_Nombre;
                document.getElementsByName("ctl00$mainCopy$txtDomicilioAltura")[0].value = ds.Tables[0].Rows[0].Calle_Altura;
                document.getElementsByName("ctl00$mainCopy$txtDomicilioPlanta")[0].value = ds.Tables[0].Rows[0].Piso;
                document.getElementsByName("ctl00$mainCopy$txtDomicilioDto")[0].value = ds.Tables[0].Rows[0].Departamento;
                document.getElementsByName("ctl00$mainCopy$txtPSId")[0].value = ds.Tables[0].Rows[0].PS_ID;
                if (ds.Tables[0].Rows[0].Partida != "999999")
                    document.getElementsByName("ctl00$mainCopy$txtPartida")[0].value = ds.Tables[0].Rows[0].Partida;

                var radioButtons = document.getElementsByName("ctl00$mainCopy$rbSexo");
                for (var x = 0; x < radioButtons.length; x ++) {
                    if (radioButtons[x].value == ds.Tables[0].Rows[0].Sexo)
                        radioButtons[x].checked = "checked";
                }       
               setCtrls("disabled");	
               document.getElementsByName("ctl00$mainCopy$txtMail")[0].focus();
               if (document.getElementsByName("ctl00$mainCopy$txtTelefono")[0].value == "") 
                    document.getElementsByName("ctl00$mainCopy$txtTelefono")[0].disabled = "";		
            }	
            else
            {
    	        document.getElementsByName("ctl00$mainCopy$txtApellido")[0].value = "";
	            document.getElementsByName("ctl00$mainCopy$txtNombres")[0].value = "";
                document.getElementsByName("ctl00$mainCopy$txtMail")[0].value = "";
                document.getElementsByName("ctl00$mainCopy$txtTelefono")[0].value = "";
                document.getElementsByName("ctl00$mainCopy$ddlDomicilioTipo")[0].value = "1";
                document.getElementsByName("ctl00$mainCopy$txtDomicilioNro")[0].value = "";
                document.getElementsByName("ctl00$mainCopy$ddlDomicilioLocalidad")[0].value = "30";
                document.getElementsByName("ctl00$mainCopy$txtDomicilioNombre")[0].value = "";
                document.getElementsByName("ctl00$mainCopy$txtDomicilioAltura")[0].value = "";
                document.getElementsByName("ctl00$mainCopy$txtDomicilioPlanta")[0].value = "";
                document.getElementsByName("ctl00$mainCopy$txtDomicilioDto")[0].value = "";
                document.getElementsByName("ctl00$mainCopy$txtPartida")[0].value = "";
                document.getElementsByName("ctl00$mainCopy$txtPSId")[0].value = "0";
                document.getElementsByName("ctl00$mainCopy$rbSexo")[0].checked = "checked";
                setCtrls("");
                document.getElementsByName("ctl00$mainCopy$txtApellido")[0].focus();
            }
            
		}
   } 
} 

function setCtrls(state)
{
 	document.getElementsByName("ctl00$mainCopy$txtApellido")[0].disabled = state;
    document.getElementsByName("ctl00$mainCopy$txtNombres")[0].disabled = state;
    document.getElementsByName("ctl00$mainCopy$txtTelefono")[0].disabled = state;
    document.getElementsByName("ctl00$mainCopy$rbSexo")[0].disabled = state;
    document.getElementsByName("ctl00$mainCopy$rbSexo")[1].disabled = state;
    document.getElementsByName("ctl00$mainCopy$ddlDomicilioTipo")[0].disabled = state;
    document.getElementsByName("ctl00$mainCopy$txtDomicilioNro")[0].disabled = state;
    document.getElementsByName("ctl00$mainCopy$ddlDomicilioLocalidad")[0].disabled = state;
    document.getElementsByName("ctl00$mainCopy$txtDomicilioNombre")[0].disabled = state;
    document.getElementsByName("ctl00$mainCopy$txtDomicilioAltura")[0].disabled = state;
    document.getElementsByName("ctl00$mainCopy$txtDomicilioPlanta")[0].disabled = state;
    document.getElementsByName("ctl00$mainCopy$txtDomicilioDto")[0].disabled = state;
    if (document.getElementsByName("ctl00$mainCopy$txtPartida")[0].value != "")
        document.getElementsByName("ctl00$mainCopy$txtPartida")[0].disabled = state;
}

function setReclamo()
{
        var varSexo;
        var radioButtons = document.getElementsByName("ctl00$mainCopy$rbSexo");
        for (var x = 0; x < radioButtons.length; x ++) {
            if (radioButtons[x].checked)
                varSexo = radioButtons[x].value;
        }       
 	    App_SuRVirtual_Default.SetReclamo(document.getElementsByName("ctl00$mainCopy$txtPSId")[0].value,
 	        document.getElementsByName("ctl00$mainCopy$txtApellido")[0].value,
 	        document.getElementsByName("ctl00$mainCopy$txtNombres")[0].value,
 	        document.getElementsByName("ctl00$mainCopy$ddlDocumentoTipo")[0].value,
 	        document.getElementsByName("ctl00$mainCopy$txtDocumentoNro")[0].value,
 	        varSexo,
 	        document.getElementsByName("ctl00$mainCopy$txtTelefono")[0].value,
 	        document.getElementsByName("ctl00$mainCopy$txtMail")[0].value,
 	        document.getElementsByName("ctl00$mainCopy$ddlDomicilioTipo")[0].value,
 	        document.getElementsByName("ctl00$mainCopy$txtDomicilioNro")[0].value,
 	        document.getElementsByName("ctl00$mainCopy$txtDomicilioNombre")[0].value,
 	        document.getElementsByName("ctl00$mainCopy$txtDomicilioAltura")[0].value,
            document.getElementsByName("ctl00$mainCopy$txtDomicilioPlanta")[0].value,
            document.getElementsByName("ctl00$mainCopy$txtDomicilioDto")[0].value,
            document.getElementsByName("ctl00$mainCopy$ddlDomicilioLocalidad")[0].value,
            document.getElementsByName("ctl00$mainCopy$txtPartida")[0].value,
            document.getElementsByName("ctl00$mainCopy$ddlSubTipo")[0].value,
            document.getElementsByName("ctl00$mainCopy$txtMotivo")[0].value,
 	        document.getElementsByName("ctl00$mainCopy$ddlCalleTipo")[0].value,
            document.getElementsByName("ctl00$mainCopy$txtCalleNro")[0].value,
 	        document.getElementsByName("ctl00$mainCopy$txtCalleNombre")[0].value,
 	        document.getElementsByName("ctl00$mainCopy$txtCalleAltura")[0].value,
            document.getElementsByName("ctl00$mainCopy$txtCalleEntreNro1")[0].value,
 	        document.getElementsByName("ctl00$mainCopy$txtCalleEntreNombre1")[0].value,
 	        document.getElementsByName("ctl00$mainCopy$txtCalleEntreNro2")[0].value,
 	        document.getElementsByName("ctl00$mainCopy$txtCalleEntreNombre2")[0].value,
 	        document.getElementsByName("ctl00$mainCopy$ddlLocalidad")[0].value,
 	        document.getElementsByName("ctl00$mainCopy$txtToken")[0].value,
            SetReclamo_callback);
}

function SetReclamo_callback(response)
{
   if (response.error == null || response.value == null){
      window.location="Notificar.aspx";}
   else {
     window.location="Error.aspx";}
}

function validar() {
    if (WebForm_DoPostBackWithOptions_Override(new WebForm_PostBackOptions_Override('', '', true, '', '', false, true)))
        setReclamo();
}

function WebForm_PostBackOptions_Override(eventTarget, eventArgument, validation, validationGroup, actionUrl, trackFocus, clientSubmit) {
    this.eventTarget = eventTarget;
    this.eventArgument = eventArgument;
    this.validation = validation;
    this.validationGroup = validationGroup;
    this.actionUrl = actionUrl;
    this.trackFocus = trackFocus;
    this.clientSubmit = clientSubmit;
}

function WebForm_DoPostBackWithOptions_Override(options) {
    var validationResult = true;
    if (options.validation) {
        if (typeof(Page_ClientValidate) == 'function') {
            validationResult = Page_ClientValidate(options.validationGroup);
        }
    }
    if (validationResult) {
        if ((typeof(options.actionUrl) != "undefined") && (options.actionUrl != null) && (options.actionUrl.length > 0)) {
            theForm.action = options.actionUrl;
        }
        if (options.trackFocus) {
            var lastFocus = theForm.elements["__LASTFOCUS"];
            if ((typeof(lastFocus) != "undefined") && (lastFocus != null)) {
                if (typeof(document.activeElement) == "undefined") {
                    lastFocus.value = options.eventTarget;
                }
                else {
                    var active = document.activeElement;
                    if ((typeof(active) != "undefined") && (active != null)) {
                        if ((typeof(active.id) != "undefined") && (active.id != null) && (active.id.length > 0)) {
                            lastFocus.value = active.id;
                        }
                        else if (typeof(active.name) != "undefined") {
                            lastFocus.value = active.name;
                        }
                    }
                }
            }
        }
        if (options.clientSubmit)
            return true;
        else return false;
    }
}


function printPreview(print_area)
{	
	var pp = window.open();
	pp.document.writeln('<HTML><HEAD><title></title><LINK href="Style/Styles.css"  type="text/css" rel="stylesheet">')
	pp.document.writeln('<LINK href="Style/PrintStyle.css"  type="text/css" rel="stylesheet" media="print"<base target="_blank_self"></HEAD>')
	pp.document.writeln('<body MS_POSITIONING="GridLayout" bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0">');
	pp.document.writeln('<form  method="post">');
	pp.document.writeln('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=Left width=50%><TD align=right width=50%><INPUT ID="PRINT" type="button" value="Imprimir" onclick="javascript:location.reload(true);window.print();">&nbsp;&nbsp;&nbsp;<INPUT ID="CLOSE" type="button" value="Cerrar" onclick="window.close();"></TD></TR><TR><TD></TD></TR></TABLE>');
	pp.document.writeln(print_area);
	pp.document.writeln('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=right><INPUT ID="PRINT" type="button" value="Imprimir" onclick="javascript:location.reload(true);window.print();">&nbsp;&nbsp;&nbsp;<INPUT ID="CLOSE" type="button" value="Cerrar" onclick="window.close();"></TD></TR><TR><TD></TD></TR></TABLE>');
	pp.document.writeln('</form></body></HTML>');			

}		

