// JavaScript Document
var rootdomain="http://"+window.location.hostname;

function abrir_ventana(url,l,t,w,h,s){
	window.open(url,'ventana','left=' + l +',top=' + t + ',width=' + w + ',height=' + h + ',scrollbars=' + s);
}

function verificar_registro(){
	var f = document.registro;
	if(f.usuario.value==""){
		alert("Ingresa tu usuario");
		f.usuario.focus();
		return;
	}
	
	if(f.contrasena.value==""){
		alert("Ingresa la contrasea que usaras en nuestro portal");
		f.contrasena.focus();
		return;
	}

	if(f.contrasena.value!=f.contrasena2.value){
		alert("Las contraseas no coinciden, ingresa la misma en ambos campos");
		f.contrasena.focus();
		return;
	}
	
	if(f.nombre.value==""){
		alert("Ingresa tu nombre");
		f.nombre.focus();
		return;
	}

	if(f.apellido.value==""){
		alert("Ingresa tu apellido");
		f.apellido.focus();
		return;
	}

	if(f.email.value==""){
		alert("Ingresa tu email");
		f.email.focus();
		return;
	}
	
	var p=f.email.value.indexOf('@');
	if (p<1 || p==(f.email.value.length-1)){
		alert("Debes introducir una direccin de email vlida");
		f.email.focus();
		return;
	}

	if(f.doc_identidad.value==""){
		alert("Ingresa tu documento de identidad");
		f.doc_identidad.focus();
		return;
	}
	
	if(f.telefono.value==""){
		alert("Ingresa tu telefono");
		f.telefono.focus();
		return;
	}
	
	if(f.celular.value==""){
		alert("Ingresa tu nmero de celular");
		f.celular.focus();
		return;
	}

	if(f.calle.value==""){
		alert("Ingresa tu calle");
		f.calle.focus();
		return;
	}

	if(f.numero.value==""){
		alert("Ingresa tu nmero");
		f.numero.focus();
		return;
	}

	if(f.edificio.value==""){
		alert("Ingresa tu edificio");
		f.edificio.focus();
		return;
	}

	if(f.apto.value==""){
		alert("Ingresa tu apto");
		f.apto.focus();
		return;
	}

	if(f.sector.value==""){
		alert("Ingresa tu sector");
		f.sector.focus();
		return;
	}
	
	if(f.provincia.options[f.provincia.selectedIndex].value==0){
		alert("Selecciona tu provincia");
		f.provincia.focus();
		return;		
	}

	if(f.nombre_sec.value==""){
		alert("Ingresa el nombre de quien recibir por t");
		f.nombre_sec.focus();
		return;
	}

	if(f.apellido_sec.value==""){
		alert("Ingresa el apellido de quien recibir por t");
		f.apellido_sec.focus();
		return;
	}

	if(f.doc_identidad_sec.value==""){
		alert("Ingresa el documento de identidad de quien recibir por t");
		f.doc_identidad_sec.focus();
		return;
	}
	
	f.submit();
}


