

	
	initKeywords()
	initLogin();
	initPanel();
	moreclasificados;
	Loader(preloads);


/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

//
// Validador de Rut
// Descargado desde http://www.juque.cl/
//


var elemento = 'rut';
function showmsg(txt){
	var mirut = window.document.getElementById('rut');
	mirut.style.background = "#f1f19b";
	mirut.focus();		
	mirut.select();	
	mirut.value = txt;

}
function status(tipo,txt,delay){
if(!delay) delay = 5000;
	var block = document.getElementById('statusblock');
	

	switch(tipo){
	
		case 'FAIL':
		
			//$('statusblock').style.backgroundColor="#F00";
			//$('statusblock').style.color="#FFFFFF";
			$('status').innerHTML = txt;
		
		break;
				
		case 'EXITO':
		
			//$('statusblock').style.backgroundColor="#00cc00";
			//$('statusblock').style.color="#000000";
			$('status').innerHTML = txt;
		
		break;
	}	
	
	var left	= (screen.width  - 245 - $('statusblock').offsetWidth)/2;
	left=left+"px";

	$('statusblock').style.left=left;

	if($('statusblock').style.visibility=='hidden' || $('statusblock').style.visibility=='')
			$('statusblock').style.visibility='visible';
	else $('statusblock').style.visibility='hidden'; 

	setTimeout("$('statusblock').style.visibility='hidden'",delay);

}
/*********** setter *****/
function setformrut(txt){
	$('formulario').rut.value = txt
}

function setrut(txt){
	$('rut').value = txt;
}

function setrutrvy(txt){
	$('rutrvy').value = txt;
	
}
function revisarDigito( dvr , setter )
{
if(!setter) setter = function (txt){ };

	dv = dvr + ""	
	if ( dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4' && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9' && dv != 'k'  && dv != 'K')	
	{		
		setter("El digito verificador es invalido");		
		
		return false;	
	}	
	return true;
}

function revisarDigito2( crut, setter )
{
if(!setter) setter = function (txt){ };

	largo = crut.length;	
	if ( largo < 2 )	
	{
		setter("Debe ingresar todo su RUT");	
		return false;	
	}	
	if ( largo > 2 )		
		rut = crut.substring(0, largo - 1);	
	else		
		rut = crut.charAt(0);	
	dv = crut.charAt(largo-1);	
	revisarDigito( dv , setter);	

	if ( rut == null || dv == null )
		return 0	

	var dvr = '0'	
	suma = 0	
	mul  = 2	

	for (i= rut.length -1 ; i >= 0; i--)	
	{	
		suma = suma + rut.charAt(i) * mul		
		if (mul == 7)			
			mul = 2		
		else    			
			mul++	
	}	
	res = suma % 11	
	if (res==1)		
		dvr = 'k'	
	else if (res==0)		
		dvr = '0'	
	else	
	{		
		dvi = 11-res		
		dvr = dvi + ""	
	}
	if ( dvr != dv.toLowerCase() )	
	{		
		setter("EL RUT es incorrecto");
		return false	
	}

	return true
}

function Rut(texto,setter)
{	
if(!setter) setter = function (txt){ };
	var tmpstr = "";	
	for ( i=0; i < texto.length ; i++ )		
		if ( texto.charAt(i) != ' ' && texto.charAt(i) != '.' && texto.charAt(i) != '-' )
			tmpstr = tmpstr + texto.charAt(i);	
	texto = tmpstr;	
	largo = texto.length;	

	if ( largo < 2 )	
	{		
		setter("Debe ingresar el RUT completo");	
			 
		return false;	
	}	

	for (i=0; i < largo ; i++ )	
	{			
		if ( texto.charAt(i) !="0" && texto.charAt(i) != "1" && texto.charAt(i) !="2" && texto.charAt(i) != "3" && texto.charAt(i) != "4" && texto.charAt(i) !="5" && texto.charAt(i) != "6" && texto.charAt(i) != "7" && texto.charAt(i) !="8" && texto.charAt(i) != "9" && texto.charAt(i) !="k" && texto.charAt(i) != "K" )
 		{			

		setter('El RUT es invalido')

			return false;		
		}	
	}	

	var invertido = "";	
	for ( i=(largo-1),j=0; i>=0; i--,j++ )		
		invertido = invertido + texto.charAt(i);	
	var dtexto = "";	
	dtexto = dtexto + invertido.charAt(0);	
	dtexto = dtexto + '-';	
	cnt = 0;	

	for ( i=1,j=2; i<largo; i++,j++ )	
	{		
		//alert("i=[" + i + "] j=[" + j +"]" );		
		if ( cnt == 3 )		
		{			
			dtexto = dtexto + '.';			
			j++;			
			dtexto = dtexto + invertido.charAt(i);			
			cnt = 1;		
		}		
		else		
		{				
			dtexto = dtexto + invertido.charAt(i);			
			cnt++;		
		}	
	}	

	invertido = "";	
	for ( i=(dtexto.length-1),j=0; i>=0; i--,j++ )		
		invertido = invertido + dtexto.charAt(i);	

	//window.document.getElementById(elemento).style.background = "#fff";
	setter(invertido.toUpperCase());

	if ( revisarDigito2(texto,setter) )		
		return true;	

	return false;
}

