var vtippro = '';
var videter = '';
var vimprec = '';

var g_codtso = '';
var gp_rolcan = '';
var gp_rolcca = '';
var gp_rolscc = '';
var gp_rolusc = '';

// inicio  
	function inicio(){
		request_esp=new PeticionBD ('xweb_sesion_operacion.inicia_alta_especial.xml',['p_tippro', 'p_ideter', 'p_imprec', 'p_codprm', 'p_swiped','p_tiplin', 'p_origen','p_swipor','p_rolboc','p_rolage','p_rolsag','p_rolper','xsid'], cargaSiguiente_especial,errorBD);
		request = new PeticionBD ('xweb_sesion_operacion.inicia_alta.xml'
								,['p_tippro', 'p_ideter', 'p_imprec', 'p_codprm', 'p_swiped','p_tiplin', 'p_origen', 'p_tipsim','p_rolboc','p_rolage','p_rolsag','p_rolper', 'xsid']
								, cargaSiguiente,errorBD);
								
		
		g_codtso  = '';
		gp_rolcan = '';
		gp_rolcca = '';
		gp_rolscc = '';
		gp_rolusc = '';
		
		/*
		 
		if (document.getElementById("div_visdis")){		
			if(document.getElementById("r_genped_1").checked){
				v_pedsel = 'VIDISA';
    	}
			if(document.getElementById("r_genped_2").checked){
				v_pedsel = 'DISTRI';
			}					 
		}
		*/
		
		if (document.getElementById("div_rolboc")){		
			if(document.getElementById("r_rolboc_1").checked){
				v_rolboc = 'CAT';
    	}
			if(document.getElementById("r_rolboc_2").checked){
				v_rolboc = 'AGE';
			}					 
			//PONEMOS LA PAGINA WEB EN ESTADO INICIAL

			document.getElementById("r_rolboc_1").checked=false;	
			document.getElementById("r_rolboc_2").checked=false;	
			document.getElementById("r_genped_1").checked=false;	
			document.getElementById("r_genped_2").checked=false;		 
		}
		try{
		  iniciarBotones();
		} catch(err) {
		  null;
        }
    }
    
	/*function tiene_transporte(){
		if (v_rolboc != 'CAT'){
			return '';
		}
		if (v_pedsel == ''){
			return '';
		}
		if (v_pedsel == 'VIDISA'){
              return 'S';				    
            }
		if (v_pedsel == 'DISTRI'){
           return 'N';            				 				  
          } 
    }*/
    
	function tiene_transporte(){
		if (v_pedsel == 'VIDISA'){
              return 'S';				    
            }
		if (v_pedsel == 'DISTRI'){
           return 'N';            				 				  
          }
		if (v_rolboc == 'AGE'){
			return 'N';
		}
		if (v_rolboc == 'LCR'){
			return 'N';
		}		
		if (v_pedsel == ''){
			return 'S';
		}		   
    }     
// Petición a la Base de datos 
	function actualizaBD(tippro, ideter, imprec, tiplin,origen,codprm,tipsimms)
	{
		
	
		delCookie ('ck_promocion','/','pepephone.com');
		vtippro = tippro;
		videter = ideter;
		vimprec = imprec;
		vxsid=document.foLista.xsid.value;
		if(origen){
			vorigen=origen;
			}else{
			vorigen='PEPEPHONE';
			}
			
		if(codprm){
			vcodprm=codprm;
		}else{
			vcodprm='';
		}
		
		if(tipsimms){
			vtipsimms=tipsimms;
		}else{
			vtipsimms='';
		}				
		vcodprm = vcodprm.toUpperCase();
		// No debemos pasar ni tiplin ni origen para que asigne por defecto la tarifa básica
		if (!tiplin) {
				vtiplin = 'VOZ';
		} else{
			vtiplin = tiplin;
		}
		
		if (document.getElementById("div_visdis")){
			if (!validaciones_BOC()) return;
		} 		
		request.Iniciar([tippro, ideter, imprec, vcodprm, tiene_transporte(), vtiplin, vorigen, vtipsimms,gp_rolcan, gp_rolcca, gp_rolscc, gp_rolusc, vxsid]);
		
		}
	function actualizaBD_especial(tippro, ideter, imprec, tiplin,swipor,codprm,xsid)
	{
			
		
		
		vtippro = tippro;
		videter = ideter;
		vimprec = imprec;
		
		if(codprm){
			vcodprm=codprm;
		}else{
			vcodprm='';
		}		
		vcodprm = vcodprm.toUpperCase();
		
		vswipor=swipor;
		vxsid=document.foLista.xsid.value;
		
		//Borramos la coockie de promoción
		delCookie ('ck_promocion','/','pepephone.com');
        
		// No debemos pasar ni tiplin ni origen para que asigne por defecto la tarifa básica
		if (!tiplin) {
				vtiplin = 'VOZ';
		} else{
			vtiplin = tiplin;
		}
		
		if (document.getElementById("div_visdis")){
			if (!validaciones_BOC()) return;
		}
		
		request_esp.Iniciar([tippro, ideter, imprec, vcodprm, tiene_transporte(),vtiplin,'PEPEPHONE',vswipor,gp_rolcan,gp_rolcca,gp_rolscc,gp_rolusc,vxsid]);
	}
