  //  
  // PSA Parts ES Web Site methods - Ben Jay Aug 2006 
 
  var siteTag = 'es2'; 
  var siteLinkRoot = 'http://www.psaparts.es/'; 
  var siteSecRoot = 'https://www.psaparts.es/'; 
  var siteRoot = 'http://www.psaparts.es/'; 
  var siteServRoot = 'http://www.psaparts.es/'; 
  var siteDomain='psaparts.es'; 
	 
	// ============================================== 
	var isLive=false; 
	function showLive(html) 
	{ 
		if(isLive) 
			document.write(html); 
	} 
	// ------------------ 
  function showLiveStock(level, order, central) 
  { 
    if(!isLive) 
      return;  
 
    if(level > 0) 
     document.write('En stock actualmente'); 
    else if(order > 0) 
      document.write('<b>Bajo pedido</b><br>(disponible pronto)'); 
    else if(central > 0) 
      document.write('<b>Bajo pedido</b><br>(disponible 8 días)'); 
    else 
      document.write('<b>Pedido bajo pedido</b><br>(disponibilidad desconocida)'); 
  }  
// ============================================== 
		var tileRollerSrc=null; 
		 
		function tileRollerShow(img, tileName) 
		{ 
			if(!tileName) 
			  tileName=img.name; 
				 
			if(tileRollerSrc==img) { 
				if(tileRollerHiding) 
					clearTimeout(tileRollerHiding); 
				return;				 
			} 
			tileRollerSrc=img; 
 
			var el1=document.getElementById('tileRoller'); 
			// in case it is already showing elsewhere, hide while we populate and move: 
			el1.style.visibility='hidden';		 
 
			var l1=document.getElementById('l1-'+tileName); 
			if(!l1) 
				return; 
			 
			el1.style.left=(img.offsetLeft+50)+'px'; 
			el1.style.top=(img.offsetTop+50)+'px'; 
			el1.style.height='auto'; 
			el1.innerHTML=l1.innerHTML; 
			el1.style.visibility='visible'; 
		} 
	// ------------------ 
		function tileRollerHide() 
		{ 
			var el1=document.getElementById('tileRoller');		 
			el1.style.visibility='hidden'; 
			tileRollerSrc=null; 
		}		 
	// ------------------ 
		var tileRollerHiding=null;		 
		 
		function tileRollerOver() 
		{ 
			if(tileRollerHiding) 
				clearTimeout(tileRollerHiding); 
		} 
	// ------------------ 
		function tileRollerOut() 
		{				 
			tileRollerHiding=setTimeout('tileRollerHide()',50);   
		}	 
 
// ============================================== 
    // modify the height of the tiles to match the tallest.  
    function adjustTileHeight(tag)   
    {   
      if(typeof document.body.clientHeight == 'undefined')     
        return;       // clientHeight is not supported by old netscape   
  
      var offHeight=0;  
      var divs=document.getElementsByTagName(tag);  
      for(var i=0;i<divs.length;i++)  
      {  
        var div=divs[i];  
//        if(div.id.substr(0,5)=='tile-' && div.offsetHeight>offHeight)  
//          offHeight=div.offsetHeight;  
        if(div.id.substr(0,5)=='tile-') 
				{ 
//						alert('div.offsetHeight:'+div.offsetHeight+', offHeight:'+offHeight+', margin:'+div.style.margin); 
					if( div.offsetHeight>offHeight)  
          	offHeight=div.offsetHeight;  
				} 
      }          
      for(var i=0;i<divs.length;i++)  
      {  
        var div=divs[i];  
        if(div.id.substr(0,5)=='tile-')  
          div.style.height=offHeight+'px';  
      }          
    }   
		 
// ============================================== 
		var orderRollerVisible=false; 
		 
		function orderRollerShow() 
		{ 
			if(orderRollerVisible) 
				return;				 
 
			var el1=document.getElementById('orderRoller'); 
			el1.style.visibility='visible'; 
		} 
	// ------------------ 
		function orderRollerHide() 
		{ 
			var el1=document.getElementById('orderRoller');		 
			el1.style.visibility='hidden'; 
			orderRollerVisible=false; 
		}		 
	// ------------------ 
		var orderRollerHiding=null;		 
		 
		function orderRollerOver() 
		{ 
			if(orderRollerHiding) 
				clearTimeout(orderRollerHiding); 
		} 
	// ------------------ 
		function orderRollerOut() 
		{				 
			orderRollerHiding=setTimeout('orderRollerHide()',50);   
		}	 
