//<!--
function search()
{
	document.form.elements['search'].value='yes';
	document.form.elements['page'].value=0;
	document.form.elements['items'].value=0;
	document.form.elements['sortletter'].value='';
	document.form.elements['stockid'].value='';
	document.form.submit();
}

function printpage()
{
	var maincat = document.form.elements['maincat'].value;
	var subcat = document.form.elements['subcat'].value;
	var stockid = document.form.elements['stockid'].value;
	var currency = document.form.elements['currency'].value;
	var page = document.form.elements['page'].value;
	var sortletter = document.form.elements['sortletter'].value;
	var newsid = document.form.elements['newsid'].value;
	var w=window.screen.width;
	var h=window.screen.height;
	mywindow=open('default.asp?curreny=' + currency + '&maincat=' + maincat + '&subcat=' + subcat + '&stockid=' + stockid + '&print=yes&page=' + page + '&sortletter=' + sortletter + '&newsid=' + newsid,'','width=' + w + ',height=' + h + ',fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes');
	mywindow.moveTo((window.screen.width/2)-(w/2),(window.screen.height/2)-(h/2));

}

function addbasket(item,price,xeCurrency,CurrSym)
{
	if(confirm('Okay to add ' + item + ' at ' + CurrSym + price + ' (' + xeCurrency + ') to your shopping cart?'))
	{
		document.paypal.currency_code.value=xeCurrency;
		document.paypal.item_name.value=item;
		document.paypal.amount.value=price;
		document.paypal.submit();
	}
}

function shoppingcart()
{
	var w=1024;
	var h=768;
	mywindow=open('shoppingcart.htm','','width=' + w + ',height=' + h + ',fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes');
	mywindow.moveTo((window.screen.width/2)-(w/2),(window.screen.height/2)-(h/2));
}

function checkout()
{
	var w=800;
	var h=600;
	mywindow=open('checkout.htm','','width=' + w + ',height=' + h + ',fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes');
	mywindow.moveTo((window.screen.width/2)-(w/2),(window.screen.height/2)-(h/2));
}

function howtoorder()
{
	var w=640;
	var h=480;
	mywindow=open('howtoorder.htm','','width=' + w + ',height=' + h + ',fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes');
	mywindow.moveTo((window.screen.width/2)-(w/2),(window.screen.height/2)-(h/2));
}

function shipping()
{
	var w=640;
	var h=480;
	mywindow=open('shipping.htm','','width=' + w + ',height=' + h + ',fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes');
	mywindow.moveTo((window.screen.width/2)-(w/2),(window.screen.height/2)-(h/2));
}

function terms()
{
	var w=640;
	var h=480;
	mywindow=open('terms.htm','','width=' + w + ',height=' + h + ',fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes');
	mywindow.moveTo((window.screen.width/2)-(w/2),(window.screen.height/2)-(h/2));
}

function privacy()
{
	var w=640;
	var h=480;
	mywindow=open('privacy.htm','','width=' + w + ',height=' + h + ',fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes');
	mywindow.moveTo((window.screen.width/2)-(w/2),(window.screen.height/2)-(h/2));
}


function shippingquote(weight)
{
	var w=640;
	var h=480;
	mywindow=open('postalcalc.asp?weight=' + weight,'','width=' + w + ',height=' + h + ',fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes');
	mywindow.moveTo((window.screen.width/2)-(w/2),(window.screen.height/2)-(h/2));
}

function ImageURL(stockid,imageid)
{
	var w=570;
	var h=370;
	mywindow=open('images.asp?stockid=' + stockid + '&imageid=' + imageid,'Picture','width=' + w + ',height=' + h + ',fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes');
	mywindow.moveTo((window.screen.width/2)-(w/2),(window.screen.height/2)-(h/2));
	mywindow.focus();
}
function NImageURL(newsid,imageid)
{
	var w=570;
	var h=370;
	mywindow=open('nimages.asp?newsid=' + newsid + '&imageid=' + imageid,'Picture','width=' + w + ',height=' + h + ',fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes');
	mywindow.moveTo((window.screen.width/2)-(w/2),(window.screen.height/2)-(h/2));
	mywindow.focus();
}

function wanted(stockid)
{
	var w=600;
	var h=500;
	mywindow=open('wanted.asp?stockid=' + stockid,'Wanted','width=' + w + ',height=' + h + ',fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes');
	mywindow.moveTo((window.screen.width/2)-(w/2),(window.screen.height/2)-(h/2));
	mywindow.focus();
}

