var LastTimerId=0;
var basketChanged=1;

function modifyBasket() {

	basketChanged=1;
}


 if((!document.getElementById) && document.all){
	document.getElementById = function(id){return document.all[id];};
}

function xObject(x) {
	return document.getElementById(x);
}
	
function send_httprequest(obsluha, method, url, content) {
	if (window.XMLHttpRequest) { 
		xmlhttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) { 
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (error) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	xmlhttp.onreadystatechange = function() { obsluha(xmlhttp); };
	xmlhttp.open(method, url, true);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send(content);
    return true;
}


function isRequestOk(xmlhttp) {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		return true;
	}  else {
		return false;	
	}
}


	
	
function select_hide() {
	var allSelects = document.getElementsByTagName("select");
	for (i=0;i<allSelects.length;i++) {
		if (allSelects[i].getAttribute("id")!="currency") {
			allSelects[i].style.visibility='hidden';
		}
	}
	return true;
}

function select_show() {
	var allSelects = document.getElementsByTagName("select");
	for (i=0;i<allSelects.length;i++) {
		allSelects[i].style.visibility='visible';
	}
	return true;
}



var marked_row = new Array;


/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   integer  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    //alert('chzba ');
	var theCells = null;
	var textColor = '#000000';
	
    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
		
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"

	currentColor = theCells[0].style.backgroundColor;
	//alert(currentColor);

    //currentColor = theCells[0].getAttribute('bgcolor');

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
			textColor = '#000000';	
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
			textColor = '#ffffff';
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
			textColor = '#000000';
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
			textColor = '#ffffff';
			
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
		//alert (textColor);
				
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
				//theCells[c].style.color=textColor;
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
				//theCells[c].style.textColor = textColor;
				//theCells[c].style.color=textColor;

            }
        }
    } // end 5

	
    return true;
} // end of the 'setPointer()' function



function setOpacity(obj,opacity){
		opacity=(opacity==100)?99.999:opacity;
		obj.style.filter="alpha(opacity:"+opacity+",style=0)";
		obj.style.KHTMLOpacity=opacity/100;
		obj.style.MozOpacity=opacity/100;
		obj.style.opacity=opacity/100;

}


function getCookie(name) {
   var bites = document.cookie.split("; ");
   for (var i=0; i < bites.length; i++) {
       nextbite = bites[i].split("=");
      if (nextbite[0] == name) return unescape(nextbite[1]);
	}
    return null;
}


function ElementShow(elmId) {
  //objElm=xObject(elmId); if (objElm) objElm.style.display='block';
  xObject(elmId).style.display='block';
 // xObject(elmId+'ar').style.display='block';
}

function ElementHide(elmId) {
  window.clearTimeout(LastTimerId);
  //objElm=document.getElementById(elmId); if (objElm) objElm.style.display='none';
  xObject(elmId).style.display='none';
//  xObject(elmId+'ar').style.display='none';

}

function TimedElementShow(elmId) {
  LastTimerId=window.setTimeout("ElementShow('"+elmId+"')",500);
}

function confirmit(){
	var alertend = "Pozor!!! Zboží s ukončenou výrobou. Větší množství než máme skladem NELZE A NEPŮJDE DODAT!";
	if (confirm(alertend)) {
		return (true);
	} else {
		return (false);
	}
}


function __getDdlKey(e)
{
  var code;
  if (!e)
    var e = window.event;
  if (e.keyCode)
    code = e.keyCode;
  else
   if (e.which)
     code = e.which;
  return code;
}
var lastValue = '';
function __searchDdlReset()
{
  lastValue = '';
  //window.status = 'Najít:';
}
function __searchDdlList(eventObj,slcObj)
{
  if (navigator.userAgent.indexOf('MSIE') > -1 || navigator.userAgent.indexOf('Opera') > -1)
  {
    var lastKey = __getDdlKey(eventObj);
    if (lastKey == 8 && lastValue.length > 1)
      lastValue = lastValue.substring(0,lastValue.length-1);
    else
      lastValue += String.fromCharCode(lastKey);
    //window.status = 'Najít: ' + lastValue;
    for (i=0; i<slcObj.length; i++)
    {
      if ((slcObj.options[i].text.toLowerCase().indexOf(lastValue.toLowerCase()) == 0) && (lastValue.value != ''))
      {
        slcObj.options[i].selected = true;
        return false;
      }
    }
    return false;
  }
  else
    return true;
}





function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && (document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && (document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY ;
}

function showThumb(img,dir)
{
	obj_pop	= xObject('thumbholder');
	ico = "<img src='http://www.kkpneu.cz/"+dir+"/"+img+".jpg'>";
	obj_pop.innerHTML = ico;
  obj_pop.style.top  = (getScrollY()+200)+"px";
  
	obj_pop.style.left = (((screen.width)/2)-170)+"px";
 	obj_pop.style.display = 'block';
}




function hideIcon()
{
  obj_pop	= xObject('thumbholder');
	obj_pop.style.display = 'none';
	document.onmousemove = null;
	
}




	function testBrowser() {
		var testcookie='testcookie=valid';
		document.cookie=testcookie;
		var iscookie=document.cookie.indexOf(testcookie);
		if (iscookie==-1) {
			//top.location="info o zapnu ti cookies ";
			return false;
		}
	}


	var showOkno = 1;
    function ShowImage(url, name)
	{
            var features = 'toolbar=0,directories=0,menubar=0,scrollbars=0,resizable=1,status=0,location=0,width=' + (620) + ',height=' + (500);
            win = window.open(url, name, features);
            return (typeof(win) == 'object');
	}

    function ShowWWW(url, name)
	{
            var features = 'toolbar=1,directories=1,menubar=1,scrollbars=1,resizable=1,status=1,location=1,width=' + (500) + ',height=' + (400);
            win = window.open(url, name, features);
            return (typeof(win) == 'object');
    }

	
	function showHelpW() {
		if (showOkno == 1) {
			document.getElementById('LoginHelp').style.display='block';
		}
		showOkno = 0;
	}
	

	function HideHelpW() {
		document.getElementById('LoginHelp').style.display='none';
	}
	
	function ResizePage()
	{
		var levy = document.getElementById("leftcol");
		var pravy = document.getElementById("rightcol");
		var prostredni = document.getElementById("centercol");
		var nejvetsi = levy.offsetHeight;
		if (nejvetsi < prostredni.offsetHeight) {nejvetsi = prostredni.offsetHeight;}
		if (nejvetsi < pravy.offsetHeight) {nejvetsi = pravy.offsetHeight;}
		 
		var rozmer = nejvetsi+"px";
		levy.style.height = rozmer; 
		pravy.style.height = rozmer; 
		//prostredni.style.height = rozmer; 
		//alert (rozmer);	
		return true;
		
		
	}