// ============================================== 
	// handle the cookie used to display the mini order box 
//  function eraseCookie(name) {  
//		createCookie(name,"",-1);  
//  }  
	// ------------------ 
//  createOrderCookie(); 
//  if(!document.cookie || document.cookie.length==0) 
//		alert('no cookie'); 
//	else 
//		alert('cookie:"'+document.cookie+'"'); 
	// ------------------ 
	function readCookie(name) { 
	var nameEQ = name + "="; 
	var ca = document.cookie.split(';'); 
	for(var i=0;i < ca.length;i++) { 
		var c = ca[i]; 
		while (c.charAt(0)==' ') c = c.substring(1,c.length); 
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); 
	} 
	return null; 
	} 
	// ------------------ 
	function getAccountText() 
	{ 
		if(isLoggedIn()) 
			document.write('My Account'); 
		else 
			document.write('Not Logged In'); 
	} 
	// ------------------ 
  function setLoginCookie(status) 
	{ 
		var loggedIn=''; 
		if(status=='0') 
			loggedIn='no'; 
		else if(status=='1' || status=='2') 
			loggedIn='yes'; 
		else 
			return; 
			 
		document.cookie = 'login='+loggedIn+'; path=/'; 
  } 
	// ------------------ 
	function isLoggedIn() 
	{ 
		if(!document.cookie || document.cookie.length==0 || document.cookie.indexOf('login=')<0) 
			return false; 
		var start=document.cookie.indexOf('login='); 
		var end=document.cookie.indexOf(';',start); 
		var status; 
		if(end<0) 
			status=document.cookie.substring(start+6); 
		else 
			status=document.cookie.substring(start+6,end); 
//		alert('"'+document.cookie+'"\n start:'+start+',\n end:'+end+',\n status:'+status); 
		return (status=='yes'); 
	} 
	// ------------------ 
  function createOrderCookie() 
	{ 
//    if(!document.cookie || document.cookie.length==0) 
//		document.cookie = "od_items=; path=/"; 
		// cookie length must be less that 4KB. 
		// must check that the seperator characters |:; are not included in the text we wish to store! 
//		document.cookie = "order=123.45|12.34|AcerNote 3000 Adapter:1|iPod Video Battery:1; path=/"; 
//		document.cookie = "order=; path=/"; 
	} 
	// ------------------ 
//	function readCookie(name) { 
//	var nameEQ = name + "="; 
//	var ca = document.cookie.split(';'); 
//	for(var i=0;i < ca.length;i++) { 
//		var c = ca[i]; 
//		while (c.charAt(0)==' ') c = c.substring(1,c.length); 
//		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); 
//	} 
//	return null; 
//	} 
	// ------------------ 
  function createOrderRollerHtml() 
	{ 
		var emptyHtml='<p class="empty">You have not added any items to your order yet.</p>' 
		if(!document.cookie || document.cookie.length==0 || document.cookie.indexOf('order=')<0) 
			return emptyHtml; 
 
		var start=document.cookie.indexOf('order='); 
		var end=document.cookie.indexOf(';',start); 
		var order; 
		if(end<0) 
			order=document.cookie.substring(start+6); 
		else 
			order=document.cookie.substring(start+6,end); 
		// turn ^ chars back into ; chars: 
		order=replaceChar(order,'^',';'); 
		 
		var items = order.split('|'); 
		if(items.length<5) 
			return emptyHtml; 
		var subTotal=items[0]; 
		var delivery=items[1]; 
		var total=items[2]; 
//		var itemCount=items[3]; 
		numItems=items[3]; 
		 
//		numItems=0; 
		var html='<table class="orItems">'; 
		for(var i=4;i < items.length;i++) {  
			var itm = items[i].split(':');  
			html+='<tr><th><b>'+itm[1]+'</b>x</th><td>'+itm[0]+'</td></tr>'; 
//			numItems=numItems+parseInt(itm[1]); 
		} 
		html+='<tr><td colspan="2"><div class="dtd">&nbsp;</div></td></tr>';  
		html+='<tr><td colspan="2" align="right"><table>';   
		html+='<tr><td></td><th><small>(ex VAT)</small> <b>sub total</b>:</th><td><b>'+subTotal+'</b></td></tr>';   
		html+='<tr><td></td><th>delivery:</th><td>'+delivery+'</td></tr>';   
		html+='<tr><td></td><th><small>(inc VAT)</small> total:</th><td>'+total+'</td></tr>';   
		html+='</table></td></tr>';   
		html+='</table>';   
		html+='<p><a href="/e/Shopping.Cart" class="bsq">view/change your order</a>';   
		html+='<a href="'+siteSecRoot+'e/Shopping.CheckOut" class="bsq">purchase your order</a></p>';   
		return html; 
	} 
 
		var numItems=0; 
	  var orderRollerHtml=createOrderRollerHtml(); 
	// ------------------ 
	function showHelp(helpTopic)  
  {  
    var win = window.open(siteServRoot+'e/Page.Filler?_page=help/'+helpTopic,'_help','status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=yes, width=650, height=400');  
    win.focus();  
  }  
