/* COPYRIGHT DREW WALLER - fizzstream 2004 - 2008*/
/* reversion 3 Feb 2008. Calculate multiple variable shipping rates in child datasets  */
/* reversion 4 Mar 2008. Add Protx integration    
/* reversion 16 Nov 2008. integration  with multi-product offline generator                                                       */
/* Base64 encode/decode public domain code from Tyler Akins -- http://rumkin.com */

       	var showDetail=false;var isIE=false;var badEmailFlag=true;
	var custName=custEMail="";
    GBPsym="&pound;";
    EURsym="&euro;";
    USDsym="$";
    currfactor=1;
    currsym=GBPsym;
    currcode="GBP";
    shipvalue=0;
    discfactor=1;
var Acc1;
   	var isIE = (window.navigator.userAgent.indexOf("MSIE") > 0);
	shippingPointer=0;
	var relativeURL="../";

	/* for protx testing - first, safe characters for base64 encoding 
	var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var init="ddw";																											init="foxylady";
	 switch between servers here 0=simulator, 1=test, 2=live - any other number will do internal checks
	var vspSwitch=1;

	 set a safe default and override after 
	var vspURL="http://www.hackup.co.uk/shop/paypal_vars.asp";
	var vspAct="";
	init=simpXOR(decodeBase64("CAAPWQMZHVkKDhwA"),init);
	*/

	/* Order constructor */
	function LineItem(desc,price,qty,suid,ship,shipa,pointer) {
 		this.desc = desc;
 		this.price = price;
 		this.qty = qty;
 		this.suid = suid;
 		this.unitprice = price;
		this.ship = ship;
		this.unitship = shipa;
		this.shippoint=pointer;
	};

	/* define Order() constructor */
	function Order() {
		this.orders = new Array(arguments.length);
		for(i=0;i<arguments.length;i++){
   		    this.orders[i] = arguments[i];
		}
	
 	/* Order total method */
 	     this.totalPrice = function(n) {
   		var totalCost = new Number(0.00);
   		for(i=0;i<this.orders.length;i++){
     		     totalCost += (n=="price"?this.orders[i].price:this.orders[i].ship);
		     this.orders[i].shippoint=shippingPointer;
   		}
		totalCost=totalCost.toFixed(2);
 		return totalCost;
	    };

 	/* Order recalc based on new shipping - Feb 2008 */
 	     this.recalcPrice = function(p) {
   		var totalCost = new Number(0.00);
   		for(i=0;i<this.orders.length;i++){
		     this.orders[i].ship=this.orders[i].unitship[p]*this.orders[i].qty;
     		     totalCost += this.orders[i].ship;
		     this.orders[i].shippoint=shippingPointer;
   		}
		totalCost=totalCost.toFixed(2);
 		return totalCost;
	     } ;

	/* remove item method (by desc[ription] comparison */
  	     this.removeItem = function(toRemove) {
		var iQty=0;
      		for (var j=0; j < this.orders.length; j++) {
            		     if ( toRemove == this.orders[j].suid) {
		        this.orders[j].qty--;
		        iQty=this.orders[j].qty;
		        this.orders[j].price-=Math.abs(((this.orders[j].unitprice * currfactor) * discfactor).toFixed(2));
		        this.orders[j].ship-=this.orders[j].unitship[shippingPointer];
		        if (this.orders[j].qty==0) {
                		              this.orders.splice(j, 1);
		        }
            		     }
        		}
	     return iQty;
  	     };

	/* add item method
	*/
 	this.addLineItem = function(obj) {
		var lineIndex=null;
		       if (obj.suid !=null ) {
		          for (var i=0; i<this.orders.length;i++) {
			if (obj.suid==this.orders[i].suid) {
			   this.orders[i].qty++;
			   this.orders[i].price+=obj.price;
			   this.orders[i].ship+=obj.unitship[shippingPointer]; 
		//	   this.orders[i].shippoint=shippingPointer;
			   lineIndex=i;
			   break;
		       	} 
		           }
			if (lineIndex==null) {
			   this.orders.push(obj);
			   lineIndex=this.orders.length-1;
		       	}
		       } else {
			this.orders.push(obj);
			lineIndex=this.orders.length-1;
		       }
	     return lineIndex;
	     };

	/* utility methods */
  	    this.length = new Function("return this.orders.length");
  	    this.averagePrice = new Function("return this.totalPrice()/this.orders.length");
	};

	/* Instantiate Order -  IN persist.js window.onload*/
	thisOrder=new Order();

	/* HTML specific rendering utility functions */
	/* next three functions are interface drilldown show and hide (contents) - unused */

	function detShowHide(t) {
              var binPlus=/\+/.test(t.innerHTML);
              var binMinus=/\-/.test(t.innerHTML);
		if ( !(binPlus || binMinus)) { return true; };

		if (binPlus) {
	   	   t.innerHTML=t.innerHTML.replace(/\+/g,"-");
	  	  showDet(t);
		}
		if (binMinus) {
	   	   t.innerHTML=t.innerHTML.replace(/\-/g,"+");
	   	   hideDet(t);
		}
	};

	function showDet(d) {
	   var z="d_"+d.parentNode.id;

	/* kludge due Mozilla/IE differences in childnodes/empty innerHTML checking !!
	   'describe' will at least contain a vowel if there's content !!
	*/
	   if (/a|e|i|o|u/gi.test(document.getElementById(z).innerHTML)) {
	       document.getElementById(z).style.display="block";
	   }
	return true;
	};

	function hideDet(d) {
	   var z="d_"+d.parentNode.id;
	   document.getElementById(z).style.display="none";
		if(isIE) { 
		      showDetail=false; 
		}
	   return true;
	};


	function OrderAdd(s,n,id,c,ix) {
		n=Math.abs(n);
		d=c[ix];
		d=Math.abs(d);
		objS=new LineItem(s,n,1,id,d,c,ix);
		var itemNum=thisOrder.addLineItem(objS);
		objS=null;
		//var itemDisplay=DisplayAllOrders();
	    	//document.getElementById("ticket").innerHTML=itemDisplay;
		showOrderTotal();
		/*if ($('#App1').hasClass('AccordionPanelOpen')) {
			Acc1.closePanel(0);
		}*/
	//	Acc1.openPanel(0);
	//	return true;
	};

	function OrderDisplay(id,txt,num,amt) {
		var domstr="<table class=\"lister\" border=\"0\">"
			+"<tr>"
			+"<td class=\"txt\">"+txt
			+"</td><td class=\"currency\"><strong> &pound;"+amt+"</strong>"
			+"</td><td class=\"small\"><div class=\"orderItem\" id=\""+num+"\">"
			+"<img src=\""+relativeURL+"css/images/box_minus.gif\" alt=\"Delete item\" onclick=\"OrderRemove('"+id+"')\" "
			+"class=\"clearoff\" title=\"Delete\"/></div></td></tr></table>";

		return domstr;
	};

	function OrderRemove(t) {
	    thisOrder.removeItem(t); //.parentNode.id);
	//    document.getElementById("cart").innerHTML=DisplayAllOrders();
	    showOrderTotal();
	    return true;
	} ;

	function showOrderTotal() {
	    var tmp=thisOrder.totalPrice("price");
	    var tmpship=0; //thisOrder.totalPrice("ship");
	    tmp=(Math.abs(tmp)+Math.abs(tmpship)).toFixed(2);
	    generateCartCookie();
	    //document.getElementById("totals").innerHTML+="<span>&pound;"+tmp+"</span>";
	    try {
		var itemDisplay=DisplayAllOrders();
		document.getElementById("cart").innerHTML=itemDisplay;
	    } catch(e) {
		alert(e+document.getElementById("cart"));
	    }
	};

	function recalcOrderTotal() {
	    var tmp=thisOrder.totalPrice("price");
	    var tmpship=0; //thisOrder.recalcPrice(shippingPointer);
	    tmp=(Math.abs(tmp)+Math.abs(tmpship)).toFixed(2);
	    generateCartCookie();
		var itemDisplay=DisplayAllOrders();
	    	document.getElementById("cart").innerHTML=itemDisplay;
	};

	function DisplayAllOrders() {
		var domstr=plural="",tqty=mship=tot=overtot=0;

		for (var i=0;i < thisOrder.length();i++) {
		     var qty=thisOrder.orders[i].qty;
		     var qtystr=qty>1?" ("+qty+")":"";
		tqty+=qty;
		     var id=thisOrder.orders[i].suid;
		     var desc=thisOrder.orders[i].desc+"<strong>"+qtystr+"</strong>";
		     var itemNum=i+1;
		     var curr=thisOrder.orders[i].price.toFixed(2);
		     tot+=Math.abs(curr);
		     mship='FREE'; //+=Math.abs(thisOrder.orders[i].ship);
		     domstr+=OrderDisplay(id,desc,itemNum,curr);
		}
	overtot=(Math.abs(tot)).toFixed(2);; //+Math.abs(mship)).toFixed(2);	
	// now accordion panel
	plural=tqty<=1?"":"s";
	 if(i == 0) {
	//	Acc1.closePanel(0);
		eraseCookie("fs_cart");
	  } else {
		var advisory=badEmailFlag?"<br/><strong>If you wish to receive a confirmation email of your order from Protx, you will need to to add a valid email address in the panel to the left.</strong>":"";
		mship='FREE'; //mship.toFixed(2);
		domstr+="<div class=\"displayTotals\">Shipping: <span style=\"color:#b4206c;\">"+mship+"</span></div>"; //&pound;"+mship+"</div>";
		domstr+="<div class=\"displayTotals\">Total       : &pound;"+overtot+"</div>";
	//	domstr+="<div class=\"OrderBtn\" style=\"text-align:right;\">Disconnected<br/><input type=\"button\" value=\"Click to Order\" onclick=\"tmpDB()\"/></div>";

		domstr+="<div class=\"OrderBtn\" style=\"text-align:right;\"><img style=\"cursor:pointer;border:0;margin:7px 0 5px 20px;\" src=\""+relativeURL+"css/images/btn_xpressCheckout.gif\" onclick=\"doPayPal()\"/></div>";
	//	domstr+="<div class=\"OrderBtn2\">Pay by Protx<br/><img style=\"cursor:pointer;margin-top:3px;\" src=\"assets/protx.gif\" onclick=\"doProtx()\"/></div>";
		domstr+="<div class=\"clr\"></div>";
		domstr+="<div id=\"helpnote\" style=\"clear:both;\">Clicking the button above will link to our <span style=\"color:#b4206c;font-weight:bold;\">SECURE</span> payment page on "
			+"<span style=\"font-weight:bold;\">PayPal</span> "
			+"</div>";

	  }
	   return domstr;
	};

		
	function tmpDB(){
		var tb=""
		//tb+="<strong>This is a representation of the Order JSON object ready for transmission to a Payment Service Provider - </strong><br/></br/><br/>";
		tb+=Fizz.Utils.serializeObject(thisOrder.orders);
		document.getElementById('dbug').innerHTML=tb;
	};
	function generateCartCookie() {
		var sb=""
		//sb+="<strong>This is a representation of the Order JSON object ready for transmission to a Payment Service Provider - </strong><br/></br/><br/>";
		sb+=escape(Fizz.Utils.serializeObject(thisOrder.orders));
		document.cookie = "fs_cart=" + sb+"; path=/";
	};


	function formatMoney(fp) { 
		return fp.toFixed(2);
	};


