var vendorAction = "";

function popup(url, name, width, height) {
    var pars = "toolbar=no,location=no,menubar=no,resizable=no,scrollbars=yes";
    pars += ",width=" + width + ",height=" + height
    
    var left, top;

    left = (screen.width - width) / 2;
    top = (screen.height - height) / 2;

    pars += ",left = " + left;
    pars += ",top = " + top;
    
    var popup = window.open("", name, pars);
    popup.focus();
    popup.location = url;
    return false;
}

function moreInfoPopup(url, id, name, width, height) {
    if (url.indexOf("?") == -1)
        return popup(url + "?id=" + id, name, width, height);
    else
        return popup(url + "&id=" + id, name, width, height);    
}

function downloadPopup(url, id, name, width, height) {
    if (url.indexOf("?") == -1)
        return popup(url + "?id=" + id, name, width, height);
    else
        return popup(url + "&id=" + id, name, width, height);    
}

function updateVendorsAndModels(url, option) {
    var modelsForm = $("modelsSelect");
    modelsForm.innerHTML = "<option value=\"\">-- Trwa wczytywanie --</option>";
    var string = window.location.search;
    var reg = /\?/;
    var pars = "vendor=" + option.value + string.replace(reg, "&");
    var updater = new Ajax.Updater(
                                    "changeTerminalDiv",
                                    url,
                                    {
                                        method: 'post',
                                        parameters: pars
                                    }
                                    );
}

function openMoreInfo(elemSrc, size, group) {
    var backDiv = $("back");
    var aocDiv = $("aoc_div");
    var aoc = $("aoc");
    var width = 662;
    var height = 550;
    var h = self.innerHeight || (document.documentElement&&document.documentElement.clientHeight) || document.body.clientHeight;
    var w = self.innerWidth || (document.documentElement&&document.documentElement.clientWidth) || document.body.clientWidth;
    var left = (w - width) / 2;
    var top = (h - height) / 2;

    if (group == 'POSTCARDS') {
        $('getSpan').style.display = 'none';
        $('sendSpan').style.display = 'block';
        $('runSpan').style.display = 'none';
    } else if (group == 'VIDEOSTREAMING') {
        $('getSpan').style.display = 'none';
        $('allSizeSpan').style.display = 'none';
        $('sendSpan').style.display = 'none';
        $('runSpan').style.display = 'block';
    } else {
        $('getSpan').style.display = 'block';
        $('allSizeSpan').style.display = 'inline';
        $('sendSpan').style.display = 'none';
        $('runSpan').style.display = 'none';
    }

    window.scrollTo(0, 0);
    backDiv.style.height = (document.body.scrollHeight + 100) + "px";    
    backDiv.style.display = "block";
    aocDiv.style.display = "block";
    document.body.parentNode.style.overflowY = "hidden";  
    aocDiv.style.left = left + "px";
    aocDiv.style.top = top + "px";
    backDiv.style.width = w + "px";
    aocDiv.style.height = height + "px";
    aocDiv.style.width = width + "px";
    $('sizeSpan').innerHTML = "" + size;
    aoc.src = elemSrc;
    
    var flash = document.getElementsByTagName("object");
    for (var i = 0; i < flash.length; i++) {
        flash[i].parentNode.style.display = "none";
    }
    $('changeTerminalDiv').style.display = "none";
    
    return false;
}

function closeMoreInfo() {
    var aoc = $("aoc");
    var backDiv = $("back");
    var aocDiv = $("aoc_div");
    document.body.parentNode.style.overflowY = "scroll";
    backDiv.style.display = "none";
    aocDiv.style.display = "none";
    aoc.src = "";
    var flash = document.getElementsByTagName("object");
    for (var i = 0; i < flash.length; i++) {
        flash[i].parentNode.style.display = "block";
    }
    $('changeTerminalDiv').style.display = "block";
}

function fixForms() {
    if ($('wwwSearchForm') != null) {
        $('wwwSearchForm').name = "wwwSearchForm";
    }
    if ($('wwwChangeTerminalForm') != null) {
        $('wwwChangeTerminalForm').name = "wwwChangeTerminalForm";
    }
}

    var ie = (document.all)? true:false;
    if(!ie) {
        document.addEventListener("mousemove", mousePos, false);
        var pozX, pozY;
    }
    
    function mousePos(e) {
        pozX=e.pageX;
        pozY=e.pageY;
    }
    function move_tel() {
        scrolly=0;
        if(document.documentElement.scrollTop) scrolly=document.documentElement.scrollTop;
        if(document.body.scrollTop) scrolly=document.body.scrollTop;
        var x = (!ie)? pozX : event.x+document.body.scrollLeft;
        var y = (!ie)? pozY : event.y+scrolly;
        $('div_thumb').style.left=(x-100)+"px";
        $('div_thumb').style.top=(y-0+5)+"px";
        $('iframe').style.width=$('thumb').width + "px";
        $('iframe').style.height=$('thumb').height + "px";
        $('iframe').style.left=(x-100)+"px";
        $('iframe').style.top=(y-0+5)+"px";
    }
    function show_tel(urlTel) {
        $('thumb').src=urlTel;
        move_tel();
        $('iframe').style.display = "block";
        Element.show('div_thumb');
        return true;
    }
    function hide_tel() {
        Element.hide('iframe');
        Element.hide('div_thumb');
    }
    
  // SPR dodano funkcje

			
		
			
		function doChangePage (actionUrl, pars) {
				var element = document.getElementById ('ajaxLoading');
				if (element != null) {
					element.style.visibility = "visible";
				}
		 		var updater = new Ajax.Updater(
		 						"pagined_area",
		 						actionUrl,
		 				{
		 						method: 'post',
		 						parameters: pars,
		 						evalScripts: true
		 				}
		 				);
		
		
		}	
		
	//MCA dodano funkcje
	
	function addLoadEvent(func) { 
	  var oldonload = window.onload; 
	  if (typeof window.onload != 'function') { 
	    window.onload = func; 
	  } else { 
	    window.onload = function() { 
	      if (oldonload) { 
	        oldonload(); 
	      } 
	      func(); 
	    } 
	  } 
	} 	
			
	addLoadEvent(fixForms)
	
		
