function showBox(fullUrl){
	window.open(fullUrl,"showBoxCovers","left=10,top=10,width=875,height=600,resizable=1,status=1,scrollbars=1");
}

function showFeedback(fullUrl) {
	window.open(fullUrl,"showFeedback","left=10,top=10,width=700,height=500,resizable=1,status=1,scrollbars=1");
}

function showTerms(fullUrl) {
    window.open(fullUrl, 'termsAndConditions', 'width=500,height=400,resizable=1,status=1,scrollbars=1');
}

function openLiveHelpBox(cm_re){
	window.open('http://server.iad.liveperson.net/hc/599832/?'+cm_re+'cmd=file&file=visitorWantsToChat&site=599832&skill=AEBN&imageUrl=https://server.iad.liveperson.net/hcp/Gallery/ChatButton-Gallery/English/General/1a/&referrer='+document.location,'chat599832','width=472,height=320');
	return false;
}

function resizeToCovers() {
	var resizerDiv = document.getElementById('resizer');
	var resizerHeight =  resizerDiv.offsetHeight;
	var resizerWidth = resizerDiv.offsetWidth;
	var boxFront;
	var boxBack;
	boxFront = document.getElementById("frontBoxCover");
	boxBack = document.getElementById("backBoxCover");
	var deltaWidth;
	var deltaHeight;
	if (boxFront) {
		deltaWidth = boxFront.width;
		deltaHeight = boxFront.height;
	}
	if (boxBack) {
		deltaWidth += boxBack.width;
		if (boxBack.height > deltaHeight) {
			deltaHeight = boxBack.height;
		}
	}
	deltaWidth = deltaWidth - resizerWidth;
	deltaHeight = deltaHeight - resizerHeight;
	window.resizeBy(deltaWidth, deltaHeight);
	window.focus();
}

function resizeToImage() {
	var resizerDiv = document.getElementById('resizer');
	var resizerHeight =  resizerDiv.offsetHeight;
	var resizerWidth = resizerDiv.offsetWidth;

	var gImage;
	gImage = document.getElementById("galleryImage");
	
	var deltaWidth;
	var deltaHeight;
	
	if (gImage) {
		deltaWidth = gImage.width
		deltaHeight = gImage.height;
	}
	deltaWidth = deltaWidth - resizerWidth;
	deltaHeight = deltaHeight - resizerHeight;
	window.resizeBy(deltaWidth, deltaHeight);
	window.focus();
}

/* cookie functionality by yilong */

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+escape(value)+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
	}
	return null;
}

function deleteCookie(name) {
	createCookie(name,"",-1);
}
/* end cookie functionality by yilong */

// function to pop realtouch search select on realtouch frontdoor
function getRealtouchSearchOptions(link, defaultOption) {
    $.getJSON(link, function(data) {
        var searchOptions = '';
        searchOptions += '<option>' + defaultOption + '</option>';
        for (var i = 0; i < data.options.length; i++) {
            searchOptions += '<option value="' + data.options[i].optionValue + '">' + data.options[i].optionDisplay + '</option>';
        }
        $("select#realtouchSearchItems").html(searchOptions);
    });
}

// add realtouch movies/clips to favs
function addRealtouchToFavorites(id, type, link) {
    $.ajax({
        type: "POST",
        url: link,
        data: {type: type, id: id},
        dataType: "text/html",
        cache: false,
        success: function(html) {
            $("#TB_ajaxWindowTitle").html(html);
        },
        error: function() { //remove me
            alert("Error adding favorite");
        }
    })
}

