// JavaScript Document

function $(id){return document.getElementById(id);}

function addLoadEvent(func) {

  var oldonload = window.onload;

  if (typeof window.onload != 'function') {

    window.onload = func;

  } else {

    window.onload = function() {

      if (oldonload) {

        oldonload();

      }

      func();

    }

  }

}

function addEvent(obj, evType, fn, useCapture){

 

 if (obj.addEventListener){

    obj.addEventListener(evType, fn, useCapture);

    

  } else if (obj.attachEvent){

    obj.attachEvent("on"+evType, fn);

   

  } else {

   obj['on'+evType]=fn;

  }

}



function removeEvent(obj, evType, fn, useCapture){

  if (obj.removeEventListener){

    obj.removeEventListener(evType, fn, useCapture);

  } else if (obj.detachEvent){

    obj.detachEvent("on"+evType, fn);

  } else {

    obj['on'+evType]=function(){};

  }

}

String.prototype.tratarResponseText=function(){

    var pat=/<script[^>]*>([\S\s]*?)<\/script[^>]*>/ig;

    var pat2=/\b\s+src=[^>\s]+\b/g;

    var elementos = this.match(pat) || [];

    for(i=0;i<elementos.length;i++) {

        var nuevoScript = document.createElement('script');

        nuevoScript.type = 'text/javascript';

        var tienesrc=elementos[i].match(pat2) || [];

        if(tienesrc.length){

            nuevoScript.src=tienesrc[0].split("'").join('').split('"').join('').split('src=').join('').split(' ').join('');

        }else{

            var elemento = elementos[i].replace(pat,'$1');

            nuevoScript.text = elemento;

        }

        document.getElementsByTagName('body')[0].appendChild(nuevoScript);

    }

    return this.replace(pat,'');

} 

function http(){

	if(typeof window.XMLHttpRequest!='undefined'){

		return new XMLHttpRequest();	

	}else{

		try{

			return new ActiveXObject('Microsoft.XMLHTTP');

		}catch(e){

			alert('Su navegador no soporta AJAX');

			return false;

		}	

	}	

	

}

function request(url,divId,params){

	var H=new http();

	if(!H)return;

	H.open('post',url+'?'+Math.random(),true);

	H.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

	H.onreadystatechange=function(){

		if(H.readyState==4){

			$(divId).parentNode.style.backgroundImage='none';

			$(divId).innerHTML=H.responseText.tratarResponseText();

			H.onreadystatechange=function(){}

			H.abort();

			H=null;

		}else{

			$(divId).innerHTML='';

		}

	}

	var p='';

	for(var i in params){

		p+='&'+i+'='+escape(params[i]);	

	}

	H.send(p);

}

function request2(url,divId,params){

	var H=new http();

	if(!H)return;

	H.open('post',url+'?'+Math.random(),true);

	H.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

	H.onreadystatechange=function(){

		if(H.readyState==4){

			$(divId).parentNode.style.backgroundImage='none';

			$(divId).style.width='100%';

			$(divId).style.height='95%';

			$(divId).style.margin=0;

			$(divId).style.backgroundColor='#D0DCDA';

			$(divId).innerHTML=H.responseText;

			H.onreadystatechange=function(){}

			H.abort();

			H=null;

		}else{

			$(divId).innerHTML='';

		}

	}

	var p='';

	for(var i in params){

		p+='&'+i+'='+escape(params[i]);	

	}

	H.send(p);

}

function requestGET(url,divId,params){

	var H=new http();

	if(!H)return;

	var p='';

	for(var i in params){

		p+='&'+i+'='+escape(params[i]);	

	}

	H.open('get',url+'?'+p+'&'+Math.random(),true);

	H.onreadystatechange=function(){

		if(H.readyState==4){

			$(divId).parentNode.style.backgroundImage='none';

			$(divId).innerHTML=H.responseText.tratarResponseText();

			H.onreadystatechange=function(){}

			H.abort();

			H=null;

		}else{

			$(divId).innerHTML='';

		}

	}

	

	H.send(null);

}

function requestCallback(url,callback,params){

	var H=new http();

	if(!H)return;

	H.open('post',url+'?'+Math.random(),true);

	H.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

	H.onreadystatechange=function(){

		if(H.readyState==4){

			callback();

			H.onreadystatechange=function(){}

			H.abort();

			H=null;

		}

	}

	var p='';

	for(var i in params){

		p+='&'+i+'='+escape(params[i]);	

	}

	H.send(p);

}

