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 cartadd(frm, session_id, currency, user_type){
	
	if(user_type == '') user_type = '1';
	var url = "../ajax/cart_add.php?currency="+currency+"&user_type="+user_type+"&session_id="+session_id+"&productStamp="+frm.productStamp.value+"&qty="+frm.qty.value;
	//window.location=url;		  
	var ajax = new net.ContentLoader(url, cartloading); 
								
}

function cartloading(){
	var elmnt = document.getElementById('cart-ajax');
	var data = this.req.responseXML.documentElement;
	var ks = Number(data.lastChild.firstChild.nodeValue);
	var cena = data.firstChild.firstChild.nodeValue;
	if(!isNaN(ks)){
		elmnt.innerHTML = ks + "<br />"+cena;
		alert("Vybrané zboží bylo přidáno do košíku. Děkujeme.");
	}
}


function watchDog(e, productId){
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posx = e.clientX + document.documentElement.scrollLeft;
		posy = e.clientY + document.documentElement.scrollTop;
	}
	
	
	var frm = document.getElementById('frm_watchDog');
	frm.wdProductId.value = productId;
	var wdBox = document.getElementById('watchDog');
	
	wdBox.style.top = (posy + 5) + "px";
	wdBox.style.left = (posx +5) + "px";
	wdBox.style.display = 'block';
}

function addItem(box, id) {
   var sel = document.getElementById(box);
   var opt = document.createElement("OPTION");
   opt.value = id;
   
	var txt = document.createTextNode(id);
	opt.appendChild(txt);
   sel.appendChild(opt);
}


function ValidateEmail( email){
	var regStr = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if( !regStr.test(email)){
		alert("Vámi zadaná e-mailová adresa nemá platný formát.");
		return false;
	}
	return true;
}

function ValidateEmailNotStrict( email){
	if(email == '') return true;
	var regStr = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if( !regStr.test(email)){
		alert("Vámi zadaná e-mailová adresa nemá platný formát.");
		return false;
	}
	return true;
}

function ValidateNotEmpty( values){
	for(var i=0; i<values.length; i++){
		
		if(values[i] == ''){
			alert("Vyplňte prosím požadované údaje.");
			return false;
		}
	}
	return true;
}

function ValidateAreNumbers( values  ){
	var regStr = /^(\d)+$/;
	for(var i=0; i<values.length; i++){
		if(!regStr.test(values[i])){
			alert("Do číselných polí prosím vložte nezáporné celé číslo.");
			return false;
		}
	}
	return true;
}

function ShowTooltip(e, tip)
{
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posx = e.clientX + document.documentElement.scrollLeft;
		posy = e.clientY + document.documentElement.scrollTop;
	}
	
	var tooltipBox = document.getElementById('tooltip');
	tooltipBox.innerHTML = tip;
	
	tooltipBox.style.top = (posy + 5) + "px";
	tooltipBox.style.left = (posx +5) + "px";
	tooltipBox.style.display = 'block';
	
}

function HideTooltip(){

	var tooltipBox = document.getElementById('tooltip');
	
	tooltipBox.style.display = 'none';
}

