var numveces = 0;
var flag = true;

function verDetalle(cod,query){
//var url='detallefoto.php?cod='+cod+'&query='+document.getElementById('query').value;
var url='detallefoto.php?cod='+cod;
window.open(url,"detalle","height=700,width=720,scrollbars=yes");
}
function gotoPageCombo(valor,Categoria,Buscar,Verticales,Libre_Dere,Horizontal,Dere_Regis,Registros){
	location.href='resultados.php?pageNum_rs_Fotos='+valor+'&h_oriAccion=2&categoria='+Categoria+'&campoBuscar='+Buscar+'&buscarVertical='+Verticales+'&buscarLibreDerechos='+Libre_Dere+'&buscarHorizontal='+Horizontal+'&buscarDerechosRegistrados='+Dere_Regis+'&nreg='+Registros;
}

function cerrarsesion(){
	if(confirm("En caso de tener algun presupuesto activo sera eliminado\nDesea continuar?")){
		location.href='cerrarsesion.php';		
	}
}
function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
	if(window.screen)if(isCenter)if(isCenter=="true"){
	var myLeft = (screen.width-myWidth)/2;
	var myTop = (screen.height-myHeight)/2;
	features+=(features!='')?',':'';
	features+=',left='+myLeft+',top='+myTop;
	}
	window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight+',scrollbars=yes');
}
function ver(div){
document.getElementById(div).style.visibility = 'visible'	
}
function isEmpty(field) {
	var _isEmpty = 1;
	// The replace function (js1.2) isn't supported -> basic tests
    if (typeof(field.value.replace) == 'undefined') {
        _isEmpty = (field.value == '') ? 1 : 0;
    }
    // js1.2+ -> validation with regular expressions
    else {
        var space_re = new RegExp('\\s+');
        if (field.value.replace(space_re, '') != '') {
            _isEmpty = 0;
        }
    }
	return _isEmpty;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

var checkHorizontales = true;
var checkVerticales = true;
var checkDerechosregistrados = true;
var checkLibredederechos = true;


function buscar(id){

	if(id=='checkHoriz' && checkHorizontales==true){
		document.getElementById(id).innerHTML = '<img src="Principal/imagenes/checkNo.gif" width="13" height="12" align="absmiddle" />';
		document.getElementById('buscarHorizontal').value = false;
		checkHorizontales=false;
	}else if(id=='checkHoriz' && checkHorizontales==false){
		document.getElementById(id).innerHTML = '<img src="Principal/imagenes/checkSi.gif" width="13" height="12" align="absmiddle" />';
		document.getElementById('buscarHorizontal').value = true;
		checkHorizontales=true;
	}	
	
	if(id=='checkVert' && checkVerticales==true){
		document.getElementById(id).innerHTML = '<img src="Principal/imagenes/checkNo.gif" width="13" height="12" align="absmiddle" />';
		document.getElementById('buscarVertical').value = false;
		checkVerticales=false;
	}else if(id=='checkVert' && checkVerticales==false){
		document.getElementById(id).innerHTML = '<img src="Principal/imagenes/checkSi.gif" width="13" height="12" align="absmiddle" />';
		document.getElementById('buscarVertical').value = true;
		checkVerticales=true;
	}	
	
	if(id=='checkDerReg' && checkDerechosregistrados==true){
		document.getElementById(id).innerHTML = '<img src="Principal/imagenes/checkNo.gif" width="13" height="12" align="absmiddle" />';
		document.getElementById('buscarDerechosRegistrados').value = false;
		checkDerechosregistrados=false;
	}else if(id=='checkDerReg' && checkDerechosregistrados==false){
		document.getElementById(id).innerHTML = '<img src="Principal/imagenes/checkSi.gif" width="13" height="12" align="absmiddle" />';
		document.getElementById('buscarDerechosRegistrados').value = true;
		checkDerechosregistrados=true;
	}	
	
	if(id=='checkLibreDer' && checkLibredederechos==true){
		document.getElementById(id).innerHTML = '<img src="Principal/imagenes/checkNo.gif" width="13" height="12" align="absmiddle" />';
		document.getElementById('buscarLibreDerechos').value = false;
		checkLibredederechos=false;
	}else if(id=='checkLibreDer' && checkLibredederechos==false){
		document.getElementById(id).innerHTML = '<img src="Principal/imagenes/checkSi.gif" width="13" height="12" align="absmiddle" />';
		document.getElementById('buscarLibreDerechos').value = true;
		checkLibredederechos=true;
	}		

}

function checksRegistrese(id){
	if(id=='boletin_correonormal' && checkCorreoNormal==false){
		document.getElementById(id).innerHTML = '<img src="Principal/imagenes_regist/checkSi.gif" alt="" />';
		document.getElementById('info_correonormal').value = true;
		checkCorreoNormal=true;
	}else if(id=='boletin_correonormal' && checkCorreoNormal==true){
		document.getElementById(id).innerHTML = '<img src="Principal/imagenes_regist/checkNo.gif" alt="" />';
		document.getElementById('info_correonormal').value = false;
		checkCorreoNormal=false;
	}
	if(id=='boletin_correoelectronico' && checkCorreoElectronico==false){
		document.getElementById(id).innerHTML = '<img src="Principal/imagenes_regist/checkSi.gif" alt=""/>';
		document.getElementById('info_correoelectronico').value = true;
		checkCorreoElectronico=true;
	}else if(id=='boletin_correoelectronico' && checkCorreoElectronico==true){
		document.getElementById(id).innerHTML = '<img src="Principal/imagenes_regist/checkNo.gif" alt=""/>';
		document.getElementById('info_correoelectronico').value = false;
		checkCorreoElectronico=false;
	}
	if(id=='aceptar_terminos' && checkTerminos==false){
		document.getElementById(id).innerHTML = '<img src="Principal/imagenes_regist/checkSi.gif" alt=""/>';
		checkTerminos=true;
	}else if(id=='aceptar_terminos' && checkTerminos==true){
		document.getElementById(id).innerHTML = '<img src="Principal/imagenes_regist/checkNo.gif" alt=""/>';
		checkTerminos=false;
	}
}

function validarFormulario(){
var form = document.getElementById('formRegistrese');

	if(form.usuario.value==""){
		alert("Ingrese un usuario");
		form.usuario.focus();	
		return;
	}else if(form.clave.value==""){
		alert("Ingrese su clave");
		form.clave.focus();	
		return;
	}else if(form.confirma_clave.value==""){
		alert("Confirme su clave");
		form.confirma_clave.focus();	
		return;
	}else if(form.confirma_clave.value!=form.clave.value){
		alert("Las claves no coinciden");
		form.confirma_clave.value='';	
		form.clave.value='';	
		return;
	}else if(form.nombres.value==""){
		alert("Ingrese su nombre");
		form.nombres.focus();
		return;
	}else if(form.apellidos.value==""){
		alert("Ingrese su apellido");
		form.apellidos.focus();
		return;
	}else if(form.email.value==""){
		alert("Ingrese su email");
		form.email.focus();
		return;
	}else if((form.direccion_contacto.value=="")&&(checkCorreoNormal==true)){
		alert("Ingrese su dirección de envío");
		form.direccion_contacto.focus();
		return;
	}else if((form.distrito_contacto.value=="")&&(checkCorreoNormal==true)){
		alert("Ingrese su distrito");
		form.distrito_contacto.focus();
		return;
	}else if((form.provincia_contacto.value=="")&&(checkCorreoNormal==true)){
		alert("Ingrese su provincia/región");
		form.provincia_contacto.focus();
		return;
	}else if(checkTerminos==false){
		alert("Debe aceptar los terminos y condiciones");
		return;
	}else{
		if(confirm("¿Todos los datos son correctos?")){
		document.formRegistrese.submit();
		}
	}

}
function tecla(e) { 
  var tecla = (document.all) ? e.keyCode :e.which;  
  if(tecla==13){ 
  	if(document.getElementById('campoBuscar').value==''){
		alert("Ingrese un criterio de busqueda");
		return false;
	}else{
		buscarFoto();
	}  
  }
} 
function validar(){
	if(document.getElementById('campoBuscar').value==''){
		return false;
	}else{
		return true;
	}	
}

function login(form){
document.getElementById('formGeneral').action = 'phpLogin.php';
document.getElementById('formGeneral').submit();
}
function buscarFoto(){
	if(document.getElementById('campoBuscar').value!=''){
		document.getElementById('formGeneral').action = 'resultados_all.php';
		document.getElementById('formGeneral').submit();
	}else{
		alert("Ingrese un criterio de busqueda");
		return;		
	}
}
 
function nuevoAjax(){
	var xmlhttp=false;
 	try {
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch (e) {
 		try {
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		} catch (E) {
 			xmlhttp = false;
 		}
  	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function agregar(cod,uso,otros1,tiempo,otros2,valorExclusividad,comentarios){
	
	var cod;
	var uso;
	var otros1;
	var tiempo;
	var otros2;
	var valorExclusividad;
	var comentarios;

	ajax=nuevoAjax();
	ajax.open("POST", "includes/cfg/agregafotos.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			bgThumbnails(cod,"show");
			cargar();
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("cod="+cod+"&uso="+uso+"&otros1="+otros1+"&tiempo="+tiempo+"&otros2="+otros2+"&valorExclusividad="+valorExclusividad+"&comentarios="+comentarios);
}
function cargar(){
		ajax=nuevoAjax();
		ajax.open("POST", "includes/cfg/cargarcarrito.php",true);
		ajax.onreadystatechange=function() {
			if (ajax.readyState==4) {
			if(numveces == 0){
				var aux = document.getElementById('fixme');				if (aux!= null ) aux.style.display = 'block';				//else alert('fixme es nulo');
				flag = true;
				ocultarMostrar();
			}
			var aux2 = document.getElementById('divCarrito');			if (aux2!=null) aux2.innerHTML = ajax.responseText;			//else alert('divCarrito es nulo');
			numveces=1;
			}
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(null);	
}
function ocultarMostrar(){
	if(flag){
		document.getElementById('fixme').style.display = "block";
		document.getElementById('fixme2').style.display = "none";
		flag = false
	}else{
		document.getElementById('fixme').style.display = "none";
		document.getElementById('fixme2').style.display = "block";
		flag = true
	}
}