/***************************************************************************************************/
/*****************************************FUNCIONES AJAX********************************************/
/***************************************************************************************************/
function setBoton(valor){
	if(valor == 1){
		eval(document.form1.emailCantv.type='hidden');
	}
}

function execJS(node,target,pagina) {
	//alert("hola");
	var strExec;
  	var stringNoScript;
	var stringNoScriptSelectEstado;
  
	strExec="";
	strExecSelectEstado ="";
	stringNoScript = "";
	stringNoScriptSelectEstado="";
		
	//En caso de que sea llamada por direcctorio telefónico
	//En caso de que se modifique la lista de tipo de cliente
	if(pagina=="SMS"){
		//alert("Se ejecuta la pagina de SMS")
	
		var st = this.req.responseText.split("#$%&");
		//alert("cero"+st[0])
		//alert("uno"+st[1])
		//alert("uno"+st[1])
		
		for(var i=0;i<st.length; i++){     
			//alert("Estas en el for")
			//alert("El valor de i es: "+i+" y el modulo i%2 es: "+(i%2))
			if(i%2==0) {
				//alert("estas en el si")
				
				stringNoScript = stringNoScript + st[i];
			}else{
				//alert("Estas en el NO")
				strExec = strExec + st[i];
			}
			//alert("Sales del for")
		}
		
		//alert("El codigo script que se va a evaluar es:\n\n\n "+strExec);
		//alert("El codigo NO SCRIPT que se va a ejecutar es:\n\n\n "+stringNoScript);
		
		document.getElementById(target).innerHTML = stringNoScript;	  
		eval(strExec);
	
	
	//En caso de que la pagina a traese no contenga ningun script de validacion
	}else{
	
	//alert("Se ejecuta la pagina que no contiene validaciones scripts")
	document.getElementById(target).innerHTML = node;	  
	}
	  
}	
function ahah(method,url,target,pagina,str) {
	if(method == "GET"){
		// native XMLHttpRequest object
		//alert(target);
		document.getElementById(target).innerHTML = 'Cargando, por favor espere...';
	   if (window.XMLHttpRequest) {
		   req = new XMLHttpRequest();
		   
			//alert("entras en ahah");
		   req.onreadystatechange = function() {ahahDone(target,pagina);};
		   //	alert("si");
		   req.open("GET", url, true);
		   req.send(null);
	   
	   // IE/Windows ActiveX version
	   } else if (window.ActiveXObject) {
		   req = new ActiveXObject("Microsoft.XMLHTTP");
		   if (req) {
			   req.onreadystatechange = function() {ahahDone(target,pagina);};
			   req.open("GET", url, true);
			   req.send();
		   }
	   }
	}else{
		document.getElementById(target).innerHTML = 'Cargando, por favor espere...';
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			req.onreadystatechange = function() {ahahDone(target,pagina);};
			req.open("POST", url, true);
			req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
			req.send(str);
	   
		//IE/Windows ActiveX version
		}else if(window.ActiveXObject){
			req = new ActiveXObject("Microsoft.XMLHTTP");
		   	if (req) {
				req.onreadystatechange = function() {ahahDone(target,pagina);};
				req.open("POST",url,true);
				req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
				req.send(str);
			}
		}
	}
}

function ahahDone(target,pagina) {
		//alert("si");
   // only if req is "loaded"
   if (req.readyState == 4) {
	   
		//alert("si");
		// only if "OK"   
	   if (req.status == 200 || req.status == 304) {
			//alert("si");
		  // alert("El texto es: "+req.responseText)
		  results = req.responseText;
		//  document.getElementById(target).innerHTML = results;
		//OJO OJO OJO OJO OJO OJO
		
			execJS(results,target,pagina)
	   } else {
		   document.getElementById(target).innerHTML="Oficina Virtual (ERROR): " +req.statusText;
	  }
   }
}
	
/***************************************************************************************************/
/***************************************FUNCIONES DE EMAIL******************************************/
/***************************************************************************************************/

