function displayYear(){
	var year=new Date();
	year=year.getYear();
	if (year<1900){
		year+=1900;
	}
	document.write(year);
	return;
}

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;

var oldbackground='';
var selectedLoc = '';
var dirFrom = '';
var infoWindowContentStart = "<table id='infowindowcontent' width='400'><tr><td width='50%'><strong>Sunrise Oilfield Supply</strong>"
var infoWindowContentEnd = "<br><br><a href='javascript:print();'>Print Map</a></td><td valign='top'><form onsubmit='gotoDirections(); return false;'><input id='dirFrom' type='text' value='enter address' onclick='cleardefault();'><p class='example'>(ex. Wichita, KS)</p><input type='submit' value=' Get Directions '></form></td></tr></table>";
var arrLocs =new Array();
var defaultcleared=0;

arrLocs['eldoradostore']=new Array();
arrLocs['eldoradostore']['lat'] = 37.826800;
arrLocs['eldoradostore']['long'] = -96.877000;
arrLocs['eldoradostore']['address'] = '764 N. Oil Hill Rd.';
arrLocs['eldoradostore']['address2'] = '';
arrLocs['eldoradostore']['city'] = 'El Dorado';
arrLocs['eldoradostore']['state'] = 'KS';
arrLocs['eldoradostore']['zip'] = '67042';
arrLocs['eldoradostore']['phone'] = '(316) 321-9323';

arrLocs['gardencitystore']=new Array();
arrLocs['gardencitystore']['lat'] = 37.979103;
arrLocs['gardencitystore']['long'] = -100.894412;
arrLocs['gardencitystore']['address'] = '2106 W. Jones Ave';
arrLocs['gardencitystore']['address2'] = '';
arrLocs['gardencitystore']['city'] = 'Garden City';
arrLocs['gardencitystore']['state'] = 'KS';
arrLocs['gardencitystore']['zip'] = '67846';
arrLocs['gardencitystore']['phone'] = '(620) 276-1700';

arrLocs['haysstore']=new Array();
arrLocs['haysstore']['lat'] = 38.859395;
arrLocs['haysstore']['long'] = -99.305000;
arrLocs['haysstore']['address'] = '1720 Highway 40 Bypass';
arrLocs['haysstore']['address2'] = '';
arrLocs['haysstore']['city'] = 'Hays';
arrLocs['haysstore']['state'] = 'KS';
arrLocs['haysstore']['zip'] = '67601';
arrLocs['haysstore']['phone'] = '';

arrLocs['hugotonstore']=new Array();
arrLocs['hugotonstore']['lat'] = 37.171730;
arrLocs['hugotonstore']['long'] = -101.388200;
arrLocs['hugotonstore']['address'] = '1590 W. 10th St.';
arrLocs['hugotonstore']['address2'] = 'PO Box 446';
arrLocs['hugotonstore']['city'] = 'Hugoton';
arrLocs['hugotonstore']['state'] = 'KS';
arrLocs['hugotonstore']['zip'] = '67951';
arrLocs['hugotonstore']['phone'] = '(620) 428-6604';

arrLocs['hugotonshop']=new Array();
arrLocs['hugotonshop']['lat'] = 37.170290;
arrLocs['hugotonshop']['long'] = -101.389770;
arrLocs['hugotonshop']['address'] = '1595 W. 10th St.';
arrLocs['hugotonshop']['address2'] = '';
arrLocs['hugotonshop']['city'] = 'Hugoton';
arrLocs['hugotonshop']['state'] = 'KS';
arrLocs['hugotonshop']['zip'] = '67951';
arrLocs['hugotonshop']['phone'] = '(620) 428-6617';

arrLocs['mccookstore']=new Array();
arrLocs['mccookstore']['lat'] = 40.197116;
arrLocs['mccookstore']['long'] = -100.61356;
arrLocs['mccookstore']['address'] = '101 E 9th';
arrLocs['mccookstore']['address2'] = 'PO Box 875';
arrLocs['mccookstore']['city'] = 'McCook';
arrLocs['mccookstore']['state'] = 'NE';
arrLocs['mccookstore']['zip'] = '69001';
arrLocs['mccookstore']['phone'] = '(308) 345-1542';

