/*<![CDATA[*/
		   
function FormatMoney(value) {

   result=""+Math.floor(value)+".";

   var cents=100*(value-Math.floor(value))+0.5;

   result += Math.floor(cents/10);

   result += Math.floor(cents%10);

   return result;

}

function createCookie(name,value,days) 
{
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*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);
}

function AddToBookmarks(thisa) {

	window.external.AddFavorite(thisa);	

}

function $(obj_id)
{
	return document.getElementById(obj_id);
}

function RemoveElement(el_id)
{
	$(el_id).parentNode.removeChild($(el_id));
}

function Search()
{
	var qstring = $('qstring').value;
	if(qstring == 'Search')
		qstring = '';
		
	qstring = escape(qstring);
	qstring = qstring.replace(/%20/g,'+');
	document.location.href = SITEADDR+'search/'+qstring;
}

function EnterSubmit(e)
{
	var key;
	if(window.event)
		key = window.event.keyCode; //IE
	else
 		key = e.which; //firefox     
		
	if(key == 13)
     	Search();
	return false;
}

function showZoom(product_id)
{
	$('zoom_'+product_id).style.display = 'block';
}

function hideZoom(product_id)
{
	$('zoom_'+product_id).style.display = 'none';
}

function validate_email(str)
{
	var validRegExp = /^\w(\.?[\w-])*@\w(\.?[\w-])*\.[a-z]{2,6}$/i;
	if(str.search(validRegExp) == -1) return false
	else return true;
	
}

/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/

var Url = {

    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

function TrackClicks(code)
{
	
	var preventDefault = false;
	var a_tags = document.getElementsByTagName('a');
	
	for(i=0;i<a_tags.length;i++)
	{
		obj_id = a_tags[i].getAttribute('id');
		obj_id_val = obj_id;
		
		if(obj_id)
		{
			
			if(obj_id.indexOf('product_') == 0)
			{
				
				$(obj_id).title = '';
				
				$(obj_id).onclick = function(event)
				{
					if(preventDefault)
					{
						if(browser == 'IE')
						{
							ev = window.event.returnValue = false; 
						}
						else
						{
							ev = event.preventDefault();
						}
					}
					tmp_id = this.id;
					var id = tmp_id.split('_');
					id = id[1];
					
					i = new Image();
					i.src = 'tracker.php?case=p&code='+code+'&pid='+ id + '&loc=\'' + location.href + '\'';
					
				};
			}
			
			if(obj_id.indexOf('tag_') == 0)
			{
				
				$(obj_id).onclick = function(event)
				{
					if(preventDefault)
					{
						if(browser == 'IE')
						{
							ev = window.event.returnValue = false; 
						}
						else
						{
							ev = event.preventDefault();
						}
					}
					
					var keyword = Url.encode(this.title);
					
					i = new Image();
					i.src = 'tracker.php?case=t&code='+code+'&keyword='+ keyword + '&loc=\'' + location.href + '\'';
					
				};
			}
			
			
		}
				
	}
	
	
	
}

/*]]>*/
