// Initialize the object:
var ajax = false;

// Create the object...

// Choose object type based upon what's supported:
if (window.XMLHttpRequest) {

	// IE 7, Mozilla, Safari, Firefox, Opera, most browsers:
	ajax = new XMLHttpRequest();
	
} else if (window.ActiveXObject) { // Older IE browsers

	// Create type Msxml2.XMLHTTP, if possible:
	try {
		ajax = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e1) { // Create the older type instead:
		try {
			ajax = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e2) { }
	}
	
}

function update_photoset(photosetId, gallery) {
	if (ajax) { // Confirm that the object is usable
		form=document.getElementById('form_import_'+photosetId);
		loading=document.getElementById('import_'+photosetId);
		form.style.display="none";
		loading.style.display="block";
		showPleaseWait(true);
		ajax.open('get', '/members/membership_flickr_ajax.php?photosetId=' + encodeURIComponent(photosetId) + '&gallery=' + encodeURIComponent(gallery));
		ajax.onreadystatechange = function(){
			if(ajax.readyState == 4){
				form.style.display="block";
				loading.style.display="none";
				showPleaseWait(false);
			}
		}

		ajax.send(null); // Send the request
	}
}

function imageLoadComplete(image,width,height){
//	height=100;
//	var aspect=image.height/image.width;
//	image.style.visibility="hidden";
//	if(image.height>height){
//	
//		image.style.height=height;
//		//image.style.width=parseInt(image.style.width*aspect);
//		
//	}else{
//		if(image.width>width){
//			image.style.height=height/aspect;
//			image.style.width=width;
//		}
//	}
//	image.style.visibility="visible";

}

function showPleaseWait(show){
	box=document.getElementById("please_wait");
	if(show){
		box.style.display="block";
	}else{
		box.style.display="none";
	}
}


function insertIns(){
	//ins=document.getElementById("ins11");
	//ins.innerHTML="<td><p>If you need to insure your custom car then check out Cheap Car Insurance to get a quote</p><p><a href=\"http://www.cheapcarinsurance.net\" target=\"_blank\" title=\"Cheap Car Insurance\">Cheap Car Insurance</a></p>";

	ins=document.getElementById("auto1");
	ins.innerHTML="<p><a href=\"http://www.autoshowvents.com\" target=\"_blank\" title=\"Auto Show Event Coverage\">Auto Show Event Coverage</a></p></td>";
}

