function openCartViewWindow(url){
	newwindow=window.open(url,'Popup','scrollbars=yes,width=600,height=650,top=84,left=217');
	if (window.focus) {newwindow.focus()}
	return false;
}


/// handle the mouse on and off the rating camerats
function HighlightRatingCameras(Rate){

	TotalCameras = 5;

	/// dim all cameras
	for ( i=1; i <= TotalCameras; i++){
		RatingImage = eval('document.rating' + i);
		RatingImage.src='images/camera_0.gif';
	}

	if ( Rate <= 0 ){
		return;
	}

	/// highlight cameras
	for ( i=1; i <= Rate; i++ ){
		RatingImage = eval('document.rating' + i);
		RatingImage.src='images/camera_1.gif';
	}
}


/// handle the search keywords on the file close up pop up
function GetSearchText(){

	searchText = "";

    // disambiguation maps array
    dmMaps = [];

    // disambiguation language
    dmLang = SearchParamsDefault.textDisambiguation['language'];

	doSearch = false;

    // concatenate selected keywords (does not include color) into a url parameter
	selectedKeyword = document.searchKeywordForm.selectedKeyword;

	disambiguationFields = new Array();
	for (i=0; i<selectedKeyword.length; ++i){
		if (selectedKeyword[i].checked){
			tagField = $(selectedKeyword[i].value);
			doSearch = true;
			value = new String(tagField.value);
			if ( value.indexOf('+') > -1 ){
				searchText += '"' + value.gsub('+', ' ') + '" AND ';
			} else {

				searchText += value + ' AND ';
			}

            map = {
                "tag": value,
                "choices": [selectedKeyword[i].value],
                "language" : dmLang
            };
            dmMaps.push(map);
		}
	}

    if (searchText) {
        searchText = searchText.replace(/(.*) AND $/i,"$1");
        SearchParams.text = searchText;

        // recreate the text disambiguation object, and set the map array
        textDM = Object.clone(SearchParamsDefault.textDisambiguation);
        textDM.maps = dmMaps;
        SearchParams.textDisambiguation = textDM;
    }


    // take care of colorField
    if ($("kwColorField")) {
        doSearch = true;
        SearchParams.color = $F("kwColorField");
    }

	////////////////////////////////////////////////////////////////////////////////
	// add the copyspace args to the url - if they exist
	if ($('kwCopySpaceCBox')) {
		copySpaceCheckbox = document.searchKeywordForm.copySpace;
		if ( copySpaceCheckbox.checked ){
			doSearch = true;
            SearchParams.copySpace = escape(copySpaceCheckbox.value);
		}
	}
    ////////////////////////////////////////////////////////////////////////////////
    // For Audio - add the keyfield and timesignature values if
    // they are checked
    if ($('kwTimeSignature')) {
        if ( $('kwTimeSignature').checked ){
            doSearch = true;
            SearchParams.timeSignature1 = escape($F('kwTimeSignature1'));
            SearchParams.timeSignature2 = escape($F('kwTimeSignature2'));
        }
    }
    if ($('kwKeyfld')) {
        if ( $('kwKeyfld').checked ){
            doSearch = true;
            SearchParams.audioKey = escape($F('kwKeyfld'));
        }
    }
    if ($('Genre')) {
        if ( $('Genre').checked ){
            doSearch = true;
            mt = Object.clone(SearchParamsDefault.majorterms);
            mt.csv = escape($F('Genre'));
            SearchParams.majorterms = mt;
        }
    }
    if ($('Tempo')) {
        if ( $('Tempo').checked ){
            doSearch = true;
            SearchParams.tempo = escape($F('Tempo'));
        }
    }

    if ( doSearch ){
        LegacySearch();
    }
}

function LegacySearch() {
        var query = new Hash(),
            actionUrl = '',
            form;

        if (!Object.isUndefined(SearchParams.text)) {
            query.set('text', encodeURIComponent(SearchParams.text.replace(/^\s+|\s+$/g,"").replace(/\s+/g, '_')));
        }

        query.set('source', 'keywords');

        if (query.toQueryString() !== '') {
            actionUrl = istock.url + 'search/';

            query.each(function(pair) {
                actionUrl += pair.key + '/' + pair.value + '/';
            });

            form = new Element('form', {method: 'get', action: actionUrl});

            $$('body').first().insert(form);

            form.submit();
        }

        return false;
}

