/***********************************************
* Fading Scroller- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var delay = 5000; //set delay between message change (in miliseconds)
var maxsteps=30; // number of steps to take to change from start color to endcolor
var stepdelay=40; // time in miliseconds of a single step
//**Note: maxsteps*stepdelay will be total time in miliseconds of fading effect
var startcolor= new Array(255,255,255); // start color (red, green, blue)
var endcolor=new Array(0,0,0); // end color (red, green, blue)
var fwidth='260px'; //set scroller width
var fheight='75px'; //set scroller height

var fadelinks=1;  //should links inside scroller content also fade like text? 0 for no, 1 for yes.

var ie4=document.all&&!document.getElementById;
var DOM2=document.getElementById;
var faderdelay=0;
var index=0;


/*Rafael Raposo edited function*/
//function to change content
function changecontent(){
  if (index>=fcontent.length)
    index=0
  if (DOM2){
    document.getElementById("fscroller").style.color="rgb("+startcolor[0]+", "+startcolor[1]+", "+startcolor[2]+")"
    document.getElementById("fscroller").innerHTML=begintag+fcontent[index]+closetag
    if (fadelinks)
      linkcolorchange(1);
    colorfade(1, 15);
  }
  else if (ie4)
    document.all.fscroller.innerHTML=begintag+fcontent[index]+closetag;
  index++
}

// colorfade() partially by Marcio Galli for Netscape Communications.  ////////////
// Modified by Dynamicdrive.com

function linkcolorchange(step){
  var obj=document.getElementById("fscroller").getElementsByTagName("A");
  if (obj.length>0){
    for (i=0;i<obj.length;i++)
      obj[i].style.color=getstepcolor(step);
  }
}

/*Rafael Raposo edited function*/
var fadecounter;
function colorfade(step) {
  if(step<=maxsteps) {	
    document.getElementById("fscroller").style.color=getstepcolor(step);
    if (fadelinks)
      linkcolorchange(step);
    step++;
    fadecounter=setTimeout("colorfade("+step+")",stepdelay);
  }else{
    clearTimeout(fadecounter);
    document.getElementById("fscroller").style.color="rgb("+endcolor[0]+", "+endcolor[1]+", "+endcolor[2]+")";
    setTimeout("changecontent()", delay);
	
  }   
}

/*Rafael Raposo's new function*/
function getstepcolor(step) {
  var diff
  var newcolor=new Array(3);
  for(var i=0;i<3;i++) {
    diff = (startcolor[i]-endcolor[i]);
    if(diff > 0) {
      newcolor[i] = startcolor[i]-(Math.round((diff/maxsteps))*step);
    } else {
      newcolor[i] = startcolor[i]+(Math.round((Math.abs(diff)/maxsteps))*step);
    }
  }
  return ("rgb(" + newcolor[0] + ", " + newcolor[1] + ", " + newcolor[2] + ")");
}

var swidth=133; 
var sheight=150; 
var sspeed=2;
//var singletext=new Array();
//singletext[0]='yes';
//singletext[1]='test';
//if (singletext.length>1) i=1; else i=0;

function doAddToBasket (qtyField , productCode, unitCost) {
document.getElementById("loading").style.display="inline";
	unitCostNumber = parseFloat(unitCost);
	qtyNumber = parseFloat(document.forms[2].elements[qtyField].value);
	if (isNaN(qtyNumber)) {
		qtyNumber=0;
	}
	total = unitCostNumber * qtyNumber;
	query = document.forms[0].elements['order'].value;
	productList = query.substring(query.indexOf('=')+1,query.length);
	newProductList = '';
	isNewLine = 'YES';
	if (query.value != "") {
		BasketContents = productList.split('&');
		for (a=1; a < BasketContents.length; a++) {
			productFields = BasketContents[a].split('+');
			if (productFields[1] == productCode) {
				//add this quantity
				newQTY = parseFloat(productFields[0]) + qtyNumber;
				total = unitCostNumber * newQTY;
				newProductList = newProductList + '&' +newQTY.toString() + '+' + productFields[1] + '+'  + total;
				isNewLine = 'NO';
			} else {
				newProductList = newProductList + '&' +  productFields[0] + '+' + productFields[1] + '+'  + productFields[2] ;

			}
		}
	}
	if (isNewLine == 'YES') {
		newProductList = newProductList + '&' + document.forms[2].elements[qtyField].value+'+'+productCode+'+'+total;	

	}
	document.forms[0].elements['order'].value=newProductList;
	document.forms[0].submit();
	
}

