/*020310*/

//Shop store identity
var storeID = "storeid value=10000";
var taxRate = "17.5";

//Prices
var band1h = "10.20";
var band1s ="27.50";
var band1hl ="6.80";
var band1sl ="12.00";

var band2h ="12.76";
var band2s ="32.50";
var band2hl ="7.65";
var band2sl ="13.50";

var band3h ="17.01";
var band3s ="37.50";
var band3hl ="8.50";
var band3sl ="15.00";

var band4h ="21.27";
var band4s ="42.50";
var band4hl = "0";
var band4sl = "0";

var band5h = "25.52";
var band5s ="47.50";
var band5hl = "0";
var band5sl = "0";

var currency = "£";

//Launcher

//Auto change header graphcs in menus
var header = 9;
function newhead(loc){
	n = Math.floor(Math.random() * (header)) + 1;
	writeDetails ("head", '<img src=' + loc + n + '.gif' + '>');
}; //end newHead
	
function maintainIndex(nav){
	moveNav2(nav);
	draw(nav);
}; //end maintainIndex

function startup() {
	if (document.getElementById("platform")){writeDetails ("platform", winStuff);};
	if (document.getElementById("position")){pixchange(0)};
	if (document.getElementById("suprice")){
		//Use at home?
		if (huser && (basePrice != 'Free')) {
			basePrice = addVAT(homePrice);
			if (langPrice != 0) {langPrice = addVAT(langhomePrice)};
			writeDetails ("vat", taxRate);
		};
		showBase();
	};
	if (document.getElementById("tryThis")){similar()};
	if (document.getElementById("sup")){external()};
	if (document.getElementById("supriceAU")){
		showBaseAU();
	}
	setNavigation();
}; //end startup

function startupMenu(s) {
	newhead (s);
	//if database menu turn this on
	if (document.getElementById("ColL")){discover()};
	setNavigation();
}; //end start

function addVAT(price){
	rate = taxRate / 100 + 1;
	price = "" + Math.round(parseFloat(price * rate) * Math.pow(10, 2));
	price = price.substring(0, price.length - 2) + "." + price.substring(price.length - 2, price.length);
	return price;
}; // end addVAT

function startdori() {
	writeDetails ("platform", winStuff);
	writeDetails ("vernum", vnum);
	writeDetails ("pname1", progName);
	writeDetails ("pname2", progName);
	if (document.getElementById("dloaddata")){writeDetails ("dloaddata", downdata)};
	writeDetails ("implement", impdata);
	if (langPrice != "0"){
		writeDetails ("t2tstuff", '<p>For the most up-to-date information on what <strong>Talk·<span class="bull">2</span>·Talk</strong> language packs are available, please refer to the <strong>Talk&middot;<span class="bull">2</span>&middot;Talk</strong> pages: <a href="http://www.resourcekt.co.uk/t2tweb/introduction.htm"><strong>Talk&middot;<span class="bull">2</span>&middot;Talk</strong> - Introduction</a></p>');
	}; //end if
	setNavigation();
}; //end start download or install
	
function writeDetails (thisPlace, thisStuff) {
	document.getElementById(thisPlace).innerHTML = thisStuff;
}; // end writeShop

//----------------- Australian Rules Prices

var prMultsAU = new Array (1, 150, 190, 220, 245, 270, 284.5)

function showBaseAU() {
	var	scale = Math.pow(10, 2);
	if (document.getElementById("supriceAU")){writeDetails ("supriceAU", currency + basePrice)};
	
	if (document.getElementById("fupriceAU")) {;
		tStr = currency + Math.round(parseFloat(Math.round((basePrice / 100 * prMultsAU[1]) / .5) * .5) * scale);
		writeDetails ("fupriceAU", tStr.substring(0, tStr.length - 2) + "." + tStr.substring(tStr.length - 2, tStr.length))
		}; //end if
}; //end showbase

//Standard price management
function multilicenceAU(usersNo) {
	scale = Math.pow(10, 2);
	if(usersNo){
		if (usersNo == "site") {usersNo = 30};
		licenceNo = Math.round((basePrice / 100 * prMultsAU[usersNo / 5]) / .5) * .5;
		tStr = currency + Math.round(parseFloat(licenceNo) * scale);
		if (usersNo == 30) {
			writeDetails ("calc1", "The site licence price: ");
		} else {
			writeDetails ("calc1", "The " + usersNo + "-user price: ");
		}; //end if
		writeDetails ("calc2", tStr.substring(0, tStr.length - 2) + "." + tStr.substring(tStr.length - 2, tStr.length));
		return true;
	}; //end if
}; //end multilicence
// end Standard Price Management

//-----------------