var timeout;
var web = 'http://observador.cl';
function $(id){
	var element = document.getElementById(id);
	return element;
}

function explode (delimiter, string, limit) {
	  var emptyArray = { 0: '' };

	 // limite es opcional.
	if ( arguments.length < 2 ||
		  typeof arguments[0] == 'undefined' ||	typeof arguments[1] == 'undefined' )
	{
		  return null;
	}
	 if ( delimiter === '' ||
		  delimiter === false ||
		  delimiter === null )
	{
		  return false;	 }
 
	if (	typeof delimiter == 'function'	||
			typeof delimiter == 'object'	||
			typeof string == 'function'	||  
			typeof string == 'object')
	{
		  return emptyArray;
	}
	 if ( delimiter === true ) {
		  delimiter = '1';
	}
	 
	if (!limit) {		  return string.toString().split(delimiter.toString());
	} else {
		  // valor default para limite
		  var splitted = string.toString().split(delimiter.toString());
		  var partA = splitted.splice(0, limit - 1);		  var partB = splitted.join(delimiter.toString());
		  partA.push(partB);
		  return partA;
	}
}

function wordwrap (str, int_width, str_break, cut) {
	 var m = ((arguments.length >= 2) ? arguments[1] : 75	);
	 var b = ((arguments.length >= 3) ? arguments[2] : "\n" );
	 var c = ((arguments.length >= 4) ? arguments[3] : false);

	 var i, j, l, s, r;

	 str += '';

	 if (m < 1) {
		  return str;
	 }

	 for (i = -1, l = (r = str.split(/\r\n|\n|\r/)).length; ++i < l; r[i] += s) {
		  for (s = r[i], r[i] = ""; s.length > m; r[i] += s.slice(0, j) + ((s = s.slice(j)).length ? b : "")){
			j = c == 2 || (j = s.slice(0, m + 1).match(/\S*(\s)?$/))[1] ? m : j.input.length - j[0].length || c == 1 && m || j.input.length + (j = s.slice(m).match(/^\S*/)).input.length;
		  }
	 }
	 
return r.join("\n");
}

function is_array(variable) {
var retorno = false;
	if(variable.constructor == Array)
		retorno = true;

return retorno;
}

function is_string(variable){
var retorno = false;
		if (typeof variable == 'string')
			retorno = true;

return retorno;
}

function is_int(variable){
var retorno = false;
		if (typeof variable == 'number')
			retorno = true;

return retorno;
}

function is_numeric(sText){
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;

 	for (i = 0; i < sText.length && IsNumber == true; i++) 
		{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
			{
			IsNumber = false;
			}
	}
	return IsNumber;  
}

function preg_replace(pattern,replace_p,cadena){
	return cadena.replace(pattern, replace_p);		
}
																																																			
