/* Script for Partner Teaser $Revision: 1.10 $ */

dojo.declare("mam.odb.partnerTeaserControl", mam.app.ChainedSelects, {

	_teaserForm: null,
	_ptUrl: null,
	_psUrl: null,
	_webRep:null,
	_partnerMap:null,	
	constructor: function(params) {
		//this.inherited(arguments, params);
		this._teaserForm = dojo.byId(params.teaserFormId);
		this._ptUrl = params.partnerTeaserUrl;
		this._psUrl = params.partnerSearchUrl;
		this._webRep = params.webRep;
		this._partnerMap = params.partnerMap;
	},
	submitForm: function() {
		var _partnerFilter = this._targetField;											
		if(_partnerFilter.options[0].selected == false){
			var trackStr ="";
			if (this._webRep) {
				trackStr+="\"" + this._webRep.catKey + "\" , \"" + this._inputField.options[this._inputField.selectedIndex].value + "\"";
				trackStr+=", \"" + this._webRep.parterKey + "\" , \"" + this._partnerMap[this._targetField.options[this._targetField.selectedIndex].value] + "\"";
				for (var key in this._webRep.optParams)  {
					trackStr+=", \"" + key + "\" , \"" + this._webRep.optParams[key] + "\"";
				}
			}
			eval("mam.webRep.multiTrack(" + trackStr + ")");
			this._teaserForm.action = this._ptUrl;
			this.addParams();
	    	this._teaserForm.submit();
		}	else {
			this._teaserForm.action = this._psUrl;
			this.addParams();
			this._teaserForm.submit();
		}	
	},
	
	addParams: function() {
		var searchString = this._teaserForm.action;
		searchString = searchString.substring(this._teaserForm.action.indexOf("?") + 1, this._teaserForm.action.length);
		var nvPairs = searchString.split("&");
		for (i = 0; i < nvPairs.length; i++)
		{
		     var nvPair = nvPairs[i].split("=");
			 var el = document.createElement("input");
			 el.type = "hidden";
			 el.name = nvPair[0];
			 el.value = nvPair[1];
			 this._teaserForm.appendChild(el);
		}
	}
});