function insertExtLinks(){
	ins=document.getElementById("extlinks");
	var topLimit=8
	var relLimit=5
	var limit=4
	var html="";
	
	if(Math.floor(Math.random()*11)<relLimit){
		html=html+'<p><a href="http://cars.88000.org/">Sexy Wallpaper</a></a></p>'
	}
	if(Math.floor(Math.random()*11)<relLimit){
		html=html+'<p><a href="http://www.cognitivedistortion.com/">Desktop Wallpaper</a></a></p>'
	}
	if(Math.floor(Math.random()*11)<topLimit){
		html=html+'<p><a href="http://www.real-tuning.com/"><img src="http://www.real-tuning.com/button.php?u=david_lamerton" alt="Tuning Cars top news hot rod wallpaper" border="0" /></a></p>'
	}
	if(Math.floor(Math.random()*11)<relLimit){
		html=html+'<p><a href="http://www.top50wallpaper.com/enter.php?dlamerton"><img src="/images/top50wallpaperButton7.gif"/></a></p>';
	}
	if(Math.floor(Math.random()*11)<relLimit){
		html=html+'<p><a href="http://computerwallpapers.onlytopsites.com/?rm=vote&link_id=875" target="_blank" >Vote For This Site - Click Here</a><p>';
	}
       	if(Math.floor(Math.random()*11)<relLimit){
       		html=html+'<p><a href="http://www.wallpaperama.com/" title="wallpaperama"><img src="http://www.wallpaperama.com/images/wallpaperama.gif" width="88" height="31" alt="wallpaperama banner" border="0"><p>';
	}
	if(Math.floor(Math.random()*11)<topLimit){
		html=html+'<p><a href="http://www.fastcarsites.com/action.asp?site=2649&action=in" target="_blank" title="Fast Car Sites"><img width="100" src="/images/fastcarsites_com_120x90.gif"/></a><br/>Fast Car Sites</p>';
	}
	if(Math.floor(Math.random()*11)<relLimit){
		html=html+'<p><a href="http://www.super-trucks.net/action.asp?site=14997&action=in" target="_blank" title="Super Trucks"><img width="100" src="/images/super-trucks_net_120x90.gif"/></a><br/>Super Trucks Car Sites</p>';
	}
	if(Math.floor(Math.random()*11)<relLimit){
		html=html+'<p><a href="http://www.veedub.com/action.asp?site=691&action=in" target="_blank" title="Top VW Sites"><img width="100" src="/images/veedub_com_120x90.gif"/></a><br/>Top VW Sites</p>';
	}
	if(Math.floor(Math.random()*11)<relLimit){
		html=html+'<p><a href="http://www.customcarsites.com/action.asp?site=552&action=in" target="_blank" title="Top Custom Car Sites"><img width="100" src="/images/customcarsites_com_125x30.gif"/></a><br/>Top Custom Car Sites</p>';
	}
	if(Math.floor(Math.random()*11)<relLimit){
		html=html+'<p><a href="http://www.musclecarsites.net/action.asp?site=496&action=in" target="_blank" title="Top Muscle Car Sites"><img width="100" src="/images/musclecarsites_net_120x90.gif"/></a><br/>Top Muscle Car Sites</p>';
	}
	if(Math.floor(Math.random()*11)<relLimit){
		html=html+'<p><a href="http://www.performance100.net/action.asp?site=10022&action=in" target="_blank" title="The Performance 100"><img width="100" src="/images/performance100_net_120x90.gif"/></a><br/>The Performance 100</p>';
	}
	if(Math.floor(Math.random()*11)<relLimit){
		html=html+'<p><a href="http://www.customtrucksites.com/action.asp?site=546&action=in" target="_blank" title="Top Custom Truck Sites"><img width="100" src="/images/customtrucksites_com_120x90.gif"/></a><br/>Top Custom Truck Sites</p>';
	}
	if(Math.floor(Math.random()*11)<relLimit){
		html=html+'<p><a href="http://www.toplowridersites.com/action.asp?site=2520&action=in" target="_blank" title="Top Lowrider sites"><img width="100" src="/images/toplowridersites_com_120x90.gif"/></a><br/>Top Lowrider Sites</p>';
	}
	if(Math.floor(Math.random()*11)<relLimit){
		html=html+'<p><a href="http://www.topcarsites.net/action.asp?site=4763&action=in" target="_blank" title="Top Car sites"><img width="100" src="/images/topcarsites_net_120x90.gif"/></a><br/>Top Car Sites</p>';
	}
	if(Math.floor(Math.random()*11)<relLimit){
		html=html+'<p><a href="http://www.toptrucksites.net/action.asp?site=1008&action=in" target="_blank" title="Top Truck sites"><img width="100" src="/images/toptrucksites_net_120x90.gif"/></a><br/>Top Truck Sites</p>';
	}
	if(Math.floor(Math.random()*11)<relLimit){
		html=html+'<p><a href="http://www.ultimate-top100.com/car-and-truck-sites/php/in.php?id=dlamerto" target="_blank" title="Ultimate Top 100"><img width="100" src="/images/button-01.gif"/></a><br/>Ultimate Top 100</p>';
	}
	
	if(Math.floor(Math.random()*11)<limit){
		html=html+'<p><a href="http://www.carsnmodels.net/action.asp?site=2038&action=in" target="_blank" title="Cars and Models"><img width="100" src="/images/carsnmodels_net_120x90.gif"/></a><br/>Cars and Models</p>';
	}
	if(Math.floor(Math.random()*11)<limit){
		html=html+'<p><a href="http://www.exoticcarsites.com/action.asp?site=3346&action=in" target="_blank" title="Exotic Car Sites"><img width="100" src="/images/exoticcarsites_com_120x90.gif"/></a><br/>Exotic Car Sites</p>';
	}
	if(Math.floor(Math.random()*11)<limit){
		html=html+'<p><a href="http://www.hotcarshotbabes.net/action.asp?site=1249&action=in" target="_blank" title="Hot Cars and Babes"><img width="100" src="/images/hotcarshotbabes_net_120x90.gif"/></a><br/>Hot Cars and Babes</p>';
	}
	if(Math.floor(Math.random()*11)<limit){
		html=html+'<p><a href="http://www.motorpix.net/action.asp?site=3051&action=in" target="_blank" title="Motor Pix"><img width="100" src="/images/motorpix_net_120x90.gif"/></a><br/>Motor Pix</p>';
	}
	if(Math.floor(Math.random()*11)<limit){
		html=html+'<p><a href="http://www.performancebmw.com/action.asp?site=455&action=in" target="_blank" title="Performance BMW"><img width="100" src="/images/performancebmw_com_120x90.gif"/></a><br/>Performance BMW</p>';
	}
	if(Math.floor(Math.random()*11)<limit){
		html=html+'<p><a href="http://www.performancegti.net/action.asp?site=2932&action=in" target="_blank" title="Performance GTI"><img width="100" src="/images/performancegti_net_120x90.gif"/></a><br/>Performance GTI</p>';
	}
	if(Math.floor(Math.random()*11)<limit){
		html=html+'<p><a href="http://www.super-cars.net/action.asp?site=4637&action=in" target="_blank" title="Super Cars"><img width="100" src="/images/super-cars_net_120x90.gif"/></a><br/>Super Cars</p>';
	}
	if(Math.floor(Math.random()*11)<limit){
		html=html+'<p><a href="http://www.topcruisesites.net/action.asp?site=5360&action=in" target="_blank" title="Top Cruise Sites"><img width="100" src="/images/topcruisesites_net_120x90.gif"/></a><br/>Top Cruise Sites</p>';
	}
	if(Math.floor(Math.random()*11)<limit){
		html=html+'<p><a href="http://www.topimportsites.net/action.asp?site=2416&action=in" target="_blank" title="Top Import Sites"><img width="100" src="/images/topimportsites_net_120x90.gif"/></a><br/>Top Import Sites</p>';
	}
	if(Math.floor(Math.random()*11)<limit){
		html=html+'<p><a href="http://www.topmarques.net/action.asp?site=2395&action=in" target="_blank" title="Top Marques"><img width="100" src="/images/topmarques_net_120x90.gif"/></a><br/>Top Marques</p>';
	}
	if(Math.floor(Math.random()*11)<limit){
		html=html+'<p><a href="http://www.ukcarsites.com/action.asp?site=1512&action=in" target="_blank" title="Top UK Sites"><img width="100" src="/images/ukcarsites_com_120x90.gif"/></a><br/>Top UK Sites</p>';
	}
	if(Math.floor(Math.random()*11)<limit){
		html=html+'<p><a href="http://www.elitetop50.com/cgi-bin/rankem.cgi?id=dlamerto" target="_blank" title="Elite Top 50"><img width="100" src="/images/top50.gif"/></a><br/>Elite Top 50</p>';
	}
	if(Math.floor(Math.random()*11)<limit){
		html=html+'<p><a href="http://usa.ultimatetopsites.com/bin/topsite.cgi?topcarsites&cat=kewl&ID=45" target="_blank" title="Ultimate Top Sites"><img width="100" src="http://usa.ultimatetopsites.com/bin/votepicture.art?topcarsites&cat=kewl&ID=45"/></a><br/>Ultimate Top Sites</p>';
	}

	ins.innerHTML=html;

}

