/*
	s3pin.js
	enhanced user search experience for pinnacle
	4/23/08 arb Xartech.com
*/

var esearch = {
misBlank: 1, elm: 0, elmdd: 0, checkmode: function(sel) { var tval = this.getddval(sel); switch(tval) { case "-mode2":
case "--mode2": esearch.setmode2(""); break; case "-listbrands": case "--listbrands": 

//handle frames and no-frames situations
if (top==self) 
        location = "http://www.pinnaclemicro.com/newcart/brandlist.php";
else
        top.frames[1].location = "/newcart/brandlist.php?frame";

break; case "-": break; default: this.setmode2blank(); document.getElementById("txtS").focus(); } }, setmode2: 
function(txt) { document.getElementById("ddLabel").innerHTML = "Brand:"; var pos = 
esearch.cumulativeOffset(esearch.elmdd); (1+pos[0]) + "px"; this.elm.style.top = (1+pos[0]) + "px"; 
this.elm.style.left= (1+pos[1]) + "px"; this.elm.value = txt; this.elm.style.display = ""; this.elm.focus();
if (this.shim) { this.shim.style.top = (1+pos[0]) + "px"; this.shim.style.left= (1+pos[1]) + "px";
this.shim.style.display=""; } }, setmode2blank: function() { m=this.elm; esearch.misBlank = 1;
m.value=""; m.style.display="none"; if (this.shim) this.shim.style.display="none";
document.getElementById("ddLabel").innerHTML = "Search:"; }, 
setall: function(vsearch, vbrand, vtype,vsmartc) {
document.getElementById('txtS').value = vsearch; this.setdd(document.getElementById('ddBrand'), vbrand);
this.setdd(document.getElementById('ddType'), vtype); 
this.setdd(document.getElementById('ddC'), vsmartc);
document.getElementById('txtS').focus(); 

                var c=this.getcookieo().refhist;
                for(var i=document.forms.length-1;i>0;i--){
                        var frm=document.forms[i];
                        if (frm.refhist) frm.refhist.value=c;
                }
},

getddval: function(sel) { if (sel.value) return sel.value; if (sel[sel.selectedIndex]) return 
sel[sel.selectedIndex].innerHTML; }, setdd: function(sel, val) { if (val=="" || val=="-") { sel.selectedIndex = 0;
sel.focus(); return; } var z=sel.length; for(i=0; i<z; i++) { if (sel[i].value != "") { if (val==sel[i].value) {
sel.selectedIndex = i; return; } } else if (sel[i].innerHTML == val) { sel.selectedIndex = i; return; } }
var temp = new Option(val); sel[z] = temp; sel.selectedIndex = z; }, listen: function(element, name, handler) {
if (element.addEventListener) element.addEventListener(name, handler, false); else if (element.attachEvent) 
element.attachEvent('on' + name, handler); }, presend: function() { if (this.misBlank) 
document.getElementById("txtM").value = ""; return true; }, 

showSearchHelp: function(rf,qf){if(!jQuery)return;if(rf=="")return;if($('#landingsearch').length==
0)$('<div id="landingsearch"></div>').prependTo("body");$('#landingsearch').load(
'/newcart/landingsearch.php',{r:rf});},

saveref:function(){var temp;var friends=" ezsystems.com pinnaclemicro.com pinnaclemicrogb.co.uk";
temp=document.referrer.match(/^\w+:\/\/(www.|)([\w.]+)/);if(temp!=null&&friends.indexOf(temp[2])>0)
return;this.refpush(document.referrer||"-");this.showSearchHelp(document.referrer);},

getcookieo:function(){var obj,list,i,temp;obj={};list=document.cookie.split(/; */);for(i in list){
temp=list[i].split(/=/);if(temp.length==2)obj[unescape(temp[0])]=unescape(temp[1]);}return obj;},

refpush:function(loc){var c,hist,ehist,stamp,now,dl;dl=document.location;if(dl.protocol=="https:"
)return;loc=loc+" ->"+dl.pathname+dl.search;now=new Date();stamp="\\\\"+(100*(now.getMonth()+1)+
now.getDate())+" "+loc;c=this.getcookieo();if(c.refhist&&c.refhist.length>1){hist=c.refhist;if(
stamp!=hist.substr(0,stamp.length))hist=stamp+hist;}else hist=stamp;if(hist.length>3000)hist=
hist.substr(0,3000);this.setcookie("refhist",hist,30);return ehist;},


setcookie:function(name,val,days){
var cescape=function(v){return v.replace(/%/g,"%25").replace(/=/g,"%3D").replace(/;/g,"%3B")};
var cook=escape(name) + "=" + cescape(val);var today=new Date();var expire=new Date();if(days>0){
expire.setTime(today.getTime()+3600000*24*days);cook+="; expires="+expire.toGMTString();}document
.cookie=cook+"; path=/";},


start: function() { this.saveref(); document.getElementById("txtS").focus();
document.getElementById("txtS").select(); this.elm = document.getElementById("txtM"); var frm = document.forms['s3form'];
if (frm) this.listen(frm, 'submit', function() { if (esearch.misBlank) esearch.elm.value=""; }); var bdd= 
document.getElementById("ddBrand"); this.elmdd = bdd; if (navigator.userAgent.indexOf("MSIE 6")>1) {
this.shim = document.createElement( 'iframe' ); this.shim.setAttribute( 'src', "javascript:''" );
this.shim.setAttribute( 'frameBorder', '0' ); this.shim.setAttribute( 'frameBorder', '0' );
this.shim.style.position = "absolute"; this.shim.style.width = "160px"; this.shim.style.height = "20px";
this.shim.style.display = "none"; this.shim.style.zIndex= "9"; this.shim.scrolling = "no";
bdd.parentNode.insertBefore(this.shim, bdd); this.elm.style.border = "1px white"; }
var m = this.elm; this.setmode2blank(m); this.listen(m, "focus", function() { if (esearch.misBlank) {
m.value=""; m.style.color = ""; esearch.misBlank=0; } }); this.listen(m,'blur', function() { if (m.value=="") {
esearch.setmode2blank(m); esearch.elmdd.selectedIndex = 0; } }); this.listen(bdd, "focus", function() {
if (m.value=="") { esearch.setmode2blank(m); } if (esearch.getddval(esearch.elmdd).charAt(0) == "-") bdd.selectedIndex = 0;
}); }, cumulativeOffset: function(element) { var vtop = vleft = 0; var el = element; do { vtop += el.offsetTop  || 0;
vleft += el.offsetLeft || 0; el= el.offsetParent; } while (el); return [vtop, vleft]; } };


