// Is this MSIE?
IsMSIE = navigator.appVersion.indexOf('MSIE') != -1;


// GETS A SPECIFIED GET VARIABLE FROM A GIVEN OR CURRENT URL
function fetchGETVar(GETVar, OverrideURL) {
	
	// Figure out what URL to use and then parse out the unnecessary parts
	UseURL = (OverrideURL)?OverrideURL:document.location.href;
	if (UseURL.indexOf('?') != -1 && UseURL.indexOf(GETVar) != -1) {
		URLArray      = UseURL.split('?');
		QueryStrArray = URLArray[1].split('&');
		
		// Set array of get vars
		GETVarArray = new Array(QueryStrArray.length);
		
		// Set the array values
		for (i in QueryStrArray) {
			CurrentVarSplit = QueryStrArray[i].split('=');
			CurrentVarName  = CurrentVarSplit[0];
			CurrentVarValue = CurrentVarSplit[1];
			eval('GETVarArray[\'' + CurrentVarName + '\'] = CurrentVarValue;');
		}
		
		if (GETVar)
			return GETVarArray[GETVar];
	}
	else
		return null;
}

function populateSearchBox() {
	if (fetchGETVar('q'))
		document.SearchForm.q.value = unescape(fetchGETVar('q')).replace(/\+/ig, ' ');
	
	if (IsMSIE) {
		document.SearchForm.q.style.height          = '16px';
		document.SearchForm.submit_btn.style.height = '20px';
		document.SearchForm.submit_btn.style.width  = '31px';
	}
}

// Use this code in the head

// Create spider proof email addresses
// Use this code in the body:

//	<SCRIPT language=javascript>generateAntiSpiderEmail('user', 'domain', 'tld', 'display_text');</SCRIPT>
function generateAntiSpiderEmail(Username, DomainName, TLD, Text) {
	Address = Username + "&#64;" + DomainName + "." + TLD;

	if (!(Text)) {DisplayText = Address}
	else {DisplayText = Text};

	document.write("<a href=\"ma" + "il" + "to:" + Address + "\">" + DisplayText + "</a>");
}


// ASSIGNS A JAVASCRIPT EVENT TO A SPECIFIED OBJECT ACCORDING TO THE BROWSER
function setEvent(Obj, Event, Action) {
	
	// For IE, use attachEvent
	if (IsMSIE) {
		eval("Obj.attachEvent('" + Event.toLowerCase() + "', function() { " + Action + " });");
	}
	
	// For proper browsers, simply use setAttribute
	else
		Obj.setAttribute(Event, Action);
}


// Function to create image overlay
function enlargeImg(ImgSrc, ImgLabel) {
	
	with (document) {
		NewContainerDiv	= createElement('div');
		NewDisableDiv	= createElement('div');
		NewImg		= createElement('img');
		NewXImg		= createElement('img');
	}
	
	with (NewImg) {
		src		= ImgSrc;
		style.margin	= '10px';
		style.cursor	= 'pointer';
		style.display	= 'block';
	
		TmpLabel = ImgLabel + ' [click to close]';		
		setAttribute('alt', TmpLabel);
		setAttribute('title', TmpLabel);
		setAttribute('id', 'MainImg');
	}
	
	with (NewXImg) {
		src = '../images/x.gif';
		
		style.position	= 'absolute';
		style.margin	= '-15px 10px 0px ' + ((IsMSIE)?NewImg.width-5:NewImg.width+5) + 'px';
		style.cursor	= 'pointer';
		
		setAttribute('width', '30');
		setAttribute('height', '35');
		setAttribute('alt', 'close');
		setAttribute('title', 'close');
		setAttribute('id', 'XImg');
	}
	
	setEvent(NewImg, 'onClick', 'closeMainImg()');
	setEvent(NewXImg, 'onClick', 'closeMainImg()');
	
	if (NewImg.width == 0) {
		setTimeout('enlargeImg("' + ImgSrc + '", "' + ImgLabel + '")', 500);
		return;
	}

	setLeft = (Math.round(document.body.clientWidth / 2)*1)/1 - ((NewImg.width + 10) / 2);
	setLeft = String(setLeft).substr(0, String(setLeft).lastIndexOf('.')) + 'px';
	
	setTop = String(document.documentElement.scrollTop + 35) + 'px';
	
	with (NewContainerDiv) {
		setAttribute('id', 'MainImgContainer');
		
		style.position	= 'absolute';
		style.top	= setTop;
		style.left	= setLeft;
		style.zIndex	= '2';
		style.background= '#FFFFFF';
	}
	
	with (NewDisableDiv.style) {
		top        = '0px';
		left       = '0px';
		width      = '100%';
		position   = 'absolute';
		height     = String(document.body.scrollHeight) + 'px';
		background = '#204052';
		zIndex     = '1';
		
		if (IsMSIE) {
			toggleSelectMenuVisibility(true, 'hidden');
			filter = 'alpha(opacity=75)';
		}
		else {
			setProperty('-moz-opacity', '.75', ''); 
			setProperty('opacity', '.75', '');			
		}			
	}
	
	NewDisableDiv.setAttribute('id', 'DisableDiv');
	
	with (document.body) {
		appendChild(NewDisableDiv);
		appendChild(NewContainerDiv);
	}
	
	NewContainerDiv.appendChild(NewXImg);
	NewContainerDiv.appendChild(NewImg);
}


// Function to close overlay
function closeMainImg() {
	with (NewContainerDiv) {
		removeChild(document.getElementById('MainImg'));
		removeChild(document.getElementById('XImg'));
	}
	
	with (document.body) {
		removeChild(document.getElementById('DisableDiv'));
		removeChild(document.getElementById('MainImgContainer'));
	}
}


// Opens or closes menu item
function menu(Toggle, IDInitStr) {
	document.getElementById('SubMenu_' + IDInitStr).style.display = (Toggle)?'block':'none';
	setClass(Toggle, IDInitStr);	
}


// For highlighting or unhighlighting a menu item
function setClass(Toggle, IDInitStr) {

	Obj = (typeof(IDInitStr) == 'object')?IDInitStr:document.getElementById('MainMenu_' + IDInitStr);
	
	with (Obj)
		className = (Toggle)?className + '_On':String(className).replace('_On', '');
}

// TOGGLES VISIBILITY OF ALL SELECT MENUS
function toggleSelectMenuVisibility(OnlyForIE, OverrideVisibility) {
	if (navigator.appName == "Microsoft Internet Explorer" || !OnlyForIE) {
		for (i = 0; i < document.forms.length; i++) {
			for (j = 0; j < document.forms[i].elements.length; j++) {
				Obj       = document.forms[i].elements[j];
				ElmntType = Obj.type;
	
				if (ElmntType == "select-one" || ElmntType == "select-multiple") {					
					if (OverrideVisibility)
						Obj.style.visibility = OverrideVisibility;
					else {
						NoVisibility = (document.forms[i].elements[j].style.visibility == "")?true:false;
						Obj.style.visibility = (NoVisibility)?'hidden':'visible';
					}
				}
			}
		}
	}
}

// www.sean.co.uk

function pausecomp(millis)
	{
	var date = new Date();
	var curDate = null;
	
	do { curDate = new Date(); }
	while(curDate-date < millis);
} 

// Opens a window
function openWindow(url, w, h) {
	window.open(url, 'PaypalWindow', 'width=' + w + ',height=' + h + ',scrollbars,menubar,status');
}