function delete_photo(gallery, imgName) {
	if (ajax) { // Confirm that the object is usable
		showPleaseWait(true);
		ajax.open('get', '/gallery/create_gallery_page_step2_delete.php?gallery=' + encodeURIComponent(gallery) + '&img=' + encodeURIComponent(imgName));
		ajax.onreadystatechange = function(){
			if(ajax.readyState == 4){
				showPleaseWait(false);
				var d = document.getElementById('thumbnails');
				var olddiv = document.getElementById(imgName);
				d.removeChild(olddiv);
			}
		}

		ajax.send(null); // Send the request
	}
}

function copyToClipBoard(sContents)
{
	clipboardData.setData("text", sContents);
	alert("The contents have been copied to your clipboard.\t");
}


//---------------------------------------------------------
//GOOGLE MAPS
//---------------------------------------------------------
function MapTypeControl(opt_opts) {
  this.options = opt_opts || {};
}

MapTypeControl.prototype = new GControl();

MapTypeControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  var me = this;
  var mapDiv = me.createButton_("Map");
  var satDiv = me.createButton_("Satellite");
  var hybDiv = me.createButton_("Hybrid");
  var phyDiv = me.createButton_("Terrain");
 
  me.assignButtonEvent_(mapDiv, map, G_NORMAL_MAP, [phyDiv, satDiv, hybDiv]);
  me.assignButtonEvent_(phyDiv, map, G_PHYSICAL_MAP, [mapDiv, satDiv, hybDiv]);
  me.assignButtonEvent_(satDiv, map, G_SATELLITE_MAP, [phyDiv, mapDiv, hybDiv]);
  me.assignButtonEvent_(hybDiv, map, G_HYBRID_MAP, [phyDiv, satDiv, mapDiv]);
  GEvent.addListener(map, "maptypechanged", function() {
    if (map.getCurrentMapType() == G_NORMAL_MAP) {
      GEvent.trigger(mapDiv, "click"); 
    } else if (map.getCurrentMapType() == G_PHYSICAL_MAP) {
      GEvent.trigger(phyDiv, "click");
    } else if (map.getCurrentMapType() == G_SATELLITE_MAP) {
      GEvent.trigger(satDiv, "click");
    } else if (map.getCurrentMapType() == G_HYBRID_MAP) {
      GEvent.trigger(hybDiv, "click");
    }
  });

  container.appendChild(mapDiv);
  container.appendChild(satDiv);
  container.appendChild(hybDiv);
  container.appendChild(phyDiv);

  map.getContainer().appendChild(container);

  GEvent.trigger(map, "maptypechanged");
  return container;
}

