/*101008*/
var NBLoffsety = 2;
var moffsetx = 140;
var moffsety = 10;
var huser = false;

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

//Prices
var band1h = "120.00";
var band1s ="300.00";
var band1hl ="75.00";
var band1sl ="75.00";

var band2h ="168.00";
var band2s ="360.00";
var band2hl ="75.00";
var band2sl ="75.00";

var band3h ="212.00";
var band3s ="420.00";
var band3hl ="75.00";
var band3sl ="75.00";

var band4h ="260.00";
var band4s ="480.00";
var band4hl = "0";
var band4sl = "0";

var band5h = "300.00";
var band5s ="540.00";
var band5hl = "0";
var band5sl = "0";

//Launcher

//Auto change header graphcs in menus
function newhead(loc){
	header = 7;
	n = Math.floor(Math.random() * (header)) + 1;
	thisOne = loc + n + ".gif";
	writeDetails ("head", thisOne).src;
}; //end newHead
  
function runThis (pr){
	window.location.href = pr;
}; //end runThis

function writeDetails (thisPlace, thisStuff) {
	document.getElementById(thisPlace).innerHTML = thisStuff;
}; //end writeDetails

function startupMenu() {
	newhead ('../resources/header');
	setNavigation();
	//does menu use db?
	if (document.getElementById("thisCol")){discover()};
}; //end startupMenu

function startupIndex(headstuff){
	newhead (headstuff);
	setNavigation();
}; //end startupIndex
	
function maintainIndex(nav){
	moveNav2(nav);
	draw(nav);
}; //end maintainIndex

//Standard price management
function startup() {
	if (document.getElementById("platform")){writePlatform ()};
	if (document.getElementById("position")){pixchange(0)};
	if (document.getElementById("suprice")){showBase()};
	if (document.getElementById("tryThis")){similar()};
	if (document.getElementById("sup")){external()};
	setNavigation();
}; //end startup

function startuphome() {
	basePrice = addVAT(homePrice);
	if (langPrice != 0) {langPrice = addVAT(langhomePrice)};
	if (document.getElementById("suprice")){showBase()};
	writePlatform ();
	//homeBase();
	setNavigation();
}; //end startup

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() {
	writePlatform ();
	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 our website: <a href="http://www.talk-2-talk.com">www.talk-2-talk.com</a></p>');
	}; //end if
	setNavigation();
}; //end start download or install
		
// 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
	
function writePlatform () {
	writeDetails ("platform", winStuff);
}; // end writePlatform
	
function writeShop (thisPlace, thisStuff) {
	writeDetails (thisPlace, thisStuff);
}; // end writeShop

function showBase() {
	if (document.getElementById("privprice")) {
		homePrice = addVAT(homePrice);
		writeDetails ("privprice", homePrice);
		};
	writeDetails ("suprice", basePrice);
	if (document.getElementById("fuprice")) {writeDetails ("fuprice", basePrice * 2 + ".00")};
	//T2T program? If yes then:
	if (langPrice != "0"){
		//home language price inc VAT
		langhomePrice = addVAT(langhomePrice);
		writeDetails ("privlangprice", langhomePrice);
		writeDetails ("t2tsuprice", langPrice);
		//Home edition? If no then:
		if (document.getElementById("t2tfuprice")) {
			writeDetails ("t2tfuprice", langPrice * 2 + ".00");
			writeDetails ("t2tsiteprice", langPrice * 4 + ".00");
		};// end if
	}; // end if
}; //end showbase

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

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 = "" + Math.round(parseFloat(licenceNo) * scale);
	if (usersNo == 30) {
		writeDetails ("calc1", "Platslicens pris: ");
	} else {
		writeDetails ("calc1", usersNo + "-anv&auml;ndare pris (ex moms): ");
	}; //end if
	writeDetails ("calc2", tStr.substring(0, tStr.length - 2) + "." + tStr.substring(tStr.length - 2, tStr.length));
	return true;
}; //end multilicence
// end Standard Price Manamgement

//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');
	};
}; // end external suppliers

function addRow(t,c1,cName1,c2, cName2){
	newRow = document.getElementById(t).insertRow(-1);
	// Inserts at first new row position
	newCell = newRow.insertCell(0);
	newCell.innerHTML = c1;
	newCell.className = cName1;
	newCell.style.backgroundColor ="#FFFFCC";
	// Inserts at second new row position
	newCell = newRow.insertCell(1);
	newCell.innerHTML = c2;
	newCell.className = cName2;
	newCell.style.backgroundColor ="#FFFFCC";
	newCell.style.align = "right";
}; //end addRow

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, message) {
	outgoing = decode (pass, wizzo);
	outgoing = outgoing + "?subject=Demo CD&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() {
	pageSize();
	// current = where navigation is now: choose reference points
	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

//Somthing 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) == phaseCheck) & (progName != currentRec[0])){
		if (((eval(currentRec[2]) & phaseCheck) > 0) & (progName != currentRec[0])){
			if ((eval(currentRec[2]) & idCheck) == idCheck){
				conclusion = conclusion + '<A href=\"../' + currentrec[1] + '">' + 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 similar
