//CARGA LA PELICULA FLASH PARA LOS CARRUSELES
function cargaXmlFlashPost(rutaXML,idobject,nombreVar){
	  
		var PeliculaObj = document.getElementById(idobject);
		PeliculaObj.SetVariable(nombreVar,rutaXML);
		PeliculaObj.SetVariable("semaforo",true);
} 
//FORMATO DE LA FECHA PARA EL POST
function PostFormatFecha(fechaf,formato,salida,idioma,tipo) {
	 if ((formato == undefined)||(formato == '')){ fecformato='l';} else { fecformato=formato; }
	 if ((salida == undefined) ||(salida == '')) { salidaformato='pantalla';} else { salidaformato=salida; }
	 if ((idioma == undefined) ||(idioma == '')) { idiomaformato='eng';} else { idiomaformato=idioma; }
	 if (tipo == undefined) { tipo='';} 
	 
	 fec=fechaf.split("/");

	 anyo=parseInt(parseFloat(fec[0]));
	 mes=parseInt(parseFloat(fec[1]));
	 dia=parseInt(parseFloat(fec[2]));
	 
	 var fechaPost=new Date(anyo,mes-1,dia,0,0,0);

	 var dias=new Array('Domingo','Lunes','Martes','Miércoles','Jueves','Viernes','Sábado');
	 var diass=new Array('Dom','Lun','Mar','Mie','Jue','Vie','Sab');
	 
	 var days=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
	 var dayss=new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');

	 var mesesmay=new Array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre');
	 var meses=new Array('enero','febrero','marzo','abril','mayo','junio','julio','agosto','septiembre','octubre','noviembre','diciembre');
	 
	 var months=new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	 var monthss=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');


	 if (fecformato.toLowerCase() == 'l'){
		
		if (salidaformato.toLowerCase() == 'pantalla'){
				
			if (idiomaformato.toLowerCase() == 'esp'){ 
				if(tipo=="may"){
					document.write(dias[fecha.getDay()]+', '+dia+' '+mostrar_mensaje('47')+' '+mesesmay[mes-1]+' '+mostrar_mensaje('47')+' '+anyo);
				}
				else{
					document.write(dias[fecha.getDay()]+', '+dia+' '+mostrar_mensaje('47')+' '+meses[mes-1]+' '+mostrar_mensaje('47')+' '+anyo);
				}
			}
			else{
				document.write('Spain, '+days[fechaPost.getDay()]+' '+months[mes-1]+' '+dia+', '+anyo);
				
			}
		}
		
		if (salidaformato.toLowerCase() == 'variable'){
			
			if (idiomaformato.toLowerCase() == 'esp'){ 
				txt=''+dias[fechaPost.getDay()]+', '+dia+' '+mostrar_mensaje('47')+' '+meses[mes-1]+' '+mostrar_mensaje('47')+' '+anyo;
				return txt;
			}
			else{
				txt='Spain, '+days[fechaPost.getDay()]+' '+months[mes-1]+' '+dia+', '+anyo;
				return txt;
				
			}
		}
		
	 }
	
	 if (fecformato.toLowerCase() == 'c'){	
		var mesText=''+mes; if(mes<=9) mesText="0"+mes;
		var diaText=''+dia; if(dia<=9) diaText="0"+dia;
		var txt=diaText+'/'+mesText+'/'+anyo;
		return txt;
	 }
	
	 if (fecformato.toLowerCase() == 's'){	
		 
		if (salidaformato.toLowerCase() == 'pantalla'){ 
			
			if (idiomaformato.toLowerCase() == 'esp'){ 
				document.write(diass[fechaPost.getDay()]+', '+dia+' '+mostrar_mensaje('47')+' '+mesess[mes-1]+' '+mostrar_mensaje('47')+' '+anyo);
			}
			else{
				document.write('Spain, '+dayss[fechaPost.getDay()]+' '+monthss[mes-1]+' '+dia+', '+anyo);
				
			}
		}
		
		if (salidaformato.toLowerCase() == 'variable'){
			
			if (idiomaformato.toLowerCase() == 'esp'){  
				txt=''+diass[fechaPost.getDay()]+', '+dia+' '+mostrar_mensaje('47')+' '+mesess[mes-1]+' '+mostrar_mensaje('47')+' '+anyo;
				return txt;
			}
			else{
				txt='Spain, '+dayss[fechaPost.getDay()]+', '+monthss[mes-1]+' '+dia+', '+anyo;
				return txt;
				
			}
		}
		
	 }
}
//FUNCION DE VOTACION CUANDO SE PICA EN ALGUNA ESTRELLA
function votacionval(dkc,dkp,num){
	variableses=eval("votepost"+dkp);
	if (variableses == 0){
		for(var i=1; i<=num; i++){
			document.getElementById(dkc+'vote'+i).className="voteOn";
		}
		if (num<4){	
			for(var i=num+1; i<=4; i++){
				document.getElementById(dkc+'vote'+i).className="voteOff";
			}
		}
		var cadenaURL = cgiurl+'/v.cgi?D.templ='+htmg+'/componentes/intermedia/votepost.html&D.k='+dkp+'&val='+num;
		var mycarga=new serverLoad();	
		mycarga.onLoad= function(ok){
			if (ok){
				var varcortar=mycarga.text;
				varcortar = varcortar.split(",");
				var valora = varcortar[0];
				var votaci = varcortar[1];
				document.getElementById('cantVotos'+dkp).innerHTML=votaci + ' ' + mostrar_mensaje('326');
				promedio = valora/votaci;
				var residuo = promedio-parseInt(promedio);
				if (residuo > 0.5){
					var resulprom=Math.ceil(promedio);
				}
				else{
					var resulprom=Math.floor(promedio);
				}								
				for (var i=1; i<=resulprom; i++){					
					document.getElementById(dkc+'viewvote'+i).className="voteOn nocursor";
				}				
				if (resulprom<4){				
					for(var i=resulprom+1; i<=4; i++){					
						document.getElementById(dkc+'viewvote'+i).className="voteOff nocursor";
					}
				}
				var mySend = new callServer();							
				mySend.onLoad = function(cargo){
					if (cargo){
						eval("votepost"+dkp+"=1;");
					}
				};
				mySend.loadXMLhttp(cgiurl+"/s.cgi?D.templ="+vistacomunidadpath+"/dummy.html&votepost"+dkp+"=1","POST",true);
			}							
		};
		mycarga.loadTXT(cadenaURL);
	}
	else{alert(mostrar_mensaje('323'));}

}
//CARGA INICIAL DE LA VOTACION Y LA VALORACION