MapTypeControl.prototype.createButton_ = function(text) {
  var buttonDiv = document.createElement("div");
  this.setButtonStyle_(buttonDiv);
  buttonDiv.style.cssFloat = "left";
  buttonDiv.style.styleFloat = "left";
  var textDiv = document.createElement("div");
  textDiv.appendChild(document.createTextNode(text));
  textDiv.style.width = "6em";
  buttonDiv.appendChild(textDiv);
  return buttonDiv;
}

MapTypeControl.prototype.assignButtonEvent_ = function(div, map, mapType, otherDivs) {
  var me = this;

  GEvent.addDomListener(div, "click", function() {
    for (var i = 0; i < otherDivs.length; i++) {
      me.toggleButton_(otherDivs[i].firstChild, false);
    }
    me.toggleButton_(div.firstChild, true);
    map.setMapType(mapType);
  });
}

MapTypeControl.prototype.toggleButton_ = function(div, boolCheck) {
   div.style.fontWeight = boolCheck ? "bold" : "";
   div.style.border = "1px solid white";
   var shadows = boolCheck ? ["Top", "Left"] : ["Bottom", "Right"];
   for (var j = 0; j < shadows.length; j++) {
     div.style["border" + shadows[j]] = "1px solid #b0b0b0";
  } 
}

MapTypeControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7));
}

MapTypeControl.prototype.setButtonStyle_ = function(button) {
  button.style.color = "#000000";
  button.style.backgroundColor = "white";
  button.style.font = "small Arial";
  button.style.border = "1px solid black";
  button.style.padding = "0px";
  button.style.margin= "0px";
  button.style.textAlign = "center";
  button.style.fontSize = "12px"; 
  button.style.cursor = "pointer";
}

function computepos (point)
{
	var latA = Math.abs(Math.round(value=point.y * 1000000.));
	var lonA = Math.abs(Math.round(value=point.x * 1000000.));

	if(value=point.y < 0)
	{
		var ls = '-' + Math.floor((latA / 1000000));
	}
	else
	{
		var ls = Math.floor((latA / 1000000));
	}

	var lm = Math.floor(((latA/1000000) - Math.floor(latA/1000000)) * 60);
	var ld = ( Math.floor(((((latA/1000000) - Math.floor(latA/1000000)) * 60) - Math.floor(((latA/1000000) - Math.floor(latA/1000000)) * 60)) * 100000) *60/100000 );

	if(value=point.x < 0)
	{
	  var lgs = '-' + Math.floor((lonA / 1000000));
	}
	else
	{
		var lgs = Math.floor((lonA / 1000000));
	}

	var lgm = Math.floor(((lonA/1000000) - Math.floor(lonA/1000000)) * 60);
	var lgd = ( Math.floor(((((lonA/1000000) - Math.floor(lonA/1000000)) * 60) - Math.floor(((lonA/1000000) - Math.floor(lonA/1000000)) * 60)) * 100000) *60/100000 );

	document.getElementById("latbox").value=point.y;
	document.getElementById("lonbox").value=point.x;
}

