/* ===================================================
	Copyright (c) 2003-2005 Macromedia Inc.
	global JavaScript functions 
	$Revision: 1.85 $
==================================================== */
/*
	TOC:
	Namespace
	Open Window	
	PNG
	Crockford's Remedial Javascript
	DOM Utils
	Attributes
	Style Utils
	Cookie
	Element Coordinates
	Dropdown
	WMode
	Browser
	On Load
	Deconcept
*/

/*////////// Namespace //////////*/
if( typeof com == "undefined" ) var com = new Object();
if( typeof com.adobe == "undefined" ) com.adobe = new Object();
if( typeof com.adobe.util == "undefined" ) com.adobe.util = new Object();
if( typeof com.adobe.www == "undefined" ) com.adobe.www = {
	is: true,
	isSecure: document.location.href.indexOf("https:") == 0
};

/*                    Popup                          */
function OpenWindow( url, width, height, opt , name ) {
	window.open( url, (name || "OutsideWindow"), "width="+(width || 714)+",height="+(height || 536)+","+(opt ||  "scrollbars=yes,menubar=yes,toolbar=yes,location=yes,status=yes,resizable=yes")).focus();
}

/* ////////// PNG Image Support //////////////////// */

PNG = function (id,src,altsrc) {
	
	var png = document.createElement('img');
	png.setAttribute('id',id);
	
	if (browser.ua.indexOf('msie 5.0') != -1) {
		
		// WinIE 5.0 neither supports PNG images nor image opacity filters
		// if an alternative source is provided use this and continue
		if (altsrc != null) png.src = altsrc;
		else return;
	
	} else if ((browser.appN.indexOf('microsoft') != -1) && (browser.ua.indexOf('mac') == -1)) {
		
		// WinIE 5.5+ support
		png.src = '/images/alpha/blank.gif';
		png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"',sizingMethod='scale');";
		
	} else {
		png.src = src;
	}
	
	return png;
}	

/* ////////// Cookie Management //////////////////// */

var cookies;

function parseCookies() {
	var cookiesHash = new Object();
	var cookiesArray = document.cookie.split(';');
	for (i=0; i < cookiesArray.length; i++) {
		cookie = cookiesArray[i];
		cookie = cookie.split('=');
		cookiesHash[cookie[0]] = cookie[1];
	}
	return cookiesHash;
}


function getCookie (name) {
	var value = null;
	if (name != null) {
		name = name.toUpperCase();
		cookies = (cookies) ? cookies : parseCookies();
		for (key in cookies) {
			if (key.toUpperCase().match(name)) {
				value = decodeURI(cookies[key]);
				if (value.indexOf('%') != -1) value = unescape(value);
				break;
			}
		}
	}
	return value;
}


/* 	parse cookies and return them as a strin in the following format,
	"storedropin=summer_sale,build_your_own_studio;cookie_storeregion=ols-us;" */
function cookiesToString () { 
	
	cookies = (cookies) ? cookies : parseCookies();
	
	var fvString = new String();
	
	if (arguments.length != 0) {
		
		for (var i=0; i < arguments.length; i++) {
			cookieName = arguments[i];
			//fvString += cookieName +'='+ cookies[cookieName] +';';
			fvString += cookieName +'='+ getCookie(cookieName) +';';
		}

	} else {
		
		for (cookie in cookies) {
			fvString += cookie +'='+ cookies[cookie] +';';
		}
	}
	
	return fvString;
}


function setCookie (name,value,msec,path,domain,secure) {
	if (name != null) {
		var now = new Date();
		var exp_date = new Date(now.getTime()+(msec?msec:0));
		var cookie = name+'='+escape(value)+';';
		if (msec) cookie += 'expires='+exp_date.toUTCString()+';';
		if (path) cookie += 'path='+path+';';
		if (domain) cookie += 'domain='+domain+';';
		if (secure) cookie += 'secure;';
		document.cookie = cookie;
	}
}

/* ////////// Form Utilities //////////////////// */

function selectFormAction (formID,dropdownID) { 
	var selectedLink = document[formID][dropdownID].options[document[formID][dropdownID].selectedIndex].value;
	if (selectedLink != '#') {
		window.location=document[formID][dropdownID].options[document[formID][dropdownID].selectedIndex].value;
	} else if (selectedLink == '#') {
		document[formID][dropdownID].selectedIndex = 0;
	}
}



/* ////////// Element Coordinates //////////////////// */

Dimensions = function (w,h) { 

	this.width = w || 0;
	this.height = h || 0;
	return this;
}


XYCoords = function (x,y) { 
	
	this.x = x || 0;
	this.y = y || 0;	
	return this;
}


BoxCoords = function (x1,y1,x2,y2) {

	this.x1 = x1 || 0;
	this.y1 = y1 || 0;
	this.x2 = x2 || 0;
	this.y2 = y2 || 0;
	return this;
}


function getEventCoords (e) {
	
	var coords = new XYCoords();
	
	if (e.pageX && e.pageY) {
		
		// W3C model
		coords.x = e.pageX;
		coords.y = e.pageY;
		
	} else if (e.clientX && e.clientY) {
		
		// Internet Explorer model
		coords.x = e.clientX + document.body.scrollLeft;
		coords.y = e.clientY + document.body.scrollTop;
	}
	
	return coords;
}


/*this function always calculates from the offsetParent 
	IE 6 standards mode calculates values for offsetTop and offsetLeft values 
	from the BODY element NOT from the offsetParent */
	
