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){
	Categoria = Categoria == '-1' ? '' : Categoria;
	Buscar = Buscar== '-1' ? '' : Buscar;
	location.href='resultados_all.php?nreg='+Registros+'&pageNum_rs_Fotos='+valor+'&h_oriAccion=2&c='+Categoria+'&b='+encodeURIComponent(Buscar)+'&v='+Verticales+'&ld='+Libre_Dere+'&h='+Horizontal+'&dr='+Dere_Regis;
}

//http://localhost/PROD/inkafotos/resultados_all.php?nreg=5&pageNum_rs_Fotos=0&h_oriAccion=2&c=&b=M&v=1&ld=0&h=0&dr=0

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 = 1;
var checkVerticales = 1;
var checkDerechosregistrados = 1;
var checkLibredederechos = 1;*/


function cambiarIcono(idImg, name, idHdd){
//alert("idImg"+idImg+'-'+document.getElementById(idHdd).value);
	if(document.getElementById(idHdd).value == '0'){
		document.getElementById(idImg).innerHTML = '<img src="images/btnFotoCabSelec.png" width="14" height="14" align="absmiddle" style="margin-bottom:3px" /> '+name;
		document.getElementById(idHdd).value = '1';
	}else{
		document.getElementById(idImg).innerHTML = '<img src="images/btnFotoCabNoSelec.png" width="14" height="14" align="absmiddle" style="margin-bottom:3px"/>  '+name;
		document.getElementById(idHdd).value = '0';
	}
}

function validarIcono(idImg, name, idHdd){
//alert("idImg"+idImg+'-'+document.getElementById(idHdd).value);
	if(document.getElementById(idHdd).value == '1'){
		document.getElementById(idImg).innerHTML = '<img src="images/btnFotoCabSelec.png" width="14" height="14" align="absmiddle" /> '+name;
		document.getElementById(idHdd).value = '1';
	}else{
		document.getElementById(idImg).innerHTML = '<img src="images/btnFotoCabNoSelec.png" width="14" height="14" align="absmiddle"/>  '+name;
		document.getElementById(idHdd).value = '0';
	}
}

function jsChangeImg(img, nameImagen){		
	img.src = nameImagen;		
}

	/*if(id=='checkHoriz' && !document.getElementById('chkHorizontal').checked){
		
		document.getElementById(id).innerHTML = '<img src="images/btnFotoCabNoSelec.png" width="13" height="13" align="absmiddle"/>  Horizontales';
		document.getElementById('chkHorizontal').value = 0;
		checkHorizontales=0;
	}else if(id=='checkHoriz' && document.getElementById('chkHorizontal').checked){
		//alert("c"+checkHorizontales);
		document.getElementById(id).innerHTML = '<img src="images/btnFotoCabSelec.png" width="13" height="13" align="absmiddle" /> Horizontales';
		document.getElementById('chkHorizontal').value = 1;
		checkHorizontales=1;
	}	
	
	if(id=='checkVert' && checkVerticales==1){
		document.getElementById(id).innerHTML = '<img src="images/btnFotoCabNoSelec.png" width="13" height="13" align="absmiddle"/> Verticales';
		document.getElementById('chkVertical').value = 0;
		checkVerticales=0;
	}else if(id=='checkVert' && checkVerticales==0){
		document.getElementById(id).innerHTML = '<img src="images/btnFotoCabSelec.png" width="13" height="13" align="absmiddle"/> Verticales';
		document.getElementById('chkVertical').value = 1;
		checkVerticales=1;
	}	
	
	if(id=='checkDerReg' && checkDerechosregistrados==1){
		document.getElementById(id).innerHTML = '<img src="images/btnFotoCabNoSelec.png" width="13" height="13" align="absmiddle"/> Derechos Registrados';
		document.getElementById('chkDereRegi').value = 0;
		checkDerechosregistrados=0;
	}else if(id=='checkDerReg' && checkDerechosregistrados==0){
		document.getElementById(id).innerHTML = '<img src="images/btnFotoCabSelec.png" width="13" height="13" align="absmiddle"/> Derechos Registrados';
		document.getElementById('chkDereRegi').value = 1;
		checkDerechosregistrados=1;
	}	
	
	if(id=='checkLibreDer' && checkLibredederechos==1){
		document.getElementById(id).innerHTML = '<img src="images/btnFotoCabNoSelec.png" width="13" height="13" align="absmiddle"/> Libre de derechos';
		document.getElementById('chkLibreDere').value = 0;
		checkLibredederechos=0;
	}else if(id=='checkLibreDer' && checkLibredederechos==0){
		document.getElementById(id).innerHTML = '<img src="images/btnFotoCabSelec.png" width="13" height="12" align="absmiddle"/> Libre de derechos';
		document.getElementById('chkLibreDere').value = 1;
		checkLibredederechos=1;
	}	*/	



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,txtUsoFoto,tiempo,txtTiempoAlquiler,valorExclusividad,comentarios, descUso, descTiempo, foto1){
	//alert(foto1);
	ajax=nuevoAjax();
	ajax.open("POST", "includes/cfg/agregafotos.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {			
			bgThumbnails(cod,"show");
			cargar();
			jsOcultarDiv("divErrorSinFoto");
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("cod="+cod+"&uso="+uso+"&otros1="+encodeURIComponent(txtUsoFoto)+"&tiempo="+tiempo+"&otros2="+encodeURIComponent(txtTiempoAlquiler)+"&valorExclusividad="+valorExclusividad+"&comentarios="+encodeURIComponent(comentarios)+"&descUso="+encodeURIComponent(descUso)+"&descTiempo="+encodeURIComponent(descTiempo)+"&foto1="+foto1);
}

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;
				//alert("2.00");
				ocultarMostrar();
				
			}
			var aux2 = document.getElementById('divCarrito');
			if (aux2!=null) aux2.innerHTML = jQuery.trim(ajax.responseText);			//else alert('divCarrito es nulo');
			numveces=1;
			//alert("2.11"+aux2);
			//alert("responseText"+ajax.responseText);
			}
		}
		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
	}
}

