$(document).ready(function() {
  //kliky na bannery
  $('.banStat').parent().each(function(){
    $(this).click(function(){
      var url = $(this).attr('href');
      $.get('/inc/bannerStat.asp?id='+$(this).attr('id').replace('ban',''), function(data){
        window.location.href=url;
      });
      return false;
    });
  });

  $('#dostupnost').click(function(){
    $.get($(this).attr('url'), function(data){
        $(data).find('.navigation').each(function(){
          $(this).css('display','none');
        });
        $(data).find('#column-2').each(function(){
          $(this).find('div.navigation').each(function(){
            $(this).css('display','none');
          });
          var sHtml = $(this).html() + "<div class='dost-close'><a href='#' onclick=$('#dostupnost-cnt').css('display','none');>[ Zavřít ]</a></div>";
          $('#dostupnost-cnt').css('display','inline');
          $('#dostupnost-cnt').html(sHtml);
        });
    });
  });
});


function isIE() {
    return (navigator.appVersion.replace(/[\/]/g,' ').indexOf("MSIE")>-1 ? true : false );
}
function isMOZ() {
    return false;
}
function isOP() {
    return (navigator.userAgent.indexOf("Opera")>-1 ? true : false );
}

function getE(objectID) {
	return document.getElementById(objectID); 
}

function getF(formName) {
	return document.forms[formName];
}

    function plusSign( number ) {
    	return (number>0 ? '+ ' : '' );
    }
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function OpenWnd( path ){

//	var objWnd = window.open( "/getfile.asp?path="+path, "Popis parametru", "scrollbars=no, height=400, width=400, left=10, top=10");
	var objWnd = window.open( "", "", "scrollbars=no, height=300, width=400, left=300, top=150, status=0");
	objWnd.document.write("<html><head><title>Popis parametru</title><style>* {margin:0;padding:0;border:0;}</style></head><body><div id='body'></div><iframe width='400' height='300' border='0' src='/getfile.asp?path="+path+"'></iframe></body></html>");
	objWnd.focus();
}

function availQuery( comm ){
	var objWnd = open( "/availability/?do=askavail&d="+comm, "", "scrollbars=yes, height=450, width=400, left=300, top=150, resizable=no");
	objWnd.focus();
}

function openWindow( path, width, height ){
    if (!width>0) width = 600;
    if (!height>0) height = 500;
	var objWnd = window.open( path, '', "scrollbars=yes, height="+ height +", width="+ width +", left=300, top=150");
	objWnd.focus();
}

function ExtractCookies(strName){
	var cookieList=document.cookie.split("; ");
	var cookieArray = new Array();
	var name = "#"
	for (var i=0; i < cookieList.length; i++){
		if(cookieList[i].indexOf(strName)>-1){
			if( cookieList[i].indexOf("=")>-1){name = cookieList[i].split("=");}
		}
	}
	if (name != "#"){
		return name[1];
	}else{
		return "none";
	}
}

	var cookie_expire=new Date();
	cookie_expire.setDate(cookie_expire.getDate() + 365);
	
