//****************************************************
//ALL CODE COPYRIGHT PETER DOBBIE & NEIL FAICHNEY 2001
//****************************************************

function updateCart( theform, itemstr )
{
  var newCookie = 'iceitems=';
  if( itemstr )
  {
    var items = new Array();
    items = itemstr.split( ':' );
    for( var i = 0; i < items.length; i++ )
    {
      if( eval( 'theform.q' + items[i] + '.value' ) > 0 )
      {
        if( newCookie.indexOf( ':' ) != -1 )	// we have at least one item already
          newCookie += ':';
        newCookie += items[i] + ':' + eval( 'theform.q' + items[i] + '.value' );
      }
    }
  }

  if( newCookie.indexOf( ':' ) == -1 )
  {
    var gone = new Date( 2000, 1, 1 );
    newCookie = "iceitems=none; expires=" + gone;
  }

  document.cookie = newCookie;
}

function clearCart()
{
  var gone = new Date( 2000, 1, 1 );
  var newCookie = "iceitems=none; expires=" + gone;

  document.cookie = newCookie;
}

function addItem( item, qty )
{
  var cookies = new Array();
  cookies = document.cookie.split( ';' );

  var isNewItem = true;
  var newCookie = '';
  var i, j;
  for( i = 0; i < cookies.length; i++ )
  {
    var cookie = new Array();
    cookie = cookies[i].split( '=' );
    if( cookie[0].indexOf( 'iceitems', 0 ) >= 0 )
    {
      var items = new Array();
      items = cookie[1].split( ':' );
      for( j = 0; j < items.length; j = j + 2 )
      {
        if( items[j] == item )
        {
          isNewItem = false;
          items[j+1] = Number( items[j+1] ) + Number( qty );
        }

	if( newCookie == '' )
	  newCookie += 'iceitems=';
	else
	  newCookie += ':';
	newCookie += items[j] + ':' + items[j+1];
      }
    }
  }

  if( isNewItem )
  {
    if( newCookie == '' )
      newCookie += 'iceitems=';
    else
      newCookie += ':';
    newCookie += item + ':' + qty;
  }

  document.cookie = newCookie;
}

function mOvr(src,clrOver){
	if (!src.contains(event.fromElement)){
		src.style.cursor = 'hand';
		src.bgColor = clrOver;
	}
}

function mOut(src,clrIn){
	if (!src.contains(event.toElement)){
		src.style.cursor = 'default';
		src.bgColor = clrIn;
	}
}

function mClk(src){
	if(event.srcElement.tagName=='TD')
		src.children.tags('A')[0].click();
}

function OpenWindow(theURL,winName,features) { //v2.0
	var winopen = window.open(theURL,winName,features);
	winopen.focus();
}

function showStatusMsg(msgStr) { //v1.0
	status=msgStr;
	document.returnValue = true;
}

function goToURL() { //v3.0
  var i, args=goToURL.arguments; document.returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

// ***** Tool Tip Code *****

if (!document.layers&&!document.all)
event="test"

function showtip(current,e,text)
{
  if (document.all)
  {
    thetitle=text.split('<br>')
    if (thetitle.length>1)
    {
      thetitles=''
      for (i=0;i<thetitle.length;i++)
      thetitles+=thetitle[i]
      current.title=thetitles
    }
    else current.title=text
  }
  else if (document.layers)
  {
    document.tooltip.document.write('<layer bgColor="white" style="border:1px solid black;font-size:12px;">'+text+'</layer>')
    document.tooltip.document.close()
    document.tooltip.left=e.pageX+5
    document.tooltip.top=e.pageY+5
    document.tooltip.visibility="show"
  }
}

function hidetip()
{
  if (document.layers)
  document.tooltip.visibility="hidden"
}

// ***** End Tool Tip Code *****

function addhtml(form,fieldName,htag,htagplus)
{
  var SelectedString = document.selection.createRange().text;  //put the selected text string into a variable & procede if it's not empty
  if (SelectedString != "" && lastfocus == fieldName)
  {
      var ReplaceString = "<"+htag+""+htagplus+">"+SelectedString+"</"+htag+">";  //Put the required tags around our string  
      document.selection.createRange().text = ReplaceString;  //assign the replace string value to the selected string
  }
  else alert("Please select some text first.");
}

function striptags(fieldName)
{
  window.document.forms['form1'].elements[fieldName].value = window.document.forms['form1'].elements[fieldName].value.replace( /<[^>]*>/g, '' );
}

function storeCaret(textEl)
 {
  if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
 }

function insertAtCaret (textEl, htag, fieldName)
{
  var SelectedString = document.selection.createRange().text;
  if (textEl.createTextRange && textEl.caretPos && lastfocus == fieldName)
  {
    if (SelectedString != "")
    {
      if (confirm ("Are you sure you want to replace the selected text with this element?"))
      {
        var caretPos = textEl.caretPos;
        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?text + ' ' : htag;
      }
    }
    else 
    {
      var caretPos = textEl.caretPos;
      caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?text + ' ' : htag;
    }
  }
  else alert("Please select the position where you would like this element to appear.");
 }

function submitForm(button,labelmsg)  
 {
  //form1.elements[button].value = labelmsg;
  eval('form1.'+button+'.value = labelmsg;');
  return true;
  //var check = 'yes';
 }

var lastfocus = '';

function setfocus(element)
 {
  lastfocus = element;
 }

var lastchange = false;

function setchange(element, changed)
 {
  lastchange = changed;
  if (document.all) 
   {
    document.all.save.style.visibility="visible";
    document.all.save1.style.visibility="visible";
   }

  else if (document.layers) 
   {
    document.layers["save"].visibility="visible";
    document.layers["save1"].visibility="visible";
   }
 }

function checkchange(href)
{
if (lastchange) // If there has been a change somewhere on the page
  if (confirm("There appear be changes to this page that have not yet been applied.\nAre you sure you wish to leave without applying?")) 
window.location.href = href;
  else lastchange = true;
else window.location.href = href;
}

function nowloaded() 
{
  if (document.all) document.all.wait.style.visibility="hidden";

  else if (document.layers) document.layers["wait"].visibility="hidden";
}

function nowsending() 
{
  if (document.all)
  {
    document.all.applybutton.style.visibility="hidden";
    document.all.applymsg.style.visibility="visible";
  }
  else if (document.layers) 
  {
    document.layers["applybutton"].visibility="hidden";
    document.layers["applymsg"].visibility="visible";
  }
}

function uploading() 
{
  if (document.all) {
   document.all.uploading1.style.visibility="visible";
   document.all.uploading2.style.visibility="visible";
  }

  else if (document.layers) {
   document.layers["uploading1"].visibility="visible";
   document.layers["uploading2"].visibility="visible";
  } 
}