/* PayPal */
	function doPayPal(){
		var r="http://www.globalherbs.co.uk/; //shop/thankyou.asp" ;  
		var cr="http://www.globalherbs.co.uk/; //shop/cancelback.asp" ;  
		var u=self.location.href
		var ustr=u.substr(0,u.lastIndexOf("/"));
		var uniqueID=new Date().getTime();
		var currcode="GBP";

		sform="<form id='ppform' action='https://www.paypal.com/cgi-bin/webscr' method='POST' target='_self'>"
		  +"<input type='hidden' name='cmd' value='_cart'/>"
		  +"<input type='hidden' name='business' value='paypal@globalherbs.co.uk'/>"
		  +"<input type='hidden' name='item_name' value='"+uniqueID+"'/>"
		  +"<input type='hidden' name='currency_code' value='"+currcode+"'/>"
		  +"<input type='hidden' name='return' value='"+r+"'/>"
		  +"<input type='hidden' name='cancel_return' value='"+cr+"'/>"
		  +"<input type='image' name='submit' src='mybutt.gif' style='visibilty:hidden;' onerror='return false;'/>"
		  +"<input type='hidden' name='upload' value='1'/>";
		sform+=getBasketContent();

		sform+="</form>";
		document.getElementById("payForm").innerHTML=sform;
		document.getElementById("ppform").submit();
		document.getElementById("payForm").innerHTML="";
	};

	function getBasketContent() {
		var x="",cnt=0;
		for (var i=0;i < thisOrder.length();i++) {
		     cnt=i+1;
		     var qty=thisOrder.orders[i].qty;
		     var ship=0.00; //thisOrder.orders[i].ship.toFixed(2); //unitship.toFixed(2);
		     var desc=thisOrder.orders[i].desc;
		     var price=thisOrder.orders[i].unitprice.toFixed(2);
		     x+="<input type=\"hidden\" name=\"quantity_"+cnt+"\" value=\""+qty+"\"/> \
		            <input type=\"hidden\" name=\"shipping_"+cnt+"\" value=\""+ship+"\"/> \
		            <input type=\"hidden\" name=\"item_name_"+cnt+"\" value=\""+desc+"\"/> \
		            <input type=\"hidden\" name=\"amount_"+cnt+"\" value=\""+price+"\"/>";
		}
	  return x;
	};
	
	function swapCurrency(evt,nc){ /* not used this implement */
	  currcode=nc;
	  currfactor=eval(nc);
	  currsym=eval(nc+"sym");
	   if(evt=="click" && thisOrder.orders.length > 0 ) {
	     showOrderTotal();
	   }
	};
 
	function getPayPalHelp(){
		var src_url="https://www.paypal.com/cgi-bin/webscr?cmd=_help-ext&source_page=_home";
		newWindow = window.open(src_url,"newWindow","menubar=1,scrollbars=1,resizable=1,status=1,location=1,width=720,height=500,left=40,top=20");  
	};