function requestCallbackParam(url,callback,params){

	var H=new http();

	if(!H)return;

	H.open('post',url+'?'+Math.random(),true);

	H.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

	H.onreadystatechange=function(){

		if(H.readyState==4){

			callback(H.responseText);

			H.onreadystatechange=function(){}

			H.abort();

			H=null;

		}

	}

	var p='';

	for(var i in params){

		p+='&'+i+'='+escape(params[i]);	

	}

	H.send(p);

}

function escribir(texto){

vec=texto.split('-');

document.getElementById('Ffecha').innerHTML='&nbsp;'+vec[0]+'-'+vec[1]+'-'+vec[2];

requestCallbackParam('timestamp.php',function(n){document.getElementById('fecha').value=n;},{'fecha':vec[2]+'-'+vec[1]+'-'+vec[0]})

cerrar();

}

function escribir2(texto){

vec=texto.split('-');

document.getElementById('Ffecha').innerHTML='&nbsp;'+vec[0]+'-'+vec[1]+'-'+vec[2];

requestCallbackParam('timestamp.php',function(n){document.getElementById('fechaCasamiento').value=n;},{'fecha':vec[2]+'-'+vec[1]+'-'+vec[0]})

cerrar();

}

function escribir3(texto){

vec=texto.split('-');

document.getElementById('Ffecha2').innerHTML='&nbsp;'+vec[0]+'-'+vec[1]+'-'+vec[2];

requestCallbackParam('timestamp.php',function(n){document.getElementById('cumpleanos').value=n;},{'fecha':vec[2]+'-'+vec[1]+'-'+vec[0]})

cerrar();

}

function escribir4(texto){

vec=texto.split('-');

document.getElementById('Ffecha2').innerHTML='&nbsp;'+vec[0]+'-'+vec[1]+'-'+vec[2];

requestCallbackParam('timestamp.php',function(n){document.getElementById('autorizadoHasta').value=n;},{'fecha':vec[2]+'-'+vec[1]+'-'+vec[0]})

cerrar();

}

function tomarData(obj){

	var i;

	for(i in obj){

		if(i=='localidad'){

			for(var m=0;m<$(i).options.length;m++){

				$(i).options[m].selected=0;

			}

			if(obj[i].toString().length>0){

				var vp=obj[i].split('#');

				for (var n=0;n<vp.length;n++){

					$(i).options[vp[n]].selected=1;

				}

			}

		}

		$(i).value=obj[i];

	}

	cerrar();

}

function listarSubCat(cat,Subcat){

		$('divCat').innerHTML='<img src="images/ajax-loader.gif" />';

	var callback=function(n){

		$('divCat').innerHTML=n;

	}

	requestCallbackParam('subcategoriasAjax.php',callback,{'categoria':cat,'subcategoria':Subcat});

}

function buscarAnunciante(key){

	request('anuncianteBuscar.php','ifr',{'key':key});

}

function buscarProfesional(key){

	request('profesionalBuscar.php','ifr',{'key':key});

}

function seleccionarAnunciante(nombre,id){

	$('divAnu').innerHTML=nombre;

	$('anunciante').value=id;

	cerrar();

}

function seleccionarProfesional(nombre,id){

	$('divProf').innerHTML=nombre;

	$('nombre_profesional').value=id;

	cerrar();

}

function borrarFotoGaleria(id){

	if(!confirm('está seguro de eliminar esta imagen?'))return;

	var callback=function(n){

		$('gal').innerHTML=n;

	}

	requestCallbackParam('proceso.php',callback,{'id':id,'proceso':'BORRAR_IMAGEN_GALERIA'});

}

function borrarFotoGaleriaRevista(id){

	if(!confirm('está seguro de eliminar esta imagen?'))return;

	var callback=function(n){

		$('gal').innerHTML=n;

	}

	requestCallbackParam('proceso.php',callback,{'id':id,'proceso':'BORRAR_IMAGEN_GALERIA_REVISTA'});

}

function borrarFotoGaleriaDirectorio(id){

	if(!confirm('está seguro de eliminar esta imagen?'))return;

	var callback=function(n){

		$('gal').innerHTML=n;
		var fm=$("filemanager").contentDocument || $("filemanager").contentWindow.document;
		fm.location.href=fm.location.href;
	}

	requestCallbackParam('proceso.php',callback,{'id':id,'proceso':'BORRAR_IMAGEN_GALERIA_DIRECTORIO'});

}