function cargavaloracionvoto(Dkp,Dkc,escrito)
{
	if (escrito != "")
	{
		var mycarga=new callServer();
		mycarga.onLoad= function(ok){
			if (ok){
				var promedio = "";
				var numvot = mycarga.isNull(mycarga.getValue('numvotos',0),0);
				var valora = mycarga.isNull(mycarga.getValue('valoracion',0),0);
				promedio = valora/numvot;
				var residuo = promedio-parseInt(promedio);
				if (residuo > 0.5)
				{var resulprom=Math.ceil(promedio);}
				else
				{var resulprom=Math.floor(promedio);}
				for (var i=1;i<=resulprom;i++){if(document.getElementById(Dkc+'viewvote'+i)){document.getElementById(Dkc+'viewvote'+i).className="voteOn nocursor";}}
				if (resulprom<4){for(var i=resulprom+1; i<=4; i++){if (document.getElementById(Dkc+'viewvote'+i)){document.getElementById(Dkc+'viewvote'+i).className="voteOff nocursor";}}}
				if (document.getElementById('cantVotos'+Dkp)){document.getElementById('cantVotos'+Dkp).innerHTML=numvot+' '+mostrar_mensaje('326')};
			}
		}
		var url=cgiurl+"/q2XML.cgi?type=post&where=D.k="+Dkp+"&r="+Math.random();
		mycarga.loadXMLhttp(url,'POST',true);
	}
}



//PARA LO DEL MAPA EN CASO DE EXISTIR
// Objeto mapa
var vecMap = new Array();
function Map(idContent) {
    
    this.idContent = idContent;

    this.map;
    this.geocoder;
	
	this.globalReference = false;
	this.centerMap = false;
	this.cache = false;

	this.index;
	this.gdir = null; 
	
	this.initialtype = G_NORMAL_MAP;
	this.zoom = 15;
	this.zoomControl = true;
	this.typeControl = true;
	this.scaleControl = true;	

    this.vecPoint = new Array();
	this.vecGlobalReference = new Array();
	this.vecOverlay = new Array ();

}