/* Protx - added 10 March 2008 */

/* */
	function doProtx() {
	     if (vspSwitch==0) {	
	     	vspURL="https://ukvpstest.protx.com/VSPSimulator/VSPFormGateway.asp";
	    	vspAct=simpXOR(decodeBase64("GAEbFRkRSBAKOCc9AyUWZg=="),init); 
	     } else if (vspSwitch==1) {
	     	vspURL="https://ukvps.protx.com/vspgateway/service/vspform-register.vsp";
	     	vspAct=simpXOR(decodeBase64("BAwla1xNGlUoGCAhCFoRWg=="),init);
	     }

	    var totalnett=thisOrder.totalPrice("price");
	    var totalship=thisOrder.totalPrice("ship");
	    var totals=(Math.abs(totalnett)+Math.abs(totalship)).toFixed(2);
	    var encryptedField="";
		var buildForm="";
		buildform="<form id='pxform' action='"+vspURL+"' method='POST' target='_self'>"
		  +"<input type='hidden' name='VPSProtocol' value='2.22'/>"
		  +"<input type='hidden' name='TxType' value='PAYMENT'/>"
		  +"<input type='hidden' name='Vendor' value='oxyfizz'/>";
		  encryptedField=genCryptField(totals,totalship) ;

		/* nb - double quote 'encryptedField' for transmission */
		 buildform+="<input type='hidden' name='Crypt' value='"+encryptedField+"'/>"
		
		buildform+="</form>";

		document.getElementById("payForm").innerHTML=buildform;
		document.getElementById("pxform").submit();
		document.getElementById("payForm").innerHTML="";
		
	};

	function genCryptField(totals,totalship) {
	//	custName="";custEMail="drew@fizzequestrian.co.uk";
		custEMail=badEmailFlag?"":custEMail;
		var cfield=basketContent="";
		var strAct=vspAct; 
		var generalDesc="Your purchase from Hackup Ltd - UK Suppliers of Equine Oxyshot.";
		var authorisedEmailHeadingToClient="Thank you for your order from Hackup Ltd - UK Suppliers of Equine Oxyshot. "
					          +"Your order will be despatched immediately.";

		var ourTxID="oxy_"+new Date().getTime()+"_"+randomString(3);
		cfield+="VendorTxCode="+ourTxID+"&"
		        +"Amount="+totals+"&"
		        +"Currency=GBP&"
		        +"Description="+generalDesc+"&"
		        +"SuccessURL=http://www.hackup.co.uk/shop/thankyou.asp&"
		        +"FailureURL=http://www.hackup.co.uk/shop/cancelback.asp&"
		        +"CustomerName="+custName+"&"
		        +"CustomerEMail="+custEMail+"&"
		        +"VendorEMail=sales@hackup.co.uk&"
		        +"eMailMessage="+authorisedEmailHeadingToClient+"&";

		basketContent=getProtxBasketContent();
		cfield+="basket="+basketContent;    
		cfield+="Delivery:::::"+totalship;
		cfield=encodeBase64(simpXOR(cfield,strAct));

		return cfield;
	};

	function getProtxBasketContent() {
		var cart="",cnt=thisOrder.length();
		cart+=(cnt+1)+":"; 			// we're manually adding a row for delivery charges
		for (var i=0;i < cnt;i++) {
		     var qty=thisOrder.orders[i].qty;
		     var desc=thisOrder.orders[i].desc;
		     var price=thisOrder.orders[i].unitprice.toFixed(2);
		     var lineprice=(price*qty).toFixed(2);
		     cart+=desc+":"+qty+":"+price+":::"+lineprice+":" ;
		}
	  /* strip the trailing colon below ONLY if we're not adding a delivery total row - ('cart+=cnt' above) 
	     ie only rows in order constructor */
	  //cart=cart.substr(0,cart.length-1);
	  return cart;

	};

	 function randomString(length) {
   		chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  		 pass = "";

  		 for(x=0;x<length;x++) {
      			i = Math.floor(Math.random() * 62);
      			pass += chars.charAt(i);
   		}

   		return pass.toString();
	};

	function simpXOR(instr, pwd) {
	 var enc_str="";
	 var pwindex=0;
	  for(var i=0; i<instr.length; i++) {
	    enc_chr = parseInt(instr.charCodeAt(i)) ^ parseInt(pwd.charCodeAt(pwindex));
	      pwindex++;
	      if(pwindex==pwd.length) {
	        pwindex=0;
	      } 
	   enc_str += String.fromCharCode(enc_chr);
	  }
	  return enc_str;
	};

	function encodeBase64(input) {
	   var output = "";
	   var chr1, chr2, chr3;
	   var enc1, enc2, enc3, enc4;
	   var i = 0;

	   do {
	      chr1 = input.charCodeAt(i++);
	      chr2 = input.charCodeAt(i++);
	      chr3 = input.charCodeAt(i++);

	      enc1 = chr1 >> 2;
	      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
	      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
	      enc4 = chr3 & 63;

	      if (isNaN(chr2)) {
	         enc3 = enc4 = 64;
	      } else if (isNaN(chr3)) {
	         enc4 = 64;
	      }

	      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
	      keyStr.charAt(enc3) + keyStr.charAt(enc4);
	   } while (i < input.length);
   
	   return output;
	};

	function decodeBase64(input) {
	   var output = "";
	   var chr1, chr2, chr3;
	   var enc1, enc2, enc3, enc4;
	   var i = 0;

	   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
	   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

	   do {
	      enc1 = keyStr.indexOf(input.charAt(i++));
	      enc2 = keyStr.indexOf(input.charAt(i++));
	      enc3 = keyStr.indexOf(input.charAt(i++));
	      enc4 = keyStr.indexOf(input.charAt(i++));

	      chr1 = (enc1 << 2) | (enc2 >> 4);
	      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
	      chr3 = ((enc3 & 3) << 6) | enc4;

	      output = output + String.fromCharCode(chr1);

	      if (enc3 != 64) {
	         output = output + String.fromCharCode(chr2);
	      }
	      if (enc4 != 64) {
	         output = output + String.fromCharCode(chr3);
	      }
	   } while (i < input.length);

	   return output;
	};


	function entryHelp(field) {
		badEmailFlag=true;
		document.getElementById("inputMessage").style.color="white";
		document.getElementById("inputMessage").innerHTML="Your email address";
			var checkStr=new String(field.value);
			if (checkStr=="") {
				return true;
			}

			if ( !checkStr.IsEmail()) {
				document.getElementById("inputMessage").style.color="yellow";
				document.getElementById("inputMessage").innerHTML="Please enter a valid email";
				if (document.getElementById("dbug")) {
				     document.getElementById("dbug").innerHTML="Clicking the buttons above will link to our "
					+"<span style=\"color:white;font-weight:bold;\">SECURE</span> payment pages on either "
					+"<span style=\"font-weight:bold;\">PROTX</span> "
					+"or PayPal. <br/><strong>If you wish to receive a confirmation email of your order from Protx, "
					+"you will need to to add a valid email address in the panel above.</strong>";
				}	
				return false;
			} else {
				badEmailFlag=false;
				custEMail=checkStr;
				if (document.getElementById("dbug")) {
				     document.getElementById("dbug").innerHTML="Clicking the buttons above will link to our "
					+"<span style=\"color:white;font-weight:bold;\">SECURE</span> payment pages on either "
					+"<span style=\"font-weight:bold;\">PROTX</span> "
					+"or PayPal. ";
				}		
			}
		return true;
	};