function checkForm(nameForm) {
	//Se decidio no hacer nada con el nameForm que se esta recibiendo en la funcion.
	checkResult = true;
  	if ((document.lgform.Username.value.length==0) || (document.lgform.Password.value.length==0)) {
    	alert('Todos los campos deben contener algun valor. Por favor complete los datos.');
		return false;
 	}		
	window.document.lgform.action = "http://correo.cantv.net/FUNC_verifyPwd.asp"
	window.document.lgform.submit();
	document.lgform.Username.value="";
	document.lgform.Password.value="";
	return false;
}
	
/***************************************************************************************************/
/**********************************FUNCIONES DE OFICINA VIRTUAL CANTV NET***************************/
/***************************************************************************************************/

function checkFormulario() {
	//Se decidio no hacer nada con el nameForm que se esta recibiendo en la funcion.
	if ((document.frmOficVirtCantvNet.Login.value.length==0) || (document.frmOficVirtCantvNet.Password.value.length==0)) {
    	alert('Todos los campos deben contener algun valor. Por favor complete los datos.');
		return false;
 	}
	window.document.frmOficVirtCantvNet.action = "http://oficina.cantv.net/oficina/outaccess/gatewaypage.asp";
	window.document.frmOficVirtCantvNet.submit();
	document.frmOficVirtCantvNet.Login.value="";
	document.frmOficVirtCantvNet.Password.value="";
	return false;
}


function checkFormulario2() {
	//Se decidio no hacer nada con el nameForm que se esta recibiendo en la funcion.
	if ((document.prepago.login.value.length==0) || (document.prepago.user_password.value.length==0)) {
    	alert('Todos los campos deben contener algun valor. Por favor complete los datos.');
		return false;
 	}
	window.document.prepago.action = "";
	window.document.prepago.submit();
	document.prepago.Login.value="";
	document.prepago.user_password.value="";
	return false;
}



function checkFormulario3() {
	//Se decidio no hacer nada con el nameForm que se esta recibiendo en la funcion.
	if ((document.consulta_saldo.login.value.length==0) || (document.consulta_saldo.user_password.value.length==0)) {
    	alert('Todos los campos deben contener algun valor. Por favor complete los datos.');
		return false;
 	}
	window.document.consulta_saldo.action = "http://oficina.cantv.net/oficina/prepagoext/2_acceso_pers_prepago_cool_saldo.asp";
	window.document.consulta_saldo.submit();
	document.consulta_saldo.login.value="";
	document.consulta_saldo.user_password.value="";
	return false;
}





/***************************************************************************************************/
/********************************FUNCIONES DE CONSULTA TU SALDO*************************************/
/***************************************************************************************************/
function validarformbasico1(){
	if (document.form2.sarea.value == "") {
		document.form2.sarea.select();
		document.form2.sarea.focus();
		alert("Debe indicar su Código");
		return false;
	} else if (document.form2.stelefono.value == "") {
		document.form2.stelefono.select();
		document.form2.stelefono.focus();
		alert("Debe indicar su No. Telefónico");
		return false;
	}else if(document.form2.sarea.value != "" && document.form2.stelefono.value != ""){	
		return true;
		//document.form2.submit();
		
		/**************IMPLEMENTACION HECHA POR ANTONIO FIGUEROA***************************/
		//*************MODIFICACION PARA NO MOSTRAR LA RESPUESTA EN LA OFICINA VIRTUAL*****/
		/**************FECHA: 03-04-07*****************************************************/
		
		/*//En esta sección se apaga el formulario correspondiente a consulta de saldo para que es id del formulario no pierda la información
		//Se encienden y apagan los id correspondientes para el muestreo de la información debida
		document.getElementById('form_sald_enlinea').style.display= "none";
		document.getElementById('resultado_saldo_enlinea').style.display= "block";
		
		cod_area = document.form2.sarea.value;
		num_tlf = document.form2.stelefono.value;
		
		document.form2.sarea.value = "";
		document.form2.stelefono.value = "";
		
		var url="http://www.cantv.com.ve/OtraApp/consulta_saldo/saldo_cics_prueba.asp?sarea="+cod_area+"&stelefono="+num_tlf;	
		ahah('GET',url,'resultado_saldo_enlinea');*/
		
		/**********************************************************************************/
		//*****************************FIN DE IMPLEMENTACION*******************************/
		/**********************************************************************************/	
	}
}
/***************************************************************************************************/
/***************************************FUNCIONES DE SMS********************************************/
/***************************************************************************************************/