function ExtractCookies_simple(strName){
	var cookieList=document.cookie.split("; ");
	var cookieArray = new Array();
	var name = "#"
	for (var i=0; i < cookieList.length; i++){
		if(cookieList[i].indexOf(strName+'=')==0){
			return cookieList[i].substr(cookieList[i].search('=')+1);
		}
	}
	return "";
}
function ExtractUserCookie(strKey){ // vyuziva hlavniho klice USER
	var strKeysValues = ExtractCookies_simple('USER');
	if ((strKeysValues=="none")||(strKeysValues=="")) return "";
	aKeyValue = new Array();
	aOneKeyValue = new Array();
	aKeyValue = strKeysValues.split("&");
	for (var i = 0; i<aKeyValue.length; i++) {
		aOneKeyValue = aKeyValue[i].split("=");
		if (aOneKeyValue[0].toLowerCase()==strKey.toLowerCase()) { return unescape(aOneKeyValue[1]); }
	}
	return "";
}
function InsertUserCookie(strKey, strValue){
	var strKeysValues = ExtractCookies_simple('USER');
	var sTmp = '';
	var sDelimiter = '';
	aKeyValue = new Array();
	aOneKeyValue = new Array();
	if ((strKeysValues=="none")||(strKeysValues=="")) {
		document.cookie = 'USER' + "=" + strKey + "=" + strValue + ";";
	} else if (("&"+strKeysValues.toLowerCase()).indexOf("&"+strKey.toLowerCase()+"=")==-1) {
		document.cookie = 'USER' + "=" + strKeysValues + "&" + strKey + "=" + strValue + ";path=/;";
	} else {
		aKeyValue = strKeysValues.split("&");
		for (var i = 0; i<aKeyValue.length; i++) {
			aOneKeyValue = aKeyValue[i].split("=");
			if (aOneKeyValue[0].toLowerCase()==strKey.toLowerCase()) aOneKeyValue[1] = strValue;
			sTmp += sDelimiter + aOneKeyValue[0] + "=" + aOneKeyValue[1];
			sDelimiter = "&";
		}
		document.cookie = 'USER' + "=" + sTmp + "; expires=" + cookie_expire.toGMTString() + ";path=/;";
	}
}
function ParseCookies(strName){
	var strCook = ExtractCookies(strName)
	if (strCook != "none"){
		var strList = strCook.split("a");
		for (var i=0; i < strList.length-1; i++){
			if (getE(strList[i]+'a')) if (getE(strList[i]+'a').tagName=='A') if(typeof(getE(strList[i]+'a')) == "object"){getE(strList[i]+'a').click();}
		}
	}
}


function emailControl( str ){
	if (str.replace(/^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$/,"")=="") { 
		return true
	} else {
		return false;
	}
}
function ControlNumber(){
	if (!isIE()) return;
	if ((event.keyCode <48) || (event.keyCode >57)) event.returnValue = false;
}
function controlMaxNumber(value,nMax){
		if(value > nMax && value >= 1){    
        alert("Číslo stránky musí být v rozmezí od 1 - " + nMax);
        return false;
    }else{    
        return true;
    }
}
function ControlFloat(){
	if (!isIE()) return;
	if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode !=46)) event.returnValue = false;
}

function ControlPhone() {
	if (!isIE()) return;
    if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 32)  && (event.keyCode!=40) && (event.keyCode!=41) && (event.keyCode!=43))
		event.returnValue = false;
}
function ControlPSC() {
	if (!isIE()) return;
    if (((event.keyCode < 48) || (event.keyCode > 57)) && (event.keyCode != 32))
		event.returnValue = false;
}
function ControlStringLength(testedInput,maxLong) {
	if (testedInput.value.length>maxLong) {
		testedInput.value = testedInput.value.substring(0,maxLong-1);
		return false;
	}
	return true;
}
function ValidateAccount(sAccount) {
	var u1,u2,t1,t2,i;
	var vahy = new Array("1","2","4","8","5","10","9","7","3","6")
	u1 = sAccount.substring(0,sAccount.length - 10);
	u2 = sAccount.substring(sAccount.length - 10,12);
	t1 = 0;t2 = 0;
	for(i=u1.length ;i>0;i--) {
		t1 += u1.charAt(i - 1)*vahy[10 - i];
	}	  
	for(i=u2.length ;i>0;i--) {
		t2 += u2.charAt(i - 1)*vahy[10 - i];
	}
	if (((t2%11) == 0)&&((t1%11 == 0))) {
		return true;
	} else {
		return false;
	}
}

function ShowHide(element) {
	var e = (typeof(element)=="object" ? element : getE( element ));
	if (e.style.display=="none") { e.style.display = "" } else { e.style.display = "none" };
}
function ShowHide2(element) {
	var e = (typeof(element)=="object" ? element : getE( element ));
	if (e.className.indexOf('closed')>-1) {
		e.className = e.className.replace('closed','opened');
	} else {
		e.className = e.className.replace('opened','closed');
	}
}
function changeCross(element) {
		if (getE(element).className == 'crossClosed') {
			getE(element).className = 'crossOpened' 
		} else {
			getE(element).className = 'crossClosed';
		}
}

function styleChange(elementId,classNameStr) {	
	var e = getE( elementId );	
	e.className = classNameStr;	
}



