// Validating script for the picture upload forms
// ----------------------------------------------
// (c) 2001-2002 Alpinet.org 
// djonexx, 17/05/2002 - added remote scripting support
// djonexx, 23/02/2003 - added client-side image validation
// djonexx, 03/03/2003 - fixed client-side image validation in IE
// djonexx, 08/03/2003 - fixed client-side image validation 
// djonexx, 09/11/2004 - removed wallpapers in 640x480 and 800x600 sizes... we live in the 21st century...
// djonexx, 15/10/2005 - fixed stuff
// djonexx, 12/10/2006 - fixed client-side image validation in IE 7; made asynchronous wait for picture to completely load.

var res_sMissingFotoName = "res_sMissingFotoName";
var res_sMissingAlbumName = "res_sMissingAlbumName";
       
function listCallback(resultString) {

try
{   
  completeFillList(resultString);
}
catch(e)
{

}
  getById("f","zonaid").disabled = false;
}

function zonachange() {

  var f = document.getElementById("f");
  
  if(document.layers) {

	  if(f == null) return false;
	  
	  if(f.zonaid.value != -1) {
	    f.assoc.value = "1";
	    if(f.fisier.value != "")
	      f.fisier.value = "";
	    return f.submit();
	  }
	  return true;
  }
  //window.alert(jsrsBrowserSniff());
  if(jsrsBrowserSniff() == "IE" || jsrsBrowserSniff() == "MOZ" ) { /* we're remote-scripting enabled */
	  rsObject = "http://alpinet.org/bin/rs/rsuigen.php";
	  getById("f", "zonaid").disabled = true;
	  fillList(getById("f", "punctid"), "listPoints", listCallback, getById("f", "zonaid").value);
  }
  
  return true;
}  
  

function checkFormData(bCheckPic) 
{
	try 
  {
		
		if(getById("f", "nume").value == "") { 
			alert(res_sMissingFotoName);
			getById("f", "nume").focus();
			return false;
		}
	  
		if ((getById("f", "taraid") != null) && (getById("f", "taraid").value< 0)) {
			alert(res_sMissingCountry);
			getById("f", "taraid").focus();
			return false;
		}
		
		if(bCheckPic && (false == foto_verifica())) 
			return false;
				
		return true;	
	} 
  catch(e) 
  {
		window.alert(e);
	}
	return false;
}

function foto_verifica() {

	var sizesH = null;
	try {
		var f = getById("f", "fisier");
	
		if((f.value.toLowerCase().indexOf('.jpg') == f.value.length-4) ||
		    (f.value.toLowerCase().indexOf('.jpeg') == f.value.length-5))
		{										
			return true;
		}
	}
	catch(e)
	{
	    window.alert('exception: ' + e.toString());
	}
	return false;
}

function album_checkForm() {
	try {	  
		if(getById("f", "nume").value == "") 
    { 
			alert(res_sMissingAlbumName);
			getById("f", "nume").focus();
			return false;
		}
				
		return true;	
	} catch(e) {
		
	}
	return false;
}

// -- show picture

var _showMapContainer;
var _showZoomLevel;
var _showLat = null;
var _showLon = null;
var _showTitle;

function ShowPictureOnMap(idMapContainer, zoomLevel, lat, lon, title)
{
  _showMapContainer = document.getElementById(idMapContainer);
  if(lat != '' && lon != '')
  {    
    _showZoomLevel = parseInt(zoomLevel);
    _showLat = parseFloat(lat);
    _showLon = parseFloat(lon);
    _showTitle = title;    
    //libAddEvent(window, 'load', PictureOnMap_onGmapInit);         
  }  
  else
  {    
    _showMapContainer.innerHTML = title;
  }
}

var _map = null;
var _centerPoint = null;
var _marker = null;


function PictureOnMap_Refresh()
{
  if(_map == null && _showLat != null && _showLon != null)
  {
    _centerPoint = new google.maps.LatLng(_showLat, _showLon);
    var mapOptions = {
      center: _centerPoint,
      zoom: _showZoomLevel,
      mapTypeId: google.maps.MapTypeId.HYBRID       
    };
    _map = new google.maps.Map(_showMapContainer, mapOptions);  
    _marker = new google.maps.Marker(
      {
        position: _centerPoint, 
        title: _showTitle, 
        map: _map 
      });
  }
}