function applyPNGFix(imgToFix){
	var img = imgToFix;
	var imgName = img.src.toUpperCase();
	if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
		var imgID = (img.id) ? "id='" + img.id + "' " : "";
		var imgClass = (img.className) ? "class='" + img.className + "' " : "";
		var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
		var imgStyle = "display:inline-block;" + img.style.cssText;
		if (img.align == "left") imgStyle = "float:left;" + imgStyle;
		if (img.align == "right") imgStyle = "float:right;" + imgStyle;
		if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
		var imgWidth = (img.width == 0) ? img.style.width : img.width + "px";
		var imgHeight = (img.height == 0) ? img.style.height : img.height + "px";
		var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + imgWidth + "; height:" + imgHeight + ";" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
		img.outerHTML = strNewHTML;
		i = i-1;
	}
}
function requiresPNGFix() {
	var browser = new BrowserDetectVeryLite();
	return (browser.isIE5to6 && browser.isWin32);
}

function applyMultiplePNGFixes(imageIdArray) {
	if (requiresPNGFix()) {
		for (var i = 0; i < imageIdArray.length; i++) {	
			var imgToFix = document.getElementById(imageIdArray[i]);
			applyPNGFix(imgToFix);
		}
	}
}

// Stripped version of Browser Detect Lite  v2.1
// http://www.dithered.com/javascript/browser_detect/index.html
// modified by shannonh to only check for IE 5.5 - 7 and windows
function BrowserDetectVeryLite() {
	var ua = navigator.userAgent.toLowerCase(); 
	this.ua = ua;
	// browser name
	this.isIE = ( (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) ); 
	// browser version
	this.versionMinor = parseFloat(navigator.appVersion); 
	// correct version number for IE4+ 
	if (this.isIE && this.versionMinor >= 4) {this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );}
	this.versionMajor = parseInt(this.versionMinor); 
	// platform
	this.isWin   = (ua.indexOf('win') != -1);
	this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1) );
	this.isIE5to6 = (this.isIE && this.versionMajor >= 5 && this.versionMajor < 7);
}

// hide / show the sort favorites select if it exists
// this is a workaround for the IE6 z-index bug
// We will hide the select so that it doesn't 
// appear with a higher z-index than the bandwidth popup.
function hideSortSelect() {
	if (requiresPNGFix()) {
		// is IE5 to IE6 on Windows
		var sortMoviesSelect = document.getElementById('sortMoviesSelect');
		if (sortMoviesSelect != null) {
			sortMoviesSelect.style.display = 'none';
		}
	}
}
function showSortSelect() {
	if (requiresPNGFix()) {
		// is IE5 to IE6 on Windows
		var sortMoviesSelect = document.getElementById('sortMoviesSelect');
		if (sortMoviesSelect != null) {
			sortMoviesSelect.style.display = 'block';
		}
	}
}
// END hide / show the sort favorites select if it exists

//switch boxcover on the 1024 wide layout frontdoor
function switchBoxCover(divId, itemIndex){
	var boxcoverDivId = "#"+divId+"BoxCover";
	var newBoxcoverDivId = "#"+divId+"BoxCover"+itemIndex;
    $(boxcoverDivId).html($(newBoxcoverDivId).html());
}

//Find PNGs without IDs so that applyPNGFix will work in IE6.
//pageZone narrows the page search area
//function ex.: $(function() { pngNoIdFix('.helpFaq'); });
function pngNoIdFix(pageZone){
	if($.browser.msie && $.browser.version.substr(0,1) == 6){
		var imageId = new Array();
		var pngObj = pageZone == undefined ? $("img[src*='png']") : $(pageZone + " img[src*='png']");
		var i = 0;
		
		pngObj.each(function(i){	
			if(!$(this).attr('id')){
				pngHeight = $(this).height();
				pngWidth = $(this).width();
				
				$(this).attr({ 
					height : pngHeight,
					width  : pngWidth,
					id     : function(){return "png" + i;}
				});
				
				imageId.push($(this).attr('id'));
				i++; 
			}
		});
		applyMultiplePNGFixes(imageId);
	}
}

//returns locale and orientation of page
function getLocaleOrientation(){
	localeOrientation = $('body').attr('class').split(' ');
	
	return {locale:localeOrientation[0], orientation:localeOrientation[1]}; 
}
