/**
 * 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 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('enviar');
	
	/* 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
