// JScript File


var requ=null;
var reque=null;


function ActualizaBanner()
{
    var xmlhttpreq = crearXMLHttpRequest();
    if (xmlhttpreq != null){
        xmlhttpreq.open("GET","/Templates/barraderecha.html" ,true);
        xmlhttpreq.onreadystatechange= function()
                            {
                                    if (xmlhttpreq.readyState == 4){
                                       if (xmlhttpreq.status == 200){
		                                    document.getElementById("propagandas").innerHTML = xmlhttpreq.responseText;
	                                       // setTimeout("holaas()",1000);				
                                        }
                                        else{
                                            alert(xmlhttpreq.status);
                                        }
                                   }
                            }

    }
    xmlhttpreq.send(null);
}
function crearXMLHttpRequest() 
{
  var xmlHttp=null;
  if (window.ActiveXObject) 
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  else 
    if (window.XMLHttpRequest) 
      xmlHttp = new XMLHttpRequest();
  return xmlHttp;
}

function AgregaAlChango(id) {
//debugger;
    
    var prefijo = id.substring(0,1);
    var nroid = id.substring(1);
    
    var dd = null;
    try {
        dd = document.getElementById("selecttipo");
        var myindex  = dd.selectedIndex;
        var SelValue = dd.options[myindex].value;
    }
        catch(err)
    {
        dd = null;
    }
    
    var f=document.aspnetForm;
  
  if(prefijo=='c' || (prefijo=='s' && SelValue == "anio")) { 
    
    document.getElementById("ctl00_Progress1").style.display = "block";
	requ = crearXMLHttpRequest();
    var url="/ajaxfcn.aspx?idart=" + nroid;
	if(requ!=null)
	{
	 	requ.open("GET", url, true);
	 	requ.send(null);
	} else {
    	//alert("Error en Agrega al chango");
    }
     
    setTimeout("ActualizaChango()",2000);
    
   } 
   
   if(prefijo=='s' && SelValue == "nro") {
   
        window.location = "/nroanro.aspx?cod=" + f.ctl00$ContentPlaceHolder1$hiddencod.value + "&desc=" + f.ctl00$ContentPlaceHolder1$hiddenprod.value;
   }
}
	

function ActualizaChango() {
	reque = crearXMLHttpRequest();
 
    var today = new Date();
    var num = today.getTime();
    num = Math.round(Math.abs(Math.sin(num) * 1000000))
    num = num * num / 2;
    var urld="/ajaxfcn.aspx?funct=act"+ "&param=" + num;
		
	if(reque!=null)
	{
	 	reque.open("GET", urld, true);
	 	reque.onreadystatechange = Refresh;
	 	reque.send(null);
        
	} else {
    	//alert("Error en actualiza chango");
    }
}

function Refresh() {

    if (reque.readyState == 4) 
    {
        // solo si fue "ok";
			if (reque.status == 200) 
			{
				document.getElementById("carritovisor").innerHTML = reque.responseText;
				setTimeout("holaas()",1000);
			} else 
			{
			    alert("error en 200");
			}
    }
}

function holaas() {
      document.getElementById("ctl00_Progress1").style.display = "none";
}


function unlock() {
    
    var x = 0;
    var y = 0;

    var obj = document.getElementById("ctl00_ContentPlaceHolder1_txttitulo");
    var obj2 = document.getElementById("ctl00_ContentPlaceHolder1_txtautor");
    var obj3 = document.getElementById("ctl00_ContentPlaceHolder1_txteditorial");
    

    if((obj.value.length >= 2) || (obj2.value.length >= 2) || (obj3.value.length >= 2)){
        x = 1;
    }
    
    if((obj.value.length < 2) && (obj2.value.length < 2) && (obj3.value.length < 2)){
        y = 1;
    }
    
    if(x==1 && y==0) {
        
        
        document.getElementById("ctl00_ContentPlaceHolder1_radiolibro").disabled = false;
        document.getElementById("ctl00_ContentPlaceHolder1_radiorevista").disabled = false;
        document.getElementById("ctl00_ContentPlaceHolder1_radioambos").disabled = false;
        document.getElementById("ctl00_ContentPlaceHolder1_ddltemas").disabled = false;
    }
    
    if(y==1) {
        
        
        document.getElementById("ctl00_ContentPlaceHolder1_radiolibro").disabled = true;
        document.getElementById("ctl00_ContentPlaceHolder1_radiorevista").disabled = true;
        document.getElementById("ctl00_ContentPlaceHolder1_radioambos").disabled = true;
        document.getElementById("ctl00_ContentPlaceHolder1_ddltemas").disabled = true;
    }

}