// ============================================== 
  function order(locator)  
  {  
    if(typeof(locator) == "undefined")  
      this.location=siteServRoot+'e/Shopping.Cart'; 
    else  
      this.location=siteServRoot+'e/Shopping.Cart?_action=add&p_surrogate='+locator; 
  }  
	// ------------------ 
  function orderVpn(vpn, vpn2, isTip) 
  { 
		if(typeof(isTip) != "undefined" && isTip=='true' && !confirm('WARNING: This power tip can only be used with the 2-Power branded, multi-tip devices shown on this page. Do you wish to continue ordering this power tip?')) 
		  return; 
 
    if(typeof(vpn) == "undefined") 
      this.location=siteServRoot+'e/Shopping.Cart'; 
		else if(typeof(vpn2) == "undefined" || vpn2=='-') 
      this.location=siteServRoot+'e/Shopping.Cart?_action=add&vpn='+vpn;	 
    else 
      this.location=siteServRoot+'e/Shopping.Cart?_action=add&vpn='+vpn+'&vpn2='+vpn2; 
  } 
// ============================================== 
		// show/hide a category on the navigation bar 
    var categories=new Object();		 
		 
		function showL1(catname) 
		{ 
			var el1=document.getElementById('l1-'+catname); 
			if(!categories['l1-'+catname]) 
				categories['l1-'+catname]=false; 
				 
			if(categories['l1-'+catname]) 
			{ 
				el1.style.height=0; 
				categories['l1-'+catname]=false; 
			} 
			else 
			{			 
				// close all the other open categories: 
				for(cat in categories) 
				{ 
					if(cat.substr(0,3)=='l1-' && categories[cat]) {					 
						var el2=document.getElementById(cat); 
						el2.style.height=0; 
						categories[cat]=false; 
					} 
				} 
 
				el1.style.height='auto'; 
				categories['l1-'+catname]=true;				 
			}				 
		} 
		 
// ============================================== 
	// Show/hide the drop down lists within a category 
  var catListVisible=new Object();	 
 
  function toggleCatList(cat,level) 
  { 
	  // close all the other lists in that category: 
		var divs=document.getElementsByTagName('div'); 
    for(var i=0;i<divs.length;i++)  
    {  
      var div=divs[i] 
			if(div.id && div.id.substr(0,cat.length+6)==cat+'-list-' && div.id!=cat+'-list-'+level) 
				displayCatList(cat,div.id.substr(cat.length+6),false); 
		} 
		// and display/hide the one we want: 
		displayCatList(cat,level,!catListVisible[cat+'-'+level]);		 
	} 
	 
	// ------------------ 
	function displayCatList(cat,level,showList) 
	{ 
		var listName=cat+'-'+level; 
		if(!catListVisible[listName]) 
			catListVisible[listName]=false;  // handle initially undefined level states. 
 
		if(catListVisible[listName]==showList) 
			return;  // nothing to do. 
			 
		var selDiv=document.getElementById(cat+'-sel-'+level); 
		var listDiv=document.getElementById(cat+'-list-'+level); 
		if(showList) 
		{ 
			listDiv.style.height='auto'; 
		} 
		else 
		{ 
			listDiv.style.height=0; 
 
			// rendering bug in Firefox2 leaves bottom list on screen sometimes, so force redraw of whole category div when hiding a list: 
			var catDiv=document.getElementById('l1-'+cat); 
			catDiv.innerHTML=catDiv.innerHTML; 
		} 
		catListVisible[listName]=showList; 
	} 
	 