function fborrar(){
	document.sms.selectCodigo.value = "";
	document.sms.txtNumero.value = "";
	document.sms.txtMensaje.value = "";
	document.sms.txtCaract.value = 120;
}
function fenvia(){
	if (document.sms.selectCodigo.value == ""){
		alert("Debe seleccionar el código del número");
		return 0;
	}	
	if (document.sms.txtNumero.value == ""){
		alert("Disculpe el número es incorrecto");
		return 0;
	}
	var numero = document.sms.txtNumero.value;
	//alert(numero.length)
	if (numero.length < 7){
		alert("Disculpe el número es incorrecto");
		return 0;	
	}
	//alert(numero.substr(0,1))
	if (numero.substr(0,1) == '0'){
		alert("Disculpe el número es incorrecto");
		return 0;	
	}
	if (document.sms.txtMensaje.value == ""){
		alert("Debe escribir un mensaje");
		return 0;
	}
	ahah('GET','http://www.cantv.com.ve/otraapp/sms_fijos/enviar_smsAjax.asp?selectCodigo='+document.sms.selectCodigo.value+'&txtNumero='+document.sms.txtNumero.value+'&txtMensaje='+document.sms.txtMensaje.value,'form_sms','SMS');
}

function NumPress() {

	// Valida que solo tipee números
	var intI;
	var strC = new String('');
	var strT = '';
	var strChequear = new String('1234567890');

	if (window.event){
		for(intI=0; intI < strChequear.length; intI++){
			strC = strChequear.substr(intI,1);          
			if(strC.charCodeAt(0)==window.event.keyCode){
				break;
			}
		}
		if((intI<strChequear.length)||(window.event.keyCode == 13)) {
			window.event.returnValue = true;
		}
		else {
			window.event.returnValue = false;
		}
	}
}

function chrRest(totalChr){
	var sms = document.sms.txtMensaje.value
	
	document.sms.txtCaract.value = totalChr - sms.length;
	
}

function TextoPress() {
	// Valida que solo tipee un conjunto de caracteres
	var intI;
	var strC = new String('');
	var strT = '';
	var strChequear = new String(' abcdefghijklmnñopqrstuvwxyz@_ÁÉÍÓÚáéíóúABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890.,?!#$%&*-+/\¿=¡:;()"');
	if (window.event){
		for(intI=0; intI < strChequear.length; intI++){
			strC = strChequear.substr(intI,1); 
			if(strC.charCodeAt(0)==window.event.keyCode || window.event.keyCode == 33){
				break;
			}
		}
		var smsCHRS = document.sms.txtMensaje.value;
		if(((intI<strChequear.length)||(window.event.keyCode == 13))&&(smsCHRS.length < 120)) {
			window.event.returnValue = true;
		}
		else {
		
			window.event.returnValue = false;
		}
	}
}

function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function abrirVentana(url,name,valor){
	if(valor=="Si"){
		var parametros = "?codigo=" + document.sms.codigo.value + "&numero="  + document.sms.numero.value + "&mensaje=" + document.sms.mensaje.value + "&servicio=" + document.sms.servicio.value; 		
		window.open(url + parametros, name,'toolbar=0,location=0,directories=0,status=0,menubar=0, scrollbars=0,resizable=0,width=250,height=210,left=100,top=100');
    return false;
	}	
}