function showBox( name ) {
	var box = document.getElementById(name);
	//box.style.left = document.documentElement.clientWidth / 2 - 350 + "px";
	box.style.top = topScroll() + document.documentElement.clientHeight / 2 - 150 + "px";
	box.style.display = 'block';
}
function hideBox( name ) {
    var box = document.getElementById(name);   
	box.style.display = 'none';
}


/* positions */
function leftPosition(obj,ev){
	if (ev) {
		if ( obj.offsetLeft + ((obj==document.body) ? 0 : leftPosition(obj.offsetParent)) < ev.clientX )  {
			return obj.offsetLeft + ((obj==document.body) ? 0 : leftPosition(obj.offsetParent))
		} else { // quli dvouradkovym elementum, tak aby se to nezobrazilo daleko od kurzoru na prvnim radku
			return ( ev.clientX );
		}
	} else { // kdyz volame rekurzivne, tak neni objekt ev k dispozici
		return obj.offsetLeft + ((obj==document.body) ? 0 : leftPosition(obj.offsetParent));
	}
}
function objXPosition( obj ) {
    return obj.offsetLeft + ((obj==document.body) ? 0 : objXPosition(obj.offsetParent));
}
function objYPosition( obj ) {
    return obj.offsetTop + ((obj==document.body) ? 0 : objYPosition(obj.offsetParent));
}

function topPosition(ev) {
	 return ( ev.clientY + topScroll() );
}
function topScroll() {
	if (window.innerHeight) {
		  return ( window.pageYOffset )
	} else if (document.documentElement && document.documentElement.scrollTop) {
		return ( document.documentElement.scrollTop )
	} else if (document.body) {
		  return ( document.body.scrollTop )
	}
	return 0;
}
/* /positions */

var fadeInOut;
function fadeInObject ( objID, speed, opacity ) { // fce necha plynule zobrazit libovolny objekt na strance dle jeho ID; speed je 1-100; opacity je nepovinna vychozi hodnota
	window.clearTimeout(fadeInOut);
	var obj = getE(objID);
	if (!(opacity>0)) opacity = 0;
	if (!(speed>0)) speed = 5;
	opacity+=speed;
	if (isIE()) {
		obj.style.filter = 'alpha(Opacity='+opacity+')';
		if (opacity<100) { fade=setTimeout("fadeInObject('"+objID+"',"+speed+","+opacity+");", 0) } else { obj.style.filter='' }
	} else if (isMOZ()) {
		obj.style.MozOpacity = opacity/100;
		if (opacity<100) { fade=setTimeout("fadeInObject('"+objID+"',"+speed+","+opacity+");", 0) } else { obj.style.MozOpacity=1; }
	}
	if (obj.style.display!='block') obj.style.display='block';
}
function fadeOutObject ( objID, speed, opacity ) { // fce necha plynule zmiznout libovolny objekt na strance dle jeho ID; speed je 1-100; opacity je nepovinna vychozi hodnota
	window.clearTimeout(fadeInOut);
	var obj = getE(objID);
	if (!(opacity>0)) opacity = 100;
	if (!(speed>0)) speed = 5;
	opacity-=speed;
	if (isIE()) {
		obj.style.filter = 'alpha(Opacity='+opacity+')';
		if (opacity>0) { fade=setTimeout("fadeOutObject('"+objID+"',"+speed+","+opacity+");", 0) } else { obj.style.display='none'; obj.style.filter=''; }
	} else if (isMOZ()) {
		obj.style.MozOpacity = opacity/100;
		if (opacity>0) { fade=setTimeout("fadeOutObject('"+objID+"',"+speed+","+opacity+");", 0) } else { obj.style.display='none'; obj.style.MozOpacity=1; }
	}
}



function hideBillingAddress( yesOrNo ){
    if (yesOrNo==1) {
        getE('billingAddress').style.display='none';
    }else{
        getE('billingAddress').style.display='block';
    }
}

