if(typeof defaultWidgetLanguage != 'undefined') {
	dojo.require("dojo.io.script");
	dojo.require("dijit.form.Form");
	dojo.require("dojo.io.iframe");
}


dojo.provide("com.voicearchive.orderForm");

dojo.declare("com.voicearchive.orderForm", null, {
    constructor: function(args) {
	this.currentOrderId = 0;
	this.currentJobId = 0;
	this.currentVersionId = 0;
	this.currentTaskId = 0;
	this.currentEndCustomer = '';
	this.currentProductName = '';
	this.possibleLangauges = [{"uid":"4","name":"Arabic"},{"uid":"61","name":"Bahasa-Malaysia"},{"uid":"532","name":"Bosnian"},{"uid":"6","name":"Bulgarian"},{"uid":"62","name":"Chinese-Cantonese"},{"uid":"8","name":"Chinese-Mandarin"},{"uid":"10","name":"Croatian"},{"uid":"12","name":"Czech"},{"uid":"14","name":"Danish"},{"uid":"15","name":"Dutch"},{"uid":"240","name":"English (Australian)"},{"uid":"16","name":"English (Indian)"},{"uid":"308","name":"English (Mid-Atlantic\/Neutral)"},{"uid":"17","name":"English (UK)"},{"uid":"18","name":"English (US)"},{"uid":"19","name":"Estonian"},{"uid":"20","name":"Finnish"},{"uid":"63","name":"Flemish"},{"uid":"22","name":"French"},{"uid":"21","name":"French Canadian"},{"uid":"23","name":"German"},{"uid":"24","name":"Greek"},{"uid":"26","name":"Hebrew"},{"uid":"25","name":"Hindi "},{"uid":"27","name":"Hungarian"},{"uid":"28","name":"Icelandic"},{"uid":"29","name":"Irish"},{"uid":"30","name":"Italian"},{"uid":"31","name":"Japanese"},{"uid":"32","name":"Korean"},{"uid":"33","name":"Latvian"},{"uid":"34","name":"Lithuanian"},{"uid":"117","name":"Macedonian"},{"uid":"36","name":"Norwegian"},{"uid":"37","name":"Polish"},{"uid":"39","name":"Portuguese"},{"uid":"38","name":"Portuguese-Brazilian"},{"uid":"41","name":"Romanian"},{"uid":"42","name":"Russian"},{"uid":"45","name":"Slovakian"},{"uid":"46","name":"Spanish"},{"uid":"47","name":"Spanish-Latin"},{"uid":"48","name":"Spanish-Mexican"},{"uid":"49","name":"Swedish"},{"uid":"54","name":"Turkish"},{"uid":"55","name":"Ukrainian"},{"uid":"56","name":"Urdu"}];
	dojo.mixin(this, args);
    },
    createOrder: function(title) {
	var defaultParams = {
	    apiMethod: 'create',
	    apikey: '',
	    title: title
	};
	dojo.mixin(defaultParams, {apikey: this.apiKey});
	dojo.io.script.get({
	    callbackParamName: 'callback',
	    preventCache: true,
	    url: 'http://system.voicearchive.com/services/Customer/Order/jsonp',
	    content: defaultParams,
	    load: dojo.hitch(this, 'orderCreated'),
	    error: function(err) {
		if (err.dojoType == 'timeout') {
		    console.log(err.toString());
		    return;
                }
	        if (err.dojoType == 'cancel') {
		    return;
                }
	        console.log(err.toString());
        	return;
	    }
	});
    },
    orderCreated: function(response) {
	this.orderId = response.data;

	this.orderCreationSubmitButton.disabled = true;
	this.titleTextBox.disabled = true;

	this.addManuscriptArea();
    },
    createJob: function(orderId, customerReference) {
	var defaultParams = {
	    apiMethod: 'createJob',
	    apikey: '',
	    orderId: orderId,
	    customerReference: customerReference
	};
	dojo.mixin(defaultParams, {apikey: this.apiKey});
	dojo.io.script.get({
	    callbackParamName: 'callback',
	    preventCache: true,
	    url: 'http://system.voicearchive.com/services/Customer/Order/jsonp',
	    content: defaultParams,
	    load: dojo.hitch(this, 'jobCreated'),
	    error: function(err) {
		if (err.dojoType == 'timeout') {
		    console.log(err.toString());
		    return;
                }
	        if (err.dojoType == 'cancel') {
		    return;
                }
	        console.log(err.toString());
        	return;
	    }
	});
    },
    jobCreated: function(response) {
	var jobId = response.data;
	var nextJobArea = this.createDiv('jobArea-'+jobId);
	var jobAreaContent = this.createDiv('jobAreaContent-'+jobId);

	this.addUploadForm(jobAreaContent, jobId);
	

	var header = dojo.create('h2', {className: 'versionHeader', innerHTML: 'Versions'});
	var versionArea = this.createVersionArea(jobId);
	dojo.place(header, nextJobArea);
	dojo.place(jobAreaContent, nextJobArea);
	dojo.place(versionArea, nextJobArea);
	dojo.place(nextJobArea, this.manusArea);
	
    },
    uploadJobFile: function(formNode) {
	dojo.io.iframe.send({
        url: "http://system.voicearchive.com/api/uploadFile",
        method: "post",
        handleAs: "json",
        form: formNode,
        handle: dojo.hitch(this, 'jobFileUploaded')
    });
    },
    jobFileUploaded: function(response) {
	
    },
    createVersion: function(jobId, languageId, customerReference) {
	var defaultParams = {
	    apiMethod: 'createVersion',
	    apikey: '',
	    jobId: jobId,
	    languageId: languageId, 
	    customerReference: customerReference
	};
	dojo.mixin(defaultParams, {apikey: this.apiKey});
	dojo.io.script.get({
	    callbackParamName: 'callback',
	    preventCache: true,
	    url: 'http://system.voicearchive.com/services/Customer/Order/jsonp',
	    content: defaultParams,
	    load: dojo.hitch(this, 'versionCreated'),
	    error: function(err) {
		if (err.dojoType == 'timeout') {
		    console.log(err.toString());
		    return;
                }
	        if (err.dojoType == 'cancel') {
		    return;
                }
	        console.log(err.toString());
        	return;
	    }
	});
    },
    versionCreated: function(response) {
	var jobId = response.data.parenttask;
	var versionId = response.data.uid;
	var languageId = response.data.targetlanguage;
	dojo.query('.jobArea-'+jobId+' .versionContainer').forEach(function(item) {
	    this.addTranslation(item, versionId, languageId);
	}, this);
    },
    setVersionLanguage: function(versionId, languageId) {
	var defaultParams = {
	    apiMethod: 'setVersionLanguage',
	    apikey: '',
	    versionId: versionId,
	    languageId: languageId
	};
	dojo.mixin(defaultParams, {apikey: this.apiKey});
	dojo.io.script.get({
	    callbackParamName: 'callback',
	    preventCache: true,
	    url: 'http://system.voicearchive.com/services/Customer/Order/jsonp',
	    content: defaultParams,
	    load: dojo.hitch(this, 'versionLanguageSet'),
	    error: function(err) {
		if (err.dojoType == 'timeout') {
		    console.log(err.toString());
		    return;
                }
	        if (err.dojoType == 'cancel') {
		    return;
                }
	        console.log(err.toString());
        	return;
	    }
	});
    },
    versionLanguageSet: function(response) {
	
    }, 
    createTask: function(versionId, typeId, deadline, customerReference, endCustomer, productName) {
	var defaultParams = {
	    apiMethod: 'createJob',
	    apikey: '',
	    versionId: versionId,
	    typeId: typeId,
	    deadline: deadline,
	    customerReference: customerReference,
	    endCustomer: endCustomer,
	    productName: productName
	};
	dojo.mixin(defaultParams, {apikey: this.apiKey});
	dojo.io.script.get({
	    callbackParamName: 'callback',
	    preventCache: true,
	    url: 'http://system.voicearchive.com/services/Customer/Order/jsonp',
	    content: defaultParams,
	    load: dojo.hitch(this, 'taskCreated'),
	    error: function(err) {
		if (err.dojoType == 'timeout') {
		    console.log(err.toString());
		    return;
                }
	        if (err.dojoType == 'cancel') {
		    return;
                }
	        console.log(err.toString());
        	return;
	    }
	});
    },
    taskCreated: function(response) {
	
    },
    setTaskSupplier: function(taskId, supplierId) {
	var defaultParams = {
	    apiMethod: 'setTaskSupplier',
	    apikey: '',
	    taskId: taskId,
	    supplierId: supplierId
	};
	dojo.mixin(defaultParams, {apikey: this.apiKey});
	dojo.io.script.get({
	    callbackParamName: 'callback',
	    preventCache: true,
	    url: 'http://system.voicearchive.com/services/Customer/Order/jsonp',
	    content: defaultParams,
	    load: dojo.hitch(this, 'taskSupplierSelected'),
	    error: function(err) {
		if (err.dojoType == 'timeout') {
		    console.log(err.toString());
		    return;
                }
	        if (err.dojoType == 'cancel') {
		    return;
                }
	        console.log(err.toString());
        	return;
	    }
	});
    },
    taskSupplierSelected: function(repsonse) {

    },

    createMainOrderForm: function() {
	if(typeof this.apiKey == 'undefined' || this.apiKey == '') {
	    return false;
	}

	this.container = this.createDiv('mainFormDiv');
	var header = this.createDiv('mainFormHeader');
	var heading = dojo.create('h1', {innerHTML: 'Place Order'});
	dojo.place(heading, header);
	dojo.place(header, this.container);
	
	var orderTitleForm = this.createOrderTitleForm();
	dojo.place(orderTitleForm, this.container);
	dojo.empty(this.parentNode);
	dojo.place(this.container, this.parentNode);
	return this.container;
    },
    createOrderTitleForm: function() {
	var container = this.createDiv('orderTitleForm');
	var span = this.createSpan('orderTitleRow');
	var rowTitle = dojo.create('strong', {innerHTML: 'Order Title: '});
	
	this.titleTextBox = dojo.create('input', {type: 'text'});
	this.orderCreationSubmitButton = dojo.create('button', {innerHTML: 'Create'});
	dojo.connect(this.orderCreationSubmitButton, 'onclick', this, 'orderCreationSubmitButtonClicked');
	dojo.place(rowTitle, span);
	dojo.place(this.titleTextBox, span);
	dojo.place(this.orderCreationSubmitButton, span);
	dojo.place(span, container);
	return container;
    },
    orderCreationSubmitButtonClicked: function() {
	this.createOrder(this.titleTextBox.value);
    },
    addManuscriptArea: function() {
	this.manusArea = this.createDiv('orderManusArea');
	this.createManusButton = dojo.create('button', {innerHTML: 'Add Script'});
	dojo.connect(this.createManusButton, 'onclick', this, 'addManuscript');
	dojo.place(this.manusArea, this.container);
	dojo.place(this.createManusButton, this.container);
    },
    createVersionArea: function(jobId) {
	var container = this.createDiv('versionContainer');
	var createVersionButton = dojo.create('button', {className: 'versionFor-'+jobId, innerHTML: 'Add Language'});
	dojo.connect(createVersionButton, 'onclick', this, 'addVersionUI');
	dojo.place(createVersionButton, container);
	return container;
    },
    addVersionUI: function(e) {
	jobId = e.target.className;
	jobId = jobId.replace('versionFor-','');
	this.createVersion(jobId, 0, '');
    }, 
    addManuscript: function() {
	this.createJob(this.orderId, '');
    },

    addUploadForm: function(placeInTo, jobId) {
	var container = this.createDiv('uploadFormContainer');
	var uploadForm = new dijit.form.Form({encType: 'multipart/form-data'});

	var fileNode = dojo.create('input', {name: 'apiFileField'+jobId, type: 'file'});
	var taskIdNode = dojo.create('input', {name: 'taskId', type:'hidden', value: ''+jobId});
	var fieldnameNode = dojo.create('input', {name: 'fieldname', type:'hidden', value: 'apiFileField'+jobId});
	var apiKeyNode = dojo.create('input', {name: 'apikey', type:'hidden', value: this.apiKey});
	
	dojo.connect(fileNode, "onchange", this, 'uploadFormChanged');
	
	dojo.place(fileNode, uploadForm.domNode);
	dojo.place(taskIdNode, uploadForm.domNode);
	dojo.place(fieldnameNode, uploadForm.domNode);
	dojo.place(apiKeyNode, uploadForm.domNode);
	dojo.place(uploadForm.domNode, container);
	dojo.place(container, placeInTo);


    },
    uploadFormChanged: function(e) {
	this.uploadJobFile(e.target.parentNode);
    },

    addTranslation: function(placeInTo, versionId, languageId) {
	console.log('Creating container');
	var container = this.createDiv('translationContainer');
	console.log('Creating select');
	var select = this.createSelect();
	dojo.addClass(select, 'version-'+versionId+'-language');
	dojo.connect(select, 'onchange', this, 'versionLanguageChanged');

	console.log('Placing select in container');
	dojo.place(select, container);

	//dojo.place(supplierDiv, container);
	console.log('Placing container in targetNode');
	dojo.place(container, placeInTo);

	//var supplierDiv = this.createSupplierDiv(400);
	console.log('Creating demowidget');
	var demoWidget = this.createLanguageSelectWidget(select, languageId, true);

	
	return demoWidget;
    },
    versionLanguageChanged: function(e) {
	var versionId = e.target.className;
	
	versionId = versionId.replace('version-','');
	
	versionId = versionId.replace('-language','');
	
	var languageId = e.target.options[e.target.selectedIndex].value;
	this.setVersionLanguage(versionId, languageId);
    },
    createSpan: function(className) {
	var span = dojo.create('span');
	if(typeof className !=='undefined') {
	    dojo.addClass(span, className);
	}
	return span;
    },
    createDiv: function(className) {
	var span = dojo.create('div');
	if(typeof className !=='undefined') {
	    dojo.addClass(span, className);
	}
	return span;
    },
    createSelect: function () {
	var selectBox = dojo.create('select');
	return selectBox;
    },
    createSupplierDiv: function(width) {
	var demoDiv = this.createDiv('demoList');
	dojo.attr(demoDiv, {style: {width: width+'px'}});
	return demoDiv;
    }, 
    createNewDemoWidget: function(languageListNode, supplierListNode, defaultLanguage, initialize) {
	var demoList = new com.voicearchive.demoList({supplierListNode: supplierListNode, languageListNode: languageListNode, languageId: defaultLanguage, apikey: this.apiKey});
	if(typeof initialize!= 'undefined' && initialize !== false) {
	    demoList.initializeDemoList();
	    demoList.getAllSuppliers();
	    demoList.getAllLanguages();
	}
	return demoList;
    },
    createLanguageSelectWidget: function(languageListNode, defaultLanguage, initialize) {
	dojo.forEach(this.possibleLangauges, function(item) {
	    var currentOption = dojo.create('option', {value: item.uid, innerHTML: item.name});
	    if(item.uid==defaultLanguage) {
		dojo.attr(currentOption, {selected: true});
	    }
	    dojo.place(currentOption, languageListNode);
	}, this);
    }
});

