﻿// Main project javascript file

var d = document;
dId =  function(id){
	//return d.getElementById(id);
        if (document.getElementById) 
            var returnVar = document.getElementById(id); 
        else if (document.all) 
            var returnVar = document.all[id]; 
        else if (document.layers) 
            var returnVar = document.layers[id]; 
        
        return returnVar; 	
}
dCss = function(id){
	return dId(id).style;
}
dTags = function(id, tagName){
	if(tagName == undefined){
		return false;
	} else {
		if(id == undefined){
			return d.getElementsByTagName(tagName);
		} else {
			return dId(id).getElementsByTagName(tagName);
		}
	}
}
// enumerate through properties and methods in an object and show the results
function dEnum(myObject){
	var temp = "";
	for(myItem in myObject){
		temp += myItem +": "+ myObject[myItem] + " // ";
	}
	alert(temp);
}

isIE = (document.attachEvent) ? true : false;

// search button client id
var searchButtonID = '';

function showTC()
{
	var newwin;
	var leftVal = (700 - screen.width) / 2;
	var topVal = (500 - screen.height) / 2;

	newwin = window.open("tc.htm","TC","width=700,height=600,resizable=yes,scrollbars=yes,left="+leftVal+",top="+topVal);

	return false;
}

function showPS()
{
	var newwin;
	var leftVal = (700 - screen.width) / 2;
	var topVal = (500 - screen.height) / 2;

	newwin = window.open("ps.htm","PS","width=700,height=600,resizable=yes,scrollbars=yes,left="+leftVal+",top="+topVal);

	return false;
}

function showSearchTips()
{
	var newwin;
	var leftVal = (700 - screen.width) / 2;
	var topVal = (500 - screen.height) / 2;

	newwin = window.open("searchtips.htm","ST","width=700,height=600,resizable=yes,scrollbars=yes,left="+leftVal+",top="+topVal);

	return false;
}

function emailLightbox()
{
	var newwin;
	var leftVal = (600 - screen.width) / 2;
	var topVal = (700 - screen.height) / 2;

	newwin = window.open("EmailLightbox.aspx","ST","width=600,height=700,resizable=yes,scrollbars=yes,left="+leftVal+",top="+topVal);

	return false;
}

function DownloadEPS(downloadURL)
{
    var faction = dId("ActionsFrame");
    faction.src = downloadURL;

    return false;
}

function showDisclaimer()
{
	var newwin;
	var leftVal = (700 - screen.width) / 2;
	var topVal = (600 - screen.height) / 2;

	newwin = window.open("disclaimer.htm","disclaimer","width=700,height=600,resizable=yes,scrollbars=yes,left="+leftVal+",top="+topVal);

	return false;
}

function showEvent(eventnumber)
{
    window.top.location = 'EventViewer.aspx?id=' + eventnumber;
}

function showGraphicSet(setid)
{
    window.top.location = 'GraphicsViewer.aspx?id=' + setid;
}

function showRFSet(setid)
{
    window.top.location = 'RoyaltyFreeViewer.aspx?id=' + setid;
}


function showLiveEvent(eventnumber, eventid)
{
	var mywidth = screen.availWidth;
	var myheight = screen.availHeight;

    window.open('LiveEventViewer.aspx?id=' + eventnumber,eventid.replace("-","_"),'resizable=yes,width=' + mywidth + 'px,height=' + myheight + 'px,left=0,top=0,scrollbars=yes');
}

function openZipDownloader()
{
    window.open('zipDownloader.aspx','zipDownloader','resizable=yes,width=600px,height=90px,scrollbars=yes');
}

function confirmZipDownload()
{
    if(parseInt(catalogTotalRecords) <= 0)
    {
        alert('No images available in the Download Cart to download.');
        return false;
    }

    var zipPanel = dId('zipDCartPanel');
    var dCartPage = dId('dCartPage');
    var zipForm = dId('zipDCartForm');
    
    var pos = findBothPos(dCartPage);
    zipPanel.style.cssText = 'position: absolute; z-index: 99;background-color:#f0f0f0;opacity: 0.8; -moz-opacity: 0.8; filter: alpha(opacity=80);  display: block; left: '
    + dCartPage.offsetLeft + 'px; top: ' + dCartPage.offsetTop + 'px; width: ' + dCartPage.offsetWidth + 'px; height: ' + dCartPage.offsetHeight + 'px';
    
    zipForm.style.display = 'block';

    return false;
}

function closeZipDownload()
{
    var zipPanel = dId('zipDCartPanel');
    var zipForm = dId('zipDCartForm');
    
    zipPanel.style.display = 'none';
    zipForm.style.display = 'none';
}
        
