<!--DOCUMENT CONTENT_TYPE="text/javascript"  -->
/* 
  Copyright 2004 - Certifica.com 
  $Id: certifica.js,v 1.12 2004/10/27 20:12:21 leus Exp $
*/

DEFAULT_PIVOT_NAME = 'cert_Pivot';
DEFAULT_REDIRECT_TIME = 3000;
DEFAULT_PERIODIC_REDIRECT_TIME = 605000;

function cert_qVal(sValue) 
{
    var pos = String(document.location).indexOf('?');
    if (pos != -1) {
       var query = String(document.location).substring(pos+1);
       var vars = query.split("&");
       for (var i=0; i < vars.length; i++) {
          var pair = vars[i].split("=");
          if (pair[0] == sValue)
             return pair[1];
       }       
    }
    return null;  
}

function cert_getReferrer()
{
   var referrer = document.referrer;
   if (self.cert_getReferrer14)
      return cert_getReferrer14();
/*@cc_on
  @if(@_jscript_version >= 5 )
   try { 
      if ( self != top ) referrer = top.document.referrer;
   } catch(e) {};
  @end
  @*/
  return referrer;
}
 
function cert_getTagCertifica(iSiteId, sPath, sAppend) 
{
    var size, colors, referrer, url;
    size = colors = referrer = 'otro';
    var o = cert_qVal('url_origen');
    if (o != null && o != '')
       referrer = o;
    else 
       referrer = escape(cert_getReferrer());
    if ( window.screen.width ) size = window.screen.width;
    if ( window.screen.colorDepth ) colors = window.screen.colorDepth;
    else if ( window.screen.pixelDepth ) colors = window.screen.pixelDepth;
    url = 
       'http://hits.e.cl/cert/hit.dll?sitio_id=' + iSiteId + '&path=' + sPath +
       '&referer=' + referrer + '&size=' + size + '&colors=' + colors;
    url += '&java=' + navigator.javaEnabled();
    if (sAppend)
        url += sAppend;
    return url;    
}

/* Efectua un hit en certifica usando una imagen pivote. */
function cert_registerHit(iSiteId, sPath, sPivotName) 
{
   var sAppend = '&cert_cachebuster=' + (1 + Math.floor (Math.random() * 10000));
   if ( !sPivotName )
      sPivotName = DEFAULT_PIVOT_NAME;
   if ( document.images )
      if ( document.images[sPivotName] )
         document.images[sPivotName].src = cert_getTagCertifica(iSiteId, sPath, sAppend);
}

/* Efecta una redirecci n marcando la ruta de salida */
function cert_registerHitAndRedirect( sURL, iSiteId, sPath, sPivotName ) 
{
   cert_registerHit( iSiteId, sPath, sPivotName );
   setTimeout( "location.href = '" + sURL + "'", DEFAULT_REDIRECT_TIME );
}

/* Abre una nueva ventana, marcando el hit */
function cert_registerHitAndOpenWindow( sURL, iSiteId, sPath, sPivotName, sName, sFeatures, bReplace )
{
   cert_registerHit( iSiteId, sPath, sPivotName );
   if (!sName)
      sName = 'Downloads';
   if (!sFeatures)
      sFeatures = 'toolbar=no,location=no,directories=no,status=yes,menubar=no, scrollbars=no,resizable=no,width=425,height=510,screenX=20,screenY=20';
   window.open( sURL, 
      sName, 
      sFeatures, 
      bReplace 
   );
   return false;
}

/* Abre una nueva ventana fullscreen, marcando el hit */
function cert_registerHitAndOpenWindowfull(  sURL, iSiteId, sPath, sPivotName, sName, sFeatures, bReplace )
{
   cert_registerHit( iSiteId, sPath, sPivotName );
   if (!sName)
      sName = 'Downloads';
   if (!sFeatures)
      sFeatures = 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes, scrollbars=yes,resizable=yes,';
   window.open( sURL, 
      sName, 
      sFeatures, 
      bReplace 
   );
   return false;
}


/* Marca el hit y reemplaza/abre una URL en el frame 'sName' */
function cert_registerHitAndReplaceOtherFrame( sURL, sName, iSiteId, sPath, sPivotName ) 
{
   cert_registerHitAndOpenWindow( sURL, iSiteId, sPath, sPivotName, sName, 0, true );
}

/* Marca el hit y reemplaza/abre una URL en el frame 'sName' */
function cert_registerHitAndReplaceThisFrame( sURL, iSiteId, sPath, sPivotName ) 
{
   cert_registerHitAndRedirect( sURL, iSiteId, sPath, sPivotName );
}

