var cargadoEditor = false;
var noCargarTituloSite = false
var indArray = 0
function Browser(){
	this.dom = document.getElementById?1:0;
	this.ie4 = (document.all && !this.dom)?1:0;
	this.ns4 = (document.layers && !this.dom)?1:0;
	this.ns6 = (this.dom && !document.all)?1:0;
	this.ie5 = (this.dom && document.all)?1:0;
	this.ok = this.dom || this.ie4 || this.ie5;
	this.platform = navigator.platform;
}
var browser = new Browser();

function popup(pag, nombre, parametros){
	var ven = window.open(pag,nombre,parametros)
	ven.focus();
}

function ventana(url,targe,ancho,alto) {
	var ven
	posh=(Math.round(screen.height-(alto))/2)//centra la ventana a lo alto
	posv=(Math.round(screen.width-(ancho))/2)//centra a lo ancho

	if (ven && !ven.closed){ven.close();}
	ven = window.open(url,targe,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=" + ancho + "px,height=" + alto + "px,left=" + posv + ",top=" + posh + ",resizable=no");

	ven.focus()
}

function LTrim(str){
	var whitespace = new String(" \t\n\r");

	var s = new String(str);

	if (whitespace.indexOf(s.charAt(0)) != -1) {
		var j=0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			j++;
		s = s.substring(j, i);
	}
	return s;
}


function RTrim(str){
	var whitespace = new String(" \t\n\r");

	var s = new String(str);

	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		var i = s.length - 1;
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
			i--;
		s = s.substring(0, i+1);
	}

	return s;
}

function Trim(str){
	return RTrim(LTrim(str));
}

function isArray(obj){
	return(typeof(obj.length)=="undefined")?false:true;
}

function txtBlanco(elemento, msg){
	valor = Trim(elemento.value);
	if(valor==""){
		alert(msg);
		if(elemento.type!="hidden")
			elemento.focus();
		return false;
	}
	elemento = valor;
	return true;
}

function validacbo (elemento, msg){
	valor = elemento.selectedIndex;
	if(valor==-1){
		alert(msg);
		elemento.focus();
		return false;
	}
	return true;
}

function validacboBlanco (elemento, msg){
	valor = elemento.options[elemento.selectedIndex].value;
	if(valor==""){
		alert(msg);
		elemento.focus();
		return false;
	}
	return true;
}

function replaceStr(str, strBuscar, strSustituir){
	var regExpresion = new RegExp(strBuscar, 'gi');
	return str.replace(regExpresion,strSustituir)
}

function validaMoneda(elemento, msg){
	elemento.value = replaceStr(elemento.value, ",", ".")
	valor = Trim(elemento.value);
	if(valor != "" && isNaN(valor)){
		alert(msg);
		elemento.focus();
		return false;
	}
	return true;
}

function validaNumero(elemento, msg){
	valor = Trim(elemento.value);
	if(valor != "" && isNaN(valor)){
		alert(msg);
		elemento.focus();
		return false;
	}
	return true;
}

function posimgY(obj){
	if(browser.ie4 || browser.ie5 || browser.dom) return wipeGetOffset(obj,"Top");
	if(browser.ns4) return obj.y;
}

function posimgX(obj){
	if(browser.ie4 || browser.ie5 || browser.dom) return wipeGetOffset(obj,"Left");
	if(browser.ns4) return obj.x;
}

function wipeGetOffset(obj, coord) {
	var val = obj["offset"+coord] ;
	while ((obj = obj.offsetParent )!=null) {
		val += obj["offset"+coord];
		if (obj.border && obj.border != 0) val++;
	}
	return val;
}

function div(nombre, imgRef){
	if (browser.ns4){
		var tmpLayer = new Layer(127);
	}
	if (browser.dom || browser.ie4){
		var tmpLayer = browser.dom?document.getElementById(nombre):document.all(nombre);
	}
	if(isObject(tmpLayer))
		this.existe = true;
	else
		this.existe = false;
	if(imgRef != ""){
		objRef = document.images[imgRef];
		this.xRef = posimgX(objRef);
		this.yRef = posimgY(objRef);
	}else{
		this.xRef = 0;
		this.yRef = 0;
	}
	this.containerLayer = tmpLayer;
	this.desplazaX = desplazaX;
	this.desplazaY = desplazaY;
	this.escribeDiv = escribeDiv;
	this.visible = visible;
	this.display = display;
	this.muestraContenido = contenido;
}

function contenido(){
	if (browser.ie4 || browser.dom)
		return this.containerLayer.innerHTML
}

function visible(valor){
	if (browser.ie4 || browser.dom){
		divmenu = this.containerLayer.style
		switch(valor){
			case 0:
				nuevo_estado = "hidden";
				break;
			case 1:
				nuevo_estado = "visible";
		}
	}else{
		if (browser.ns4){
 			divmenu = this.containerLayer;
 			switch(valor){
		 		case 0:
		 			nuevo_estado = "hide";
		 			break;
		 		case 1:
		 			nuevo_estado = "show";
			}
		}
	}

	divmenu.visibility = nuevo_estado
}