function confirmEmailDownload()
{
    if(parseInt(catalogTotalRecords) <= 0)
    {
        alert('No images available in the Download Cart to download.');
        return false;
    }
    
    var zipMsg = 'You are about to download all the images from the Download Cart to your email. Please confirm? \n\nPlease note this may take few seconds to several minutes depends on the number of images in your Download Cart.';
    if(confirm(zipMsg))
    {
        var faction = dId("DCartActionsFrame");
        faction.src = 'doActions.aspx?action=dcartemaildownload';
        return false;
    }
    else
    {
        return false;
    }
}

function confirmFTPDownload()
{
    if(parseInt(catalogTotalRecords) <= 0)
    {
        alert('No images available in the Download Cart to download.');
        return false;
    }
    else
    {
        window.open('ftpDownloader.aspx','ftpDownloader','resizable=yes,width=425px,height=330px,scrollbars=yes');
    }
}

function confirmClearDownload()
{
    if(parseInt(catalogTotalRecords) <= 0)
    {
        alert('No images available in the Download Cart to clear.');
        return false;
    }
    else
    {
        return confirm('You are about to remove all the images from your Download Cart. Please click OK to clear the Download Cart, otherwise click CANCEL.');
    }
}

function zipdownload(sidx, eidx)
{
    var faction = dId("DCartActionsFrame");
    faction.src = 'doActions.aspx?action=dcartzipdownload&sidx=' + sidx + '&eidx=' + eidx +'&id=';
}

function findBothPos(obj)
{
    var curleft = curtop = 0;

    if (obj.offsetParent)
    {
        curleft = obj.offsetLeft;
        curtop = obj.offsetTop;
        while (obj = obj.offsetParent) 
        {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        }
        
        curleft = 0;
        curtop = 0;
    }
    return [curleft,curtop];
}

function scroll2Top()
{
   var myPage = dId('PageContainer');
   
   if(myPage)
    myPage.scrollTop = 0;
}

function ResetScrollPosition()
{
   var scrollX = dId('__SCROLLPOSITIONX');
   var scrollY = dId('__SCROLLPOSITIONY');

   if(scrollX && scrollY)
   {
      scrollX.value = 0;
      scrollY.value = 0;
   }
}  


function validateFTPDownloader(ftpServer,isAms,uName,Pwd)
{
    if(dId(ftpServer).value == '')
    {
        alert('FTP Server Address is mandatory');
        return false;
    }
    
    if(!dId(isAms).checked)
    {
        if((dId(uName).value == '') || (dId(Pwd).value == ''))
        {
            alert('Invalid username and password specified. Please try again.');
            return false;
        }        
    }
    
    var ftpMsg = 'You are about to upload all the images from the Download Cart to your FTP Server. Please confirm? \n\nPlease note this may take few seconds to several minutes depends on the number of images in your Download Cart.';
    if(confirm(ftpMsg))
    {
        return true;
    }
    else
    {
        return false;
    }
}

function showAlbum(albumid)
{
    window.top.location = 'AlbumViewer.aspx?id=' + albumid;
}

// download image
function downloadImage(imageURL)
{
    if(imageURL == '')
    {
        alert('Invalid image to add to download cart.');
        return;
    }       
    
    var faction = document.getElementById("ActionsFrame");
    faction.src = imageURL;
}

// download cart add or remove image 
function downloadCartToggleImage(imageid,sourceControl)
{
    if(imageid == '')
    {
        alert('Invalid image to add to download cart.');
        return;
    }       
    
    var faction = document.getElementById("ActionsFrame");
    faction.src = 'doActions.aspx?action=dcarttoggleimage&imageid=' + imageid;
    
    if(sourceControl.alt.toLowerCase() == 'add to download cart')
    {
        sourceControl.src = 'siteimages/downloadcart_selected.gif';
        sourceControl.title = 'Remove from Download Cart';
        sourceControl.alt = 'Remove from Download Cart';
    }
    else
    {
        sourceControl.src = 'siteimages/downloadcart_normal.gif';
        sourceControl.title = 'Add To Download Cart';
        sourceControl.alt = 'Add To Download Cart';    
    }
}

// lightbox add or remove image for imageviewer
function lightBoxToggleImage(imageid,lightboxid,sourceControl)
{
    if(imageid == '')
    {
        alert('Invalid image to add to lightbox.');
        return;
    }       
    
    var faction = document.getElementById("ActionsFrame");
    faction.src = 'doActions.aspx?action=lboxtoggleimage&lboxid=' + lightboxid + '&imageid=' + imageid;
    
    if(sourceControl.alt.toLowerCase() == 'add to lightbox')
    {
        sourceControl.src = 'siteimages/NewRemoveFromLightBox.gif';
        sourceControl.title = 'Remove from Light Box';
        sourceControl.alt = 'Remove from Light Box';
    }
    else
    {
        sourceControl.src = 'siteimages/NewAddToLightBox.gif';
        sourceControl.title = 'Add To Lightbox';
        sourceControl.alt = 'Add To Lightbox';    
    }
}