function doRemoveFromBasket (productCode) {
document.getElementById("loading").style.display="inline";
	query = document.forms[0].elements['order'].value;
	productList = query.substring(query.indexOf('=')+1,query.length);
	newProductList = '';
	if (query.value != "") {
		BasketContents = productList.split('&');
		for (a=1; a < BasketContents.length; a++) {
			productFields = BasketContents[a].split('+');

			if (productFields[1] == productCode) {
				//skip this line
			} else {
				newProductList = newProductList + '&' +  productFields[0] + '+' + productFields[1] + '+'  + productFields[2] ;

			}
		}
	}
	document.forms[0].elements['order'].value=newProductList;
	document.forms[0].submit();
	
}

function start(){
	if (document.all){
		ieslider1.style.top=sheight;
		iemarquee(ieslider1);
	}
	else if (document.layers){
		document.ns4slider.document.ns4slider1.top=sheight;
		document.ns4slider.document.ns4slider1.visibility='show';
		ns4marquee(document.ns4slider.document.ns4slider1);
	}
	else if (document.getElementById&&!document.all){
		document.getElementById('ns6slider1').style.top=sheight;
		ns6marquee(document.getElementById('ns6slider1'));
	}
}

function iemarquee(whichdiv){
	iediv=eval(whichdiv);
	if (iediv.style.pixelTop>0&&iediv.style.pixelTop<=sspeed){
		iediv.style.pixelTop=0;
		setTimeout("iemarquee(iediv)",100);
	}
	if (iediv.style.pixelTop>=sheight*-1){
		iediv.style.pixelTop-=sspeed;
		setTimeout("iemarquee(iediv)",100);
	}
	else{
		iediv.style.pixelTop=sheight;
		iediv.innerHTML=singletext[i];
		if (i==singletext.length-1)
			i=0;
		else
			i++;
	}
}

function ns4marquee(whichlayer){
	ns4layer=eval(whichlayer);
	if (ns4layer.top>0&&ns4layer.top<=sspeed){
		ns4layer.top=0;
		setTimeout("ns4marquee(ns4layer)",100);
	}
	if (ns4layer.top>=sheight*-1){
		ns4layer.top-=sspeed;
		setTimeout("ns4marquee(ns4layer)",100);
	}else{
		ns4layer.top=sheight;
		ns4layer.document.write(singletext[i]);
		ns4layer.document.close();
		if (i==singletext.length-1)
			i=0;
		else
			i++;
	}
}

function ns6marquee(whichdiv){
	ns6div=eval(whichdiv);
	if (parseInt(ns6div.style.top)>0&&parseInt(ns6div.style.top)<=sspeed){
		ns6div.style.top=0;
		setTimeout("ns6marquee(ns6div)",100);
	}
	if (parseInt(ns6div.style.top)>=sheight*-1){
		ns6div.style.top=parseInt(ns6div.style.top)-sspeed;
		setTimeout("ns6marquee(ns6div)",100);
	}else{
		ns6div.style.top=sheight;
		ns6div.innerHTML=singletext[i];
		if (i==singletext.length-1)
			i=0;
		else
			i++;
	}
}

function computeForm(form) { 
	calcrate = (form.basictax.value / (100 - form.basictax.value))+1; 
	money= 100 * form.donation.value * calcrate; 
	money= (Math.round(money))/100; 
	form.amount.value = money 
}

function switchads() {
     var srctxt=document.getElementById('ad').src;
	var srctxt1=srctxt.split('_')
     var srctxt2=srctxt1[1].split('.')
	thenum=parseInt(srctxt2[0]);
	if (thenum>8) thenum=0;
	document.getElementById('ad').src=pics[thenum];
	document.getElementById('adslink').href=links[thenum];
	setTimeout('switchads()',5000);
}