function checkOrderForm(){
    var frm = getF('order').elements;
    var isSelectedOption;
    
    // je vybrana doprava?
    var d = document.getElementsByName('deliveryOption');
    isSelectedOption = false;
    for (i=0; i<d.length; i++){  
        if (d[i].checked) { isSelectedOption=true; }
    }
    if (!isSelectedOption) { alert('Zvolte si prosím způsob dopravy.'); return false; }
    
    // jevybrana platba?
    var p = document.getElementsByName('paymentOption');
    isSelectedOption = false;
    for (i=0; i<p.length; i++){  
        if (p[i].checked) { isSelectedOption=true; }
    }
    if (!isSelectedOption) { alert('Zvolte si prosím způsob platby.'); return false; }
    
    // jsou vyplneny vsechny udaje adresy?
    if (getE('billaddressthesame1').checked) {
        return controlUserData( frm, 'delivery');
    }else{
        return (controlUserData( frm, 'delivery') && controlUserData( frm, 'billing'));
    }
}

function controlUserData( frm, prefix ) {
    if (trim(frm[prefix+'_name'].value)=='') { 
      alert('Vyplňte prosím jméno a příjmení.'); 
      frm[prefix+'_name'].focus(); 
      return false; 
    }
    if (trim(frm[prefix+'_name'].value).indexOf(' ') < 0) { 
      alert('Vyplňte prosím jméno a příjmení.'); 
      frm[prefix+'_name'].focus(); 
      return false; 
    }
    
    if (trim(frm[prefix+'_street'].value)=='') { alert('Vyplňte prosím ulici.'); frm[prefix+'_street'].focus(); return false; }
    if (trim(frm[prefix+'_city'].value)=='') { alert('Vyplňte prosím město.'); frm[prefix+'_city'].focus(); return false; }
    if (isNaN(parseInt(trim(frm[prefix+'_psc'].value)))) { alert('Vyplňte prosím správně psč.'); frm[prefix+'_psc'].focus(); return false; }
    if (trim(frm[prefix+'_phone'].value)=='') { alert('Vyplňte prosím telefon.'); frm[prefix+'_phone'].focus(); return false; }
    if (parseInt(frm[prefix+'_phone'].value.replace(/ /g,''))!=frm[prefix+'_phone'].value.replace(/ /g,'')) { alert('Vyplňte prosím správně telefon. Vložte jen číslice, případně mezery. '); frm[prefix+'_phone'].focus(); return false; }
    if (frm[prefix+'_phone'].value.length<6) { alert('Vyplňte prosím správně telefon. Minimum je šest cifer. '); frm[prefix+'_phone'].focus(); return false; }
    if (trim(frm[prefix+'_email'].value)=='') { alert('Vyplňte prosím email.'); frm[prefix+'_email'].focus(); return false; }
    if (!emailControl(frm[prefix+'_email'].value)) { alert('Vyplňte prosím správně email.'); frm[prefix+'_email'].focus(); return false; }
    return true;
}