arrLocs['nesscitystore']=new Array();
arrLocs['nesscitystore']['lat'] = 38.467868;
arrLocs['nesscitystore']['long'] = -99.902761;
arrLocs['nesscitystore']['address'] = 'N. Hwy 283';
arrLocs['nesscitystore']['address2'] = 'PO Box 40';
arrLocs['nesscitystore']['city'] = 'Ness City';
arrLocs['nesscitystore']['state'] = 'KS';
arrLocs['nesscitystore']['zip'] = '67560';
arrLocs['nesscitystore']['phone'] = '(785) 798-3629';

arrLocs['spiveystore']=new Array();
arrLocs['spiveystore']['lat'] = 37.445624;
arrLocs['spiveystore']['long'] = -98.16973;
arrLocs['spiveystore']['address'] = '420 W. Stanley';
arrLocs['spiveystore']['address2'] = 'PO Box 37';
arrLocs['spiveystore']['city'] = 'Spivey';
arrLocs['spiveystore']['state'] = 'KS';
arrLocs['spiveystore']['zip'] = '67142';
arrLocs['spiveystore']['phone'] = '(620) 532-5261';

arrLocs['wichitastore']=new Array();
arrLocs['wichitastore']['lat'] = 37.685879;
arrLocs['wichitastore']['long'] = -97.335715;
arrLocs['wichitastore']['address'] = '105 S. Broadway';
arrLocs['wichitastore']['address2'] = 'Suite 610';
arrLocs['wichitastore']['city'] = 'Wichita';
arrLocs['wichitastore']['state'] = 'KS';
arrLocs['wichitastore']['zip'] = '67202';
arrLocs['wichitastore']['phone'] = '(316) 263-6060';

function openMap(location) {
	selectedLoc = location;
	Lightview.show({
		href: 'map.html',
		rel: 'iframe', 
		title: 'Directions to Sunrise'
	  });
}
function showMap(location) {
	selectedLoc = location;
	defaultcleared = 0;
  if (GBrowserIsCompatible()) {
	var locmap = new GMap2(document.getElementById('mapbox'));
	var currloc = new GLatLng(arrLocs[selectedLoc]['lat'],arrLocs[selectedLoc]['long']);
				
	locmap.setCenter(currloc, 14);
	//locmap.setMapType(G_ROAD_MAP);
	locmap.addOverlay(new GMarker(currloc));
	
	
	/*
	if (geocoder) {
        geocoder.getLatLng(
          buildToAddress(),
          function(point) {
            if (!point) {
              alert(" not found");
            } else {
			alert(point);
              locmap.setCenter(point, 13);
              var marker = new GMarker(point);
			  
				locmap.setMapType(G_HYBRID_MAP);
				locmap.addOverlay(marker);
				locmap.openInfoWindowHtml(locmap.getCenter(),infowindowHTML(selectedLoc));
				locmap.setUIToDefault();
              //locmap.addOverlay(marker);
              //locmap.openInfoWindowHtml(buildToAddress());
            }
          }
        );
      }*/
	
	locmap.openInfoWindowHtml(locmap.getCenter(),infowindowHTML(selectedLoc));
			
	locmap.setUIToDefault();
	/*
	Lightview.show({
		href: 'map.html',
		rel: 'iframe', 
		title: 'Directions to Sunrise'
	  });
	*/
  }
}

function infowindowHTML(selectedLoc) {
	selectedHTML = infoWindowContentStart + '<br>' + arrLocs[selectedLoc]['address'];
	if(arrLocs[selectedLoc]['address2'].length > 0){
		selectedHTML = selectedHTML + '<br>' + arrLocs[selectedLoc]['address2'];
	}
	selectedHTML = selectedHTML + '<br>' + arrLocs[selectedLoc]['city'] + ', ' + arrLocs[selectedLoc]['state'] + ' ' + arrLocs[selectedLoc]['zip'];
	selectedHTML = selectedHTML + '<br>' + arrLocs[selectedLoc]['phone'];
	selectedHTML = selectedHTML + infoWindowContentEnd;
	
	return selectedHTML;
}


function gotoDirections(){
	//Lightview.hide();
	if(document.getElementById('dirFrom').value.length > 0){
		parent.dirFrom = document.getElementById('dirFrom').value;
		/*Lightview.show({
			href: 'directions.html',
			rel: 'iframe', 
			title: 'Directions to Sunrise'
		  });*/
		document.location.href='directions.html';
	} else {
		alert('Please enter a From location.');
	}
}
		
function cleardefault(){
	if(!defaultcleared){
		document.getElementById('dirFrom').value = '';
	}
	defaultcleared = 1;
}

