var xmlHttp
var divctl
var failform

function copyctl(fr,to) {
  to.value=fr.value
}

function chksame() {
  ctl=eval(document.formchkout.shipsame)
  if ( ctl.checked == false) {
    ctl.checked = true
    sameaddr()
  } else {
    ctl.checked = false
  }
}

function sameaddr() {
  frm=eval(document.formchkout)
  if (frm.shipsame.value=='1') {    
    copyctl(frm.billfirst,frm.shipfirst)
    copyctl(frm.billlast,frm.shiplast)
    copyctl(frm.billadd1,frm.shipadd1)
    copyctl(frm.billadd2,frm.shipadd2)
    copyctl(frm.billadd3,frm.shipadd3)
    copyctl(frm.billcity,frm.shipcity)
    //copyctl(frm.billstate,frm.shipstate)
    document.getElementById("ShipDropDown").value = frm.billstate.value
    copyctl(frm.billzip,frm.shipzip)
    copyctl(frm.billphone,frm.shipphone)
  }
}
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}
// 10-7 bak
function updbask() {
  document.formbask.prog.value='viewbask';
  document.formbask.pend.value='updbask';
  document.formbask.pendovr.value='Y';
  document.formbask.submit();
  }

  
function chkQty(ele) {
  if (ele.value == 0) {
    //var theId = ele.id.match(/\d+/);
	var theId = (ele.id.match(/\d+/) == null)? "" : ele.id.match(/\d+/);
    document.getElementById('dgrp' + theId).checked = true;
	}
 
    if (isNaN(ele.value)) {
	var theId = (ele.id.match(/\d+/) == null)? "" : ele.id.match(/\d+/);
	//var theId = ele.id.match(/\d+/);
	alert('that quantity is not a number');
	document.getElementById('qty' + ele.id.match(/\d+/)).value = '1';
	//alert(document.getElementById('qty' + theID).value);
  }
    if (ele.value < 0){
	alert("quantity can't be a negative number");
	document.getElementById('qty' + ele.id.match(/\d+/)).value = '1';
	}
}

/*
  function updbask() {

 rows=document.getElementById('formbask').getElementsByTagName("TR");
   for (var j=0; j<rows.length; j++)  {
    
    cells=rows[j].getElementsByTagName("TD");
    for (var i=0; i<cells.length; i++)  {
	
	if (document.formbask.dgrp.checked) 
	{
	//alert('removed. Thank you');
	
	//ffox looops this
    document.formbask.prog.value='viewbask';
    document.formbask.pend.value='updbask';
    document.formbask.pendovr.value='Y';
    document.formbask.submit();
    window.stop();
	}
	//else
	//{
	//if(cells[i].innerHTML == '<INPUT class=inpC3 value=0 name=qty> '
	// ||cells[i].innerHTML == '<input class="inpC3" name="qty" value="0" type="text">')
	/*
	if(document.formbask[i].value == '0'
	 || cells[i].innerHTML == '<INPUT class=inpC3 value=0 name=qty> ')
	//if (document.formbask[i].type.match(/text/i) && document.formbask[i].value == '0')
	{
	//alert(cells[i].innerHTML);
	alert('the quantity is zero at line ' + j + ' ! Please check where it says remove and update basket again');
	window.stop();
	}
	////////////////////////////////
	//}
    } 
}

  document.formbask.prog.value='viewbask';
  document.formbask.pend.value='updbask';
  document.formbask.pendovr.value='Y';
  document.formbask.submit();
}
*/



//function lineiChkBoxClick() {
	//if(document.formbask.dgrp.checked {
	
//}

function selcolr(colrid,blok,bloks,typ,sku) {
  var colrtext=document.getElementById('colrdesc' + blok).innerHTML
  document.formitem.prog.value='showitem';
  document.formitem.stylcolr.value=colrid;
  document.formitem.stylsize.value='';
  document.formitem.colrdesc.value=colrtext;
  document.formitem.stokid.value='';
  document.getElementById('colrtxt1').innerHTML=colrtext;
  document.getElementById('colrtxt2').innerHTML=colrtext;
  switch (typ) {
    case '_cs':
      callajax("go.asp?url=none&prog=popsizes&pend=&lastprog=&stylsize=&bestprc=&stylcolr=" + colrid,'divsizes',formitem)
      document.getElementById('sizetxt1').innerHTML="<span style='color: red; font-weight: normal'>choose below</span>";
      document.getElementById('sizetxt2').innerHTML='';
      break
    case '_c':
      callajax("go.asp?url=none&prog=bestprc&pend=bestprc&lastprog=&stylcolr=" + colrid + '&stokid=' + sku + '&qtyordered=' + document.formitem.qtyordered.value,'divprice',formitem)
      document.formitem.stokid.value=sku;
      break
  }

  for (i=0; i<bloks; i++) {
   setbord('ctbl' + i,'False')
  }
  setbord('ctbl' + blok,'True')
}

function selsize(sizeid,blok,bloks,sku) {
  document.formitem.prog.value='showitem';
  document.formitem.pend.value='bestprc';
  document.formitem.stylsize.value=sizeid;
  document.formitem.sizedesc.value=sizeid;
  document.formitem.stokid.value=sku;
  document.getElementById('sizetxt1').innerHTML=sizeid;
  document.getElementById('sizetxt2').innerHTML=sizeid;
  callajax("go.asp?url=none&prog=bestprc&pend=bestprc&lastprog=&stylsize=" + sizeid + '&stokid=' + sku + '&qtyordered=' + document.formitem.qtyordered.value,'divprice',formitem)

  for (i=0; i<bloks; i++) {
    setbord('stbl' + i,'False')
  }
  setbord('stbl' + blok,'True')
}


function setbord(ctl,val) {
  switch (val) {
    case 'True':
      document.getElementById(ctl).style.borderColor="#cccccc";
      document.getElementById(ctl).style.borderWidth="2px";
      document.getElementById(ctl).style.borderStyle="solid";
      break
    case 'False':
      document.getElementById(ctl).style.borderColor="#ffffff";
      document.getElementById(ctl).style.borderWidth="2px";
      document.getElementById(ctl).style.borderStyle="solid";
  }
}

function callajax(url,ctl,frm) {
  divctl=ctl
  failform=frm

  //un-rem out following 2 lines to disable ajax
  //failform.submit();
  //return false;
  //window.location=url
  url=url + "&st=" + new Date().getTime() + '&nocache=' + Math.random()
  xmlHttp=GetXmlHttpObject(stateChanged)
  xmlHttp.open("GET", url , false)
  xmlHttp.send(null)
}

