// JavaScript Document

function locationInput(in_out){
	if(in_out == 'in'){
		if($('location').value=="city, state ??"){
			$('location').value = "";
		}
	}
	else if(in_out == 'out'){
		if($('location').value==""){
			$('location').value = "city, state ??";
		}
	}
}

function websiteInput(in_out){
		if($('website').value==""){
			$('website').value = "http://";
		}
}
function firstNameInput(in_out){
	if(in_out == 'in'){
		if($('first_name').value=="First"){
			$('first_name').value = "";
		}
	}
	else if(in_out == 'out'){
		if($('first_name').value==""){
			$('first_name').value = "First";
		}
	}
}
function lastNameInput(in_out){
	if(in_out == 'in'){
		if($('last_name').value=="Last"){
			$('last_name').value = "";
		}
	}
	else if(in_out == 'out'){
		if($('last_name').value==""){
			$('last_name').value = "Last";
		}
	}
}

function openContactForm(){
	$('contactFormBox').tween('height', 405);
	var req = new Request.HTML({  
			method: 'post',  
			url: 'contact.php',  
			data: {
			'ajaxAction' : "showContactForm"
			},
			onRequest: $('contactFormBox').innerHTML = "loading...<br /><img src='images/ajax_loader.gif />",  
			onSuccess: function(html) {
				$('contactFormBox').set('text', '');
				$('contactFormBox').adopt(html);
			},
			evalResponse: true
		}).send();
}
function closeContactForm(){
	$('contactFormBox').tween('height', 0);
	$('contactFormBox').innerHTML = ""; 
	$('map_canvas').tween('height', 0);
	$('map_canvas').innerHTML = ""; 
}
function submitContactForm(){
	//alert('SUBMITTED CONTACT FORM');
	//$('contact_form').submit();
	//console.log($('validated').value);
	
	

	var req = new Request.JSON({  
		method: 'post',  
		url: 'contact.php',  
		data: $('contact_form'),  
		onRequest: $('dialogueBoxErrors').innerHTML = "validating ...",  
		onSuccess: function(response) {
			//console.log(response);
			//console.log(response.fields[0].name);
			for(i=0; i<response.fields.length; i++){
				//console.log(response.fields[i].name);
				if(response.fields[i].success=='false'){
					$(response.fields[i].name).tween('border', '2px solid #ff0099');
				} else if(response.fields[i].success=='true'){
					$(response.fields[i].name).tween('border', '1px solid #fff');
				}
			}
			if(response.success=='true'){
				$('dialogueBoxErrors').innerHTML = "";
				$('ajaxAction').value = '';
				$('postAction').value = 'formPosted';
				$('contact_form').submit();
				
			} else {
				$('dialogueBoxErrors').innerHTML = "Oops, please fix the hilited fields.";
			}
		},
		evalScripts: true
	}).send();
	
	return false;
}
function openShowInfo(event_id){
	$('contactFormBox').tween('height', 200);
	$('contactFormBox').setStyle('overflow', 'auto');
		$('map_canvas').innerHTML = "";
		$('map_canvas').tween('height', 300);
	var req = new Request.HTML({  
			method: 'post',  
			url: 'ajax.php',  
			data: {
			'ajaxAction' : "openShowInfo",
			'event_id' : event_id
			},
			onRequest: $('contactFormBox').innerHTML = "loading...<br /><img src='images/ajax_loader.gif />",  
			onSuccess: function(html) {
				$('contactFormBox').set('text', '');
				$('contactFormBox').adopt(html);
			},
			evalResponse: true
		}).send();
}


function loadAllShows(){
	$('contactFormBox').tween('height', 400);
	$('contactFormBox').setStyle('overflow', 'scroll');
	var req = new Request.HTML({  
			method: 'post',  
			url: 'ajax.php',  
			data: {
			'ajaxAction' : "openAllShows"
			},
			onRequest: $('contactFormBox').innerHTML = "loading...<br /><img src='images/ajax_loader.gif />",  
			onSuccess: function(html) {
				$('contactFormBox').set('text', '');
				$('contactFormBox').adopt(html);
			},
			evalResponse: true
		}).send();
}

var map = null;
    var geocoder = null;
 
function initializeGmap() {
      if (GBrowserIsCompatible()) {
        map = new GMap2($("map_canvas"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 13);
		map.setMapType(G_NORMAL_MAP);
		var mapControl = new GLargeMapControl();
		map.addControl(mapControl);
		var mapTypeControl = new GMapTypeControl ();
		map.addControl(mapTypeControl);
        geocoder = new GClientGeocoder();
      }
    }
	function showAddress(address) {
      if (geocoder) {
        geocoder.getLocations(
          address,
          function(response) {
            map.clearOverlays();
			if (!response || response.Status.code != 200) {
				alert("Sorry, we were unable to geocode that address");
			 } else {
				place = response.Placemark[0];
				point = new GLatLng(place.Point.coordinates[1],
									place.Point.coordinates[0]);
				marker = new GMarker(point);
				map.addOverlay(marker);
				marker.openInfoWindowHtml("<br />" + place.address);
			  }
          }
        );
      }
    }