function checkDeliveryAndPayment( nDelivery, nPayment ){

    var s = document.getElementsByName('serviceOption');
    var p = document.getElementsByName('paymentOption');
    var d = document.getElementsByName('deliveryOption');
    var dSel=0, pSel=0, pays, i,j,k, payAllowed;
    var deliveryPrice=0, paymentPrice=0, deliveryName='', paymentName='', servicesPrice=0;
    
    // zjistime ktera doprava je vybrana
    for (i=0; i<d.length; i++){  
        if (d[i].checked) { dSel=d[i].value }
    }

    if ((nDelivery == 3)||(dSel == 3)){ // pokud je doprava postovni balik
      for (i=0; i<s.length; i++){
        s[i].checked=false;
        s[i].disabled=true;
      }
    }else{
      for (i=0; i<s.length; i++){
        s[i].disabled=false;
      }
    }
    
    
    // zjistime ktera sluzby jsou vybrany
    for (i=0; i<s.length; i++){  
        if (s[i].checked) { 
            getE('serviceline'+s[i].value).style.display = 'block';
            servicesPrice += parseInt( getF("order").elements['servicePrice'+s[i].value].value );
        }else{
            getE('serviceline'+s[i].value).style.display = 'none';        
        }
    }

    if (nDelivery>0) dSel=nDelivery;
    if (dSel==0) {
        // zadna doprava neni vybrana
        getE('servicelineD').style.display = 'none';
    }else{
        
        // aktualizujeme dopravu v kosiku
        deliveryPrice = parseInt(getF('order').elements['deliveryPrice'+dSel].value);
        deliveryName  = getF('order').elements['deliveryDescription'+dSel].value;
        
        // zviditelnime dopravu        
        getE('servicelineD').style.display = (deliveryPrice>0 ? 'block' : 'none' );

        getE('deliveryPrice').innerHTML = deliveryPrice;
        getE('deliveryPriceSum').innerHTML = deliveryPrice;
        getE('deliveryDescription').innerHTML = deliveryName;

        // a ktere zpusoby platby jsou k ni povoleny
        pays = getF('order').elements['payments'+dSel].value.split(',');

        // disablujeme nepovolene zpusoby platby
        for (j=0; j<p.length; j++){
            payAllowed = false;
            for (i=0; i<pays.length-1; i++){
                if (p[j].value==pays[i]) {payAllowed=true;}
            }
        
            if (payAllowed) {
                p[j].disabled=false;
                getE('paymentLabel'+p[j].value).className='';
                
             }else{
                getE('paymentLabel'+p[j].value).className='disabled';
                p[j].disabled=true;             
            }
        }
        // nezustalo nam checknute neco disablovane?
        for (j=0; j<p.length; j++){
                if (p[j].checked && p[j].disabled) {
                      p[j].checked=false; break;
//                    for (k=0; k<p.length; k++){
//                        if (!p[k].disabled) { p[k].checked=true; break; }
//                    }
                }  
        }

    }

    // zjistime ktera platba je vybrana
    for (i=0; i<p.length; i++){  
        if (p[i].checked) { pSel=p[i].value }
    }
    if (nPayment>0) pSel=nPayment;
    if (pSel==0) {
        getE('servicelineP').style.display = 'none';        
    }else{        
        paymentPrice = parseInt(getF('order').elements['paymentPrice'+pSel].value);
        paymentName  = getF('order').elements['paymentDescription'+pSel].value;
        
        // zviditelnime zpusob platby v kosiku
        getE('servicelineP').style.display = (paymentPrice>0 ? 'block' : 'none');


        getE('paymentPrice').innerHTML = paymentPrice;
        getE('paymentPriceSum').innerHTML = paymentPrice;
        getE('paymentDescription').innerHTML = paymentName;    
    }
    
    // secteme celkovou cenu objednavky
    var basketPriceSum = formatMoney(parseInt(getE('priceNoDelivery').value) + deliveryPrice + paymentPrice + servicesPrice );
    
    // aktualizujeme vsechny ceny na strance
    var prices = document.getElementsByTagName('cite'); // vsechny ceny na strance mam v tagu CITE, abych je jednoduse nasel
    for (i=0; i<prices.length; i++) {
        prices[i].innerHTML = basketPriceSum;
    }

}

function checkQuestionForm(){
    var frm = getF('question');
    if (frm.elements.question.value == '') { alert('Nevyplnili jste svůj dotaz.'); frm.elements.question.focus(); return false; }
    if (frm.elements.email.value == frm.elements.email.defaultValue) { alert('Emailový kontakt je povinný, volitelně pak telefon pro urgentní dotazy.'); frm.elements.email.focus(); return false; }
    if (frm.elements.antispamnumber.value == frm.elements.antispamnumber.defaultValue) { alert('Nevyplnili jste kontrolní kód z obrázku.'); frm.elements.antispamnumber.focus(); return false; }
    return true;    return true;
}

function formatMoney( str ){
    str = str.toString();
    if (str.length>3) { 
        return str.substring(0,str.length-3) + ' ' + str.substring(str.length-3,str.length) + ',- Kč';
    }else{
        return str + ',- Kč';
    }
    
}

function resizeMe(){

}

function availabilityCheck() {
    var av = getE('availability');
    if (av.innerHTML=='zjišťuji...') { av.innerHTML='nepodařilo se zjistit'; }
}

        // admin - list
        function resizeListWindow() {
          getE('listscroll').style.height= ( window.innerHeight-objYPosition(getE('listscroll'))-10 ) +  'px';
        }