function desdestacar(par,id){

	var campo;

	switch(par){

		case 'sdh':

		campo='superDestacadaHome';

		$('superDestacadaHomeSi').checked=1;

		$('superDestacadaHomeNo').checked=0;

		cerrar();

		break;

		case 'DH':

		campo='destacadaHome';

		$('destacadaHomeSi').checked=1;

		$('destacadaHomeNo').checked=0;

		cerrar();

		break;

		case 'PPAL':

		campo='principalCategoria';

		$('principalCategoriaSi').checked=1;

		$('principalCategoriaNo').checked=0;

		cerrar();

	}

	requestCallback('proceso.php',function(){},{'id':id,'campo':campo,'proceso':'ANULAR_DESTACADOS'});

}

//

function desdestacarVideo(id){

	var campo;

	campo='destacado';

	$('destacadoSi').checked=1;

	$('destacadoNo').checked=0;

	cerrar();

	requestCallback('proceso.php',function(){},{'id':id,'campo':campo,'proceso':'ANULAR_VIDEO_DESTACADO'});

}

function verificarDestacadas(cat,id){

	var callback=function(n){

		if(n=='ok')

			return true;

		else{

			mostrarDestacadasHomeCat(cat);

			$('destacadaHomeNo').checked=1;

			return false;

		}

	}

	requestCallbackParam('proceso.php',callback,{'categoria':cat,'proceso':'VERIFICAR_DESTACADAS','id':id});

}

function mostrarDestacadasHomeCat(cat){

	ventana();

	request('mostrarDestacadasElim.php','ifr',{'categoria':cat});

}



function verificarPrincipalCategoria(cat,id){

	var callback=function(n){

		if(n=='ok')

			return true;

		else{

			mostrarPrincipalCat(cat);

			$('principalCategoriaNo').checked=1;

			return false;

		}

	}

	requestCallbackParam('proceso.php',callback,{'categoria':cat,'proceso':'VERIFICAR_PRINCIPAL','id':id});

}

function mostrarPrincipalCat(cat){

	ventana();

	request('mostrarPrincipalElim.php','ifr',{'categoria':cat});

}

function verificarSuperHome(id){

	var callback=function(n){

		if(n=='ok')

			return true;

		else{

			mostrarSuperHome();

			$('superDestacadaHomeNo').checked=1;

			return false;

		}

	}

	requestCallbackParam('proceso.php',callback,{'proceso':'VERIFICAR_SUPER_HOME','id':id});

}

function mostrarSuperHome(){

	ventana();

	request('mostrarSuperHomeElim.php','ifr',{});

}

//verificarVideoDestacado



function verificarVideoDestacado(id){

	var callback=function(n){

		if(n=='ok')

			return true;

		else{

			mostrarVideoDestacado();

			$('destacadoNo').checked=1;

			return false;

		}

	}

	requestCallbackParam('proceso.php',callback,{'proceso':'VERIFICAR_VIDEO_DESTACADO','id':id});

}

function mostrarVideoDestacado(){

	ventana();

	request('mostrarVideoDestacadoElim.php','ifr',{});

}

function sortear(){

	objEnc={};

	objEnc.limit=30;

	objEnc.inicio=1;

	ventana();

	request('sorteo.php','ifr',{});

}

function ganador(id){

		var callback=function(){

			cerrar();

			window.location='?id='+id;

		}

		requestCallbackParam('proceso.php',callback,{'proceso':'ESTABLECER_GANADOR','id':id});

}

function favoritos(id,tabla,accion,e){

	requestCallbackParam('proceso2.php',function(){},{'proceso':accion,'id':id,'tabla':tabla});

	var e=e || window.event;

	var obj=e.srcElement || e.target;

	var ni=document.createElement('img');

	ni.src='img/butt_fab_del.gif';

	ni.border="0";

	addEvent(ni, 'click', function(e){des_favoritos(id,tabla,'DESHACER_FAVORITO',e);}, false);

	obj.parentNode.replaceChild(ni,obj);

	alert('el item seleccionado ha sido agregado a tus favoritos');

	$('superfavoritos').innerHTML=parseInt($('superfavoritos').innerHTML)+1;

}