/* ------------------------------------------------ */

function IsEmailAddress() {
	var s = "", re;
	//retrieve email instance.
	s = "" +this + "";

	//length check: remove leading and trailing spaces and then test length.
	//x@x.xx is the smallest address... that's 6 characters. so, length
	//must be greater than 5 to continue.
	s = s.replace(/^\s*|\s*$/g, "");
	if (s == "undefined" || s.length < 6) {return false;}

	//test for spaces before checking syntax. spaces are illegal 
	//in an email address. if a space is found, it's definitely an illegal address:
	re = /\s+/g
	if (re.test(s)) {return false;}

	//validate email address syntax and remove any emails that don't 
	//match the basic syntax pattern below.
	re = /^(\w|[^_]\.|[\-])+((\@){1}([^_]))(([a-z]|[\d]|[\-]|\.)+|([^_]\.[^_])*)+\.[a-z]{2,6}$/i
	if (!re.test(s)) {return false;}

	//validate domain part of the email against all known TLDs as of May 2001 
	re = /\.(a[c-gil-oq-uwz]|b[a-bd-jm-or-tvwyz]|c[acdf-ik-orsuvx-z]|d[ejkmoz]|e[ceghr-u]|f[i-kmorx]|g[abd-ilmnp-uwy]|h[kmnrtu]|i[delm-oq-t]|j[emop]|k[eg-imnprwyz]|l[a-cikr-vy]|m[acdghk-z]|n[ace-giloprtuz]|om|p[ae-hk-nrtwy]|qa|r[eouw]|s[a-eg-ort-vyz]|t[cdf-hjkm-prtvwz]|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[admrw]|com|edu|net|org|mil|gov|biz|pro|aero|coop|info|name|museum)$/i
	if (!re.test(s)) {return false;}

	//fix the .. problem...
	re = /\.\./
	if (re.test(s)) {return false;}

	//fix the @@ problem...
	re = /\@\@/
	if (re.test(s)) {return false;}

return true;
}