function viewpage()
{
	document.form.elements['print'].value='view';
	document.form.submit();
}
function viewgallery()
{
	document.form.elements['print'].value='G';
	document.form.submit();
}

function normalpage()
{
	document.form.elements['print'].value='';
	document.form.submit();
}
function doLetter(letter)
{
	document.form.elements['page'].value=0;
	document.form.elements['items'].value=0;
	document.form.elements['sortletter'].value=letter;
	document.form.submit();
}
function newpage(page)
{
	document.form.elements['page'].value=page;
	document.form.submit();
}
function round(objValue, decPlaces)
{
	objValue = '' +  Math.round(objValue*100)/100;


	if(objValue == 'NaN' || objValue=='.' || objValue=='' || objValue == null)
	{
		return '0.00';
	}
	if(objValue.indexOf('.')==-1)
	{
		return objValue + '.00';
	}
	// construct round value:
	var plusPoint5 = new String(".");
	for (var j = 0; j < decPlaces; j++){
	plusPoint5 += "0";
	}
	plusPoint5 += "5";
	// For two places, we now have .005.

	var localStr = new String(objValue + parseFloat(plusPoint5));
	// Now search for the '.', trucate and return.
	decPos = localStr.indexOf(".");
	localStr = localStr.substring(0, decPos+decPlaces);
	return localStr;
}

function keydown(obj,decplace)
{
	var k = window.event.keyCode;
	if(k>=48 && k<=57);
	else if(k==8);
	else if(k==13 && decplace==true)
	{
		obj.value=round(obj.value,3);
	}
	else if(k==46 && decplace==true && obj.value.indexOf('.')<0);
	else
	{
		window.event.keyCode=null;
		return;
	}
}
function newImage(picbox) 
{
	mywindow=open('http://triplemoonstar.brinkster.net/edit/upload.htm','Upload','resizable=no,width=600,height=260');
	mywindow.opener=picbox;
}
function deletecat(id,name)
{
	if (confirm("Are you sure you want to permanently delete category " + name + "?"))
	{
		document.form._action.value='delcat';
		document.form.catid.value=id;
		document.form.submit()
	}
}
function deletesubcat(id,name)
{
	if (confirm("Are you sure you want to permanently delete sub category " + name + "?"))
	{
		document.form._action.value='delsubcat';
		document.form.catid.value=id;
		document.form.submit()
	}
}
function deleteitems(section)
{
	var cnt = 0;
	var formitem;
	var action;

	if(section=='news')
	{
		formitem='newsids';
		action='delnews';
	}
	else if(section=='stock')
	{
		formitem='stockids';
		action='delstock';
	}
	else if(section=='wanted')
	{
		formitem='wantedids';
		action='delwanted';
	}

		for (var i=0;i<document.form.elements.length;i++)
    		{
	      		if (document.form.elements[i].name == formitem && document.form.elements[i].checked)
        			cnt++;
	    	}
		if(cnt)
		{
			if (confirm("Are you sure you want to permanently delete " + cnt + " selected item(s)?"))
			{
				document.form._action.value=action;
				document.form.submit()
			}
		}
		else
			alert("Please select item(s) to delete.");
}

/* Date Functions */
function date_init(form,fulldate,dy,dyval,mon,monval,yr,yrval)
{
    dy=form.elements[dy];
    mon=form.elements[mon];
    yr=form.elements[yr];

    for(var i=0;i<dy.length;i++)
    {
        if(dy[i].value == dyval)
        {
            dy.selectedIndex=i;
            break;
        }
    }

    for(var i=0;i<mon.length;i++)
    {
        if(mon[i].value == monval)
        {
            mon.selectedIndex=i;
            break;
        }
    }

    for(var i=0;i<yr.length;i++)
    {
        if(yr[i].value == yrval)
        {
            yr.selectedIndex=i;
            break;
        }
    }
    if(i==yr.length)
    {
        yr.options[i] = new Option(yrval);
        yr.options[i].value = yrval;
        yr.selectedIndex=i;
    }
    
    month_refresh(form,fulldate,dy.name,mon.name,yr.name);
}

