function ShowEmailDownloadLinkPopup(UrlRecipient,ImageName,Size,Usage)
{ // Opens an Email Form

	var w = 600;
	var h = 550;
	var left = (screen.width) ? parseInt((screen.width - w) / 2) : 0;
	var top = (screen.height) ? parseInt((screen.height - h) / 4) : 0;
	var winUrl = "emaildownloadlink.asp?UrlRecipient=" + UrlRecipient + "&ImageName=" + ImageName + "&Size=" + Size + "&Usage=" + Usage ;
	var emailPopUp = window.open(winUrl ,"EmailDownloadLink","resizable=0,scrollbars=0,toolbar=0,menubar=0,directories=0,height="+h+",width="+w+",top="+top+",left="+left);
		
	if (window.focus) emailPopUp.focus();	
}

function ShowDownloadPopup(UrlRecipient, ImageName,Size,Usage, CheckHiRes)
{// Opens a Download Popup

	var w = 550;
	var h = 365;	
	var left = (screen.width) ? parseInt((screen.width - w) / 2) : 0;
	var top = (screen.height) ? parseInt((screen.height - h) / 3) : 0;
	var winUrl = "DownloadHolding.asp?UrlRecipient=" + UrlRecipient + "&ImageName=" + ImageName + "&Size=" + Size + "&Usage=" + Usage + "&CheckHiRes=" + CheckHiRes;
	var downloadPopUp = window.open(winUrl ,"Download","resizable=no,scrollbars=no,toolbar=no,status=no,menubar=no,directories=no,height="+h+",width="+w+",top="+top+",left="+left);
	
	if (window.focus) downloadPopUp.focus();
}


function ShowSODPopup(ImageName)
{// Opens a SOD Message Popup
	
	var w = 450;
	var h = 300;	
	var left = (screen.width) ? parseInt((screen.width - w) / 2) : 0;
	var top = (screen.height) ? parseInt((screen.height - h) / 3) : 0;
	var sodUrl = "SODMessage.asp?ImageName=" + ImageName;
	var sodPopUp = window.open(sodUrl ,"ImageAvailability","resizable=no,scrollbars=no,toolbar=no,status=no,menubar=no,directories=no,height="+h+",width="+w+",top="+top+",left="+left);
	
	if (window.focus) sodPopUp.focus();
}

function ShowImagePopup(imageid, imagex){
	imageid = escape(imageid);
		
	// Billy Atkins - 8/15/2005 - Added Brand Search vars
	var isBrandSearch = false;
	var brandName = "";
	var searchPG = "";
	
	try{
		isBrandSearch = document.frmSearch.IsBrandSearch.value;
		brandName = document.frmSearch.BrandName.value;
		fotog = document.frmSearch.fotog.value;
	}catch(e){}
	
	ShowPreviewPopup(imageid, null, null, imagex, isBrandSearch, brandName, fotog, "0001");
	//var prevUrl = "preview.asp?pbtop=&image=" + imageid + "&imagex=" + imagex + "&searchnum=0001&isBrandSearch=" + isBrandSearch + "&BrandName=" + brandName + "&fotog=" + fotog;
	//var previewPop = window.open(prevUrl,"PopupPreview","status=yes,scrollbars=yes,resizable=yes,directories=no,toolbar=no,menubar=no,height=625,width=800,top=10,left=10");	
	
	//previewPop.focus();
}

function ShowCDPopup(imageid, imagex){
	imageid = escape(imageid);
		
	// Billy Atkins - 8/15/2005 - Added Brand Search vars
	var isBrandSearch = false;
	var brandName = "";
	var searchPG = "";
	
	try{
		isBrandSearch = document.frmSearch.IsBrandSearch.value;
		brandName = document.frmSearch.BrandName.value;
		fotog = document.frmSearch.fotog.value;
	}catch(e){}
	
	//ShowPreviewPopup(imageid, 860, null, imagex, isBrandSearch, brandName, fotog, "0001");
	
	var prevUrl = "preview.asp?pbtop=&image=" + imageid + "&imagex=" + imagex + "&searchnum=0001&isBrandSearch=" + isBrandSearch + "&BrandName=" + brandName + "&SearchPG=" + searchPG;
	var previewPop = window.open(prevUrl,"PopupPreview","status=yes,scrollbars=yes,resizable=yes,directories=no,toolbar=no,menubar=no,height=625,width=860,top=10,left=10");	
	
	previewPop.focus();
}


