var cookie_name="iaorderform";

// strings

var button_del="delete";
var button_change="change";
var button_write="write";
var comment="of them";
var entry="Item ";

var confirm_del="Do you really want to delete this item?";
var dialog_comment="Please enter a the new number!";
var info_allreadyadded="This item is already on the order form!";
var confirm_delall="Do you really want to delete all items?";
var info_text="There are no items on the order form!";
info_text=info_text+"";
info_text=info_text+"";

// css vars
var css_delchange="textsmall";
var css_comment="textsmallred";
var css_info="textsmallred";
var css_entry="textsmallred";
var css_price="textnormalred";
var css_entry_headline="";


var img_delimiter="<img src='../img/line.jpg' width=351 height=1>";

function nmem(val01,val02) {
	
	var ck_i=0;var flag=false;var ckUtil = new CJL_CookieUtil( cookie_name,60,"/");

	while ( ckUtil.getSubValue(ck_i+"title") ) { 
		current_title=ckUtil.getSubValue(ck_i+"title");
		
		if (current_title == val01 )
			flag=true;
		ck_i++;	
	 }	

	if (flag==true) {
		alert(info_allreadyadded);
		window.open("shop_en/frameset.html", "IAPOPUP", "width=391,height=451,status=yes,scrollbars=yes");
	}
	else {
		//cleanup 'deleted'
		while ( ckUtil.getSubValue(ck_i+"title") ) {ck_i++;};
		ckUtil.setSubValue(ck_i+"title",val01);
		ckUtil.setSubValue(ck_i+"url",val02);
		ckUtil.setSubValue(ck_i+"note","1");
		window.open("shop_en/frameset.html", "IAPOPUP", "width=391,height=451,status=yes,scrollbars=yes");
	}
}	
	 
function nshow(){
	window.open("shop_en/frameset.html", "IAPOPUP", "width=391,height=451,status=yes,scrollbars=yes");
}	
	
function del(num) {
	if (confirm(confirm_del)){
	var ck_i=num; var ckUtil = new CJL_CookieUtil(cookie_name,60,"/");
	ckUtil.setSubValue(ck_i+"title","deleted");
	location.reload();}
}

function list()
{
				
	var ck_i=0;	var flag=false; num=1; var ckUtil = new CJL_CookieUtil(cookie_name,60,"/");
	while ( ckUtil.getSubValue(ck_i+"title") )
	{ 
		if ( ckUtil.getSubValue(ck_i+"title") != "deleted" ) 
			{
				document.write("<table width=371 cellspacing=0 cellpadding=0 border=0><tr><td width=20><img src='img/spacer.gif'></td><td width=280 valign='top'><span class='"+css_entry+"'>"+entry+num+"</strong></span></td><td align='right' width=71 valign='top'><a href='javascript:del("+ck_i+");' class='"+css_delchange+"'>"+button_del+"</a><br><img src='img/spacer.gif' width=1 height=5><br></td></tr>");
				//document.write(ckUtil.getSubValue(ck_i+"no")+"<br>");
				document.write("<tr><td width=20><img src='img/spacer.gif'></td><td><strong>"+ckUtil.getSubValue(ck_i+"title")+"</strong></td><td align='right'><span class='"+css_price+"'><strong>"+ckUtil.getSubValue(ck_i+"url")+" &euro;</strong></span></td></tr>");

				document.write("<tr><td width=20><img src='img/spacer.gif' height=1 width=20></td><td><img src='img/spacer.gif' width=1 height=2><br><span class='"+css_comment+"'>"+ckUtil.getSubValue(ck_i+"note")+"&nbsp;"+comment+"</span></td><td align='right' valign='bottom'><a href='javascript:note("+ck_i+");' class='"+css_delchange+"'>"+button_change+"</a></td></tr></table><img src='img/spacer.gif' width=1 height=5><br><img src='img/spacer.gif' width=20 height=1>"+img_delimiter+"<br><img src='img/spacer.gif' width=1 height=5><br> ");
				flag=true;
				num++;
				}
		ck_i++;	
	}
	if (flag==false)
		document.write("<table width=371 cellspacing=0 cellpadding=0 border=0><tr><td width=20><img src='img/spacer.gif'></td></td><td width=351 valign='top'><span class='"+css_info+"'>"+info_text+"</td></tr></table>");
}

