function ge(a)
{
	return document.getElementById(a);	
}

function clearField(a)
{
	if(ge(a).innerHTML)
	{
		ge(a).innerHTML='';
	}
	if(ge(a).value)
	{
		ge(a).value='';
	}
}

function checkErrors()
{
	var message='';
	if(errorsArray.length>0)
	{
		//for(var item in	errorsArray)
		//{
			//message	+= "Please ensure "+ errorsArray[item] +" is filled in\n";
		//}
		message="Please ensure all fields are filled in.\nThank you for your understanding";
		alert(message);
	}else{
		ge(form).submit();
	}
	errorsArray=[];
}

function moveToMap()
{
	var l=ge('left_locationChoice').value;	
	window.open("/malta-location/"+l,"_self");
	
	
}

var lat,long;
var locations = new Array();
var infowindow = new Array();
var contentString = new Array();
var listener = new Array();


function initialize() {
	//alert(locations);
    var latlng = new google.maps.LatLng(lat, long);
	//alert(lat);
    var myOptions = {
      zoom: 15,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(ge("pharmacy_map"),
        myOptions);
	
	//creating all markers
	var marker;
	




	for(var i=0;i<locations.length;i++)
	{
		  latlng = new google.maps.LatLng(locations[i][1], locations[i][2]);
		  marker = new google.maps.Marker({
		  	position: latlng, 
		  	map: map, 
		  	title:"Brown's Pharmacy - "+ locations[i][0] +"",
			clickable: true 
	 	  });
      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][3]);
          infowindow.open(map, marker);
        }
      })(marker, i));



  	infowindow = new google.maps.InfoWindow();



	}
  
}

function showInfoWindow(i) {
	//alert(i);
	  infowindow.setContent(contentString[i]);
  	  infowindow.setPosition(new google.maps.LatLng(locations[i][1], locations[i][2]));
	//alert(event.latlng);
}

function checkPage()
{
	if(ge("g_map"))
	{
		initialize();
	}
	startTopImageChanger('#top_stock','#topstockimage');
}

var err='';
var formError='';

function submit_reservation()
{
	formError='';
	if(ge('res_fname').value==''){formError+="Please Enter your First Name\n";}
	if(ge('res_lname').value==''){formError+="Please Enter your Last Name\n";}
	if(ge('res_telephone').value==''){formError+="Please Enter a Telephone Number\n";}
	validate_email('res_email',"Please Enter a Valid Email Address\n");
	if(!formError==''){alert(formError); return false;}
	return true;
}

function submit_contactus()
{
	formError='';
	if(ge('con_fname').value==''){formError+="Please Enter your First Name\n";}
	if(ge('con_lname').value==''){formError+="Please Enter your Last Name\n";}
	if(ge('con_telephone').value==''){formError+="Please Enter a Telephone Number\n";}
	if(ge('con_message').value==''){formError+="Please Enter your Message\n";}
	validate_email('con_email',"Please Enter a Valid Email Address\n");
	if(!formError==''){alert(formError); return false;}
	return true;
}

function validate_email(field,alerttxt){
  //emailError='';
  var apos=ge(field).value.indexOf("@");
  var dotpos=ge(field).value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2){
	formError+=alerttxt+'\n';
	return false;}
  return true;
}