function stateChanged() { 
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
    if (xmlHttp.responseText != '') {
      document.getElementById(divctl).innerHTML=xmlHttp.responseText
      document.getElementById(divctl).style.display='block';
    }
  } 
} 

function GetXmlHttpObject(handler) { 
  var objXmlHttp=null
  if (navigator.userAgent.indexOf("Opera")>=0) {
    failform.submit();
    return 
  }
  if (navigator.userAgent.indexOf("MSIE")>=0) { 
    var strName="Msxml2.XMLHTTP"
    if (navigator.appVersion.indexOf("MSIE 5.5")>=0) {
      strName="Microsoft.XMLHTTP"
    } try { 
      objXmlHttp=new ActiveXObject(strName)
      objXmlHttp.onreadystatechange=handler 
      return objXmlHttp
    } 
      catch(e) { 
      //error-even if a supposedly valid xmlhttp object is available for user's                       //browser, some other error ocurred, so submit the failform instead...  
      failform.submit();
      return 
    } 
  } 
  if (navigator.userAgent.indexOf("Mozilla")>=0) {
    objXmlHttp=new XMLHttpRequest()
    objXmlHttp.onload=handler
    objXmlHttp.onerror=handler 
    return objXmlHttp
  }
}

function setrow(row,tdcnt,bgcol,fgcol) {
  document.getElementById('tr' + row).style.backgroundColor=bgcol
  for (i=0;i<tdcnt;i++) {
    document.getElementById('td' + i + row).style.color=fgcol
  }
}

function additem(colrsize, related) {
  if (related > 0) document.formitem.prog.value='relitems';
    else document.formitem.prog.value='viewbask';
  if (document.formitem.embroid) if (document.formitem.embroid.checked == 1) document.formitem.prog.value='embopts';

  if (document.formitem.stylcolr.value=='' && colrsize=='_cs') {
    alert("Please select a valid color to continue.");
  } else if (document.formitem.stylsize.value=='' && (colrsize=='_cs' || colrsize=='_s')) { 
    alert("Please select a valid size to continue.");
  } else if (document.formitem.stokid.value=='') { 
    alert("This item is currently unavailable. We apologize for the inconvenience.");
  } else {
    document.formitem.pend.value='additem'
    document.formitem.submit()
  }
}

//END LIFEUNIFORM SCRIPT

// ** Standard internal functions [ left, right, toNum, round, incl, excl, 



function closewin() { window.close(); }

function cr() { if(event.keyCode==13) event.keyCode=9; }

function w2tof1(xctl,xval,xctl2,xval2) {
	ctl = eval("opener.document.form1." + xctl);
	ctl2 = eval("opener.document.form1." + xctl2);
	ctl.value=xval;
	ctl2.value=xval2;
	window.close(); }

function mag1(prog,ctl1,ctl2,x,y) {
	hwnd = window.open ('go.asp?url=rslt&rsltid=' +prog + '&ctl1=' +ctl1 + '&ctl2=' +ctl2,
	'popup','width=150,height=100,left=' + x + ',top=' + y + ',scrollbars=yes,status=yes'); void('');}


function yesno(src) {
  ctl = retobj(src)
  if ( ctl.length > 1 ) ctl = eval("document.form1." + src)
  if ( ctl.value == 'N') ctl.value = 'Y'
  else ctl.value = 'N' }

function scroll(src,min,max) {
  ctl = retobj(src)
  if ( ctl.length > 1 ) ctl = eval("document.form1." + src)
  x = min * 1
  y = max * 1
  z = ctl.value * 1 + 1
  if ( z > y || z < x ) ctl.value = min
  else ctl.value = z }

function left(str, n) {
  if (n <= 0 || n > String(str).length) return str;
  else return String(str).substring(0,n); }

function right(str, n) {
  if (n <= 0 || n > String(str).length) return str;
  else sLen = String(str).length; return String(str).substring(sLen, sLen - n); }

function toNum(str) {
  x = str * 1;
  if (isNaN(x)) { return '0' } else return x }

function round_attemptimprovement(num,deci) {
  if ( deci > 0 ) { a = ".0000000000" }
  else { a = "" }
  if ( deci == -1 ) { return num }
  else {
    roundnum = Math.round(num * Math.pow(10,deci)) / Math.pow(10,deci);
    newnum = roundnum.toString(); z = deci * 1
    if ( deci = 0 ) { return newnum }
    else { x = newnum.indexOf(".");
	 if ( x == -1 ) { return newnum + left( a, z - 1 ) }
	 else { rarr = newnum.split("."); return rarr[0] + left(rarr[1] + a, z ) } } } }

function round(num,deci) {
  if ( deci == -1 ) { return num }
  else {
    roundnum = Math.round(num * Math.pow(10,deci)) / Math.pow(10,deci);
    newnum = roundnum.toString(); z = deci * 1
    if ( deci = 0 ) { return newnum }
    else { x = newnum.indexOf("."); a = "0000000000";
	 if ( x == -1 ) { return newnum + "." + left(a,z) }
	 else { rarr = newnum.split("."); return rarr[0] + "." + left(rarr[1] + a,z) } } } }

function incl(str,istr) { newstr=''
  for (j = 0; j < str.length; j++) {
    c = str.charAt(j); if (istr.indexOf(c) > -1) newstr += c; }
  return newstr }

function excl(str,estr) { newstr=''
  for (j = 0; j < str.length; j++) {
    c = str.charAt(j); if (estr.indexOf(c) == -1) newstr += c; }
  return newstr }

function fmtnum(src,deci) {
  ctl = retobj(src)
  if (ctl == null) { return }

  if ( ctl.length > 1 ) {
    for (i = 0; i < ctl.length; i++) {
	num = incl(ctl[i].value,'0123456789.')
	ctl[i].value = round(num,deci * 1) } }
  else { 
	num = incl(ctl.value,'0123456789.')
	ctl.value = round(num,deci * 1) } }

// Standard ** Control/Object ** related functions


function sf() { document.form1.submit() }

function retobj(obj) {
 return eval("document.form1." + left( obj, obj.indexOf("[") ) ); }

function addstr(src,dest) {
  ctl = eval("document.form1." + dest)
  ctl.value = ctl.value + src }

// Standard ** DateAdd & DateFormat **  functions

function adddays(src,days,dest) {
  dt = new Date( eval("document.form1." + src + ".value") );
  ms = dt.getTime() + (days*24*60*60*1000);
  newdt = new Date(); newdt.setTime(ms);
  ctl = eval("document.form1." + dest)
  ctl.value = newdt.toLocaleString() }

