//data scripts for the price calculator
						 
var rightsArray = new Array ('Standard Television', 
						'Cable / Satellite / Digital (CSD)', 
						'Standard Television + CSD', 
						'Standard Television + DVD',
						'Cable / Satellite / Digital (CSD) + DVD',
						'Standard Television + CSD + DVD',
						'Schools / Educational TV',
						'24 Hour News',
						'DVD / Home Video', 
						'All  Media',
						'Advertising',
						'Trapped Audiences',
						'Corporate / Exhibition / Presentation',
						'Exhibition - Free',
						'Exhibition - Paid',
						'Feature Film',
						'Internet',
						'Non-Theatrical',					
						'Pop Promo',
						'Radio'			
						);
				
var territoriesArray = new Array ( 	'Single Country', 
					'Europe', 
					'Worldwide', 
					'Worldwide ex USA',
					'Local',
					'National'
					 );

var periodArray = new Array (		'1TX', 
					'2TX', 
					'5 Years', 
					'7 Years', 
					'10 Years', 
					'Perpetuity',
					'24 hours',
					'1 Year',
					'2 Years',
					'3 Years'
					);

rightsArray ['Standard Television'] = new Array ('Territories', 'Periods');
rightsArray ['Standard Television']['Territories'] = new Array (0, 1, 2, 3);
rightsArray ['Standard Television']['Periods'] = new Array (2, 3, 4, 5);

rightsArray ['Cable / Satellite / Digital (CSD)'] = new Array ('Territories', 'Periods');
rightsArray ['Cable / Satellite / Digital (CSD)']['Territories'] = new Array (0, 1, 2, 3);
rightsArray ['Cable / Satellite / Digital (CSD)']['Periods'] = new Array (2, 3, 4, 5);	

rightsArray ['Standard Television + CSD'] = new Array ('Territories', 'Periods');
rightsArray ['Standard Television + CSD']['Territories'] = new Array (0, 1, 2, 3);
rightsArray ['Standard Television + CSD']['Periods'] = new Array (2, 3, 4, 5);

rightsArray ['Standard Television + DVD'] = new Array ('Territories', 'Periods');
rightsArray ['Standard Television + DVD']['Territories'] = new Array (0, 1, 2, 3);
rightsArray ['Standard Television + DVD']['Periods'] = new Array (2, 3, 4, 5);

rightsArray ['Cable / Satellite / Digital (CSD) + DVD'] = new Array ('Territories', 'Periods');
rightsArray ['Cable / Satellite / Digital (CSD) + DVD']['Territories'] = new Array (0, 1, 2, 3);
rightsArray ['Cable / Satellite / Digital (CSD) + DVD']['Periods'] = new Array (2, 3, 4, 5);
	
rightsArray ['Standard Television + CSD + DVD'] = new Array ('Territories', 'Periods');
rightsArray ['Standard Television + CSD + DVD']['Territories'] = new Array (0, 1, 2, 3);
rightsArray ['Standard Television + CSD + DVD']['Periods'] = new Array (2, 3, 4, 5);

rightsArray ['Schools / Educational TV'] = new Array ('Territories', 'Periods');
rightsArray ['Schools / Educational TV']['Territories'] = new Array ("0");
rightsArray ['Schools / Educational TV']['Periods'] = new Array (2, 3, 4, 5);

rightsArray ['24 Hour News'] = new Array ('Territories', 'Periods');
rightsArray ['24 Hour News']['Territories'] = new Array (4, 5, 2);
rightsArray ['24 Hour News']['Periods'] = new Array ("6");

rightsArray ['DVD / Home Video'] = new Array ('Territories', 'Periods');
rightsArray ['DVD / Home Video']['Territories'] = new Array (0, 1, 2, 3);
rightsArray ['DVD / Home Video']['Periods'] = new Array (2, 3, 4, 5);

rightsArray ['All  Media'] = new Array ('Territories', 'Periods');
rightsArray ['All  Media']['Territories'] = new Array ("2");
rightsArray ['All  Media']['Periods'] = new Array (2, 3, 4, 5);	

rightsArray ['Advertising'] = new Array ('Territories', 'Periods');
rightsArray ['Advertising']['Territories'] = new Array (0, 1, 2);
rightsArray ['Advertising']['Periods'] = new Array ("7");