function verificar_actualizacion_perfil(){
	var f = document.frm_actualizar_perfil;
	
	if(f.nombre.value==""){
		alert("Ingresa tu nombre");
		f.nombre.focus();
		return;
	}

	if(f.apellido.value==""){
		alert("Ingresa tu apellido");
		f.apellido.focus();
		return;
	}

	if(f.email.value==""){
		alert("Ingresa tu email");
		f.email.focus();
		return;
	}
	
	var p=f.email.value.indexOf('@');
	if (p<1 || p==(f.email.value.length-1)){
		alert("Debes introducir una direccin de email vlida");
		f.email.focus();
		return;
	}

	if(f.doc_identidad.value==""){
		alert("Ingresa tu documento de identidad");
		f.doc_identidad.focus();
		return;
	}
	
	if(f.telefono.value==""){
		alert("Ingresa tu telefono");
		f.telefono.focus();
		return;
	}
	
	if(f.celular.value==""){
		alert("Ingresa tu nmero de celular");
		f.celular.focus();
		return;
	}

	if(f.calle.value==""){
		alert("Ingresa tu calle");
		f.calle.focus();
		return;
	}

	if(f.numero.value==""){
		alert("Ingresa tu nmero");
		f.numero.focus();
		return;
	}

	if(f.edificio.value==""){
		alert("Ingresa tu edificio");
		f.edificio.focus();
		return;
	}

	if(f.apto.value==""){
		alert("Ingresa tu apto");
		f.apto.focus();
		return;
	}

	if(f.sector.value==""){
		alert("Ingresa tu sector");
		f.sector.focus();
		return;
	}
	
	if(f.provincia.options[f.provincia.selectedIndex].value==0){
		alert("Selecciona tu provincia");
		f.provincia.focus();
		return;		
	}

	if(f.nombre_sec.value==""){
		alert("Ingresa el nombre de quien recibir por t");
		f.nombre_sec.focus();
		return;
	}

	if(f.apellido_sec.value==""){
		alert("Ingresa el apellido de quien recibir por t");
		f.apellido_sec.focus();
		return;
	}

	if(f.doc_identidad_sec.value==""){
		alert("Ingresa el documento de identidad de quien recibir por t");
		f.doc_identidad_sec.focus();
		return;
	}
	
	f.submit();
}


function seleccionar_movil_registro(id_movil,ua){
	parent.document.frm_registro.idmovil.value=id_movil;
	parent.document.images['movil'].src = 'imagenes/moviles/' + ua + '.gif';
}

function verificar_agregar_album(){
	var f = document.frm_agregar_album;

	if(f.nombre.value==""){
		alert("Ingresa el nombre del album a crear");
		f.nombre.focus();
		return;
	}
	f.submit();	
}


function preview(archivo,imagen){
	var archivo = findObj(archivo);
	var imagen = findObj(imagen);

	imagen.src='file://'+archivo.value;
}

// Example: obj = findObj("image1");

function findObj(theObj, theDoc){
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
}



function agregar_carrito(id){
	if (tipo!=''){
		window.location='agregar_carrito.php?id=' + id + '&tipo=' + tipo;
	}else{
		alert('Elija si quiere alquilar o comprar');
	}
}

function confirmar_imprimir(){
	var f = document.frm_imprimir;

	if (confirm('Al imprimir se legaliza la factura, desea imprimirla?')){
		abrir_ventana('version_impr.php?cambio='+f.cambio.value+'&horario='+f.horario.value,0,0,800,800,1);
	}
}

function verificar_cambio_contrasena(){
	var f=document.frm_cambio_contrasena;
	if(f.contrasena_nueva.value==''){
			alert('Ingrese la nueva contasea');
			f.contrasena_nueva.focus();
			return;
	}
	if(f.contrasena_nueva2.value==''){
			alert('Ingrese la verificacion de la nueva contasea');
			f.contrasena_nueva2.focus();
			return;
	}
	if(f.contrasena_nueva.value!=f.contrasena_nueva2.value){
		alert('las contraseas no coinciden. Verifique');
		return;
	}
	f.submit();
}


function verificar_buscar(){
	var f=document.frm_buscar;
	if(f.nombre.value==''){
		alert('ingresa el nombre a buscar');
		f.nombre.focus();
		return;
	}
	window.location=f.tipo.value + '?buscar=si&nombre=' + f.nombre.value;
}

function cambiar_contenido_div(div,contenido){
	var d = findObj(div);
	d.innerHTML=contenido;
}


function findObj(theObj, theDoc){
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length){
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}



//Cambiar visibilidad

IE4 = (document.all) ? 1 : 0; // initialize browser.. 
NS4 = (document.layers) ? 1 : 0; // identification and... 
ver4 = (IE4 || NS4) ? 1 : 0; // DHTML variables 


function cambiar_visibilidad_a(i,vis){
	var e = document.getElementById(i);
	e.className=vis;
}

