//######################################################################
//# Mearns Services Shopping Cart Version 1.1
//# Copyright 1999 Gordon Smith   Mearns@mearns.org.uk
//# Created 30 June 1999          Last Modified 26th Oct 1999
//# WWW Link:                     http://www.mearns.org.uk
//######################################################################
//# COPYRIGHT NOTICE
//# Copyright 1999 Mearns Services - Gordon Smith   All Rights Reserved. 
//######################################################################


// Flash Version Detector  v1.1.4
// http://www.dithered.com/javascript/flash_detect/index.html
// code by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)
// with VBScript code from Alastair Hamilton

var flashVersion = 0;
function getFlashVersion() {
	var agent = navigator.userAgent.toLowerCase(); 
	
	// NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object') { 
			if (flashPlugin.description.indexOf('7.') != -1) flashVersion = 7;
			else if (flashPlugin.description.indexOf('6.') != -1) flashVersion = 6;
			else if (flashPlugin.description.indexOf('5.') != -1) flashVersion = 5;
			else if (flashPlugin.description.indexOf('4.') != -1) flashVersion = 4;
			else if (flashPlugin.description.indexOf('3.') != -1) flashVersion = 3;
		}
	}

	// IE4+ Win32:  attempt to create an ActiveX object using VBScript
	else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
	  document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('dim obFlash \n');
		document.write('set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.7") \n');
		document.write('if IsObject(obFlash) then \n');
		document.write('flashVersion = 7 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.6") end if \n');
		document.write('if flashVersion < 7 and IsObject(obFlash) then \n');
		document.write('flashVersion = 6 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.5") end if \n');
		document.write('if flashVersion < 6 and IsObject(obFlash) then \n');
		document.write('flashVersion = 5 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.4") end if \n');
		document.write('if flashVersion < 5 and IsObject(obFlash) then \n');
		document.write('flashVersion = 4 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.3") end if \n');
		document.write('if flashVersion < 4 and IsObject(obFlash) then \n');
		document.write('flashVersion = 3 \n');
		document.write('end if');
		document.write('</scr' + 'ipt\> \n');
  }
		
	// WebTV 2.5 supports flash 3
	else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;

	// older WebTV supports flash 2
	else if (agent.indexOf("webtv") != -1) flashVersion = 2;

	// Can't detect in all other cases
	else {
		flashVersion = flashVersion_DONTKNOW;
	}

	return flashVersion;
}

flashVersion_DONTKNOW = -1;

// END FLASH DETECT CODE

//This Shopping Cart has also been customised by Artistscope for 
//distribution under licence to the original author Gordon Smith. 
//Copyright of the Shopping Cart is that case is Artistscope-Gordon Smith. 
//The unregistered, unauthorised use or redistribution of either Shopping 
//Cart system is strictly forbidden and offenders will be exposed and/or 
//prosecuted.

var mystate = "Not Selected";

 theStuff=""
 function startUp(){
 	theStuff=""
 	theStuff+="<script>\r"
 	theStuff+="	function stopErrors(){ \r"
 	theStuff+="		return true;"
 	theStuff+="} \r"
 	theStuff+="window.onerror=stopErrors\r"
 	theStuff+="</scr"
 	theStuff+="ipt>\r"
 	
 }
 
 	function objectTag(){
 		startUp()
 		return theStuff
 	
 	}
 	
order_total =0;  
item_num = 1
present_item = 1;
items_ordered = 0;
total_item_price =0;
maxarray = 50
var st_astr = '<html><body bgcolor=#ffffff>'
var en_astr = '</body></html>'
grand_total_again = 0;


function getCookie (name) {
var dcookie = document.cookie; 
var cname = name + "=";
var clen = dcookie.length;
var cbegin = 0;
        while (cbegin < clen) {
        var vbegin = cbegin + cname.length;
                if (dcookie.substring(cbegin, vbegin) == cname) { 
                var vend = dcookie.indexOf (";", vbegin);
                        if (vend == -1) vend = clen;
                return unescape(dcookie.substring(vbegin, vend));
                }
        cbegin = dcookie.indexOf(" ", cbegin) + 1;
                if (cbegin == 0) break;
        }
return null;
}