function showAddress(address) {
 if (geocoder) {
	 geocoder.getLatLng(
	 address,
	 function(point) {
	 if (!point) {
		 alert(address + " not found");
		 } else {
			 posset = 1;

			 map.setMapType(G_HYBRID_MAP);
			 map.setCenter(point,16);
			 zm = 1;
			 marker.setPoint(point);
			 GEvent.trigger(marker, "click");
		 }
	 }
 );
 }
}

function showLatLong(latitude, longitude) {
	if (isNaN(latitude)) {
		alert(' Latitude must be a number. e.g. Use +/- instead of N/S');
		return false;
	}
	if (isNaN(longitude)) {
		alert(' Longitude must be a number.  e.g. Use +/- instead of E/W');
		return false;
	}

	latitude1 = Math.abs( Math.round(latitude * 1000000.));
	if(latitude1 > (90 * 1000000)) {
		alert(' Latitude must be between -90 to 90. ');
		document.getElementById("latbox1").value='';
		return;
	}

	longitude1 = Math.abs( Math.round(longitude * 1000000.));
	if(longitude1 > (180 * 1000000)) {
		alert(' Longitude must be between -180 to 180. ');
		document.getElementById("lonbox1").value='';
		return;}

	var point = new GLatLng(latitude,longitude);

	posset = 1;

	if (zm == 0)
	{
		map.setMapType(G_HYBRID_MAP);
		map.setCenter(point,16);
		zm = 1;
	}
	else
	{
		map.setCenter(point);
	}

	var html = "";
	html += html + "Latitude, Longitude<br>" + point.toUrlValue(6);

	var baseIcon = new GIcon();
	baseIcon.iconSize=new GSize(32,32);
	baseIcon.shadowSize=new GSize(56,32);
	baseIcon.iconAnchor=new GPoint(16,32);
	baseIcon.infoWindowAnchor=new GPoint(16,0);
	var thisicon = new GIcon(baseIcon, "/images/blue-dot.png", null, "/images/msmarker.shadow.png");

	var marker = new GMarker(point,thisicon);
	GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
	map.addOverlay(marker);

	GEvent.trigger(marker, "click");
}
var map = null;
var geocoder = null;
var latsgn = 1;
var lgsgn = 1;
var zm = 0;
var marker = null;
var posset = 0;

function xz() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(20.0, -10.0), 2);
		map.setMapType(G_NORMAL_MAP);
		map.addControl(new GLargeMapControl());
		map.addControl(new MapTypeControl());
		map.addControl(new GScaleControl());
		map.enableScrollWheelZoom();
		map.disableDoubleClickZoom();
		geocoder = new GClientGeocoder();

		marker = new GMarker(new GLatLng(20.0, -10.0), {draggable: true});
		map.addOverlay(marker);

		GEvent.addListener(map, 'click', function(overlay,point)
		{
			if (overlay)
			{
			}
			else
			{
				posset = 1;

				fc( point) ;
				//marker.setPoint(point);
				if (zm == 0)
				{
					map.setCenter(point,7); zm = 1;}
				else
				{
					map.setCenter(point);
				}
				computepos(point);
			}
		});

		GEvent.addListener(map, 'singlerightclick', function(point,src,overlay)
		{
			if (overlay)
			{
				if (overlay != marker)
				{
					map.removeOverlay(overlay)
					document.getElementById("latbox").value='';
					document.getElementById("lonbox").value='';
				}
			}
			else
			{
			}
		});

		GEvent.addListener(marker, "dragend", function() {
			var point = marker.getLatLng();
			posset = 1;

			if (zm == 0)
			{
				map.setCenter(point,7); zm = 1;
			}
			else
			{
				map.setCenter(point);
			}
			computepos(point);
		});


		GEvent.addListener(marker, "click", function() {
			var point = marker.getLatLng();
			marker.openInfoWindowHtml(marker.getLatLng().toUrlValue(6));
			computepos (point);
		});

	}
}