function verificar_formulario(f){
	var i=0;
	for(i=0; i<f.elements.length; i++){
		if(f.elements[i].alt=='OBLIGATORIO' && f.elements[i].value==""){
			alert('Por favor ingrese '+f.elements[i].title);
			f.elements[i].focus();
			return;
		}
	}
	f.submit();
}


function check_email(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
}
function confirmar(mensaje,url){
	if(confirm(mensaje)==true){
		window.location=url;
	}
}

function verify_form(f){
	var i=0;
	for(i=0; i<f.elements.length; i++){
		switch(f.elements[i].type){
			case 'password':	if(f.elements[i].value!="" && f.elements[i].alt!='MANDATORY'){
									if(f.elements[i].lang!='' && findObj(f.elements[i].lang).value!=f.elements[i].value){
									alert(f.elements[i].title + ' does not match');
									f.elements[i].focus();
									return(false);
									}	
								}									
								if(f.elements[i].alt=='MANDATORY' && f.elements[i].value==""){
									alert('Please enter '+f.elements[i].title);
									f.elements[i].focus();
									
									return(false);
								}
								
								if(f.elements[i].lang!='' && findObj(f.elements[i].lang).value!=f.elements[i].value){
									alert(f.elements[i].title + ' does not match');
									f.elements[i].focus();
									return(false);
								}									
								
								break;
			case 'text':		if(f.elements[i].alt=='MANDATORY' && f.elements[i].value==""){
									alert('Please enter '+f.elements[i].title);
									f.elements[i].focus();
									return(false);
								}
								if(f.elements[i].lang!='' && findObj(f.elements[i].lang).value!=f.elements[i].value){
									alert(f.elements[i].title + ' does not match');
									f.elements[i].focus();
									return(false);
								}									
								
								break;
			case 'checkbox':	if(f.elements[i].alt=='MANDATORY' && !f.elements[i].checked){
									alert('Please check '+f.elements[i].title);
									f.elements[i].focus();
									return(false);
								}
								break;
			case 'select-one':	//alert (f.elements[i].options[f.elements[i].selectedIndex].value);
								if(f.elements[i].lang=='MANDATORY' && f.elements[i].options[f.elements[i].selectedIndex].value==-1){
									alert('Please select '+f.elements[i].title);
									f.elements[i].focus();
									return(false);
								}
								break;					
		}
	}
	return(true);
}

function verif_form(f){
	var i=0;
	for(i=0; i<f.elements.length; i++){
		switch(f.elements[i].type){
			case 'password':	if(f.elements[i].value!="" && f.elements[i].alt!='MANDATORY'){
									if(f.elements[i].lang!='' && findObj(f.elements[i].lang).value!=f.elements[i].value){
									alert(f.elements[i].title + ' does not match');
									f.elements[i].focus();
									return(false);
									}	
								}									
								if(f.elements[i].alt=='MANDATORY' && f.elements[i].value==""){
									alert('Please enter '+f.elements[i].title);
									f.elements[i].focus();
									
									return(false);
								}
								
								if(f.elements[i].lang!='' && findObj(f.elements[i].lang).value!=f.elements[i].value){
									alert(f.elements[i].title + ' does not match');
									f.elements[i].focus();
									return(false);
								}									
								
								break;
			case 'text':		if(f.elements[i].alt=='MANDATORY' && f.elements[i].value==""){
									alert('Please enter '+f.elements[i].title);
									f.elements[i].focus();
									return(false);
								}
								if(f.elements[i].lang!='' && findObj(f.elements[i].lang).value!=f.elements[i].value){
									alert(f.elements[i].title + ' does not match');
									f.elements[i].focus();
									return(false);
								}									
								
								break;
			case 'checkbox':	if(f.elements[i].alt=='MANDATORY' && !f.elements[i].checked){
									alert('Please check '+f.elements[i].title);
									f.elements[i].focus();
									return(false);
								}
								break;
			case 'select-one':	//alert (f.elements[i].options[f.elements[i].selectedIndex].value);
								if(f.elements[i].lang=='MANDATORY' && f.elements[i].options[f.elements[i].selectedIndex].value==-1){
									alert('Please select '+f.elements[i].title);
									f.elements[i].focus();
									return(false);
								}
								break;					
		}
	}
	return(true);
}



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_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_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];}
}