/*Inicio - Para mostrar el efecto de imagen pequeña cuando pasa el mouse por la lista de imagenes*/
$(document).ready(function(){
//Larger thumbnail preview

$(".thumbnail").hover(function() {							
		//$(this).css({'z-index' : '10'});		
		var cadena =  (this.name).split("|");
		//var cadena = $(".thumbnail").attr("name").split("|");
		
		if(parseInt(cadena[1]) > parseInt(cadena[0])){ // si height es mayor
			$(".thumbnail:hover span").css({'marginTop' : '0', 'marginLeft' : '0', 'top' : '-1480%', 'left' : '-68%', 'padding' : '0'});
		}else{
			$(".thumbnail:hover span").css({'marginTop' : '0', 'marginLeft' : '0', 'top' : '-998%', 'left' : '-61%', 'padding' : '0'});
		}
//		alert(cadena);
	//	alert(parseInt(cadena[0]));
		//alert(parseInt(cadena[1]));
		
		//marginTop:0px;marginLeft:0px;top:-1480%;left:-68%;padding:0px;
		
		/*$(this).find('#imgListaA').addClass("hover").stop()
		.animate({
			marginTop: '-110px',
			marginLeft: '-110px',
			top: '50%',
			left: '50%',
			width: '174px',
			height: '174px',
			padding: '20px'
		}, 200);*/
	} , function() {
		//alert("outt");
		//$(this).css({'z-index' : '0'});		
		//$('#imgListaA').hide();
//		$('#imgListaA').css({'display' : 'none'});	
		//$(this).find('#imgListaA').removeClass("display")
		//$('#imgListaA').hide();
		
		/*$(this).find('#imgListaA').removeClass("hover").stop()
		.animate({
			marginTop: '0',
			marginLeft: '0',
			top: '0',
			left: '0',
			width: '100px',
			height: '100px',
			padding: '5px'
		}, 400);*/		
	});

	//Swap Image on Click
	/*$("pl.thumb li a").click(function() {

		var mainImage = $(this).attr("href"); //Find Image Name
		$("#main_view img").attr({ src: mainImage });
		return false;
	});*/

});
//Fin - Para mostrar el efecto de imagen pequeña cuando pasa el mouse por la lista de imagenes