function display(valor){
	if (browser.ie4 || browser.dom){
		divmenu = this.containerLayer.style
		switch(valor){
			case 0:
				nuevo_estado = "none";
				break;
			case 1:
				nuevo_estado = "block";
		}
		divmenu.display = nuevo_estado
	}
}

function escribeDiv(str){
	if (browser.ie4)
		this.containerLayer.innerHTML = str;
	else
		if (browser.dom)
			this.containerLayer.innerHTML = str;
		else
			if(browser.ns4){
				this.containerLayer.document.open();
				this.containerLayer.document.write(str);
				this.containerLayer.document.close();
			}
}

function desplazaX(x){
	if (browser.dom || browser.ie4)
		this.containerLayer.style.left = x + "px";
	if(browser.ns4)
		this.containerLayer.left = x;
}

function desplazaY(y){
	if (browser.dom || browser.ie4)
		this.containerLayer.style.top = y + "px";
	if(browser.ns4)
		this.containerLayer.top = y;
}

function isObject(a){
	return (typeof a == 'object' && !!a) || isFunction(a);
}

function isFunction(a) {
	return typeof a == 'function';
}


var indFavoritos = 0
var indFavoritosSel = 0
function favItem(ind, total){			
	indFavoritos += ind;
	if(indFavoritos<0) indFavoritos = total - 1
	if(indFavoritos>=total) indFavoritos = 0		
	var favorito = new div("favItem" + indFavoritos, "")
	favorito.display(1)
	var favoritoImg = new div("favItemImg" + indFavoritos, "")
	if(favoritoImg.existe)
		favoritoImg.display(1)
	favorito = new div("favItem" + indFavoritosSel, "")
	if(total > 1){
		favorito.display(0)
		favoritoImg = new div("favItemImg" + indFavoritosSel, "")
		if(favoritoImg.existe)
			favoritoImg.display(0)
	}
	indFavoritosSel = indFavoritos
}

function verImg(ind){
	indFavoritos += ind;
	if(indFavoritos<0){
		indFavoritos = arrayImgGaleria.length - 1
	}else
		if(indFavoritos >= arrayImgGaleria.length){
			indFavoritos = 0
		}
	document.images['imgGal'].src = arrayImgGaleria[indFavoritos];
}

function verImgDirecto(ind){
	indFavoritos = ind;
	document.images['imgGal'].src = "p_Thumbnails.php?ruta="+arrayImgGaleria[indFavoritos]+"&ancho=400&alto=300";
}

function validaCheckAct(checks){
	var frm = document.forms["frm"]
	bError = true

	if(bError){
		for(ind=0;ind<frm[checks].length;ind++){
			if(frm[checks][ind].checked){
				bError = false
				break
			}
		}
	}

	return bError
}



function validar_envio()
{
	 nmovil = document.form1.receiver.value;
	 function trim(s) 
	 { 
	   return s;
	 } 
	 nmovil = trim(nmovil);
	 texto = "";
	 if(document.form1.receiver.value=="")
	 { 
	  	 texto = texto + "\n" + "- Debe introducir un numero de movil"; 		 
	 }	
	 else
	 { 
		if(nmovil.length < 9)
		{ 
			texto = texto + "\n" + "- El numero de movil debe tener 9 cifras"; 
		} 
		else
		{
			if (isNaN(nmovil))
			{ 
				texto = texto + "\n" + "- Movil incorrecto, introduzca solo numeros";
			} 
			else
			{ 
				if(nmovil.substr(0,1)!= '6')
				{
					texto = texto + "\n" + "- Movil incorrecto, el numero de movil debe empezar por 6";
				}
				else
				{
					if(document.form1.text.value == '')
					{
						texto = texto + "\n" + "- Introduzca el texto del mensaje";
					}
				}
			}
		}
	} 
	if (texto != "")
	{
	 	alert(texto);
	}
	else
	{		  
		enviaSmsGratis(document.forms['form1'].phone.value,document.forms['form1'].ps.value,document.forms['form1'].receiver.value,document.forms['form1'].text.value);
	}
}




// A G E N D A
function Send_new_contact(msisdn,nombre,apellido,numero,pag){
//	alert('Session: '+msisdn+' Nombre: '+nombre+' Ape: '+apellido+' Num: '+numero);
	if (confirm('Desea agregar este contacto nuevo?')) 
	{
   		ajaxManager("update","/mware/add_contact.php?msisdn="+msisdn+"&name="+nombre+"&surname="+apellido+"&phonenumber="+numero+"&pag="+pag,'divcontact');
 	}
}