
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function popupSelectPhone(selectPhoneURL, makeId) {
        if(makeId != "")
        {
                selectPhoneURL += '&makeId=' + makeId;
        }
        selectPhoneWindow = window.open(
                selectPhoneURL,
                'selectPhone',
                'width=676,height=378,resizable=no,scrollbars=no,resizable=no,status=no,toolbar=no,location=no,menubar=no'
                );
        // in case of pop up blocker (user can select phone from main window)
        if (selectPhoneWindow!=null && typeof(selectPhoneWindow)!="undefined")
        {
                selectPhoneWindow.moveTo(50,50);
                selectPhoneWindow.focus();
        }
}

function closeSelectPhonePopup(oldDeviceID, newDeviceID)
{
	parent.window.close();
	parent.opener.changeDeviceCategory(oldDeviceID, newDeviceID);
	parent.window.deviceSelectionForm.submit();
}

function popupMoreInfo(moreInfoURL, productId, SKU)
{
	if( (productId != "") && (SKU != "") )
	{
		moreInfoURL += '&prodId=' + productId + '&SKU=' + SKU;
	}
	infoWindow = window.open(moreInfoURL,'MoreInfo','width=560,height=580,resizable=yes,scrollbars=yes');
	infoWindow.moveTo(10,30);
	infoWindow.focus();
}

function popupBundleMoreInfo(moreInfoURL, resourceID)
{
	if(resourceID != "")
	{
		moreInfoURL += '&resourceID=' + resourceID;
	}
	infoWindow = window.open(moreInfoURL,'MoreInfo','width=560,height=580,resizable=yes,scrollbars=yes');
	infoWindow.moveTo(10,30);
	infoWindow.focus();
}

function closePopupAndChangeOpener(url)
{
	if(opener)
	{
		window.close();
		opener.location.replace(url);
	}
	else
	{
		window.moveTo(0,0);
		window.outerHeight = screen.availHeight;
		window.outerWidth = screen.availWidth;
		location.replace(url);
	}
}




function changeDeviceCategory(oldDeviceID, newDeviceID)
{

	if(oldDeviceID != newDeviceID){
		currentURL = window.document.location.href;
		currentURL = currentURL.replace(/&amp;/g, "&");
		currentDc = "dc=" + oldDeviceID;
		emptyDc = "dc=";
		newDc = "dc=" + newDeviceID;
		indexDc = currentURL.indexOf(currentDc);
		indexQuestion = currentURL.indexOf("?");
		indexEmptyDc = currentURL.indexOf(emptyDc);
		indexNewDc = currentURL.indexOf(newDc);
		newUrl = currentURL;
		tempUrl = currentURL;
	
		/*
		 * In the event the user is looking at content with multiple pages and not on the
		 * first page of content need to look for the resourceIndex field to remove from
		 * the URL. This will send the user to page 1 of the currently selected content
		 * whenever a new device is selected. Fix for bug 30514.
		 */
		indexResourceIndex = currentURL.indexOf("resourceIndex");
		if( indexResourceIndex != -1 ) 
		{
			// Check to see if the param is in the middle of the URL or at the end
			//
			indexAmpAfterResource = currentURL.indexOf("&", indexResourceIndex);
			if( indexAmpAfterResource == -1 )
			{
				currentURL = currentURL.substring(0, indexResourceIndex);
			}
			else
			{
				tempUrl = currentURL.substring(0, indexResourceIndex);
				currentURL = tempUrl.concat(currentURL.substring(indexAmpAfterResource+1));	
			}
		}
		
		if (indexEmptyDc == -1){
			if(indexQuestion == -1)
			{
				newUrl = currentURL + "?" + newDc;
			}
			else
			{
				newUrl = currentURL + "&" + newDc;
			}
		}
		else{
			if(indexDc != -1)
			{
				newUrl = currentURL.replace(currentDc, newDc);
			}else
			{
				newUrl = currentURL.replace(emptyDc, newDc);
			}
		}
		
		window.location.replace(newUrl);
		dcSet(newDeviceID);
	}	
}


function appendDeviceCategory(newDeviceID)
{
	currentURL = window.document.location.href;
	if (currentURL.indexOf("?") == -1)
	{
		newUrl = currentURL + "?dc=" + newDeviceID;
	}
	else
	{
		newUrl = currentURL + "&dc=" + newDeviceID;
	}

	window.location.replace(newUrl);
}

function popupStafInstructions(stafInstrUrl)
{
	//stafInstrWindow = window.open(stafInstrUrl, 'SendToAFriendInstructions','width=445,height=500,resizable=yes,scrollbars=yes');
	stafInstrWindow = window.open(stafInstrUrl, 'SendToAFriendWapInstructions','width=445,height=500,resizable=yes,scrollbars=yes');
	stafInstrWindow.moveTo(10,30);
	stafInstrWindow.focus();
}

function popupSendToAFriend(stafUrl)
{
	stafWindow = window.open(stafUrl, 'SendToAFriend','width=460,height=647,resizable=yes,scrollbars=no');
	stafWindow.moveTo(10,30);
	stafWindow.focus();
}

function popupMediaMallTour(mediaMallTourUrl, width, height)
{
	mediaMallTourWindow = window.open(mediaMallTourUrl, 'MediaMallTour','width=' + width + ',height=' + height + ',resizable=yes');
	//mediaMallTourWindow.moveTo(10,30);
	mediaMallTourWindow.focus();
}

function popupRatingsInfo(ratingsInfoUrl)
{
	ratingsHelpWindow = window.open(ratingsInfoUrl, 'RatingsInfo','width=550,height=720,resizable=yes,scrollbars=no');
	ratingsHelpWindow.moveTo(10,30);
	ratingsHelpWindow.focus();
}
