<!--
//script by http://www.yvoschaap.com

//XMLHttpRequest class function

var xmlhttp=false;
var xmlhttpocupado=false;
function datosServidor() {
};
datosServidor.prototype.iniciar = function() {
	try {
		// Mozilla / Safari
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		// Explorer
		var _ieModelos = new Array(
		'MSXML2.XMLHTTP.5.0',
		'MSXML2.XMLHTTP.4.0',
		'MSXML2.XMLHTTP.3.0',
		'MSXML2.XMLHTTP',
		'Microsoft.XMLHTTP'
		);
		var success = false;
		for (var i=0;i < _ieModelos.length && !success; i++) {
			try {
				xmlhttp = new ActiveXObject(_ieModelos[i]);
				success = true;
			} catch (e) {
			}
		}
		if ( !success ) {
			return false;
		}
		return true;
	}
}

datosServidor.prototype.ocupado = function() {
	estadoActual = xmlhttp.readyState;
	return (estadoActual && (estadoActual < 4));
}

datosServidor.prototype.procesa = function() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		this.procesado = true;
	}
}

datosServidor.prototype.enviar = function(urlget,datos) {
	if (!xmlhttp) {
		this.iniciar();
	}
	if (!this.ocupado()) {
		xmlhttp.open("GET",urlget,false);
		xmlhttp.send(datos);
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			return xmlhttp.responseText;
		}
		
	}
	return false;
}
datosServidor.prototype.enviarpost = function(urlget,datos,elem,mostrar) {
	if (!xmlhttp) {
		this.iniciar();
	}
	if (!this.ocupado()) {
		xmlhttpocupado = true;
		elem.innerHTML = '<img src="/img/ajax-loader.gif" width="15" />';   
		xmlhttp.open("POST",urlget,true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", datos.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				elem.innerHTML = mostrar;
				xmlhttpocupado = false;
				return xmlhttp.responseText;
			}
		}
		xmlhttp.send(datos);
	}
}


var urlBase = "/js/update.php";
var formVars = "";
var changing = false;


function fieldEnter(campo,evt,idfld) {
	evt = (evt) ? evt : window.event;
	if (evt.keyCode == 13 && campo.value!="") {
		elem = document.getElementById( idfld );
		remotos = new datosServidor;

		var text = "";

		
		

		//remove glow
//		noLight(elem);
	
		
		//poner controles
		var valor = campo.value; 
		valor = returnhtml(valor);
		valor = control(elem,valor);

		if(document.getElementById( campo.id ).selectedIndex != null)
		{
			var ss = document.getElementById( campo.id ).selectedIndex;
			var tipo = elem.id.split('%');
			if(tipo[0] == "venta" && valor == 0)
				text = returnhtml(document.getElementById(campo.id).options[1].text);
			else
				text = returnhtml(document.getElementById(campo.id).options[ss].text);
		}

		nt = remotos.enviar(urlBase + "?fieldname=" +encodeURI(elem.name)+ "&content="+encodeURI(valor)+ "&text="+text);
		elem.innerHTML = nt;

		sendajax(elem,valor);

		changing = false;
		return false;
	} else {
		return true;
	}
}

