var agent=navigator.userAgent.toLowerCase();
var ie=((agent.indexOf("msie") != -1) && (agent.indexOf("opera") == -1));

function checkScorch() {
	var scorch_plugin = null;
	if(navigator.plugins && navigator.mimeTypes.length)
		scorch_plugin = (navigator.plugins['ScorchNetscapePlugin'] || navigator.plugins['ScorchPlugin'])?true:false;
	return scorch_plugin;
}

function writeScorch (src, copies, div, width, height, command) {
	var object = ''
	if ( checkScorch() == false ) {
		object = $('#howToInstallScorch').html();
		$('#' + div).addClass('installationGuide');
	} else {
		var params = {
			'src': src,
			'type': 'application/x-sibelius-score',
			'scorch_minimum_version': '6010',
			'scorch_preferred_version': '6010',
			'scorch_security': 'challengeResponse',
			'scorch_command': command,
			'scorch_num_copies': copies,
			'scorch_shrink_limit': '100',
			'ShrinkWindow': '0',
			'AutoZoomPercent': '100'
		};
		object = '<object classid="clsid:A8F2B9BD-A6A0-486A-9744-18920D898429" codebase="http://www.sibelius.com/download/software/win/ActiveXPlugin.cab" width="'+width+'" height="'+height+'">';
		for (i in params)
			object += '<param name="'+i+'" value="'+params[i]+'">';
		if (!ie) {
			object += '<embed ';
			for (i in params)
				object += i.toLowerCase() + '="'+params[i]+'" ';
			object += 'pluginspage="http://www.sibelius.com/cgi/plugin.pl" width="'+width+'" height="'+height+'"></embed>';
		}
		object += '</object>';
	}
	$('#' + div).html(object);
}

function multiWriteScorch () {
	var HTML = '';
	for (i in aScores)
		HTML+=" <a href=\"javascript:scorchInNewWindow('"+aScores[i][2] +"', '"+aScores[i][1]+"', '"+ aScores[i][0] +"')\">"+ aScores[i][2] +"</a>";
	$('#sibeliusScores').html(HTML);
	writeScorch(aScores[0][0], aScores[0][1], 'sibelius', '100%', 920, 'print');
}

function scorchInNewWindow(title, quantity, link) {
	var popupWin = popup('/imp/scorch.html?score='+escape(link) ,'d', '550', '750', 'yes', 'center')
}

function popup(url,title,w,h,scroll,pos) {
	if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
	if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
	else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(url,title,settings);
	return win;
}	//	<a href="http://pwm.com.pl" onclick="popup(this.href,'Okno','300','200','no','center');return false" onfocus="this.blur()">pwm</a>