function alertaUsuario(mensaje,valor){
	if(valor=="no"){
		alert(mensaje);
	}
}

/***************************************************************************************************/
/************************************FUNCIONES PAGINAS AMARILLAS************************************/
/***************************************************************************************************/

function Trim(TRIM_VALUE)
  {if(TRIM_VALUE.length < 1)
     {return"";}
   var VALOR =  TRIM_VALUE; 
   VALOR = RTrim(TRIM_VALUE);
   VALOR = LTrim(VALOR);
   if(VALOR=="")
     {return "";}
   else
   	 {return VALOR;}
  }

function RTrim(VALUE)
  {var w_space = " ";
   var v_length = VALUE.length;
   var strTemp = "";
   if(v_length < 0)
     {return"";}
   var iTemp = v_length -1;
   while(iTemp > -1)
     {if(VALUE.charAt(iTemp) == w_space)
        {}
      else
      	{strTemp = VALUE.substring(0,iTemp +1);
         break;
        }
      iTemp = iTemp-1;
     } //End While
   return strTemp;
  }

function LTrim(VALUE)
  {var w_space = " ";
   var v_length = VALUE.length;
   if(v_length < 1)
     {return"";}
   var v_length = VALUE.length;
   var strTemp = "";
   var iTemp = 0;
   while(iTemp < v_length)
     {if(VALUE.charAt(iTemp) == w_space)
        {}
      else
      	{strTemp = VALUE.substring(iTemp,v_length);
         break;
        }
      iTemp = iTemp + 1;
     } //End While
   return strTemp;
  }
     
function EsNulo(Texto)
  {
   var reBlank = /^[ 	]+$/
   if(Texto.value.length==0) 	 
     {return true;}
   else if(Texto.value=="")  
     {return true;}
   else if(reBlank.test(Texto.value))  
     {return true;}
   else
     {return false;}
  }
    	function ValCampos()
    	  {if(EsNulo(document.getElementById("RazonName")))
           {alert("Para realizar esta operación es necesario que indique las palabras claves o nombre de la empresa, luego haga click en el botón buscar");
       	    document.getElementById("RazonName").focus();
            return false;
    	  	 }
    	   else
    	   	 {
            if(!EsNulo(document.getElementById("RazonName")))
    	   	 	  {var strName = Trim(document.getElementById("RazonName").value);
    	   	 	   var splName = strName.split("\%");  
    	   	 	   var intI    = 0;
    	   	 	   var intL    = 0;
    	   	 	   for(intI=0; intI<splName.length; intI++)
    	   	 	      {strName = splName[intI];
    	   	 	       intL += strName.length;
    	   	 	      }
    	   	 	   if(intL<3)
    	   	 	     {alert("El nombre de empresa debe contener mínimo 3 caracteres");
                  document.getElementById("RazonName").value = ""
       	          document.getElementById("RazonName").focus();
                  return false;
    	   	 	     }
    	   	 	  }
    	   	 	  if(document.getElementById("selcity").selectedIndex >= 1)
    	   	 	     {var strVAL = document.getElementById("selcity").item(document.getElementById("selcity").selectedIndex).value;
	                var splVAL = strVAL.split("@");  
    	   	 	     	document.getElementById("Ciudad_ID").value    = splVAL[1];
	                document.getElementById("Estado_ID").value    = splVAL[0];
    	   	 	     }
              else
                 {document.getElementById("Ciudad_ID").value    = "";
	                document.getElementById("Estado_ID").value    = "";
                 }
    	   	 	  return true;       	   	 	   
    	   	 } 	 
    	   return false;
    	  }
      function ValEmpresa()
       {var blnOK = ValCampos();
        if(blnOK)
          {frmBuscar.submit()}
        return false;
       } 
      function CambioRazon()
        {if(document.getElementById("RazonName").value == "Escriba aquí la palabra clave o el nombre de la empresa a consultar")
           {document.getElementById("RazonName").value="";}
        }
		  
