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


function inicio(){
	requestNew = new PeticionBD('xweb_sesion_operacion.inicia.xml',['p_idezpt','p_swiped','p_rolboc','p_rolage','p_rolsag','p_rolper','xsid'], cargaSiguiente, errorBD);
	request_esp_3GB = new PeticionBD ('xweb_sesion_operacion.inicia_alta.xml'
								,['p_tippro', 'p_ideter', 'p_imprec', 'p_codprm', 'p_swiped','p_tiplin', 'p_origen', 'p_rolboc','p_rolage','p_rolsag','p_rolper', 'xsid']
								, cargaSiguiente_3GB,errorBD);
	request_esp_TPmicro = 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']
								, cargaSiguienteTPmicro,errorBD);
	request_esp_TPsim = 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']
								, cargaSiguienteTPsim,errorBD);
	request_esp_TPmicro25 = 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']
								, cargaSiguienteTPmicro25,errorBD);
	request_esp_TPsim25 = 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']
								, cargaSiguienteTPsim25,errorBD);
	g_codtso  = '';
//	gp_rolcan = '';
	gp_rolcca = '';
	gp_rolscc = '';
	gp_rolusc = '';
	
	if (g_accpub){
		if (g_accpub=='S'){
		    inicio_sesion();
		    g_ideses = v_xsid;
		    controlSesion();
	    }
    }	
	
	if (document.getElementById("div_rolboc")){		
		if(document.getElementById("r_rolboc_2").checked){
			chequeaRadioRol(v_rolboc);
          			
		}		 
	}
	try{
	  iniciarBotones();
	} catch(err) {
	  null;
    }
}


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';
	}		   
} 


function inicia (idezpt){	
	g_idezpt = idezpt;	
	switch(aZPT[idezpt].tiplnk){
		case "ENLACE":
			document.location.href=aZPT[g_idezpt].lnkzpt;
			break;
		case "SINLNK":
			break;
		default:
			actualizaBD(idezpt);		
	}
}
	
function inicia_confirmacion( idezpt )
{
	var text_ter = '';
	
	switch(idezpt){
		case "59":
			text_ter = 'iphone 4';
			break;
		case "27":
			text_ter = 'ipad';
			break;
		default:
			text_ter = 'iphone 4 o un ipad';		
	}	
	
	 cargando2.confirm({
         descripcion: 'Vas a contratar tu tarifa con una "SIM estándar".<br/>Esta elección es la correcta siempre, excepto si tienes un '+ text_ter +'. Si es tu caso,  pincha en VOLVER y contrata en "Otras ofertas" la misma tarifa con MICROSIM',
         func: 'inicia('+ idezpt +');'
              
	 });      
	 cargando2.visible('On');

}
	
function actualizaBD(idezpt){	
	
	if (document.getElementById("div_visdis")){
		if (!validaciones_BOC()) return;
	}	
	requestNew.Iniciar([idezpt, tiene_transporte(), gp_rolcan, gp_rolcca, gp_rolscc, gp_rolusc, v_xsid]);
}


