var xmlhttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
@end @*/

/* force ie5.0 win to set xmlhttp to off since it doesn't support encodeURIComponent() */
if (is_win && (is_minor < 5.1) && (is_minor > 4.9)) {
	xmlhttp = false;
}

if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	xmlhttp = new XMLHttpRequest();
}

// this is not redundant. We need to turn this off for Opera even though Opera 8 supports xmlhttp
// (they support it in a weird way which we don't have time to debug). Hence we have to turn it off manually for O8.
if (is_opera) {
	xmlhttp = false;
}

function addTokenAndRedirect (targetPage, requireUrlToken) {
    var hasQuery = targetPage.toString().indexOf("?");						
    var location;
    location = targetPage;				  	
    
    if (hasQuery < 0) {								
        location += "?" + gST + "&sourceid=" + gSourceID;
            
    }  else  {								
        location += "&" + gST + "&sourceid=" + gSourceID;                       
    }
    
    if (arguments.length == 2) {
        location += "&UV=" + gUV;
    }		  				  				 								 
    
    this.location.href = location;
    return false;
}

// Tabs are controlled with CSS now, these are just to catch missed instances
function tabon(o) { return; }
function taboff(o) { return; }

/**
Called by event handlers to submit a form.
Accepts 0, 1 or 2 parameters.

submitForm()
@param (null) :  submits form referenced by 'pri-form'

submitForm(arg)
@param arg overrides either form element reference or form action attribute

submitForm(formName, action)
@param formName submits form referenced by formName
@param action submits form referenced by formName and sets the form action attribute to action.
*/
function submitForm() {
	var args = submitForm.arguments;
	var sFormName="pri-form";
	if (!args || args.length == 0) {
		/** submits pri-form **/
		executeSubmit(sFormName);
		return false;
	}
	if (args.length==1) {
		if (args[0].indexOf(".action") > -1 || args[0].indexOf(".jsp") > -1) {
			/** submits pri-form with an overridden action attribute **/
			executeSubmit(sFormName,args[0]);
			return false;
		} else {
			/** submits form whose id was passed in to submitForm() **/
			executeSubmit(args[0]);
			return false;
		}
	} else {
		/** submits form whose id was passed in to submitForm() and overrides the action attribute **/
		executeSubmit(args[0],args[1]);
		return false;
	}
}
/**
Utility function used by submitForm(). May be used directly to submit a form
@param sFormName reference to form element
@param action sets the form action attribute
*/
function executeSubmit(sFormName, action) {
	var form = getForm(sFormName);
	if(form){
		if (action) {
			form.action = action;
		}
		form.submit();
	}
}

/**
utility function used by submitForm(). May be used directly to obtain a form object reference
@return form object reference.
@param formName id and/or name attribute of a document form
*/
function getForm(formName) {
	var form =	document.forms[formName];
	if (form) {
		return form;
	} else {
		form = document.getElementById(formName);
		return form;
	}
}

function findPosX (obj) {
	var curLeft = obj.offsetLeft;
	if (obj.offsetParent) {
		if (is_ie) {
			obj = obj.offsetParent;
			curLeft += obj.offsetLeft;
		}
	}
	else if (obj.x) {
		curLeft += obj.x;
	}
	return curLeft;
}

function findPosY (obj) {
	var curTop;
	if (!is_opera) {
		curTop = obj.offsetTop;
	}
	if (obj.offsetParent) {
		if (is_ie) {
			obj = obj.offsetParent;
			curTop += obj.offsetTop;
		}
	}
	else if (obj.y) {
		curTop += obj.y;
	}
	return curTop;
}

function findHeight (obj) {
	if (obj.offsetHeight) {
		return obj.offsetHeight;
	} 
	else if (obj.height) {
		return obj.height;
	}
}

function findWidth (obj) {
	if (obj.offsetWidth) {
		return obj.offsetWidth;
	} 
	else if (obj.width) {
		return obj.width;
	}
}

function capitalize (val) {
	if (val == null) return "";
	return val.substring(0, 1).toUpperCase() + val.substring(1, val.length);
}