rightsArray ['Trapped Audiences'] = new Array ('Territories', 'Periods');
rightsArray ['Trapped Audiences']['Territories'] = new Array (0, 1, 2, 3);
rightsArray ['Trapped Audiences']['Periods'] = new Array (2, 3, 4, 5);	

rightsArray ['Corporate / Exhibition / Presentation'] = new Array ('Territories', 'Periods');
rightsArray ['Corporate / Exhibition / Presentation']['Territories'] = new Array (0, 1, 2);
rightsArray ['Corporate / Exhibition / Presentation']['Periods'] = new Array (7, 8);

rightsArray ['Exhibition - Free'] = new Array ('Territories', 'Periods');
rightsArray ['Exhibition - Free']['Territories'] = new Array (0, 1, 2);
rightsArray ['Exhibition - Free']['Periods'] = new Array (7, 8, 9, 5);	

rightsArray ['Exhibition - Paid'] = new Array ('Territories', 'Periods');
rightsArray ['Exhibition - Paid']['Territories'] = new Array (0, 1, 2);
rightsArray ['Exhibition - Paid']['Periods'] = new Array (7, 8, 9, 5);

rightsArray ['Feature Film'] = new Array ('Territories', 'Periods')
rightsArray ['Feature Film']['Territories'] = new Array ("2");
rightsArray ['Feature Film']['Periods'] = new Array ("5");

rightsArray ['Internet'] = new Array ('Territories', 'Periods');
rightsArray ['Internet']['Territories'] = new Array ("2");
rightsArray ['Internet']['Periods'] = new Array (2, 3, 4, 5);

rightsArray ['Non-Theatrical'] = new Array ('Territories', 'Periods');
rightsArray ['Non-Theatrical']['Territories'] = new Array (0, 1, 2, 3);
rightsArray ['Non-Theatrical']['Periods'] = new Array (2, 3, 4, 5);

rightsArray ['Pop Promo'] = new Array ('Territories', 'Periods');
rightsArray ['Pop Promo']['Territories'] = new Array (0, 1, 2);
rightsArray ['Pop Promo']['Periods'] = new Array (2, 3, 4, 5);

rightsArray ['Radio'] = new Array ('Territories', 'Periods');
rightsArray ['Radio']['Territories'] = new Array (0, 2);
rightsArray ['Radio']['Periods'] = new Array (0, 1);


//main scripts for the price calculator

function changeRights () {
	var selectedIndex = document.ratesForm.rightsList.selectedIndex;
	var selectedValue = document.ratesForm.rightsList.options[ selectedIndex ].value;
	if (selectedValue != "XXX") {
		changeTerritories (selectedValue, "XXX", "XXX");
	}
}


function alterTerritories () {
	var selectedIndex = document.ratesForm.rightsList.selectedIndex;
	var selectedValue = document.ratesForm.rightsList.options[ selectedIndex ].value;
	if (selectedValue != "XXX") {
		changePeriods (selectedValue, "XXX", "XXX");
	}
}


function changeTerritories (rightsIndex, territoriesIndex, periodsIndex) {
	var territoryDD = document.ratesForm.territoryList;
	var tmp1 = rightsArray [rightsIndex];
	var tmpArray = rightsArray [tmp1]['Territories'];
	var count = 0;
	territoryDD.length = 1;
	
	for (count = 0; count < tmpArray.length; count++) {
		territoryDD.length = territoryDD.length + 1;
		var territoryIndex = tmpArray[count];
		var newOption = new Option (territoriesArray [territoryIndex]);
		territoryDD.options[count + 1] = newOption;
		territoryDD.options[count + 1].value = territoryIndex;			
	}	
	if (territoryDD.length == 2) {
		territoryDD.selectedIndex = 1;
	} else {		
		var territoryDDIndex = 0;
		for (count = 0; count <= tmpArray.length; count ++) {
			if (territoryDD.options [count].value == territoriesIndex) {
				territoryDDIndex = count;
			}
		}
		
		territoryDD.selectedIndex = territoryDDIndex;	
	}	
	
	//alert (rightsIndex + ". " + territoriesIndex + ". " + periodsIndex);
	changePeriods (rightsIndex, territoriesIndex, periodsIndex);
}



