var addthis_config = {
	services_exclude : 'print,email'
}
var fieldvalue = {
	"search" : "Product Search"
};
var addthis_disable_flash = true;

var Cookie = {
	data : {},
	options : {
		expires : 1,
		domain : "",
		path : "",
		secure : false
	},

	init : function(options, data) {
		Cookie.options = Object.extend(Cookie.options, options || {});

		var payload = Cookie.retrieve();
		if (payload) {
			Cookie.data = payload.evalJSON();
		} else {
			Cookie.data = data || {};
		}
		Cookie.store();
	},
	getData : function(key) {
		return Cookie.data[key];
	},
	setData : function(key, value) {
		Cookie.data[key] = value;
		Cookie.store();
	},
	removeData : function(key) {
		delete Cookie.data[key];
		Cookie.store();
	},
	retrieve : function() {
		var start = document.cookie.indexOf(Cookie.options.name + "=");

		if (start == -1) {
			return null;
		}
		if (Cookie.options.name != document.cookie.substr(start,
				Cookie.options.name.length)) {
			return null;
		}

		var len = start + Cookie.options.name.length + 1;
		var end = document.cookie.indexOf(';', len);

		if (end == -1) {
			end = document.cookie.length;
		}
		return unescape(document.cookie.substring(len, end));
	},
	store : function() {
		var expires = '';

		if (Cookie.options.expires) {
			var today = new Date();
			expires = Cookie.options.expires * 86400000;
			expires = ';expires=' + new Date(today.getTime() + expires);
		}

		document.cookie = Cookie.options.name + '='
				+ escape(Object.toJSON(Cookie.data)) + Cookie.getOptions()
				+ expires;
	},
	erase : function() {
		document.cookie = Cookie.options.name + '=' + Cookie.getOptions()
				+ ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
	},
	getOptions : function() {
		return (Cookie.options.path ? ';path=' + Cookie.options.path : '')
				+ (Cookie.options.domain ? ';domain=' + Cookie.options.domain
						: '') + (Cookie.options.secure ? ';secure' : '');
	}
};