//added on 16-04-09

function addMore(obj){
	var ln_count,lo_tr,lo_td2,lo_inp,ln_name;
	
    ln_count=parseInt(document.getElementById("photo_count").value)+1;
	document.getElementById("photo_count").value=ln_count;


	lo_tr=document.createElement('tr');
	lo_td2=document.createElement('td');
	lo_td2.style.valign='top';
	lo_td2.style.align='right';
	lo_td2.style.className='txt';
	lo_td2.appendChild(document.createTextNode("Photo Caption"));
	lo_inp=document.createElement('input');
	lo_inp.setAttribute("type","text");
	var ln_name="photo_name_"+ln_count;
	lo_inp.setAttribute("name",ln_name);
	lo_inp.setAttribute("id",ln_name);
	lo_td2.appendChild(lo_inp);
	lo_inp.style.className='txtbox';
	lo_tr.appendChild(lo_td2);
	document.getElementById("photo_tbl").appendChild(lo_tr);


	lo_td2=document.createElement('td');
	lo_td2.style.valign='top';
	lo_td2.style.className='txt';

	lo_inp=document.createElement('input');
	lo_inp.setAttribute("type","file");
	ln_name="photo_file_"+ln_count;
	lo_inp.setAttribute("name",ln_name);
	lo_td2.appendChild(lo_inp);
	lo_inp.style.className='txtbox';
	lo_tr.appendChild(lo_td2);
	//document.getElementById("photo_tbl").appendChild(lo_tr);
	document.getElementById("photo_tbl").getElementsByTagName("TBODY")[0].appendChild(lo_tr);


}
function SaveImages(){
var i,ln_count;
document.getElementById("action").value="add_image";
document.getElementById("mode").value="update";

Remove_Image();	
document.admin_frm.submit();
}
function Cancel1(){
document.getElementById("action").value="";
document.getElementById("mode").value="";
document.admin_frm.submit();	
}

function Remove_Image(){
var i;
var ls_image="";
var ls_num=parseInt(document.getElementById('remove_image').value);
for(i=1;i<ls_num;i++){
if(document.getElementById('remove_'+i).checked){
ls_image=ls_image+","+document.getElementById('remove_'+i).getAttribute("photo_id");
}
}
ls_image=ls_image.substr(1);
document.getElementById("remove_images").value=ls_image;
return;
}
function Edit_caption(ars_id){
	inpid="cap_"+ars_id.id.split("_")[1];
	var font_id="fn_"+ars_id.id.split("_")[1];
	if(document.getElementById(inpid).style.display=="inline"){
		document.getElementById(inpid).style.display="none";
		document.getElementById(inpid).value="";
	}else{
		document.getElementById(inpid).style.display="inline";
		document.getElementById(inpid).value=document.getElementById(font_id).innerHTML;
	}
}
function Edit_change(ars_obj){
	var font_id="fn_"+ars_obj.id.split("_")[1];
	var rem_id="remove_"+ars_obj.id.split("_")[1];
	var ls_val=ars_obj.value;
	document.getElementById(font_id).innerHTML=ls_val;
	ars_obj.style.display="none";
//	document.getElementById("img_cap").value;

	var ln_name="imgcap_"+ars_obj.id.split("_")[1];	
	if(!document.getElementById(ln_name)){	
		lo_inp=document.createElement('input');
		lo_inp.setAttribute("type","hidden");
		lo_inp.setAttribute("name",ln_name);
		lo_inp.setAttribute("id",ln_name);
		document.admin_frm.appendChild(lo_inp);	
	}
	document.getElementById(ln_name).value=document.getElementById(rem_id).getAttribute("photo_id")+","+ls_val;
}