function fmt_date(src, fmt) {
  ctl = eval("document.form1." + src)
  var aDate = new Date(ctl.value);
  var aVar = { MM: aDate.getMonth()+1, DD: aDate.getDate(), YYYY: aDate.getFullYear(),
    YY: aDate.getFullYear() % 100, hh: aDate.getHours(), mm: aDate.getMinutes(),
    ss: aDate.getSeconds(), ap: "AM" }
  if(fmt.match(/\bap\b/i)){ if(aVar.hh>12){ aVar.hh -= 12; aVar.ap = "PM"; } }
  for(v in aVar){ fmt = fmt.replace(v, f2(aVar[v])); }
  ctl.value = fmt }

function f2(theVal) { if(theVal<10) return "0"+theVal; return theVal; }



function mv(src,dest) {
  ctl = retobj(dest)
  if ( ctl.length > 1 ) ctl = eval("document.form1." + dest)
  if ( ctl == null ) { return }
  ctl.value = eval("document.form1." + src + ".value") }

function mvall(src,dest) {
  a = eval("document.form1." + src + ".value"); 
  ctl = retobj(dest)
  if ( ctl.length > 1 ) { for (i = 0; i < ctl.length; i++) ctl[i].value = a }
  else ctl.value = a }

function mvmany(src,dest) {
  ctl2 = retobj(src); ctl = retobj(dest)
  if ( ctl.length > 1 ) { for (i = 0; i < ctl.length; i++) ctl[i].value = ctl2[i].value }
  else ctl.value = ctl2.value }

function chk(src) {
  ctl = retobj(src)
  if ( ctl.length > 1 ) ctl = eval("document.form1." + src)
  if ( ctl.checked == false) ctl.checked = true
  else ctl.checked = false }

function chkall(src,dest) {
  ctl = retobj(src)
  bool = new Boolean();
  if ( ctl.length > 1 ) ctl = eval("document.form1." + src + "[0]")
  if ( ctl.checked == false ) bool = true; else bool = false
  ctl2 = retobj(dest)
  if ( ctl2.length > 1 ) { for (i = 0; i < ctl2.length; i++) ctl2[i].checked = bool }
  else { ctl2.checked = bool } }

function write(val,dest) {
  ctl = retobj(dest)
  if ( ctl.length > 1 ) { for (i = 0; i < ctl.length; i++) ctl[i].value = val }
  else ctl.value = val }

function copy(val,dest) {
  ctl = retobj(dest)
  if ( ctl.length > 1 ) ctl = eval("document.form1." + dest)
  ctl.value = val }

function copyo(str,dest) {
  ctl = eval("opener.document.form1." + dest);
  ctl.value = str }

function copynext(str,dest) {
  ctl = retobj(dest)
  var x = 1
  if ( ctl == null ) { ctl = retobj(dest + x)
    if ( ctl == null ) { return }
    else {
	for (i = 0; i < 4; i++)
	  if (ctl.value == '') { ctl.value = str; return }
	  else { x = x * 1 + 1; ctl = retobj(dest + x);
		    if ( ctl == null ) { return } } } }
  else {
    if ( ctl.length > 1 ) {
	for (i = 0; i < ctl.length; i++)
          if (ctl[i].value == '') { ctl[i].value = str; return } } } }


function copyx(val,ctlx,x) {
  ctl = eval("document.form1." + ctlx);
  if ( ctl.length > 1 ) { ctl = eval("document.form1." + ctlx + "(" + x + ")"); }
  ctl.value = val }

function writeback(val,ctlx) {
  ctl = eval("opener.document.form1." + ctlx);
  ctl.value = val;
  }


// Standard ** Math ** functions

function calc(str) {
  a = ""
  if ( str.indexOf("=") >= 0 ) { 
    arr = str.split("="); a = arr[0]; rslt = retobj(arr[1]) }
  else { a = str }

  if ( a.indexOf("*") >= 0 ) { oper = "*"; arr2 = a.split("*"); }
  op1 = retobj(arr2[0]);
  if (op1 == null) { return }
  op2 = retobj(arr2[1])

  if ( op1.length > 1 ) { 
    for (i = 0; i < op1.length; i++) rslt[i].value = toNum(op1[i].value) * toNum(op2[i].value) }
  else { rslt.value = toNum(op1.value) * toNum(op2.value) } }

function sum(src,dest) {
  ctl = retobj(src);
  if (ctl == null) { return }

  ctl2 = retobj(dest); x = 0
  if ( ctl.length > 1 ) {
    for (i = 0; i < ctl.length; i++) { x = x + toNum(ctl[i].value) } }
  else { x = toNum(ctl.value) }
  ctl2.value = x }

function incr(src,val) {
  ctl = eval("document.form1." + src);
  if ( ctl.value == '') { ctl.value = parseInt(val) }
  else { ctl.value = parseInt(ctl.value) + parseInt(val) } }


// ** FUNKY ** functions

function append(ctlx,ctly) {
  ctl = eval("document.form1." + ctlx);
  var incl = ''; var excl = ''; var x = 0;

  if ( ctl.length > 1 ) {
	for (i = 0; i < ctl.length; i++) {
	  if (ctl[i].checked == true) { incl = incl + ctl[i].value + ", " } 
	  else { excl = excl + ctl[i].value + ", " } } }
  else {  if (ctl.checked == true) { incl = ctl.value + ", " } 
	  else { excl = ctl.value + ", " } }

  x = parseInt(incl.length) - 2;
  if ( x >= 0 ) { incl = incl.substring(0, x ) }

  ctl2 = eval("document.form1." + ctly); val2 = ctl2.value;

  if ( val2 != '' && incl != '' ) { val2 = val2 + ", " + incl } 
  else { if ( incl != '' ) { val2 = incl } }

  var a = '';  var b = ''; ary = val2.split(",");
  for (i = 0; i < ary.length; i++) { a = ary[i] + ",";
    if ( excl.indexOf(a) == -1 && b.indexOf(a) == -1 ) { b = b + a} }

  x = parseInt(b.length) - 1;
  if ( x >= 0 ) { b = b.substring(0, x ) }

  ctl2.value = b; }


