/*
Copyright (c) 2007, Ilikethis! Inc. All rights reserved.
Code licensed under the BSD License
version: 1.0.0
*/

Ilt.Sportkoncept = {};
Ilt.Sportkoncept.User = {};
Ilt.Sportkoncept.User.Registration = {};
mytime = null;
mytimeisrunning = false;
skok = 4;

/**
 *  trimy - odstraneni bilych znaku na zacatku a na konci
 */
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

/**
 * prida k registraci oteviraci box
 */
Ilt.Sportkoncept.User.Registration.addRegistrationBoxHandler = function( id )
{
  YAHOO.util.Event.onContentReady(id, function() {
  	var pE = YAHOO.util.Dom.getPreviousSibling( id );
	YAHOO.util.Event.addListener( pE , "click", function(e,o) {
		Ilt.Effect.Slide.toggle(id,{duration:0.3});
	} );
  } );
}

/**
 * Zobrazovani a skryvani loginBoxu na HP
 */

function zobrazSkryjLoginBoxHp() {
	
	var box = document.getElementById("loginBox");
	var obal = document.getElementById("obalLoginu");
	
	if (box.style.display == "block") {
        box.style.display = "none";
		YAHOO.util.Dom.removeClass('obalLoginu', 'rozbaleno');
	} else {
        box.style.display = "block";
		YAHOO.util.Dom.addClass('obalLoginu', 'rozbaleno');
	}
	
	return false;
	
}

function callBrandboxAjax(page, selected) {
	
	var sUrl = "/product/brand/brand-box/ajax/true/brandPage/" + page + "/selectedBrand/" + selected;
	
	var callback = {
		success: function(o) {
			document.getElementById("productNaviBox").innerHTML = o.responseText;
		},
		failure: function(o) {
		}
	}
	
	var transaction = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback, null);
}

function naseptavac(hodnota) {
	if (hodnota.trim().length > 2) {
		var sUrl = "/autocompleter/" + hodnota.trim();
		
    
        var callback = {
            success: function(o) {
                if (o.responseText.length > 0) {
                    document.getElementById("autocompleter").style.display = "block";
                    document.getElementById("autocompleter").innerHTML = o.responseText;
                }
            },
            failure: function(o) {
                //alert("AJAX doesnt works!")
            }
        }
        
        var transaction = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback, null);
	} else {
        document.getElementById('autocompleter').style.display = 'none';
    }
}

function naseptavacVymazat() {
    var hodnota = document.getElementById("vyhledavaciPole").value;
    if (hodnota == "Hledaný výraz") { document.getElementById("vyhledavaciPole").value = ""; }
}

function znaseptavace(data) {
	document.getElementById('vyhledavaciPole').value = data;
	hideAutocompleter();
}

function startTimeBrandBox(smer, interval) {
	if (mytimeisrunning == false) {
		mytimeisrunning = true;
		mytime = setInterval("loadNewBrandBox('" + smer + "')", interval);
	}
}

function clearTimeBrandBox() {
	if (mytimeisrunning == true) {
		clearTimeout(mytime);
		mytimeisrunning = false;
	}
}

function hideAutocompleter() {
    setTimeout("hideAutocompleterNow()", 50);
    return false;
}

function hideAutocompleterNow() {
    document.getElementById('autocompleter').style.display = 'none';
    if (document.getElementById('vyhledavaciPole').value != "") { // pokud mam nejaky vyraz na vyhledani
        document.getElementById('searchForm').submit();
    }
}

function hideVypisZnacek() {
    setTimeout("hideVypisZnacekNow()", 1000);
    return false;
}

function hideVypisZnacekNow() {
    document.getElementById('vypisznacek').style.display = 'none';
}

function displayHideZnacek() {
    var vypisZnacekStyle = document.getElementById('vypisznacek').style;
    if (vypisZnacekStyle.display == 'block') {
        vypisZnacekStyle.display = 'none';
    } else {
        vypisZnacekStyle.display = 'block';
    }
    return false;
}
function hideVypisSezon() {
	setTimeout("hideVypisSezonNow()", 1000);
	return false;
}

function hideVypisSezonNow() {
	document.getElementById('vypissezon').style.display = 'none';
}

function displayHideSezon() {
	var vypisSezonStyle = document.getElementById('vypissezon').style;
	if (vypisSezonStyle.display == 'block') {
		vypisSezonStyle.display = 'none';
	} else {
		vypisSezonStyle.display = 'block';
	}
	return false;
}

function skryjSelectVariant() {
    setTimeout("hideVypisVariantNow()", 500);
    return false;
}

function hideVypisVariantNow() {
    document.getElementById('varSelect').style.display = 'none';
}

function displayHideVariant() {
    var varSelectStyle = document.getElementById('varSelect').style;
    if (varSelectStyle.display == 'block') {
        varSelectStyle.display = 'none';
    } else {
        varSelectStyle.display = 'block';
    }
    return false;
}

function skryjZobrazJinouAdresu() {
    var isChecked = document.getElementById('jinaDodaciAdresaChbx').checked;
    if (isChecked != true) { document.getElementById('dodaciAdresaForm').style.display = "none"; } else { document.getElementById('dodaciAdresaForm').style.display = "block"; }
    return true;
}

function setspeed(rozmer) {
    skok = rozmer;
}

function hideantispam() {
    var element = document.getElementById('radekAntispam');
    if (element != null) {
        document.getElementById('antispam').value = '6';
        element.style.display = 'none';
    }
}