function getElementBoxCoords(domElement) {
	
	this.element = domElement;
	this.calculated_offset;
	
	this.calcOffsetFrom = function (element,from,reset) {
	
		if (reset != false) this.calculated_offset = 0;
		
		if (element != null)	{
			switch (from) {
				case 'top': 
					this.calculated_offset += element.offsetTop;
					break;
				case 'left': 
					this.calculated_offset += element.offsetLeft;
					break;
			}
			
			if ((element.offsetParent == document.body) || (element.offsetParent.tagName == ('HTML'||'BODY'))) {				
				return this.calculated_offset;
			} else {
				return this.calcOffsetFrom(element.offsetParent,from,false);
			}
			
		}
	}
	
	/*IE6 compatible mode offsetWidth and offsetHeight values include border
		IE6 standards mode, Netscape, MacIE these values includes padding + border 
		Safari, Opera6, Opera7, Mozilla ...? */
	this.w = this.element.offsetWidth;
	this.h = this.element.offsetHeight;

	var coords = new BoxCoords();
	
	coords.x1 = this.calcOffsetFrom(this.element,'left',true);
	coords.y1 = this.calcOffsetFrom(this.element,'top',true);
	coords.x2 = coords.x1 + this.w;
	coords.y2 = coords.y1 + this.h;
	
	return coords;
}

// extension to getElementBoxCoords function 
// accepts element id instead of element object
function getElementBoxCoordsById(elementID) {
	var element = document.getElementById(elementID);
	if (element != null) {
		return getElementBoxCoords(element);
	}
}


function getWindowDimensions () {
	
	var width = (window.innerWidth) ? window.innerWidth : document.body.clientWidth;
	var height = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
	return new Dimensions(width,height);
}


function getContentDimensions () {
	
	// take the greater of scroll and offset dimension
	var width = Math.max(document.body.offsetWidth,document.body.scrollWidth);
	var height = Math.max(document.body.offsetHeight,document.body.scrollHeight);
	return new Dimensions(width,height);
}


function getScrollPosition () {
	
	var scrollPosition = new XYCoords();
	
	if (window.scrollX && window.scrollY) {
		
		// Netscape implementation
		scrollPosition.x = window.scrollX;
		scrollPosition.y = window.scrollY;
	
	} else {
	
		// Internet Explorer		
		var docBody = document.body;
		
		var parent_scrollLeft = (docBody.parentNode.scrollLeft) ? docBody.parentNode.scrollLeft : 0;
		var parent_scrollTop = (docBody.parentNode.scrollTop) ? docBody.parentNode.scrollTop : 0;
		
		scrollPosition.x = Math.max(docBody.scrollLeft,parent_scrollLeft);
		scrollPosition.y = Math.max(docBody.scrollTop,parent_scrollTop);
	}
	
	return scrollPosition;
}


/* ////////// Event Registration //////////////////// */


function defineEventHandler (element,eventName,handler,capture) {
	
	try {
		
		if (document.addEventListener) {
			// W3C Event model
			element.addEventListener(eventName,handler,capture);
			
		} else if (document.attachEvent) {
			// Internet Explorer Event model
			eventName = 'on'+eventName;
			element.attachEvent(eventName,handler);
		}
		
	} catch (ex) {
		return;
	}
}


function removeEventHandler (element,eventName,handler,capture) {

	try {
	
		if (document.removeEventListener) {
			// W3C Event model
			element.removeEventListener(eventName,handler,capture);
			
		} else if (document.detachEvent) {
			// Internet Explorer Event model
			element.detachEvent('on'+eventName,handler);
		}	

	} catch (ex) {
		return;
	}
}


/* ////////// Browser Detection //////////////////// */

BrowserDescription = function () {
	this.appN = navigator.appName.toLowerCase();
	this.appV = parseInt(navigator.appVersion);
	this.ua = navigator.userAgent.toLowerCase();
	this.plt = navigator.platform.toLowerCase();
	//the preferred OS language in IE 
	//or the language version of the browser for non IE
	this.lang = (navigator.language || navigator.userLanguage).substring(0,2); 
	// reset appV string incorrect user agent
	if (this.ua.indexOf('opera/7') != -1 || this.ua.indexOf('opera 7') != -1) {
		this.appV = 7;
	}
	this.ax = window.ActiveXObject != "undefined";
	this.isSafari = (this.ua.indexOf('safari') != -1); //should remove this
	
	if(this.ua.indexOf('safari') != -1) 
	{
		var wk = 'applewebkit/';
		var kitpos = this.ua.indexOf(wk);
		if(kitpos == -1) return null;
		var kit = this.ua.substring(kitpos+wk.length);
		kit = kit.substring(0,kit.indexOf(" "));
		this.kitV = parseInt(kit);
	}
	return this;
}

/* ////////// global variables //////////////////// */

var browser = new BrowserDescription();

/* Copied from /lib/com.adobe/_all.js*/

[an error occurred while processing this directive]
[an error occurred while processing this directive]
adobe.setLibraryPath(adobe.getMyPath() + "../lib/com.adobe/");
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
adobe.Dwt.require("swf","dropdown","tree","tab","pod","user");

adobe.Loader.requireAsset("_/module/SearchBuddy.js");
document.observe('dom:loaded', function() {
	new SearchBuddy();
});

(com.adobe.htmltemplate = {}).loadCondAssets = function() {
	for(var i=0, l=arguments.length; i<l; i++) {
		adobe.Dwt.require(arguments[i]);
	}
}
