﻿/*
 * Common.js
 * Copyright (c) 2008 
 */
var detect,browser,thestring,OS;
var d = document;

/************************************
	function VerifyPopup

	Check that the window we just tried to open was successfully opened.
   If it was not, display a message telling the user that their popup blocker
   has blocked the window.
*************************************/
function VerifyPopup(val) {
	if (val == null) 	{
		var popupBlockedNotification = "Your browser appears to be blocking popups.  " + 
			"This content appears in a separate window to allow you to view it at " +
			"the same time that you continue using LambdaforLess.  " +
			"To access this content, you will need to allow this popup.  For many popup blockers " +
			"this can be done by holding down the CTRL key while clicking the link or button."
		alert(popupBlockedNotification);
	} else {
		// If window exists, put the focus on it, in case it was already
		// open, but buried under other windows.
		val.focus();
	}	
}//end VerifyPopup

/************************************
	function DetectBrowser

	Detect browser of the user
*************************************/
function DetectBrowser() {
	detect = navigator.userAgent.toLowerCase();
	if (checkIt('konqueror')) {
		browser = "Konqueror";
		OS = "Linux";
	} else if (checkIt('safari')) browser = "Safari"
	else if (checkIt('omniweb')) browser = "OmniWeb"
	else if (checkIt('opera')) browser = "Opera"
	else if (checkIt('webtv')) browser = "WebTV"
	else if (checkIt('icab')) browser = "iCab"
	else if (checkIt('netscape')) browser = "Netscape Navigator"
	else if (checkIt('firefox')) browser = "FireFox"
	else if (checkIt('msie')) browser = "Internet Explorer"
	else if (!checkIt('compatible')) {
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	} else browser = "An unknown browser";
}//end DetectBrowser

/************************************
	function checkIt(string)

	Find instance of variable in string
*************************************/
function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}//end CheckIt

/************************************
	function DetectOS

	Detect operating system of the user
*************************************/
function DetectOS() {
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}//end DetectOS

/************************************
	function DetectJava

	Detect if user has java installed and what version
*************************************/
function DetectJava() {
	java.installed=navigator.javaEnabled() ? true:false;
	java.version='0.0';

	var numPlugs=navigator.plugins.length;
	if (numPlugs) {
		for (var x=0; x<numPlugs; x++) {
			var pluginjava = navigator.plugins[x];
			if (pluginjava.name.toLowerCase().indexOf('java plug-in') != -1)	{
				java.version=pluginjava.description.toLowerCase().split('java plug-in ')[1].split(' for')[0];
				break;
			}
		}
	}
}//end DetectJava

/************************************
	function EnterKeyPressed

	Returns true if keypress was the Enter key, false otherwise
*************************************/
function EnterKeyPressed(e) {
	return KeyPressed(13, e);
}//end EnterKeyPressed

/************************************	
	function KeyPressed

	Returns true if keypress was the given keyCode, false otherwise
*************************************/
function KeyPressed(keyCode, e) {
	var key;
	if (window.event)
	{
		key = window.event.keyCode;  //IE
	}
	else
	{
		key = e.which;	//firefox
	}
	if (key == keyCode)
		return true;
	else 
		return false;	
}//end KeyPressed

/************************************
 Move an element directly on top of 
 another element (and optionally make
 it the same size)
*************************************/
function Cover(bottom, top, ignoreSize) {   
    top.style.position = 'absolute';
    top.style.top = bottom.style.top;
    top.style.left = bottom.style.left;
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}//end Cover

/************************************
 Generic AJAX failure handler.
*************************************/
function AJAX_Failure(err,userContext,methodName) {
   alert(err.get_message());
   alert(err.get_stackTrace());
}//end AJAX_Failure