function chkvar(ctlx,x,ctly) {
  ctl = eval("document.form1." + ctlx);
  if ( ctl.length > 1 ) { ctl = eval("document.form1." + ctlx + "(" + x + ")"); }
  switch(ctl.type) {
    case 'checkbox': if (ctl.checked == false) { ctl.checked = true}
			else { ctl.checked = false }; break; 
    case 'radio':    if (ctl.checked == false) { ctl.checked = true}
			else { ctl.checked = true }; break; }
  
  ctl2 = eval("document.form1." + ctly);
  val1 = ctl.value;  val2 = ctl2.value; a = '';

  if (val2 == ''  && ctl.checked == true) { ctl2.value = val1 }
  else {
	ary = val2.split(", ");
	for (i = 0; i < ary.length; i++)
	    if ( ary[i] != val1 ) { a = a + ary[i] + ", " }

	if (ctl.checked == true)  { a = a + val1 + ", " }
	x = parseInt(a.length);
	if ( x > 0 ) { x = x - 2; a = a.substring(0,x) }
	ctl2.value = a; } }


function sel(src) {
  ctl=eval("document.form1." + src);
  switch(ctl.type) {
    case 'checkbox':
	if (ctl.checked == false) { ctl.checked = true}
		else { ctl.checked = false }; break; 
    case 'radio':
	if (ctl.checked == false) { ctl.checked = true}
		else { ctl.checked = true }; break; } }

function pop(pop) { hwnd=window.open('go.asp?prog=&pop='+pop,'pop',
  'width=100,height=100,left=100,top=100,scrollbars=yes,status=no,resizable=1'); void('')}

function convnbr(src,fmt) {
  src = eval("document.form1." + src)
  src.value = fmtnbr(src.value,fmt) }

function nbr(src,x) {
  ctl = eval("document.form1." + src);
  if ( ctl.length > 1 ) { 
	ctl = eval("document.form1." + src + "(" + x + ")"); }
  num = ctl.value
  num = num.toString().replace(/\$|\,/g,'')
  if(isNaN(num)) { num = '0' }
  ctl.value = num }



function fmtnbr(num,fmt) {
  num = num.toString().replace(/\$|\,/g,''); if(isNaN(num)) num = '0'
  switch(fmt) {
    case '0': cents = ''
	      num = Math.floor((num*1+0.5)).toString(); break
    case '1': cents = '.' + Math.floor((num*10+0.5)%10)
	      num = Math.floor((num*10+0.5)/10).toString(); break
    case '2': cents = Math.floor((num*100+0.5)%100)
	      if(cents < 10) {cents = ".0" + cents} else {cents = "." + cents}
	      num = Math.floor((num*100+0.5)/100).toString(); break }
  num = num+cents; return num.toString() }

function fmtdate(src,fmt) {
  ctl = eval("document.form1." + src);
  num = ctl.value;
  var d = num;
  d = new Date(d);
  d = new Date(num);
//  if (!isNaN(d)) return;
  newnum = '';
  now = new Date();
  dy = now.getDate();
  mo = now.getMonth() + 1;
  yr = now.getYear();
  for (var i = 0; i < num.length; i++)
    if (num.substring(i) >= '0') {
      if (num.substring(i) < ':') {newnum = newnum + num.substring(i,i + 1) } }

    x = parseInt(newnum.length);

    switch(x) {
	case 0: ctl.value = ''; return true;
	case 1: dy = parseInt(newnum); break; 
	case 2: dy = parseInt(newnum.substring(1,2),10);
		mo = parseInt(newnum.substring(0,1),10); break;
	case 3: dy = parseInt(newnum.substring(1,3),10);
		mo = parseInt(newnum.substring(0,1),10);
		if (dy > 31) {dy = parseInt(newnum.substring(2,3),10);
			mo = parseInt(newnum.substring(0,2),10);
			if (mo > 12) {dy = parseInt(newnum.substring(1,2),10);
				mo = parseInt(newnum.substring(0,1),10);
				yr = parseInt(newnum.substring(2,3),10); } }; break;
	case 4: dy = parseInt(newnum.substring(2,4),10);
		mo = parseInt(newnum.substring(0,2),10);
		if (mo > 12) {dy = parseInt(newnum.substring(1,2),10);
				mo = parseInt(newnum.substring(0,1),10);
				yr = parseInt(newnum.substring(2,4),10); }; break;
	case 5: dy = parseInt(newnum.substring(2,3),10);
		mo = parseInt(newnum.substring(0,2),10);
		yr = parseInt(newnum.substring(3,5),10);
		if (mo > 12) {dy = parseInt(newnum.substring(1,3),10);
			mo = parseInt(newnum.substring(0,1),10) }; break;
	case 6: mo = parseInt(newnum.substring(0,2),10);
		if (mo > 12) {dy = parseInt(newnum.substring(1,2),10);
			mo = parseInt(newnum.substring(0,1),10);
			yr = parseInt(newnum.substring(2,6),10); }
		else {dy = parseInt(newnum.substring(2,4),10);
			yr = parseInt(newnum.substring(4,6),10); }; break;
	case 7: dy = parseInt(newnum.substring(1,3),10);
		mo = parseInt(newnum.substring(0,1),10);
		yr = parseInt(newnum.substring(3,7),10);
		if (dy > 31) {mo = parseInt(newnum.substring(0,2),10);
			if (mo > 12) {dy = parseInt(newnum.substring(1,3),10);
				mo = parseInt(newnum.substring(0,1),10); }
			else  {dy = parseInt(newnum.substring(2,3),10);
				mo = parseInt(newnum.substring(0,2),10); } }; break;
	default: mo = parseInt(newnum.substring(0,2),10);
		if (mo > 12) {mo = parseInt(newnum.substring(0,1),10);
			dy = parseInt(newnum.substring(1,3),10);
			if (dy > 31) {dy = parseInt(newnum.substring(1,2),10);
				yr = parseInt(newnum.substring(2,6),10); }
			else {	yr = parseInt(newnum.substring(3,7),10); } }
		else {dy = parseInt(newnum.substring(2,4),10);
			if (dy > 31) {dy = parseInt(newnum.substring(2,3),10);
				yr = parseInt(newnum.substring(3,7),10); }
			else {yr = parseInt(newnum.substring(4,8),10);} }; break; }

  if (yr < 50) { yr = yr + 2000 } else if (yr < 100) { yr = yr + 1900 };
  while ( mo > 12) { mo = parseInt(mo); mo = mo - 12; yr = yr + 1 }
  for (var i = 0; i < 3; i++) { 
	var days = daysinmonth(mo,yr)
	if (dy > days) {dy = dy - days; mo = mo + 1} 
	if (mo > 12) {mo = 1; yr = yr + 1} }

  if (mo<0) { mo=1 }
  if (mo==2) { var isleap = (yr % 4 == 0 && (yr % 100 != 0 || yr % 400 == 0));
	if (dy>29 || (dy==29 && !isleap)) { dy = dy - 28; mo = mo + 1 } }

  if ((mo==1 || mo==3 || mo==5 || mo==7 || mo==8 || mo==10 || mo==12) && dy>31) {
	while (dy>31) { dy = dy - 31; mo = mo + 1 } }
  if ((mo==4 || mo==6 || mo==9 || mo==11) && dy>30) {
	while (dy>30) { dy = dy - 30; mo = mo + 1 } }


  m1 = mo.toString(); d1 = dy.toString(); y1 = yr.toString()

  switch(fmt) {
	case '2': if (m1.length == 1) {m1 = '0' + m1 };
		  if (d1.length == 1) {d1 = '0' + d1 };
		  ctl.value = m1 + '/' + d1 + '/' + right(y1,2); break;
	case '3': ctl.value = m1 + '/' + d1 + '/' + y1; break;
	case '4': if (m1.length == 1) {m1 = '0' + m1 };
		  if (d1.length == 1) {d1 = '0' + d1 };
		  ctl.value = m1 + '/' + d1 + '/' + y1; break;
	default:  ctl.value = m1 + '/' + d1 + '/' + right(y1,2); break; } }