function setCookie (name, value, expires) {
        if (!expires) expires = new Date();
document.cookie = name + "=" + escape (value) + 
"; expires=" + expires.toGMTString() +  "; path=/";
}

function delCookie (name) {
var expireNow = new Date();
document.cookie = name + "=" +
"; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}

var shiparray =  new parent.createArray(10);

function getCookieArray(name){
var i = 0;
        while (getCookie(name + i) != null) {
        shiparray[i + 1] = getCookie(name + i);
        i++;
		shiparray.length = i; 
        }
}

 var expdate = new Date();
 
 expdate.setTime (expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 

function setCookieArray(name){
    temp_length = setCookieArray.arguments.length - 1;
        for (var i = 0; i < temp_length; i++) {
        data = setCookieArray.arguments[i + 1]
        setCookie (name + i, data, expdate);
        }        
    }
	



function go_with_cookie()
{
setCookieArray('gifttails',
parent.ship_details.f_namea,
parent.ship_details.l_namea,
parent.ship_details.email,
parent.ship_details.ad_onea,
parent.ship_details.ad_twoa,
parent.ship_details.citya,
parent.ship_details.statea,
parent.ship_details.countrya,
parent.ship_details.zipa);
}









function get_that_cookie()
{
var i;
getCookieArray('gifttails');
//alert('shiparray.length = '+ shiparray.length);
for (i=0;i<shiparray.length+1;i++)
    {if (shiparray[i])
	  { //alert('ship_array[' + i + '] ='+ shiparray[i]);
        ship_details[i]  = shiparray[i];
		//alert('ship_details[' + i + '] ='+ ship_details[i]);
	  }
	  else
	  {// to initiate array values
	   ship_details[i] = ''
	  }
    }
	
parent.ship_details.f_namea = ship_details[1];
parent.ship_details.l_namea = ship_details[2];
parent.ship_details.email = ship_details[3];
parent.ship_details.ad_onea = ship_details[4];
parent.ship_details.ad_twoa = ship_details[5];
parent.ship_details.citya = ship_details[6];
parent.ship_details.statea = ship_details[7];
parent.ship_details.countrya = ship_details[8];
parent.ship_details.zipa = ship_details[9];
	
//alert('shiparray length= ' + shiparray.length + '\nshiparray[1] = ' + shiparray[1] + '\nshiparray[2] = ' + shiparray[2] + '\nshiparray[3] = ' + shiparray[3] + '\nshiparray[4] = ' + shiparray[4] + '\nshiparray[5] = ' + shiparray[5] + '\nshiparray[6] = ' + shiparray[6] + '\nshiparray[7] = ' + shiparray[7] + '\nshiparray[8] = ' + shiparray[8]);
}


// shipping details object creation

ship_details = new shipp_details();

function shipp_details()
{

this.f_namea = ''
this.l_namea= ''
this.ad_onea = ''
this.ad_twoa = ''
this.citya = ''
this.statea =''
this.zipa = ''
this.countrya = ''
this.phonea = ''
this.faxa = ''
this.mailon = false
this.sameflag = false
this.shipname=''
this.ad_oneb = ''
this.ad_twob=''
this.shipb = ''
this.stateb=''
this.zipb=''
this.countryb=''
this.phoneb=''
this.faxb=''
this.email=''
this.comments = ''
}


function refresh_ship_details(shipform)
{
parent.MainFrame.document.order.comments.value = shipform.comments
parent.MainFrame.document.order.name_first.value= shipform.f_namea
parent.MainFrame.document.order.name_last.value= shipform.l_namea
parent.MainFrame.document.order.email.value=shipform.email
parent.MainFrame.document.order.address1.value=shipform.ad_onea
parent.MainFrame.document.order.address2.value=shipform.ad_twoa
parent.MainFrame.document.order.city.value=shipform.citya
parent.MainFrame.document.order.state.value=shipform.statea
parent.MainFrame.document.order.zip.value=shipform.zipa
parent.MainFrame.document.order.country.value=shipform.countrya
parent.MainFrame.document.order.phone.value=shipform.phonea
parent.MainFrame.document.order.fax.value=shipform.faxa
parent.MainFrame.document.order.mail_list.value=shipform.mailon
parent.MainFrame.document.order.same_flag.value=shipform.sameflag
parent.MainFrame.document.order.ship_name.value=shipform.shipname
parent.MainFrame.document.order.ship_address1.value=shipform.ad_oneb
parent.MainFrame.document.order.ship_address2.value=shipform.ad_twob
parent.MainFrame.document.order.ship_city.value=shipform.shipb
parent.MainFrame.document.order.ship_state.value=shipform.stateb
parent.MainFrame.document.order.ship_zip.value=shipform.zipb
parent.MainFrame.document.order.ship_country.value=shipform.countryb
parent.MainFrame.document.order.ship_phone.value=shipform.phoneb

}

function add_ship_details(shipform)
{

shipform.comments = parent.MainFrame.document.order.comments.value
shipform.f_namea = parent.MainFrame.document.order.name_first.value
shipform.l_namea= parent.MainFrame.document.order.name_last.value
shipform.email = parent.MainFrame.document.order.email.value
shipform.ad_onea = parent.MainFrame.document.order.address1.value
shipform.ad_twoa = parent.MainFrame.document.order.address2.value
shipform.citya = parent.MainFrame.document.order.city.value
shipform.statea =parent.MainFrame.document.order.state.value
shipform.zipa = parent.MainFrame.document.order.zip.value
shipform.countrya =parent.MainFrame.document.order.country.value
shipform.phonea = parent.MainFrame.document.order.phone.value
shipform.faxa = parent.MainFrame.document.order.fax.value
shipform.mailon = parent.MainFrame.document.order.mail_list.value
shipform.sameflag = parent.MainFrame.document.order.same_flag.value
shipform.shipname=parent.MainFrame.document.order.ship_name.value
shipform.ad_oneb = parent.MainFrame.document.order.ship_address1.value
shipform.ad_twob=parent.MainFrame.document.order.ship_address2.value
shipform.shipb = parent.MainFrame.document.order.ship_city.value
shipform.stateb=parent.MainFrame.document.order.ship_state.value
shipform.zipb=parent.MainFrame.document.order.ship_zip.value
shipform.countryb=parent.MainFrame.document.order.ship_country.value
shipform.phoneb=parent.MainFrame.document.order.ship_phone.value
}

// end of shipping details object handling

function item_tot_price(i)
{
 total_item_price = eval((itemlist[i].price * itemlist[i].quan));
 return total_item_price;
}

function all_order_totals()

{order_total = 0;
if (item_num > 0)
 {  
for (i =1;i < item_num;i++)
 {order_total = order_total + item_tot_price(i)}
   
 } return order_total;
}

function remove_nil_items(inputlist)
{var i = 0; 
 var j = 1; 
  for (i=1;i<item_num;i++)
   {if (itemlist[i].quan != 0)
    {temp_array[j]=itemlist[i]
     items_ordered =j 
     j=j+1
     } 
   } 
  itemlist = temp_array
  item_num = items_ordered + 1
}

function update_this_page()
{
var i = 0; 
var k = 0; 
 {for (i = 0;i < parent.MainFrame.document.form1.elements.length;i++)
  {for (k=1;k<=items_ordered;k++)
   {
if ((itemlist[k].code ==  parent.MainFrame.document.form1.elements[i].name) && (k<=items_ordered) && (i<=parent.MainFrame.document.form1.elements.length))
         if (itemlist[k].quan > 0) {
         parent.MainFrame.document.form1.elements[i].value = itemlist[k].quan
           }
         else {
         parent.MainFrame.document.form1.elements[i].value = '';
           }
   }
  }
 }   
}

function item_quan(code)
{
var loc = check_if_in(code)
if (loc > 0)
 var quantities = itemlist[loc].quan
else
 var quantities = 0;
return quantities
}

function display_pic(graphic,price)
{
parent.frames[0].document.close()
// parent.frames[1].document.open()
parent.frames[0].document.write(st_astr);
parent.frames[0].document.write('<img src=images/' + graphic + '><br>' + price);
parent.frames[0].document.write('<p><a href="javascript:parent.updatenav_nav()">Navigation Table</a>');
parent.frames[0].document.write(en_astr);
parent.frames[0].document.close()
}

function createArray(n)
//n		size of array
//init	what you want all values initialized to
{               this.length = n
		var i = 0
		for (i = 1 ; i < n ; i++) 
			this[i] = null;	
                return this
}


function product(code,price,desc,quan,url)
{ this.price = 0
  this.code = code
  this.price = price
  this.desc = desc
  this.quan = quan
  this.url = url
 return this;
}

var itemlist = new createArray(50);
var temp_array = new createArray(50);

function initialize_arrays(arraysa)
{
for (i = 1;i < maxarray;i++)
{
arraysa[i] = new product('',0,'',0,'')
}
}

function updatemain_order()
{
//alert('index-updatemain_order');
parent.frames[1].document.close()
// parent.frames[1].document.open()
parent.frames[1].location = "order.html";
parent.frames[1].document.close()
}

function updatenav_nav()
{
  parent.frames[0].document.close()
  // parent.frames[0].document.open()
  parent.frames[0].location = "navigate.html";
  parent.frames[0].document.close()
}

function check_if_in(code_check) // this works
{
var i = 1
loc = 0;
// line 47
while ((i < item_num) && (itemlist[i].code != code_check))
  i = i + 1;
   if (itemlist[i].code == code_check)
    loc = i
   else
    loc = -1;
//alert('loc is ' + loc);
return loc;
}


function additem(codes,prices,descrip,url)
{
//alert('additem');
//alert(codes + ' ' + prices + ' ' + descrip + ' ' + url);
// adds another item to a variable length array
// remember to do it via new product()
// line 61
loc = check_if_in(codes)
// present_item = item_num
//last_item = item_num;
//alert('item_num = ' + item_num)

if (loc != -1){
  // update existing item
  olditem =  itemlist[loc].quan
  //alert(' loc is before oldvalue ' + loc);
  //alert('olditem is ' + olditem);
  itemlist[loc] = new product(codes,prices,descrip,olditem + 1,url)}
    else // new item
    {olditem =  itemlist[item_num].quan
    itemlist[item_num] = new product(codes,prices,descrip,olditem + 1,url);
    items_ordered = item_num
    item_num = item_num + 1
     }
    remove_nil_items(itemlist)
     
   
 }
// line 78

function subitem(codes,prices,descrip,url)
{
loc = check_if_in(codes)
if ((loc != -1) && (itemlist[loc].quan > 0)) {
  // update existing item
  olditem =  itemlist[loc].quan
  //alert(' loc is before oldvalue ' + loc);
  //alert('olditem is ' + olditem);
  itemlist[loc] = new product(codes,prices,descrip,olditem - 1,url)}
  //updatepage(codes) 
  
}




initialize_arrays(itemlist)
initialize_arrays(temp_array)

function check_window()
{

alert('check window');

if (self == mainbody)
{document.write('<head><META HTTP-EQUIV="Refresh" CONTENT="15; URL=cart.html"></head><body><center><h1>Warning!</h1><br><font color=#ff000><b>This is inside a multiple frame window.<br>The scripts may not work correctly!!!!,</font><BR>We are jumping you directly to our <a href="cart.html" target=_top>Main page</a> in 15 seconds.</center>');

self.location = "cart.html";
parent.document.close();

}

}

 function popupWindow(thefile)

	{
	mapWindow = window.open(thefile,'mapWin','scrollbars=yes,width=300,height=300')
	}

	


function displayCart()
{
index = 0;
astring_intermediate = '';
for (i =1;i < item_num;i++)
   {
   
   if (itemlist[i].quan > 0)
     {index = index + 1;
astring_intermediate = itemlist[i].desc + '=' + itemlist[i].quan + '&' +  astring_intermediate;
     }
   }


//alert('astring intermediate = ' + astring_intermediate);
astring = astring_intermediate;
astr = 'cart.html' + '?' + astring
//astr = 'cart.html'
//alert('astr = ' + astr);
//this.form.submit();
popupWindow(astr)
}

