var ct4GalImg = 0;
var currentImg = 0;
var ct4Evt = 0;
var currentEvt = 0;
var galleryImages = new Array()
var upcomingEvts = new Array()

var amountDue = 0;
var cashDisply;
var total = 0;
var prodTxt ="";


function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}
function toggle(obj) {
	var el = $(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}



function galleryImage (title, location, date, size, description, id,galorevent)
{
this.title = title;
this.location = location;
this.date = date;
this.size = size;
this.desc = description;
this.id = id;
if (galorevent == 'evt')
	{
	this.fileName = ("images/bkg_upcoming_"+id+".gif")
	}
else{
	this.fileName = ("images/g_"+imgBase+"_"+id+".jpg")
	}
}


function swapBkg(div,img)
{
div.style.backgroundImage = ("url("+img+")");
}

function swapImage(id,img)
{
var thisImage = $(id);
thisImage.src = img;

}

function innerHtml (div,txt)
{
div.innerHTML = (txt);
}

var cssLink;
var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
if (IE6 == true)
	{
	cssLink = $("style")
	cssLink.href = "css/common4ie6.css";
	}
	


//inc_purchase scripts
function isEmpty(s)
{
return ((s == null) || (s.length == 0) || (Trim(s) == ""));
}
var xfield = "";
//remove spaces, remove $, remove .00
function Trim(s)
{

var bTrailing = false;


// first check for leading spaces
for (i = 0; i < s.length; i++)
	{

	if (bTrailing || ((!bTrailing && s.substr(i, 1) != " ")&&(s.substr(i, 1) != "$")))
		{
		bTrailing = true;
		xfield = xfield + s.substr(i, 1);
		}
	}

// now do trailing
for (i = xfield.length-1; i >= 0; i--)
	{
// find last non-space
	if (xfield.substr(i, 1) != " ")
		{
		xfield = xfield.substring(0, i+1);
		break;
		}
	}
return xfield;
}

function calc(entry) {
var form = document.ppform;
var fieldname=entry.name
var fieldvalue=entry.value
//alert(lamt+fieldname+fieldvalue)
if(!isEmpty(fieldvalue)){
	updateAmount ( fieldname , xfield )
	}

}




















	
function updateAmount (id, amount)
{
//find feild check if selected if yes add else subtract
//figure total
//play amount
cashDisply = document.getElementById('cash');
//cashDisply = $('cash');
var chkBox = ($(id));
if (id == "invasionfinal")
	{
		
		total = (amount)
	}
else if (chkBox.checked)
	{
	total = (total+amount)
	}	
else
	{
	total = (total-amount)
	}
buildForm (id)
if (!amount.indexOf(".00")){
	//dont add .00 to sting
cashDisply.innerHTML = ("Total: $"+total+".00")	
	}
	else{
	cashDisply.innerHTML = ("Total: $"+total)
	}
}
function buildForm (id)
{
var itemTitle = ($(id+"txt"));
var itemTitleTxt = (itemTitle.innerHTML);
var redirect = ($('return'));
var formItemName = ($('item_name'));
var formPrice = ($('amount'));
var formNewsltr = ($('os0'));
var newsLetter = ($('newsltrchbx'));
var digiNeg = ($('dneg'));
var kingWS = ($('altprows'));
if (prodTxt =="")
	{
	prodTxt = itemTitleTxt
	}
else {prodTxt +=", "+ itemTitleTxt}


formItemName.value = prodTxt
if (!total.indexOf(".00")){
	//dont add .00 to sting
	formPrice.value = (total+".00")
	}
	else{
	formPrice.value = (total)
	}

redirect.value = ("http://www.elevatorworkshops.com/thankyou.html?"+prodTxt)
}







function galImage (div, dir)
{
var button = ($(dir))
var newImg;
if (dir == 'pgup')
	{
	currentImg++
		if (currentImg == ct4GalImg)
		{
		button = ($(dir))
		toggle(button)
		button = ($('pgdown'))
		button.style.margin = "0 0 0 25px"
		}
		else if (currentImg == 1)
		{
		button = ('pgdown')
		toggle(button)
		}
	}
else
	{
	currentImg--
		if (currentImg==0)
		{
		button = ($(dir))
		toggle(button)
		}
		else if (currentImg == (ct4GalImg-1))
		{
		button = ($('pgup'))
		toggle(button)
		button = ($(dir))
		button.style.margin = "0"
		}
	
	}
galleryDisplay ()
}

function evtImage (div, dir)
{
var button = ($(dir))
var newImg;
if (dir == 'evtup')
	{
	currentEvt++
		if (currentEvt  == ct4Evt )
		{
		
		button = ($(dir))
		toggle(button)
		button = ($('evtdown'))
		button.style.margin = "0 0 0 25px"
		}
		else if (currentEvt == 1)
		{
		button = ('evtdown')
		toggle(button)
		}
	}
else
	{
	currentEvt--
		if (currentEvt==0)
		{
		button = ($(dir))
		toggle(button)
		}
		else if (currentEvt == (ct4Evt-1))
		{
		button = ($('evtup'))
		toggle(button)
		button = ($(dir))
		button.style.margin = "0"
		}
	
	}
evtDisplay ()
}






function galleryDisplay ()
{
//find info
//find div
var imgDiv = $('galimg');
var txtDiv = $('galtext');
var img = (galleryImages[currentImg].fileName)
var txt = ("<address><strong>"+galleryImages[currentImg].title+"</strong><br/>")
txt += (galleryImages[currentImg].size+"<br/>");
txt += ("<em>"+galleryImages[currentImg].location+" "+galleryImages[currentImg].date+"</em><br/>");
txt += (galleryImages[currentImg].desc+"</address>");
swapBkg(imgDiv,img)
innerHtml (txtDiv,txt)
}




function evtDisplay ()
{
//find info
//find div
var imgDiv = $('evtimg');
var txtDiv = $('evttext');
var img = (upcomingEvts[currentEvt].fileName)
var txt = ("<address><strong>"+upcomingEvts[currentEvt].title+"</strong><br/>")
txt += (upcomingEvts[currentEvt].size+"<br/>");
txt += ("<em>"+upcomingEvts[currentEvt].location+" "+upcomingEvts[currentEvt].date+"</em><br/>");
txt += (upcomingEvts [currentEvt].desc+"</address>");
swapBkg(imgDiv,img)
innerHtml (txtDiv,txt)
}