/// handle the removal of keywords
function RemoveKeywords(fileID) {

	keywordList = "";
	doRemove = false;

	////////////////////////////////////////////////////////////////////////////////
	// concatenate selected keywords into a comma delimited list
	selectedKeyword = document.searchKeywordForm.selectedKeyword;
	size = selectedKeyword.length - 1; // dont allow the colorProfile checkbox to be included
	for (i=0; i < size; ++i) {
		if (selectedKeyword[i].checked) {
			doRemove = true;
			keywordList += decodeURIComponent(selectedKeyword[i].value) + ',';
		}
	}

	// trim trailing comma
	keywordList = keywordList.replace(/\,*$/, '');

	if ( doRemove ) {
		answer = confirm('You have suggested to remove the selected keywords. Is this correct?');
		if (answer) {
			// lets go to the page
			window.location="/keyword_wiki.php?id=" + fileID + "&toRemove=" + escape(keywordList);
		}
		else {
			return; //exit
		}
	}
	else {
		alert('Please choose keywords for removal.');
	}
}

/// handle the edit of keywords
function EditKeywords(fileID) {

	keywordList = "";
	doEdit = false;

	////////////////////////////////////////////////////////////////////////////////
	// concatenate selected keywords into a comma delimited list
	selectedKeyword = document.searchKeywordForm.selectedKeyword;
	size = selectedKeyword.length - 1; // dont allow the colorProfile checkbox to be included
	for (i=0; i < size; ++i) {
		if (selectedKeyword[i].checked) {
			doEdit = true;
			keywordList += selectedKeyword[i].value + ',';
		}
	}

	// trim trailing comma
	keywordList = keywordList.replace(/\,*$/, '');

	// lets go to the page
	if (doEdit) { editParam = "&toEdit=" + escape(keywordList); } else { editParam = ""; }
	window.location="/keyword_wiki.php?id=" + fileID + editParam;
}

function ShowHiddenKeywords(){
	document.getElementById('moreKeywords').style.display = 'block';
}



// script to switch between the different tabs on the page // the prints tab will popup the print dialog
var tabSwitcher = Class.create();
tabSwitcher.prototype = {
	initialize: function(){
		if ($("downloadTab")) $("downloadTab").onclick=function() { this.setOnClick("downloadTab"); }.bind(this);
	},

	setOnClick: function(tab) {
		switch (tab) {
			case 'downloadTab':
				lyrs = new Array('downloadTabContent', 'imageContainer', 'printsTabContent', 'croppingContainer', 'downloadTab', 'printsTab');
				if ($('ZoomControlDiv')) {
					if(zoomFile.size!=6) {
						$('ZoomControlDiv').show();
					}
				}
				this.setPrintsTabCookie(0);
			break;
			case 'printsTab':
				lyrs = new Array('printsTabContent', 'croppingContainer', 'downloadTabContent', 'imageContainer', 'printsTab', 'downloadTab');
				if ($('ZoomControlDiv')) $('ZoomControlDiv').hide();
				this.setPrintsTabCookie(1);
			break;
		}
		$(lyrs[0], lyrs[1]).invoke('show');
		$(lyrs[2], lyrs[3]).invoke('hide');
		$(lyrs[4]).className="tabContainer";
		$(lyrs[5]).className="tabContainerOff";
	},

	setPrintsTabCookie: function(isActive) {
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+30);
		document.cookie='FileCloseupPrintsTab='+isActive+';expires='+exdate.toGMTString()+';domain=.istockphoto.com;path=/';
	}
}


// bit to launch the waveform inline popup
function loadWaveform(fileID) {

	var url = "ajax_class_creator.php";
	var params = "ajax_action=Show&ajax_class=waveform&FileID="+fileID;
	var myAjax = new Ajax.Request (
		url,
		{
			asynchronous: true,
			method: "get",
			parameters: params,
			onComplete: function(xhrReq) {
				var json = xhrReq.responseText.evalJSON();
				ajaxWin.show(json);
			},
			onFailure: function() {
				alert('There has been an XHR error, please try your request again.');
			}
		}
	);
}


/* some event listeners that we will need on the page */


