/*
JavaScript functions for Tcat
*/

function SelObj(formname,selname,textname,str) {
this.formname = formname;
this.selname = selname;
this.textname = textname;
this.select_str = str || '';
this.selectArr = new Array();
this.initialize = initialize;
this.bldInitial = bldInitial;
this.bldUpdate = bldUpdate;
}

function initialize() {
if (this.select_str =='') {
for(var i=0;i<document.forms[this.formname][this.selname].options.length;i++) {
this.selectArr[i] = document.forms[this.formname][this.selname].options[i];
this.select_str += document.forms[this.formname][this.selname].options[i].value+":"+
document.forms[this.formname][this.selname].options[i].text+",";
   }
}
else {
var tempArr = this.select_str.split(',');
for(var i=0;i<tempArr.length;i++) {
var prop = tempArr[i].split(':');
this.selectArr[i] = new Option(prop[1],prop[0]);
   }
}
return;
}
function bldInitial() {
this.initialize();
for(var i=0;i<this.selectArr.length;i++)
document.forms[this.formname][this.selname].options[i] = this.selectArr[i];
document.forms[this.formname][this.selname].options.length = this.selectArr.length;
return;
}

function bldUpdate() {
var str = document.forms[this.formname][this.textname].value.replace('^\\s*','');
if(str == '') {this.bldInitial();return;}
this.initialize();
var j = 0;
pattern1 = new RegExp("^"+str,"i");
for(var i=0;i<this.selectArr.length;i++)
if(pattern1.test(this.selectArr[i].text)) 
document.forms[this.formname][this.selname].options[j++] = this.selectArr[i];
document.forms[this.formname][this.selname].options.length = j;
if(j==1){
document.forms[this.formname][this.selname].options[0].selected = true;
//document.forms[this.formname][this.textname].value = document.forms[this.formname][this.selname].options[0].text;
   }
}
function setUp() {
obj1 = new SelObj('menuform','itemlist','entry');
// menuform is the name of the form you use
// itemlist is the name of the select pulldown menu you use
// entry is the name of text box you use for typing in
obj1.bldInitial(); 
}




var checkflag = "false";
var quantity = 0;

function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
return "None"; }
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
return "All"; }
}

function formClick(form){
var stryr = form + "="
var veh = "ecveh.asp?iyear="
var URL = document.form.site.options[document.form.site.selectedIndex].value; 
var sURL = stryr + URL
alert (sURL)
//  alert (stryr)
// window.location.href = sURL;
}

function formHandler(form){
var stryr = form + "="
var veh = "ecveh.asp?iyear="
var URL = document.form.site.options[document.form.site.selectedIndex].value; 
var sURL = "shopdisplaycategories.asp" + stryr + URL
// alert (sURL)
//  alert (stryr)
window.location.href = sURL;
}

function goToURL(url) { window.location = url; }

function topWindow(popupwin){
window.open(popupwin,"","top=50,left=50,height=500,width=300,resizable,scrollbars");
}

function HelpWin(popupwin){
window.open(popupwin,"helpwin","top=50,left=50,height=700,width=400,resizable,scrollbars");
}

function CustWin(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function xxsetQty(oLink, which) {
	var qty = document.formname['quantity'+which].value;
	var part = document.formname['partnum'+which].value;
	alert(part);
	oLink.href += (qty) ? '&quantity=' + qty : '&quantity=1';
	return true;
	}
	
function setQty(oLink, which) {
	var qty = document.formname['quantity'+which].value;
	var part = document.formname['partID'+which].value;
	//alert('part=' + part + ' - qty=' + qty + ' - which=' + which);
	oLink.href += (qty) ? '&quantity=' + qty : '&quantity=1';
	return true;
	}
	
function setQtySingle(oLink, which) {
	var qty = document.formname['quantity'+which].value;
	var part = document.formname['partID'+which].value;
	//alert('part=' + part + ' - qty=' + qty + ' - which=' + which);
	oLink.href += (qty) ? '&quantity=' + qty : '&quantity=1';
	return true;
	}

function xxcheckAll(k) {
for (var j = 0; j <= k-1; j++) {
box = eval("document.formname.Partnum" + j); 
if (box.checked == false) box.checked = true;
   }  
alert ('j=' + j);
}

function checkAllc(f) {
var el, i = 0;
while (el = f.elements[i++])
if (el.type == 'checkbox' && el.name.indexOf('ipdmulti') != -1) el.checked = true;
}

function uncheckAllc(f) {
var el, i = 0;
while (el = f.elements[i++])
if (el.type == 'checkbox' && el.name.indexOf('ipdmulti') != -1) el.checked = false;
}

function checkAll(f) {
var el, i = 0;
while (el = f.elements[i++])
if (el.type == 'checkbox' && el.name.indexOf('Partnum') != -1) el.checked = true;
}

function uncheckAll(f) {
var el, i = 0;
while (el = f.elements[i++])
if (el.type == 'checkbox' && el.name.indexOf('Partnum') != -1) el.checked = false;
}

function chkChg(oTextbox) {
var bWhich = (oTextbox.value != '');
var el, i = 0, f = oTextbox.form;
while (el = f.elements[i++]) if (el == oTextbox) f.elements[i].checked = bWhich;
}

function win400x(webpage,h,w) {
var strPage = webpage;
alert (strPage + " " + h + " " + w);
win = window.open(strPage,"poppic","height=h,width=w,scrollbars=yes,resizable=yes,left=50,top=50");
win.focus();
}

function win400(webpage,h,w) {
window.open(webpage,"mypage","height=584,width=700,scrollbars=yes,resizable=yes,left=10,top=10");
}

function win2(webpage) {
// window.close("largeimage");
winsmall=window.open(webpage,"partimage","height=335,width=330,scrollbars=yes,resizable=yes,left=10,top=10");
}

function win2cc(webpage,winheight) {
// window.close("largeimage");
winsmall=window.open(webpage,"partimage","height=" + winheight + ",width=330,scrollbars=yes,resizable=yes,left=10,top=10");
}

function win2rp(webpage,winheight) {
// window.close("largeimage");
winsmall=window.open(webpage,"partimage","height=" + winheight + ",width=330,scrollbars=yes,resizable=yes,left=10,top=10");
}

function win2a(webpage) {
//  window.winsmall.close();
window.close("smallimage");
winlarge=window.open(webpage,"","height=700,width=700,scrollbars=yes,resizable=yes,left=10,top=10");
}

function winswap(webpage) {
if (winsmall.closed){
   winsmall=window.open(webpage,"","height=315,width=330,scrollbars=yes,resizable=yes,left=10,top=10");
   }

window.open(webpage,"largeimage","height=700,width=700,scrollbars=yes,resizable=yes,left=10,top=10");
}

function go(loc) {
var strGo = "ecveh.asp?redosome=" + loc
//alert(strGo);
window.location.href = strGo;
}

function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=500,height=600,scrollbars=yes');
return false;
}

function firstFocus()
{
   if (document.forms.length > 0)
   {
      var TForm = document.forms[0];
      for (i=0;i<TForm.length;i++)
      {
         if ((TForm.elements[i].type=="text")||
           (TForm.elements[i].type=="textarea")||
           (TForm.elements[i].type.toString().charAt(0)=="s"))
         {
            document.forms[0].elements[i].focus();
            break;
         }
      }
   }
}


/* end of tcat_jscript.js */