function note(num)
{
	var ckUtil = new CJL_CookieUtil(cookie_name,60,"/");old="";
	if (ckUtil.getSubValue(num+"note"))
		old = ckUtil.getSubValue(num+"note");
		
	var new_num=prompt(dialog_comment, old );
	if (!Number(new_num))
		new_num=1;
	if (new_num!=0 && new_num!="")
		ckUtil.setSubValue(num+"note", new_num );	
	else
		ckUtil.setSubValue(num+"title","deleted");

	location.reload();
}

function del_all()
{		
		var yesorno = confirm(confirm_delall)
	 	if (yesorno == true) 
		{
			var ck_i=0;var ckUtil = new CJL_CookieUtil(cookie_name,60,"/");
			//cleanup 'deleted'
			while ( ckUtil.getSubValue(ck_i+"title") ) 
			{
				ckUtil.setSubValue(ck_i+"title","");
				ckUtil.setSubValue(ck_i+"url","");
			//	ckUtil.setSubValue(ck_i+"no","");
				ckUtil.setSubValue(ck_i+"note","");
				ck_i++;
			}
			location.reload();
		}
		
}

function del_all2()
{		

			var ck_i=0;var ckUtil = new CJL_CookieUtil(cookie_name,60,"/");
			//cleanup 'deleted'
			while ( ckUtil.getSubValue(ck_i+"title") ) 
			{
				ckUtil.setSubValue(ck_i+"title","");
				ckUtil.setSubValue(ck_i+"url","");
			//	ckUtil.setSubValue(ck_i+"no","");
				ckUtil.setSubValue(ck_i+"note","");
				ck_i++;
			}

		
}

/**
 * Copyright (C) 2002-2003, CodeHouse.com. All rights reserved.
 * CodeHouse(TM) is a registered trademark.
 *
 * THIS SOURCE CODE MAY BE USED FREELY PROVIDED THAT
 * IT IS NOT MODIFIED OR DISTRIBUTED, AND IT IS USED
 * ON A PUBLICLY ACCESSIBLE INTERNET WEB SITE.
 * 
 * CodeHouse(TM) JavaScript Library Module: Cookie Utility Class
 * You can obtain this script at http://www.codehouse.com
 *
 * Created: 8/28/2003
 */
function CJL_CookieUtil(name, duration, path, domain, secure)
{
   this.affix = "";
   
   if( duration )
   {   	  
    var date = new Date();
	  var curTime = new Date().getTime();

	  date.setTime(curTime + (1000 * 60 * duration));
	  this.affix = "; expires=" + date.toGMTString();
   }
   
   if( path )
   {
      this.affix += "; path=" + path;
   }
   
   if( domain )
   {
      this.affix += "; domain=" + domain;
   }

   if( secure )
   {
      this.affix += "; secure=" + secure;
   }
   
      
   function getValue()
   {
      var m = document.cookie.match(new RegExp("(" + name + "=[^;]*)(;|$)"));

      return m ? m[1] : null;   
   }
   
   this.cookieExists = function()
   {
      return getValue() ? true : false;
   }
      
   this.expire = function()
   {
      var date = new Date();
	  date.setFullYear(date.getYear() - 1);
	  document.cookie=name + "=noop; expires=" + date.toGMTString(); 
   }
        
   this.setSubValue = function(key, value)
   {
      var ck = getValue();

      if( /[;, ]/.test(value) )
      {
         //Mac IE doesn't support encodeURI
		 value = window.encodeURI ? encodeURI(value) : escape(value);
      }

      
      if( value )
      {
         var attrPair = "@" + key + value;

         if( ck )
         {
             if( new RegExp("@" + key).test(ck) )
	         {
		        document.cookie =
				   ck.replace(new RegExp("@" + key + "[^@;]*"), attrPair) + this.affix;
	         }
	         else
	         {
		        document.cookie =
				   ck.replace(new RegExp("(" + name + "=[^;]*)(;|$)"), "$1" + attrPair) + this.affix;
	         }
         }
         else
         {
	        document.cookie = name + "=" + attrPair + this.affix;
         }
      }
      else
      {      
	     if( new RegExp("@" + key).test(ck) )
	     {
	        document.cookie = ck.replace(new RegExp("@" + key + "[^@;]*"), "") + this.affix;
	     }
      }
   }

      
   this.getSubValue = function(key)
   {
      var ck = getValue();

      if( ck )
      {
         var m = ck.match(new RegExp("@" + key + "([^@;]*)"));

	     if( m )
	     {
	        var value = m[1];

	        if( value )
	        { 
	           //Mac IE doesn't support decodeURI
			   return window.decodeURI ? decodeURI(value) : unescape(value);
	        }
	     }
      }
   }
}

