/* hh only script */

if (document.layers) {
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS4;
} else if (document.all&&!document.getElementById) {
	document.onmousedown=clickIE4;
}

// power search modal form


var oSearchModal;

function searchModal() {
	this.tf=null;
	this.init();
}

searchModal.prototype.init = function() {
	this.tf=parent.resultspanel;
}

searchModal.prototype.show = function() {
	if(!this.tf) return false;
	this.tf.infradoxApp.removeElementFromDoc('divSearchModal');
	this.tf.infradoxModal.createModalBoxForContent(450,300);
	this.tf.infradoxModal.loadModalBoxContentURL('go?a=disp&t=site\\searchmodal_ajax.inc', onsearchModalShow);
}

searchModal.prototype.getForm = function() {
	if(this.tf) {
		return this.tf.document.formSearchModal;
	} else return null;
}

searchModal.prototype.onshow = function() {
	var form=this.getForm();
	if(!form) return false;

	var fset = this.tf.infradoxFilters._filters.settings;
	var filters = {settings:[
		{name:"orientation",label:"Orientation",filter:"_sf0",value:fset[0].value,options:["OH","OV","OS","OP"],optionnames:["Horizontal","Vertical","Square","Panoramic"],type:"checkbox",all:""},
		{name:"rights",label:"Rights",filter:"_sf1",value:fset[1].value,options:["@RM","@RF","@MR"],optionnames:["Rights managed","Royalty free","Model released"],type:"checkbox","all":""},
		{name:"collections",label:"Collections",filter:"_sf2",value:fset[2].value,options:["J","P","L","C","S","X","F","Y","M"],optionnames:["Journalism","Personalities","Lifestyle","Commercial","Sports","Classics","Fashion","Entertainment","No entertainment"],type:"checkbox","all":""},
		{name:"news",label:"news",filter:"_sf3",value:fset[3].value,options:["NNL","NBL"],optionnames:["Nederland","buitenland"],type:"checkbox","all":""}
		],invertedcheckboxes:0};

	this.tf.infradoxFilters.initialize(filters, form);

	infradoxEnterKeyHandler.relay(form.key1, 'key1', function(){onsearchModalSearch()}); 
	infradoxEnterKeyHandler.relay(form.key2, 'key2', function(){onsearchModalSearch()}); 
	form.key1.focus();
}

searchModal.prototype.search = function() {
	var o, form, oSearch;

	form=this.getForm();
	if(!form) return false;

	oSearch = parent.toppanel.oSearch;
	if(!oSearch) {alert('no search object!'); return false;}

	oSearch.settings.operators = [CONST_BOOLEANAND];
	oSearch.settings.auxparameters=this.tf.infradoxSearchTools.getToolboxParameters();

	var fobj;
	if(parent) {
		fobj=parent.resultspanel.infradoxFilters;
	} else {
		fobj=infradoxFilters;
	}
	fobj.applyFiltersFromControls();
	oSearch.powerSearch(form, fobj.filtersAsString(), (this.tf.infradoxApp.pagetype!=1));
}
// end power search modal form



// disable right-click on ff
//document.oncontextmenu=new Function("return false")


// 0=nieuws,1=reportage,2=dossier,3=portret,4=lifestyle,5=entertainment,6=creative,7=reizen,8=historisch,9=24 uur,10=sport,11=portfolios,12=natuur 
// Sanoma - 3116,3117,3118,3119,3120,3121,3122,3123,3124,3257
// >>>>> CHANGE SP_HH_GETHHITEMS <<<<< 
var hhtopids = [1056,1057,1058,1059,1060,1062,1089,1061,1090,1065,1309,1610,2862,0,0,0,0,0,0,3116,3117,3118,3119,3120,3121,3122,3123,3124,3257]; 

function HHinitLeftmenu(id) {
	this.hhid='submenu_2_'+id;
	this.id=id;

	var e=infradoxApp.getElement('hhmenu'),li,n;
	var hid;
	
	for(var i=0; i<e.childNodes.length; i++) {
		if(e.childNodes[i].nodeName=='LI') {
			li = e.childNodes[i];
			hid=li.id.split('_');

			if(hid[1]==id) li.style.backgroundPosition="-113px 0px";

			li.onmouseover=function() {
				this.style.backgroundPosition="-113px 0px";
			}

			li.onmouseout=function() {
				if(this.id!="hh_"+id) this.style.backgroundPosition="0px 0px";
			}

			li.onclick=function() {parent.toppanel.menuHandler(this.id);};
		}
	}
}

function initialiseTools(defaultSearchboxLabel,user) {
	if(!document.powersearchForm) return;
	var s='',o=document.powersearchForm.key1;
	if(o) {
		s=infradoxApp.allTrim(o.value);
		var xs=infradoxApp.getElement('_execsrch');
		if(xs) {
			if(xs.value.charAt(0)=='^') s='';
		}
		if(s=='') o.value=defaultSearchboxLabel;
	}
	if(!user) {
		if(document.formLeftLogin) {
			var o=document.formLeftLogin.loginName;
			if(o) {
				if(infradoxApp.allTrim(o.value)=='') o.value=document.formLeftLogin.loginlabel.value;
			}
		}
	}
}