function fieldBlur(campo,idfld) {
	if (campo.value!="") {
		elem = document.getElementById( idfld );
		remotos = new datosServidor;


		var text = "";


		//poner controles
		var valor = campo.value; 
		valor = returnhtml(valor);
		valor = control(elem,valor);


		if(document.getElementById( campo.id ).selectedIndex != null)
		{
			var ss = document.getElementById( campo.id ).selectedIndex;
			var tipo = elem.id.split('%');
			if(tipo[0] == "venta" && valor == 0)
				text = returnhtml(document.getElementById(campo.id).options[1].text);
			else
				text = returnhtml(document.getElementById(campo.id).options[ss].text);
		}

		nt = remotos.enviar(urlBase + "?fieldname=" +encodeURI(elem.name)+ "&content="+encodeURI(valor)+ "&text="+text);
		elem.innerHTML = nt;

		sendajax(elem,valor);
	
	
		changing = false;
		return false;
	}
}
function control(elem,valor)
{
	var temp = elem.id.split('%');
	type = temp[0];
	id = temp[1];
	var vret = valor;

	switch(type)
	{
		case "venta":
			valor = (valor == "Si" ? "1" : "0");
			var com = document.getElementById('comisiones').value;
			var precio = document.getElementById('precio%'+id);
			var pos = precio.innerHTML.indexOf('$');
			if(pos != -1)
			{
				var mySplitResult = precio.innerHTML.split("U$D");
				precio = mySplitResult[1].trim();	
				precio = replaceAll(precio,',','');
			}
			if(datos == 0)
			{
				jQuery.facebox({ajax:'/dominios/completar_datos/'});
				vret = 0;				
			}
			else if(precio < 300 && valor == 1 && com == 0)
			{
				jQuery.facebox({ajax:'/dominios/comision_minima/'});
			}
			
			if(precio == 0 && valor == 1) 
			{
				vret = 0;				
			}
			

			break;
		case "precio":
			if(valor < 50)
			{
				vret = 0;
				jQuery.facebox({ajax:'/dominios/precio_minimo/'});
			}
			break;
	}
	return vret;
}
function sendajax(elem,valor)
{
		var temp = elem.id.split('%');
		type = temp[0];
		id = temp[1];
		var destino = "";
		var param = "";
		var mostrar = elem.innerHTML;
		switch(type)
		{
			case "venta":
				valor = (valor == "Si" ? "1" : "0");
				destino = "alaventa";
				param = 'param='+id+"-"+valor;
				break;
			case "park":
				valor = (valor == "Si" ? "1" : "0");
				destino = "setparking";
				param = 'param='+id+"-"+valor;
				break;
			case "lang":
				destino = "setlang";
				param = 'param='+id+"-"+valor;
				break;
			case "precio":
				destino = "setprice";
				param = 'param='+id+"-"+valor;
				break;
			case "comercial_funcionesadmin":
				destino = type;
				param = 'id='+id+'&type='+temp[2]+'&valor='+valor;
				break;
			case "comercial_sino":
				valor = (valor == "Si" ? "1" : "0");
				if(valor == 1)
				{
					document.getElementById('str'+temp[2]+"%"+id).className="contiene";
					document.getElementById('2str'+temp[2]+"%"+id).style.display="block";
				}
				else
				{
					document.getElementById('str'+temp[2]+"%"+id).className="nocontiene";
					document.getElementById('2str'+temp[2]+"%"+id).style.display="none";
				}
				destino = type;
				param = 'id='+id+"&type="+temp[2]+"&valor="+valor;
				break;
			case "comercial_estado":
				destino = "comercial_estado";
				valor = (valor == "Activo" ? "1" : "0");
				param = 'param='+id+"-"+valor;
				if(valor == 1)
					document.getElementById('estado_web').className = "activo";
				else
					document.getElementById('estado_web').className = "inactivo";
				break;
			case "proy":
				valor = (valor == "Si" ? "1" : "0");
				destino = "setproject";
				param = 'param='+id+"-"+valor;
				break;
			case "web":
				valor = (valor == "Si" ? "1" : "0");
				if(document.URL.indexOf("/micuenta/dominios/") == -1 && document.getElementById('tabber') != null)
				{
					showhidetabber(valor);
				}
				else
				{
					var web = document.getElementById('a_sitioweb').value;
					if(valor == 1 && web == 0)
						jQuery.facebox({ajax:'/dominios/web_comercial/'+id});
				}
				destino = "setwebsite";
				param = 'param='+id+"-"+valor;
				break;
			case "texto":
				destino = "editar_texto";
				param = 'id='+id+'&valor='+valor;
				break;
			
			case "link":
				var pos = valor.indexOf("*E*");
				if(pos != -1)
				{
					var mySplitResult = valor.split("*E*");
					valor = mySplitResult[0].trim();	
				}
				destino = "editar_texto";
				param = 'id='+elem.id+'&valor='+valor;
				break;
		}
	remotos = new datosServidor;
	remotos.enviarpost("/micuenta/"+destino+"/",param,elem,mostrar);

	return valor;
}