// ============================================== 
// Show/hide products based on filters 
// this object is populated by script within each product block. 
var productProperties=new Object(); 
 
// these objects are populated by resetProductFilters() 
var productFilters=new Object(); 
productFilters['and']=new Object(); 
productFilters['or1']=new Object(); 
var productVisible = new Object(); 
 
	// ------------------ 
function resetProductFilters() 
{ 
  // reset all the filters and check boxes to their default states: 
  var ft=document.getElementById('filters'); 
  var ips=ft.getElementsByTagName('INPUT'); 
  for(var i=0; i<ips.length; i++) 
	{ 
  	var cb=ips[i];		 
    cb.checked=cb.defaultChecked; 
    var filterType=cb.id.substr(3,3); 
		var filterProperty=cb.id.substring(7); 
	  productFilters[filterType][filterProperty]=cb.checked; 
	} 
		 
	// mark all the products as visible: 
	var divs=document.getElementsByTagName('div'); 
  for(var i=0;i<divs.length;i++)  
  {  
    var div=divs[i] 
		if(div.id && div.id.substr(0,3)=='vp-') 
		  productVisible[div.id.substring(3)]=true; 
	}		 
		 
	// apply the default filters: 
	applyProductFilters(); 
} 
 
	// ------------------ 
function setProductCheckBox(td) 
{ 
  var cb=td.getElementsByTagName('INPUT')[0]; 
  var filterType=cb.id.substr(3,3); 
	var filterProperty=cb.id.substring(7); 
  setProductFilter(cb.id.substring(3),!productFilters[filterType][filterProperty]); 
} 
 
	// ------------------ 
function setProductFilter(filterName,newState)  
{ 
  var filterType=filterName.substr(0,3); 
	var filterProperty=filterName.substring(4); 
  productFilters[filterType][filterProperty]=newState; 
  var cb=document.getElementById('cb-'+filterName); 
	cb.checked=newState; 
	 
	// apply the current filters: 
  applyProductFilters(); 
} 
 
	// ------------------ 
// check the specified product meets the active filters. 
function matchesProductFilters(vpId) 
{ 
	var properties=productProperties[vpId]; 
 
	// check all the active AND filters are matched: 
	var matches=true; 
	for(var propertyName in productFilters['and']) 
	{ 
	  if(productFilters['and'][propertyName] && properties.indexOf('-'+propertyName)<0) 
			matches=false; 
	} 
	if(!matches) 
		return false; 
		 
	// check one of the active OR filters is matched: 
	for(var propertyName in productFilters['or1']) 
	{ 
	  if(productFilters['or1'][propertyName] && properties.indexOf('-'+propertyName)>-1) 
			return true; 
	}	 
	return false; 
} 
 
	// ------------------ 
function applyProductFilters() 
{ 
  // show or hide products based on active filter settings: 
	for(var vpId in productProperties) 
		displayProduct(vpId, matchesProductFilters(vpId)); 
} 
	// ------------------ 
function displayProduct(vpId,show) 
{ 
  if(productVisible[vpId]==show) 
	  return; 
 
	var prod=document.getElementById('vp-'+vpId); 
  var tile=document.getElementById('ti-'+vpId); 
  if(!show) 
  { 
    prod.style.height=0; 
		prod.style.marginBottom=0; 
    prod.style.visibility='hidden'; 
		if(tile) 
			tile.className='hidden'; 
  } 
  else 
  { 
    prod.style.height='auto'; 
		prod.style.marginBottom=''; 
    prod.style.visibility='visible'; 
		if(tile) 
			tile.className=''; 
 
		/* forces a redraw to fix ie7 bug which makes rolling over the category>mans list respond slowly after re-showing a filtered product */ 
		var tags=document.getElementsByTagName('BODY'); 
		var bod=tags[0]; 
		bod.innerHTML=bod.innerHTML; 		 
  } 
	productVisible[vpId]=show; 
} 
	// ------------------ 
