// jip.js: les diverses fonctions d'ouverture de fentres annexes
//------------------------------------

//------------------------------------
// ouverture de la page Photos
function OpenPhotos(theURL,id,lang)
{
    sendTag(lang,"IGTU",id);
    w=window.open(theURL,"Photos","toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=462,height=462");
    MSIE=(navigator.appVersion.indexOf("MSIE")!=-1);
    VERS=parseInt(navigator.appVersion);
    if ((!MSIE) || (VERS >=5)) w.focus();
}
//------------------------------------
// ouverture de la page Info Consommateur
function OpenInfoconso(theURL)
{
    w=window.open(theURL,"Photos","toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=320,height=250");
    MSIE=(navigator.appVersion.indexOf("MSIE")!=-1);
    VERS=parseInt(navigator.appVersion);
    if ((!MSIE) || (VERS >=5)) w.focus();
}
//------------------------------------
// ouverture de la page envoyer mail
function OpenEnvoyerAmi() 
{
    MM_validateForm('correo','','RisEmail','email','','RisEmail');
}
//------------------------------------
// envoi du mail
function sendMail() 
{
    top.document.location="javascript:doSubmit();";
}
//------------------------------------
// fermeture de la page Photos
function MM_callJS(jsStr) //v2.0
{
    return eval(jsStr);
}
//------------------------------------
// Imprimer
function printWindow()
{
    bV = parseInt(navigator.appVersion)
    if (bV >= 4) top.focus();
}
//------------------------------------
// Itineraire
function pj_switch_menu (le_titre1, le_titre2) {
    document.getElementById(le_titre1);
    document.getElementById(le_titre2);
    var le_form1= document.getElementById("form_"+le_titre1);
    var le_form2= document.getElementById("form_"+le_titre2);
    le_form1.style.display='block';
    le_form2.style.display='none';
}
//------------------------------------
// Recherche d'un objet HTML
function MM_findObj(n, d) //v4.0
{
    var p,i,x;  

    if(!d) d=document;
    if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document;
        n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all) x=d.all[n];
    for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && document.getElementById) x=document.getElementById(n); 

    return x;
}
function sendTag2(lang, t, id, enlace){ 
	$.get('/mig/scripts/set_stadistics.php?d='+(Math.random()*100000)+'&lang=' + lang + '&p=Q&tipo=' + t + '&referencia=' + id);
    if (enlace !='' && enlace != undefined) {
    	// Dejo un tiempo para que cargue la página, porque sino no funciona
    	setTimeout("cargarEnlace('"+enlace+"');",500);
    }
}
function cargarEnlace(enlace) {
	document.location.href = enlace;
}
//------------------------------------
// Envoi un nouvelle tag sur le log
function sendTag(lang, t, id){ 
    if (t != null && t.length > 0) {
      peticion_http = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         peticion_http = new XMLHttpRequest();
         if (peticion_http.overrideMimeType) {
            peticion_http.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            peticion_http = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               peticion_http = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }

      if (!peticion_http) {
         //alert('Cannot create XMLHTTP instance');
         alert ("Se ha producido un error al mostrar la pagina, seleccionela de nuevo");
      }

        // Preparar la funcion de respuesta
        //peticion_http.onreadystatechange = muestraContenido();        
        // Realizar peticion HTTP
	    var url = window.location.href;
	    var car = url.indexOf("/",8);
	    var urlfinal=url.substring(0,car+1); 

		urlfinal = urlfinal + '/mig/scripts/set_stadistics.php?d='+(Math.random()*100000)+'&lang=' + lang + '&p=Q&tipo=' + t + '&referencia=' + id;
        peticion_http.open('GET', urlfinal , true);        
        peticion_http.send(null);
        function muestraContenido() {
            if(peticion_http.readyState == 4) {
                if(peticion_http.status == 200) {
                }
            }
        }
    }
}

function pim_click()
{
    var pim = document.getElementById('ag_pim_type').value;
    var url = ag_server + '/inserter/xagent_insert.jsp?' + ag_button_params + '&pim=' + pim;
    if (navigator.appName.indexOf('Internet') == -1)
        url = ag_server + '/inserter/cards/insert_card.jsp?' + ag_button_params;
    window.open(url, "pim", "toolbar=no,location=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=400,height=400");	
    return false;
}