function showBase() {
	writeDetails ("suprice", currency + basePrice);
	if (document.getElementById("fuprice")) {writeDetails ("fuprice", currency + basePrice * 2 + ".00")};
	//T2T program? If yes then:
	if (langPrice != "0"){
		writeDetails ("t2tsuprice", currency + langPrice);
		//Home edition? If no then:
		if (document.getElementById("t2tfuprice")) {
			writeDetails ("t2tfuprice", currency + langPrice * 2 + ".00");
			writeDetails ("t2tsiteprice", currency + langPrice * 4 + ".00");
		}; //end if
	}; // end if
}; //end showbase

function homeBase() {
	writeShop ("shop1", shopDetails);
	//writeShop ("shop3", basketview);
	return true;
}; //end homebase

//Standard price management
function multilicence(usersNo) {
	if (usersNo == "site") {usersNo = 30};
	var licenceNo = Math.round(basePrice * 2 / 5 * (105 - usersNo) / 100 *  usersNo / .5) * .5;
	scale = Math.pow(10, 2);
	tStr = currency + Math.round(parseFloat(licenceNo) * scale);
	if (usersNo == 30) {
		writeDetails ("calc1", "The site licence price is ");
	} else {
		writeDetails ("calc1", "The " + usersNo + "-user price is ");
	}; //end if
	writeDetails ("calc2", tStr.substring(0, tStr.length - 2) + "." + tStr.substring(tStr.length - 2, tStr.length));
	return true;
}; //end multilicence
// end Standard Price Management
		
// Gallery picture exchange
function pixchange(i1){
	writeDetails ('pix', '<img src=' + pixlist[i1].src + '>');
	writeDetails ("position", (pixthisone + 1) + " / " + (pixcount + 1));
}; // end pixchange

function previous(){
	pixthisone = (pixthisone - 1);
	if (pixthisone < 0) pixthisone = pixcount;
 	pixchange(pixthisone);
}; // end previous
	 
function next(){
	pixthisone = (pixthisone + 1);
	if (pixthisone > pixcount) pixthisone = 0;
		pixchange(pixthisone);
};  //end next
//end Gallery pixchange

//External supplier prices
function external(){
	addString = 0;
	//document.getElementById("a").innerHTML = firstText;
	writeDetails ("sup", '£' + basePrice);
	if (fiveu != ""){
		addRow('Prices','Five-user', 'pricelead', '£' + fiveu, 'prices');
	};
	if (tenu != ""){
		addRow('Prices','Ten-user', 'pricelead', '£' + tenu, 'prices');
	};
	if (site != ""){
		addRow('Prices','Site licence', 'pricelead', '£' + site, 'prices');
	};
};

function addRow(t,c1,cName1,c2, cName2){
	newRow = document.getElementById(t).insertRow(-1);
	// parameter of 0 inserts at first cell position
	newCell = newRow.insertCell(0);
	newCell.innerHTML = c1;
	newCell.className = cName1;
	newCell.style.backgroundColor ="#FFFFCC";
	// parameter of 1 inserts at second cell position
	newCell = newRow.insertCell(1);
	newCell.innerHTML = c2;
	newCell.className = cName2;
	newCell.style.backgroundColor ="#FFFFCC";
	newCell.style.align = "right";
}; 
// end external suppliers
  
function runThis (pr){
	window.location.href = pr;
}; //end runThis

function bchange(n, button){
	document[n].src=button;
	return true;
	} // end bchange

function popwin(thepage,thetarget) {
  window.open(thepage,thetarget,'status=no,scrollbars=yes,resizable=yes,width=700,height=450');
}; //end popwin

function poppix(thepage,thetarget) {
  window.open(thepage,thetarget,'resizable=yes,width=650,height=525');
}; //end poppix

function popzoom(thepage, thetarget, w, h) {
	vSize = "resizable=yes,width=" + w + ", height=" + h;
  window.open(thepage,thetarget, vSize);
}; //end popzoom

function sortout(pass, towho, wizzo) {
	outgoing = decode (pass, wizzo);
	document.write('<a href="MAILTO:' + outgoing + '">');
	document.write(towho);
	document.write('</a>');
}; //end sortout

function sortoutplus(pass, towho, wizzo, subj, message) {
	outgoing = decode (pass, wizzo);
	outgoing = outgoing + "?subject=" + subj + "&body=" + message;
	document.write('<a href="MAILTO:' + outgoing + '">');
	document.write(towho);
	document.write('</a>');
}; //end sortout
	
function decode (a, b){
	out = "";
	for (var i = 0; i < a.length; i +=2){
		letter = a.charAt(i);
		if (letter == "*") {
			letter = b.charAt(4);
		}  //end if *	
		if (letter == "?") {
	  		letter = b.charAt(1);
		  }  //end if ?
	    out = out + letter;
	}; //end for
	return out;
}; //end decode

