


// JavaScript Document

/*  Prototype JavaScript framework, version 1.5.0_rc1
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *  For details, see the Prototype web site: http://prototype.conio.net/
 *
*/

/*FUNCIONES COBERTURA*/
function sendForm(){
 $('c_number').value='';
 $('c_number').onclick='function(){ return checkNumber();}';
}

function checkNumber(){
	var error=false;
	if(!$('c_number').value.match(/^[9,8]{1}\d{8}$/) || $('c_number').value.match(/^9{1}[0]{1}\d{7}$/)) {
		$('c_number').value="número de tlf erróneo."
		Field.select($('c_number'));
		return false;
	}else{
		lanzarLayer('layer-55');
		//$('img_captcha').src="/cobertura/captcha/captcha.php?" + new Date().getTime();
		//cargar un iframe oculto para contar las visitas al layer
		$('ioculto').src="/html/contador_cobertura.html";
	}
}


function doRequest() {

if(!$('captcha').value.match(/^([0-9]|[a-zA-Z]){4}$/)) {
	$('errorcaptcha').innerHTML="Código incorrecto. Los caracteres introducidos no corresponden con la imagen.<br>Por favor vuelva a introducirlos"
	return false;
}else{
	$('errorcaptcha').innerHTML=""
}

	Element.hide($('comprobar_cobertura'));
	
	
	var sParams = "c_number="+$('c_number').value+"&c_captcha="+$('captcha').value+"&pregunta1="+$('pregunta1').value+"&pregunta2="+$('pregunta2').value;
 	
     if($('c_referer')) sParams += "&c_referer="+ $('c_referer').value;
   
 	$('captcha').value=" escribe el código";
                               
 new Ajax.Request("/cobertura/coberturac.php", {
 	method    : 'post', 
 	parameters : sParams,
 	onFailure : function (){location.href="http://internet.orange.es/contratacion_rapida/pagina_de_error/";},
 	onSuccess: function(transport) {
 			var msg=transport.responseText

			if(msg=='ko1'){
				if($('comprobar_cobertura')) Element.show($('comprobar_cobertura'));
				if($('msg_o')) Element.show($('msg_o'));
				if($('carg2')) Element.hide($('carg2'));	
				if($('esperauser')) Element.hide($('esperauser'));	
				new Insertion.Top('errorcaptcha', "Código incorrecto. Los caracteres introducidos no corresponden con la imagen.<br>Por favor vuelva a introducirlos");
				Field.select($('captcha'));
		   	$('img_captcha').src="/cobertura/captcha/captcha.php?" + new Date().getTime();
			}else{
				
				if(msg.indexOf("internet.orange.es")!=-1){
						location.href=msg;
					}else{
						location.href="http://internet.orange.es/contratacion_rapida/pagina_de_error/";
					}
			}

 		}
 	});                              
       if($('carg2')) Element.show($('carg2'));     
	   if($('esperauser')) Element.show($('esperauser'));
	   if($('msg_o')) Element.hide($('msg_o'));                        
}

//Fin peticion ajax a cobertura

/*FIN FUNCIONES COBERTURA*/
var lnkCounter = 0;

function lanzarLayer (id_layer){	
	
	if (lnkCounter == 0) // Sustituye enlaces con # para evitar desplazamiento página
		{
//		var tb = $("menu").getElementsByTagName('a');
		var tb = document.getElementsByTagName('a');
		for(var i = 0; i < tb.length; i++){
			if( tb[i].href.indexOf('#') != -1 )	{ tb[i].href = 'javascript:;'; lnkCounter ++; }
			}			
		}

	//$$('select').invoke('hide');
	startLoading(id_layer,layerAbierto);
	
}
 
function cerrarLayer (id_layer)
{
  //$$('select').invoke('show')
  if (existe(id_layer)== 1)//si existe el layer
  {
	   activeLayers--;
	   Element.hide("" + id_layer);
	   if (activeLayers < 1) { Element.hide("popup") } 
	   if( $(id_layer + "section_0") != null ) abrirLayer((id_layer + "section_0"),6,id_layer);
  }else
  {
	   return;
  }
 }
 
 
