var gmap = null;
var geocoder = null;
var mappoint = null;

function nothing() {}

// Image Mouse-Over
function picChange(id, url, newW, newH){
	var id = document.getElementById(id);
	id.src=url;
	id.style.width=newW;
	id.style.height=newH;
}


// Popup Window
function targetBlank(url){
   blankWin = window.open(url,'_blank','menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes');
}


// Centered Popup
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
   LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
   settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';
   win = window.open(mypage,myname,settings);
}


// Image Popup
function previewPhoto(img){
   photo1= new Image();
   photo1.src=(img);
   Control(img);
}
function Control(img){
   if((photo1.width!=0)&&(photo1.height!=0)){
      viewPhoto(img);
   }else{
      funz="Control('"+img+"')";
      inter=setTimeout(funz,20);
   }
}
function viewPhoto(img){
   width=photo1.width+20;
	height=photo1.height+20;
	LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
	params="width="+width+",height="+height+",top="+TopPosition+",left="+LeftPosition+"";
	stra=window.open(img,"",params);
}

// Google Maps
function googleMaps(lon, lat, name, location) {
	//<![CDATA[
	if (GBrowserIsCompatible()) {
		var WINDOW_HTML = "<div style=\"width: 12em; style: font-size: small; text-align:left;\">" + name + "<br />" + location + "<br /><a style=\"color: #0000ff;text-decoration:underline;\" href=\"http://www.google.com/maps/?daddr=" + location + "\" onclick=\"targetBlank(this.href);return false;\">Get Directions</a>" + "</div>";
		var icon = new GIcon();
		icon.image = "http://www.google.com/mapfiles/marker.png";
		icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		icon.iconSize = new GSize(20, 34);
		icon.shadowSize = new GSize(37, 34);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);
		
		gmap = new GMap(document.getElementById("map"));
		gmap.addControl(new GLargeMapControl());
		gmap.addControl(new GMapTypeControl());
		gmap.centerAndZoom(new GPoint(lon, lat), 4);
		
		function createMarker (point) {
			var marker = new GMarker(point, icon);
			gmap.addOverlay(marker);
			GEvent.addListener(marker, 'click', function() {
				marker.openInfoWindowHtml(WINDOW_HTML);
			});
			marker.openInfoWindowHtml(WINDOW_HTML);
		}
		
		createMarker(new GPoint(lon, lat));
	}
	//]]>
}

function simpleMap(obj, lat, lon) {
	if (GBrowserIsCompatible()) {
		mappoint = new GLatLng(lat, lon);
		gmap = new GMap2(document.getElementById(obj));
		gmap.setCenter(mappoint, 13);
		gmap.addControl(new GSmallMapControl());
		gmap.addOverlay(new GMarker(mappoint));
	}
}

function piwik(clientId) {
	var uri = 'piwik.directorstech.com';
	var protocol = 'http';
	if (document.location.protocol == 'https') {
		protocol = (protocol + 's');
	}
	
	uri = (protocol + '://' + uri + '/');
	document.write(unescape('%3Cscript src="' + uri + 'piwik.js" type="text/javascript"%3E%3C/script%3E'));
	document.write(unescape('%3Cscript type="text/javascript"%3E'));
	document.write(unescape('try {'));
	document.write(unescape("var tracker = Piwik.getTracker('" + uri + "piwik.php', " + clientId + ");"));
	document.write(unescape('tracker.trackPageView();'));
	document.write(unescape('tracker.enableLinkTracking();'));
	document.write(unescape('}'));
	document.write(unescape('catch(err) {}'));
	document.write(unescape('%3C/script%3E'));
}

function fixChars(field){
	var str = field.value;
	var myReplacements = new Array();
	var myCode, intReplacement;
	myReplacements[8211] = "-";
	myReplacements[8212] = "-";
	myReplacements[8216] = "'";
	myReplacements[8217] = "'";
	myReplacements[8218] = "'";
	myReplacements[8220] = '"';
	myReplacements[8221] = '"';
	myReplacements[8222] = '"';
	myReplacements[8224] = "+";
	myReplacements[8226] = ".";
	myReplacements[8230] = "...";
	myReplacements[8249] = "<";
	myReplacements[8250] = ">";
	
	for(c = 0; c < str.length; c++) {
		var myCode = str.charCodeAt(c);
		if (myReplacements[myCode] != undefined) {
			intReplacement = myReplacements[myCode];
			str = (str.substr(0, c) + intReplacement + str.substr(c + 1));
		}
	}
	
	str = str.replace(/‘/g, "'");
	str = str.replace(/’/gi, "'");
	str = str.replace(/“/g, "\"");
	str = str.replace(/”/g, "\"");
	str = str.replace(/…/g, "...");
	str = str.replace(/®/g, "&reg;");
	str = str.replace(/©/g, "&copy;");
	str = str.replace(/™/g, "&trade;");
	str = str.replace(/€/g, "&euro;");
	str = str.replace(/½/g, "&frac12;");
	str = str.replace(/¼/g, "&frac14;");
	str = str.replace(/¾/g, "&frac34;");
	return field.value = str;
}

var DT = new Object();
DT.Maps = {
	insert: function(domains) {
		document.write('<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=' + DT.Maps.key(domains) + '"><\/script>');
	},
	
	key : function(domains) {
		var url = location.host;
		for (var i = 0; i < domains.length; i++) {
			if (url == domains[i][0]) {
				return domains[i][1];
			}
		}
		
		return null;
	}
};
