var txCargando='Cargando...';
function cargaNoticia(id)
{
	document.getElementById('recNot').innerHTML="<table width='100%' height='100%' class='df'><tr><td align='center'><img src='img/loading.gif' align='absmiddle'/>&nbsp;&nbsp;&nbsp;&nbsp;"+txCargando+"</td></tr></table>";
	K_loadAJAX('cargaNoticia.php?id='+id,'finCargaNoticia');
}

function finCargaNoticia(xmldoc)
{
	document.getElementById('recNot').innerHTML=xmldoc.getElementsByTagName('datos')[0].firstChild.data;
}

function cargaGaleria(id)
{
	document.getElementById('contFotoGal').innerHTML="<table width='100%' height='100%' class='df'><tr><td align='center'><img src='img/loading.gif' align='absmiddle'/>&nbsp;&nbsp;&nbsp;&nbsp;"+txCargando+"</td></tr></table>";
	document.getElementById('contTxtGal').innerHTML="<table width='100%' height='100%' class='df'><tr><td align='center'><img src='img/loading.gif' align='absmiddle'/>&nbsp;&nbsp;&nbsp;&nbsp;"+txCargando+"</td></tr></table>";
	K_loadAJAX('cargaGaleria.php?id='+id,'finCargaGaleria');
}

function finCargaGaleria(xmlDoc)
{
	var cad="<img src='"+xmlDoc.getElementsByTagName('img')[0].getAttribute('src')+"'/>";
	document.getElementById('contFotoGal').innerHTML=cad;
	var cat=xmlDoc.getElementsByTagName('cat')[0].firstChild.data;
	var mod=xmlDoc.getElementsByTagName('mod')[0].firstChild.data;
	var desc=xmlDoc.getElementsByTagName('desc')[0].firstChild.data;
	var cad="<div style='font-family:\"Arial Black\";color:#6A8BB4;font-size:15px;'>"+cat+"</div>";
	cad+="<div style='margin-top:6px;font-family:\"Arial Black\";color:#646466;font-size:13px;'>"+mod+"</div><br /><div class='df'>"+desc+"</div>";
	document.getElementById('contTxtGal').innerHTML=cad;
}

var ob=null;
var op=0;
var anim=0;

function abreSelIdioma()
{
	ob=document.getElementById('contIdiomas');
	if (anim==0)
	{
		ob.style.display='inline';
		doAnim1();
	}
	else
		doAnim2();
}

function doAnim1()
{
	op+=5;
	if (op<100)
	{
		K_trans(ob,op);
		setTimeout('doAnim1()',10);
	}
	else
	{
		K_trans(ob,100);
		anim=1;
	}
}

function doAnim2()
{
	op-=5;
	if (op>0)
	{
		K_trans(ob,op);
		setTimeout('doAnim2()',10);
	}
	else
	{
		K_trans(ob,0);
		ob.style.display='none';
		anim=0;
	}
}

function K_trans(obj,opacity)
//By Richard Rutter
{
 	opacity = (opacity == 100)?99.999:opacity;
  	obj.style.KhtmlOpacity = opacity/100;
  	obj.style.filter = "alpha(opacity:"+opacity+")";
  	obj.style.MozOpacity = opacity/100;
  	obj.style.opacity = opacity/100;
}

function init()
{
	var pos=navigator.userAgent.indexOf("MSIE");
	if (pos>-1)
	{
		pos=navigator.userAgent.indexOf("MSIE");
		var majv=navigator.userAgent.charAt(pos+5);
		var minv=navigator.userAgent.charAt(pos+7)+navigator.userAgent.charAt(pos+8);
		if(majv<7)
			document.getElementById('contenido').style.border='0px solid';
	}
}

function checkNews()
{
	var email=document.getElementById('emailBox').value;
	if(email=='')
	{
		alert('Por favor, escriba su dirección de email');
		document.getElementById('emailBox').focus();
		return;
	}
	if(!echeck(email))
	{
		alert('La dirección de email parece incompleta.\r\n\r\nPor favor, revísela.');
		document.getElementById('emailBox').focus();
		return;
	}
	document.getElementById('ifr1').src='registroNews.php?email='+email;
}

function actProv(val)
{
	if(val==1)
	{
		document.getElementById('listprov').style.display='inline';
		document.getElementById('txprov').style.display='none';
	}
	else
	{
		document.getElementById('listprov').style.display='none';
		document.getElementById('txprov').style.display='inline';
	}
}

function checkContacto()
{
	if (document.f1.nombre_empresa.value=='')
	{
		alert('Por favor, rellene el nombre de la empresa');
		document.f1.nombre_empresa.focus();
		return;
	}
	if (document.f1.pais.value=='')
	{
		alert('Por favor, seleccione el país');
		document.f1.pais.focus();
		return;
	}
	if (document.getElementById('txprov').style.display=='inline' && document.f1.provincia.value=='')
	{
		alert('Por favor, rellene la provincia');
		document.f1.provincia.focus();
		return;
	}
	if (document.f1.email.value=='')
	{
		alert('Por favor, rellene el campo de email');
		document.f1.email.focus();
		return;
	}
	if (document.f1.telefono.value=='')
	{
		alert('Por favor, rellene el campo de teléfono');
		document.f1.telefono.focus();
		return;
	}
	document.f1.submit();
}



/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true
	}


function K_getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

function K_loadAJAX(file, callback)
{
	var http=K_getHTTPObject();
	var js_load=false;
	var ended=false;
	if (file.substr(file.length-3,3)=='.js')
		js_load=true;

	var pos=file.indexOf("?");
	if (pos>-1)
		file+='&K_rand='+Math.random();
	else
		file+='?K_rand='+Math.random();

	http.open("GET", file, true);
	http.onreadystatechange = function()
	{
		if (http.readyState==4)
		{
			if (http.status == 200)
			{
				if (ended) return; ended=true;
				if (js_load==false)
				{
					var xmlDoc = http.responseXML;
					var stat= xmlDoc.getElementsByTagName('stat')[0].firstChild.data;
					if (!K_parseXMLres(stat))
						return;
					eval (callback+"(xmlDoc);");
				}
				else
				{
					eval(http.responseText);
					pos=callback.indexOf("(");
					if (pos>-1)
						eval(callback);
					else
						eval (callback+"();");
				}
			}
			else
				alert('File '+file+' not found');
		}
	};
	http.send(null);
}
function K_parseXMLres(res)
{
	if (res=='NOK')
	{
		alert('RPC App error');
		return 0;
	}
	if (res=='DBERR')
	{
		alert('RPC DB error');
		return 0;
	}
	if (res=='AUTHERR')
	{
		alert('RPC Auth error');
		return 0;
	}
	return 1;
}