function abrirLayer (id_layer, maxi, id) {
   var aux = id_layer.split("_");
   Element.show(id_layer);
   var cnt='';
   if(aux[0].indexOf("sec") > -1) cnt = "sec";
   if(aux[0].indexOf("linkse") > -1) cnt = "lin";
   if(aux[0].indexOf("la") > -1) cnt = "linla";
   for(var i = 0; i < maxi; i++)
   {
     var id_aux = id+cnt+"_"+i;
     var id_aux2 = id+cnt+"2_"+i;	
     if ($(id_aux)!= null ||  $(id_aux2)!= null )
	 {
	    if(i != aux[1])
	   {
	    if(i == 0 && aux[0].indexOf("sec") > -1)  $(id_aux).className ="lnkcnt_left";	
	    else $(id_aux).className ="lnkcnt"; 
	    $(id_aux2).className ="lnk";
	    $(aux[0]+"_"+i).style.display = "none";
       }
	   else
	   {
		if(i == maxi-1 && aux[0].indexOf("sec") > -1) $(id_aux).className ="lnkcnt_on_right";
	    else $(id_aux).className ="lnkcnt_on";
		$(id_aux2).className ="lnk_on";
	   }

	}// if
  }// for 
}


/*-------------------------------------------------------------
FUNCIONES DE POSICIONAMIENTO DEL LAYER
---------------------------------------------------------------*/