dojo.provide("com.voicearchive.demoList");
dojo.declare("com.voicearchive.demoList", null, {
    constructor: function(args) {
	defaultArgs = {
	    supplierListNode: null,
	    languageListNode: null,
	    languageId: 0,
	    typeId: 2,
	    categoryId: 0,
	    priorityId: 0,
	    searchPhrase: "",
	    gender: 0,
	    apikey: "",
	    allowLanguageChange: true,
	    allowTypeChange: true,
	    allowCategoryChange: true,
	    allowPriorityChange: true,
	    allowSearchPhraseChange: true,
	    allowGenderChange: true,
	    allowApiKeyChange: true
	};
	args = dojo.mixin(defaultArgs, args);
	this.supplierListNode = args.supplierListNode;
	this.languageListNode = args.languageListNode;
	this.currentLanguageId = args.languageId;
	this.currentTypeId = args.typeId;
	this.currentCategoryId = args.categoryId;
	this.currentPriorityId = args.priorityId;
	this.currentSearchPhrase = args.searchPhrase;
	this.currentGender = args.gender;
	this.currentApiKey = args.apikey;

	this.allowLanguageChange = args.allowLanguageChange;
	this.allowTypeChange = args.allowTypeChange;
	this.allowCategoryChange = args.allowCategoryChange;
	this.allowPriorityChange = args.allowPriorityChange;
	this.allowSearchPhraseChange = args.allowSearchPhraseChange;
	this.allowGenderChange = args.allowGenderChange;
	this.allowApiKeyChange = args.allowApiKeyChange;
    },
    getAllLanguages: function() {
	if(typeof this.languageListNode == 'undefined') {
	    return;
	}
	dojo.connect(this.languageListNode, 'onchange', this, 'onLanguageNodeChange');
	var defaultParams = {
	    apiMethod: 'getLanguagesWithSuppliers',
	    apikey: ''
	};
	dojo.mixin(defaultParams, {apikey: this.currentApiKey});
	dojo.io.script.get({
	    callbackParamName: 'callback',
	    preventCache: true,
	    url: 'http://system.voicearchive.com/services/PublicServices/Suppliers/jsonp',
	    content: defaultParams,
	    load: dojo.hitch(this, 'buildLanguageDropDown'),
	    error: function(err) {
		if (err.dojoType == 'timeout') {
		    console.log(err.toString());
		    return;
                }
	        if (err.dojoType == 'cancel') {
		    return;
                }
	        console.log(err.toString());
        	return;
	    }
	});

    },

    getAllSuppliers: function(params) {
	if(typeof this.supplierListNode == 'undefined') {
	    return;
	}
	var defaultParams = {
	    apiMethod: 'find',
	    languageId: 0,
	    typeId: 2,
	    categoryId: 0,
	    ageId: 0,
	    priorityId: 0,
	    userId: '',
	    gender: 0,
	    includeDemos: 1,
	    apikey: ''
	};
	dojo.mixin(defaultParams, {languageId: this.currentLanguageId, typeId: this.currentTypeId, categoryId: this.currentCategoryId, priorityId: this.currentPriorityId, searchString: this.currentSearchPhrase, gender: this.currentGender, apikey: this.currentApiKey});
	dojo.mixin(defaultParams, params);

	dojo.io.script.get({
	    callbackParamName: 'callback',
	    preventCache: true,
	    url: 'http://system.voicearchive.com/services/PublicServices/Suppliers/jsonp',
	    content: defaultParams,
	    load: dojo.hitch(this, "buildSupplierList"),
	    error: function(err) {
		if (err.dojoType == 'timeout') {
		    console.log(err.toString());
		    return;
                }
	        if (err.dojoType == 'cancel') {
		    return;
                }
	        console.log(err.toString());
        	return;
	    }
	});
    },


    initializeDemoList : function () {
	if(typeof this.supplierListNode == 'undefined') {
	    return;
	}
	dojo.empty(this.supplierListNode);

    },
    onLanguageNodeChange: function () {
	languageId = this.languageListNode.options[this.languageListNode.selectedIndex].value;

	this.setCurrentLanguageId(languageId);
    },

    buildLanguageDropDown: function (jsonpData) {
	this.createLanguageDropDown(this.languageListNode, jsonpData.data);
    },

    buildSupplierList: function (jsonpData) {
	this.createSupplierList(this.supplierListNode, jsonpData.data);
    },

    createLanguageDropDown: function (inNode, rows) {
	dojo.empty(inNode);
	for(var i=0;i<rows.length;i++) {
	    dojo.place(this.createLanguageOption(rows[i]), inNode);
	}
    },

    createLanguageOption: function(row) {
	var optionHtml = dojo.create('option');
	dojo.attr(optionHtml, "value", ''+row.uid);
	if(this.currentLanguageId==row.uid) {
	    dojo.attr(optionHtml, "selected", 'selected');
	}
	optionHtml.innerHTML = ''+row.name;
	return optionHtml;
    },

    createSupplierList: function (inNode, supplierRows) {
	var _self = this;
	dojo.empty(inNode);
	dojo.forEach(supplierRows, function(item) {_self.createSupplierItem(item, inNode);});
    },

    createSupplierItem: function (supplierRow, inNode) {
	var titleRow = this.createSupplierTitleRow(supplierRow.userid, (supplierRow.recommended==1), '', '');
	var commercialDemo = this.createDemoOfTypeIfAny(supplierRow, 1);
	var commercialDemoRow = dojo.create('span');
	if(commercialDemo!==false) {
	    commercialDemoRow  = this.createSupplierDemoRow('supplierCommercialDemo', 'Commercial', 'http://system.arnsbomedia.com/download/supplier/demo/'+commercialDemo['uid'], commercialDemo['uid'], supplierRow.userid, supplierRow.uid);
	}
	var narrationDemoRow = dojo.create('span');
	var narrationDemo = this.createDemoOfTypeIfAny(supplierRow, 2);
	if(narrationDemo!==false) {
	    narrationDemoRow  = this.createSupplierDemoRow('supplierProfileDemo', 'Corporate', 'http://system.arnsbomedia.com/download/supplier/demo/'+narrationDemo['uid'], narrationDemo['uid'], supplierRow.userid, supplierRow.uid);
	}
	//var languageRow = createSupplierLanguageRow('Langauge', supplierRow['languages'][0]['name']);
	var languageRow = this.createSupplierLanguageRow('Langauge', 'Test Lang');
	var gender = 'Male';
	if(supplierRow['gender']==2) {
	    gender = 'Female';
	}

	var contentNode = dojo.create('div', {"class": 'singleSupplierContent'});
	dojo.addClass(contentNode, 'singleSupplierContent');


	dojo.place(titleRow, contentNode);
	dojo.place(commercialDemoRow, contentNode);
	dojo.place(narrationDemoRow, contentNode);
	dojo.place(languageRow, contentNode);

	var containerNode = dojo.create('div');
	dojo.addClass(containerNode, 'singleSupplier');
	dojo.addClass(containerNode, 'supplier'+gender);
	dojo.place(contentNode, containerNode);
	dojo.place(containerNode, inNode);
    },

    createSupplierTitleRow: function (supplierId, isSupplierRecommended, supplierRecomendedUrl, supplierRecommendedTitle) {
	if(typeof supplierRecomendedUrl == 'undefined') {
	    supplierRecomendedUrl = '';
	}
	if(typeof supplierRecommendedTitle == 'undefined') {
	    supplierRecommendedTitle = '';
	}

        var titleSpan = this.createDemoSpan('supplierTitleText');
	titleSpan.innerHTML = supplierId;
	var ratingSpan = this.createDemoSpan('supplierRating');
	if(isSupplierRecommended) {
	    ratingSpan.innerHTML = this.createRatedStar();
	}
	if(supplierRecomendedUrl!='' && supplierRecommendedTitle!='') {
	    dojo.attr(ratingSpan, "onclick", 'Modalbox.show(\''+supplierRecomendedUrl+'\', {title: \''+supplierRecommendedTitle+'\', width: 600, height: 400}); return false;');
	}
	var rowSpan = this.createDemoSpan('supplierTitle');
	dojo.place(titleSpan, rowSpan);
	dojo.place(ratingSpan, rowSpan);

	return rowSpan;
    },

    createRatedStar: function () {
	return '<img src="http://assets.voicearchive.com/fileadmin/template/images/superspeak.png" border="0">';
    },

    createSupplierDemoRow: function (rowClass, rowTitle, demoUrl, demoId, supplierPublicId, supplierId) {
	var demoTitleSpan = this.createDemoSpan('demoTitle');
	demoTitleSpan.innerHTML = '<a href="' + demoUrl + '">' +rowTitle + '</a>';
	var demoButtonsSpan = this.createDemoSpan('demoButtons');
	demoButtonsSpan.innerHTML = this.createDemoButton(supplierId, rowTitle, demoId, supplierPublicId);
	var rowSpan = this.createDemoSpan(rowClass);
	dojo.place(demoTitleSpan, rowSpan);
	dojo.place(demoButtonsSpan, rowSpan);

	return rowSpan;
    },

    createDemoButton: function (supplierId, rowTitle, demoId, supplierPublicId) {
	var demoTypeName = rowTitle.toLowerCase();
	var internalName = '';
	if(demoTypeName=='commercial') {
	    internalName = 'reklame';
	}
	if(demoTypeName=='corporate') {
	    internalName = 'profil';
	}

	var imgTag = '<img style="cursor:pointer"';
	imgTag += ' src="http://assets1.voicearchive.com/fileadmin/template/play.png"';
	imgTag += ' id="'+internalName+'-icon-'+supplierId+'"'
	imgTag += ' onclick="pageTracker._trackPageview(\'/supplier/'+supplierPublicId+'/demo/'+demoTypeName+'\');playClicked('+supplierId+', \'/stream/supplier/demo/'+demoId+'.mp3\', \''+internalName+'\');">';
	return imgTag;
    },

    createSupplierLanguageRow: function (header, languageTitle) {
	var languageNode = this.createDemoSpan('supplierLanguageTitle');
	languageNode.innerHTML = header+': '+languageTitle;
	return languageNode;
    },

    createDemoOfTypeIfAny: function (supplierRow, demoTypeId) {
	var demos = supplierRow['demos'];
	for(var i=0;i<demos.length;i++)  {
	    if(demos[i]['type']==demoTypeId) {
		return demos[i];
	    }
	}
	return false;
    },

    createDemoSpan: function(className) {
	var span = dojo.create('span');
	if(typeof className !=='undefined') {
	    dojo.addClass(span, className);
	}
	return span;
    },
    setSupplierListNode: function(node) {
	this.supplierListNode = node;
    },
    setLanguageListNode: function(node) {
	this.languageListNode = node;
    },
    setCurrentApiKey: function(value) {
	this.currentApiKey = value;
	this.initializeDemoList();
	this.getAllSuppliers();
    },
    setCurrentLanguageId: function(value) {
	this.currentLanguageId = value;
	this.initializeDemoList();
	this.getAllSuppliers();
    },
    setCurrentTypeId: function(value) {
	this.currentTypeId = value;
	this.initializeDemoList();
	this.getAllSuppliers();
    },
    setCurrentCategoryId: function(value) {
	this.currentCategoryId = value;
	this.initializeDemoList();
	this.getAllSuppliers();
    },
    setCurrentPriorityId: function(value) {
	this.currentPriorityId = value;
	this.initializeDemoList();
	this.getAllSuppliers();
    },
    setCurrentSearchPhrase: function(value) {
	this.currentSearchPhrase = value;
	this.initializeDemoList();
	this.getAllSuppliers();
    },
    setCurrentGender: function(value) {
	this.currentGender = value;
	this.initializeDemoList();
	this.getAllSuppliers();
    }
});




dojo.addOnLoad(function() {
	if(typeof defaultWidgetLanguage == 'undefined') {
	    return;
	}
	if(typeof defaultWidgetApiKey == 'undefined' || defaultWidgetApiKey=='') {
	    defaultWidgetApiKey = 'fisk';
	}
	var currentSupplierListNode;

	dojo.query('.demoList').forEach(function(item) {currentSupplierListNode = item});
	theCreationForm = new com.voicearchive.orderForm({parentNode: currentSupplierListNode, apiKey: defaultWidgetApiKey});
	theCreationForm.createMainOrderForm();
});