document.write(
'<font face="Arial" size="2">&nbsp;<span id=ddLabel>Search: 2,000,000+ Models</span></font>&nbsp;',"\n",
'<input id=txtM name=m style="font-size:13px; width:160px; height:20px; border: 1px white;',
'position:absolute;color:#505080;background:#FFFFF0;z-index:10">',"\n",
'<select id=ddBrand name=brand style="font-size:13px;width:180px;height:20px" onchange="esearch.checkmode(this)">',"\n",
'<option value="-">All Brands</option>',"\n",
'<option value="-mode2" style="color:#505080;background:#FFFFF0">Enter Brand Name</option>',"\n",
'<option value="-listbrands" style="color:blue;text-decoration:underline;">More Brands...</option>',"\n"
);

brandslist();

document.write(
'<option value="--mode2" style="color:#808080;background:#FFFFF0">Enter Brand Name</option>',"\n",
'<option value="--listbrands" style="color:blue;text-decoration:underline;">More Brands...</option>',"\n",
'<option value="--">All Brands</option>',"\n",
'</select>',"\n",
'',"\n",
'<select id=ddType name="stype" style="width:92px;height:20px;font-size: 13px">',"\n",
'<option value="P">Part/Model</option>',"\n",
'<option value="K">Keyword(s)</option>',"\n",
'</select>',"\n",
'',"\n",
'<input id=txtS type="text" name="s" value="" style="width:180px; font-size: 13px">',"\n",
'<select id="ddC" name="smartc"><option value="">All Conditions</option><option value="ref">Refurbished</option><option value="new">New</option><option value="rep">Repair</option></select>',
' &nbsp; <input type="submit" value="Search">',
' &nbsp; <a href="http://www.pinnaclemicro.com/computer/advanced.php" style="font:13px Arial">Advanced</a>',"\n",
'&nbsp; &nbsp; <a href="http://www.pinnaclemicro.com/newcart/converter.php" style="font:13px Arial">&pound; &yen &euro; $</a>'
);

esearch.start();


function brandslist() {
	var temp, i;
	temp = '3Com, ACER, ACP MEMORY, Adaptec, ALCATEL, AMD, APC American Power, Apple Computer, ASUS TEK, ATI TECHNOLOGIES, AT&T, Avaya, AXIOM MEMORY, Belkin, BROTHER, CA Computer Ass, CABLES TO GO, CANON, CISCO Systems, Citoh, Compaq, DA-LITE, DATAPRODUCTS, DEC Digital Equipment, Decision Data, Dell, Digi International, EMC, ERICSSON, EXTREME NETWORKS, FORTINET, FUTURE MEMORY, Gateway, Genicom, HITACHI America, HP Hewlett Packard, IBM, Intel Corporation, INTERMEC, Juniper Networks, Kaspersky Lab, KENTROX, KINGSTON TECH, KONICA MINOLTA, LENMAR, LENOVO, Lexmark, LUCENT TECH, MCAFEE, Microsoft, Motorola, NCR, NEC AMERICA, Nortel, OKIDATA, Oracle Corporation, Panasonic, PLANTRONICS, Polycom, PREMIUM POWER, Printronix, Quantum, Ricoh, RSA, SAMSUNG, Seagate Technology, Sharp Electronics, SIEMENS, SONICWALL, Sony, STARTECH, Sun Microsystems, SUPERMICRO, SYMANTEC, SYMBOL TECHNOLOGIES, TALLY GENICOM, Texas Instruments, TOSHIBA, TRIPP LITE, WDC Western Digital, Xerox, ZEBRA TECHNOLOGIES';
	temp = temp.split(/,\s*/);
	for(i=0;i<temp.length;i++) {
		document.write("<option>" + temp[i] + "</option>\n");
	}
}