function daysinmonth(mo,yr)  {
  var days;
  if (mo==1 || mo==3 || mo==5 || mo==7 || mo==8 || mo==10 || mo==12)  days=31;
  else if (mo==4 || mo==6 || mo==9 || mo==11) days=30;
  else if (mo==2)  {if (isleapyr(yr)) {days=29;} else {days=28;} }
  return (days); }

function isleapyr (yr) {
  if (((yr % 4)==0) && ((yr % 100)!=0) || ((yr % 400)==0)) { return (true); } 
  else { return (false); } }

function fmtime(src) {
  ctl = eval("document.form1." + src)
  num = ctl.value; newnum = ''; hr = 0; min = 0
  for (i = 0; i < num.length; i++)
    if (num.substring(i) >= '0') {
	if (num.substring(i) < ':') {newnum = newnum + num.substring( i , i + 1) } }
  if (newnum.length < 3) {
	for (var i = 0; i < 3-num.length; i++) { newnum = '0' + newnum } }
  if (newnum.length > 3) { hr = newnum.substring(0,2); min = newnum.substring(2,4) }
	else  { hr = newnum.substring(0,1); min = newnum.substring(1,3); }
  if (min > 59) { hr = parseInt(hr); hr = hr + 1; min = parseInt(min); min = min - 60 }
  while ( hr > 23) { hr = parseInt(hr); hr = hr - 24; }
  min = min.toString();
  if (min.length < 2) { min = '0' + min }
  hr = hr.toString();
  if (hr.length > 1 & hr.substring(0,1) == '0') { hr = hr.substring(1,2) }
  ctl.value = hr + ':' + min }

function timediff(nx) {
  frdt = eval("document.form1.fr_dt["+nx+"]")
  frtm = eval("document.form1.fr_tm["+nx+"]")
  todt = eval("document.form1.to_dt["+nx+"]")
  totm = eval("document.form1.to_tm["+nx+"]")
  ctl = eval("document.form1.hours["+nx+"]")
  date1 = new Date(); date2 = new Date(); diff = new Date();

  if (frdt.value > '' && frtm.value > '' && todt.value > '' && totm.value > '') {
    a = new Date(frdt.value + " " + frtm.value);  date1.setTime(a.getTime());
    b = new Date(todt.value + " " + totm.value);  date2.setTime(b.getTime());
    x = 0;
    diff.setTime(Math.floor(date2.getTime() - date1.getTime()));
    x = Math.floor(diff.getTime() / (1000 * 60)); 
    x = parseFloat(x / 60);
    a = x.toString(); ary = a.split(".")
    if (ary.length > 1) { a = ary[1] } else { a = '0' }
    while ( a.length < 2) { a = a + '0' }
    ctl.value = ary[0] + '.' + a.substring(0,2) } }

function calchrs(fr,to,dest) {
  fr = eval("document.form1." + fr)
  to = eval("document.form1." + to)
  dest = eval("document.form1." + dest)
  y = timeinhrs(fr.value);
  z = timeinhrs(to.value);
  y = z - y
  if ( y < 0 ) { y = 0 }
  dest.value = fmtnbr(y,'2') }

function timeinhrs(num) {
  newnum = ''; hr = 0; min = 0;
  for (i = 0; i < num.length; i++)
    if (num.substring(i) >= '0') {
      if (num.substring(i) < ':') {newnum = newnum + num.substring(i,i + 1) } }
  if (newnum.length < 3) {
    for (var i = 0; i < 3-num.length; i++) { newnum = '0' + newnum } }
  if (newnum.length > 3) { hr = newnum.substring(0,2); min = newnum.substring(2,4) }
    else  { hr = newnum.substring(0,1); min = newnum.substring(1,3) }
  if (min > 59) { hr = parseInt(hr); hr = hr + 1; min = parseInt(min); min = min - 60 }
  while ( hr > 23) { hr = parseInt(hr); hr = hr - 24 }
  min = min / 60
  hr = parseInt(hr); hr = hr + min
  return hr.toString() }

function chkhrs(fr,hrs,to) {
  fr = eval("document.form1." + fr)
  val = eval("document.form1." + hrs + ".value")
  to = eval("document.form1." + to)
  if (fr.value == '') { return }
  if (document.form1.fr.value > '') { addtime('fr',document.form1.hr.value,'to') }
  document.form1.hr.value = fmtnbr(document.form1.hr.value,'2') }

function addtime(fr,dest,hr) {
  fr = eval("document.form1." + fr)
  to = eval("document.form1." + dest)
  x = eval("document.form1." + hr + ".value")
  x = parseFloat(x)
  y = timeinhrs(ctl.value)
  z = parseFloat(x) + parseFloat(y)
  a = z.toString(); ary = a.split(".")
  if (ary.length > 1) { a = "." + ary[1]; a = parseInt(parseFloat(a) * 60 + 0.5 ) } else { a=''}
  a = a.toString()
  while ( a.length < 2) { a = '0' + a }
  to.value = ary[0] + a
  fmtime(dest) }


function showtime () {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeval = "" + ((hours >24) ? hours -24 :hours)
if (timeval == "0") timeval = 12;
timeval += ((minutes < 10) ? ":0" : ":") + minutes
timeval += ((seconds < 10) ? ":0" : ":") + seconds
document.form1.timer.value = timeval;
timerID = setTimeout("showtime()",1000);
timerRunning = true; }