function getWindowWidth()
{
	var wHeight, wWidth, sHeight, sWidth, bitDepth;

	if (document.all)
	{
		wHeight = document.body.clientHeight;
		wWidth = document.body.clientWidth;
		sHeight = screen.height;
		sWidth = screen.width;
		bitDepth = screen.colorDepth; 
	}
	else if (document.layers)
	{	
		wHeight = window.innerHeight;
		wWidth = window.innerWidth;
		sHeight = screen.height;
		sWidth = screen.width;
		bitDepth = screen.colorDepth; 
	}
	else
	{
		wHeight = window.innerHeight;
		wWidth = window.innerWidth;
		sHeight = screen.height;
		sWidth = screen.width;
		bitDepth = screen.colorDepth; 				
	}

	//alert("wHeight : "+ wHeight + " - wWidth : " + wWidth + " - sHeight : " + sHeight + " - sWidth : " + sWidth);
	setCookie("wHeight",wHeight);
	setCookie("wWidth",wWidth);
	setCookie("sHeight",sHeight);
	setCookie("sWidth",sWidth);
}

function showImage(qstring)
{
    window.open('ImageViewer.aspx?id=' + qstring,'showImage','resizable=yes,width=650px,height=600px,scrollbars=yes');
}

function showEventImage(qstring)
{
    window.open('EventImageViewer.aspx?id=' + qstring,'showEventImage','resizable=yes,width=750px,height=650px,scrollbars=yes');
}

function showAlbumImage(qstring)
{
    window.open('AlbumImageViewer.aspx?id=' + qstring,'showAlbumImage','resizable=yes,width=750px,height=650px,scrollbars=yes');
}

function showEShelfImage(qstring)
{
    window.open('EShelfImageViewer.aspx?id=' + qstring,'showEShelfImage','resizable=yes,width=750px,height=650px,scrollbars=yes');
}

function showGraphicsImage(qstring)
{
    window.open('GraphicsImageViewer.aspx?id=' + qstring,'showGraphicsImage','resizable=yes,width=750px,height=650px,scrollbars=yes');
}

function showRFImage(qstring)
{
    window.open('RFImageViewer.aspx?id=' + qstring,'showRFImage','resizable=yes,width=750px,height=650px,scrollbars=yes');
}

function showDCartImage(qstring)
{
    window.open('DCartImageViewer.aspx?id=' + qstring,'showDCartImage','resizable=yes,width=750px,height=650px,scrollbars=yes');
}

function showLBoxImage(qstring)
{
    window.open('LBoxImageViewer.aspx?id=' + qstring,'showLBoxImage','resizable=yes,width=750px,height=650px,scrollbars=yes');
}

function showSearchImage(qstring)
{
    window.open('searchImageViewer.aspx?id=' + qstring,'showSearchImage','resizable=yes,width=750px,height=650px,scrollbars=yes');
}

function resizePreviewWindow(size)
{
    if(size == 'large')
    {
        var leftpos = (self.screen.width/2) - (415);
		var toppos = (self.screen.height/2) - (320);    
		self.moveTo(leftpos,toppos);
		self.resizeTo(750,650);
    }
    else if(size == 'screensize')
    {
        maximiseWin();
    }
}
        
function maximiseWin() 
{
	if (window.screen) 
	{
		var mywidth = screen.availWidth;
		var myheight = screen.availHeight;
		if(window)
		{
		    window.top.moveTo(0, 0);
		    window.top.resizeTo(mywidth,myheight);
		}
	}
}


function addOption(selectObject,optionText,optionValue) {
    if ( !recheck (selectObject, optionText, optionValue) ){
      var optionObject = new Option(optionText,optionValue)
      var optionRank = selectObject.options.length
      selectObject.options[optionRank]=optionObject
    }
    else{
        alert("Option is already present");
    } 

}

function deleteOption(selectObject,optionRank) {
    if (selectObject.options.length!=0) { selectObject.options[optionRank]=null }
}

function recheck (selectObject, optionText, optionValue){ 
  var sltbool = false;
  for (i=0; i<selectObject.options.length; i++){
     if (optionText == selectObject.options[i].text ||  optionValue == selectObject.options[i].text ){
        sltbool = true;
        break
     }
  } 
  return sltbool;
}

function toggleSlide(panelName,triggerImgName)
{
    var sPanel = dId(panelName)
    var triggerImg = dId(triggerImgName);
    
    if(sPanel)
    {
        if(sPanel.style.display == 'none')
        {
            slidedown(panelName);
            triggerImg.src = 'siteImages/collapse.gif';
            triggerImg.alt = 'collapse'; 
        }
        else
        {
            slideup(panelName);
            triggerImg.src = 'siteImages/expand.gif';
            triggerImg.alt = 'expand';
        }
    }
}