function validate() {

    var obj = document.getElementById("ctl00_ContentPlaceHolder1_txttitulo");
    var obj2 = document.getElementById("ctl00_ContentPlaceHolder1_txtautor");
    var obj3 = document.getElementById("ctl00_ContentPlaceHolder1_txteditorial");
    
    
    if(((obj.value.length > 0) && (obj.value.length < 2)) || ((obj2.value.length > 0) && (obj2.value.length < 2)) || ((obj3.value.length > 0) && (obj3.value.length < 2))) {
        alert("El campo completado debe tener al menos 2 caracteres");
        return false;
    } else {
        return true;
    }
}




function getCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') {
		    c = c.substring(1,c.length);
		}
		if (c.indexOf(nameEQ) == 0) 
		    return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function setCookie(name,value,expires, options) {
if (options===undefined) { options = {}; }
if ( expires ) {
var expires_date = new Date();
expires_date.setDate(expires_date.getDate() + expires)
}
document.cookie = name+'='+escape( value ) +
( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) +
( ( options.path ) ? ';path=' + options.path : '' ) +
( ( options.domain ) ? ';domain=' + options.domain : '' ) +
( ( options.secure ) ? ';secure' : '' );
}

function GuardarCookie (nombre, valor, caducidad) {
	if(!caducidad)
		caducidad = Caduca(0)

	//crea la cookie: incluye el nombre, la caducidad y la ruta donde esta guardada
	//cada valor esta separado por ; y un espacio
	document.cookie = nombre + "=" + escape(valor) + "; expires=" + caducidad + "; path=/"
}

function Caduca(dias) {
	var hoy = new Date()					//obtiene la fecha actual
	var msEnXDias = eval(dias) * 24 * 60 * 60 * 1000	//pasa los dias a mseg.

	hoy.setTime(hoy.getTime() + msEnXDias)			//fecha de caducidad: actual + caducidad
	return (hoy.toGMTString())
}

function BorrarCookie(nombre) {
	//para borrar la cookie, se le pone una fecha del pasado mediante Caduca(-1)
	document.cookie = nombre + "=; expires=" + Caduca(-1) + "; path=/"
}

function doVisorChango()
{
	var t = getCookie("totalart");
	var m = getCookie("montoart");
	var inner = "";
	
	if(t==0 || t==null || m==null)
	    inner = "<span id=\"ctl00_lblcantart\">0 art&iacute;culos</span><br/><span id=\"ctl00_lblmonto\">$ 0,00</span>";
	if(t == 1)
	    inner = "<span id=\"ctl00_lblcantart\">" + t + " art&iacute;culo</span><br/><span id=\"ctl00_lblmonto\">$ " + m + "</span>";
	if(t > 1)
	    inner = "<span id=\"ctl00_lblcantart\">" + t + " art&iacute;culos</span><br/><span id=\"ctl00_lblmonto\">$ " + m + "</span>";	    
		
    document.getElementById("carritovisor").innerHTML = inner;

}


function solapaDefault() {
    var ids = getCookie("oreja");//CojerCookie("solap"); //getCookie("solap");
    if(ids!=null) {
        document.getElementById(ids).style.display = "block"; 
    }
}