function timenow(src) {
  src = eval("document.form1." + src)
  now = new Date();
  hours = now.getHours();
  minutes = now.getMinutes();
  timeval = "" + ((hours >24) ? hours -24 :hours)
  if (timeval == "0") timeval = 12;
  timeval += ((minutes < 10) ? ":0" : ":") + minutes
  src.value = timeval }

function chktab(el) { if ((document.all) && (9==event.keyCode) && (event.ctrlKey)) {
    el.selection=document.selection.createRange(); 
    setTimeout("proctab('" + el.id + "')",0) } }


function valiDate(ctl) {
if (chkDate(ctl) == false) {
alert("That date is invalid.  Please try again.");
ctl.value='';
ctl.focus();
ctl.select();
return false;
}
else {
return false;
   }
}

function chkDate(ctl) {
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = ctl;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;

strDate = datefield.value;
if (strDate.length < 1) {
return true;
}

if (strDate.length > 0 && strDate.length < 6) {
return false;
}


for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) {
err = 1;
return false;
}
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
   }
}
if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
}

//if (strYear.length == 2) {
//strYear = '20' + strYear;
//}


strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;

intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);


intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
}
}
else {
if (intday > 28) {
err = 10;
return false;
}
}
}

datefield.value = intMonth + "\/" + intday+"\/" + strYear;

return true;
}
function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}

function reswnd() {
  var h=document.getElementById('lgimg').height * 1.4
  var w=document.getElementById('lgimg').width * 1.3
  window.moveTo(0,0)
  window.resizeTo(w,h)

}

function pg(pg) { document.pgform.pg.value=pg; document.pgform.submit() }

//Scroll to Name
function pageXY(el) {
	var XY={x:0, y:0};
	for(var node = el; node; node=node.offsetParent) { 
		XY.x += node.offsetLeft;
		XY.y += node.offsetTop;
	}
	return XY;
}
function gotoName(name) {
	var anchors, anchor, XY;
	anchors=document.anchors;
	anchor=anchors[name];
	//IE
	if(!anchor) { 
		for(var i = 0; i < anchors.length; ++i) { 
			if(anchors[i].name==name) { 
				anchor = anchors[i];
				break;
			}
		}
	}
	if(!anchor) { 
		if(document.getElementById) anchor=document.getElementById(name);
		else if(document.all) anchor=document.all[name];
	}
	if(anchor) { 
		XY = pageXY(anchor);
		window.scrollTo(XY.x, XY.y);
	}
}

function validEmail(email) {
	invalidChars = " /:,;"
	if (email == "") return false
	for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) return false
	}
	atPos = email.indexOf("@",1)			// there must be one "@" symbol
	if (atPos == -1) return false
	if (email.indexOf("@",atPos+1) != -1) return false	// and only one "@" symbol
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) return false		// and at least one "." after the "@"
	if (periodPos+3 > email.length) return false	// must be at least 2 characters after the "."
	return true
}

function mailThisUrl(email, subject, body) {
	//checkEmailAddress(document.eMailer.email);
	window.location = "mailto:"+email+"?subject="+subject+"&body="+body;
}

//Open new pop up window
function newWindow(url, w, h) {
	var attr = 'width='+w+',height='+h+',scrollbars=1,resizable=1,toolbar=0,location=1,menubar=1,status=1,directories=1';
  	var winContent = window.open(url,'',attr);
}

//Validate Credit Card Number
function isValidCC(ccnum) {
   	// Remove all dashes for the checksum checks to eliminate negative numbers
   	ccnum = ccnum.split("-").join("");
	ccnum = ccnum.replace(/^\s*|\s*$/g,"")

   	// Checksum ("Mod 10")
   	var check = 0;
   	for(var i=0;i<ccnum.length;i++){
     		var num = ccnum.substr(i,1);
     		num *= ((i+ccnum.length)%2)?1:2;
     		check += (num>9)?num%10+1:num;
   	}
   	if(check%10 == 0 && ccnum != "") return (true);
   	else return (false);
}

//Validate Credit Card Type
function isValidCCType(ccnum, type) {
	ccnum = ccnum.replace(/^\s*|\s*$/g,"");
	ccnum = ccnum.substr(0,1);
	type = type.replace(/^\s*|\s*$/g,"");
	if (type == "A" && ccnum == 3) return(true);
	if (type == "V" && ccnum == 4) return(true);
	if (type == "M" && ccnum == 5) return(true);
	if (type == "D" && ccnum == 6) return(true);
	return(false);
}

//Validate Credit Card Expiration
function isValidCCExp(exp) {
	var actDate = new Date();
	var dPart = exp.match(/(\d+)(\d\d)$/);
	var YY = actDate.getFullYear()%100;
	var MM = actDate.getMonth();
	if (dPart[2]>YY || dPart[2]==YY&&dPart[1]>MM) return (true);
	else return (false);
}