Map.prototype.addPoint = function(point) {
    this.vecPoint[this.vecPoint.length] = point;
}

Map.prototype.addOverlays = function(overlay) {
    
	this.vecOverlay[this.vecOverlay.length] = overlay;
}

Map.prototype.getOverlay = function() {
    return this.vecOverlay;
}


Map.prototype.setCenterMap = function(point) {
    this.centerMap = point;
}

Map.prototype.getCenterMap = function(point) {
    return this.centerMap;
}

Map.prototype.setCache = function(valor) {
     this.cache = valor;
}

Map.prototype.getCache = function() {
    return this.cache;
}

Map.prototype.setZoomMap = function(valor) {
     this.zoom = valor;
}

Map.prototype.getZoomMap = function() {
    return this.zoom;
}


Map.prototype.showZoomControlMap = function(valor) {
  
	  if (valor){
		
		
		if (valor == "false"){
			this.zoomControl = false;
		} else {
			this.zoomControl = true;
		}
		
	  }else {
		return  this.zoomControl;	  
	  }
  
}

Map.prototype.showTypeControlMap = function(valor) {
  
	  if (valor){
		
		if (valor == "false"){
			this.typeControl = false;
		} else {
			this.typeControl = true;
		}
		
	  }else {
		  
		return  this.typeControl;	  
	  }
  
}

Map.prototype.showScaleControlMap = function(valor) {
  
	  if (valor){
		
		if (valor == "false"){
			this.scaleControl = false;
		} else {
			this.scaleControl = true;
		}
		
	  }else {
		  
		return  this.scaleControl;	  
	  }
  
}




Map.prototype.showMap = function() {
	
	if (!this.getCache()){
		this.create();		
	}
	
}




Map.prototype.setIndex = function(index) {
    this.index = index;
}

Map.prototype.getIndex = function() {
    return this.index;
}

Map.prototype.convertType = function(type) {
    
	switch(type)
	{

		case "normal":
			return  G_NORMAL_MAP;
		break;

		case "satelite":
			return G_SATELLITE_MAP;
		break;

		case "hibrido":
			return G_HYBRID_MAP;
		break;

		case "relieve":
			return G_PHYSICAL_MAP;
		break;


	}
	
	
	
}


Map.prototype.setInitialType = function(type) {
    this.initialtype = this.convertType (type);
}

Map.prototype.getInitialType = function() {
    return this.initialtype;
}



Map.prototype.getGdir = function() {
    return this.gdir;
}


Map.prototype.create = function() {

    if (GBrowserIsCompatible()) {
        this.map = new GMap2(document.getElementById(this.idContent));
        this.setIndex(vecMap.length);
		this.map.addMapType(G_PHYSICAL_MAP);
        vecMap[vecMap.length] = this;
        //this.map.addControl(new GSmallZoomControl());
		
		
        this.map.setMapType(this.getInitialType());
		
		if (this.showZoomControlMap()) {
            this.map.addControl(new GLargeMapControl());
        }

        if (this.showTypeControlMap()) {
            this.map.addControl(new GMapTypeControl());
        }
		
		if (this.showScaleControlMap()) {
            this.map.addControl(new GScaleControl());
        }


        this.gdir = new GDirections(this.map);




        //this.map.checkResize();


        //map.setCenter(new GLatLng(37.4419, -122.1419), 13);

        this.geocoder = new GClientGeocoder();

        if (this.getCenterMap()) {
            //this.centrarMapa();
			this.map.setCenter(this.getCenterMap(), this.getZoomMap());
        }

        if (this.getGlobal()) {

            this.showGlobalReference();

        } else {
            var vec = this.vecPoint;
            for (var i = 0; i < vec.length; i++) {

                this.showPoint(vec[i]);

            }
			
			var vecOver = this.getOverlay();
			//this.map.setUIToDefault();

			for (var j = 0; j < vecOver.length; j++) {
				
				 //var boundaries = new GLatLngBounds(new GLatLng(40.716216,-74.213393), new GLatLng(40.765641,-74.139235));
				//var oldmap = new GGroundOverlay("http://www.lib.utexas.edu/maps/historical/newark_nj_1922.jpg", boundaries);
				this.map.addOverlay(vecOver[j]);

            }
        }



    }
}