function validateActiveLightbox(alboxname)
{
    var albox = dId(alboxname);
    
    if(albox)
    {
        if(albox.options.length == 0)
            return false;
        else
            return true;
    }
}

function validateDeleteLightbox(alboxname)
{
    if(validateActiveLightbox(alboxname))
    {
        return confirm('Are you sure want to delete the active lightbox?');
    }
    else
    {
        alert('No active lightbox exists to delete.');
        return false;
    }
}

function validateClearLightbox(alboxname)
{
    if(validateActiveLightbox(alboxname))
    {
        return confirm('Are you sure want to clear all images from the active lightbox?');
    }
    else
    {
        alert('No active lightbox exists to clear.');
        return false;
    }
}

function validateRenameLightbox(alboxname)
{
    if(validateActiveLightbox(alboxname))
    {
        return true;
    }
    else
    {
        alert('No active lightbox exists to rename.');
        return false;
    }
}

function promptAgent(strImageid)
{
	if(confirm("THIS IS AN AGENT PICTURE. PLEASE NOTE: FOR EDITORIAL SALES ONLY. CONTRACT CLIENTS: ADDITIONAL FEES MAY APPLY - PLEASE CONTACT YOUR ACCOUNT MANAGER. DO YOU WANT TO DOWNLOAD THE PICTURE?"))
	{
		if(strImageid=='')
			return true;
		else
			return showDownloadPage(strImageid);
	}
	else
		return false;
}
		
function showDownloadPage(strImageid)
{
		var newwin;
		var leftVal = (450 - screen.width) / 2;
		var topVal = (200 - screen.height) / 2;
		
		newwin = window.open("downloadpage.aspx?id=" + strImageid,"ImgDownload","width=450,height=200,resizable=yes,scrollbars=yes,left="+leftVal+",top="+topVal);
		
		return false;
}


function onDateFilterChange(obj_DS)
{
	var DSItems = obj_DS.options;
	var selectedtext = DSItems[DSItems.selectedIndex].value;
	var myform = document.forms.fSearch
	
	switch(selectedtext)
	{
		case '6':
						showObject("searchDateRange",obj_DS)
						hideObject("searchDateBefore",obj_DS)
						hideObject("searchDateAfter",obj_DS)
						break;
		case '4':
						showObject("searchDateBefore",obj_DS)
						hideObject("searchDateRange",obj_DS)
						hideObject("searchDateAfter",obj_DS)
						break;
		case '5':
						showObject("searchDateAfter",obj_DS)
						hideObject("searchDateBefore",obj_DS)
						hideObject("searchDateRange",obj_DS)
						break;
		default:
						hideObject("searchDateAfter",obj_DS)
						hideObject("searchDateBefore",obj_DS)
						hideObject("searchDateRange",obj_DS)
						break;
	}
}

function refreshDateFilterChange(objDateFilter)
{
    onDateFilterChange(dId(objDateFilter));
}

function showObject(obj, cue) 
{
    if (document.getElementById || document.all) 
    {
		var oStyle = (document.all)?document.all[obj].style:document.getElementById(obj).style;
		oStyle.display = 'block';
		//oStyle.visibility = 'visible';
	} 
	else 
	{
		var sw = document.layers[obj].visibility;
		document.layers[obj].visibility = 'visible';
	}
} 

function hideObject(obj, cue) 
{
    if (document.getElementById || document.all) 
    {
		var oStyle = (document.all)?document.all[obj].style:document.getElementById(obj).style;
		oStyle.display = 'none';
		//oStyle.visibility = 'hidden';
	}
	else 
	{
		var sw = document.layers[obj].visibility;
		document.layers[obj].visibility = 'hidden';
	}
} 

		<!-- Begin
	function emailCheck (emailStr) {
	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */
	var emailPat=/^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of
	non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


	/* Finally, let's start trying to figure out if the supplied address is
	valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
	/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */
		//alert("Email address seems incorrect (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid 
	if (user.match(userPat)==null) {
		// user is not valid
		//alert("The username doesn't seem to be valid.")
		return false
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				//alert("Destination IP address is invalid!")
			return false
			}
		}
		return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		//alert("The domain name doesn't seem to be valid.")
		return false
	}

	/* domain name seems valid, but now make sure that it ends in a
	three-letter word (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	/* Now we need to break up the domain to get a count of how many atoms
	it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) {
	// the address must end in a two letter or three letter word.
	//alert("The address must end in a three-letter domain, or two letter country.")
	return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
	var errStr="This address is missing a hostname!"
	//alert(errStr)
	return false
	}

	// If we've gotten this far, everything's valid!
	return true;
	}
	//  End -->