//Validate Checkout form
function validateCheckout(step) {

var theForm = document.formchkout;

	if (step==1) {

		if (theForm.newcust[0].checked && theForm.unm.value == "") {
		    alert('Please enter your user name.');
		    theForm.unm.focus();
		    return (false);
		}

		if (theForm.newcust[0].checked && theForm.upw.value == "") {
		    alert('Please enter your password to continue.');
		    theForm.upw.focus();
		    return (false);
		}

		if (theForm.newcust[1].checked && !validEmail(theForm.newuser.value)) {
		    alert('Please enter a valid Email address for your user name.');
		    theForm.newuser.focus();
		    return (false);
		}

		if (theForm.newcust[1].checked && theForm.newpass.value == "") {
		    alert('Please enter a password to continue.');
		    theForm.newpass.focus();
		    return (false);
		}

	} else if (step==2) {

		if (theForm.billfirst.value == "") {
		    alert('Please enter a value for the "Billing First Name" field.');
		    theForm.billfirst.focus();
		    return (false);
		}

		if (theForm.billlast.value == "") {
		    alert('Please enter a value for the "Billing Last Name" field.');
		    theForm.billlast.focus();
		    return (false);
		} else theForm.billname.value = nameArrange(theForm.billfirst.value, theForm.billlast.value);

		if (theForm.billadd1.value == "" && theForm.billadd2.value == "") {
		    alert('Please enter a value for the "Billing Address" field.');
		    theForm.billadd1.focus();
		    return (false);
		}

		if (theForm.billcity.value == "") {
		    alert('Please enter a value for the "Billing City" field.');
		    theForm.billcity.focus();
		    return (false);
		}

		if (theForm.billstate.value == "0") {
		    alert('Please enter a value for the "Billing State" field.');
		    theForm.billstate.focus();
		    return (false);
		}

		if (theForm.billzip.value == "") {
		    alert('Please enter a value for the "Billing Zip Code" field.');
		    theForm.billzip.focus();
		    return (false);
		}

		if (theForm.billphone.value == "") {
		    alert('Please enter a value for the "Billing Phone Number" field.');
		    theForm.billphone.focus();
		    return (false);
		}

		if (!validEmail(theForm.billemail.value)) {
		    alert('Please enter a valid email address.');
		    theForm.billemail.focus();
		    return (false);
		}


		if (theForm.shipfirst.value == "") {
		    alert('Please enter a value for the "Shipping First Name" field.');
		    theForm.shipfirst.focus();
		    return (false);
		}

		if (theForm.shiplast.value == "") {
		    alert('Please enter a value for the "Shipping Last Name" field.');
		    theForm.shiplast.focus();
		    return (false);
		} else theForm.shipname.value = nameArrange(theForm.shipfirst.value, theForm.shiplast.value);

		
		if (theForm.shipadd1.value == "" && theForm.shipadd2.value == "") {
		    alert('Please enter a value for the "Shipping Address" field.');
		    theForm.shipadd1.focus();
		    return (false);
		}
		
		if (theForm.shipcity.value == "") {
		    alert('Please enter a value for the "Shipping City" field.');
		    theForm.shipcity.focus();
		    return (false);
		}
		
		if (theForm.shipstate.value == "0") {
		    alert('Please enter a value for the "Shipping State" field.');
		    theForm.shipstate.focus();
		    return (false);
		}
		
		if (theForm.shipzip.value == "") {
		    alert('Please enter a value for the "Shipping Zip Code" field.');
		    theForm.shipzip.focus();
		    return (false);
		}
		
		if (theForm.shipphone.value == "") {
		    alert('Please enter a value for the "Shipping Phone" field.');
		    theForm.shipphone.focus();
		    return (false);
		}
	
	} else if (step==3) {

		var ansArray = theForm.paymeth.options[theForm.paymeth.selectedIndex].value.split("|");
		var cctype = ansArray[0];
		var nbrReq = ansArray[1];
		var modReq = ansArray[2];
		var expReq = ansArray[3];
		var payacct = ansArray[4];
		
		if(theForm.ccnbr.value=='' && nbrReq=='Y') {
			alert('Please enter a value for the "Credit Card Number" field.');
			theForm.ccnbr.focus();
			return (false);
		} 

		if(!isValidCC(theForm.ccnbr.value) && modReq=='Y') {
			alert('Please enter a valid value for the "Credit Card Number" field.');
			theForm.ccnbr.focus();
			return (false);
		} 

		if(!isValidCCType(theForm.ccnbr.value, cctype) && modReq=='Y') {
			alert('Please enter a valid value for the "Credit Card Payment Method" field.');
			theForm.ccnbr.focus();
			return (false);
		} 

		var fullexp = theForm.expmnth.value.toString()+theForm.expyear.value.toString();
		if(!isValidCCExp(fullexp) && expReq=='Y') {
			alert('Please enter a valid value for the "Credit Card Expiration Date" field.');
			return (false);
		}

		theForm.paymeth.options[theForm.paymeth.selectedIndex].value = cctype;
		theForm.ccmask.value = theForm.ccnbr.value.replace(/\d{12}/,"XXXX-XXXX-XXXX-");

		if(cctype=='LC' && theForm.comments.value=='') {
			alert("Please enter the amount of the Gift Certificate in the 'Special Notes' section");
			theForm.comments.value="My Gift Certificate amount: $";
			return (false);
		}
		
		theForm.payacct.value = payacct;	

/*
		//ICVERIFY Preauth stuff
		if (theForm.expmnth.value.length.toString() < 2) 
			icvexp = theForm.expyear.value.toString() + 0 + theForm.expmnth.value.toString();
		else 	icvexp = theForm.expyear.value.toString() + theForm.expmnth.value.toString();

		if (theForm.cccvv.value != "")
			var cid = 1;
		else	var cid = 9;
		//var cc_answer = ajaxFunctionReturn('bod/icverify.asp?type=C6&comment='+theForm.icvcomm.value+'&operator=WEB&contents="'+theForm.quoteid.value+'","'+theForm.ccnbr.value+'","'+icvexp+'","'+theForm.cc_subtotal.value+'","","","","'+theForm.billzip.value+'","'+theForm.billadd1.value+'","0","'+cid+'","'+theForm.cccvv.value+'"');
		var cc_answer = ajaxFunctionReturn('bod/icverify.asp?type=C6&operator=WEB&comment='+formchkout.icvcomm.value+'&contents="'+formchkout.ccnbr.value+'","'+icvexp+'","'+formchkout.cc_subtotal.value+'","","","'+formchkout.billzip.value+'","'+formchkout.billadd1.value+'"');

		var response_code = cc_answer.substr(1,1);
		var response_auth = cc_answer.substr(2,6);
		var response_avs = cc_answer.substr(8,1);
		var ccerror = "";

		if (response_code == 'N')
			ccerror += "<li>Your credit card was not approved. Please check the number and click Continue.</li>";

		//Address verification result
		//if (response_avs == 'N' || response_avs == 'P' || response_avs == 'W' || response_avs == 'Z')
		//	ccerror += "<li>Your street address did not match your credit card information. Please re-enter a correct billing address.</li>";

		//if (response_avs == 'B' || response_avs == 'N' || response_avs == 'A')
		//	ccerror += "<li>Your zip code did not match your credit card information. Please re-enter a correct billing zip code.</li>";
			
		if (ccerror != "") {
			// Return true if this is the second error to let them through 
			if(document.getElementById("ccerror").style.visibility == 'visible') {  
				return true; 
			} 
			ccerror = "Credit Card Verification error: <ul>"+ccerror+"</ul>";
			document.getElementById("ccmsg").innerHTML = ccerror;
			document.getElementById("ccerror").style.display = '';
			document.getElementById("ccerror").style.visibility = 'visible';
			return false;		
		} else {
			var alphaExp = /^[0-9a-zA-Z]+$/;
			if (response_auth.match(alphaExp))
				formchkout.ccpreauth.value = response_auth;

			formchkout.rawpreauth.value = cc_answer;
			document.getElementById("ccerror").style.display = 'none';
			document.getElementById("ccerror").style.visibility = 'hidden';
		}
		//END ICVERIFY Preauth stuff
*/
	}

	return (true);
}