function trimLeft (val) {
	var len = val.length;
	var split = 0;
	for (i=0; i<len; i++) {
		if (val.charAt(i) != ' ') {
			split = i;
			break;
		}
	}
	return val.substring(split, len);
}

function isBlank (val) {
	if (0 == val.length) return true;
	for (i=0; i<val.length; i++) {
		if (val.charAt(i) != ' ') {
			return false;
		}
	}
	return true;
}

function removeChildren(node) {
	if (!node)
		return;
	var children = node.childNodes;
	for (var i=0; i < children.length; i++) {
		removeChildren(children[i]);
	}
	while(node.hasChildNodes() == true) {
		node.removeChild(node.childNodes[0]);
	}
}

function setCaretToEnd (el) {
	if (el.createTextRange) {
		var range = el.createTextRange();
		range.collapse(false);
		range.select();
	}
	else if (el.setSelectionRange) {
		el.setSelectionRange(el.value.length, el.value.length);
	}
}

function loadPNGIntoDiv(div, imgPath, noRepeat, backgroundPosition) {
	if (is_ie5_5up && is_win32) {
		div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imgPath + "', sizingMethod='scale')";
	}
	else {
		div.style.backgroundImage = "url(" + imgPath + ")";
		if (noRepeat == true)
			div.style.backgroundRepeat = "no-repeat";
		if (backgroundPosition)
			div.style.backgroundPosition = backgroundPosition;
	}
}


function replaceOfototext(elementName, value) {
	if (document.getElementById(elementName)) {
		document.getElementById(elementName).innerHTML = value;
	}	
} 

function postViaXmlHttp(queryStr, formContent, callback) {
	if (!xmlhttp)
		return;
	if (!callback)
		return;

	xmlhttp.open("POST", queryStr, true);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.onreadystatechange = callback;
	xmlhttp.send(formContent);	
}

function formatAsQueryStr(frm) {
	var s = "";
	var inputs = frm.getElementsByTagName("INPUT");
	for (var idx=0; idx<inputs.length; idx++) {
		var input = inputs[idx];
		var name;
		if (input.name != null) {
			name = input.name;
		}
		else if (input.id != null) {
			name = input.id
		}
		else {
			return s + "UNNAMEDINPUT!";
		}
		var value = input.value;

		// if we have an id, get the value again.  For some reason values set via getElementById
		// aren't pulled properly using the lines above.
		// This was causing "Edit Details and Rearrange" to not work on IE6.
		if (input.id && !value) {
			value = document.getElementById(input.id).value;
		}
  	  	s += encodeURIComponent(name);
  	  	s += "=";
  	  	s += encodeURIComponent(value);
  	  	if (idx < inputs.length - 1)
  	  		s += "&";
	}
	return s;
}


function getElText(parent, id) {
	if (!parent || !id) 
		return;

	try {
		var items = parent.getElementsByTagName(id);
		if (items) {
			var item = items[0];
			if (item) {
				// handle whitespace
				if (item.childNodes.length > 1)
					return item.childNodes[1].nodeValue;
				else
					return item.firstChild.nodeValue;
			}
		}
		return "NO DATA";
 	}
 	catch (e) { 
		return "";
 	}
}

function dump(node) {
	var children = node.childNodes;
	for (var idx=0; idx<children.length; idx++)
		dump(children[idx]);
	alert(node.nodeName);
}

function getElAttrValue(el, attrName) {
	if (!el || !attrName)
		return;
	attrName = attrName.toLowerCase();
	var attrs = el.attributes;
	if (attrs) {
		for (var idx=0; idx < attrs.length; idx++) {
			var attr = attrs.item(idx);
			if (attr.name.toLowerCase() == attrName)
				return attr.value;
		 }
	}
	return "";
}


function setAlbumNavFolder(collID) {
	document.getElementById("navfolderid").value = collID;
	submitForm("album-form");
	return false;
}


/*-------------------------------------------
  shared search functions
-------------------------------------------*/

var searchErrorType = "";

function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

