/**
 * Reemplazar TAGS por IMG
 * (c) 2009 Asesoramiento Pymesweb, S.L.
 * Por Alejandro Arco <http://www.alejandroarco.es>
 */
replaceTAGSbyIMG=function() {
	var url = '/img/sec/comunes/';	
	var ext = '.gif';
	
	if(!document.getElementsByTagName) { return null; }
	
	/* H2 */
	var anchors = document.getElementsByTagName('h2');
	for(var i=0;i<anchors.length;i++) {
		var anchor = anchors[i];
		var img = '<img src="'+ url +'h2/'+ anchor.getAttribute('id') + ext +'" alt="'+ anchor.getAttribute('title') +'" />';
		
		replaceHTML(anchor, img);
	}
	
	/* H3 */
	var anchors = document.getElementsByTagName('h3');
	for(var i=0;i<anchors.length;i++) {
		var anchor = anchors[i];
		var img = '<img src="'+ url +'h3/'+ anchor.getAttribute('id') + ext +'" alt="'+ anchor.getAttribute('title') +'" />';
		
		replaceHTML(anchor, img);
	}	
	
	/* STRONG */
	var anchors = document.getElementsByTagName('strong');
	for(var i=0;i<anchors.length;i++) {
		var anchor = anchors[i];
		
		if(anchor.getAttribute('id')) {
			var img = '<img src="'+ url +'strong/'+ anchor.getAttribute('id') + ext +'" alt="'+ anchor.getAttribute('title') +'" />';

			replaceHTML(anchor, img);
		}
	}	
}

if(document.all&&window.attachEvent) { window.attachEvent("onload",replaceTAGSbyIMG); } // IE-Win
else if(window.addEventListener) { window.addEventListener("load",replaceTAGSbyIMG,false); } // Otros

/**
 * Enlaces Externos Accesibles
 * (c) 2009 Asesoramiento Pymesweb, S.L.
 * Por Alejandro Arco <http://www.alejandroarco.es>
 */
setExternalLinks=function() {
	if(!document.getElementsByTagName) { return null; }
	
	var anchors = document.getElementsByTagName('a');
	for(var i=0;i<anchors.length;i++) {
		var anchor = anchors[i];
		if(anchor.getAttribute('href') && ((anchor.getAttribute('href').substr(0,7)=='http://' && anchor.getAttribute('href').lastIndexOf(document.domain)==-1) || anchor.getAttribute('class')=='external')) { anchor.setAttribute('target','_blank'); }
	}
}

if(document.all&&window.attachEvent) { window.attachEvent("onload",setExternalLinks); } // IE-Win
else if(window.addEventListener) { window.addEventListener("load",setExternalLinks,false); } // Otros

/**
 * Validar Buscador
 * (c) 2009 Asesoramiento Pymesweb, S.L.
 * Por Alejandro Arco <http://www.alejandroarco.es>
 */
validateSearch=function() {
	if(!document.frm_src) { return null; }
	
	var q = new Array(document.getElementById('q'), document.frm_src['q'].value);
	var enviar = document.getElementById('sa');
	
	/* Eventos */
	q[0].onfocus = onFocus; q[0].onblur = onBlur;
	enviar.onclick = validateForm;
	
	/* Funciones */
	function onFocus() { if(document.frm_src[this.name].value==eval(this.name)[1]) document.frm_src[this.name].value='' }	
	
	function onBlur() {
		var value = document.frm_src[this.name].value;
		value = value.replace(/^\s*/, ''); value = value.replace(/\s*$/, '');
		if(!value) document.frm_src[this.name].value = eval(this.name)[1]
	}
	
	function validateForm() {
		if(document.frm_src['q'].value==q[1]) { viewError(document.frm_src['q']); return false; }
		document.frm_src.target = '_blank';
		return true;
	}
	
	function viewError(el) {
		el.focus();
		alert('Introduzca una cadena de busqueda.');
	}	
}

if(document.all&&window.attachEvent) { window.attachEvent("onload",validateSearch); } // IE-Win
else if(window.addEventListener) { window.addEventListener("load",validateSearch,false); } // Otros

/**
 * Validar Contacto
 * (c) 2009 Asesoramiento Pymesweb, S.L.
 * Por Alejandro Arco <http://www.alejandroarco.es>
 */
validateContact=function() {
	if(!document.frm_con) { return null; }
	
	var nombre = new Array(document.getElementById('nombre'), document.frm_con['nombre'].value);
	var email = new Array(document.getElementById('email'), document.frm_con['email'].value);
	var telefono = new Array(document.getElementById('telefono'), document.frm_con['telefono'].value);
	var mensaje = new Array(document.getElementById('mensaje'), document.frm_con['mensaje'].value);	
	var enviar = document.getElementById('submit');
	
	/* Eventos */
	nombre[0].onfocus = onFocus; nombre[0].onblur = onBlur;
	email[0].onfocus = onFocus; email[0].onblur = onBlur;
	telefono[0].onfocus = onFocus; telefono[0].onblur = onBlur;
	mensaje[0].onfocus = onFocus; mensaje[0].onblur = onBlur;	
	enviar.onclick = validateForm;
	
	/* Funciones */
	function onFocus() { if(document.frm_con[this.name].value==eval(this.name)[1]) document.frm_con[this.name].value='' }	
	
	function onBlur() {
		var value = document.frm_con[this.name].value;
		value = value.replace(/^\s*/, ''); value = value.replace(/\s*$/, '');
		if(!value) document.frm_con[this.name].value = eval(this.name)[1]
	}
	
	function validateForm() {
		if(document.frm_con['nombre'].value==nombre[1]) { viewError(document.frm_con['nombre']); return false; }
		else if(document.frm_con['email'].value==email[1]) { viewError(document.frm_con['email']); return false; }
		else if(document.frm_con['telefono'].value==telefono[1]) { viewError(document.frm_con['telefono']); return false; }
		else if(document.frm_con['mensaje'].value==mensaje[1]) { viewError(document.frm_con['mensaje']); return false; }
		return true;
	}
	
	function viewError(el) {
		el.focus();
		alert('El campo "'+ el.name +'" es obligatorio.');
	}
}

if(document.all&&window.attachEvent) { window.attachEvent("onload",validateContact); } // IE-Win
else if(window.addEventListener) { window.addEventListener("load",validateContact,false); } // Otros

/**
 * Buscador GSearch
 * (c) 2009 Asesoramiento Pymesweb, S.L.
 * Por Alejandro Arco <http://www.alejandroarco.es>
 */
setGSearch=function() {
	new CSEOverlay('001658335411010420783:bs2qwxjpo80', document.getElementById('frm_src'), document.getElementById('res_src'));
}

if(document.all&&window.attachEvent) { window.attachEvent("onload",setGSearch); } // IE-Win
else if(window.addEventListener) { window.addEventListener("load",setGSearch,false); } // Otros

/**
 * Reemplazar HTML
 */
function replaceHTML(el, html) {
	var oldEl = (typeof el === "string" ? document.getElementById(el) : el);
	/*@cc_on
	oldEl.innerHTML = html;
	return oldEl;
	@*/
	var newEl = oldEl.cloneNode(false);
	newEl.innerHTML = html;
	oldEl.parentNode.replaceChild(newEl, oldEl);
	return newEl;
};