function dropDownHolder (a,b) {
	if (a==b) return('selected="true"');
}

//First-Last name Arrangement
function nameArrange (first, last) {
	return (last+", "+first);
}

//First-Last name display
function nameDisplay (name, code) {
	if (code.toLowerCase() == 'fname') return (name.substr(name.indexOf(',')+1, name.length).replace(/^\s*|\s*$/g,""));
	if (code.toLowerCase() == 'lname') return (name.substr(0,name.indexOf(',')).replace(/^\s*|\s*$/g,""));
}

//Validate Change Address form
function validateChgAdd(theForm) {

		if (theForm.custfirst.value == "") {
		    alert('Please enter a value for the "First Name" field.');
		    theForm.custfirst.focus();
		    return (false);
		}

		if (theForm.custlast.value == "") {
		    alert('Please enter a value for the "Last Name" field.');
		    theForm.custlast.focus();
		    return (false);
		} else theForm.custname.value = nameArrange(theForm.custfirst.value, theForm.custlast.value);

		if (theForm.custadd1.value == "") {
		    alert('Please enter a value for the "Address" field.');
		    theForm.custadd1.focus();
		    return (false);
		}

		if (theForm.custcity.value == "") {
		    alert('Please enter a value for the "City" field.');
		    theForm.custcity.focus();
		    return (false);
		}

		if (theForm.custstate.value == "") {
		    alert('Please enter a value for the "State" field.');
		    theForm.custstate.focus();
		    return (false);
		}

		if (theForm.custzip.value == "") {
		    alert('Please enter a value for the "Zip Code" field.');
		    theForm.custzip.focus();
		    return (false);
		}

		if (theForm.custphone.value == "") {
		    alert('Please enter a value for the "Phone Number" field.');
		    theForm.custphone.focus();
		    return (false);
		}

		if (!validEmail(theForm.custemail.value)) {
		    alert('Please enter a valid email address.');
		    theForm.custemail.focus();
		    return (false);
		}
}

			function openclick121(page)	{
				var left=(screen.availWidth - 550) / 2;
				var top=(screen.availHeight - 550) / 2;
				window.open(page,'tour', 'top=' + top + ', left=' + left + ', scrollbars=no,resizable=yes,toolbar=no,location=no,width=550,height=550');
			}
			function jumpToCategory(which)	{
				if(document.getElementById(which).options[document.getElementById(which).selectedIndex].value!='')	{
					window.location=document.getElementById(which).options[document.getElementById(which).selectedIndex].value;
				}
			}


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=320,height=436,scrollbars=no');
return false;
}

function ajaxFunction(url)
{  
	var xmlHttp;
  	try // Firefox, Opera 8.0+, Safari
    	{
		xmlHttp=new XMLHttpRequest();    
	} catch (e) // Internet Explorer 
    	{       
		try
      		{      
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
		} catch (e)
      		{      
			try
        		{        	
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
			} catch (e)
        		{        
				alert("Your browser does not support AJAX!");
			}      
		}    
	}
	url = url + "&nocache=" + Math.random();	
	xmlHttp.open("GET",url,false);
	xmlHttp.send(null);  
}

function ajaxFunctionReturn(url)
{  
	var xmlHttp;
  	try // Firefox, Opera 8.0+, Safari
    	{
		xmlHttp=new XMLHttpRequest();    
	} catch (e) // Internet Explorer 
    	{       
		try
      		{      
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
		} catch (e)
      		{      
			try
        		{        	
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
			} catch (e)
        		{        
				alert("Your browser does not support AJAX!");
			}      
		}    
	}
	url = url + "&nocache=" + Math.random();	
	xmlHttp.open("GET",url,false);
	xmlHttp.send(null);  
	return xmlHttp.responseText;
}

function ajaxStateChanged()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		if (xmlHttp.responseText != '')
      		document.write(xmlHttp.responseText);
}

function ajaxXMLHttp(ajaxStateChanged)
{

}


//Onclick event for Apply Coupon button
function ApplyCoupon_Click(coupon)
{
	if (coupon.length == 0) 
	{ 
		alert('You must enter a coupon code here.'); 
		return (false); 
	}

	document.formbask.prog.value = "addcpn";
	document.formbask.action.value = "new";
	document.formbask.couponCode.value = coupon;
	document.formbask.submit();
}

//secure SSL page
function pageSSL(secure)
{
	switch (secure)
	{
		case 0:
	 	  if(location.protocol.toLowerCase() == "https:") 
		  	location.replace(location.href.replace('https:','http:'));
		  break;
		case 1:
	 	  if(location.protocol.toLowerCase() != "https:") 
		  	location.replace(location.href.replace('http:','https:'));
		  break;
		default:
	}
}

function callAjaxBE(url, params, method, async, getResponse)
{
	var xmlHttp;

	try
	{    
		//Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
		xmlHttp.overrideMimeType('text/html');
	}
  	catch (e)
    	{    
		//Internet Explorer  
		var XMLHTTP_IDS = new Array(
			'MSXML2.XMLHTTP.5.0',
			'MSXML2.XMLHTTP.4.0',
			'MSXML2.XMLHTTP.3.0',
			'MSXML2.XMLHTTP',
			'Microsoft.XMLHTTP');
		var success = false;
		for (var i=0; i < XMLHTTP_IDS.length && !success; i++)
		{
			try
			{
				xmlHttp = new ActiveXObject(XMLHTTP_IDS[i]);
				success = true;
			}
			catch (e) {}
		}  

		if (!success || typeof(xmlHttp) == "undefined")
		{
			alert("Your browser does not support AJAX!");        
			return false;
		}
	}	

	//Get parameters
	var parameters = "";
	for(var i in params) 
	{
		if (typeof(params[i]) == "undefined")
			params[i] = "";

		var temp = params[i].toString().replace(/(\r\n|\r|\n)|^\s+|\s+$/g, "");		
		parameters += "&" + i + "=" + encodeURI(temp);
	}

	//Handle response and failures
	var response;
	xmlHttp.onreadystatechange = function()
	{	
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
		{		
			if(xmlHttp.status == 200)
				response = xmlHttp.responseText;
			else
			{
				//Error response, ie. 404
			}
		}
		else
		{
			//waiting
		}
	};

	//Fire ajax
	url = url + '?nocache=' + Math.random() + parameters;
	xmlHttp.open(method, url, async);
	xmlHttp.send(null);

	//Return results
	if(getResponse == true)
	{
		if (!async) 
			response = xmlHttp.responseText;

		if (typeof(response) == "undefined")
			response = "";

		return response;
	}
}