/***************************************************************************************************/
/************************************FUNCIONES DIRECTORIO TELEFÓNICO********************************/
/***************************************************************************************************/

	function busca_nombestado(codigo){
		i = codigo.indexOf(",");
		return  (codigo.substr(i+1))
	}
	function Validar(){
		sin_valor = false
		if((document.forms["Forma"].elements["cliente"].value.length > 0)){
			if (Validacion(document.forms["Forma"].elements["cliente"].value)){
				Forma.cliente.focus
				return false
			}
			sin_valor = true;
		}else{
			alert("Por Favor Indique el Criterio de Búsqueda (Cliente)")
		}
		
		
		if(eval("Forma.tipo_cliente.options[Forma.tipo_cliente.selectedIndex].value") == "X") {
			alert("Por Favor Seleccione el Tipo de Cliente")
			return false
		}
		if(eval("Forma.estado.options[Forma.estado.selectedIndex].value") == "X") {
			alert("Por Favor Seleccione el Estado")
			return false
		}
		
		if(sin_valor){
			document.Forma.ind_oper.value = "buscar"			
			document.Forma.ind_estado.value = document.Forma.estado.selectedIndex			
			document.Forma.txt_estado.value = busca_nombestado(document.Forma.estado.options[document.Forma.estado.selectedIndex].value)			
			document.Forma.ind_localidad.value = document.Forma.localidad.selectedIndex			
			document.Forma.txt_localidad.value = "desc_localidad = '"+ document.Forma.localidad.options[document.Forma.localidad.selectedIndex].text + "'"
			if (document.Forma.ind_localidad.value == "") {
				document.Forma.ind_localidad.value = "0"
				document.Forma.txt_localidad.value = ""
			}
			document.Forma.txt_cliente.value = ""
			if (eval("document.Forma.tipo_cliente.options[document.Forma.tipo_cliente.selectedIndex].value") != "X"){
				for (i = 0;i < 3;i++){
					document.Forma.ind_cliente.value = document.Forma.tipo_cliente.selectedIndex
					document.Forma.ind_tipo_cliente.value = i			
				} 
			}
			document.Forma.txt_cliente.value = "sta_res = '"+ document.Forma.ind_cliente.value + "'"
			if (eval("document.Forma.tipo_cliente.options[document.Forma.tipo_cliente.selectedIndex].value") == "3"){
				document.Forma.txt_cliente.value = document.Forma.txt_cliente.value + " AND substring(ind_Gobierno,1,3) = '3XX'"
			}else{
				document.Forma.ind_cliente.value = "0"
				document.Forma.ind_tipo_cliente.value = 3
			}
		}	
		
		/*str = "&tipo_cliente='"+document.Forma.tipo_cliente.value+"'";
		str = str +"&estado='"+document.Forma.estado.value+"'";
		str = str +"&localidad='"+document.Forma.localidad.value+"'";
		str = str +"&cliente='"+document.Forma.cliente.value+"'";
		
		str = str +"&txtoperacion='"+document.Forma.txtoperacion.value+"'";
		str = str +"&ind_oper='"+document.Forma.ind_oper.value+"'";
		str = str +"&ind_estado='"+document.Forma.ind_estado.value+"'";
		str = str +"&txt_estado='"+document.Forma.txt_estado.value+"'";
		str = str +"&ind_localidad='"+document.Forma.ind_localidad.value+"'";
		str = str +"&txt_localidad='"+document.Forma.txt_localidad.value+"'";
		str = str +"&ind_cliente='"+document.Forma.ind_cliente.value+"'";
		str = str +"&txt_cliente='"+document.Forma.txt_cliente.value+"'";
		str = str +"&ind_tipo_cliente='"+document.Forma.ind_tipo_cliente.value+"'";
		*/
		/*
			http://www.cantv.com.ve/seccion.asp?
			pid=1&amp;sid=467?tipo_cliente='1'&
			
			estado='7,DttoFederal'&									NO
			
			localidad='CARACAS'&
			cliente='mendez'&
			txtoperacion=''&
			ind_oper='buscar'&
			ind_estado='7'&
			txt_estado='DttoFederal'&
			ind_localidad='7'&
			
			
			txt_localidad='desc_localidad%20=%20'CARACAS''&
			
			
			ind_cliente='0'&
			
			
			txt_cliente='sta_res%20=%20'1''&
				
			ind_tipo_cliente='3'
		*/
		
		/*req = new ActiveXObject("Microsoft.XMLHTTP");
		req.open("POST","http://www.cantv.com.ve/seccion.asp?pid=1&amp;sid=467",true);
		req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		req.send(str);*/
				
		document.Forma.action="http://www.cantv.com.ve/seccion.asp?pid=1&amp;sid=467";
		document.Forma.submit();
		//window.location = "http://www.cantv.com.ve/seccion.asp?pid=1&amp;sid=467";
		
		return sin_valor;
	}	
	function Validacion(theForm){
		var checkOK = ' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.,()"';
    	checkStr = theForm;
  		var allValid = true;
		for(i = 0;i < checkStr.length;i++){
			ch = checkStr.charAt(i);
		for(j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
			break;
			if (j == checkOK.length){
				allValid = false;
				break;
			}
		}
		if(!allValid){
			alert("Este valor ("+ch+") no es valido ");
			return (true);
		}
		return (false)
	}
	function hacer_submit(){
		str='tipo_cliente='+document.Forma.tipo_cliente.value
		str = str +'&estado='+document.Forma.estado.value
		str = str +'&localidad='+document.Forma.localidad.value;
		str = str +'&cliente='+document.Forma.cliente.value;
		ahah('POST','http://www.cantv.com.ve/OtraApp/113digital/BusquedaDTOficVirtAjax.asp','form_dirtele','',str);
	}
	
/***************************************************************************************************/
/********************************FUNCIONES DE FACTURA EN LINEA**************************************/
/***************************************************************************************************/


function validarformbasico() {
	if (document.form_fact_enlinea.ID.value == "") {
		document.form_fact_enlinea.ID.select();
		document.form_fact_enlinea.ID.focus();
		alert("Debe indicar su Identificación");
		return false;
	} else if (form_fact_enlinea.CLAVE.value == "") {
		document.form_fact_enlinea.CLAVE.select();
		document.form_fact_enlinea.CLAVE.focus();  
		alert("Debe indicar su Clave");
		return false;
	}else if(document.form_fact_enlinea.ID.value != "" && form_fact_enlinea.CLAVE.value != ""){
		return true;	
	}
	
	
	/**************IMPLEMENTACION HECHA POR ANTONIO FIGUEROA***************************/
	//*************MODIFICACION PARA NO MOSTRAR LA RESPUESTA EN LA OFICINA VIRTUAL*****/
	/**************FECHA: 03-04-07*****************************************************/
	
	/*str='ID='+document.form_fact_enlinea.ID.value+'&CLAVE='+document.form_fact_enlinea.CLAVE.value;
	
	//Borrar los campos
	document.form_fact_enlinea.ID.value="";
	document.form_fact_enlinea.CLAVE.value="";
	
	ahah('POST','http://www.cantv.com.ve/OtraApp/FacturaL/Default_prueba.asp','form_fact_enlinea','',str);*/
	
	/**********************************************************************************/
	//*****************************FIN DE IMPLEMENTACION*******************************/
	/**********************************************************************************/
}						

function abrirMLinea() {
self.open('https://www.movilnet.com.ve/movilnetenlinea/','vmlinea','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0,status=0,left=0,top=0,width=480,height=250',true); 
}  

function DemoFacLinea(){
	window.open('http://www.cantv.com.ve/OtraApp/Factural/Demo_digital_cantv/inicio.htm','vmlinea','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0,status=0,left=0,top=0,width=800,height=600',true); 

}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=600');");
}