String.prototype.IsEmail = IsEmailAddress;

function getCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return "";
};

function createCookie(name,value,mins) { /*days) {*/
	//if (days) {
	if (mins) {

		var date = new Date();
		//date.setTime(date.getTime()+(days*24*60*60*1000));
		date.setTime(date.getTime()+(mins*60*1000));

		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
};

// FizzData.js - version 0.35 - Fizz Pre-Release 1.5

var Fizz; if (!Fizz) Fizz = {};

//////////////////////////////////////////////////////////////////////
//
// Fizz.Utils
//
//////////////////////////////////////////////////////////////////////

if (!Fizz.Utils) Fizz.Utils = {};



Fizz.Utils.escapeQuotesAndLineBreaks = function(str)
{
	if (str)
	{
		str = str.replace(/\\/g, "\\\\");
		str = str.replace(/["']/g, "\\$&");
		str = str.replace(/\n/g, "\\n");
		str = str.replace(/\r/g, "\\r");
	}
	return str;
};



Fizz.Utils.serializeObject = function(obj)
{
	// Create a JSON representation of a given object.

	var str = "";
	var firstItem = true;

	if (obj == null || obj == undefined)
		return str + obj;

	var objType = typeof obj;

	if (objType == "number" || objType == "boolean")
		str += obj;
	else if (objType == "string")
		str += "\"" + Fizz.Utils.escapeQuotesAndLineBreaks(obj) + "\"";
	else if (obj.constructor == Array)
	{
		str += "[";
		for (var i = 0; i < obj.length; i++)
		{
			if (!firstItem)
				str += ", ";
			str += Fizz.Utils.serializeObject(obj[i]);
			firstItem = false;
		}
		str += "]";
	}
	else if (objType == "object")
	{
		str += "{";
		for (var p in obj)
		{
			if (!firstItem)
				str += ", ";
			str += "\"" + p + "\": " + Fizz.Utils.serializeObject(obj[p]);
			firstItem = false;
		}
		str += "}";
	}
	return str;
};