// Menu floater
var oldX = 0;
var targetX = 0;
var targetY = 0;
var findW = 0;
var findH = 0;
var stepRate = 5;
var slowDown = 1;
var counter = 0;
var setUpFlag = false;

function pageSize(){
// find window width and height
	if (window.innerHeight) {
		findH = window.innerHeight;
		findW = window.innerWidth;
	} else {
		findH = document.body.clientHeight;
		findW = document.body.clientWidth;
	}; //end if
}; //end pageSize

function draw(nav, x, y){
	document.getElementById(nav).style.left = x + "px";
	document.getElementById(nav).style.top = y + "px";
	document.getElementById(nav).style.visibility = "visible";
}; // end draw

function redraw(){
	if (document.getElementById('main')) {draw('main', newX + moffsetx, moffsety);}
	if (document.getElementById('NBtop')) {draw('NBtop', newX, newY)};
	if (document.getElementById('NBleft')) {draw('NBleft', newX, newY + NBLoffsety)};
};
//First time through to establish X & Y
function setNavigation(){
	setNavigation2();
	//allow first draw to complete before setting setUpFlag or redraw starts too soon
	setUpFlag = true;
}; // end setNavigation

function setNavigation2(){
	pageSize();
	
	//set position of navigation
	newX = ((findW - 780) / 2); 
	if (targetX < 0) {newX = 0};
	
	newY = 0;
	redraw();
}; // end setNavigation2
 
 //Subsequent times through
function moveNav(){
	if (setUpFlag) {
		moveNav2();
	}; //end if
}; // end MoveNav

function moveNav2(navigation) {
	pageSize();
	// current = where navigation is now
	if (document.getElementById('NBtop')) {
		newLocation('NBtop')
		} else 	{
		newLocation('NBleft')
	} //end if
		
	// assume IE6 +4.01 and user has not scrolled until otherwise
	bodyTop = 0;
	if (window.pageYOffset) {
		bodyTop = window.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		// IE6 +4.01 and user has scrolled
		bodyTop = document.documentElement.scrollTop;
	} else if (document.body && document.body.scrollTop){
		// IE5
		bodyTop = document.body.scrollTop;
	}; //end if
	//target = where it will be at finish
	targetX	= Math.round((findW - 780) / 2); 
	if (targetX < 0) {targetX = 0};
	targetY = bodyTop;
	// has it moved since last check?
	if ( currentX != targetX || currentY != targetY ) {
		xDiff = targetX - currentX;
		yDiff = targetY - currentY;
		reduceX = Math.round(xDiff / stepRate);
		reduceY = Math.round(yDiff / stepRate);
		// reduce = incremental move towards target
		// new = new location of navigation moving towards target
		newX = currentX + reduceX;
		newY = currentY + reduceY;
		// delayer = length of shortest path * slowDown factor
		delayer = (slowDown - (xDiff + yDiff)) * slowDown;
		for (var i = 0 ; i <= delayer; i++){
		}
	redraw();
	}; //end if
}; //end moveNav2

function newLocation (nav) {
	currentX = parseInt(document.getElementById(nav).style.left); 
	currentY = parseInt(document.getElementById(nav).style.top);
}
// end menu floater

//Something similar in the database?
var binary = new Array (16, 32, 64); //fnd, prim or sec
function similar(){
	conclusion = "";
	idCheck = 0;
	phaseCheck = 0;
	
	// Look through to find current
	index = 0;
	for (i = 0; i < progList.length; i++){
		currentRec = progList[i].split(',');
		if (currentRec[0] == progName){
			index = i;
			//Which phase(s)?
			for (i=0; i < 3; i++){
				if ((binary[i] & currentRec[2]) == binary[i]){
					phaseCheck = phaseCheck + binary[i];
				}; //end if
			};//end for
			idCheck = currentRec[2] - phaseCheck;
			break
		};//end if
	};//end for

	//Create Match list
	for (i = 0; i < progList.length; i++){
		currentRec = progList[i].split(',');
		if (((eval(currentRec[2]) & phaseCheck) > 0) & (progName != currentRec[0])){
			if ((eval(currentRec[2]) & idCheck) == idCheck){
				conclusion = conclusion + '<a href=\"../' + currentRec[1] + '/product.htm">' + currentRec[0] + '</A>';
				if (i != progList.length) {conclusion = conclusion + ' - '};
			};//end if
		};//end if
	};//end for
	if (conclusion.length > 0){
		conclusion = '<p class="bull">You might also like to look at:</p><p>' + (conclusion.slice(0, conclusion.length - 3)) + '</p>';
		writeDetails ("tryThis", conclusion);
	};//end if
};//end similar