var basket_count=0;
var imgstore=new Object;
var imgcount=0;
var all_checked=false;
var ns4=(document.layers) ? 1 : 0;
var ie4=(document.all) ? 1 :0;
var rnd1=Math.round(Math.random()*100000);
var rot=0;
var sstd_form=0;


function setbasketcount(cnt)
{
	basket_count=cnt;
	doloaded();
	showbasketcount();
	if(window.runinit1)init1();
}

function showbasketcount()
{
	if(document.getElementById)
	{
		if(document.getElementById('basketitems'))document.getElementById('basketitems').innerHTML='&nbsp;Items: ' + basket_count;
	}
	else if(document.all)
	{
		if(document.all.basketitems)document.all.basketitems.innerHTML='i&nbsp;Items: ' + basket_count;
	}
}


function incbasketcount()
{
	basket_count++;
	showbasketcount();
}

function bigaddtobasket(which)
{
	imgstore[imgcount]=new Image;
	pro=document.toolbarform.tb_product.options[document.toolbarform.tb_product.selectedIndex].value;
	if(document.toolbarform.tb_quantity)qty=document.toolbarform.tb_quantity.value;
	else qty=1;
        imgstore[imgcount++].src='/lib/addtobasket' + rnd1 + '.gif?ph=' + which + '&q=' + qty + '&pr=' + pro;
//	document.images["bk"+which].src='/sg/1/group/add_to_basketon.gif';
	alert('This photo has been added to your shopping basket. \nYou can change the print size and number of prints from the\n view basket screen');
	incbasketcount();
}

function addtobasket(which,showalert,product)
{
        if(basket_count>=999)
        {
                alert('You can not have more than 999 items in your shopping basket');
                return;
        }
        rnd1=Math.round(Math.random()*100000)
        imgstore[imgcount]=new Image;
        imgstore[imgcount++].src='/lib/addtobasket' + rnd1 + '.gif?ph=' + which + '&pr='+product;
        document.images["bk"+which].src='/sg/1/basketon.gif';
	if(showalert==1)alert('This photo has been added to your shopping basket. \nYou can change the print size and number of prints from the\n view basket screen');
	incbasketcount();
}

function atbox(attrib)
{
        var na=0;
        d=document.photo_form.elements;
	numchecked=countchecked();
	if(!numchecked)
	{
		alert("You haven't checked any photos");
		return;
	}
	
        for(i=0;i<d.length;i++)
        {
						if (!d[i].name) continue; // some form elements have no name (e.g. fieldsets)
                if(d[i].name.substring(0,9)=='c_checked' && (d[i].checked || document.photo_form.c_quantity.value=='scaled'))
                {
			rnd1=Math.round(Math.random()*100000);
                        which=d[i].name.substring(9,d[i].name.length);
			if(document.photo_form.c_quantity.value=='scaled')
                        document.images["th"+which].src='/lib/addtobasket' + rnd1 + '.gif?ph=' + which + '&s=1&a=attrib&v=' + attrib;
                        else document.images["th"+which].src='/lib/addtobasket' + rnd1 + '.gif?ph=' + which + '&a=attrib&v=' + attrib;
                        na++;
                }
        }
	if(numchecked>1)alert('Your photos are being rotated.\nThis may take some time for large albums.');
}

function ck()
{
        all_checked=!all_checked;
        d=document.photo_form.elements;
        for(i=0;i<d.length;i++) {
					if(!d[i].name) continue; // some form elements have no name (e.g. fieldsets)
					if(d[i].name.substring(0,9)=='c_checked')d[i].checked=all_checked;
				}
  if(all_checked)
	{
		document.images.checkp.src="/sg/1/icons/select_on.gif"
		if(document.all)document.all.seltext.innerText='Deselect all';
	}
        else 
	{
		document.images.checkp.src="/sg/1/icons/select.gif";
		if(document.all)document.all.seltext.innerText='Select all';
	}
}

function countchecked()
{
	
	if(document.photo_form.c_quantity.value=='scaled')return(1);
	d=document.photo_form.elements;
	num_checked=0;
	for(i=0;i<d.length;i++) {
		if (!d[i].name) continue; // some form elements have no name (e.g. fieldsets)
		if(d[i].name.substring(0,9)=='c_checked' && d[i].checked)num_checked++;
	}
	return(num_checked);
}

