 var caution = false
   

function remove(sPartNo) {
	var thisForm = MM_findObj('basket_list');
	var thisField;	// = document.forms['basket_list'].elements['121-09-G'];

	// Horrible way of doing this, but couldn't get any direct access to these form fields!
	for(i=0; i<document.forms['basket_list'].elements.length; i++)
	{
		if(document.forms['basket_list'].elements[i].id == sPartNo)
		{
			document.forms['basket_list'].elements[i].value = 0;
			break;
		}
	}
	thisForm.submit();
}

function openPDF(ID){
	var strLocation = '/content/latest_news/attachments/TobyElectronicsNews' + ID.toString() + '.pdf';
	var PDF = open(strLocation, 'PDF', 'menubar=no,resizeable=yes');
}

function MM_displayStatusMsg(msgStr)  { //v3.0
	status=msgStr; document.MM_returnValue = true;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function Trim(strInput){
	
	strOutput = strInput;
	
	//trim the leading character if it is a space
	while(strOutput.charAt(0) == " "){
		strOutput = strOutput.substring(1,strOutput.length);
	}
	
	//trim the trailing character if it is a space
	while(strOutput.charAt(strOutput.length-1) == " "){
		strOutput = strOutput.substring(0,(strOutput.length)-1);
	}
	
	//return the resulting string
	return strOutput;

}

function ValidateEmail(strEmail){

	if((strEmail.indexOf("@") == -1) || (strEmail.indexOf("@") == 0) || (strEmail.indexOf("@") > strEmail.length-5)){
		return false;
	}
	if((strEmail.lastIndexOf(".") != strEmail.length-4) && (strEmail.lastIndexOf(".") != strEmail.length-3)){
		return false;
	}
	
	return true;

}

function integersOnly(field)
{
	var key;
	var keychar;

	key = window.event.keyCode;
	keychar = String.fromCharCode(key);
	
	// control keys
	if ((key==null) || (key==0) || (key==8) ||
			(key==9) || (key==13) || (key==27) )
		 return true;

	// Num Lock keys (numbers)
	else if (key >= 96 && key <= 105)
		return true;

	// numbers
	else if ((("0123456789-").indexOf(keychar) > -1))
		 return true;

	else {
		 window.event.keyCode = 0;
		 return false;
	}
}


function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "")
	if (!caution || (name + "=" + escape(value)).length <= 4000)
		document.cookie = curCookie
	else
		if (confirm("Cookie exceeds 4KB and will be cut!"))
			document.cookie = curCookie
}
function getCookie(name) {
	var prefix = name + "="
	var cookieStartIndex = document.cookie.indexOf(prefix)
	if (cookieStartIndex == -1)
		return null
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
	if (cookieEndIndex == -1)
		cookieEndIndex = document.cookie.length
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT"
	}
}
function fixDate(date) {
	var base = new Date(0)
	var skew = base.getTime()
	if (skew > 0)
		date.setTime(date.getTime() - skew)
}
function item(parent, text, depth) {
	this.parent = parent 
	this.text = text 
	this.depth = depth 
}
function makeArray(length) {
	this.length = length 
}
function makeDatabase() {
	outline = new makeArray(16) 
   
    
	outline[0] = new item(true, '<font class=body><A HREF="/content/catalogue/section.asp?id=8" class=bodylink>Audio Visual (AV) products</A>', 0)
	outline[1] = new item(false, '<A HREF="content/catalogue/section.asp?id=8" class=bodylink>High Speed Headers</A>', 1)
	outline[2] = new item(true, '<A HREF="content/catalogue/section.asp?id=4" class=bodylink>Board-to-board connections</a>', 0)
	outline[3] = new item(false, '<A HREF="http://simplythebest.net/scripts/" class=bodylink>DHTML Scripts</A>', 2)
	outline[4] = new item(false, '<A HREF="http://simplythebest.net/scripts/" class=bodylink>CGI Scripts</A>', 2)
	outline[5] = new item(false, '<A HREF="http://info.simplythebest.net" class=bodylink>Information library</A>', 1)
	outline[6] = new item(false, '<A HREF="http://info.simplythebest.net" class=bodylink>Device drivers</A>', 1)
	outline[7] = new item(false, '<A HREF="http://simplythebest.net/fonts/" class=bodylink>Free fonts</A>', 1)
	outline[8] = new item(false, '<A HREF="http://simplythebest.net/affiliate_programs/" class=bodylink>Affiliate programs</A>', 1)
	outline[9] = new item(true, 'Board-to-board connections', 0)
	outline[10] = new item(false, '<A HREF="http://planmagic.com" class=bodylink>Business software</A>', 1)
	outline[11] = new item(false, '<A HREF="http://planmagic.com/business_planning.html" class=bodylink>Business plan</A>', 1)
	outline[12] = new item(false, '<A HREF="http://planmagic.com/marketing_planning.html" class=bodylink>Marketing plan</A>', 1)
	outline[13] = new item(false, '<A HREF="http://planmagic.com/financial_planning.html" class=bodylink>Financial plan</A>', 1)
	outline[14] = new item(false, '<A HREF="http://plan-a-restaurant.com" class=bodylink>Restaurant plan</A>', 1)
	outline[15] = new item(false, '<A HREF="http://planmagic.com/business_plan/hotel_business_plan.html" class=bodylink>Hotel plan</A>', 1)
	
	setStates()
	setImages()
	
}

function setStates() {
	var storedValue = getCookie("outline")
	
	if (!storedValue) {
		for (var i = 0; i < outline.length; ++i) {
			if (outline[i].depth == 0)
				outline[i].state = true
			else
				outline[i].state = false
		}
	} else {
		for (var i = 0; i < outline.length; ++i) {
			if (storedValue.charAt(i) == '1')
				outline[i].state = true
			else
				outline[i].state = false
		}
	}
}
function setImages() {
	
	for (var i = 0; i < outline.length; ++i) {
		if (outline[i].state)
			if (outline[i].parent) 
				if (outline[i + 1].state) 
					outline[i].pic = '<A HREF="javascript:toggle(' + i + ')"><IMG SRC="../images/bullet_nav.gif" BORDER=0></A>'
				else 
					outline[i].pic = '<A HREF="javascript:toggle(' + i + ')"><IMG SRC="../images/arrow_blue.gif" BORDER=0></A>'
			else 
				outline[i].pic = '<IMG SRC="../images/bullet_nav.gif" BORDER=0>'
	}
	
}
function toggle(num) {


    for (var i =0; i < outline.length ; ++i) {
        if (outline[i].depth >0)
        {
            outline[i].state = false
        }
    }
	for (var i = num + 1; i < outline.length && outline[i].depth >= outline[num].depth + 1; ++i) {
	   
		if (outline[i].depth == outline[num].depth + 1)
			outline[i].state = !outline[i].state 
	}

	setStorage()
	history.go(0)
}
function setStorage() {

	var text = ""
	for (var i = 0; i < outline.length; ++i) {
		text += (outline[i].state) ? "1" : "0"
	}

	setCookie("outline", text)
}


