function showTab(id){
	for(i=1;i<6;i++){
		el = document.getElementById('tab'+i);
		if(el){
			el.className = (id==i ? 'span' : 'nospan');
		}
		el = document.getElementById('bl'+i);
		if(el){
			el.style.display = (id==i ? 'inline' : 'none');
		}
		el = document.getElementById('br'+i);
		if(el){
			el.style.display = (id==i ? 'inline' : 'none');
		}
		el = document.getElementById('tabContent'+i);
		if(el){
			el.style.display = (id==i ? 'block' : 'none');
		}
	}
	return false;
}
function ce (tagName) {	return document.createElement(tagName) }
galwin = 0;
function openWindow( winvar, url, name, width, height )
{
url = unescape(url);
window.open( url, "_blank", 'toolbar=0,status=0,resizable=0,scrollbars=1,width='+width+',height='+height );
}
function showDir( width, height, url )
{
   w=width;
   h=height;
   if (w>screen.width) w=screen.width*0.75;
   if (h>screen.height) h=screen.height*0.75;
   openWindow(galwin, url, "showgal", w, h);
}
winvar = 0;
function popup()
{
winvar = open( '', 'wishwin', 'toolbar=0,status=0,resizable=0,scrollbars=0,width=300,height=150' );
}

    function setX() {
        document.getElementById('axcrt').style.pixelTop = document.body.scrollTop + Math.ceil((document.body.clientHeight-100)/2);
    }

    var agt = navigator.userAgent.toLowerCase();
    var is_ie = (agt.indexOf("ie") != -1);
    var width=540,height=334;
  	if(self.innerWidth && self.innerHeight) { // Mozilla, Firefox etc
    	width=self.innerWidth;
    	height=self.innerHeight ;
  	} else if (document.body){ // MS IE
	    width=document.body.clientWidth;
	    height=document.body.clientHeight;
  	}
    iebag = ( is_ie ) ? 'absolute' : 'fixed';
    document.write('<div id="axcrt" style="background: none repeat scroll 0% 0% #bfd1da; border: 1px dotted rgb(203, 203, 203); position: ' + iebag + '; display: none; visibility: hidden; z-index: 100; left: '+Math.ceil((width-300)/2)+'px; top: '+Math.ceil((height-100)/2)+'px; width: 400px; height: 40px;"><table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td style="text-align: center; vertical-align: middle;"><div id="axcrt_text">Идет добавление товара в корзину...</div></td></tr></table></div>');
    if ( is_ie ) {
        window.onscroll = setX;
    }
    
function setModels(chooser) {
    var modelChooser = chooser.form.elements["model_id"];
    // empty previous settings
    modelChooser.options.length = 0;
    // get chosen value to act as index to modeldb hash table
   	modelChooser.options[0] = new Option("Загрузка...", "0", true, false);
    var choice = chooser.options[chooser.selectedIndex].value;
    JsHttpRequest.query(
    '/ajax/model_loader.php',
    {
        'man_id': choice,
        'bugfix': "yes"
	    },
	    function(result, errors) {
	    	if (!errors && result.array) {
				// insert default first item
			    modelChooser.options.length = 0;
			    modelChooser.options[0] = new Option("выберите ...", "0", true, false);
			        if (choice != "") {
				        // loop through array of the hash table entry, and populate options
				        for (var i = 0; i < result.array.length; i++) {
				            modelChooser.options[i + 1] = new Option(result.array[i].name, result.array[i].model_id);
				        }
				    }
	    	}
	    },
	    true
	);
}

function checkModelForm(chooser) {
	var model = chooser.form.elements["model_id"];
	if ( model.selectedIndex !=-1 )
		{
			if (model.options[model.selectedIndex].value>0) {
  				return true;
			} else {
				alert("Вы не выбрали модель телефона");
				return false;
			}
		}
		else 
		{
			alert("Вы не выбрали модель телефона");
			return false;
		}
}

hs.graphicsDir = '/design/user/images/';
hs.outlineType = 'rounded';
hs.loadingOpacity = 1;

hs.restoreTitle = 'Нажмите на картинку, чтобы закрыть окно';
hs.loadingText = 'Загрузка...';
hs.loadingTitle = 'Отменить загрузку';
hs.focusTitle = 'Нажмите для возврата к картинке';
hs.fullExpandTitle = 'Развернуть во всю величину';


// Jquery UI
$(document).ready(function() {
    $("input#search_product").autocomplete({
    	delay: 100,
		minLength: 3,
		source: function(req, add) {
			$.getJSON("/ajax/search_help.php?callback=?", req, function(data) {  
				var suggestions = [];  
				$.each(data, function(i, val){  
				suggestions.push(val.name);  
			});
			add(suggestions);  
			});
		}
	});
});