function showProd(img) 
{ 
	var vpId=img.id.substring(3); 
	displayProduct(vpId,true); 
} 
 
// ============================================== 
	// show/hide enlarged product image 
	var prodImgRollerVisible=false; 
	var prodImgRollerSrc=''; 
		 
	function enlargeProdImg(enlink) 
	{ 
		var vpId=enlink.id.substring(3); 
		var img=document.getElementById('pi-'+vpId); 
		prodImgRollerShow(img,true); 
	}		 
	// ------------------ 
		function prodImgRollerShow(img,enlarge) 
		{ 
			if(prodImgRollerSrc=img.src) 
			{ 
				if(prodImgRollerHiding) 
					clearTimeout(prodImgRollerHiding); 
				else if(prodImgRollerVisible) 
					return;				 
			} 
			 
			var el1=document.getElementById('prodImgRoller'); 
			prodImgRollerSrc=img.src; 
			var vpId=img.id.substring(3); 
			var html=''; 
			if(enlarge) 
			{ 
				html+='<img src="'+img.src+'">'; 
				el1.innerHTML=html;			 
				el1.style.left=(img.offsetLeft+100)+'px'; 
				el1.style.top=(img.offsetTop+0)+'px';			 
			} 
			else 
			{ 
				if(!productVisible[vpId]) 
					html='<table class="alert"><tr><th><img src="/i/icons/alert.gif"></th><td><b>This product is currently hidden.</b><br>Change the \'Product Display Filter\' options on the left, or click on the thumnail image to display this product.</td></tr></table>'; 
				else 
					html='<p>Click on the thumbnail image to jump to this product.</p>'; 
 
				html+='<img src="'+img.src+'">'; 
				el1.innerHTML=html;			 
				el1.style.left=(img.offsetLeft+0)+'px'; 
				el1.style.top=(img.offsetTop+70)+'px'; 
			} 
 
			el1.style.visibility='visible'; 
		} 
	// ------------------ 
		function prodImgRollerHide() 
		{ 
			var el1=document.getElementById('prodImgRoller');		 
			prodImgRollerSrc=''; 
			el1.style.visibility='hidden'; 
			prodImgRollerVisible=false; 
		}		 
	// ------------------ 
		var prodImgRollerHiding=null;		 
		 
		function prodImgRollerOver() 
		{ 
			if(prodImgRollerHiding) 
				clearTimeout(prodImgRollerHiding); 
		}		 
	// ------------------ 
		function prodImgRollerOut() 
		{				 
			prodImgRollerHiding=setTimeout('prodImgRollerHide()',50);   
		}	 
 
// ============================================== 
		// Handle the product info tabs 
		var frontTabs= new Object(); 
 
		function pTab(clickedTab) 
		{ 
      var idx=clickedTab.id.lastIndexOf('-'); 
			var vpId=clickedTab.id.substr(idx+1); 
			if(!frontTabs[vpId]) 
				frontTabs[vpId]='x'; 
			frontTabId=frontTabs[vpId]; 
		 
			if(frontTabId==clickedTab.id) 
				return; 
 
			var tags=document.getElementsByTagName('div'); 
  	  for(var i=0;i<tags.length;i++)  
    	{  
      	var tab=tags[i]; 
				if(tab.id &&  
					tab.id.substr(0,4)=='tab-' &&  
					tab.id.length>vpId.length &&  
					tab.id.substring(tab.id.length-vpId.length)==vpId && 
					tab.id!=clickedTab.id) 
				{ 
					tab.className='backTab'; 
					var otherDiv=document.getElementById('div-'+tab.id); 
					otherDiv.className='hidnTab'; 
					// ie7 has odd bug which causes some of the old div (eg images in tables) to be left behind on the screen, force a redraw of hidden div to fix: 
					otherDiv.innerHTML=otherDiv.innerHTML; 
				} 
			} 
 
			var clickedDiv=document.getElementById('div-'+clickedTab.id); 
			clickedDiv.className=''; 
			clickedTab.className='frontTab'; 
			frontTabs[vpId]=clickedTab.id; 
			// similar ie7 redraw bug, requires a forced redraw here to display previously hidden tables: 
			clickedDiv.innerHTML=clickedDiv.innerHTML; 
		} 
 