function des_favoritos(id,tabla,accion,e){

	requestCallbackParam('proceso2.php',function(){},{'proceso':accion,'id':id,'tabla':tabla});

	var e=e || window.event;

	var obj=e.srcElement || e.target;

	var ni=document.createElement('img');

	ni.src='img/butt_fab_off.gif';

	ni.border="0";

	addEvent(ni, 'click', function(e){favoritos(id,tabla,'AGREGAR_FAVORITOS',e);}, false);

	obj.parentNode.replaceChild(ni,obj);

	alert('el item seleccionado ha sido removido de tu lista de favoritos');

	$('superfavoritos').innerHTML=parseInt($('superfavoritos').innerHTML)-1;

	if(parseInt($('superfavoritos').innerHTML)<0)$('superfavoritos').innerHTML='0';

}



function galeria(vec){

	this.miarray=vec;

	this.indice=0;

	this.directorio='';

	this.precarga=function(){

		for(var i=0;i<this.miarray.length;i++){

			eval("imagen"+i+"=new Image();");

			eval("imagen"+i+".src=" + "\"" +this.directorio+this.miarray[i]+"\";");

		} 

	}

	this.cambia=function(como){

		if(como=='menos'){

			this.indice--;

		}else{

			this.indice++;

		}

		if (this.indice < 0) this.indice = this.miarray.length - 1;

		if (this.indice > this.miarray.length-1) this.indice = 0;

		document.visor.src=this.miarray[this.indice];
		//$('visor').style.backgroundImage='url('+this.miarray[this.indice]+')';

	}

}

function rotadorPubli(vecF,vecT,vecC,vecID){

		this.indice=0;

		this.vecF=vecF;

		this.vecT=vecT;

		this.vecC=vecC;

		this.vecID=vecID;

		this.precarga=function(){

			for(var i=0;i<this.vecF.length;i++){

				eval("imagen"+i+"=new Image();");

				eval("imagen"+i+".src=" + "\"" +this.vecF[i]+"\";");

			} 

		}

		this.posicionar=function(){

			$('fotoRotador').innerHTML='<a href="disenadores.php?id='+this.vecID[this.indice]+'"><img src="'+this.vecF[this.indice]+'" width="100" hspace="5" border="0"></a>';

			$('tituloRotador').innerHTML='<h3><a href="disenadores.php?id='+this.vecID[this.indice]+'" class="links_TitListNota_Fashion">'+this.vecT[this.indice]+'</a></h3>';

			$('textoRotador').innerHTML='<span class="links_TxtListNota_Fashion">'+this.vecC[this.indice]+'</span>';

			this.indice++;

			if(this.indice>this.vecID.length-1)this.indice=0;

		}

		this.rotar=function(){

			var _this=this;

			setInterval(function(){_this.posicionar();},15000);	

		}

}

function rotadorPubli2(vecF,vecT,vecC,vecID){

		this.indice=0;

		this.vecF=vecF;

		this.vecT=vecT;

		this.vecC=vecC;

		this.vecID=vecID;

		this.precarga=function(){

			for(var i=0;i<this.vecF.length;i++){

				eval("imagen"+i+"=new Image();");

				eval("imagen"+i+".src=" + "\"" +this.vecF[i]+"\";");

			} 

		}

		this.posicionar=function(){

			$('fotoRotador').innerHTML='<a href="estilistas.php?id='+this.vecID[this.indice]+'"><img src="'+this.vecF[this.indice]+'" width="100" hspace="5" border="0"></a>';

			$('tituloRotador').innerHTML='<h3><a href="estilistas.php?id='+this.vecID[this.indice]+'" class="links_TitListNota_Fashion">'+this.vecT[this.indice]+'</a></h3>';

			$('textoRotador').innerHTML='<span class="links_TxtListNota_Fashion">'+this.vecC[this.indice]+'</span>';

			this.indice++;

			if(this.indice>this.vecID.length-1)this.indice=0;

		}

		this.rotar=function(){

			var _this=this;

			setInterval(function(){_this.posicionar();},15000);	

		}

}

function setVideo(VIDEO){

	var so = new SWFObject("swf/videoss.swf", "player", "400", "343", "8", "#FFFFFF");

  	so.addParam("quality", "high");

	so.addParam("wmode", "transparent");

	so.addVariable("VIDEO", VIDEO);

   	so.write("flashcontent");	

}