function delcheck(prphoto)
{
	na=0;
	var yesno=0;
	document.photo_form.t_basket.value=0;
	document.photo_form.t_album.value=0;
	document.photo_form.xdel.value=1;
	d=document.photo_form.elements;
	na=countchecked();
	if(prphoto!=1 && na>0)document.photo_form.submit();
	if(na==1)yesno=confirm('Are you sure you want to delete this photo?\nYou will not be able to get it back afterwards.');
	else if(na>0)yesno=confirm('Are you sure you want to delete these ' + na + ' photos?\nYou will not be able to get them back afterwards.');
	else
	{
		alert('You have not selected any photos to delete');
		return;
	}
	if(yesno)document.photo_form.submit();
	return;
}

function basketbox()
{
//	if(countchecked() + bcount>[+ $basket->{max_items} +])
//	{
//		alert('You can not have more than [+ $basket->{max_items} +] items in your shopping basket');
//		return;
//	}
	if(!countchecked())
	{
		alert("You haven't checked any photos to add to your basket");
		return;
	}
	document.photo_form.t_basket.value=1;
	document.photo_form.c_quantity.value=document.toolbarform.tb_quantity.value;
	document.photo_form.c_product.value=document.toolbarform.tb_product.options[document.toolbarform.tb_product.selectedIndex].value;
	document.photo_form.t_style.value=document.toolbarform.c_style.options[document.toolbarform.c_style.selectedIndex].value;
	document.photo_form.submit();
	if(countchecked()>1)alert('These photos are being added to your shopping basket.\nThis action may take several seconds to complete');
	else alert('This photo is being added to your shopping basket.');
}

function newmovebox()
{
	if(!countchecked())
	{
		alert("You haven't checked any photos");
		return;
	}
	document.photo_form.t_album.value=document.toolbarform.tb_toalbum.options[document.toolbarform.tb_toalbum.selectedIndex].value;
	document.photo_form.submit();
}

function addtogroup()
{
	if(!countchecked())
	{
		alert("You haven't checked any photos");
		return;
	}
	document.photo_form.t_album.value=document.toolbarform.tb_toalbum.options[document.toolbarform.tb_toalbum.selectedIndex].value;
	document.photo_form.c_product.value=document.toolbarform.tb_groupproduct.options[document.toolbarform.tb_groupproduct.selectedIndex].value;
	document.photo_form.c_quantity.value="addtogroup";
	document.photo_form.submit();
	if(countchecked()>1)alert('These photos are being added to your group product.\nThis action may take several seconds to complete');
	else alert('This photo is being added to your group product.');
}


function loadscaled(which,next_id)
{
	rnd1=Math.round(Math.random()*100000);
        document.images["th"+which].src='/lib/addtobasket' +rnd1 + '.gif?a=loadscaled&ph=' + next_id;
	document.photo_form.c_photo.value=next_id;
}

function changephoto(is_static)
{
	if(is_static==1)
	{
		location.href=document.toolbarform.tb_tophoto.options[document.toolbarform.tb_tophoto.selectedIndex].value;
	}
	else
	{
		next_id=document.toolbarform.tb_tophoto.options[document.toolbarform.tb_tophoto.selectedIndex].value;
		document.photo_form.c_photo.value=next_id;
		document.photo_form.submit();
	}
}


function vpopup(url)
{
        window.open(url, "Info", "left=50,top=50,width=400,height=300,scrollbars,menubar=no,status=no,resizable=no,toolbar=no");
}

function doloaded()
{
	if(sstd_form==1) sstd();
}

function slideshow(album)
{
	//window.open('/slideshow/index.html?c_album=' + album,'Slideshow','left=50,top=20,width=600,height=680,scrollbars=no,menubar=no,status=no,resizable=yes,toolbar=no');
	window.open('/slideshow/viewer.html?c_album=' + album,'Slideshow','left=50,top=20,width=700,height=500,scrollbars=no,menubar=no,status=no,resizable=yes,toolbar=no');
}
