{	// STRING PROTOTYPES 
	String.prototype.trim = function(chars) { //zrychlit
		var chars = chars || " \t\r\n\0";
		var str = this;
		str = str.replace(/\r\n/gi,"\n"); //remplace \r\n by \n
		while(str&&chars.indexOf(str.charAt(0))>-1)
			str=str.substring(1,str.length);
		while(str&&chars.indexOf(str.charAt(str.length-1))>-1) 
			str=str.substring(0,str.length-1);
		return str;
	}
	String.prototype.ascii2html = function() { // pridat entity
		var html = this;
		html = html.replace(/&/g,'&amp;'); // & --MUST BE FIRST
		html = html.replace(/\"/g,'&quot;'); // "
		html = html.replace(/</g,'&lt;'); // <
		html = html.replace(/>/g,'&gt;'); // >
		html = html.replace(/  /g,' '); // remove double-spaces
		html = html.replace(/\n/g,'<br/>'); //line break  --MUST BE LAST
		// SPECIAL LINK TAGS
		html = html.replace(/\{(.+?);(.+?)\}/gi,"<a href=\"$2\">$1</a>"); //zrychlit
		html = html.replace(/\[(.+?)\]/gi,"<b>$1</b>");  // bold
		return html;
	}
	String.prototype.html2ascii = function() { // add Array.foreach
		var ascii = this;
		// SPECIAL LINK TAGS
		ascii = ascii.replace(/<a href="(.+?)">(.+?)<\/a>/gi,"{$2;$1}"); //zrychlit
		ascii = ascii.replace(/<b>(.+?)<\/b>/gi,"[$1]"); //zrychlit
		// essentials
		ascii = ascii.replace(/\0/gi,''); // remove \0
		ascii = ascii.replace(/\t/gi,''); // remove \t
		ascii = ascii.replace(/\n/gi,''); // remove \n
		ascii = ascii.replace(/\r/gi,''); // remove \r
		ascii = ascii.replace(/  /gi,' '); // remove double space
		ascii = ascii.replace(/&amp;/gi,'&'); // &
		ascii = ascii.replace(/&quot;/gi,'"'); // "
		ascii = ascii.replace(/&lt;/gi,'<'); // <
		ascii = ascii.replace(/&gt;/gi,'>'); // >
		ascii = ascii.replace(/<br *\/*>/gi,"\n"); //line break 2
		return ascii;
	}
	String.prototype.plusEscape = function() {
		var plusChar = "%" + "+".charCodeAt(0).toString(16).toUpperCase();
		return this.replace(/\+/g,plusChar);
	}
	String.prototype.colorHEX = function() {
		// if HEX
		var m = this.match(/^#[a-fA-F0-9]{6}$/);
		if(m) return this;
		// if RGB
		var m = this.match(/rgb\(([0-9 ]+),([0-9 ]+),([0-9 ]+)\)/);
		if(m) {
			var h = new Array(3);
			h[0] = parseInt(m[1], 10).toString(16).toLowerCase();
			h[1] = parseInt(m[2], 10).toString(16).toLowerCase();
			h[2] = parseInt(m[3], 10).toString(16).toLowerCase();
			h[0] = (h[0].length == 1) ? '0' + h[0] : h[0];
			h[1] = (h[1].length == 1) ? '0' + h[1] : h[1];
			h[2] = (h[2].length == 1) ? '0' + h[2] : h[2];
			return ('#' + h.join(""));
		}
		// no match
		else return null;
	}
	String.prototype.colorRGB = function() {	// returns integers R,G,B [0-255]
		// if HEX
		var m = this.match(/^#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})$/);
		if(m) return {r:parseInt(m[1],16), g:parseInt(m[2],16), b:parseInt(m[3],16)};
		// if RGB
		var m = this.match(/rgb\(([0-9 ]+),([0-9 ]+),([0-9 ]+)\)/);
		if(m) return {r:parseInt(m[1],10), g:parseInt(m[2],10), b:parseInt(m[3],10)};
		// no match
		else return null;
	}
}

{	// DOM HELPERS
	hasClass = function(o,cName) {
	   	if((' '+o.className+' ').indexOf(' '+cName+' ')>-1)
			return true;
		else
			return false;
	}
	getElementsByClassName = function(o,cName) { // all sub levels
		var list = o.getElementsByTagName('*');
		var elements = [];
		for(var i in list)
	    	if((' '+list[i].className+' ').indexOf(' '+cName+' ')>-1)
	        	elements.push(list[i]);
		return elements;
	}
	getParentByClassName = function(o,cName) {
	    function goParent(o) {
	    	var parO = o.parentNode;
	        if(parO.nodeName=='HTML')
				return false; // ??
	        if((' '+parO.className+' ').indexOf(' '+cName+' ')>-1)
				return parO;
	        else
				return goParent(parO);
	    }
		return goParent(o);
	}
	getParentByTagName = function(o,tName) {
		var tName = tName.toUpperCase();
	    function goParent(o) {
	    	var parO = o.parentNode;
	        if(parO.nodeName=='HTML')
				return false; // ??
	        if(parO.tagName==tName)
				return parO;
	        else
				return goParent(parO);
	    }
		return goParent(o);
	}
	getChildsByClassName = function(o,cName) {
		var children = [];
		for(var i in o.childNodes)
			if(o.childNodes[i].nodeType==1)
		    	if((' '+o.childNodes[i].className+' ').indexOf(' '+cName+' ')>-1)
		        	children.push(o.childNodes[i]);
	    return children;
	}
	getChildsByTagName = function(o,tName) {
		var tName = tName.toUpperCase();
		var children = [];
		for(var i in o.childNodes)
			if(o.childNodes[i].nodeType==1)
				if(o.childNodes[i].tagName==tName||tName=='*')  
					children.push(o.childNodes[i]);
	    return children;
	}
	getNextChild = function(o) {
	    function goNext(o) {
			if(!(nextO = o.nextSibling))
				return false;
	        if(nextO.nodeType != 1)
				return goNext(nextO);
	        else
				return nextO;
	    }
	    return goNext(o);
	}
	getPrevChild = function(o) {
	    function goPrev(o) {
			if(!(prevO = o.previousSibling))
				return false;
	        if(prevO.nodeType != 1)
				return goPrev(prevO);
	        else
				return prevO;
	    }
	    return goPrev(o);
	}
	isset = function(varname){
	  return(typeof(window[varname])!='undefined');
	}
	isImageLoaded = function(o) {
		// IE
	    if (!o.complete) return false;
		// GECKO
	    if (typeof o.naturalWidth != "undefined" && o.naturalWidth == 0) return false;
	    // ELSE
	    return true;
	}	
	insertBefore = function(newElement,targetElement) {
		targetElement.parentNode.insertBefore(newElement,targetElement);
	}
	insertAfter = function(newElement,targetElement) {
		var parent = targetElement.parentNode;
		if(parent.lastchild == targetElement)
			parent.appendChild(newElement);
		else
			parent.insertBefore(newElement, targetElement.nextSibling);
	}
	findPos = function(o) {
		var curleft = curtop = 0;
		if (o.offsetParent) {
			do {
				curleft += o.offsetLeft;
				curtop += o.offsetTop;
			} while (o = o.offsetParent);
		}
		return [curleft,curtop];
	}
	getStyle = function(o,styleProp)	{
		if(o.currentStyle)
			var val = o.currentStyle[styleProp];
		else if (window.getComputedStyle)
			var val = document.defaultView.getComputedStyle(o,null).getPropertyValue(styleProp);
		return val;
	}
	escape2 = function(s) {
		var plusChar = "%" + "+".charCodeAt(0).toString(16).toUpperCase();
		return escape(s).replace(/\+/g,plusChar);
	}
}
{	// HTTP - ajax
	http = {};
	http.enabled = (window.XMLHttpRequest||window.ActiveXObject) ? true : false;
	http.getText = function(url,post) {
		if(!post) var post = '';
		var getHttpObject = function() {
			try { return new XMLHttpRequest(); } catch(e) {}
			try { return new ActiveXObject("MSXML3.XMLHTTP"); } catch(e) {}
			try { return new ActiveXObject("MSXML2.XMLHTTP.3.0"); } catch(e) {}
			try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
			try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
			alert("Your browser is too old !\nUpgrade to latest version.");
			return null; // ? undefined, ? false 
		}
		try {
			var	http_request = getHttpObject();
			http_request.open("POST", url, false);
			http_request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
			http_request.send(post);
			return http_request.responseText;
		} catch(e) {
			alert(e.description);
		}
	}
	http.getData = function(url,post) {
		if(!post) var post = '';
		var text = http.getText(url,post);
		try {
			return eval('(' + text + ')');
		} catch(e) {
			return null;
		}
	}
}
{	// NAVIGATION OLD
	var SECTID;
	navExpand = function(o,pref) { //opravit, OKfN
		o.className = (o.className=='subMenu') ? 'subMenu_A' : 'subMenu';
		var id = o.id.substring(pref.length+1);
		var subBox = document.getElementById('subBox_'+pref+'_'+id);
		subBox.className = (subBox.className=='subBox') ? 'subBox_E' : 'subBox';
		o.blur();
		return false;
	}
	menuCollapseLevel = function(o) { //opravit OKfN
		var blocks = document.getElementsByTagName("a");
		for(var i in blocks) {
			if(blocks[i].className.indexOf('subMenu_A') > -1) {
				blocks[i].className = 'subMenu';
				document.getElementById('subBox_'+blocks[i].id).className = 'subBox';
			}
		}
		return false;
	}
	switchSection = function(e) {
		/*document.getElementById('mainFrame').innerHTML = '&nbsp;&nbsp;<span style="font-family: Arial, Helvetica, sans-serif;font-size:10px;color:#666666">LOADING ..&nbsp;</span><img alt="" src="/sl/loading_blue.gif">';*/
		var o = mouse.getObject(e);
		var levelMenu = o.parentNode;
		var deep = levelMenu.getAttribute('deep')
		var block, y = 0;
		if(deep=='0') {
			var blocks = levelMenu.getElementsByTagName("a");
			while(block = blocks[y]) {
				if(block.className.indexOf('subMenu_A') > -1) {
					block.className = 'subMenu';
					document.getElementById('subBox_'+block.id).className = 'subBox';
				}
				y++; 
			}
		}
		var blocks = document.getElementsByTagName("a");
		y = 0;
		while(block = blocks[y]) {
			if(block.className.indexOf('link_A') > -1) block.className = 'link';
			y++; 
		}
		o.className = 'link_A';
		SECTID = o.id;
		updateInfoLine(o);
		var post = 'section='+escape(o.id);
		document.getElementById('mainFrame').innerHTML = http.getText('/ajax/getItems',post);
		scroll(0,0);
		return false;
	}
	goDetails = function (e) {
		var o = mouse.getObject(e);
		var h = getParentByClassName(o,'holder')
		var post = 'UID='+escape(h.id);
		document.getElementById('mainFrame').innerHTML = http.getText('/ajax/getItemDetails',post);
		scroll(0,0);
		return false;
	}
}

// OPTIONS - SUMARIZE PRICE
{
	formatPrice = function(floatNumber) { 
		// prepare string
		var price = "" + Math.round(floatNumber*100); 
		while(price.length < 3) price = "0" + price;
		// insert dot .00
		var dot = price.length - 2;
		price = price.substring(0,dot) + "." + price.substring(dot,price.length); 
		// insert commas 
		var commas = [6,10,14,18];
		for(var i in commas) {
			if(price.length > commas[i]) {
				var comma = price.length - commas[i]; 
				price = price.substring(0,comma) + "," + price.substring(comma,price.length); 
			}
		}
		return price;
	} 
	updateTotal = function() {
		var mainFrame = document.getElementById('mainFrame');
		var list = getElementsByClassName(mainFrame,'options');
	    var price = parseFloat(document.getElementById('basePrice').innerHTML.replace('$','').replace('+','').replace(',',''));
	    for(i in list) {
	    	var v = list[i].value.replace('$','').replace('+','').replace(',','');
			var m = v.match(/(.+?)\([ ]*([0-9]+[.0-9]*)\)/);
			if(m) price+= parseFloat(m[2]);
	    }
		var qty = parseInt(document.getElementById('quantity').value,10);
		var total  = formatPrice(price*qty);
		getElementsByClassName(mainFrame,'itemPrice')[0].innerHTML = total.split('.')[0]
		getElementsByClassName(mainFrame,'cents')[0].innerHTML =  total.split('.')[1]
	}
}