// ============================================== 
	// Show or hide the left Navigation bar 
	var leftLB=0; 
	 
  function scrollLB() 
	{		 
		var lb=document.getElementById('leftbar'); 
		if(leftLB>-270) 
		{ 
			leftLB-=20; 
			lb.style.left=leftLB; 
			scrollingLB=setTimeout('scrollLB()',50); 
			return; 
		} 
		else if(leftLB<-280) //already been hidden once, so just hide completely now 
		{ 
			lb.style.left=-350;		 
		} 
		 
		var tags=document.getElementsByTagName('BODY'); 
		var bod=tags[0]; 
		bod.style.marginLeft='40px'; 
		var but2=document.getElementById('lbshow'); 
		but2.style.visibility='visible'; 
		leftLB=-350; 
		bod.innerHTML=bod.innerHTML; /* forces a redraw to fix ie7 bug which leaves images behind*/ 
	}	 
	// ------------------ 
	function hideLB() 
	{ 
		var but=document.getElementById('lbhide'); 
		but.style.visibility='hidden'; 
	 
		scrollingLB=setTimeout('scrollLB()',100);   
	} 
	// ------------------ 
	function showLB() 
	{ 
		var but=document.getElementById('lbshow'); 
		but.style.visibility='hidden';	 
		var tags=document.getElementsByTagName('BODY'); 
		var bod=tags[0]; 
		bod.style.marginLeft='';//316px; 
		var lb=document.getElementById('leftbar'); 
		lb.style.left=0;		 
		var but=document.getElementById('lbhide'); 
		but.style.visibility='visible';	 
		bod.innerHTML=bod.innerHTML; /* forces a redraw to fix ie7 bug which leaves images behind*/ 
	} 
// ============================================== 
  function showCountryList(start, selected)  
  {  
    document.writeln('<SELECT ' + start + '>');  
  
    var countries = [ 'GB','Reino Unido',
'AT','Austria',
'BE','Bélgica',
'CZ','República Checa',
'DK','Dinamarca',
'FI','Finlanda',
'FR','Francia',
'DE','Alemania',
'GR','Grecia',
'IE','Irlanda',
'IT','Italia',
'LU','Luxemburgo',
'NL','Holanda',
'NO','Noruega',
'PT','Portugal',
'SK','Eslovaquia',
'ES','España',
'SE','Suecia' ]; 
  
    for(var i = 0; i < countries.length; i = i+2)  
    {  
      var html = '<OPTION value="' + countries[i] + '"';  
      if(countries[i] == selected)  
        html += ' selected';  
      html += '>' + countries[i+1] + '</OPTION>';  
      document.writeln(html);  
    }  
    document.writeln('</SELECT>');  
  }  