/* zobrazovani a schovavani boxu na strance po najeti na okolni prvek */
function conditionedShow( objName ){
    getE( objName ).ismouseon = true;
    getE( objName ).style.display = "block";
}
function conditionedShow1( objName ){
    getE( objName ).ismouseon = true;
    getE( objName ).style.display = "block";
    setTimeout("conditionedHideNow('"+ objName +"');", 300);	
}
function conditionedHide( objName ){
    getE( objName ).ismouseon = false;
    setTimeout("conditionedHideNow('"+ objName +"');", 300);
}
function conditionedHide1( objName ){
    getE( objName ).ismouseon = false;
    setTimeout("conditionedHideNow('"+ objName +"');", 0);
	
}
function conditionedHideNow( objName ){
    if (getE( objName ).ismouseon == false) { getE( objName ).style.display = "none"; } ;
}

function selectImgSubProductParam(paramOptID, commodity, code, name ,paramName, paramID, priceparam){

    $('#subproductprice_'+paramID).val(priceparam);

    priceparam = priceparam.toString();
    if (priceparam.length>3) { 
        priceparam = priceparam.substring(0,priceparam.length-3) + ' ' + priceparam.substring(priceparam.length-3,priceparam.length);
    }else{
        priceparam = priceparam;
    }

    $('a.option').each(function(){
      if ($(this).attr('class') != 'option2'){
        $(this).attr('class','option');
      }
    });
    $('#paramOption_'+paramOptID).attr('class','option selected');
    $('#parameter_'+paramID).val(paramName);
    $('#commodity').val(commodity);
    $('#code').val(code);
    if (priceparam > ''){
      $('.bDPH').hide();
      $('.sDPH').find('td').html('<strong>'+(priceparam)+'<span> KČ <i>(s DPH)</i></span></strong>');
      $('.ndp-prices').hide();
      $('.nasplatky').hide();
      $('.dp-prices').find('span').html('<strong>'+(priceparam)+' Kč</strong>');
      $('.cat-prices-1').html('<strong>'+(priceparam)+'<span> Kč</span></strong>');

      if (getE('sumparameterprice') != null){
        getE('sumparameterprice').value = priceparam;
      }

    }
    $('#subProducts').show();
    //window.location.href('#selectedParam'); 

}

var lastSelectedValueID = new Array();
function selectImgParam( paramID, paramName, valueID, valuePrice, paramValue){
    getE('parameter_'+paramID).value = paramName + ': ' + paramValue;
    if (lastSelectedValueID[paramID]>0) { getE('paramOption_'+lastSelectedValueID[paramID]).className='option'; } 
    lastSelectedValueID[paramID] = valueID;
    getE('paramOption_'+lastSelectedValueID[paramID]).className='option selected';
    
}

var paramArray = new Array();
function SubProductParameter(paramOptID,paramID,obj,paramName){
  var finalPole = new Array();
  var finalDistinctPole = new Array();
  var counter = 0;
  //alert($(".subproductparameter").length);
  $(".subproductparameter").each(function(i){
    var pole = paramArray[$(this).val()].toString();
    //alert(pole);
    var splittedArray = pole.split(',');
    for (i=0;i<splittedArray.length;i++) {
      finalPole[counter] = splittedArray[i];
      //alert(splittedArray[i]);
      if ($(".subproductparameter").length > 1){
        if (!detectItem(finalDistinctPole, splittedArray[i])){
          //alert('a');
          finalDistinctPole[counter] = splittedArray[i];
        }
      }
      counter += 1;
    }
  });
  
  var test = finalPole.toString()+',';
  //alert(test);
  //alert(finalDistinctPole.toString());
  // zakomentovano protoze kdyz melo pole jeden zaznam tak se pak hnez zase smazalo . viz 
  //  http://www.nabytek-megastore.cz/novel-nhs-200/155235-3346/#imgs
  //    vs
  //  http://www.123-nabytek.cz/milena-matrace-sendvicove-prodej-splatky-d215843c4058
  for (i = 0; i < finalDistinctPole.length; i++) {
    test = test.replace(finalDistinctPole[i]+',','');
  }
  test = test.replace(',','');
  //alert(test);
  if (test > ''){
    var splittedTest = test.toString().split('##');
    var splittedTest2 = splittedTest[1].split('@@');
    var splittedTest3 = splittedTest2[1].split('--');
    
    var pkTblCommodities = splittedTest[0];
    //alert(pkTblCommodities);
    var price = splittedTest2[0];
    var code = splittedTest3[0];
    var paramName = splittedTest3[1];
    $('#subproductprice_'+paramID).val(price);
    
    priceparam = price.toString();
    if (priceparam.length>3) { 
        priceparam = priceparam.substring(0,priceparam.length-3) + ' ' + priceparam.substring(priceparam.length-3,priceparam.length);
    }else{
        priceparam = priceparam;
    }
    $('#subproductparameter').val(paramName);
    
    //alert($('#commodity').val());
    $('#commodity').val(pkTblCommodities);
    //alert($('#commodity').val());
    $('#code').val(code);
    if (priceparam > ''){

      $('.bDPH').hide();
      $('.sDPH').find('td').html('<strong>'+(priceparam)+'<span> KČ <i>(s DPH)</i></span></strong>');
      $('.ndp-prices').hide();
      $('.nasplatky').hide();
      $('.dp-prices').find('span').html('<strong>'+(priceparam)+' Kč</strong>');
      $('.cat-prices-1').html('<strong>'+(priceparam)+'<span> Kč</span></strong>');

      if (getE('sumparameterprice') != null){
        getE('sumparameterprice').value = priceparam;
      }
  
    }

  }else{
    obj.selectedIndex = 0;    
  }
}
function removeItem(originalArray, itemToRemove) {
  var j = 0;
  while (j < originalArray.length) {
    if (originalArray[j] == itemToRemove) {
      originalArray.splice(j, 1);
    } else { j++; }
  }
  return originalArray;
}