function limpiar (cadena){

	var pattern	= /[(<>\" \'&\(\)\/\{\}#$%\\.á-ýâ-ûÂ-Ûä-ÿÄ-Ü&=@ã-õÃ-Õ!¡\[\]|;°¨^,*¬¿?Çç]/g;
	var replace_p = '_'; // 1;

 return preg_replace(pattern, replace_p, cadena);

}

function CortarPalabra (cadena, limite, delim) {
	if(!delim) delim = '...';
 	  	cadena=explode('  ',wordwrap(cadena, limite,' '));
		
	if(cadena.length == 1)
			delim = '';

	return cadena[0] + delim;
}

function GetInfoByName(nombre){
	var info = document.getElementsByName(nombre);
	var total = info.length;
	var el = new Array;

	for(var i = 0; i < total; i++){
		var obj = info.item(i);
		el[i] = new GetInfo(obj.id);
	}
	// el['todos'] = total;

return el;
}

function GetInfo(variables){
	/* get/set elment info */
	this.e = $(variables);	
	
	this.valor	= this.e.value; // AVISO: devolverá un string y no la propiedad del elemento.
	this.estilo	= this.e.style;

	/* métodos */

	// este método permite identificar si el input está vacio y cambiando su color y devolviendo un status error
	this.CheckError	= function(senderror) {
		if(this.e.type == 'password'){

			if(this.e.value == '') { 	this.estilo.borderColor = "#f1f19b"; senderror = true; } 
			else { this.estilo.background = "#ffffff"; 
					// if (error = true) error = true;
			}

		} else {

			if(this.e.value == '') { this.estilo.borderColor = "#cc412d"; senderror = true; }
			else { this.estilo.background = "#ffffff";  
				// if (error = true) error = true; else false;
			}		
		}	// this.e.type
		return senderror;
	}  // method CHKERROR
	

	this.ChColor = function(color) {
		if(!color) color = '#000';
		this.estilo.color = color;
	}

	this.aviso	= function(campo){
		if(!campo) campo = this.name;
	alert(this.valor);
	}

	this.completar = function(valor){
		if(!valor) valor = '';
	this.e.value=valor;
	}
	
	this.Limpiar = function() {
		this.e.value='';
	}

}

function Emails(field,txt){
var retorno = false;
if(!txt) txt = 'Su E-mail es invalido';

	with (field){ 

		var apos=value.indexOf("@");
		var dotpos=value.lastIndexOf(".");

			if (apos<1||dotpos-apos<2) {
				value = txt;
				style.borderColor= '#808080';
				select();	focus();	select();
			}
			else retorno = true;

	  }
 return retorno;
}

function confirmacion(txt,funcion){
var retorno = true;
	var r=confirm(txt);
	if (r==true)
		{
		 funcion();
		}
	else
	{
		retorno = false;
	}

return retorno;
}

var expand;
function eExpand(e,estado1,estado2){
	with(e){
		if(className == estado1)
		expand = setTimeout(className = estado2,45);
		else expand = setTimeout(className = estado1,45);
	}
}
function ClearExpand(){
	clearTimeout(expand);
}

function url(URL,name,width,height,top,left){
	if(!name)	name	= '';
	if(!width)	width	= 500;
	if(!height)	height	= 436;
	if(!left)	left	= (screen.width  - width)/2;
	if(!top) 	top		= (screen.height - height)/2;

var opciones="toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, width="+width+", height="+height+", top="+top+", left="+left;
	
	window.open(URL,name,opciones);
}



function Remove(from,nodo){
	var padre	= document.getElementById(from);
	var hijo	= document.getElementById(nodo);	
	padre.removeChild(hijo);
}

var index=1;
function Append(to,nombre,idValor){
	
	valor = document.getElementById(idValor);
	txt = valor.value;

	if(index == 1)	index = knowNode();
		
	var frtli	= document.createElement("INPUT");		// first value
	var closer	= document.createElement("a");		// first input closer
	var salto	= document.createElement("br");

	var oList	= document.getElementById(to);

	oList.appendChild(frtli);
	frtli.type="text";
	frtli.name=nombre;
	frtli.id=index;
	frtli.value=txt;
	
	oList.appendChild(closer);
	closer.innerHTML="Cerrar "+index;
	closer.id=index+1;
		var telefono	= index;
		var closer		= index+1
	closer.href="javascript:Remove('"+to+"',"+telefono+"); Remove('"+to+"',"+closer+");";
	
	var br = 0;
	// oList.appendChild(salto); salto.id=index+2; var br = 1;

	index +=2+br;

	$(valor).value=$(valor).alt;
}

function knowNode(container){
if(!container){
	var nodo = document.getElementById('saladeventas').childNodes.length;
	nodo += document.getElementById('tels').childNodes.length;
} else
	var nodo = document.getElementById(container).childNodes.length;
	
 return nodo;
}

// better image preloading @ http://perishablepress.com/press/2009/12/28/3-ways-preload-images-css-javascript-ajax/
function preloads() {
	if (document.getElementById) {
		document.getElementById("preloads").style.background = "url("+web+"/imagenes/logo_observador_rojo.gif) no-repeat -9999px -9999px";
		initRegistro();
	}

	initRegistro();
	
 $('loadblock').style.display='none';
}

function initKeywords() {
	
	if (document.getElementById('keyword')){
		$('keyword').onfocus= function(){ TextToggle(this.id); }
		$('keyword').onblur= function(){ TextToggle(this.id);}
	} else setTimeout("initKeywords()",1000);
}

function initLogin(){
		if (document.getElementById('ingresar')) {
			$('ingresar').onclick= function(){ login('ingresar'); } 

		} else setTimeout("initLogin()",1000);
}

function initPanel(){
var undefinied = true;
	if(document.getElementById('enviar_cartas'))
		$('enviar_cartas').onclick = function() { }
	else undefinied = false;

	if(document.getElementById('enviar_documentos'))
		$('enviar_documentos').onclick= function()  {} 
	else undefinied = false;

	
	if(document.getElementById('cerrar_session')){
		$('cerrar_session').target ='think';
		$('cerrar_session').onclick= function(){ $('cerrar_session').href="calcula/get/logout" };
	}	else undefinied = false;
	
	if(!undefinied)
		setTimeout("initPanel()",1000);

}


function initRegistro(){
var undefinied = true;
	if(document.getElementById('formulario')){
		if(document.getElementById('formulario').rut){
			$('formulario').rut.onclick	 = function() { TextToggle($('formulario').rut.id); }
			$('formulario').rut.onchange = function() { return Rut($('formulario').rut.value,setformrut); }
		}
		if(document.getElementById('formulario').email){
			$('formulario').email.onchange = function() { Emails($('email')); }
		}
		

	} else undefinied = false;

 return undefinied;
}

function chLink(id,url,target,inner){

	if(!url)	url		='#';
	if(!target)	target	= '_self';
	if(!inner)	inner	= $(id).innerHTML;

			$(id).innerHTML	= inner;
			$(id).target	= target;
			$(id).href		= url;
}

function Loader(func) {
if(!func) func = function() {};

	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

function IframeLoads(url,id) {
var iframe = $(id);
	iframe.location.href = url;
	iframe.location.reload();
}

var time_stat;
function stats(txt,delay){
	if(!delay) delay = 6000;
	var status	= document.getElementById('status');
	var content = document.getElementById('estado');

	if(status.style.visibility == '' || status.style.visibility == 'hidden'){
			content.innerHTML = CortarPalabra(txt,27);
			status.style.visibility = 'visible'
					
		time_stat = setTimeout("stats('')",delay);

	} else {
		status.style.visibility = 'hidden';
		content.innerHTML = '';		
	}
	
}

function TextToggle(idClean){
	var clean	= $(idClean);
	if		(clean.value==clean.defaultValue)clean.value='';

	else if (clean.value=='')clean.value=clean.defaultValue;
}

function displayToggle(idShow,delay){
	show	= $(idShow);
	if(!delay) delay = 0;
	if(show.style.display=='')
				setTimeout("show.style.display='inline-block'",delay);
	else if(show.style.display=="inline-block")
				setTimeout("show.style.display=''",delay); 
}


var lapsus = 1000.0;
function fade(eid,TimeToFade)
{
if(!TimeToFade) TimeToFade = lapsus;
  var element = document.getElementById(eid);
  if(element == null)
    return;
   
  if(element.FadeState == null)
  {
    if(element.style.opacity == null 
        || element.style.opacity == '' 
        || element.style.opacity == '1')
    {
      element.FadeState = 2;
    }
    else
    {
      element.FadeState = -2;
    }
  }
    
  if(element.FadeState == 1 || element.FadeState == -1)
  {
    element.FadeState = element.FadeState == 1 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  }
  else
  {
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33,TimeToFade);
  }  
}
function animateFade(lastTick, eid, TimeToFade)
{  
if(!TimeToFade) TimeToFade = lapsus;
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = ' 
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = element.FadeState == 1 ? 2 : -2;
    return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
  
  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}


function Entrar(){
var retorno = false;	
	var rut		= GetInfo('rut');
	var pw		= GetInfo('password');
	
	error = false;
	if(rut['valor'] == '')	CHBACKCOLOR(rut);
	if(pw['valor'] == '')	CHBACKCOLOR(pw);
	
	if(error) return false;

return error;
}



function SendRegion(valor,tipo){
	CargaContenido('function/calcula.php?cmd=chregion&tipo='+tipo+'&valor='+valor,tipo)
}

var setcomuna;
function SendRegionOnchange(valor,tipo,onchange){
	if(!onchange) onchange = 'CHMAP()';
	if(setcomuna != '') ;
	
	CargaContenido('function/calcula.php?cmd=chregion&tipo='+tipo+'&valor='+valor+'&onchange='+onchange+'&setcomuna='+setcomuna,tipo)
}

function Encuestas(forms){
var retorno	= false;
var chosen	= ""

	var i;
	for (i in forms.myradio) {
		if (forms.myradio[i].checked) {
			chosen = forms.myradio[i].value;
		}
	}
	
	if (chosen == "") {
		retorno = false;
		status('FAIL','Debe selecionar almenos una respuesta');
	}
	else {
		document.getElementById('encuestas').action='calcula/post/encuestas.html'
	}
return retorno;
}

function registrarse(nw){
var retorno = true;

	nw.registro.disabled="true";

	if(nw.rut.value == ''){
		nw.rut.style.borderColor="#F00";
				retorno = false;
	} else  nw.rut.style.borderColor="#b2b2b2";
	
	var statusrut = Rut(nw.rut.value,setformrut);
	if(!statusrut) {
		retorno = statusrut
//		nw.rut.value="Su rut es incorrecto";
		nw.rut.style.borderColor="#b2b2b2";
	}

	if(nw.nombre.value == ''){
		nw.nombre.style.borderColor="#F00";
				retorno = false;
	} else  nw.nombre.style.borderColor="#b2b2b2";	
	
	if(nw.email.value == ''){
		nw.email.style.borderColor="#F00";
	} 
	else  nw.email.style.borderColor="#b2b2b2";	
	
	retorno = Emails(nw.email);
	
	if(nw.fono.value == ''){
		nw.fono.style.borderColor="#F00";
				retorno = false;
	} else  nw.fono.style.borderColor="#b2b2b2";
	
	if(nw.fono2.value == ''){
		nw.fono2.style.borderColor="#F00";
				retorno = false;
	} else  nw.fono2.style.borderColor="#b2b2b2";
	
	if(nw.clave.value == ''){
		nw.clave.style.borderColor="#F00";
				retorno = false;
	} else  nw.clave.style.borderColor="#b2b2b2";	
	
	if(nw.claveconfirma.value == ''){
		nw.claveconfirma.style.borderColor="#F00";
				retorno = false;
	} else  nw.claveconfirma.style.borderColor="#b2b2b2";	
	
	nw.registro.disabled="";
	
	if(retorno){
		nw.registro.disabled='';
		
	}
	
return retorno;
}

function enviarcarta(nw){
var retorno = true;

	nw.enviar_cartas.disabled="true";
	
	if(nw.nombre.value == ''){
		nw.nombre.style.borderColor="#F00";
				retorno = false;
	} else  nw.nombre.style.borderColor="#b2b2b2";	
	
	if(nw.titulo.value == ''){
		nw.titulo.style.borderColor="#F00";
				retorno = false;
	} else  nw.titulo.style.borderColor="#b2b2b2";	
	
	if(nw.texto.value == ''){
		nw.texto.style.borderColor="#F00";
				retorno = false;
	} else  nw.texto.style.borderColor="#b2b2b2";	
	
	
	nw.enviar_cartas.disabled="";
	
	if(retorno){
		nw.enviar_cartas.disabled='';
	}
	
return retorno;
}

function enviararchivo(nw){
var retorno = true;

	nw.enviar_archivo.disabled="true";
	
	if(nw.nombre.value == ''){
		nw.nombre.style.borderColor="#F00";
				retorno = false;
	} else  nw.nombre.style.borderColor="#b2b2b2";
	
	if(nw.email.value == ''){
		nw.email.style.borderColor="#F00";
	} 
	else  nw.email.style.borderColor="#b2b2b2";	
	
		retorno = Emails(nw.email);
		
	if(nw.tema.value == ''){
		nw.tema.style.borderColor="#F00";
				retorno = false;
	} else  nw.tema.style.borderColor="#b2b2b2"
	
	if(nw.texto.value == ''){
		nw.texto.style.borderColor="#F00";
				retorno = false;
	} else  nw.texto.style.borderColor="#b2b2b2";	
	
	nw.enviar_archivo.disabled="";

	if(retorno){
		nw.enviar_archivo.disabled='';
	}
	
return retorno;
}

function Recuperar_Clave(tipo){ 
	email = document.getElementById('emailrecupera').value;
	if(email != ''){
	clearTimeout(timeout);
	document.getElementById('restorethink').innerHTML='<img src="img/load.gif" border="0" />';		
	timeout = setTimeout("CargaContenido('function/calcula.php?cmd=restorepassword&email="+email+"&tipo="+tipo+"','restorethink');",500);

	setTimeout("restorelabel()",11000);
	}
}
function Ver_Mapa () {
// var left	= (screen.width  - width)/2;
// var top	 = (screen.height - height)/2;
var comuna = document.getElementById('comuna').value;
var address = document.getElementById('direccion').value;

var url = 'http://casas.newware.cl/maps/maps.php?address='+address+'&comuna='+comuna;
var opciones="toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, width=508, height=365, top=85, left=140";
window.open(url,"",opciones);

}

function ValidarProyecto(){

	var nombre				= new GetInfo('nombre');
	var salaventas			= new GetInfoByName('salaventas[]');
	
	var direccion			= new GetInfo('direccion');
	var latlng				= new GetInfo('latlng');
	var horarios			= new GetInfo('horarios');
	var telefonos			= new GetInfoByName('telefonos[]');
	var email				= new GetInfo('email');
	// var estado				= new GetInfo('estado');
	var fecha_entrega		= new GetInfo('fecha_entrega');
	var caracteristicas		= new GetInfo('caracteristicas');
	
	error = false;
	var retorno = false;
	
	error = nombre.CheckError(error);

	// error = salaventas.CheckError(error);
	for(var i = 0; i < salaventas.length; i++){
		error = salaventas[i].CheckError(error);
	}
	
	error = direccion.CheckError(error);
	error = latlng.CheckError(error);
	error = horarios.CheckError(error);

	// error = telefonos.CheckError(error);
	for(var i = 0; i < telefonos.length; i++){
		error = telefonos[i].CheckError(error);
	}

	error = email.CheckError(error);

	// error = estado.CheckError(error);

	error = fecha_entrega.CheckError(error);
	error = caracteristicas.CheckError(error);
	
	if(error){
		showerror_prop('Complete los campos resaltados');
		setTimeout("showerror('')",4600);
	 	retorno = false; 
	}else {
	
		retorno = true;
	}
	return retorno;
}

function logo(el){

	if(el.src==web+'/imagenes/logo_observador.jpg')
		el.src=web+'/imagenes/logo_observador_rojo.gif';
	else
		el.src=web+'/imagenes/logo_observador.jpg';
}

function login(status){
var retorno = true;

if(!status) status = 'login';

switch(status){
	
	case 'ingresar':
	
			$('login_ingreso').onsubmit = function() { 
					var retorno = true; if($('rut').value=='')	retorno=false; 
					if($('psd').value=='') retorno=false;
					if(!retorno)
						login('FAIL');					
					
					return retorno; 
					}

			$('rut').onfocus = function() { TextToggle(this.id)}
			$('rut').onblur = function() { TextToggle(this.id)}
			$('rut').onchange = function() { return Rut($('rut').value,setrut); }
			
			$('psd').onfocus = function() { TextToggle(this.id)}
			$('psd').onblur = function() { TextToggle(this.id)}

	if(screen.width < 1200){
			var izq = screen.width - 400;
			document.getElementById('login').style.left=izq+"px";
	}

		if($('olvido_contrasenha'))
			$('olvido_contrasenha').onclick= function() {
				
				if($('recoveryblock').style.visibility=='visible')
				$('recoveryblock').style.visibility='hidden';
				else  $('recoveryblock').style.visibility='visible'
				
			}
		if($('rutrvy')){
			$('rutrvy').onfocus		= function() { TextToggle(this.id)}
			$('rutrvy').onblur		= function() { TextToggle(this.id)}
			$('rutrvy').onchange	= function() { return Rut($('rutrvy').value,setrutrvy); }
		}
	
			$('login').style.display='block';
			$('ingresar').onclick = function(){ login('x'); } 
	
	break;
	
	case 'LOGIN':
		$('entrar').disabled="true";
	
		if($('rut').value == ''){
			$('rut').style.borderColor="#F00";
					retorno = false;
		} else  $('rut').style.borderColor="#b2b2b2";
		
		if($('psd').value == ''){
			$('psd').style.borderColor="#F00";
					retorno = false;
		} else  $('psd').style.borderColor="#b2b2b2";	
		
	
		$('entrar').disabled="";
		
		if(retorno){	
			return retorno;
		}
	
	break;
	
	
	case 'FAIL':
	
		$('psd').style.borderColor="#F00";
		$('rut').style.borderColor="#F00";
	
	break;
	
	case 'x':
	
	if($('login').style.display=='block')
		$('login').style.display='none';
	else  $('login').style.display='block'


	break;	
}
return retorno;
} // switch & function

function moregals(id){
	fade('imagenes');
		
	var ready = CargaAjax('get/imagenes.php?lemoine='+id+'&dl=ps','imagenes',1);
	setTimeout("fade('imagenes')",1500);

}

function morevideos(id){
	fade('videos');
		
	var ready = CargaAjax('get/Videos.php?vivi='+id,'videos',1);
	setTimeout("fade('videos')",1500);

}


function verVideo(id){
	fade('videos');
		
	var ready = CargaAjax('inc/verVideo.php?id='+id,'videos',1);
	setTimeout("fade('videos')",1000);

}

function moreblogs(){
	
}

function morediciones(id){
	fade('imgediciones',300);

	setTimeout("CargaAjax('get/Ediciones.php?nws="+id+"','imgediciones',0)",300);

	setTimeout("fade('imgediciones',300)",400);	
}

function moreclasificados(id){
if(!id) id = 1;

	setTimeout("CargaAjax('get/Clasificados.php?nws="+id+"','siderclasificados',0)",300);
	var next = id+1;

setTimeout("moreclasificados("+next+")",10555);
}

function sendComentario(e){
var retorno = true;

	e.enviar.disabled="true";

	if(e.nombre.value == ''){
		e.nombre.style.borderColor="#F00";
				retorno = false;
	} else  e.nombre.style.borderColor="#b2b2b2";	
	
	if(e.email.value == ''){
		e.email.style.borderColor="#F00";
	} 
	else  e.email.style.borderColor="#b2b2b2";	
	
	retorno = Emails(e.email);
	
	if(e.mensaje.value == ''){
		e.mensaje.style.borderColor="#F00";
				retorno = false;
	} else  e.mensaje.style.borderColor="#b2b2b2";	
	
	e.enviar.disabled="";
	
	if(retorno){
		e.enviar.disabled="true";
		setTimeout("CargaAjax('get/comentarios.php?nw="+e.art.value+"','comentarios-comentarios',1)",500);
		fade('comentarios-comment');
	}
	
return retorno;
}

var start = false;
var galnext = 25;
var gallast = 0;
var GalTime;
function imgNext(galimgs,commands){

if(!start)	gallast = -1*(25*galimgs-25);		
if(!commands) commands = false;
else clearTimeout(GalTime);

	if(commands == 'next'){
		galnext -=25;
	}
	else if(commands == 'last'){
		if(galnext == 0){
			galnext -=(galimgs)*25-25;
		}else
		   	galnext +=25;
	}	
	else galnext -=25;

	fade('gallery');

	setTimeout("$('gallery').style.marginLeft='"+galnext+"em'",1100);
		
	setTimeout("fade('gallery')",1200);

	if(gallast == galnext)
		galnext =25;

	
	GalTime = setTimeout("imgNext("+galimgs+")",10000);
}

function FadenBlock(id){
	fade(id);
}