function cargaSiguiente(datos){
	//Isabel Gamero (18/05/2010)
	if (g_accpub){
		if (g_accpub=='S'){
            activaCookieSesion({'ideses':v_xsid
							   ,'estses':'A'
							   ,'urlorigen':document.URL});
		}
	}
		
	if (aZPT[g_idezpt].idezpt != g_idezpt){
		alert('error');
		return false;
	}
	if (aZPT[g_idezpt].tiplnk == 'DATCLI' || aZPT[g_idezpt].tiplnk == 'SELPRE' || aZPT[g_idezpt].tiplnk == 'SELPOS') {
		if (aZPT[g_idezpt].tiplin.substring(0, 5) == 'DATOS') { //entramos si es datos
			if (datos.ok) { //   entra si es datos y pedido vidisa				
				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 = "https://www.pepephone.com/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_inicia_alta.html";
		}
	}else{   // si es alta especial
		if (aZPT[g_idezpt].tiplnk.indexOf('POR')!=-1){	 //si es portabilidad	
			document.foLista.action = "https://www.pepephone.com/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_alta_portabilidad.html";
		}else{
		    document.foLista.action = "https://www.pepephone.com/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;
}
function actualiza3GB(){
  if (document.getElementById("div_visdis")){
		if (!validaciones_BOC()) return;
	}	
  request_esp_3GB.Iniciar(['POS', '12', '', '', tiene_transporte(), 'DATOS', 'PEPEPHONE', gp_rolcan, gp_rolcca, gp_rolscc, gp_rolusc, v_xsid]);  
}
function cargaSiguiente_3GB(json){
	if (tiene_transporte()=='S'){
  		document.location = 'https://www.pepephone.com/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_actualiza_detalle_alta.html?xsid='+json.operacion.ideses;
  	}else{
     	document.foLista.action = "https://www.pepephone.com/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_alta_nuevo_num.html";
     	document.foLista.submit();
	}
}
function actualizaTPmicro(){
  if (document.getElementById("div_visdis")){
		if (!validaciones_BOC()) return;
	}
  request_esp_TPmicro.Iniciar(['POS', '', '', '', tiene_transporte(), 'DATOS_P_700MB_119', 'PEPEPHONE','M', gp_rolcan, gp_rolcca, gp_rolscc, gp_rolusc, v_xsid]);
}
function cargaSiguienteTPmicro(json){
  if (tiene_transporte()=='S'){
  		document.location = 'https://www.pepephone.com/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_actualiza_detalle_alta.html?xsid='+json.operacion.ideses;
  	}else{
     	document.foLista.action = "https://www.pepephone.com/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_alta_nuevo_num.html";
     	document.foLista.submit();
	}
}
function actualizaTPsim(){
  if (document.getElementById("div_visdis")){
		if (!validaciones_BOC()) return;
	}
  request_esp_TPsim.Iniciar(['POS', '', '', '', tiene_transporte(), 'DATOS_P_700MB_119', 'PEPEPHONE','S', gp_rolcan, gp_rolcca, gp_rolscc, gp_rolusc, v_xsid]);
}
function cargaSiguienteTPsim(json){
  	if (tiene_transporte()=='S'){
  		document.location = 'https://www.pepephone.com/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_actualiza_detalle_alta.html?xsid='+json.operacion.ideses;
  	}else{
     	document.foLista.action = "https://www.pepephone.com/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_alta_nuevo_num.html";
     	document.foLista.submit();
	}
}

function actualizaTPmicro25(){
  if (document.getElementById("div_visdis")){
		if (!validaciones_BOC()) return;
	}
  request_esp_TPmicro25.Iniciar(['POS', '', '', '', tiene_transporte(), 'DATOS', 'PEPEPHONE','M', gp_rolcan, gp_rolcca, gp_rolscc, gp_rolusc, v_xsid]);
}
function cargaSiguienteTPmicro25(json){
  	if (tiene_transporte()=='S'){
  		document.location = 'https://www.pepephone.com/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_actualiza_detalle_alta.html?xsid='+json.operacion.ideses;
  	}else{
     	document.foLista.action = "https://www.pepephone.com/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_alta_nuevo_num.html";
     	document.foLista.submit();
	}
}
function actualizaTPsim25(){
  if (document.getElementById("div_visdis")){
		if (!validaciones_BOC()) return;
	}
  request_esp_TPsim25.Iniciar(['POS', '', '', '', tiene_transporte(), 'DATOS', 'PEPEPHONE','S', gp_rolcan, gp_rolcca, gp_rolscc, gp_rolusc, v_xsid]);
}
function cargaSiguienteTPsim25(json){
	v_ideses = '';
	if (json.operacion) v_ideses = json.operacion.ideses;
	if (json.ok) v_ideses = json.ok.ideses;

	if (tiene_transporte()=='S'){
  		document.location = 'https://www.pepephone.com/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_actualiza_detalle_alta.html?xsid='+v_ideses;
  	}else{
     	document.foLista.action = "https://www.pepephone.com/ppm_web/ppm_web/1/alta/xweb_sesion_operacion.lista_alta_nuevo_num.html";
     	document.foLista.submit();
	}
}