// ==============================================  
  // check the email address is reasonable:  
 
  function checkEmail(email)  
  {  
    if(!isValidEmail(email))  
    {  
      alert('La direcci\u00f3n de email es inv\u00e1lida.\n Debe ser similar a:\n\n yourname@yourcompany.com\n\nSin espacios. Por favor vuelva a intentar.');  
      return false;  
    }  
    return true;  
  }  
  //-------------------------------------------   
  // check the email address is reasonable:  
  
  function isValidEmail(email)  
  {  
    if(isblank(email))  
      return false;  
  
    email = email.toLowerCase();  
  
    //  check for one '@':  
    var sections = email.split('@');  
    if(sections.length != 2)  
      return false;  
  
    // now split into sections on '.':  
    var username = sections[0].split('.');  
    var domain = sections[1].split('.');  
    if(domain.length < 2)  
      return false;  
  
    // check the username:  
    for(var i = 0; i < username.length; i++)  
      if(!isValidEmailSection(username[i]))  
        return false;  
  
    // check the domain:  
    for(var i = 0; i < domain.length; i++)  
      if(!isValidEmailSection(domain[i]))  
        return false;  
  
    return true;  
  }  
  //-------------------------------------------   
  // check this section of an email address is valid  
  // a-z 0-9 - . _  
  
  function isValidEmailSection(sec)  
  {  
    if(sec.length < 1)  
      return false;  
  
    for(var i = 0; i < sec.length; i++)  
    {  
      var cc = sec.charCodeAt(i);  
      if( ((cc < 97) || (cc > 122)) &&  
          ((cc < 48) || (cc > 57)) &&  
          ((cc < 45) || (cc > 46)) &&  
          (cc != 95) )  
  	  return false;  
    }  
    return true;  
  }  
  //-------------------------------------------   
  // check there is a value:  
  
  function isblank(str)  
  {  
    for(var i = 0; i < str.length; i++)  
    {  
      var ch = str.charAt(i);  
      if((ch != ' ') && (ch != '\n') && (ch != '\t'))  
        return false;  
    }  
    return true;  
  }  
  //------------------------------------------- 
	function replaceChar(text,findChar, replaceChar) 
	{ 
		var op='';	 
	  for(var cur = 0; cur<text.length; cur++) 
  	{ 
    	var ch = text.charAt(cur); 
	    if(ch == findChar) 
				op+=replaceChar; 
			else 
      	op+=ch; 
	  } 
  	return op; 
	} 
  //------------------------------------------- 
		// To match the pre-processed search table in the database, 
		// any char which is not 0-9,a-z or space, should be replaced with dash, and spaces should be replaced with commas. 
		// also keep a count of the length of each search term, ignore if too short, or ensure at least one search term is long enough. 
		function checkSearch(formName)  
		{ 
			var f=document.forms[formName]; 
			var ip=f.elements.searchtext.value.toLowerCase(); 
			 
			// see if it's a VPN: 
			if(ip.length==9 && ip.substr(0,3)=='vp-') 
			{ 
				this.location='/pno/vpnlink.html?vpn='+ip.substr(3,6); 
				return false;	   
			} 
			 
			// no, so get the search terms: 
			var minKeywordLength=3; 
			var longestKeyword=0; 
			var keyword=''; 
			var searchTerms=''; 
	    for(var i = 0; i < ip.length; i++)  
  	  {  
    	  var ch = ip.charAt(i);  
      	if( ((ch >= 'a') && (ch <= 'z')) || ((ch >= '0') && (ch <= '9')) || (ch == '_') ) 
				{ 
					keyword+=ch; 
				} 
				else if(ch == ' ' || ch==',') 
				{ 
				  if(keyword.length>0) 
					{ 
						// keywords can not end with a dash: 
						if(keyword.charAt(keyword.length-1)=='-') 
							keyword=keyword.substring(0,keyword.length-1); 
						// check keyword is longer than the minimum required, and record if it is the longest so far: 
						if(keyword.length>=minKeywordLength) 
						{ 
							searchTerms+=keyword+','; 
							if(keyword.length>longestKeyword) 
								longestKeyword=keyword.length; 
						} 
						keyword=''; 
					} 
				} 
				else 
				{ 
					// keywords can not start with a dash 
					// multiple unwanted chars are collapsed and replaced with only one dash: 
					if(keyword.length>0 && keyword.charAt(keyword.length-1)!='-') 
						keyword+='-'; 
				} 
	    }  
			// see if we ended with a new keyword still open: 
		  if(keyword.length>0) 
			{ 
				// keywords can not end with a dash: 
				if(keyword.charAt(keyword.length-1)=='-') 
					keyword=keyword.substring(0,keyword.length-1); 
				// check keyword is longer than the minimum required, and record if it is the longest so far: 
				if(keyword.length>=minKeywordLength) 
				{ 
					searchTerms+=keyword+','; 
					if(keyword.length>longestKeyword) 
						longestKeyword=keyword.length; 
				} 
			} 
						 
			// warn if search terms are too short? 
			if(longestKeyword<1) 
			{ 
				f.elements.search.value=''; 
				alert('Search terms are missing or too short.'); 
				return; 
			} 
			f.elements.search.value=searchTerms; 
			var http_idx = f.action.indexOf(':'); 
			if(http_idx>0)  
                        	f.action='http'+f.action.substring(http_idx); 
                        else 
				f.action='http://'+location.hostname+f.action.substring(http_idx); 
			var idx = f.action.indexOf('?'); 
			if(idx>-1) 
				f.action=f.action.substring(0,idx)+'?q='+escape(f.elements.searchtext.value); 
			else 
				f.action=f.action+'?q='+escape(f.elements.searchtext.value); 
			f.submit(); 
		} 
  //-------------------------------------------  
 
	function doSearch(formName) 
		{ 
			if(checkSearch(formName)) 
				document.forms[formName].submit(); 
		} 
  //-------------------------------------------  
 
  function showYearList(start, selected, full)  
  {  
//    var currentYear = 2004;   
    var currentYear = (new Date()).getFullYear();  
  
    document.writeln('<SELECT ' + start + '>');  
    var maxYear = currentYear + 10;  
    if(full)  
    {  
      maxYear = currentYear + 1;  
      currentYear = currentYear - 5;  
      if(selected == ' ')  
        document.writeln('<OPTION value=" " selected> </OPTION>');  
      else  
        document.writeln('<OPTION value=" "> </OPTION>');  
    }  
  
    for(var i = currentYear; i < maxYear; i++)  
    {  
      var html = '<OPTION value="' + i + '"';  
      if(i == selected)  
        html += ' selected';  
      html += '>' + i + '</OPTION>';  
      document.writeln(html);  
    }  
    document.writeln('</SELECT>');  
  }  
  //-------------------------------------------   
  
  function showMonthList(start, selected, full)  
  {  
    document.writeln('<SELECT ' + start + '>');  
  
    var list = [' ',' ', '01','01', '02','02', '03','03', '04','04', '05','05', '06','06', '07','07', '08','08', '09','09', '10','10', '11','11', '12','12'];  
    var start = 2;  
    var end = list.length -2;  
    if(full)  
      start = start - 2;  
  
    for(var i = start; i <= end; i = i+2)  
    {  
      var html = '<OPTION value="' + list[i] + '"';  
      if(list[i] == selected)  
        html += ' selected';  
      html += '>' + list[i+1] + '</OPTION>';  
      document.writeln(html);  
    }  
    document.writeln('</SELECT>');  
  }  
 
  //-------------------------------------------    
  function validCardNo(val, min, max)  
  {  
    var count = 0;  
    for(var i = 0; i < val.length; i++)  
    {  
      var ch = val.charAt(i);  
      if((ch == '0') || (ch == '1')|| (ch == '2') || (ch == '3') || (ch == '4') ||   
         (ch == '5') || (ch == '6') || (ch == '7') || (ch == '8') || (ch == '9'))  
        count++;  
      else if(ch != ' ')  
        return false;  
    }  
  
    if((count.valueOf() < min) || ((count.valueOf() > max) && (max > -1)))  
      return false;  
  
    return true;  
  }  
  //-------------------------------------------    
	 function lookupPno(id) 
	 { 
	 		var prodDiv=document.getElementById('vp-'+id); 
	 		var pnoDiv=document.getElementById('pnoLookup'); 
			pnoDiv.innerHTML='<table class="titlebar"><tr><th><h1>Looking up Part Number</h1></th><td><a href="javascript:closePnoLookup();"><img src="/i/icons/closewin.gif"></a></td></tr></table><iframe src="/info/pnolookup.html?vpn='+id+'"></iframe>'; 
			var left=prodDiv.offsetLeft-250; 
			if(left<0) 
				left=50; 
			pnoDiv.style.top=(prodDiv.offsetTop-50)+'px'; 
			pnoDiv.style.left=left+'px'; 
			pnoDiv.style.visibility='visible'; 
	 } 
  //-------------------------------------------    
	 function closePnoLookup() 
	 { 
	 		var pnoDiv=document.getElementById('pnoLookup'); 
			pnoDiv.style.visibility='hidden';	 		 
	 } 
 
// ============================================== 
  // function call, embedded within notes etc in the database:  
  
  function pl(linkOb, linkValue)  
  {  
    if(linkValue) 
      linkOb.href=siteLinkRoot + 'pno/plink.html?ps=' + linkValue;    
  } 
//-------------------------------------------   