function detectItem(originalArray, itemToDetect) {
  var j = 0;
  while (j < originalArray.length) {
    if (originalArray[j] == itemToDetect) {
      return true;
    } else { j++; }		
  }
  return false;
}

function SortArray(a,b){
 var aa=a[0];
 var bb=b[0];
 if (aa>bb) return 1;
 if (aa<bb) return -1;
 return 0;
}
function computePrice(){
    var i, sumPrice = 0;
    var parameters = document.getElementsByName('parameterprice');
    for (i=0;i<parameters.length;i++) {
        sumPrice += parseInt(parameters[i].value);
    }
    if (getE('sumParametersPrice') != null){
      getE('sumParametersPrice').innerHTML = formatMoney(sumPrice);
    }
}



/*
* kontrola formularu
*/
function ControlForm(form){
  var errorMessage = '';
  $('#'+form).find('input').each(function(){
    if ($(this).attr('mandatory') > ''){
      if (($(this).attr('type') == 'text')||($(this).attr('type') == 'password')){
        if ($(this).val() == ''){
          if ($(this).attr('name').search('mail') != -1){
            if(!EmailControl($(this).val())){
              errorMessage = errorMessage + $(this).attr('mandatory') + '\n';
            }
          }else{
              errorMessage = errorMessage + $(this).attr('mandatory') + '\n';
          }
        } 
      }else if ($(this).attr('type') == 'checkbox'){
        if (!$(this).is(':checked')){
          errorMessage = errorMessage + $(this).attr('mandatory') + '\n';
        } 
      }  
    }
  });
  
  if (errorMessage > ''){
    alert(errorMessage);
    return false;
  }else{
    return true;
  }
}

function EmailControl(f){
    if ((f=='' || f=='vas@email.cz') || f.indexOf('..') != -1 || f.indexOf('.@') != -1 || f.indexOf('@.') != -1 || (f.indexOf('@') < 1 || f.indexOf('@') != f.lastIndexOf('@') || f.lastIndexOf('.') < f.lastIndexOf('@')+2  || f.lastIndexOf('.') > (f.length-3) || f.lastIndexOf('.') < (f.length-4))){
       return false;
      }
    if ((f.indexOf('ř') > -1) || (f.indexOf('ě') > -1) || (f.indexOf('š') > -1) || (f.indexOf('č') > -1) || (f.indexOf('ž') > -1) || (f.indexOf('ý') > -1) || (f.indexOf('á') > -1) || (f.indexOf('í') > -1) || (f.indexOf('é') > -1) || (f.indexOf('ů') > -1) || (f.indexOf('ú') > -1)){
       return false;
    }
    return true;
}