function replaceAll( text, str1, str2 )
{
    var command = "text.replace(/"+str1+"/g,\""+str2+"\")";
    return eval(command);
}

function jlimpacampominus(strin) 
{
    var str1conv='ÁÀÃÂÄáàãâäÉÈÊËéèêëÌÍÎÏìíîïÒÓÔÕÖòóôõöÙÚÜÛÇÑùúüûçñ;:.\\"[](){}<>!&^%$#`\'?/-';
    var str2conv='AAAAAaaaaaEEEEeeeeIIIIiiiiOOOOOoooooUUUUCNuuuucn                          ';
    var strout='';
    

    for     (i=0; i < strin.length; i++) 
    {
        j=str1conv.indexOf(strin.charAt(i));
        if (j==-1) 
            strout=strout+strin.charAt(i);
        else 
            strout=strout+str2conv.charAt(j);
    }
    var tmp =strout.substring(0,1);
    strout = strout.toLowerCase();
    tmp = tmp.toUpperCase();
    tmp = tmp + strout.substring(1,strout.length);
    return (tmp);
}

function ConstruirRuta(cliente, idioma, pagina,type,ref)
{
  if ((document.domain.indexOf("infoplusec.qdq.com") != -1)||(document.domain.indexOf("infoplus.qdq.com") != -1) || (document.domain.indexOf("infoqdq") != -1) ||
  (document.domain.indexOf("qdqinfo") != -1) || (document.domain.indexOf("qdqplus") != -1)|| (document.domain.indexOf("desinfo") != -1))
  {
    if (idioma=='es')
    { if (pagina=='inicio')
        document.location.href= '/' + cliente;
      else
        document.location.href= '/' + cliente + '/' + idioma + '/' + pagina + "/" ;
    }
    else
      document.location.href= '/' + cliente + '/' + idioma + '/' + pagina + "/" ;
  }
  else
  {
    if (idioma=='es')
    {
      if (pagina=='inicio'){
        document.location.href= "http://" + document.domain;
      }else
        document.location.href= "http://" + document.domain + '/' + idioma + '/' + pagina + "/";
    }
    else
      document.location.href= "http://" + document.domain + '/' +  idioma + '/' +  pagina + '/';
  }

  jLogNav(type,ref);

}
function jcallgIP(idioma,t) {
	if (t.length>0) {
		if (t.substring(0,1)=='+')
			t=t.substring(1,t.length - 1);
		if ( (t.substring(0,2)!='34') && (t.substring(0,2)!='33') && (t.substring(0,3)!='351') )
			t='34'+t;
		var tag = new Image();
		tag.src='/mig/scripts/set_stadistics.php?d='+(Math.random()*100000)+'&lang=' + idioma + '&p=Q&tipo=LG&referencia=' + t;
		ref='TL'+t; 
		if (idioma.length<1) { idioma = 'es';	}
		if (idioma == 'vl') { idioma = 'ct';	}
		Janela_Centro_NR('http://o1.agendize.com/w1/inserter/box?lang='+idioma+'&virtual=true&type=xml&mapping=clicktocall&author=qdq&id='+ref+'&btype=contact&medias=call','click2call','500','500','no'); 
	}
}
function Janela_Centro_NR(pagina,nome,w,h,scroll) {
	if (screen.width > w)
		{var winl = (screen.width - w) / 2;}
	else
		{var winl = 0;}
	if (screen.height > h)
		{var wint = (screen.height - h) / 2;}
	else
		{var wint = 0;}
	wint-=20;
	if (wint<0) wint=0;
		winprops = 'toolbar=no,menubar=no,location=no,'+'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',noresizable'
	try
	{
		win = this.open(pagina, nome, winprops);
	}
	catch(e){}
	try
	{
		if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	}
	catch(e){}
}
$(function(){
	$.ajaxSetup({
		cache: false
	});
	$("a[data-stats]").click(function(event) {
		var stats = $(this).data('stats').split(';');
		$.ajax({
			url: "/mig/scripts/set_stadistics.php",
			data: { lang: stats[0], p: 'Q', tipo: stats[1], referencia: stats[2] },
			async: false
		});
		return true;
	});
});