function ShowPreviewPopup(imageid, width, height, imagex, isBrandSearch, brandName, fotog, searchNum, pbTop, isCDBackUrl)
{
	if (width == null)
	{
		width = 800;
	}
	
	if (height == null)
	{
		height = 625;
	}

	imageid = escape(imageid);
	
	var brandSearchVars = "IsBrandSearch=" + isBrandSearch + "&BrandName=" + brandName + "&fotog=" + fotog;	
	
	var url = "preview.asp?pbtop=" + pbTop + "&image=" + imageid + "&imagex=" + imagex + "&searchnum=" + searchNum + "&pbx=" + imagex + "&isCDBackUrl=" + isCDBackUrl + "&" + brandSearchVars
	var previewPop = window.open(url,"PopupPreview","status=yes,scrollbars=yes,resizable=yes,directories=no,toolbar=no,menubar=no,height=" + height + ",width=" + width + ",top=10,left=10");	

	previewPop.focus();
}

function HideThumbSMLTDiv(ImageName)
{// Hides the "Show more like this" link in the caption

	try
	{											
		document.getElementById("dvSMLT" + ImageName).style.visibility = 'hidden';											
	}
	catch(e)
	{										
		//	alert(e.description)
	}										
}

function PostSearchForm(SearchType)
{// Posts the search form while facilitating Web Trends tracking of the Randomize functionality

	var action = new String(document.formsearch.action);
	var q;

	if (action.indexOf("?") == -1)
	{
		q = "?";
	}
	else
	{
		q = "&";
	}
	
	document.formsearch.action = action + q + "trSearch=" + SearchType;
	document.formsearch.submit();

}

function CrushShowMoreLikeThis()
{

	try
	{
		var links = document.getElementsByTagName("a");
		var href;
		
		for (var i=0;i < links.length; i++)
		{		
			href = new String(links[i].href);
		
			if (href.indexOf("SMLT(") > 0)
			{
				links[i].innerText = "";
				links[i].innerHTML = "";
			}
		}	
	}
	catch(e){}
}


function ReplaceImagePaths()
{
// Don't need this, but the call is made all over the site
// Need to remove call to this function

// Replaces encoded image paths will the real path
/*	try{
		var imgs = document.getElementsByTagName("img");
		var path;
		
		for (var i=0;i < imgs.length; i++){		
			path = new String(imgs[i].src);
		
			if (path.toUpperCase().indexOf("I.ASP?") != -1){
				imgs[i].src = GetImagePath(path);
			}
		}	
	}catch(e){}*/
}


function GetImagePath(ImageSource){
	
	try{
		var imgSource = new String(ImageSource);

		var image = imgSource.substring(imgSource.indexOf("?I=") + 3,imgSource.indexOf("&S="));
		var url = "http://Delivery.SuperStock.com/Image/" + GetPG(image);
		var size;
		
		if (imgSource.indexOf("&F=") == -1){
			size = parseInt(imgSource.substring(imgSource.indexOf("&S=") + 3,imgSource.length));
		}else{
			size = parseInt(imgSource.substring(imgSource.indexOf("&S=") + 3,imgSource.indexOf("&F=")));
			url += "/" + imgSource.substring(imgSource.indexOf("&F=") + 3,imgSource.length);
		}
		
		// Verify that a valid size exists
		if (isNaN(size) || (size != 1 && size != 3)){
			return ImageSource;
		}

		switch (size){
			case 1:	
				url += "/Thumb/" + image + ".jpg"; 
				break;
			case 3:
				url += "/PreviewComp/SuperStock_" + image + ".jpg";
				break;
			default:
				return ImageSource;
				break;
		}

		// Return the actual image path
		return url; 
	}catch(e){
		return ImageSource;
	}
}


function GetPG(ImageName){
	try{
		var imageName = new String(ImageName);

		if (imageName.indexOf("-") != -1){
		
			var firstPart = new String(imageName.substr(0,imageName.indexOf("-")));
			var classCode =  new String(firstPart.substr(firstPart.length-1,firstPart.length));
			
			if (isNaN(classCode)){
				return new String(firstPart.substr(0,firstPart.length-1));
			}else{
				return firstPart;
			}
		
		}else{
			return "";
		}
	}catch(e){
		return "";
	}
}
function ShowRestrictionsPopup(ImageName)
{
	// Show Restriction Information Screen
	// 2006/03/14  Adrian Leishman
	var w = 375;
	var h = 250;	
	var left = (screen.width) ? parseInt((screen.width - w) / 2) : 0;
	var top = (screen.height) ? parseInt((screen.height - h) / 3) : 0;
	var wind = "RestrictionInfo.asp?ImageName=" + ImageName;
	var wind = window.open(wind ,"RestrictionInfo","resizable=no,scrollbars=no,toolbar=no,status=no,menubar=no,directories=no,height="+h+",width="+w+",top="+top+",left="+left);
	
	if (window.focus) wind.focus();
}