/* Marca el hit y baja un archivo */
function cert_registerHitAndDownloadFile( sURL, iSiteId, sPath, sPivotName ) 
{
   cert_registerHitAndRedirect( sURL, iSiteId, sPath, sPivotName );
}

/* Marca un hit en la pgina actual */
function tagCertifica(iSiteId, sPath) 
{
    document.writeln( '<img src="' + cert_getTagCertifica(iSiteId, sPath) + '" width="1" height="1" border="0" alt="Certifica.com">' );
}

/* Marca un registro cada iTime milisegundos.  */
function cert_registerPeriodicHit( iSiteId, sPath, sPivotName, iTime ) 
{
   if ( !sPivotName )
      sPivotName = DEFAULT_PIVOT_NAME;
   if ( !iTime )
      iTime = DEFAULT_PERIODIC_REDIRECT_TIME;

   cert_registerHit( iSiteId, sPath, sPivotName );
   setTimeout( 'cert_registerPeriodicHit( ' + iSiteId + ', "' + sPath + '", "' + sPivotName + '", ' + iTime + ')', iTime );
}


/* Certifica Estadistico-Comercial Sexo-Edad-Provincia */
var dominio = window.location.host;

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function getValues (atributo) {
	var Cookie  = getCookie('TEAR_PUBLI');
	var datos = Cookie.split("&");
	for (var i=0; i<datos.length; i++) {
		var dato = datos[i].split("=");
	 	if (dato[0]==atributo) {
  				return dato[1];
   	}
	}
} 

function nastyHash() {
	this.length = 0;
	this.items = new Array();
	for (var i = 0; i < arguments.length; i += 2) {
		if (typeof(arguments[i + 1]) != 'undefined') {
			this.items[arguments[i]] = arguments[i + 1];
			this.length++;
		}
	}
}

//alert(dominio);
if (dominio == 'fotolog.terra.com.ar') {
	//alert(dominio);
	var HashSexo = new nastyHash(
	0,'masculino', 
	1,'femenino'
	);

	var HashProvincia = new nastyHash(
	153, 'buenos-aires',
	1, 'catamarca',
	164, 'chaco',
	172, 'chubut',
	5, 'ciudad-de-buenos-aires',
	165, 'corrientes',
	154, 'cordoba',
	167, 'entre-rios',
	163, 'formosa',
	158, 'jujuy',
	168, 'la-pampa',
	156, 'la-rioja',
	162, 'mendoza',
	166, 'misiones',
	169, 'neuquen',
	170, 'rio negro',
	157, 'salta',
	160, 'san-juan',
	161, 'san-luis',
	173, 'santa-cruz',
	155, 'santa-fe', 
	171, 'santiago-del-estero', 
	174, 'tierra-del-fuego',
	159,'tucuman'
	);

	if (getCookie('TEAR_PUBLI')) {
		
		// SEXO //
		var value_sexo = getValues('S');
		
		var sexo = HashSexo.items[value_sexo];
		if (!sexo) { 
			sexo = 'indefinido';		
		}	

		// EDAD //
		var valor_edad = getValues('E');
		var edad;
		if (valor_edad<13) {
			edad = 'usuarios-viejos';
		}
		else if (13<=valor_edad && valor_edad<=18) {
			edad = '13-18';
		}
		else if (19<=valor_edad && valor_edad<=24) {
			edad = '19-24';
		}
		else if (25<=valor_edad && valor_edad<=30) {
			edad = '25-30';
		}
		else if (31<=valor_edad && valor_edad<=36) {
			edad = '31-36';
		}
		else if (37<=valor_edad && valor_edad<=42) {
			edad = '37-42';
		}
		else if (43<=valor_edad && valor_edad<=48) {
			edad = '43-48';
		}
		else if (49<=valor_edad && valor_edad<=54) {
			edad = '49-54';
		}
		else if (55<=valor_edad) {
			edad = '55+';
		}
		else {
			edad = 'indefinido'; 
		}
	
		// PROVINCIA //	
		var value_provincia = getValues('D');
		var provincia = HashProvincia.items[value_provincia]

		if (!provincia) { 
			provincia = 'otros';		
		}		
	
		// ETIQUETA //	
		document.write('<div style="visibility: hidden">');
		document.write('	<script type="text/javascript">tagCertifica(21221,'+"'"+'/'+sexo+'/'+edad+'/'+provincia+"'"+');</script>');
		document.write('</div>');
	}
	else {
		var parametro ='sin-cookies/sin-cookies';
	
		//alert(parametro);
		// ETIQUETA //	
		document.write('<div style="visibility: hidden">');
		document.write('	<script type="text/javascript">tagCertifica(21221,'+"'"+'/'+parametro+"'"+');</script>');
		document.write('</div>');
	}
}