function updquicksearch(f,displayName) {
	if(!document.powersearchForm) return;
	var o=document.powersearchForm.key1;
	if(!o) return;
	if(f) {
		if(o.value==displayName) o.value='';
	} else {
		if(o.value=='') o.value=displayName;
	}
}

function updpassword(f,label) {
	if(!document.formLeftLogin) return;
	var o=document.formLeftLogin.loginPassword;
	if(!o) return;
	if(f) {
		o.type="password";
		o.value='';
	}
}

function hh_showThumbnailIndicators(content, orderMedia) { 
	var e, is, cls, eln, detail, restr, data = orderMedia?content.details:content.media;
	var gete=infradoxApp.getElement;
	if(!data) return;

	for(var i=0; i<data.length; i++) {
		detail = data[i];

		is=((orderMedia)?detail.ref:(i+1).toString());

		if(detail.ed) {
			eln='ed_'+is;
			cls='1';
		} else {
			eln='co_'+is;
			cls='2';
		}
		e=gete(eln);
		if(e) e.className='current'+cls;

		if(!detail.hr) {
	 		e=gete('lo_'+is);
			if(e) e.className='current3';
		}

		if(detail.aux) {
	 		e=gete('rs_'+is);
			if(e) e.className='current4';
		}
	}
}

var hhStatus = {
	editorial:["editorial","redactioneel"],
	commercial:["commercial","commercieel"],
	mr:["model release on file","model release aanwezig"],
	nomr:["no model release on file","geen model release aanwezig"],
	rm:["rights managed","rights managed"],
	rf:["royalty free","royalty free"],
	tr:["territorial restrictions","landen restricties"],
	lowres:["only low resolution","alleen lage resolutie"],
	ru:["restricted use","restricties tav het gebruik"],
	bi:["no immediate download","onmiddelijke download niet mogelijk"]
};

var hhLicenseInfo = {
	worldwide:["worldwide rights","wereldwijde rechten"],
	bnl:["Benelux only","alleen Benelux"],
	nl:["Netherlands only","alleen Nederland"]};

function hh_getLicenseInfo(locale, world, benelux, otherinfo) {
	locale--;
	var aRes=[];
	if(world) {
		aRes.push(hhLicenseInfo.worldwide[locale]);
	} else {
		aRes.push(((benelux)?hhLicenseInfo.bnl[locale]:hhLicenseInfo.nl[locale]));
	};
	if(otherinfo) aRes.push('<br />'+otherinfo);
	return aRes;
}

function hh_getStatusText(media, locale, licinfo) { 
	locale--;
	var aRes=[];
	if(media.ed) {
		aRes.push(hhStatus.editorial[locale]);
		if(media.mr) {aRes.push(hhStatus.mr[locale])} else {aRes.push(hhStatus.nomr[locale])};
	} else { 
		aRes.push(hhStatus.commercial[locale]);
	};

	if(media.rm) {aRes.push(hhStatus.rm[locale])} else {aRes.push(hhStatus.rf[locale]);};
	if(!media.hr) aRes.push(hhStatus.lowres[locale]);
	if(media.tr) aRes.push(hhStatus.tr[locale]);

//	if(media.br||media.nb||(media.contrestr.count>0)) aRes.push('<b class="red">'+hhStatus.ru[locale]+'</b>');
	if(licinfo||media.aux) aRes.push('<b class="red">'+hhStatus.ru[locale]+'</b>');

	if(media.bi||(!media.hr)||licinfo||media.aux) aRes.push('<b class="red">'+hhStatus.bi[locale]+'</b>');

	return aRes;
}

function clickIE4(){
	if (event.button==2) return false;
}

function clickNS4(e){
	if (document.layers||document.getElementById&&!document.all) {
		if (e.which==2||e.which==3) return false;
	}
}


/* lightbox pick list */
var hhLightboxes = {
	initialize: function(lbid) {
		infradoxApp.removeElementFromDoc('divmodalLightboxList');

		infradoxModal.createModalBoxForContent(320,350);
		infradoxModal.loadModalBoxContentURL('go?a=disp&t=lightbox-list.inc&current='+lbid, function() {
			var e=infradoxApp.getElement('lb_'+lbid);
			if(e) e.className='current';
			});
	},

	changelightbox: function(id) {
		if(id) {
			if(parent.bottompanel) parent.bottompanel.infradoxLightbox.lightboxLoad(id);
		}
	}
}

function toolsectionCallback(sectionname, showing, initializing) {
	switch(sectionname) {
	case 'recentsearches':
		if(showing) getRecentSearches();
		break;
	}
}

function getRecentSearches() {
	infradoxApp.putInnerHtml('_toolsection_recentsearches','...');

	var vrs=infradoxApp.completePostVars('a=disp&t=sr-body-fsrch-sp.inc'); 
	var url=infradoxApp.completeURL('ih');

	infradoxAjax.postRequest(url, vrs, function() {infradoxApp.putInnerHtml('_toolsection_recentsearches', infradoxAjax.xmlHttp.responseText, false);});
}

function repeatSearch(s) {
	var oSearch = parent.toppanel.oSearch;
	oSearch.settings.auxparameters=infradoxSearchTools.getToolboxParameters();
	infradoxFilters.applyFiltersFromControls();
	oSearch.settings.filterstring=infradoxFilters.filtersAsString();
	oSearch.settings.repeatsearch=1;
	oSearch.settings.words=[s];
	oSearch.search(false);
}


