var totalCost = new Array(10);
totalCost[0] = 0;
totalCost[1] = 0;
totalCost[2] = 0;
totalCost[3] = 0;
totalCost[4] = 0;
totalCost[5] = 0;
totalCost[6] = 0;
totalCost[7] = 0;
totalCost[8] = 0;
//do not use position 9, reserved for multiplication
totalCost[9] = 0;
var numberCost = 1; 

function eventTrigger (e) {
	if (! e)
		e = event;
	return e.target || e.srcElement;
}

function radioClick (e) {
	var obj = eventTrigger (e);
	setCost(costoptions[obj.id],costindex[obj.id]);
	return true;
}

function getCost(ctrlid,costindex)
{
	var el = document.getElementById(ctrlid);
	//alert(el.name + ' - ' + el.selectedIndex);
	setCost(costoptions["c" + el.selectedIndex + "o" + costindex], costindex);
}

function setCost(cst,index)
{
	var ttl = 0;
	totalCost[index] = cst;
	for(var i = 0; i < 8; i++)
	{
		ttl += totalCost[i];
	}
	ttl = ttl * numberCost;
	writeCost(ttl);
}			

function loadCost()
{
	var ttl = 0;
	for(var i = 0; i < 8; i++)
	{
		ttl += totalCost[i];
	}
	ttl = ttl * numberCost;
	writeCost(ttl);
}

function multiplyCost(num)
{
	numberCost = num;
	setCost(0,9);
}

function writeCost(ttl)
{
	var s = new String(ttl);
	if(s.indexOf('.') < 0) { s += '.00'; }	
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	var el = document.getElementById("totalCostH3");
	el.innerHTML = "Total Cost: $" + s;
}

function selectClip(clipId, clipName)
{
	var el = document.getElementById('txtClipArt');
	el.value = clipName;
	var el2 = document.getElementById('hClipId');
	el2.value = clipId;
	setClipArt('hClipId','uplFile',costoptions.hClipId,3)
}

function clearClipArt(sourceCtrl,index)
{
	var ctr = document.getElementById(sourceCtrl);
	ctr.value = '';
	var el = document.getElementById('hClipId');
	el.value = '';
	if (document.getElementById('uplFile').value == '') setCost(0,index);
	else setCost(costoptions.uplFile,index);
}

function setClipArt(sourceCtrl,clearCtrl,cst,index)
{
	var ctr = document.getElementById(sourceCtrl);
	if (ctr.value != '')
	{
		var el = document.getElementById(clearCtrl);
		el.value = '';
		if (clearCtrl == 'hClipId') document.getElementById('txtClipArt').value = '';
		setCost(cst,index);
	}
	else
	{
		if (document.getElementById('hClipId').value == '') setCost(0,index);
		else setCost(costoptions.hClipId,index);
	}
}

function sstchur_SmartScroller_GetCoords()
{
    var scrollX, scrollY;
    
    if (document.all)
    {
        if (!document.documentElement.scrollLeft)
        scrollX = document.body.scrollLeft;
        else
        scrollX = document.documentElement.scrollLeft;
            
        if (!document.documentElement.scrollTop)
        scrollY = document.body.scrollTop;
        else
        scrollY = document.documentElement.scrollTop;
    }   
    else
    {
        scrollX = window.pageXOffset;
        scrollY = window.pageYOffset;
    }

    document.forms[0].xCoordHolder.value = scrollX;
    document.forms[0].yCoordHolder.value = scrollY;
}

function sstchur_SmartScroller_Scroll()
{
    var x = document.forms[0].xCoordHolder.value;
    var y = document.forms[0].yCoordHolder.value;
    window.scrollTo(x, y);
}