// Carga Siguiente 
	function cargaSiguiente(datos)
	{
 //return; //quitar----------------------------------------------------------------------------------------------------------------------------------
		// Mod Isabel Gamero(18/09/2008) 			
		if ((vtippro =='TER' && videter != '' )|| (vtiplin.substring(0,5) =='DATOS')){
		 	//borramos cualquier cookie de promo
			delCookie ('ck_promocion','/','pepephone.com');		
			//Mod Isabel Gamero(20/07/09)para redireccionar la contratación para DATOS según el tipo de pedido del canal logeado
            if(datos.ok){
                document.foLista.action = "https://www.pepephone.com/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_alta_nuevo_num.html";
            }else{
                if (datos.operacion.pedsel == 'VIDISA'){
    				document.foLista.action = "https://www.pepephone.com/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_actualiza_detalle_alta.html";
    			} else {				 
    	  			document.foLista.action = "https://www.pepephone.com/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_alta_nuevo_num.html";
    			}
            }	
		}else
		{
		//Sino hay que hacer el proceso normal
			document.foLista.action = "/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_inicia_alta.html";
		}
		document.foLista.submit();
	} 
		function cargaSiguiente_especial()
	{
 //return; //quitar----------------------------------------------------------------------------------------------------------------------------------	
	    delCookie ('ck_promocion','/','pepephone.com');
		/* Mod Isabel Gamero(18/09/2008) 			
		if ((vtippro =='TER' && videter != '' )|| (vtiplin =='DATOS')){
		 	//borramos cualquier cookie de promo
			delCookie ('ck_promocion','/','pepephone.com');		
			/* Si es solo el terminal lo que se pide o tipo de linea de DATOS para que se pase la
			tarifa como 'DATOS PLANA' tenemos que saltarnos todo lo de los numeros
			 y pasar directamente a los datos del cliente*/ /*
			if (v_codcan == 'AGE'){
				document.foLista.action = "https://www.pepephone.com/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_alta_nuevo_num.html";			
			} else {				 
	  			document.foLista.action = "https://www.pepephone.com/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_actualiza_detalle_alta.html";
			}	
		} 
		else */
		if (vswipor=='S'){
		//Sino hay que hacer el proceso normal
			document.foLista.action = "/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_alta_portabilidad.html";
		}
		else{
		    document.foLista.action = "/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_alta_nuevo_num.html";
		}
		document.foLista.submit();
	}
	function errorBD(datosError){
	   if (typeof(cargando2) != "undefined") {
	  		cargando2.display({descripcion: datosError.error.code + ' ' + datosError.error.message,
		                       boton_visible: true,
		                       gif_visible: true,
		                       img: 'error'});
	    } else {
	           alert (datosError.error.code + ' ' + datosError.error.message);
	           }
	}
	
	
	
	
	
	
	
	
	
	
	function validaciones_BOC(){
	var txterr='';
	if (gp_rolcan == 'CAT' && v_pedsel == '') {
		txterr += texto_js.tipo_ped+'<br/>';
	}		
	if (gp_rolcan == ''){
		txterr += 'Debe informar el rol<br/>';
	}
	if (gp_rolcan == 'AGE') {
		gp_rolusc = document.getElementById('numperage').value;
		
		if (gp_rolcca == ''){
			txterr += 'Debe informar el código de TSO<br/>';
		}		
	}
	
	if ((gp_rolcca == '')&&(gp_rolcan != 'AGE')) {
		txterr += 'Debe informar el canal<br/>';		
	}
	if ((gp_rolscc == '')&&(gp_rolcan != 'AGE')) {
		txterr += 'Debe informar el punto de venta<br/>';		
	}
	if ((gp_rolusc == '')&&(gp_rolcan!='LCR')) {
		txterr += 'Debe informar el Nº de personal<br/>';		
	}
	if (txterr!=''){
		cargando2.visible('on');
		cargando2.display({
			descripcion: txterr, // David (29/04/2009)
			boton_visible: true,
			gif_visible: true,
			img: 'error'
		});
		return false;
	}
	return true;
}