Map.prototype.showPoint = function(obj) {

    if (this.geocoder) {

        var objMapa = this;
        var map = this.map;
        //var address = obj.getAddress();
		var point = obj.getLatLong();
		var objPunto = obj;
		


        this.geocoder.getLocations(

					point,

							function(address) {

							    if (!address) {

							        alert(address + " not found");

							    } else {


							       
											try {
											
											var result = address.Placemark[0];
											var lat = result.Point.coordinates[1];
											var lng = result.Point.coordinates[0];
											var responsePoint = new GLatLng(lat, lng, true);
											
											if (objPunto.getTitle()){
												var marker = new GMarker(responsePoint,{title:objPunto.getTitle()});
											}else{
												var marker = new GMarker(responsePoint);
											}
											obj.setResponse (result.address);
											
																				
											map.addOverlay(marker);
																				
											map.setCenter(responsePoint, objMapa.getZoomMap());
											 
											
											GEvent.addListener(marker, 'click', function() {

												marker.openInfoWindowHtml(

												obj.getDialog(objMapa.getIndex())
																									
												);
												vecMap[objMapa.getIndex()].map.updateInfoWindow();

											});
											
											if (obj.showDialog()){
												marker.openInfoWindowHtml(
			
													obj.getDialog(objMapa.getIndex())
													   
														
													);
													setTimeout("refreshDialog ("+objMapa.getIndex()+")", 3000)
													
											}

									} catch(e){}

							    }

							}

				);

    }


}

// FUNCION TEMPORARIA 
function refreshDialog (indice){
	vecMap[indice].map.updateInfoWindow();
}


// Referencias globales

Map.prototype.setGlobal = function(valor) {
   this.globalReference = valor;
}

Map.prototype.getGlobal = function() {
   return this.globalReference;
}

Map.prototype.addGlobalReference = function(point) {
	this.vecGlobalReference[this.vecGlobalReference.length] = point;	
}

Map.prototype.centrarMapa = function() {

    
	if (this.geocoder) {

        var objActual = this;
		map = this.map;
        address = ","+this.getCenterMap();

        this.geocoder.getLatLng(

					address,

							function(point) {

							    if (!point) {

							        alert(address + " not found");

							    } else {

							        map.setCenter(point, objActual.getZoomMap());
							        
							    }

							}

				);

    }


}



Map.prototype.showGlobalReference = function() {
	
	 
	 
	var vec = this.vecGlobalReference;
	for (var i = 0; i < vec.length; i++) {
				//alert (vec[i].getProvincia());
				this.showPointGlobal(vec[i]);
	
	}
	
	
		
	
}


Map.prototype.showPointGlobal = function(obj) {

    if (this.geocoder) {
		
		var objActual = this;
        var map = this.map;
        var address = obj.getAddress();

        this.geocoder.getLatLng(

					address,

							function(point) {

							    if (!point) {

							        alert(address + " not found");

							    } else {
									
							       if (!objActual.getCenterMap()){	
										
										map.setCenter(point, objActual.getZoomMap());
							       }
									
									
									if (obj.getTitle()){
										var marker = new GMarker(point,{title:obj.getTitle()});
							        } else {
										var marker = new GMarker(point);
									}
									
									
									map.addOverlay(marker);

							        GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(obj.getDialog()); });



							    }

							}

				);

    }


}



// -- Objeto para un punto de referencia
function Point() {

    this.dk;
    
    this.camino = false;
    
    this.nombre;
    this.descripcion;
	
	this.titulo = false;

    this.lat;
	this.lng;
	this.calle;
    this.nro;
    this.localidad;
    this.provincia;

    this.showDialogs = false;
	this.contentDialog;
	this.response;


}

Point.prototype.setDk = function(dk) {
    this.dk = dk;
}

Point.prototype.getDk = function() {
    return this.dk;
}

Point.prototype.setLat = function(lat) {
    this.lat = parseFloat(lat);
}

Point.prototype.getLat = function() {
    return this.lat;
}

Point.prototype.setLong = function(lng) {
    this.lng = parseFloat(lng);
}

Point.prototype.getLong = function() {
    return this.lng;
}

Point.prototype.getLatLong = function() {
    return new GLatLng(this.getLat(), this.getLong(), true);
}


Point.prototype.setCamino = function(valor) {
    this.camino = valor;
}

Point.prototype.getCamino = function() {
    return this.camino;
}