//edit field created
function editBox(actual,type) {
	//alert(actual.nodeName+' '+changing);
	if(xmlhttpocupado == true)
		return;
	if(!changing){
		width = widthEl(actual.id) + 20;
		height =heightEl(actual.id) + 2;
		if(height < 20 && type < 10 && type != 2){
			if(width < 60)	width = 60;
			if(type == 2 && width < 480) width = 450;
				switch(type)
				{
					case 0:
						var temp = actual.innerHTML;
						/*var pos = temp.indexOf('U$D');
						if(pos != -1)
						{
							var mySplitResult = temp.split("U$D");
							temp = mySplitResult[1].trim();	
						}
						temp = replaceAll(temp,',','');
						*/
						temp = replaceAll(temp,',','');
						actual.innerHTML = "<input id=\""+ actual.id +"_field\" style=\"width: "+width+"px; height: "+height+"px; font-family: tahoma; font-size: 10px;\" maxlength=\"254\" type=\"text\" value=\"" + temp + "\" onkeypress=\"return fieldEnter(this,event,'" + actual.id + "')\" onfocus=\"highLight(this);\" onblur=\"noLight(this); return fieldBlur(this,'" + actual.id + "');\" />";
						break;
					case 2:
						actual.innerHTML = "<input id=\""+ actual.id +"_field\" style=\"width: "+width+"px; height: "+height+"px; font-family: tahoma; font-size: 10px;\" maxlength=\"254\" type=\"text\" value=\"" + actual.innerHTML + "\" onkeypress=\"return fieldEnter(this,event,'" + actual.id + "')\" onfocus=\"highLight(this);\" onblur=\"noLight(this); return fieldBlur(this,'" + actual.id + "');\" />";
						break;
					case 1:
						var temp = actual.innerHTML;
						actual.innerHTML = "<select id=\""+ actual.id +"_field\" style=\"width: 38px; height: 20px;\" maxlength=\"254\" onkeypress=\"return fieldEnter(this,event,'" + actual.id + "')\" onfocus=\"highLight(this);\" onblur=\"noLight(this); return fieldBlur(this,'" + actual.id + "');\"><option value=\"Si\">"+textsi+"</option><option value=\"No\">"+textno+"</option></select>";
						break;
					case 4:
						var temp = actual.innerHTML;
						actual.innerHTML = "<select id=\""+ actual.id +"_field\" style=\"width: 60px; height: 20px;\" maxlength=\"254\" onkeypress=\"return fieldEnter(this,event,'" + actual.id + "')\" onfocus=\"highLight(this);\" onblur=\"noLight(this); return fieldBlur(this,'" + actual.id + "');\"><option value=\"Activo\">Activo</option><option value=\"Inactivo\">Inactivo</option></select>";
						break;
					case 3:
						var langs = document.getElementById('langs').value;
					
						langs = replaceAll(langs,']','');
						var lista = new Array();
						lista = langs.split('[');
						var select = "";
						var temp = Array();
						for(var i = 1; i < lista.length ; i ++)
						{
							temp = lista[i].split(';');
							select += "<option value='"+temp[0]+"' >"+temp[1]+"</option>";
						}
						actual.innerHTML = "<select id=\""+ actual.id +"_field\" style=\"width: 68px; height: 20px;\" maxlength=\"254\" onkeypress=\"return fieldEnter(this,event,'" + actual.id + "')\" onfocus=\"highLight(this);\" onblur=\"noLight(this); return fieldBlur(this,'" + actual.id + "');\">"+select+"</select>";
						break;
				}
				//alert(actual.innerHTML);
		}else{
			if(width < 70) width = 90;
			if(height < 50) height = 50;
			
			if(type == 2) width = 440;

			actual.innerHTML = "<textarea name=\"textarea\" id=\""+ actual.id +"_field\" style=\"width: "+width+"px; height: "+height+"px; font-family: tahoma; font-size: 10px;\" onfocus=\"highLight(this);\" onblur=\"noLight(this); return fieldBlur(this,'" + actual.id + "');\">" + actual.innerHTML + "</textarea>";
		}
		changing = true;
	}

		actual.firstChild.focus();
}



//find all span tags with class editText and id as fieldname parsed to update script. add onclick function
function editbox_init(){
	if (!document.getElementsByTagName){ return; }
	var spans = document.getElementsByTagName("span");

	// loop through all span tags
	for (var i=0; i<spans.length; i++){
		var spn = spans[i];

        	if (((' '+spn.className+' ').indexOf("editText") != -1) && (spn.id)) {
			var id = spn.id;
			var pos = id.indexOf('%');
			if(pos != -1)
			{
				var mySplitResult = id.split("%");
				id = mySplitResult[0].trim();	
			}
			switch(id)
			{
				case "link":
					spn.onclick = function () { editBox(this,10); }
					break;
				case "lang":
					spn.onclick = function () { editBox(this,3); }
					break;
				case "texto":
				case "comercial_funcionesadmin":
					spn.onclick = function () { editBox(this,2); }
					break;
				
				case "precio":
					spn.onclick = function () { editBox(this,0); }
					break;
				case "comercial_estado":
					spn.onclick = function () { editBox(this,4); }
					break;
				case "comercial_sino":
				case "venta":
				case "park":
				case "proy":
				case "web":
					spn.onclick = function () { editBox(this,1); }
					break;
			}
			spn.style.cursor = "pointer";
			spn.title = clicedit;	
       		}

	}


}