function getPageSize()
{
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

function getPageScroll()
{
    var yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {
        yScroll = document.body.scrollTop;
    }
    arrayPageScroll = new Array("", yScroll);
    return arrayPageScroll;
}

function startLoading(idCapa)
{ 
	if((idCapa != layerAbierto)&&(layerAbierto != "inicio")){cerrarLayer(layerAbierto);}
	layerAbierto = idCapa;

	var pageSize = this.getPageSize();
	var layerPos = (pageSize[0]-620)/2;
	var pageScroll = this.getPageScroll()[1];
	var altoPag = pageSize[1];
	
	Element.setStyle(String(idCapa),{top: pageScroll + 20 + "px", left: layerPos + "px", width: "620" });  
	Element.show("" + idCapa);	
	var altoCapa = pageScroll + parseInt($("" + idCapa).offsetHeight) + 20;	
	if (altoCapa > altoPag) altoPag = altoCapa;
	Element.setStyle("popup",{height: altoPag + "px", width: "100%", display: "block" });
	activeLayers ++;
}

function change_captcha()
{
 var ran = Math.random()+"";
 var ran_m = ran * 10000000000000;
 if($('img_captcha')) $('img_captcha').src='http://internet.orange.es/cobertura/captcha/captcha.php?'+ran_m;
}

var activeLayers = 0;
document.write('<div id="popup" style="position:absolute;display:none; z-index:8;top:0px;left:0px;" class="transp"></div>');

/*-------------------------------------------------------------
FUNCIONES PARA VALIDAR LA ENCUESTA
---------------------------------------------------------------*/


/*ENCUESTA*/
function is_client(){
var f= document.getElementById('f_encuesta');
if(f && f.es_cliente.options[f.es_cliente.selectedIndex].value == 'si')
{
document.getElementById('clasi').style.display= "inline";
document.getElementById('motivoc').style.display= "inline";
document.getElementById('motivonc').style.display= "none";
}else{
document.getElementById('clasi').style.display= "none";
document.getElementById('motivoc').style.display= "none";
document.getElementById('motivonc').style.display= "inline";
}
}


function is_mejora(){
var f= document.getElementById('f_encuesta');
if(f && f.mejorar.options[f.mejorar.selectedIndex].value == 'otro')
{
document.getElementById('mejorastxa').style.display= "inline";
}else{
document.getElementById('mejorastxa').style.display= "none";
}
}

function cerrar_encuesta(div){
cerrarLayer(div);
if($('f_encuesta')) Form.reset('f_encuesta');
if($('motivonc')) $('motivonc').style.display="none";
if(!c_ck_get("mr_encuesta") || c_ck_get("mr_encuesta") != 'yes'){
var futdate = new Date() //Get the current time and date
var expdate = futdate.getTime() //Get the milliseconds since Jan 1, 1970
expdate += 30*24*60*60*1000; //expires in 1 month(milliseconds)
futdate.setTime(expdate);
c_ck_set("mr_encuesta",'yes',futdate,"/",".orange.es");
}
}

function addElement (id){
var aux = document.createElement('span'); 
aux.id="ad_"+id; 
aux.className = "motivo";
aux.innerHTML= ' '+$(id).title; 
return aux;
}

function validateForm(){
var send = true;
if($('es_cliente').value == ""){
var aux = addElement ('es_cliente');
Insertion.After($('es_cliente'), aux);
send= false; }

if($('motivoc').style.display != 'none' && $('motivoc').value == ""){
var aux = addElement ('motivoc');
Insertion.After($('motivoc'), aux);
send= false; }

if($('motivonc').style.display != 'none' && $('motivonc').value == ""){
var aux = addElement ('motivonc');
Insertion.After($('motivonc'), aux);
send= false; }

if( $('buscado').value == ""){
var aux = addElement ('buscado');
Insertion.After($('buscado'), aux);
send= false; }

if($('satisfaccion').value == ""){
var aux = addElement ('satisfaccion');
Insertion.After($('satisfaccion'), aux);
send= false; }

if($('general').value == ""){
var aux = addElement ('general');
Insertion.After($('general'), aux);
send= false; }


if($('grado').value == ""){
var aux = addElement ('grado');
Insertion.After($('grado'), aux);
send= false; }


if($('mejorar').value == ""){
var aux = addElement ('mejorar');
Insertion.After($('mejorar'), aux);
send= false; }

if($('clasi').style.display != 'none' && $('en_tarifas').value == ""){
var aux = addElement ('en_tarifas');
Insertion.After($('en_tarifas'), aux);
send= false; }

if($('clasi').style.display != 'none' && $('en_sexo').value == ""){
var aux = addElement ('en_sexo');
Insertion.After($('en_sexo'), aux);
send= false; }

if($('mejoras').value != ""){
var auxi = $('mejoras').value.replace(/\n/gi,'. ');
auxi = auxi.replace(/\r/gi,'. ');
$('mejoras').value = auxi;
}

return send;
}

 function enviar_encuesta(){
 if(validateForm()){ 
  //if(!c_ck_get("mr_encuesta") || c_ck_get("mr_encuesta") != 'yes'){
  /* var futdate = new Date()		//Get the current time and date
   var expdate = futdate.getTime()  //Get the milliseconds since Jan 1, 1970
   expdate += 30*24*60*60*1000;  //expires in 1 month(milliseconds)
   futdate.setTime(expdate);
   c_ck_set("mr_encuesta",'yes',futdate,"/");*/
   
   var urlPagina = "" + document.location;
   var buscarBarra = urlPagina.split("/");
   if(buscarBarra.length < 5) var procedencia ="home";
   else var procedencia ="otros";
   
   $('f_encuesta').procedencia.value = procedencia;
   $('f_encuesta').urlenc.value = urlPagina;
   $('f_encuesta').action = "http://moviltest.orange.es/php/mandar_encuesta.php";
   $('f_encuesta').request({
     onComplete: 
	 function(){
		 document.getElementById("boton_cerrar_encuesta").href="javascript:cerrarLayer('layer-1061'),document.location.href=urlDestino;";
 		 document.getElementById("boton_cerrar_encuesta2").href="javascript:cerrarLayer('layer-1061'),document.location.href=urlDestino;";
		 $('tit_enc').innerHTML ="";
		 $('ppl_encuesta').innerHTML ="";
		 $('ppl_encuesta').innerHTML="Gracias por tu colaboración"; 
		}
   })
  }else{
     return false;
  } 
  
 }
 
 


/*ENCUESTA*/



/*BUSCADOR*/
function existe(id)
{
	var e=document.getElementById(id);
	if(!e)
	{		
			return -1;
	}else
	{
			if(e.style.display != 'none')
			{
				return 1;
			}else{
				return -1;
			}
	}
}

/*FIN BUSCADOR*/


