var loaded=0;

preload_image=new Image();
preload_image.src="images/menu-primary-background-over.gif"; 

function hideMe(){
	document.getElementById('div-banner-popup').style.visibility='hidden';
}

function Fotos(detalle){
			archivo='index_fotos.php?detalle='+detalle;
			wid=650;
			hei=screen.height-74;
			winName = 'ventana_fotos';
			features='width='+wid+',height='+hei+',scrollbars=yes,status=no,menubar=no,options=no,left=0,top=0';
			ventana_fotos=window.open(archivo,winName,features);
			ventana_fotos.focus();
}

function Verify(){
	string=document.getElementById('form-contactar-form_string_test').value;

	if(string.length==4){
		document.getElementById('form-contactar-form_string_test').disabled=true;
		document.getElementById("span-form-contactar-checking").innerHTML='<img src="images/checking.gif" border="0" width="12" height="12" alt="Checking..."/>';

		var url="system-image-verify.php";
		parameters="?sid="+Math.random()+"&form_string="+string;
		Ajax(url,parameters,VerifyResult);
	}
}

function VerifyResult(){
	if(http_request.readyState==4){
		if(http_request.status==200){
			result=http_request.responseText;
			if(result==1){
				document.getElementById('form-contactar-form_string').value=document.getElementById('form-contactar-form_string_test').value;
				document.getElementById('span-form-contactar-checking').innerHTML='Enviando mensaje...';
				Send('contactar-insert.php');
			}else{
				document.getElementById('span-form-contactar-checking').innerHTML='Reintente...';
				document.getElementById('form-contactar-form_string_test').value="";
				SetFocus('form-contactar-form_string_test');
			}
		}else{
			alert('No se puede conectar... Por favor reintente...');
		}
	}
}

function Send(url){
	form=document.getElementById('form-contactar'); 
	parameters="?sid="+Math.random();
	for(i=1;i<form.elements.length;i++){
		element=form.elements[i];
		if(element.type=="checkbox"){
			if(element.checked==true){
				parameters+="&"+element.name+"="+escape(element.value);
			}
		}else{
			parameters+="&"+element.name+"="+escape(element.value);
		}
	}

	Ajax(url,parameters,SendResult);
}

function SendResult(){
	if(http_request.readyState==4){
		if(http_request.status==200){
			result=http_request.responseText;
			if(result==1){
				document.getElementById('span-form-contactar-checking').innerHTML='Muchas gracias.';
			}else{
				document.getElementById('span-form-contactar-checking').innerHTML='No se ha enviado, por favor reintente...';
			}
		}else{
			alert('No se puede conectar... Por favor reintente...');
		}
	}
}

function Ajax(url,parameters,after){
	http_request=false;
	if(window.XMLHttpRequest){
		http_request=new XMLHttpRequest();
		if(http_request.overrideMimeType){
			http_request.overrideMimeType('text/xml');
		}
	}else{
		if(window.ActiveXObject){
			try{
				http_request=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e){
				try{
					http_request=new ActiveXObject("Microsoft.XMLHTTP");
            			}
				catch(e){}
			}
		}
	}

	if(!http_request){
		alert('Cannot create XMLHTTP instance');
		return false;
	}
      
	http_request.onreadystatechange=after;
	http_request.open('POST',url,true);
	http_request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length",parameters.length);
	http_request.setRequestHeader("Connection","close");
	http_request.send(parameters);
}