Point.prototype.setCalle = function(calle) {
    this.calle = calle;
}

Point.prototype.getCalle = function() {
    return this.calle;
}


Point.prototype.setNro = function(nro) {
    this.nro = nro;
}

Point.prototype.getNro = function() {
    return this.nro;
}

Point.prototype.setLocalidad = function(localidad) {
    
    this.localidad = localidad;
}

Point.prototype.getLocalidad = function() {
    return this.localidad;
}

Point.prototype.setProvincia = function(provincia) {
    this.provincia = provincia;
}

Point.prototype.getProvincia = function() {
    return this.provincia;
}

Point.prototype.setTitle = function(titulo) {
    this.titulo = titulo;
}

Point.prototype.getTitle = function() {
    return this.titulo;
}


Point.prototype.getAddress = function() {
   
    var address = "";

    if (this.getCalle()) {
        if (this.getNro()) {
            address += this.getCalle() + " " + this.getNro();
        }
    }

    if (this.getLocalidad()) {
        address += "," + this.getLocalidad();
    }

    if (this.getProvincia()) {
        address += "," + this.getProvincia();

    }

    return address;

}


Point.prototype.setShowDialog = function(valor) {
    this.showDialogs = valor;
}

Point.prototype.showDialog = function() {
    return this.showDialogs;
}


Point.prototype.setDialog = function(contentDialog) {
    this.contentDialog = contentDialog;
}


Point.prototype.setResponse = function(valor) {
    this.response = valor;
}

Point.prototype.getResponse = function() {
    return this.response;
}


Point.prototype.getComoLlegar = function(indexMap) {
var ciudadOrigen = this.getAddress();
    var salida = "";

    salida += "<div id=\"como_llegar\" class=\"mapa_ubicacion\">";

    salida += "     Como llegar : ";

    salida += "     <a onclick=\"showText('from'," + this.getDk() + ",'" + ciudadOrigen + "',"+indexMap+");\" style=\"cursor:pointer;\">Hasta Aqu&iacute;</a>";
    salida += "     &nbsp; - &nbsp;";
    salida += "     <a onclick=\"showText('to'," + this.getDk() + ",'" + ciudadOrigen + "',"+indexMap+");\" style=\"cursor:pointer;\" >Desde Aqu&iacute;</a> ";

    salida += "     <div id=\"c_from_" + this.getDk() + "\" style=\"display:none;\" class=\"direccion\" >";
    salida += "     Direcci&oacute;n Origen";
    salida += "     <input type=\"text\" size=\"25\" id=\"fromAddress_" + this.getDk() + "\" name=\"from\"";
    salida += "     value=\"\"/>";
    salida += "     <input class=\"button_map\" type=button value='IR' onclick='setDirections(" + this.getDk() + ", " + indexMap + ")' />";


    salida += "    </div>";

    salida += "    <div id=\"c_to_" + this.getDk() + "\" style=\"display:none;\" class=\"direccion\" >";
    salida += "    Direcci&oacute;n Destino";
    salida += "    <input type=\"text\" size=\"25\" id=\"toAddress_" + this.getDk() + "\" name=\"to\"";
    salida += "    value=\"\" />";
    salida += "     <input class=\"button_map\" type=button value='IR' onclick='setDirections(" + this.getDk() + ", " + indexMap + ")' />";
    salida += "   </div>";

    salida += "   <div class=\"div_back\" id=\"back_" + this.getDk() + "\" style=\"display:none;cursor:pointer;\">";
    salida += "       <a onclick=\"volver(" + this.getDk() + ","+indexMap+");\"><< volver</a>";
    salida += "   </div>";

    salida += "</div>";

    return salida;


}

Point.prototype.getDialogResponse = function(indexMap){
	return "<div class='directionGeo'>"+this.getResponse()+"</div>";
}






Point.prototype.getDialog = function(indexMap) {
    var salida = "";
    
	
	salida += "<div class='contenidoGlobo'>";
    // agrego el contenido del usuario
    if (this.contentDialog){
        salida += this.contentDialog;
    }
    
    // agrego le componente de como llegar
    if (this.getCamino()){
        
        salida += this.getComoLlegar (indexMap);
    
    }
	
	if (this.getResponse()){
        
        salida += this.getDialogResponse ();
    
    }
       
    salida += "</div>";
    return salida;

}


