// startup.js
var startup='/includes/add_to_basket.php';
var MBstartup='/includes/multi_add_to_basket.php';

// PCH initialisation of variables for converter routines
var inText = new Array
var outText = new Array
var type=4;
var outputText='';
var inputText='';
var value=0;

// PCH 270504 call to intialise converter system
initialiseConverter();

// PCH 080202 & 010302  Set up pointer to images folder - can be changed for online/offline
urlBits = new Array
urlBits=window.location.pathname.split('\\'); // Split on backslash character - here escaped with second backslash.
// alert('Path: '+window.location.pathname+'\n0:'+urlBits[0]+'\n1: '+urlBits[1]+'\n2: '+urlBits[2]+'\n3: '+urlBits[3]+'\n4: '+urlBits[4]+'\n5: '+urlBits[5]);
// First set it for PCH or FMH development system, by default
if(urlBits[1] == "Websites"){USERVAR1=urlBits[0]+'/'+urlBits[1]+'/'+urlBits[2]+'/'+urlBits[3]+'/'+urlBits[4]+'/images/';}
// If not working where expected on PCH system , assume that this is running from a CD and change USERVAR1 appropriately
if(urlBits[1] != "Websites") {USERVAR1=window.location.pathname.substring(1,2) + ':/images/';}
// If we are working on line then set USERVAR1 to use the normal URL version of the location
if (http_mode()){USERVAR1='http://www.toolpost.co.uk/images/';}

// PCH 190103  Initialise USERVAR2 to allow it to be used to check if non-air-shippable products have been selected.
USERVAR2=0;

// PCH 080202
function photo(name){
name=USERVAR1+name
// alert('Looking for file: '+name)
window.open(name,'images','height=600, width=800, menubar=no, resizable=yes, scrollbars=yes, status=no, toolbar=no')
};

// PCH 27/05/06
function display(name,window_height,window_width){   // add 40 pixels to actual image dimensions to allow for scrollbars
// alert('Looking for file: '+name)
if (http_mode()){name='http://www.toolpost.co.uk/images/'+name;}  // ON LINE
if (!http_mode()){name='C:\\Websites\\From Robin Sys\\Websites\\ToolPost_2005\\images\\'    +name;}  // OFF LINE
// alert('Looking for file: '+name+'display in window sized '+window_height+' x '+window_width)
window.open(name,'images','height='+window_height+', width='+window_width+', menubar=no, resizable=yes, scrollbars=yes, status=no, toolbar=no')
};

// PCH 080403
function show(name){
name=USERVAR1+'Tormek_'+name
// alert('Looking for file: '+name)
window.open(name,'torpics','height=420, width=420, menubar=no, resizable=yes, scrollbars=no, status=no, toolbar=no')
};

// PCH 010302
function http_mode(){return("http"==(""+window.location).substring(0,4));}


// PCH 270504  (start Converter section)
function initialiseConverter(){
inText[1]="in."
inText[2]="in."
inText[3]="in."
inText[4]="mm."
inText[5]="cm."
inText[6]="m."

outText[1]="mm."
outText[2]="cm."
outText[3]="m."
outText[4]="in."
outText[5]="in."
outText[6]="in."
}

function updateType(form){
type=top.listvalue(form.Type);
outputText=outText[type];
inputText=inText[type];
form.OutputType.value=outputText;
form.InputType.value=inputText;
form.Value.value="0.0";
form.Result.value="0";
}

function Convert(form){
type=top.listvalue(form.Type)
value=form.Value.value
if (!Validate(value)){
	alert('Please enter a valid number');
	form.Value.value="0.0";
	form.Result.value="0";
	}
else{
	// type=1 inches to mm = *25.4
	// type =2 inches to cm = *2.54
	// type =3 inches to m = *.0254
	// type = 4 mm to inches = /25.4 (Default)
	// type = 5 cm to inches = /2.54
	// type = 6 m to inches = /.0254

	if ((type==1)||(type==4)) {factor = 25.4};
	if ((type==2)||(type==5)) {factor = 2.54};
	if ((type==3)||(type==6)) {factor = 0.0254};

	if ((type==4)||(type==5)||(type==6)) {factor = 1/factor};

	value=value * factor;
	value=Math.round(value*1000);
	value=value/1000;
	form.Result.value=value
	}
}
function Validate(value){
var points=0
if (value.length <= 0){return false}
	else{
		for(i=0; i<value.length; i++){
		if (value.charAt(i) == "."){points++};
		if (points > 1){return false};
		if ((!parseInt(value.charAt(i))) && (value.charAt(i) != ".") && (value.charAt(i) != "0")) {return false}
		}
	return true;
	}
}

// PCH 270504 (end Converter section)
