String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
var EMailValidation = "[A-Za-z0-9_\.\-]+\@[A-Za-z0-9_\.\-]+\.[A-Za-z0-9_\.\-]+";

var domOk = document.getElementById;
var IsIE = !window.innerWidth;
var IsIE7 = false;

function GetRef(id) {
    return document.getElementById(id);
}

function PadWithZeros(i) {
    if (i<10) { return "0"+i; } else { return ""+i; }
}

function DoNothing() {}

function OpenLink(url) {
    window.open(url,null,'width=750,height=500,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes');
}

function OpenLink2(url) {
    window.open(url,null,'width=750,height=500,status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes,scrollbars=yes');
}


function ShowElement(id) { GetRef(id).style.display = "block"; }
function HideElement(id) { GetRef(id).style.display = "none"; }

function CurrentTime() { return (new Date().getTime()); }

function ToInteger(value) {
    value = value + "";
    var i = parseInt(value.match(/\d+/), 10);
    return isNaN(i) ? 0 : i;
}

function FindPosition(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return {Left: curleft, Top: curtop};
}

function ElementDefault(ref) {	ref.className = ref.className.replace(/Over/g, "Default"); }
function ElementOver(ref) { ref.className = ref.className.replace(/Default/g, "Over");  }
var swfstr = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="{width}" height="{height}"><param name="movie" value="{url}"><param name="quality" value="high"><embed src="{url}" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="{width}" height="{height}"></embed></object>';
function InitializeFlashObject(id,url,width,height) {
	try {
		//alert (swfstr.replace(/\{url\}/g, url).replace(/\{height\}/g, height).replace(/\{width\}/g, width));
		GetRef(id).innerHTML = swfstr.replace(/\{url\}/g, url).replace(/\{height\}/g, height).replace(/\{width\}/g, width);
	} catch (e) {
		//alert (e);
	}
}


//Tracking
var $j = jQuery.noConflict();
jQuery(document).ready(function($){

	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	
	//use $j to call the Google Analytics JavaScript
	$j.getScript(gaJsHost + "google-analytics.com/ga.js", function(){
	
		//tell Analytics about the current page load using standard _trackPageview method
		try {
			var pageTracker = _gat._getTracker("UA-2140535-8");
			pageTracker._trackPageview();
		} catch(err) {}
		
		//loop though each anchor element
		$j('a').each(function(){
			
			var href = $j(this).attr('href');
			var filetypes = /\.(zip|exe|pdf|vcs|txt|rtf|doc*|xls*|ppt*|mp3)$j/i;
			
			//check for links starting with http or https, making sure that links to our own domain are excluded
			if ((href.match(/^https?\:/i)) && (!href.match(document.domain))){
				$j(this).click(function() {
					var extLink = href.replace(/^https?\:\/\//i, '');
					pageTracker._trackEvent('External', 'Click', extLink);
				});
			}
			//check for links starting with mailto:
			else if (href.match(/^mailto\:/i)){
				$j(this).click(function() {
					var mailLink = href.replace(/^mailto\:/i, '');
					pageTracker._trackEvent('Email', 'Click', mailLink);
				});
			}
			//check for links with file extension that match the filetypes regular expression:
			else if (href.match(filetypes)){
				$j(this).click(function() {
  					var extension = (/[.]/.exec(href)) ? /[^.]+$j/.exec(href) : undefined;
					var filePath = href.replace(/^https?\:\/\/(www.)demonzmedia\.com\//i, '');
					pageTracker._trackEvent('Download', 'Click - ' + extension, filePath);
				});
			}

		});
		
	});

});