//crossbrowser load function
function addEvent(elm, evType, fn, useCapture)
{
  if (elm.addEventListener){
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent){
    var r = elm.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Please upgrade your browser to use full functionality on this page");
  }
}

//get width of text element
function widthEl(span){

	if (document.layers){
	  w=document.layers[span].clip.width;
	} else if (document.all && !document.getElementById){
	  w=document.all[span].offsetWidth;
	} else if(document.getElementById){
	  w=document.getElementById(span).offsetWidth;
	}
return w;
}

//get height of text element
function heightEl(span){

	if (document.layers){
	  h=document.layers[span].clip.height;
	} else if (document.all && !document.getElementById){
	  h=document.all[span].offsetHeight;
	} else if(document.getElementById){
	  h=document.getElementById(span).offsetHeight;
	}
return h;
}

function highLight(span){
            //span.parentNode.style.border = "2px solid #D1FDCD";
            //span.parentNode.style.padding = "0";
            span.style.border = "1px solid #ccc";          
}

function noLight(span){
        //span.parentNode.style.border = "0px";
        //span.parentNode.style.padding = "2px";
        span.style.border = "0px";   


}

//sets post/get vars for update
function setVarsForm(vars){
	formVars  = vars;
}
function returnhtml(texto){
	texto = replaceAll(texto,'\u00E1','&aacute;');
	texto = replaceAll(texto,'\u00E9','&eacute;');
	texto = replaceAll(texto,'\u00ED','&iacute;');
	texto = replaceAll(texto,'\u00F3','&oacute;');
	texto = replaceAll(texto,'\u00FA','&uacute;');
	texto = replaceAll(texto,'\u00C1','&Aacute;');
	texto = replaceAll(texto,'\u00C9','&Eacute;');
	texto = replaceAll(texto,'\u00CD','&Iacute;');
	texto = replaceAll(texto,'\u00D3','&Oacute;');
	texto = replaceAll(texto,'\u00DA','&Uacute;');
	texto = replaceAll(texto,'\u00FC','&uuml;');
	texto = replaceAll(texto,'\u00DC','&Uuml;');
	texto = replaceAll(texto,'\u00F1','&ntilde;');
	texto = replaceAll(texto,'\u00D1','&Ntilde;');
	texto = replaceAll(texto,'\u2022','&#8226;');
	texto = replaceAll(texto,'\u00BF','&#191;');
	texto = replaceAll(texto,'\u00BB','&#187;');
	texto = replaceAll(texto,'\u00BA','&#186;');
	texto = replaceAll(texto,'\u00E2','&acirc;');
	texto = replaceAll(texto,'\u00EA','&ecirc;');
	texto = replaceAll(texto,'\u00EE','&icirc;');
	texto = replaceAll(texto,'\u00F4','&ocirc;');
	texto = replaceAll(texto,'\u00FB','&ucirc;');
	texto = replaceAll(texto,'\u00C2','&acirc;');
	texto = replaceAll(texto,'\u00CA','&ecirc;');
	texto = replaceAll(texto,'\u00CE','&icirc;');
	texto = replaceAll(texto,'\u00D4','&ocirc;');
	texto = replaceAll(texto,'\u00DB','&ucirc;');
	texto = replaceAll(texto,'\u00E7','&ccedil;');
	texto = replaceAll(texto,'\u00C7','&Ccedil;');
	texto = replaceAll(texto,'\u00E3','&atilde;');


	texto = replaceAll(texto,'&','*bur1*');
	texto = replaceAll(texto,'%','*bur2*');

	return texto;
}

function replaceAll(OldString,FindString,ReplaceString) {
  	var SearchIndex = 0;
  	var NewString = ""; 
  	while (OldString.indexOf(FindString,SearchIndex) != -1)    {
    	NewString += OldString.substring(SearchIndex,OldString.indexOf(FindString,SearchIndex));
    	NewString += ReplaceString;
    	SearchIndex = (OldString.indexOf(FindString,SearchIndex) + FindString.length);         
 	}
	
  	NewString += OldString.substring(SearchIndex,OldString.length);
  	return NewString;
}

addEvent(window, "load", editbox_init);
-->