var BrowserDetect = {
	init : function() {
		this.browser = this.searchString(this.dataBrowser)
				|| "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
				|| this.searchVersion(navigator.appVersion)
				|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString : function(data) {
		for ( var i = 0; i < data.length; i++) {
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch
					|| data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			} else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion : function(dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1)
			return;
		return parseFloat(dataString.substring(index
				+ this.versionSearchString.length + 1));
	},
	dataBrowser : [ {
		string : navigator.userAgent,
		subString : "Chrome",
		identity : "Chrome"
	}, {
		string : navigator.userAgent,
		subString : "OmniWeb",
		versionSearch : "OmniWeb/",
		identity : "OmniWeb"
	}, {
		string : navigator.vendor,
		subString : "Apple",
		identity : "Safari",
		versionSearch : "Version"
	}, {
		prop : window.opera,
		identity : "Opera"
	}, {
		string : navigator.vendor,
		subString : "iCab",
		identity : "iCab"
	}, {
		string : navigator.vendor,
		subString : "KDE",
		identity : "Konqueror"
	}, {
		string : navigator.userAgent,
		subString : "Firefox",
		identity : "Firefox"
	}, {
		string : navigator.vendor,
		subString : "Camino",
		identity : "Camino"
	}, { // for newer Netscapes (6+)
				string : navigator.userAgent,
				subString : "Netscape",
				identity : "Netscape"
			}, {
				string : navigator.userAgent,
				subString : "MSIE",
				identity : "Explorer",
				versionSearch : "MSIE"
			}, {
				string : navigator.userAgent,
				subString : "Gecko",
				identity : "Mozilla",
				versionSearch : "rv"
			}, { // for older Netscapes (4-)
				string : navigator.userAgent,
				subString : "Mozilla",
				identity : "Netscape",
				versionSearch : "Mozilla"
			} ],
	dataOS : [ {
		string : navigator.platform,
		subString : "Win",
		identity : "Windows"
	}, {
		string : navigator.platform,
		subString : "Mac",
		identity : "Mac"
	}, {
		string : navigator.userAgent,
		subString : "iPhone",
		identity : "iPhone/iPod"
	}, {
		string : navigator.platform,
		subString : "Linux",
		identity : "Linux"
	} ]

};

var cssMenu = {
	menu_obj : {},
	current_id : null,
	init : function(element) {

		// Event.observe(document, 'mousemove', cssMenu.getcords);

	if ($(element)) {
		var menu_array = $(element).childElements();

		cssMenu.create_menus(menu_array, "m1");
	}
},
getcords : function(e) {
	mouseX = Event.pointerX(e);
	mouseY = Event.pointerY(e);

	// $('debug2').innerHTML = cssMenu.current_id+' - mouseX:' + mouseX + '--
	// mouseY:' + mouseY;

	if (cssMenu.menu_obj[cssMenu.current_id]) {
		m = cssMenu.menu_obj[cssMenu.current_id];

		mc = m.submenu.className;
		mc = mc.split("_");

		if (m.submenu.className == mc[0] + '_on') {
			// $('debug').innerHTML = m.submenu.className;

	offsets = Element.cumulativeOffset(m.submenu);
	mtop = offsets[1] - 30;
	mleft = offsets[0];
	mbottom = m.submenu.getHeight() + mtop + 30;
	mright = m.submenu.getWidth() + mleft;

	// $('debug2').innerHTML =
	// mleft+"+"+m.submenu.getWidth()+"="+mright+"|"+mtop+"+"+m.submenu.getHeight()+"="+mbottom+"|"+'mouseX:'
	// + mouseX + '-- mouseY:' + mouseY;
	if (!(mouseX > mleft && mouseX < mright)
			|| !(mouseY > mtop && mouseY < mbottom)) {
		m.submenu.removeClassName(mc[0] + '_on')
		m.submenu.addClassName(mc[0] + '_off')
	}
}
}
},
create_menus : function(menu, parent) {
menu.each(function(m) {
var submenu_array = m.childElements();

if (submenu_array.length > 1) {
	mid = m.id
	if (mid != "" && !mid.include("ul")) {
		cssMenu.create_menus(submenu_array, m.id);
		cssMenu.menu_obj[m.id] = {
			"submenu" : submenu_array[1],
			"parent_menu" : parent
		};
		m.observe('mouseover', cssMenu.showMenu);
		m.observe('mouseout', cssMenu.hideMenu);
	}
}
})
// if($('debug2'))
	// $('debug2').innerHTML = Object.keys(cssMenu.menu_obj);
},
showMenu : function(e) {

	// $('debug2').innerHTML = cssMenu.menu_obj[this.id].submenu.id + " | ";

	// cssMenu.current_id = this.id;
	m = cssMenu.menu_obj[this.id].submenu;
	pm = cssMenu.menu_obj[this.id].parent_menu;
	mc = m.className;
	mc = mc.split("_");

	m.removeClassName(mc[0] + '_off');
	m.addClassName(mc[0] + '_on')
},
hideMenu : function(e) {

	m = cssMenu.menu_obj[this.id].submenu;

	mc = m.className;
	mc = mc.split("_");

	m.removeClassName(mc[0] + '_on')
	m.addClassName(mc[0] + '_off')

}
};

function clearField(element) {
	if (fieldvalue[element.name])
		if (fieldvalue[element.name] == element.value) {
			element.value = "";
		} else if (element.value == "") {
			element.value = fieldvalue[element.name];
		}
}

function switchView(key, value) {
	Cookie.init( {
		name : 'electmerCartlayout',
		path : '/'
	});

	if (key == 'layout')
		if (Cookie.getData('layout') == 3)
			Cookie.setData('pagesize', 6);
		else
			Cookie.setData('pagesize', 6);

	Cookie.setData(key, value);

	curhref = window.location.href;

	newhref = curhref.split("/p-");
	// alert(newhref[0]);
	if (newhref.length > 1) {
		test = newhref[0].split("/artist-");
		if (test.length > 1)
			window.location.href = newhref[0] + "/";
		else
			window.location.href = newhref[0] + "/p-1/";
	} else
		window.location.reload();
}

function display_login(login_status) {

	var ni = document.getElementById('loginBox');
	var newanchor = document.createElement('a');

	if (login_status)
		ni.innerHTML = "<a href='cart/my-account.php?Logout=Go&ContinueURL=/index.html' title='Login' style='color:#ffffff;text-decoration:none'>Logout</a>";
	else
		ni.innerHTML = "<a href='cart/my-account.php?ContinueURL=/index.html' title='Login' style='color:#ffffff;text-decoration:none'>Login</a>";

}

function reposition() {
    ele = $('flasharea');
    
    if(ele)
    {	
	    parents = ele.ancestors();
	    parentCont = parents[0].down(0);
	    
	    position = Element.cumulativeOffset(parentCont);
	    
	    ele.style.bottom = "0px";
	    ele.style.left = (position.left+parentCont.getWidth()-30-(ele.getWidth()/2))+"px";
    }
}

function openVideoDiv() {
	
	
	if ($('flasharea')) {
		
		//alert(BrowserDetect.version)
		if(BrowserDetect.browser == "Explorer" && BrowserDetect.version < 7)
		{
			//alert(BrowserDetect.version)
			var divwidth=0;
			var divheight=0;
			var window_width=get_document_window_width();
			var width=convert_width(divwidth,window_width);
			var window_height=get_document_window_height();
			var height=convert_height(divheight,window_height);
			var mleft=calculate_left(width,window_width);
			var mtop=calculate_top(height,window_height);
			ptop=200+"px";
			pleft=(0)+"px";
			
			$('flasharea').style.bottom = "0px";
			$('flasharea').style.right = "0px";
		}
		else reposition();
		
		$('flasharea').innerHTML = AC_FL_PreloadContent(
				'codebase',
				'https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0',
				'width', '275', 'height', '288', 'movie', 'flash/flash',
				'quality', 'high', 'allowfullscreen', 'false', 'wmode',
				'transparent');
	}
}

function hide_video() {
	if ($('flasharea')) {
		$('flasharea').remove();
	}
}

function bookmarksite(title, url) {
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
}

function get_document_window_height() {
	if (document.body && document.body.clientHeight
			&& (document.body.clientHeight > 1))
		return document.body.clientHeight;
	else if (window && window.innerHeight)
		return window.innerHeight;
	else if (document.documentElement && document.documentElement.offsetHeight)
		return document.documentElement.offsetHeight;
	else if (document.body && document.body.offsetHeight)
		return document.body.offsetHeight;
	return 0;
}

function get_document_window_width() {
	if (document.body && document.body.clientWidth)
		return document.body.clientWidth;
	else if (window && window.innerWidth)
		return window.innerWidth;
	else if (document.documentElement && document.documentElement.offsetWidth)
		return document.documentElement.offsetWidth;
	else if (document.body && document.body.offsetWidth)
		return document.body.offsetWidth;
	return 0;
}

function convert_width(width, window_width) {
	if (width == null)
		width = page_width + 52;
	else if (typeof (width) == 'string') {
		var percent_pos = width.indexOf('%');
		if (percent_pos != -1)
			width = window_width * (width.substr(0, percent_pos) / 100);
	}
	if (!document.all) {
		if (width > (window_width - 25))
			width = window_width - 25;
	} else if (width > (window_width - 10))
		width = window_width - 10;
	return width;
}

function convert_height(height, window_height) {
	if (height == null)
		height = window_height;
	else if (typeof (height) == 'string') {
		var percent_pos = height.indexOf('%');
		if (percent_pos != -1)
			height = window_height * (height.substr(0, percent_pos) / 100);
	}
	// else height += header_offset;
	if (height > (window_height - 40))
		height = window_height - 40;
	return height;
}

function calculate_left(width, window_width) {
	var left = (window_width - width) / 2;
	if (!document.all)
		left += 10;
	if (left < 0)
		left = 0;
	return left;
}

function calculate_top(height, window_height) {
	var top = ((window_height - height) / 2) - 3;
	if (top < 0)
		top = 0;
	return top;
}

function toggleDiscover() {
	if (document.getElementById("hideDiscover").style.display == 'none') {
		document.getElementById("hideDiscover").style.display = '';
	} else {
		document.getElementById("hideDiscover").style.display = 'none';
	}
}

function toggleAmex() {
	if (document.getElementById("hideAmex").style.display == 'none') {
		document.getElementById("hideAmex").style.display = '';
	} else {
		document.getElementById("hideAmex").style.display = 'none';
	}
}
function loaddivcontent(myhref, myid) {
	var me = document.getElementById(myid);
	me.src = myhref;
	me.parentNode.className = "showiframe";
	return false;
}
function unloaddivcontent(myid) {
	var me = document.getElementById(myid);
	me.src = "";
	me.parentNode.className = "hideiframe";
}
// wrapped functions
function lookupSingleHierarchyEnt() {

	cgroup = document.forms[0].elements["clientGrp"].value;

	chainnum = document.forms[0].elements["chainNum"].value;

	entityNum = document.forms[0].elements["entityNum"].value;

	path = document.forms[0].elements["path"].value;

	url = path + "/Hier.do?CGRP=" + cgroup + "&CHN=" + chainnum + "&ENT_CHAIN="
			+ entityNum;

	window.open(url, 'MidList',
			'width=850,height=650,status,scrollbars,resizeable=1')

}

function lookupEntityHierarchy() {

	cgroup = document.forms[0].elements["clientGrp"].value;

	topentity = document.forms[0].elements["entityNum"].value;

	path = document.forms[0].elements["path"].value;

	url = path + "/Hier.do?CGRP=" + cgroup + "&ENT=" + topentity;

	window.open(url, 'MidList',
			'width=850,height=650,status,scrollbars,resizeable=1')

}
function pdfWindow(loc) {
	if (loc == "#RefQuide") {
		location.href = loc;
	} else {
		loc = "online-reports" + loc;// added by Inroads, LLC
		// The window attributes
		var window_attribs = "height=650,width=850,resizable=yes,scrollbars=yes";

		window.open(loc, "PDF", window_attribs);
	}
}
function MM_jumpMenu(targ, selObj, restore) { // v3.0
	eval(targ + ".location='" + "online-reports/CWRWeb%252FSWViaWarpHelp.do"
			+ selObj.options[selObj.selectedIndex].value + "'");
	if (restore)
		selObj.selectedIndex = 0;
}

function onlyint(e, field) {
	if (window.event)
		keynum = e.keyCode;
	else if (e.which)
		keynum = e.which;

	if (keynum == "0x08")
		return true;
	if (keynum == "0x09")
		return true;
	if (keynum == "0x20")
		return true;
	if ((keynum == "0x2d" || keynum == "0x2e" || keynum == "0x28" || keynum == "0x29")
			&& field == 'phone')
		return true;
	if (keynum == "0x2E" && field == 'currency')
		return true;
	if (keynum == "0x2d" && field == 'ein')
		return true;
	if ((keynum == "0x24" || keynum == "0x2e" || keynum == "0x2C")
			&& field == 'usd')
		return true;
	if (keynum == "0x2D" && field == 'zip')
		return true;
	if (keynum == "0x2F" && field == 'date')
		return true;
	if ((keynum >= "0x30") && (keynum <= "0x39"))
		return true;
	return false;
}

function onlyAlphaNumeric(e) {
	if (window.event)
		keynum = e.keyCode;
	else if (e.which)
		keynum = e.which;

	if (keynum == "0x08")
		return true;
	if (keynum == "0x09")
		return true;
	if (keynum == "0x20")
		return true;
	if ((keynum >= "0x30") && (keynum <= "0x39"))
		return true;
	if ((keynum >= "0x41") && (keynum <= "0x5A"))
		return true;
	if ((keynum >= "0x61") && (keynum <= "0x7A"))
		return true;
	return false;
}

function onlyAlpha(e) {
	if (window.event)
		keynum = e.keyCode;
	else if (e.which)
		keynum = e.which;

	if (keynum == "0x08")
		return true;
	if (keynum == "0x09")
		return true;
	if (keynum == "0x20")
		return true;
	// if ((keynum >= "0x30") && (keynum <="0x39")) return true;
	if ((keynum >= "0x41") && (keynum <= "0x5A"))
		return true;
	if ((keynum >= "0x61") && (keynum <= "0x7A"))
		return true;
	return false;
}

function autotab(current, to) {
	if (current.getAttribute
			&& current.value.length == current.getAttribute("maxlength")) {
		to.focus()
	}
}
function printFrame(location) {
	window.frames[location].print();
}


window.onresize = reposition;
window.onscroll = reposition;

window.onload = function() {
	BrowserDetect.init();
	openVideoDiv();
}