function month_refresh(form,fulldate,dy,mon,yr)
{
    dy=form.elements[dy];
    mon=form.elements[mon];
    yr=form.elements[yr];
    
    var i = mon.selectedIndex;

    if(mon.options[i].value == "2") 
    {
      dy.options[30] = null;
      dy.options[29] = null;
      var j = yr.selectedIndex;
      var y = eval(yr.options[j].value);
      if ( ((y%400)==0) || (((y%100)!=0) && ((y%4)==0)) ) 
      {
        if (dy.options[28] == null) 
        {
          dy.options[28] = new Option("29");
          dy.options[28].value = "29";
        }
      } 
      else 
        dy.options[28] = null;
    }

    else if(mon.options[i].value == "4" || mon.options[i].value == "6" || mon.options[i].value == "9" || mon.options[i].value == "11")
    {
      if (dy.options[28] == null)
      {
        dy.options[28] = new Option("29");
        dy.options[28].value = "29";
      }
      if (dy.options[29] == null) 
      {
        dy.options[29] = new Option("30");
        dy.options[29].value = "30";
      }
      dy.options[30] = null;
    }

    else
    {
      if (dy.options[28] == null) 
      {
        dy.options[28] = new Option("29");
        dy.options[28].value = "29";
      }
      if (dy.options[29] == null) 
      {
        dy.options[29] = new Option("30");
        dy.options[29].value = "30";
      }
      if (dy.options[30] == null) 
      {
        dy.options[30] = new Option("31");
        dy.options[30].value = "31";
      }
    }

    if (dy.selectedIndex == -1)
      dy.selectedIndex = 0;

    form.elements[fulldate].value=dy.options[dy.selectedIndex].value + '/' + mon.options[mon.selectedIndex].value + '/' + yr.options[yr.selectedIndex].value;
}
function date_refresh(form,dy,mon,yr,hidden)
{
    var hdate;
    dy=form.elements[dy];
    mon=form.elements[mon];
    yr=form.elements[yr];
    hdate=dy.value + '-';
    if(mon.value==1)
        hdate=hdate + 'Jan-';
    else if(mon.value==2)
        hdate=hdate + 'Feb-';
    else if(mon.value==3)
        hdate=hdate + 'Mar-';
    else if(mon.value==4)
        hdate=hdate + 'Apr-';
    else if(mon.value==5)
        hdate=hdate + 'May-';
    else if(mon.value==6)
        hdate=hdate + 'Jun-';
    else if(mon.value==7)
        hdate=hdate + 'Jul-';
    else if(mon.value==8)
        hdate=hdate + 'Aug-';
    else if(mon.value==9)
        hdate=hdate + 'Sep-';
    else if(mon.value==10)
        hdate=hdate + 'Oct-';
    else if(mon.value==11)
        hdate=hdate + 'Nov-';
    else
        hdate=hdate + 'Dec-';
    hdate=hdate + yr.value;
    form.elements[hidden].value=hdate;
}
function calc_date_refresh(form,fulldate,dy,mon,yr,hidden)
{
    yr=form.elements[yr];
    var a='' + form.elements[hidden].value;
    var pd=a.split('-');
    if (pd.length==3) 
    {
        if(pd[1]=='Jan')
            pd[1]=1;
        else if(pd[1]=='Feb')
            pd[1]=2;
        else if(pd[1]=='Mar')
            pd[1]=3;
        else if(pd[1]=='Apr')
            pd[1]=4;
        else if(pd[1]=='May')
            pd[1]=5;
        else if(pd[1]=='Jun')
            pd[1]=6;
        else if(pd[1]=='Jul')
            pd[1]=7;
        else if(pd[1]=='Aug')
            pd[1]=8;
        else if(pd[1]=='Sep')
            pd[1]=9;
        else if(pd[1]=='Oct')
            pd[1]=10;
        else if(pd[1]=='Nov')
            pd[1]=11;
        else
            pd[1]=12;
        form.elements[dy].selectedIndex=pd[0]-1;
        form.elements[mon].selectedIndex=pd[1]-1;

        for(var i=0;i<yr.length;i++)
        {
            if(yr[i].value == pd[2])
            {
                yr.selectedIndex=i;
                break;
            }
        }
        if(i==yr.length)
        {
            yr.options[i] = new Option(pd[2]);
            yr.options[i].value = pd[2];
            yr.selectedIndex=i;
        }

    }

    form.elements[fulldate].value=pd[0] + '/' + pd[1] + '/' + pd[2];
    form.elements[hidden].value=" V ";
}

    //-->