function showsub(id) {
    
    if(document.getElementById(id).style.display == "none") {
        document.getElementById(id).style.display = "block";   
        setCookie('oreja',id,10);
    } else {
        if(document.getElementById(id).style.display == "block") {
            document.getElementById(id).style.display = "none";
            BorrarCookie('oreja');
        }
    }
}


/**
 * Verifica si se recibe por qs el codigo de asociado
 * y lo guarda en una cookie
 */

var vienede;

function parseParams(query) 
{
	var qsParm = new Array();
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) {
   		var pos = parms[i].indexOf('=');
   		if (pos > 0) {
      			var key = parms[i].substring(0,pos);
      			var val = parms[i].substring(pos+1);
      			qsParm[key] = val;
      		}
	}
	return qsParm;
}

function guardarAsociado()
{
	var query = window.location.search.substring(1);
	var qs = parseParams(query);
	if (qs['vienede'])
	{
		vienede=qs['vienede'];
		if(getCookie("vienede")!=vienede)
		{
		    var current_date = new Date();
		    //setCookie('vienede', qs['vienede'], 366);
		    set_cookie('vienede', qs['vienede'], current_date.getFullYear() + 1, current_date.getMonth(), current_date.getDate());
		    SendQueryAsoc();
		}
	}
}


function set_cookie ( name, value, exp_y, exp_m, exp_d, domain)
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }



  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  cookie_string += "; path=/"
  
  document.cookie = cookie_string;
}


var reqasoc;

function InitializeAsoc()
{
	try
	{
		reqasoc=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			reqasoc=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			
			reqasoc=null;
		}
	}

	if(!reqasoc && typeof XMLHttpRequest!="undefined")
	{
		reqasoc=new XMLHttpRequest();
		
	}
	
}

function SendQueryAsoc()
{		
	InitializeAsoc();
	var url="/actualizaAsoc.aspx?vienede="+vienede;
	
	if(reqasoc!=null)
	{
		//req.onreadystatechange = Process;
		
		reqasoc.open("GET", url, true);
        reqasoc.send(null);
        
	}
	
}


function Process()
{
    return null;
}

/* Retorna todas las queries con su valor salvo el parámtetro enviado como argumento */

function eliminarParam(strParamName)
{
    var cadena="";
    var strHref = window.location.href;

    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
        var aParam = aQueryString[iParam].split("=");
        if(aParam[0] != strParamName)
            cadena = cadena + aQueryString[iParam] + "&";
    }
    
    return cadena.substr(0,cadena.length-1);
}

/* redirige a la página actual agregando el query que crea a partir del Drop Down de orden */

function redirectDDPlus(obj) 
{
    var idxval = obj.options[obj.selectedIndex].value;
    var idx = idxval.split("=");

        if(idx[1]=="none")
        {
            var strHref = window.location.href;
            var strQueryString = strHref.split("?");
            strHref = strQueryString[0] + eliminarParam("orden");
        }
        else
        {
            var strHref = window.location.href;
            var strQueryString = strHref.split("?");
            strHref = strQueryString[0] +  eliminarParam("orden") + "&" + obj.options[obj.selectedIndex].value; 
        }

    window.location = strHref;
}


function redirectDDPlusRB(opc) 
{
    if (opc=="L")
   {
            var strHref = window.location.href;
            var strQueryString = strHref.split("?");
            strHref = strQueryString[0] + eliminarParam("tipo") + "&tipo=L"; 
   } 
    if (opc=="R")
   {
            var strHref = window.location.href;
            var strQueryString = strHref.split("?");
            strHref = strQueryString[0] + eliminarParam("tipo") + "&tipo=R";   
   } 
    if (opc=="A")
   {
            var strHref = window.location.href;
            var strQueryString = strHref.split("?");
            strHref = strQueryString[0] + eliminarParam("tipo") + "&tipo=";   
   } 
    window.location = strHref;
}