function changePeriods (rightsIndex, territoriesIndex, periodsIndex) {
	var periods	= document.ratesForm.licenseList;
	var tmp1 = rightsArray [rightsIndex];
	var tmpArray = rightsArray [tmp1]['Periods'];
	var theTerritoryDD = document.ratesForm.territoryList;
	var theTerritory = theTerritoryDD.selectedIndex;
	
	var count = 0;
	var startIndex = 0;
	periods.length = 1;
	
	if ( (tmp1 == 'Standard Television') && (theTerritory == "1") ) {
		periods.length = periods.length + 1;
		var newOption = new Option ("1 TX");
		periods.options[1] = newOption;
		periods.options[1].value = '0';
		
		periods.length = periods.length + 1;
		var newOption2 = new Option ("2 TX");
		periods.options[2] = newOption2;
		periods.options[2].value = '1';
		startIndex = 2;
	}
	
	for (count = 0; count < tmpArray.length; count++) {
			periods.length = periods.length + 1;
			var periodIndex = tmpArray[count];
			var newOption = new Option (periodArray [periodIndex]);
			periods.options[startIndex + count + 1] = newOption;
			periods.options[startIndex + count + 1].value = periodIndex;			
	}	
	
	
	
	if (periods.length == 2) {
		periods.selectedIndex = 1;
	} else {
		var periodDDIndex = 0;	
			
		for (count = 0; count <= tmpArray.length; count ++) {
			if (periods.options [count].value == periodsIndex) {
				periodDDIndex = count;
			}
		}
		
		//alert ("periods.length1: " + periods.length);
		periods.selectedIndex = periodDDIndex;	
		//alert ("periods.length2: " + periods.length);
	}	
	
}


function updateDropDowns (rightsIndex, territoryIndex, periodIndex) {
	changeTerritories (rightsIndex, territoryIndex, periodIndex); 
}


function checkFields () {
	var errorMsg = "To generate a quote please select the following items:\n";
	var hasError = false;
	var selectedRightsIndex = document.ratesForm.rightsList.selectedIndex;
	var selectedRightsValue = document.ratesForm.rightsList.options[ selectedRightsIndex ].value;
	
	var selectedTerritoryIndex = document.ratesForm.territoryList.selectedIndex;
	var selectedTerritoryValue = document.ratesForm.territoryList.options[ selectedTerritoryIndex ].value;
	
	var selectedPeriodIndex = document.ratesForm.licenseList.selectedIndex;
	var selectedPeriodValue = document.ratesForm.licenseList.options[ selectedPeriodIndex ].value;
	
	var numOfSeconds = document.ratesForm.numOfSecondsTextF.value;
	var aNumber = parseFloat (numOfSeconds);
	
	if (selectedRightsValue == "XXX") {
		errorMsg = errorMsg + "\t* the rights\n";
		hasError = true;
	}
	
	if (selectedTerritoryValue == "XXX") {
		errorMsg = errorMsg + "\t* the territories\n";
		hasError = true;		
	}
	
	if (selectedPeriodValue == "XXX") {
		errorMsg = errorMsg + "\t* the license period\n";
		hasError = true;		
	}
	
	if (isNaN (aNumber)) {
		errorMsg = errorMsg + "\t* the number of seconds\n";
		hasError = true;			
	} else {
		document.ratesForm.numOfSecondsTextF.value = aNumber;
	}
	
	if (hasError) {
		errorMsg = errorMsg + "you require."
		alert (errorMsg);
		return false;	
	}
}


var win=null;
function NewWindow(mypage,myname,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(mypage,myname,settings);win.focus();
}

function changeRights()
{
	R_selected = document.ratesForm.rightsList.value;
	T_selected = document.ratesForm.territoryList.value;
	L_selected = document.ratesForm.licenseList.value;
	theURL = 'myCalc_2.cfm?rights=' + R_selected;
	theURL = theURL + '&territory=' + T_selected;
	theURL = theURL + '&license=' + L_selected;
	document.location.href=theURL;
}

function changeTerritory()
{
	T_selected = document.ratesForm.territoryList.value;
	theURL = 'myCalc_2.cfm?territory=' + T_selected;
	document.location.href=theURL;
}

function changeLicense()
{
	L_selected = document.ratesForm.licenseList.value;
	theURL = 'myCalc_2.cfm?license=' + L_selected;
	document.location.href=theURL;
}