function cleanupSearchTerm(term) {
	// remove spaces and escape chars from search string, rewrite clean term
	term = trim(term);
	term = term.replace(/\\/g, "").replace(/\//g, "");
	if (document.getElementById("searchbox")) 
		document.getElementById("searchbox").value = term;
	return term;
}

function verifySearchTerm(term) {
	// check for search term errors
	// terms must be between 3 and 25 characters
	if ((term == "") || (term == document.getElementById("searchbox").defaultValue)) {
		searchErrorType = emptySearchError;
	} else if (term.length <= 2) {
		searchErrorType = shortSearchError;
	} else if (term.length >= 41) {
		searchErrorType = longSearchError;
	}
	// test individual words for min-length
	if (searchErrorType == "") {
		var termChunks = term.split(" ");
		for(var i=0;i<termChunks.length;i++) {
			if (termChunks[i].length <= 2) 
				searchErrorType = shortSearchError;
		}
	}
	return searchErrorType;
}

function undoErrors(level) {
	var errorbox = level + "searcherror";
	document.getElementById(errorbox).style.display="none";
}

function doError(searchErrorType, level) {
	var errorbox = level + "searcherror";
	document.getElementById(errorbox).style.display="block";
	document.getElementById(errorbox).innerHTML = searchErrorType;
}

function postAlbumSearch(level) {
	searchErrorType = "";
	undoErrors(level);
	var term = document.getElementById("searchbox").value;
	term = cleanupSearchTerm(term);
	verifySearchTerm(term);

	if (searchErrorType != "") {
		// check for errors, write any, abort post
		doError(searchErrorType, level);
		return false;
	} else {
		return true;
	}
}

function trim(strText) {
	while (strText.substring(0,1) == ' ') 
		strText = strText.substring(1, strText.length);
	while (strText.substring(strText.length-1,strText.length) == ' ')
		strText = strText.substring(0, strText.length-1);
	return strText;
}

function updateCartCount() {
}



// Common Flash detection code
	var flashinstalled = 0;
	var flashversion = 0;
	MSDetect = "false";
	if (navigator.plugins && navigator.plugins.length)
	{
		x = navigator.plugins["Shockwave Flash"];
		if (x)
		{
			flashinstalled = 2;
			if (x.description)
			{
				y = x.description;
				flashversion = y.charAt(y.indexOf('.')-1);
			}
		}
		else
			flashinstalled = 1;
		if (navigator.plugins["Shockwave Flash 2.0"])
		{
			flashinstalled = 2;
			flashversion = 2;
		}
	}
	else if (navigator.mimeTypes && navigator.mimeTypes.length)
	{
		x = navigator.mimeTypes['application/x-shockwave-flash'];
		if (x && x.enabledPlugin)
			flashinstalled = 2;
		else
			flashinstalled = 1;
	}
	else
		MSDetect = "true";



/***********************************************
* AnyLink Drop Down Menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var disappeardelay=250  //menu disappear speed onMouseout (in milliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function showhide(obj, e, visible, hidden, menuwidth){
	if (ie4||ns6)
		dropmenuobj.style.left=dropmenuobj.style.top=-500
	if (menuwidth!=""){
		dropmenuobj.widthobj=dropmenuobj.style
		dropmenuobj.widthobj.width=menuwidth
	}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
		obj.visibility=visible
	else if (e.type=="click")
		obj.visibility=hidden
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=0
	if (whichedge=="rightedge"){
		var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
	}
	else{
		var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
	}
	return edgeoffset
}

function populatemenu(what){
	if (ie4||ns6)
		dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
	// Surprise surprise, MacIE doesn't like this
	if (is_ie && is_mac) 
		return

	if (window.event) event.cancelBubble=true
	else if (e.stopPropagation) e.stopPropagation()
	clearhidemenu()
	dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
	populatemenu(menucontents)
	
	if (ie4||ns6){
		showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
		dropmenuobj.x=getposOffset(obj, "left")
		dropmenuobj.y=getposOffset(obj, "top")
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
	}
	
	// Hide all content area select boxes in IE so they don't bleed through the menu
	if (is_ie) {
		selectlist=document.getElementById("main-content").getElementsByTagName('select')
		for(i=0;i<selectlist.length;i++) {
			selectlist[i].style.visibility="hidden";
		}
	}
	
	return clickreturnvalue()
}

function clickreturnvalue(){
	if (ie4||ns6) return false
	else return true
}

function contains_ns6(a, b) {
	while (b.parentNode)
	if ((b = b.parentNode) == a)
		return true;
	return false;
}

function dynamichide(e){
	if (ie4&&!dropmenuobj.contains(e.toElement))
		delayhidemenu()
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		delayhidemenu()
}

function hidemenu(e){
	if (typeof dropmenuobj!="undefined"){
		if (ie4||ns6)
			dropmenuobj.style.visibility="hidden"
	}

	// Bring the <select>s back
	if (is_ie) {
		selectlist=document.getElementById("main-content").getElementsByTagName('select')
		for(i=0;i<selectlist.length;i++) {
			selectlist[i].style.visibility="visible";
		}
	}

	// Return shop tab to static state if you're not in the shop section
	if (!(document.getElementById("shoptab").className=="tabon"))
        taboff(document.getElementById("shoptab").firstChild)
}

function delayhidemenu(){
	if (ie4||ns6)
		delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
	if (typeof delayhide!="undefined")
		clearTimeout(delayhide)
}

function displayCharsAvailable(textArea, maxLength, displayObject) {
	// check to see if the textArea object exists
	if (document.getElementById(textArea)) {
		var taValue = document.getElementById(textArea).value;
		// get the text area length
		var taLength = taValue.length;
		var charsLeft = parseInt(maxLength) - taLength;

		// don't allow any more characters
		if (charsLeft <= 0) {
			document.getElementById(textArea).value =  taValue.substring(0, maxLength);
			charsLeft = 0;
		}

		// display the characters available
		if (document.getElementById(displayObject)) {
			document.getElementById(displayObject).innerHTML = charsLeft;
		}

		
	}
	
}
// added to move markup out of the JSPs that interfered with the validator
function getShopTabLink(linkPrefix, shopLink, shopName) {
    return '<a href="http://' + linkPrefix + '/' + shopLink + '">' + shopName + '</a>';

}

function getShareTabLink(shareName, sharetabName) { 
    return '<a href=javascript:showshareTab("'+sharetabName+'");>' + shareName + '</a>';
}

function getAnonShareTabLink(linkPrefix, shareName, sharetabName, shareLink) { 
    return '<a href="http://' + linkPrefix + '/' + shareLink + '">' + shareName + '</a>';
    document.cookie = "sharetab="+sharetabName;  
    window.location.href=linkUrl;    
}


function showCountryCodes(token) {
	var newWin = window.open("PSHelpCountryCodePopup.jsp?" + token,  "ps_popup", "resizable,width=550,height=510");
	if(newWin)  newWin.focus();
	return false;
}

function outputHTMLString(htmlString){
	document.write(htmlString);
}

function createPlayerDOM(container, attrs, params, embedAttrs){

	var myContainer = document.getElementById(container);
	var myObject = document.createElement("object");
	var param;
	for (i in params) {
		param = document.createElement("param");
		param.name = i;
		param.value = params[i];
		myObject.appendChild(param);
	}
	for (i in attrs) {
		myObject.setAttribute(i, attrs[i]);
	}
	if (document.all) {
		myContainer.appendChild(myObject);
		//initialize app special fix for IE
		myContainer.innerHTML = myContainer.innerHTML;
	} else {
		var myEmbed = document.createElement("embed");
		for (i in embedAttrs) {
			myEmbed.setAttribute(i, embedAttrs[i]);
		}
		myContainer.appendChild(myEmbed);
	}
		
}

/* Overiding the coremetrics functions */

function cmCreateRegistrationTag(customerID,customerEmail,memberType) {
	//do nothing	
}

function cmCreatePageElementTag(elementID, elementCategory, pageID, pageCategoryID, elementLocation) {
	//do nothing	
}

function cmCreatePageviewTag(pageID, searchString, categoryID, searchResults) {
	//do nothing	
}

 function cmCreateConversionEventTag(eventID, actionType, categoryID, points) {
	//do nothing
 }
 
 function cmCreateProductviewTag(productID, productName, categoryID) {
	//do nothing
}
